Merge pull request #97 from PhasicFlow/develop

Reflective boundary condition is added and tested.
This commit is contained in:
PhasicFlow
2024-04-12 00:13:42 +03:30
committed by GitHub
48 changed files with 3801 additions and 3589 deletions

View File

@ -41,11 +41,11 @@ class AdamsBashforth2
{
private:
auto& dy1()
{
return static_cast<realx3PointField_D&>(*this);
}
public:
/// Type info

View File

@ -78,6 +78,7 @@ structuredData/boundaries/boundaryBase/boundaryBaseKernels.cpp
structuredData/boundaries/boundaryExit/boundaryExit.cpp
structuredData/boundaries/boundaryNone/boundaryNone.cpp
structuredData/boundaries/boundaryPeriodic/boundaryPeriodic.cpp
structuredData/boundaries/boundaryReflective/boundaryReflective.cpp
structuredData/boundaries/boundaryList.cpp
structuredData/pointStructure/pointStructure/pointStructure.cpp
structuredData/pointStructure/selectors/pStructSelector/pStructSelector.cpp

View File

@ -28,18 +28,15 @@ Licence:
*
*/
#include <Kokkos_Core.hpp>
#include <Kokkos_DualView.hpp>
#include <Kokkos_UnorderedMap.hpp>
#include "builtinTypes.hpp"
namespace pFlow
{
/// Host memory space
using HostSpace = Kokkos::HostSpace;
@ -63,34 +60,26 @@ using DefaultHostExecutionSpace = Kokkos::DefaultHostExecutionSpace;
/// activated.
using DefaultExecutionSpace = Kokkos::DefaultExecutionSpace;
using deviceRPolicyStatic =
Kokkos::RangePolicy<
using deviceRPolicyStatic = Kokkos::RangePolicy<
Kokkos::DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Static>,
Kokkos::IndexType<pFlow::uint32>>;
using hostRPolicyStatic =
Kokkos::RangePolicy<
using hostRPolicyStatic = Kokkos::RangePolicy<
Kokkos::DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Static>,
Kokkos::IndexType<pFlow::uint32>>;
using deviceRPolicyDynamic =
Kokkos::RangePolicy<
using deviceRPolicyDynamic = Kokkos::RangePolicy<
Kokkos::DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Dynamic>,
Kokkos::IndexType<pFlow::uint32>>;
using hostRPolicyDynamic =
Kokkos::RangePolicy<
using hostRPolicyDynamic = Kokkos::RangePolicy<
Kokkos::DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Dynamic>,
Kokkos::IndexType<pFlow::uint32>>;
/// Pair of two variables
template<typename T1, typename T2>
using Pair = Kokkos::pair<T1, T2>;
@ -139,8 +128,6 @@ template<typename T, typename Layout=void>
template<typename T, typename Layout = void>
using deviceViewType3D = Kokkos::View<T***, Layout, void>;
template<typename T>
using hostViewTypeScalar = Kokkos::View<T, Kokkos::HostSpace>;
@ -158,18 +145,17 @@ template<typename T, typename Layout=void>
/// 1D vector on device with atomic capabilities
template<typename T>
using deviceAtomicViewType1D =
Kokkos::View<
using deviceAtomicViewType1D = Kokkos::View<
T*,
Kokkos::MemoryTraits<std::is_same<DefaultExecutionSpace,Serial>::value?0:Kokkos::Atomic>>;
Kokkos::MemoryTraits<
std::is_same_v<DefaultExecutionSpace, Serial> ? 0 : Kokkos::Atomic>>;
/// 3D array on device with atomic capabilities
template<typename T>
using deviceAtomicViewType3D =
Kokkos::View<
using deviceAtomicViewType3D = Kokkos::View<
T***,
Kokkos::MemoryTraits<std::is_same<DefaultExecutionSpace,Serial>::value?0:Kokkos::Atomic>>;
Kokkos::MemoryTraits<
std::is_same_v<DefaultExecutionSpace, Serial> ? 0 : Kokkos::Atomic>>;
} // pFlow

View File

@ -21,201 +21,198 @@ Licence:
#ifndef __KokkosUtilities_hpp__
#define __KokkosUtilities_hpp__
#include "KokkosTypes.hpp"
#include "pFlowMacros.hpp"
#include "types.hpp"
#include "span.hpp"
#include "dataIO.hpp"
#include "iOstream.hpp"
#include "pFlowMacros.hpp"
#include "span.hpp"
#include "types.hpp"
namespace pFlow
{
template<typename ExecutionSpace>
INLINE_FUNCTION_H
bool constexpr isHostAccessible()
INLINE_FUNCTION_H bool constexpr isHostAccessible()
{
return Kokkos::SpaceAccessibility<ExecutionSpace, HostSpace>::accessible;
}
template<typename ExecutionSpace>
INLINE_FUNCTION_H
bool constexpr isDeviceAccessible()
INLINE_FUNCTION_H bool constexpr isDeviceAccessible()
{
return Kokkos::SpaceAccessibility<ExecutionSpace,DefaultExecutionSpace::memory_space>::accessible;
return Kokkos::SpaceAccessibility<
ExecutionSpace,
DefaultExecutionSpace::memory_space>::accessible;
}
/// Is MemoerySpace accessible from ExecutionSpace
template<typename ExecutionSpace, typename MemoerySpace>
INLINE_FUNCTION_H
bool constexpr areAccessible()
INLINE_FUNCTION_H bool constexpr areAccessible()
{
return Kokkos::SpaceAccessibility<ExecutionSpace, MemoerySpace>::accessible;
}
template <
typename Type,
typename... Properties>
INLINE_FUNCTION_H
void reallocInit( ViewType1D<Type,Properties...>& view, uint32 len)
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
reallocInit(ViewType1D<Type, Properties...>& view, uint32 len)
{
Kokkos::realloc(Kokkos::WithoutInitializing, view, len);
}
template <
typename Type,
typename... Properties>
INLINE_FUNCTION_H
void reallocNoInit(ViewType1D<Type,Properties...>& view, uint32 len)
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
reallocNoInit(ViewType1D<Type, Properties...>& view, uint32 len)
{
Kokkos::realloc(Kokkos::WithoutInitializing, view, len);
}
template <
typename Type,
typename... Properties>
INLINE_FUNCTION_H
void reallocFill( ViewType1D<Type,Properties...>& view, uint32 len, Type val)
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
reallocFill(ViewType1D<Type, Properties...>& view, uint32 len, Type val)
{
reallocNoInit(view, len);
Kokkos::deep_copy(view, val);
}
template <
typename Type,
typename... Properties>
INLINE_FUNCTION_H
void reallocInit( ViewType2D<Type,Properties...>& view, uint32 len1, uint32 len2)
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
reallocInit(ViewType2D<Type, Properties...>& view, uint32 len1, uint32 len2)
{
Kokkos::realloc(view, len1, len2);
}
template <
typename Type,
typename... Properties>
INLINE_FUNCTION_H
void reallocNoInit(ViewType2D<Type,Properties...>& view, uint32 len1, uint32 len2)
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
reallocNoInit(ViewType2D<Type, Properties...>& view, uint32 len1, uint32 len2)
{
Kokkos::realloc(Kokkos::WithoutInitializing, view, len1, len2);
}
template <
typename Type,
typename... Properties>
INLINE_FUNCTION_H
void reallocFill( ViewType2D<Type,Properties...>& view, uint32 len1, uint32 len2, Type val)
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
reallocFill(
ViewType2D<Type, Properties...>& view,
uint32 len1,
uint32 len2,
Type val
)
{
reallocNoInit(view, len1, len2);
Kokkos::deep_copy(view, val);
}
template <
typename Type,
typename... Properties>
INLINE_FUNCTION_H
void reallocInit( ViewType3D<Type,Properties...>& view, uint32 len1, uint32 len2, uint32 len3)
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
reallocInit(
ViewType3D<Type, Properties...>& view,
uint32 len1,
uint32 len2,
uint32 len3
)
{
Kokkos::realloc(view, len1, len2, len3);
}
template <
typename Type,
typename... Properties>
INLINE_FUNCTION_H
void reallocNoInit(ViewType3D<Type,Properties...>& view, uint32 len1, uint32 len2, uint32 len3)
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
reallocNoInit(
ViewType3D<Type, Properties...>& view,
uint32 len1,
uint32 len2,
uint32 len3
)
{
Kokkos::realloc(Kokkos::WithoutInitializing, view, len1, len2, len3);
}
template <
typename Type,
typename... Properties>
INLINE_FUNCTION_H
void reallocFill( ViewType3D<Type,Properties...>& view, uint32 len1, uint32 len2, uint32 len3, Type val)
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
reallocFill(
ViewType3D<Type, Properties...>& view,
uint32 len1,
uint32 len2,
uint32 len3,
Type val
)
{
reallocNoInit(view, len1, len2, len3);
Kokkos::deep_copy(view, val);
}
template <
typename Type,
typename... Properties>
INLINE_FUNCTION_H
void resizeInit(ViewType1D<Type,Properties...>& view, uint32 newLen)
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
resizeInit(ViewType1D<Type, Properties...>& view, uint32 newLen)
{
Kokkos::resize(view, newLen);
}
template <
typename Type,
typename... Properties>
INLINE_FUNCTION_H
void resizeNoInit(ViewType1D<Type,Properties...>& view, uint32 newLen)
template<typename Type, typename... Properties>
INLINE_FUNCTION_H void
resizeNoInit(ViewType1D<Type, Properties...>& view, uint32 newLen)
{
Kokkos::resize(Kokkos::WithoutInitializing, view, newLen);
}
template<typename ViewType>
INLINE_FUNCTION_H
void swapViews(ViewType& v1, ViewType &v2)
INLINE_FUNCTION_H void
swapViews(ViewType& v1, ViewType& v2)
{
static_assert(
std::is_move_assignable<ViewType>::value && std::is_move_constructible<ViewType>::value,
"swapViews arguments must be move assignable and move constructible");
std::is_move_assignable_v<ViewType> &&
std::is_move_constructible_v<ViewType>,
"swapViews arguments must be move assignable and move constructible"
);
ViewType tmp = std::move(v1);
v1 = std::move(v2);
v2 = std::move(tmp);
}
template<typename T1, typename T2>
INLINE_FUNCTION_H
iOstream& operator <<(iOstream& os, const Pair<T1,T2>& p)
INLINE_FUNCTION_H iOstream&
operator<<(iOstream& os, const Pair<T1, T2>& p)
{
os << '(' << p.first << " " << p.second << ')';
return os;
}
template<typename T, typename... properties>
INLINE_FUNCTION_H
span<T> makeSpan(ViewType1D<T, properties...> & v)
INLINE_FUNCTION_H span<T>
makeSpan(ViewType1D<T, properties...>& v)
{
return span<T>(v.data(), v.size());
}
template<typename T, typename... properties>
INLINE_FUNCTION_H
span<T> makeSpan(ViewType1D<T, properties...> & v, uint32 size)
INLINE_FUNCTION_H span<T>
makeSpan(ViewType1D<T, properties...>& v, uint32 size)
{
return span<T>(v.data(), size);
}
template<typename T, typename... properties>
INLINE_FUNCTION_H
span<T> makeSpan(const ViewType1D<T, properties...> & v)
INLINE_FUNCTION_H span<T>
makeSpan(const ViewType1D<T, properties...>& v)
{
return span<T>(const_cast<T*>(v.data()), v.size());
}
template<typename T, typename... properties>
INLINE_FUNCTION_H
span<T> makeSpan(const ViewType1D<T, properties...> & v, uint32 size)
INLINE_FUNCTION_H span<T>
makeSpan(const ViewType1D<T, properties...>& v, uint32 size)
{
return span<T>(const_cast<T*>(v.data()), size);
}
template<typename T, typename... properties>
INLINE_FUNCTION_H
iOstream& operator <<(iOstream& os, const ViewType1D<T, properties...> & v)
INLINE_FUNCTION_H iOstream&
operator<<(iOstream& os, const ViewType1D<T, properties...>& v)
{
using ExSpace = typename ViewType1D<T, properties...>::execution_space;
static_assert(isHostAccessible<ExSpace>(), "View memory is not accessible from Host");
static_assert(
isHostAccessible<ExSpace>(), "View memory is not accessible from Host"
);
span<T> spn(v.data(), v.size());
os << spn;
@ -223,7 +220,6 @@ iOstream& operator <<(iOstream& os, const ViewType1D<T, properties...> & v)
return os;
}
} // pFlow
#endif //__KokkosUtilities_hpp__

View File

@ -20,29 +20,22 @@ Licence:
#ifndef __Range_hpp__
#define __Range_hpp__
#include <Kokkos_Core.hpp>
#include "pFlowMacros.hpp"
#include "typeInfo.hpp"
#include "builtinTypes.hpp"
#include "iOstream.hpp"
#include "pFlowMacros.hpp"
#include "typeInfo.hpp"
namespace pFlow
{
/**
* Range for elements in an vector [start,end)
*
*/
template<typename T>
struct Range
:
public Kokkos::pair<T,T>
struct Range : public Kokkos::pair<T, T>
{
using Pair = Kokkos::pair<T, T>;
@ -51,29 +44,30 @@ public Kokkos::pair<T,T>
//// - Constructors
/// Default
INLINE_FUNCTION_HD
Range(){}
INLINE_FUNCTION_HD Range()
{
}
/// From end, set start to 0
INLINE_FUNCTION_HD
Range(const T& e)
:
Range(0,e)
{}
: Range(0, e)
{
}
/// From componeents
INLINE_FUNCTION_HD
Range(const T& s, const T& e)
:
Range::Pair(s,e)
{}
: Range::Pair(s, e)
{
}
/// From pair
INLINE_FUNCTION_HD
Range(const Range::Pair& src)
:
Range::Pair(src)
{}
: Range::Pair(src)
{
}
/// Copy
INLINE_FUNCTION_HD
@ -134,12 +128,11 @@ public Kokkos::pair<T,T>
{
return Pair(this->first, this->second);
}
};
template<typename T>
INLINE_FUNCTION_H
iOstream& operator <<(iOstream& os, const Range<T>& rng)
INLINE_FUNCTION_H iOstream&
operator<<(iOstream& os, const Range<T>& rng)
{
os << "[" << rng.start() << " " << rng.end() << ")";
return os;
@ -153,7 +146,6 @@ using rangeU32 = Range<uint32>;
using rangeU64 = Range<uint64>;
} // pFlow
#endif //__KokkosTypes_hpp__

View File

@ -21,47 +21,38 @@ Licence:
#ifndef __ViewAlgorithms_hpp__
#define __ViewAlgorithms_hpp__
#include "numericConstants.hpp"
#include "Range.hpp"
#include "KokkosUtilities.hpp"
#include "Range.hpp"
#include "numericConstants.hpp"
#include "cudaAlgorithms.hpp"
#include "kokkosAlgorithms.hpp"
#include "stdAlgorithms.hpp"
#include "cudaAlgorithms.hpp"
namespace pFlow
{
template<typename T, typename... properties>
INLINE_FUNCTION_H
uint32 count(
INLINE_FUNCTION_H uint32
count(
const ViewType1D<T, properties...>& view,
uint32 start,
uint32 end,
const T& val)
const T& val
)
{
using ExecutionSpace = typename ViewType1D<T, properties...>::execution_space;
using ExecutionSpace =
typename ViewType1D<T, properties...>::execution_space;
uint32 numElems = end - start;
return pFlow::algorithms::KOKKOS::count<T, ExecutionSpace>
(
view.data()+start,
numElems,
val
return pFlow::algorithms::KOKKOS::count<T, ExecutionSpace>(
view.data() + start, numElems, val
);
}
template<typename T, typename... properties>
INLINE_FUNCTION_H
void fill
(
ViewType1D<T, properties...>& view,
rangeU32 span,
T val
)
INLINE_FUNCTION_H void
fill(ViewType1D<T, properties...>& view, rangeU32 span, T val)
{
using exe_space = typename ViewType1D<T, properties...>::execution_space;
auto subV = Kokkos::subview(view, span.getPair());
@ -80,24 +71,18 @@ void fill
{
static_assert("fill is not valid for non-trivially-copyable data type");
}
}
template<typename T, typename... properties>
void fill
(
ViewType1D<T, properties...>& view,
uint32 start,
uint32 end,
T val
)
void
fill(ViewType1D<T, properties...>& view, uint32 start, uint32 end, T val)
{
fill(view, rangeU32(start, end), val);
}
template<typename T, typename... properties>
void fill
(
void
fill(
ViewType3D<T, properties...>& view,
rangeU32 range1,
rangeU32 range2,
@ -111,59 +96,58 @@ void fill
}
template<typename T, typename... properties>
void fill
(
ViewType3D<T, properties...>& view,
const T& val
)
void
fill(ViewType3D<T, properties...>& view, const T& val)
{
static_assert(std::is_trivially_copyable_v<T>, "Not valid type for fill");
Kokkos::deep_copy(view, val);
}
template<
typename Type,
typename... properties>
void fillSequence(
template<typename Type, typename... properties>
void
fillSequence(
ViewType1D<Type, properties...>& view,
uint32 start,
uint32 end,
const Type startVal
)
{
static_assert(std::is_trivially_copyable_v<Type>, "Not valid type for fill");
using ExecutionSpace = typename ViewType1D<Type, properties...>::execution_space;
static_assert(
std::is_trivially_copyable_v<Type>, "Not valid type for fill"
);
using ExecutionSpace =
typename ViewType1D<Type, properties...>::execution_space;
uint32 numElems = end - start;
pFlow::algorithms::KOKKOS::fillSequence<Type, ExecutionSpace>(
view.data()+start,
numElems,
startVal);
view.data() + start, numElems, startVal
);
return;
}
template<
typename Type,
typename... properties,
typename indexType,
typename... indexProperties>
bool fillSelected
(
bool
fillSelected(
ViewType1D<Type, properties...> view,
ViewType1D<indexType, indexProperties...> indices,
uint32 numElems,
Type val
)
{
static_assert(std::is_trivially_copyable_v<Type>, "Not valid type for fillSelected");
static_assert(
std::is_trivially_copyable_v<Type>, "Not valid type for fillSelected"
);
static_assert(
areAccessible<
typename ViewType1D<Type, properties...>::execution_space,
typename ViewType1D<indexType, indexProperties...>::memory_space>(),
"In fillSelected, arguments view and indices must have similar spaces");
"In fillSelected, arguments view and indices must have similar spaces"
);
using ExSpace = typename ViewType1D<Type, properties...>::execution_space;
using policy = Kokkos::RangePolicy<ExSpace, Kokkos::IndexType<uint32>>;
@ -173,7 +157,8 @@ bool fillSelected
policy(0, numElems),
LAMBDA_HD(uint32 i){
// view[indices[i]]= val;
});
}
);
Kokkos::fence();
return true;
@ -184,66 +169,60 @@ template<
typename... properties,
typename indexType,
typename... indexProperties>
bool fillSelected(
bool
fillSelected(
ViewType1D<Type, properties...> view,
const ViewType1D<indexType, indexProperties...> indices,
const ViewType1D<Type, properties...> vals,
const uint32 numElems )
const uint32 numElems
)
{
static_assert(std::is_trivially_copyable_v<Type>, "Not valid type for fillSelected");
static_assert(
std::is_trivially_copyable_v<Type>, "Not valid type for fillSelected"
);
static_assert(
areAccessible<
typename ViewType1D<Type, properties...>::execution_space,
typename ViewType1D<indexType, indexProperties...>::memory_space>(),
"In fillSelected arguments view and indices must have similar spaces");
"In fillSelected arguments view and indices must have similar spaces"
);
using ExecutionSpace = typename ViewType1D<Type, properties...>::execution_space;
using ExecutionSpace =
typename ViewType1D<Type, properties...>::execution_space;
pFlow::algorithms::KOKKOS::fillSelected<Type, indexType, ExecutionSpace>(
view.data(),
indices.data(),
vals.data(),
numElems
view.data(), indices.data(), vals.data(), numElems
);
return true;
}
template<typename T, typename... properties>
INLINE_FUNCTION_H
T min(
const ViewType1D<T, properties...>& view,
uint32 start,
uint32 end)
INLINE_FUNCTION_H T
min(const ViewType1D<T, properties...>& view, uint32 start, uint32 end)
{
using ExecutionSpace = typename ViewType1D<T, properties...>::execution_space;
using ExecutionSpace =
typename ViewType1D<T, properties...>::execution_space;
uint32 numElems = end - start;
return
pFlow::algorithms::KOKKOS::min<T, ExecutionSpace>(
view.data()+start,
numElems);
return pFlow::algorithms::KOKKOS::min<T, ExecutionSpace>(
view.data() + start, numElems
);
}
template<typename T, typename... properties>
INLINE_FUNCTION_H
T max(
const ViewType1D<T, properties...>& view,
uint32 start,
uint32 end)
INLINE_FUNCTION_H T
max(const ViewType1D<T, properties...>& view, uint32 start, uint32 end)
{
using ExecutionSpace = typename ViewType1D<T, properties...>::execution_space;
using ExecutionSpace =
typename ViewType1D<T, properties...>::execution_space;
uint32 numElems = end - start;
return
pFlow::algorithms::KOKKOS::max<T, ExecutionSpace>(
view.data()+start,
numElems);
return pFlow::algorithms::KOKKOS::max<T, ExecutionSpace>(
view.data() + start, numElems
);
}
template<
@ -251,8 +230,8 @@ template <
typename... dProperties,
typename sType,
typename... sProperties>
INLINE_FUNCTION_H
void copy(
INLINE_FUNCTION_H void
copy(
const ViewType1D<dType, dProperties...>& dst,
const ViewType1D<sType, sProperties...>& src
)
@ -265,8 +244,8 @@ template <
typename... dProperties,
typename sType,
typename... sProperties>
INLINE_FUNCTION_H
void copy(
INLINE_FUNCTION_H void
copy(
const ViewType1D<dType, dProperties...>& dst,
uint32 dStart,
const ViewType1D<sType, sProperties...>& src,
@ -274,7 +253,6 @@ void copy(
uint32 sEnd
)
{
range32 sSpan(sStart, sEnd);
range32 dSpan(dStart, dStart + (sEnd - sStart));
@ -284,17 +262,10 @@ void copy(
Kokkos::deep_copy(dstSub, srcSub);
}
template <
typename Type,
typename... sProperties>
INLINE_FUNCTION_H
void getNth(
Type& dst,
const ViewType1D<Type, sProperties...>& src,
const uint32 n
)
template<typename Type, typename... sProperties>
INLINE_FUNCTION_H void
getNth(Type& dst, const ViewType1D<Type, sProperties...>& src, const uint32 n)
{
auto subV = Kokkos::subview(src, Kokkos::make_pair(n, n + 1));
hostViewType1D<Type> dstView("getNth", 1);
// hostViewTypeScalar
@ -302,31 +273,24 @@ void getNth(
dst = *dstView.data();
}
template<typename T, typename... properties>
INLINE_FUNCTION_H
void sort(
ViewType1D<T, properties...>& view,
uint32 start,
uint32 end)
INLINE_FUNCTION_H void
sort(ViewType1D<T, properties...>& view, uint32 start, uint32 end)
{
using ExecutionSpace = typename ViewType1D<T, properties...>::execution_space;
using ExecutionSpace =
typename ViewType1D<T, properties...>::execution_space;
uint32 numElems = end - start;
if constexpr (isHostAccessible<ExecutionSpace>())
{
pFlow::algorithms::STD::sort<T,true>(
view.data()+start,
numElems);
pFlow::algorithms::STD::sort<T, true>(view.data() + start, numElems);
return;
}
#ifdef __CUDACC__
pFlow::algorithms::CUDA::sort<T>(
view.data()+start,
numElems);
pFlow::algorithms::CUDA::sort<T>(view.data() + start, numElems);
#else
static_assert("sort on device is not defined!");
@ -336,33 +300,32 @@ void sort(
}
template<typename T, typename... properties, typename CompareFunc>
INLINE_FUNCTION_H
void sort(
INLINE_FUNCTION_H void
sort(
ViewType1D<T, properties...>& view,
uint32 start,
uint32 end,
CompareFunc compare)
CompareFunc compare
)
{
using ExecutionSpace = typename ViewType1D<T, properties...>::execution_space;
using ExecutionSpace =
typename ViewType1D<T, properties...>::execution_space;
uint32 numElems = end - start;
if constexpr (isHostAccessible<ExecutionSpace>())
{
pFlow::algorithms::STD::sort<T, CompareFunc, true>(
view.data()+start,
numElems,
compare);
view.data() + start, numElems, compare
);
return;
}
#ifdef __CUDACC__
pFlow::algorithms::CUDA::sort<T, CompareFunc>(
view.data()+start,
numElems,
compare);
view.data() + start, numElems, compare
);
#else
static_assert("sort on device is not defined!");
@ -376,48 +339,49 @@ template<
typename... properties,
typename permType,
typename... permProperties>
void permuteSort(
void
permuteSort(
const ViewType1D<Type, properties...>& view,
uint32 start,
uint32 end,
ViewType1D<permType, permProperties...>& permuteView,
uint32 permStart )
uint32 permStart
)
{
static_assert(
areAccessible<
typename ViewType1D<Type, properties...>::execution_space,
typename ViewType1D<permType, permProperties...>::memory_space>(),
"In permuteSort, view and permuteView should have the same space");
"In permuteSort, view and permuteView should have the same space"
);
using ExecutionSpace = typename ViewType1D<Type, properties...>::execution_space;
using ExecutionSpace =
typename ViewType1D<Type, properties...>::execution_space;
uint32 numElems = end - start;
pFlow::algorithms::STD::permuteSort<Type, permType, true>(
view.data()+start,
permuteView.data()+permStart,
numElems);
view.data() + start, permuteView.data() + permStart, numElems
);
return;
#ifdef __CUDACC__
pFlow::algorithms::CUDA::permuteSort(
view.data()+start,
permuteView.data()+permStart,
numElems);
view.data() + start, permuteView.data() + permStart, numElems
);
#else
static_assert("sort on device is not defined!");
#endif
}
template<typename T>
INLINE_FUNCTION_HD
int32 binarySearch_(const T* array, int32 length, const T& val)
INLINE_FUNCTION_HD int32
binarySearch_(const T* array, int32 length, const T& val)
{
if(length <= 0) return -1;
if (length <= 0)
return -1;
int low = 0;
int high = length - 1;
@ -444,42 +408,40 @@ int32 binarySearch_(const T* array, int32 length, const T& val)
}
/// On DEVICE and HOST calls
template<
typename Type,
typename... properties>
INLINE_FUNCTION_HD
uint32 binarySearch(
template<typename Type, typename... properties>
INLINE_FUNCTION_HD uint32
binarySearch(
const ViewType1D<Type, properties...>& view,
uint32 start,
uint32 end,
const Type& val)
const Type& val
)
{
if (end <= start)
return -1;
if(end<=start)return -1;
if(auto res =
binarySearch_(view.data()+start,end-start,val); res!=-1) {
if (auto res = binarySearch_(view.data() + start, end - start, val);
res != -1)
{
return res + start;
}
else{
else
{
return res;
}
}
template<
typename Type,
typename... properties,
typename... dProperties>
void exclusiveScan(
template<typename Type, typename... properties, typename... dProperties>
void
exclusiveScan(
const ViewType1D<Type, properties...>& view,
uint32 start,
uint32 end,
ViewType1D<Type, dProperties...>& dView,
uint32 dStart )
uint32 dStart
)
{
static_assert
(
static_assert(
areAccessible<
typename ViewType1D<Type, properties...>::execution_space,
typename ViewType1D<Type, dProperties...>::memory_space>(),
@ -487,48 +449,43 @@ void exclusiveScan(
);
using ExecutionSpace = typename ViewType1D<Type, properties...>::execution_space;
using ExecutionSpace =
typename ViewType1D<Type, properties...>::execution_space;
uint32 numElems = end - start;
pFlow::algorithms::KOKKOS::exclusiveScan<Type, ExecutionSpace>(
view.data()+start,
dView.data()+dStart,
numElems);
view.data() + start, dView.data() + dStart, numElems
);
}
template<
typename Type,
typename... properties,
typename... dProperties>
void inclusiveScan(
template<typename Type, typename... properties, typename... dProperties>
void
inclusiveScan(
const ViewType1D<Type, properties...>& view,
uint32 start,
uint32 end,
ViewType1D<Type, dProperties...>& dView,
uint32 dStart)
uint32 dStart
)
{
using ExecutionSpace = typename ViewType1D<Type, properties...>::execution_space;
using ExecutionSpace =
typename ViewType1D<Type, properties...>::execution_space;
static_assert
(
static_assert(
areAccessible<
typename ViewType1D<Type, properties...>::execution_space,
typename ViewType1D<Type, dProperties...>::memory_space>(),
"In exclusiveScan, view and dView should have the same space"
);
uint32 numElems = end - start;
pFlow::algorithms::KOKKOS::inclusiveScan<Type, ExecutionSpace>(
view.data()+start,
dView.data()+dStart,
numElems);
view.data() + start, dView.data() + dStart, numElems
);
}
} // pFlow
#endif // Viewalgorithms
#endif // __ViewAlgorithms_hpp__

View File

@ -19,32 +19,32 @@ Licence:
-----------------------------------------------------------------------------*/
template<typename T, typename... properties>
void insertSetElementH
(
void
insertSetElementH(
ViewType1D<T, properties...>& view,
hostViewType1D<label>& selected,
T val
);
template<typename T, typename... properties>
void insertSetElementH
(
void
insertSetElementH(
ViewType1D<T, properties...>& view,
hostViewType1D<label>& selected,
hostViewType1D<T>& vals
);
template<typename T, typename... properties>
void insertSetElementD
(
void
insertSetElementD(
ViewType1D<T, properties...>& view,
deviceViewType1D<label>& selected,
T val
);
template<typename T, typename... properties>
void insertSetElementD
(
void
insertSetElementD(
ViewType1D<T, properties...>& view,
deviceViewType1D<label>& selected,
deviceViewType1D<T>& vals

View File

@ -21,9 +21,8 @@ Licence:
#ifndef __baseAlgorithms_hpp__
#define __baseAlgorithms_hpp__
#include "numericConstants.hpp"
#include "KokkosUtilities.hpp"
#include "numericConstants.hpp"
inline const size_t sizeToSerial__ = 64;
@ -57,19 +56,18 @@ size_t count(
return totalNum;
}*/
template<typename T, typename... properties>
INLINE_FUNCTION_H
T min( const ViewType1D<T, properties...>& view, size_t start, size_t end )
INLINE_FUNCTION_H T
min(const ViewType1D<T, properties...>& view, size_t start, size_t end)
{
T minValue = largestPositive<T>();
auto RP = Kokkos::RangePolicy<
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space>(start, end);
Kokkos::parallel_reduce("baseAlgorithms-min",
Kokkos::parallel_reduce(
"baseAlgorithms-min",
RP,
LAMBDA_HD(label i, T & valueToUpdate) {
valueToUpdate = min(view[i], valueToUpdate);
@ -80,17 +78,17 @@ T min( const ViewType1D<T, properties...>& view, size_t start, size_t end )
}
template<typename T, typename... properties>
INLINE_FUNCTION_H
T max( const ViewType1D<T, properties...>& view, size_t start, size_t end )
INLINE_FUNCTION_H T
max(const ViewType1D<T, properties...>& view, size_t start, size_t end)
{
T maxValue = largestNegative<T>();
auto RP = Kokkos::RangePolicy<
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space>(start, end);
Kokkos::parallel_reduce("baseAlgorithms-max",
Kokkos::parallel_reduce(
"baseAlgorithms-max",
RP,
LAMBDA_HD(label i, T & valueToUpdate) {
valueToUpdate = max(view[i], valueToUpdate);
@ -101,8 +99,8 @@ T max( const ViewType1D<T, properties...>& view, size_t start, size_t end )
}
template<typename T, typename... properties>
INLINE_FUNCTION_H
T min_serial(const ViewType1D<T, properties...>& view, size_t start, size_t end)
INLINE_FUNCTION_H T
min_serial(const ViewType1D<T, properties...>& view, size_t start, size_t end)
{
T minValue = largestPositive<T>();
for (label i = start; i < end; ++i)
@ -113,8 +111,8 @@ T min_serial(const ViewType1D<T, properties...>& view, size_t start, size_t end)
}
template<typename T, typename... properties>
INLINE_FUNCTION_H
T max_serial(const ViewType1D<T, properties...>& view, size_t start, size_t end)
INLINE_FUNCTION_H T
max_serial(const ViewType1D<T, properties...>& view, size_t start, size_t end)
{
T maxValue = largestNegative<T>();
for (label i = start; i < end; ++i)
@ -124,49 +122,46 @@ T max_serial(const ViewType1D<T, properties...>& view, size_t start, size_t end)
return maxValue;
}
template<typename UnaryFunction, typename T, typename... properties>
void apply_to_each(const ViewType1D<T, properties...>& view, size_t start, size_t end, UnaryFunction func)
void
apply_to_each(
const ViewType1D<T, properties...>& view,
size_t start,
size_t end,
UnaryFunction func
)
{
auto RP = Kokkos::RangePolicy<
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space>(start, end);
Kokkos::parallel_for("baseAlgorithms-for_each",
RP,
LAMBDA_HD(label i){
view[i] = func(i);
}
Kokkos::parallel_for(
"baseAlgorithms-for_each", RP, LAMBDA_HD(label i) { view[i] = func(i); }
);
}
template<typename T, typename... properties>
void insertSetElementH
(
void
insertSetElementH(
ViewType1D<T, properties...>& view,
hostViewType1D<label>& selected,
T val
)
{
for (auto i = 0; i < selected.size(); ++i)
{
view[selected[i]] = val;
}
}
template<typename T, typename... properties>
void insertSetElementH
(
void
insertSetElementH(
ViewType1D<T, properties...>& view,
hostViewType1D<label>& selected,
hostViewType1D<T>& vals
)
{
for (auto i = 0; i < selected.size(); ++i)
{
view[selected[i]] = static_cast<const T&>(vals[i]);
@ -174,8 +169,8 @@ void insertSetElementH
}
template<typename T, typename... properties>
void insertSetElementD
(
void
insertSetElementD(
ViewType1D<T, properties...>& view,
deviceViewType1D<label>& selected,
T val
@ -183,19 +178,20 @@ void insertSetElementD
{
auto RP = Kokkos::RangePolicy<
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space >(0, selected.size());
typename ViewType1D<T, properties...>::execution_space>(
0, selected.size()
);
Kokkos::parallel_for(
"baseAlgorithms-insertSetElementD",
RP,
LAMBDA_D(size_t i) {
view[selected[i]] = val; } );
LAMBDA_D(size_t i) { view[selected[i]] = val; }
);
}
template<typename T, typename... properties>
void insertSetElementD
(
void
insertSetElementD(
ViewType1D<T, properties...>& view,
deviceViewType1D<label>& selected,
deviceViewType1D<T>& vals
@ -203,21 +199,20 @@ void insertSetElementD
{
auto RP = Kokkos::RangePolicy<
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space >(0, selected.size());
typename ViewType1D<T, properties...>::execution_space>(
0, selected.size()
);
Kokkos::parallel_for(
"baseAlgorithms-insertSetElementD",
RP,
LAMBDA_D(size_t i) {
view[selected[i]] = vals[i]; } );
LAMBDA_D(size_t i) { view[selected[i]] = vals[i]; }
);
}
template<typename T, typename... properties>
void fill
(
void
fill(
ViewType3D<T, properties...>& view,
range range1,
range range2,
@ -231,5 +226,4 @@ void fill
}
#endif // __VectorSingleMath_hpp__

View File

@ -23,15 +23,13 @@ Licence:
#include "streams.hpp"
pFlow::Timer::Timer(const word& name, Timers* parrent)
:
name_(name),
: name_(name),
parrent_(parrent)
{
if (parrent_)
parrent_->addToList(this);
}
pFlow::Timer::~Timer()
{
if (parrent_)
@ -48,12 +46,10 @@ pFlow::int32 pFlow::Timer::level()const
return 0;
}
bool pFlow::Timer::write(iOstream& os, bool subTree) const
{
if(!timerActive() && !master())return true;
if (!timerActive() && !master())
return true;
int32 lvl = level();
for (int32 l = 1; l < lvl; l++)
@ -63,11 +59,9 @@ bool pFlow::Timer::write(iOstream& os, bool subTree)const
if (lvl > 0)
{
if (master())
os << "┣━━ ";
else
if(lvl==1)
else if (lvl == 1)
os << "┃└─ ";
else
os << " └─ ";
@ -80,19 +74,16 @@ bool pFlow::Timer::write(iOstream& os, bool subTree)const
else if (master())
os << yellowColor;
os << name_;
auto tt = accTimersTotal();
if (abs(tt) > smallValue)
{
os<<" execution time (s): total ("<<
tt<<")";
os << " execution time (s): total (" << tt << ")";
if (!master())
{
os<<", av. ("<<
averageTime()<<").";
os << ", av. (" << averageTime() << ").";
}
}

View File

@ -18,24 +18,19 @@ Licence:
-----------------------------------------------------------------------------*/
#ifndef __Timerr_hpp__
#define __Timerr_hpp__
#include <chrono>
#include "types.hpp"
namespace pFlow
{
// forward
class Timers;
class Timer
{
protected:
@ -54,7 +49,8 @@ protected:
/// last time duration
real lastTime_ = 0.0;
/// @brief Accumulative duration for multiple steps between start() and end()
/// @brief Accumulative duration for multiple steps between start() and
/// end()
real stepAccTime_ = 0.0;
/// name for the timer
@ -70,14 +66,12 @@ public:
Timer() = default;
explicit Timer(const word& name)
:
name_(name)
{}
: name_(name)
{
}
Timer(const word& name, Timers* parrent);
const word& name() const
{
return name_;
@ -92,7 +86,6 @@ public:
virtual int32 level() const;
virtual bool master() const
{
return false;
@ -107,8 +100,11 @@ public:
void pause()
{
auto end = timer::now();
stepAccTime_ += std::chrono::duration_cast
< std::chrono::duration<real> >(end - start_).count();
stepAccTime_ +=
std::chrono::duration_cast<std::chrono::duration<real> >(
end - start_
)
.count();
}
void resume()
@ -125,33 +121,27 @@ public:
accTime_ += lastTime_;
}
inline
bool timerActive()const
inline bool timerActive() const
{
return numIteration_ != 0;
}
inline
real lastTime()const
inline real lastTime() const
{
return lastTime_;
}
inline
real totalTime()const
inline real totalTime() const
{
return accTime_;
}
inline
real averageTime()const
inline real averageTime() const
{
return accTime_ / max(numIteration_, 1);
}
virtual
real accTimersTotal()const
virtual real accTimersTotal() const
{
return totalTime();
}
@ -166,7 +156,6 @@ public:
}
};
inline iOstream& operator<<(iOstream& os, const Timer& t)
{
t.write(os, false);
@ -178,7 +167,6 @@ inline iIstream& operator>>(iIstream& is, Timer& t)
return is;
}
}
} // namespace pFlow
#endif //__Timer_hpp__

View File

@ -68,7 +68,7 @@ pFlow::uniquePtr<pFlow::boundaryField<T, MemorySpace>>
printKeys
(
fatalError << "Ctor Selector "<< bType << "for type "<<
Yellow_Text(getTypeName<T>()) << " dose not exist.\n"
Yellow_Text(getTypeName<T>()) << " does not exist.\n"
<<"Avaiable ones are: \n\n"
,
boundaryBasevCtorSelector_

View File

@ -17,20 +17,24 @@ Licence:
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __createBoundaryFields_hpp__
#define __createBoundaryFields_hpp__
#include "boundaryField.hpp"
#include "exitBoundaryField.hpp"
#include "boundaryField/boundaryField.hpp"
#include "exitBoundaryField/exitBoundaryField.hpp"
#include "periodicBoundaryField/periodicBoundaryField.hpp"
#include "reflectiveBoundaryField/reflectiveBoundaryField.hpp"
#define createDerivedBoundary(DataType, MemorySpaceType) \
template class pFlow::exitBoundaryField<DataType, MemorySpaceType>; \
template class pFlow::periodicBoundaryField<DataType, MemorySpaceType>; \
template class pFlow::reflectiveBoundaryField<DataType, MemorySpaceType>;
#define createBaseBoundary(DataType, MemorySpaceType) \
template class pFlow::boundaryField<DataType, MemorySpaceType>;
#define createBoundary(DataType, MemorySpaceType, BoundaryType) \
template class pFlow::BoundaryType##BoundaryField<DataType, MemorySpaceType>;
#define createBoundaryFields(DataType, MemorySpaceType) \
createBaseBoundary(DataType, MemorySpaceType); \
createDerivedBoundary(DataType, MemorySpaceType);
#endif //__createBoundaryFields_hpp__

View File

@ -0,0 +1,31 @@
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
template<class T, class MemorySpace>
pFlow::reflectiveBoundaryField<T, MemorySpace>::reflectiveBoundaryField
(
const boundaryBase& boundary,
const pointStructure& pStruct,
InternalFieldType& internal
)
:
BoundaryFieldType(boundary, pStruct, internal)
{
//this->addEvent(message::BNDR_DELETE);
}

View File

@ -0,0 +1,90 @@
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __reflectiveBoundaryField_hpp__
#define __reflectiveBoundaryField_hpp__
#include "boundaryField.hpp"
namespace pFlow
{
template< class T, class MemorySpace = void>
class reflectiveBoundaryField
:
public boundaryField<T, MemorySpace>
{
public:
using ReflectiveBoundaryFieldType = reflectiveBoundaryField<T, MemorySpace>;
using BoundaryFieldType = boundaryField<T, MemorySpace>;
using InternalFieldType = typename BoundaryFieldType::InternalFieldType;
using memory_space = typename BoundaryFieldType::memory_space;
using execution_space = typename BoundaryFieldType::execution_space;
public:
TypeInfoTemplate211("boundaryField","reflective", T, memory_space::name());
reflectiveBoundaryField(
const boundaryBase& boundary,
const pointStructure& pStruct,
InternalFieldType& internal);
add_vCtor
(
BoundaryFieldType,
ReflectiveBoundaryFieldType,
boundaryBase
);
bool hearChanges
(
real t,
real dt,
uint32 iter,
const message& msg,
const anyList& varList
) override
{
BoundaryFieldType::hearChanges(t,dt,iter, msg,varList);
if(msg.equivalentTo(message::BNDR_DELETE))
{
// do nothing;
}
return true;
}
};
}
#include "reflectiveBoundaryField.cpp"
#endif

View File

@ -18,76 +18,37 @@ Licence:
-----------------------------------------------------------------------------*/
#include "pointFields.hpp"
#include "createBoundaryFields.hpp"
#include "periodicBoundaryField.hpp"
#define createAllBoundary(DataType, MemorySpaceType) \
template class pFlow::exitBoundaryField<DataType, MemorySpaceType>; \
template class pFlow::periodicBoundaryField<DataType, MemorySpaceType>;
#define createPointFields(DataType) \
template class pFlow::pointField<DataType, pFlow::HostSpace>; \
createBoundaryFields(DataType, pFlow::HostSpace); \
\
template class pFlow::pointField<DataType>; \
createBoundaryFields(DataType, void);
// uint8
template class pFlow::pointField<pFlow::uint8, pFlow::HostSpace>;
createBaseBoundary(pFlow::uint8, pFlow::HostSpace);
createAllBoundary(pFlow::uint8, pFlow::HostSpace);
template class pFlow::pointField<pFlow::uint8>;
createBaseBoundary(pFlow::uint8, void);
createAllBoundary(pFlow::uint8, void);
createPointFields(pFlow::uint8);
/// uint32
template class pFlow::pointField<pFlow::uint32, pFlow::HostSpace>;
createBaseBoundary(pFlow::uint32, pFlow::HostSpace);
createAllBoundary(pFlow::uint32, pFlow::HostSpace);
template class pFlow::pointField<pFlow::uint32>;
createBaseBoundary(pFlow::uint32, void);
createAllBoundary(pFlow::uint32, void);
createPointFields(pFlow::uint32);
/// uint64
template class pFlow::pointField<pFlow::uint64, pFlow::HostSpace>;
createBaseBoundary(pFlow::uint64, pFlow::HostSpace);
createAllBoundary(pFlow::uint64, pFlow::HostSpace);
template class pFlow::pointField<pFlow::uint64>;
createBaseBoundary(pFlow::uint64, void);
createAllBoundary(pFlow::uint64, void);
createPointFields(pFlow::uint64);
/// real
template class pFlow::pointField<pFlow::real, pFlow::HostSpace>;
createBaseBoundary(pFlow::real, pFlow::HostSpace);
createAllBoundary(pFlow::real, pFlow::HostSpace);
template class pFlow::pointField<pFlow::real>;
createBaseBoundary(pFlow::real, void);
createAllBoundary(pFlow::real, void);
createPointFields(pFlow::real);
/// realx3
template class pFlow::pointField<pFlow::realx3, pFlow::HostSpace>;
createBaseBoundary(pFlow::realx3, pFlow::HostSpace);
createAllBoundary(pFlow::realx3, pFlow::HostSpace);
template class pFlow::pointField<pFlow::realx3>;
createBaseBoundary(pFlow::realx3, void);
createAllBoundary(pFlow::realx3, void);
createPointFields(pFlow::realx3);
/// realx4
template class pFlow::pointField<pFlow::realx4, pFlow::HostSpace>;
createBaseBoundary(pFlow::realx4, pFlow::HostSpace);
createAllBoundary(pFlow::realx4, pFlow::HostSpace);
createPointFields(pFlow::realx4);
template class pFlow::pointField<pFlow::realx4>;
createBaseBoundary(pFlow::realx4, void);
createAllBoundary(pFlow::realx4, void);
/// word
/// word, only on host
template class pFlow::pointField<pFlow::word, pFlow::HostSpace>;
createBaseBoundary(pFlow::word, pFlow::HostSpace);
createAllBoundary(pFlow::word, pFlow::HostSpace);
createBoundaryFields(pFlow::word, pFlow::HostSpace);

View File

@ -21,86 +21,102 @@ Licence:
#include <iostream>
#include <stdlib.h>
#include <Kokkos_Core.hpp>
#include "error.hpp"
#include "processors.hpp"
#include "streams.hpp"
// static pFlow::Ostream& errorStream = pFlow::errReport;
static pFlow::Ostream& errorStream = pFlow::pOutput;
pFlow::iOstream& fatalErrorMessage(const char* fileName, int linNumber )
pFlow::iOstream&
fatalErrorMessage(const char* fileName, int linNumber)
{
errorStream<<"\n>>> Fatal error in phasicFlow\n" <<
"Error occured in source file "<< Red_Text(fileName) <<
" at line "<<Red_Text(linNumber)<<'\n';
return errorStream;
}
pFlow::iOstream& fatalErrorInMessage(const char* fnName, const char* fileName, int linNumber )
{
errorStream<<"\n>>> Fatal error in phasicFlow\n" <<
" Error is issued in function " << Red_Text(fnName)<<
", located in file "<< Red_Text(fileName) <<
" at line "<< Red_Text(linNumber) << '\n';
errorStream << "\n>>> Fatal error in phasicFlow\n"
<< "Error occured in source file " << Red_Text(fileName)
<< " at line " << Red_Text(linNumber) << '\n';
return errorStream;
}
pFlow::iOstream& notImplementedErrorMessage(const char*fnName, const char* fileName, int lineNumber)
pFlow::iOstream&
fatalErrorInMessage(const char* fnName, const char* fileName, int linNumber)
{
errorStream << "\n>>> Fatal error in phasicFlow\n"
<< " Error is issued in function " << Red_Text(fnName)
<< ", located in file " << Red_Text(fileName) << " at line "
<< Red_Text(linNumber) << '\n';
return errorStream;
}
pFlow::iOstream&
notImplementedErrorMessage(
const char* fnName,
const char* fileName,
int lineNumber
)
{
errorStream << "\n>>> Fatal error in phasicFlow\n";
errorStream<<" Function "<< Red_Text(fnName) << " has not been implemented yet!\n" <<
" File "<< Yellow_Text(fileName) <<
" at line "<< Yellow_Text(lineNumber) <<'\n';
errorStream << " Function " << Red_Text(fnName)
<< " has not been implemented yet!\n"
<< " File " << Yellow_Text(fileName) << " at line "
<< Yellow_Text(lineNumber) << '\n';
return errorStream;
}
pFlow::iOstream& ioErrorMessage(const char* fileName, int fileLineNumber, const char* fnName, const char* fName, int lNumber)
pFlow::iOstream&
ioErrorMessage(
const char* fileName,
int fileLineNumber,
const char* fnName,
const char* fName,
int lNumber
)
{
errorStream<<"\n>>> Fatal IO file error\n"<<
" IO error at number "<<Red_Text(fileLineNumber)<<
" of file " << Red_Text(fileName)<<'\n';
errorStream<<" IO operation is peformed from function "<<Red_Text(fnName) <<
" in file "<< Red_Text(fName)<< " at line "<< Red_Text(lNumber) <<'\n';
errorStream << "\n>>> Fatal IO file error\n"
<< " IO error at number " << Red_Text(fileLineNumber)
<< " of file " << Red_Text(fileName) << '\n';
errorStream << " IO operation is peformed from function "
<< Red_Text(fnName) << " in file " << Red_Text(fName)
<< " at line " << Red_Text(lNumber) << '\n';
return errorStream;
}
pFlow::iOstream& ioErrorMessage(const pFlow::word& fileName, int fileLineNumber, const char* fnName, const char* fName, int lNumber)
pFlow::iOstream&
ioErrorMessage(
const pFlow::word& fileName,
int fileLineNumber,
const char* fnName,
const char* fName,
int lNumber
)
{
return ioErrorMessage( fileName.c_str(), fileLineNumber, fnName, fName, lNumber);
return ioErrorMessage(
fileName.c_str(), fileLineNumber, fnName, fName, lNumber
);
}
pFlow::iOstream& warningMessage(const char* fnName, const char* fileName, int linNumber )
pFlow::iOstream&
warningMessage(const char* fnName, const char* fileName, int linNumber)
{
errorStream<<"\n>>> Warning in phasicFlow\n"<<
" Warning is issued in function " << Yellow_Text(fnName)<<
" in source file "<< Yellow_Text(fileName) <<
" at line "<< Yellow_Text(linNumber) <<'\n';
errorStream << "\n>>> Warning in phasicFlow\n"
<< " Warning is issued in function " << Yellow_Text(fnName)
<< " in source file " << Yellow_Text(fileName) << " at line "
<< Yellow_Text(linNumber) << '\n';
return errorStream;
}
pFlow::iOstream& reportAndExit(int errorCode)
pFlow::iOstream&
reportAndExit(int errorCode)
{
errorStream << "\n>>> phasicFlow is exiting . . ." << pFlow::endl;
fatalExitPhasicFlow(errorCode);
return errorStream;
}
int fatalExitPhasicFlow(int errorCode)
int
fatalExitPhasicFlow(int errorCode)
{
// Kokkos should be finalized first
Kokkos::finalize();

View File

@ -21,34 +21,53 @@ Licence:
#ifndef __error_hpp__
#define __error_hpp__
#include "builtinTypes.hpp"
//- Forward decleartions
namespace pFlow
{
class iOstream;
}
//- Decleartions
/// Take actions to fatal exit phasicFlow
int fatalExitPhasicFlow(int errorCode = EXIT_FAILURE);
pFlow::iOstream& fatalErrorMessage(const char* fileName, int linNumber );
pFlow::iOstream& fatalErrorInMessage(const char* fnName, const char* fileName, int linNumber );
pFlow::iOstream& notImplementedErrorMessage(const char*fnName, const char* fileName, int lineNumber);
pFlow::iOstream& ioErrorMessage(const pFlow::word& fileName, int fileLineNumber, const char* fnName, const char* fName, int lNumber);
pFlow::iOstream& ioErrorMessage(const char* fileName, int fileLineNumber, const char* fnName, const char* fName, int lNumber);
pFlow::iOstream& warningMessage(const char* fnName, const char* fileName, int linNumber );
pFlow::iOstream& reportAndExit(int errorCode = EXIT_FAILURE);
int
fatalExitPhasicFlow(int errorCode = EXIT_FAILURE);
pFlow::iOstream&
fatalErrorMessage(const char* fileName, int linNumber);
pFlow::iOstream&
fatalErrorInMessage(const char* fnName, const char* fileName, int linNumber);
pFlow::iOstream&
notImplementedErrorMessage(
const char* fnName,
const char* fileName,
int lineNumber
);
pFlow::iOstream&
ioErrorMessage(
const pFlow::word& fileName,
int fileLineNumber,
const char* fnName,
const char* fName,
int lNumber
);
pFlow::iOstream&
ioErrorMessage(
const char* fileName,
int fileLineNumber,
const char* fnName,
const char* fName,
int lNumber
);
pFlow::iOstream&
warningMessage(const char* fnName, const char* fileName, int linNumber);
pFlow::iOstream&
reportAndExit(int errorCode = EXIT_FAILURE);
/// Report a fatal error and exit the applicaiton
#define fatalError \
fatalErrorMessage(__FILE__, __LINE__)
#define fatalError fatalErrorMessage(__FILE__, __LINE__)
/// Report a fatal error and supplied function name and exit the application
#define fatalErrorIn(functionName) \
@ -76,7 +95,6 @@ pFlow::iOstream& reportAndExit(int errorCode = EXIT_FAILURE);
#define warningInFunction warningIn(FUNCTION_NAME)
/// Fatal exit
#define fatalExit \
reportAndExit()
#define fatalExit reportAndExit()
#endif

View File

@ -21,7 +21,6 @@ Licence:
#ifndef __vocabs_hpp__
#define __vocabs_hpp__
namespace pFlow
{
@ -49,12 +48,9 @@ const inline char* propertyFile__ = "interaction";
const inline char* interactionFile__ = "interaction";
const inline char* postprocessFile__ = "postprocessDict";
const inline char* uniform__ = "uniform";
const inline char* nonUniform__ = "nonUniform";
}
#endif // __vocabs_hpp__

View File

@ -18,13 +18,12 @@ Licence:
-----------------------------------------------------------------------------*/
#include "Time.hpp"
#include "dictionary.hpp"
#include "vocabs.hpp"
bool pFlow::Time::readDictionary(const dictionary& dict)
bool
pFlow::Time::readDictionary(const dictionary& dict)
{
auto wF = toUpper(dict.getValOrSet<word>("writeFormat", "ASCII"));
@ -34,30 +33,19 @@ bool pFlow::Time::readDictionary(const dictionary& dict)
outFormatBinary_ = true;
else
{
fatalErrorInFunction<<
"Invalid writeFormat in file "<< dict.name()<<endl;
fatalErrorInFunction << "Invalid writeFormat in file " << dict.name()
<< endl;
return false;
}
return true;
}
pFlow::Time::Time
(
repository* owner,
const dictionary& setiingsDict
)
:
repository("Time", "", owner),
pFlow::Time::Time(repository* owner, const dictionary& setiingsDict)
: repository("Time", "", owner),
timeControl(setiingsDict),
geometry_
(
geometryRepository_,
geometryFolder__,
this
)
geometry_(geometryRepository_, geometryFolder__, this)
{
if (!readDictionary(setiingsDict))
{
fatalExit;
@ -70,21 +58,11 @@ pFlow::Time::Time(
real startTime,
real endTime,
real saveInterval,
word startTimeName)
:
repository("Time", "", owner),
timeControl(
setiingsDict,
startTime,
endTime,
saveInterval,
startTimeName),
geometry_
(
geometryRepository_,
geometryFolder__,
this
word startTimeName
)
: repository("Time", "", owner),
timeControl(setiingsDict, startTime, endTime, saveInterval, startTimeName),
geometry_(geometryRepository_, geometryFolder__, this)
{
if (!readDictionary(setiingsDict))
{
@ -92,24 +70,25 @@ pFlow::Time::Time(
}
}
pFlow::fileSystem pFlow::Time::localPath()const
pFlow::fileSystem
pFlow::Time::localPath() const
{
return fileSystem(timeName());
}
pFlow::fileSystem pFlow::Time::integrationFolder() const
pFlow::fileSystem
pFlow::Time::integrationFolder() const
{
return integrationFolder__;
}
bool pFlow::Time::write
(
bool verbose
) const
bool
pFlow::Time::write(bool verbose) const
{
if (outputToFile())
{
REPORT(0)<<"\nWriting to file at time: "<< Cyan_Text(timeName())<<END_REPORT;
REPORT(0) << "\nWriting to file at time: " << Cyan_Text(timeName())
<< END_REPORT;
return repository::write(verbose);
}
return true;

View File

@ -18,18 +18,15 @@ Licence:
-----------------------------------------------------------------------------*/
#ifndef __Time_hpp__
#define __Time_hpp__
#include "types.hpp"
#include "error.hpp"
#include "types.hpp"
#include "timeControl.hpp"
#include "repository.hpp"
#include "fileSystem.hpp"
#include "repository.hpp"
#include "timeControl.hpp"
namespace pFlow
{
@ -37,12 +34,10 @@ namespace pFlow
class dictionary;
class Time
:
public repository,
public timeControl
: public repository
, public timeControl
{
protected:
private:
bool outFormatBinary_ = false;
@ -62,13 +57,12 @@ public:
real startTime,
real endTime,
real saveInterval,
word startTimeName);
word startTimeName
);
//// - Methods
fileSystem localPath() const override;
// - geometry repository
const repository& geometry() const
{
@ -91,9 +85,8 @@ public:
// override the base write to manage write operation
// based on the valid write time intervals
virtual bool write(bool verbose = false) const;
};
} // pFlow
} // namespace pFlow
#endif // __Time_hpp__

View File

@ -75,3 +75,90 @@ bool pFlow::baseTimeControl::timeEvent(uint32 iter, real t, real dt) const
}
return false;
}
bool
pFlow::baseTimeControl::isInRange(uint32 iter, real t, real dt) const
{
if(isTimeStep_)
{
return iRange_.isInRange(iter);
}
else
{
return rRange_.isInRange(t);
}
}
pFlow::real
pFlow::baseTimeControl::startTime() const
{
if(!isTimeStep_)
{
return rRange_.begin();
}
fatalErrorInFunction<<"timeControl is not simulationTime or runTime"<<endl;
fatalExit;
return 0;
}
pFlow::real
pFlow::baseTimeControl::endTime() const
{
if(!isTimeStep_)
{
return rRange_.end();
}
fatalErrorInFunction<<"timeControl is not simulationTime or runTime"<<endl;
fatalExit;
return 0;
}
pFlow::real
pFlow::baseTimeControl::rInterval() const
{
if(!isTimeStep_)
{
return rRange_.stride();
}
fatalErrorInFunction<<"timeControl is not simulationTime or runTime"<<endl;
fatalExit;
return 0;
}
pFlow::int32
pFlow::baseTimeControl::startIter() const
{
if(isTimeStep_)
{
return iRange_.begin();
}
fatalErrorInFunction<<"timeControl is not timeStep"<<endl;
fatalExit;
return 0;
}
pFlow::int32
pFlow::baseTimeControl::endIter() const
{
if(isTimeStep_)
{
return iRange_.end();
}
fatalErrorInFunction<<"timeControl is not timeStep"<<endl;
fatalExit;
return 0;
}
pFlow::int32
pFlow::baseTimeControl::iInterval() const
{
if(isTimeStep_)
{
return iRange_.stride();
}
fatalErrorInFunction<<"timeControl is not timeStep"<<endl;
fatalExit;
return 0;
}

View File

@ -45,9 +45,28 @@ public:
const word& intervalPrefix = "",
real defStartTime = 0.0);
inline
bool isTimeStep()const
{
return isTimeStep_;
}
bool timeEvent(uint32 iter, real t, real dt)const;
bool isInRange(uint32 iter, real t, real dt)const;
real startTime()const;
real endTime()const;
real rInterval()const;
int32 startIter()const;
int32 endIter()const;
int32 iInterval()const;
};
}

View File

@ -33,7 +33,7 @@ namespace pFlow
class repository
{
protected:
private:
// - repository name
word name_;
@ -53,9 +53,10 @@ protected:
template <typename Type1>
word reportTypeError (IOobject& object);
word reportTypeError (IOobject& object)const;
template <typename Type>
static
bool checkForObjectType(IOobject& object);
public:
@ -167,10 +168,14 @@ public:
}
}
// - return a ref to the underlaying data in the object
/// return a ref to the underlaying data in the object
template<typename T>
T& lookupObject(const word& name);
/// return a const ref to the underlaying data in the object
template<typename T>
const T& lookupObject(const word& name)const;
// - search the name and return a ref to repository
repository& lookupRepository(const word& name);

View File

@ -20,7 +20,7 @@ Licence:
template <typename Type1>
pFlow::word pFlow::repository::reportTypeError(IOobject& object)
pFlow::word pFlow::repository::reportTypeError(IOobject& object)const
{
word err;
err = "Object " + object.name() + " with type " + Type1::TYPENAME() +
@ -65,3 +65,32 @@ T& pFlow::repository::lookupObject(const word& name)
return static_cast<T&>(*iter->second);
}
}
template<typename T>
const T& pFlow::repository::lookupObject(const word& name)const
{
if( auto [iter, success] = objects_.findIf(name); success )
{
if( checkType<T>(iter->second) )
{
return static_cast<const T&>(*iter->second);
}
else
{
fatalErrorInFunction <<
reportTypeError<T>(*iter->second)<<endl;
fatalExit;
return static_cast<T&>(*iter->second);
}
}
else
{
fatalErrorInFunction <<
"Object with name " << name << " is not found in repository " << this->name()<<endl <<
"list of avaiable objest is \n" << objectNames();
fatalExit;
return static_cast<T&>(*iter->second);
}
}

View File

@ -18,18 +18,14 @@ Licence:
-----------------------------------------------------------------------------*/
#include "types.hpp"
#include "iOstream.hpp"
#include "error.hpp"
#include "systemControl.hpp"
#include "vocabs.hpp"
#include "Lists.hpp"
#include "error.hpp"
#include "iOstream.hpp"
#include "types.hpp"
#include "vocabs.hpp"
bool pFlow::systemControl::readIncludeExclue
(
const dictionary& dict
)
bool pFlow::systemControl::readIncludeExclue(const dictionary& dict)
{
if (dict.containsDataEntry("includeObjects"))
{
@ -51,12 +47,8 @@ bool pFlow::systemControl::readIncludeExclue
return true;
}
pFlow::word pFlow::systemControl::getRunName
(
const fileSystem& path
)
pFlow::word pFlow::systemControl::getRunName(const fileSystem& path)
{
// gets the canonical form of path
word wPath = path.canonical().wordPath() + "/";
@ -65,8 +57,7 @@ pFlow::word pFlow::systemControl::getRunName
if (first == word::npos)
{
fatalErrorInFunction <<
"path is empty \n";
fatalErrorInFunction << "path is empty \n";
fatalExit;
}
@ -79,15 +70,10 @@ pFlow::word pFlow::systemControl::getRunName
word rName = wPath.substr(last + 1);
return rName;
}
pFlow::word pFlow::systemControl::getTopFolder
(
const fileSystem& path
)
pFlow::word pFlow::systemControl::getTopFolder(const fileSystem& path)
{
// gets the canonical form of path
word wPath = path.canonical().wordPath();
@ -96,8 +82,7 @@ pFlow::word pFlow::systemControl::getTopFolder
if (first == word::npos)
{
fatalErrorInFunction <<
"path is empty \n";
fatalErrorInFunction << "path is empty \n";
fatalExit;
}
@ -110,77 +95,39 @@ pFlow::word pFlow::systemControl::getTopFolder
word tFolder = wPath.substr(0, last);
return tFolder;
}
pFlow::systemControl::systemControl
(
const fileSystem path
)
:
repository
(
pFlow::systemControl::systemControl(const fileSystem path)
: repository(
"systemControl",
path, // local path
nullptr // no owner
),
runName_
(
getRunName(path)
),
topLevelFolder_
(
getTopFolder(path)
),
settingsDict_
(
makeUnique<fileDictionary>
(
objectFile
(
runName_(getRunName(path)),
topLevelFolder_(getTopFolder(path)),
settingsDict_(makeUnique<fileDictionary>(
objectFile(
settingsFile__,
settingsFolder__,
objectFile::READ_ALWAYS,
objectFile::WRITE_NEVER
),
this
)
)),
Time_(this, settingsDict_()),
settings_(
makeUnique<repository>(settingsRepository__, settingsFolder__, this)
),
Time_
(
this,
settingsDict_()
),
settings_
(
makeUnique<repository>
(
settingsRepository__,
settingsFolder__,
this
)
),
caseSetup_
(
makeUnique<repository>
(
caseSetupRepository__,
caseSetupFolder__,
this
)
caseSetup_(
makeUnique<repository>(caseSetupRepository__, caseSetupFolder__, this)
),
libs_(settingsDict_()),
outFilePrecision_
(
outFilePrecision_(
settingsDict_().getValOrSet("outFilePrecision", static_cast<uint64>(6))
),
timers_(runName_),
timersReport_
(
settingsDict_().getValOrSet("timersReport", Logical("Yes"))
),
timersReport_(settingsDict_().getValOrSet("timersReport", Logical("Yes"))),
writeToFileTimer_("Write to file", &timers_)
{
readIncludeExclue(settingsDict_());
@ -191,38 +138,25 @@ pFlow::systemControl::systemControl(
const real endTime,
const real saveInterval,
const word startTimeName,
const fileSystem path)
:
repository
(
const fileSystem path
)
: repository(
"systemControl",
path, // local path
nullptr // no owner
),
runName_
(
getRunName(path)
),
topLevelFolder_
(
getTopFolder(path)
),
settingsDict_
(
makeUnique<fileDictionary>
(
objectFile
(
runName_(getRunName(path)),
topLevelFolder_(getTopFolder(path)),
settingsDict_(makeUnique<fileDictionary>(
objectFile(
settingsFile__,
settingsFolder__,
objectFile::READ_ALWAYS,
objectFile::WRITE_NEVER
),
this
)
),
Time_
(
)),
Time_(
this,
settingsDict_(),
startTime,
@ -230,40 +164,23 @@ pFlow::systemControl::systemControl(
saveInterval,
startTimeName
),
settings_
(
makeUnique<repository>
(
settingsRepository__,
settingsFolder__,
this
)
settings_(
makeUnique<repository>(settingsRepository__, settingsFolder__, this)
),
caseSetup_
(
makeUnique<repository>
(
caseSetupRepository__,
caseSetupFolder__,
this
)
caseSetup_(
makeUnique<repository>(caseSetupRepository__, caseSetupFolder__, this)
),
libs_(settingsDict_()),
externalTimeControl_(true),
timers_(runName_),
timersReport_
(
settingsDict_->getValOrSet("timersReport", Logical("Yes"))
),
timersReport_(settingsDict_->getValOrSet("timersReport", Logical("Yes"))),
writeToFileTimer_("Write to file", &timers_)
{
readIncludeExclue(settingsDict_());
}
bool pFlow::systemControl::operator++(int)
{
auto toContinue = time()++;
if (toContinue)
@ -280,12 +197,10 @@ bool pFlow::systemControl::operator ++(int)
}
writeToFileTimer_.end();
if( time().timersReportTime() &&
timersReport() )
if (time().timersReportTime() && timersReport())
{
timers_.write(output, true);
}
}
else if (time().finalTime())
{
@ -302,5 +217,3 @@ bool pFlow::systemControl::operator ++(int)
return toContinue;
}

View File

@ -24,6 +24,7 @@ Licence:
#include "internalPoints.hpp"
#include "anyList.hpp"
#include "Time.hpp"
#include "pointStructure.hpp"
#include "boundaryBaseKernels.hpp"
void pFlow::boundaryBase::setSize(uint32 newSize)
@ -114,9 +115,9 @@ bool pFlow::boundaryBase::removeIndices
message msgBndry = message::BNDR_RESET;
uint32 iter = internal_.time().currentIter();
real t = internal_.time().currentTime();
real dt = internal_.time().dt();
uint32 iter = time().currentIter();
real t = time().currentTime();
real dt = time().dt();
if( !this->notify(iter, t, dt, msgBndry, aList) )
{
@ -197,6 +198,16 @@ pFlow::boundaryBase::boundaryBase
unSyncLists();
}
const pFlow::pointStructure &pFlow::boundaryBase::pStruct() const
{
return boundaries_.pStruct();
}
const pFlow::Time &pFlow::boundaryBase::time() const
{
return boundaries_.pStruct().time();
}
pFlow::boundaryBase &pFlow::boundaryBase::mirrorBoundary()
{
return boundaries_[mirrorBoundaryIndex()];
@ -256,7 +267,7 @@ pFlow::uniquePtr<pFlow::boundaryBase> pFlow::boundaryBase::create
{
printKeys
(
fatalError << "Ctor Selector "<< bType << " dose not exist. \n"
fatalError << "Ctor Selector "<< bType << " does not exist. \n"
<<"Avaiable ones are: \n\n"
,
dictionaryvCtorSelector_

View File

@ -37,6 +37,8 @@ namespace pFlow
class internalPoints;
class dictionary;
class boundaryList;
class pointStructure;
class Time;
class boundaryBase
:
@ -217,6 +219,10 @@ public:
return internal_;
}
const pointStructure& pStruct()const;
const Time& time()const;
inline
const auto& indexList()const
{

View File

@ -0,0 +1,149 @@
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#include "boundaryReflective.hpp"
#include "pointFields.hpp"
#include "dictionary.hpp"
#include "Time.hpp"
pFlow::boundaryReflective::boundaryReflective
(
const dictionary &dict,
const plane &bplane,
internalPoints &internal,
boundaryList &bndrs,
uint32 thisIndex
)
:
boundaryBase
(
dict,
bplane,
internal,
bndrs,
thisIndex
)
{
restitution_ = dict.getValOrSet("restitution", restitution_);
velocityName_ = dict.getValOrSet("velocityName",velocityName_);
diameterName_ = dict.getValOrSet("diameterName", diameterName_);
}
bool pFlow::boundaryReflective::beforeIteration(
uint32 iterNum,
real t,
real dt)
{
return true;
}
bool pFlow::boundaryReflective::iterate
(
uint32 iterNum,
real t,
real dt
)
{
return true;
}
bool pFlow::boundaryReflective::afterIteration
(
uint32 iterNum,
real t,
real dt
)
{
if(empty())return true;
uint32 s = size();
uint32Vector_D inContactFlags("inContactFlags",s+1, s+1, RESERVE());
inContactFlags.fill(0u);
auto inContactFlagsD = inContactFlags.deviceViewAll();
auto points = thisPoints();
auto p = boundaryPlane().infPlane();
const auto &diam = time().lookupObject<realPointField_D>(diameterName_);
auto diams = diam.BoundaryField(thisBoundaryIndex()).thisField();
uint32 numInContact = 0;
Kokkos::parallel_reduce
(
"pFlow::boundaryReflective::afterIteration",
deviceRPolicyStatic(0u,s),
LAMBDA_HD(uint32 i, uint32& nContactToUpdate)
{
if(p.inPositiveDistance(points(i), 0.5*diams(i)))
{
inContactFlagsD(i)=1;
nContactToUpdate++;
}
},
numInContact
);
// no particle in contact
if(numInContact == 0 )
{
return true;
}
uint32Vector_D inContactList("inContactList", numInContact);
const auto& inContactListD = inContactList.deviceViewAll();
exclusiveScan(inContactFlagsD, 0u, s+1, inContactFlagsD, 0u);
Kokkos::parallel_for
(
"pFlow::boundaryReflective::afterIteration",
deviceRPolicyStatic(0, s),
LAMBDA_HD(uint32 i)
{
if(inContactFlagsD(i)!= inContactFlagsD(i+1))
inContactListD(inContactFlagsD(i)) = points.index(i);
}
);
Kokkos::fence();
const auto& velocity = time().lookupObject<realx3PointField_D>(velocityName_);
const auto& velocityD = velocity.deviceViewAll();
Kokkos::parallel_for(
"pFlow::boundaryReflective::velocityChange",
deviceRPolicyStatic(0,numInContact),
LAMBDA_HD(uint32 i)
{
auto& vel = velocityD(inContactListD(i));
real vn = dot(p.normal(), vel);
if(vn < 0)
{
realx3 vt = vel - vn*p.normal();
vel = restitution_*(vt - vn*p.normal());
}
}
);
Kokkos::fence();
// TODO: notify integration for changes in the velocity
return true;
}

View File

@ -0,0 +1,73 @@
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __boundaryReflective_hpp__
#define __boundaryReflective_hpp__
#include "boundaryBase.hpp"
namespace pFlow
{
class boundaryReflective
:
public boundaryBase
{
private:
real restitution_ = 0.95;
word velocityName_{"velocity"};
word diameterName_{"diameter"};
public:
TypeInfo("boundary<reflective>");
boundaryReflective(
const dictionary &dict,
const plane &bplane,
internalPoints &internal,
boundaryList &bndrs,
uint32 thisIndex);
~boundaryReflective()override = default;
add_vCtor
(
boundaryBase,
boundaryReflective,
dictionary
);
bool beforeIteration(uint32 iterNum, real t, real dt) override;
bool iterate(uint32 iterNum, real t, real dt) override;
bool afterIteration(uint32 iterNum, real t, real dt) override;
};
}
#endif

View File

@ -18,23 +18,23 @@ Licence:
-----------------------------------------------------------------------------*/
#ifndef __typeInfo_hpp__
#define __typeInfo_hpp__
#include <typeinfo>
#include <cxxabi.h>
#include <typeinfo>
#include "bTypes.hpp"
#define has_static_member(name) \
template <typename, typename> \
struct has_static_member_##name; \
\
template <typename testType, typename Ret, typename... Args> \
struct has_static_member_##name<testType, Ret(Args...)> { \
template<typename U, U> struct Check; \
struct has_static_member_##name<testType, Ret(Args...)> \
{ \
template <typename U, U> \
struct Check; \
\
template <typename U> \
static std::true_type Test(Check<Ret (*)(Args...), &U::name> *); \
@ -43,7 +43,6 @@ Licence:
static const bool value = decltype(Test<testType>(0))::value; \
};
namespace pFlow
{
//
@ -52,8 +51,7 @@ namespace pFlow
{
has_static_member(TYPENAME);
static constexpr
bool hasMember()
static constexpr bool hasMember()
{
return has_static_member_TYPENAME<T, word(void)>::value;
}
@ -71,38 +69,61 @@ namespace pFlow
}
template <>
inline word basicTypeName<word>(){ return "word"; }
inline word basicTypeName<word>()
{
return "word";
}
template <>
inline word basicTypeName<int64>(){ return "int64"; }
inline word basicTypeName<int64>()
{
return "int64";
}
template <>
inline word basicTypeName<int32>(){ return "int32"; }
inline word basicTypeName<int32>()
{
return "int32";
}
template <>
inline word basicTypeName<int8>(){ return "int8"; }
inline word basicTypeName<int8>()
{
return "int8";
}
template <>
inline word basicTypeName<uint64>(){ return "uint64"; }
inline word basicTypeName<uint64>()
{
return "uint64";
}
template <>
inline word basicTypeName<uint32>(){ return "uint32"; }
inline word basicTypeName<uint32>()
{
return "uint32";
}
template <>
inline word basicTypeName<uint8>(){ return "uint8"; }
inline word basicTypeName<uint8>()
{
return "uint8";
}
template <>
inline word basicTypeName<real>(){ return "real"; }
inline word basicTypeName<real>()
{
return "real";
}
template <typename T>
word constexpr getTypeName()
{
if constexpr (checkStatic<T>::hasMember())
{
return T::TYPENAME();
}else
}
else
{
return basicTypeName<T>();
}
@ -114,7 +135,8 @@ namespace pFlow
if constexpr (checkStatic<T>::hasMember())
{
return T::TYPENAME();
}else
}
else
{
return basicTypeName<T>();
}
@ -133,38 +155,59 @@ namespace pFlow
{
return getTypeName<Type1>() == object.typeName();
}
}
} // namespace pFlow
#define TypeInfo(tName) \
inline static word TYPENAME() {return tName; } \
virtual word typeName() const {return TYPENAME();}
inline static word TYPENAME() \
{ \
return tName; \
} \
virtual word typeName() const \
{ \
return TYPENAME(); \
}
#define TypeInfoNV(tName) \
inline static word TYPENAME() {return tName; } \
word typeName() const {return TYPENAME();}
inline static word TYPENAME() \
{ \
return tName; \
} \
word typeName() const \
{ \
return TYPENAME(); \
}
#define TypeInfoTemplate11(tName, Type) \
inline static word TYPENAME() \
{ \
return word(tName) + "<" + getTypeName<Type>() + ">"; \
} \
virtual word typeName() const { return TYPENAME();}
virtual word typeName() const \
{ \
return TYPENAME(); \
}
#define TypeInfoTemplate12(tName, Type1, Type2) \
inline static word TYPENAME() \
{ \
return word(tName)+"<"+getTypeName<Type1>()+","+getTypeName<Type2>()+">"; \
return word(tName) + "<" + getTypeName<Type1>() + "," + \
getTypeName<Type2>() + ">"; \
} \
virtual word typeName() const { return TYPENAME();}
virtual word typeName() const \
{ \
return TYPENAME(); \
}
#define TypeInfoTemplate13(tName, Type1, Type2, Type3) \
inline static word TYPENAME() \
{ \
return word(tName)+"<"+getTypeName<Type1>()+","+getTypeName<Type2>()+","+getTypeName<Type3>()+">";\
return word(tName) + "<" + getTypeName<Type1>() + "," + \
getTypeName<Type2>() + "," + getTypeName<Type3>() + ">"; \
} \
virtual word typeName() const { return TYPENAME();}
virtual word typeName() const \
{ \
return TYPENAME(); \
}
// this is the non-virtual version
#define TypeInfoTemplateNV11(tName, Type) \
@ -172,37 +215,53 @@ namespace pFlow
{ \
return word(tName) + "<" + getTypeName<Type>() + ">"; \
} \
inline word typeName() const { return TYPENAME();}
inline word typeName() const \
{ \
return TYPENAME(); \
}
#define TypeInfoTemplateNV111(tName, Type, tName2) \
inline static word TYPENAME() \
{ \
return word(tName)+"<"+getTypeName<Type>()+","+word(tName2)+">"; \
return word(tName) + "<" + getTypeName<Type>() + "," + word(tName2) + \
">"; \
} \
inline word typeName() const { return TYPENAME();}
inline word typeName() const \
{ \
return TYPENAME(); \
}
#define TypeInfoTemplate111(tName, Type, tName2) \
inline static word TYPENAME() \
{ \
return word(tName)+"<"+getTypeName<Type>()+","+word(tName2)+">"; \
return word(tName) + "<" + getTypeName<Type>() + "," + word(tName2) + \
">"; \
} \
virtual word typeName() const { return TYPENAME();}
virtual word typeName() const \
{ \
return TYPENAME(); \
}
#define TypeInfoTemplate211(tBase, tName1, Type, tName3) \
inline static word TYPENAME() \
{ \
return word(tBase)+"<"+word(tName1)+","+getTypeName<Type>()+","+word(tName3)+">"; \
return word(tBase) + "<" + word(tName1) + "," + getTypeName<Type>() + \
"," + word(tName3) + ">"; \
} \
virtual word typeName() const { return TYPENAME();}
virtual word typeName() const \
{ \
return TYPENAME(); \
}
#define TypeInfoTemplate22(tBase, tName1, Type1, Type2) \
inline static word TYPENAME() \
{ \
return word(tBase)+"<"+word(tName1)+","+getTypeName<Type1>()+","+getTypeName<Type2>()+">"; \
return word(tBase) + "<" + word(tName1) + "," + getTypeName<Type1>() + \
"," + getTypeName<Type2>() + ">"; \
} \
virtual word typeName() const { return TYPENAME();}
virtual word typeName() const \
{ \
return TYPENAME(); \
}
#endif

View File

@ -23,36 +23,32 @@ Licence:
#include <functional>
#include "types.hpp"
#include "error.hpp"
#include "Map.hpp"
#include "error.hpp"
#include "types.hpp"
#include "uniquePtr.hpp"
#define create_vCtor(baseClass, selectorName, argList, args) \
\
typedef std::function< uniquePtr<baseClass> argList > selectorName##FunctionType; \
typedef wordMap<selectorName##FunctionType> selectorName##vCtorSelectorType; \
\
inline static selectorName##vCtorSelectorType selectorName##vCtorSelector_; \
typedef std::function<uniquePtr<baseClass> argList> \
selectorName##FunctionType; \
typedef wordMap<selectorName##FunctionType> \
selectorName##vCtorSelectorType; \
\
inline static selectorName##vCtorSelectorType \
selectorName##vCtorSelector_; \
\
template<typename dType> \
class create##selectorName##Callback \
{ \
public: \
\
create##selectorName##Callback() \
{ \
auto success = \
selectorName##vCtorSelector_.insertIf \
( \
auto success = selectorName##vCtorSelector_.insertIf( \
word(dType::TYPENAME()), \
[&] argList -> uniquePtr<baseClass> \
{ \
return uniquePtr<baseClass> \
( \
new dType args \
); \
} \
{ return uniquePtr<baseClass>(new dType args); } \
); \
\
if (!success) \
@ -62,21 +58,17 @@ public: \
<< " in virtual constructor table of " << #baseClass \
<< " with selector name " << #selectorName << endl; \
} \
\
} \
\
create##selectorName##Callback \
(const create##selectorName##Callback&)= delete; \
void operator= \
(const create##selectorName##Callback&)= delete; \
create##selectorName##Callback(const create##selectorName##Callback&) = \
delete; \
void operator=(const create##selectorName##Callback&) = delete; \
};
#define add_vCtor(baseClass, derivedClass, selectorName) \
\
inline static typename baseClass::template create##selectorName##Callback<derivedClass> baseClass##derivedClass##selectorName##_;
inline static typename baseClass::template create##selectorName##Callback< \
derivedClass> \
baseClass##derivedClass##selectorName##_;
#endif // __virtualConstructor_hpp__

View File

@ -23,23 +23,22 @@ Licence:
#include "iIstream.hpp"
#include "iOstream.hpp"
pFlow::Logical::Logical(const word& l)
{
if (!evaluteWord(l, s_, yesNoSet_))
{
fatalErrorInFunction<<
" invalid input for Logical: "<< l << endl;
fatalErrorInFunction << " invalid input for Logical: " << l << endl;
fatalExit;
}
}
pFlow::Logical::Logical(const char* ch)
:
Logical(word(ch))
{}
: Logical(word(ch))
{
}
bool pFlow::Logical::evaluteWord(const word& l, bool& b, int& yesNoSet )
bool
pFlow::Logical::evaluteWord(const word& l, bool& b, int& yesNoSet)
{
auto Ul = toUpper(l);
@ -62,7 +61,8 @@ bool pFlow::Logical::evaluteWord(const word& l, bool& b, int& yesNoSet )
return false;
}
bool pFlow::Logical::read(iIstream& is)
bool
pFlow::Logical::read(iIstream& is)
{
token t(is);
word w;
@ -85,8 +85,7 @@ bool pFlow::Logical::read(iIstream& is)
else
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Wrong token type - expected Logical value, found "
<< t;
<< "Wrong token type - expected Logical value, found " << t;
is.setBad();
return false;
}
@ -94,10 +93,8 @@ bool pFlow::Logical::read(iIstream& is)
return evaluteWord(w, s_, yesNoSet_);
}
bool pFlow::Logical::write
(
iOstream& os
)const
bool
pFlow::Logical::write(iOstream& os) const
{
if (s_)
{
@ -110,7 +107,8 @@ bool pFlow::Logical::write
return os.check(FUNCTION_NAME);
}
pFlow::iIstream& pFlow::operator>>( iIstream& is, Logical& L)
pFlow::iIstream&
pFlow::operator>>(iIstream& is, Logical& L)
{
if (!L.read(is))
{
@ -119,7 +117,8 @@ pFlow::iIstream& pFlow::operator>>( iIstream& is, Logical& L)
return is;
}
pFlow::iOstream& pFlow::operator<< ( iOstream& os, const Logical& L)
pFlow::iOstream&
pFlow::operator<<(iOstream& os, const Logical& L)
{
if (!L.write(os))
{

View File

@ -38,7 +38,7 @@ class iOstream;
*/
class Logical
{
protected:
private:
/// bool value
bool s_ = false;
@ -47,14 +47,17 @@ protected:
int yesNoSet_ = 0;
/// Set of Yes or Nos
inline static const word YesNo__[4][2] = {{"Yes", "No"},{"on","off"},{"true","false"}, {"Ok","No"}};
inline static const word YesNo__[4][2] = { { "Yes", "No" },
{ "on", "off" },
{ "true", "false" },
{ "Ok", "No" } };
/// Construct from bool and set number
inline explicit Logical(bool s, int yns)
:
s_(s),
: s_(s),
yesNoSet_(yns)
{}
{
}
public:
@ -64,13 +67,13 @@ public:
//// Constructors
/// Default constructor
inline Logical(){}
inline Logical() = default;
/// Construct from bool
inline explicit Logical(bool s)
:
s_(s)
{}
: s_(s)
{
}
/// Construct from word
Logical(const word& l);
@ -127,13 +130,13 @@ public:
//// Static members
bool static evaluteWord(const word& l, bool& b, int& yesNoSet);
};
iIstream& operator>>( iIstream& is, Logical& L);
iIstream&
operator>>(iIstream& is, Logical& L);
iOstream& operator<<( iOstream& os, const Logical& L);
iOstream&
operator<<(iOstream& os, const Logical& L);
} // pFlow

View File

@ -19,59 +19,70 @@ Licence:
-----------------------------------------------------------------------------*/
#include <algorithm>
#include <sstream>
#include <iomanip>
#include <sstream>
#include "bTypesFunctions.hpp"
pFlow::int32 pFlow::countChar(const word& s, const char c)
pFlow::int32
pFlow::countChar(const word& s, const char c)
{
return std::count(s.cbegin(), s.cend(), c);
}
pFlow::int32 pFlow::countChar( const char* s, const char c)
pFlow::int32
pFlow::countChar(const char* s, const char c)
{
return
(
s == nullptr
? 0
return (
s == nullptr ? 0
: std::count(s, (s + std::char_traits<char>::length(s)), c)
);
}
pFlow::word pFlow::toUpper(const word & inStr)
pFlow::word
pFlow::toUpper(const word& inStr)
{
word oStr(inStr);
std::transform(inStr.begin(), inStr.end(), oStr.begin(), ::toupper);
return oStr;
}
pFlow::word pFlow::firstCapital(const word& inStr)
pFlow::word
pFlow::firstCapital(const word& inStr)
{
word oStr(inStr);
oStr[0] = std::toupper(oStr[0]);
return oStr;
}
bool pFlow::isYes(const word & str)
bool
pFlow::isYes(const word& str)
{
word s = toUpper(str);
if( s == "YES" || s=="Y" || s == "OK" || s == "TRUE" || s == "ON" || s=="T") return true;
if (s == "YES" ||
s == "Y" ||
s == "OK" ||
s == "TRUE" ||
s == "ON" ||
s == "T")
return true;
return false;
}
bool pFlow::isNo(const word & str)
bool
pFlow::isNo(const word& str)
{
word s = toUpper(str);
if( s == "NO" || s == "N" || "FALSE" || s == "OFF" || s == "F") return true;
if (s == "NO" || s == "N" || "FALSE" || s == "OFF" || s == "F")
return true;
else
return false;
}
pFlow::word pFlow::real2Fixed(const real & v, int32 numPrecision)
pFlow::word
pFlow::real2Fixed(const real& v, int32 numPrecision)
{
std::stringstream ss;
@ -79,7 +90,8 @@ pFlow::word pFlow::real2Fixed(const real & v, int32 numPrecision)
return ss.str();
}
pFlow::word pFlow::real2Word(const real & v, int32 numPrecision)
pFlow::word
pFlow::real2Word(const real& v, int32 numPrecision)
{
std::stringstream ss;
if (abs(v) < verySmallValue)
@ -94,7 +106,8 @@ pFlow::word pFlow::real2Word(const real & v, int32 numPrecision)
return ss.str();
}
pFlow::word pFlow::int322Word(const int32 & v)
pFlow::word
pFlow::int322Word(const int32& v)
{
std::stringstream ss;
@ -102,13 +115,16 @@ pFlow::word pFlow::int322Word(const int32 & v)
return ss.str();
}
pFlow::word pFlow::removeDecimalZeros(const word& str)
pFlow::word
pFlow::removeDecimalZeros(const word& str)
{
auto dec = str.find('.');
if(dec == word::npos) return str;
if (dec == word::npos)
return str;
auto len = str.size();
if(len == word::npos) return str;
if (len == word::npos)
return str;
auto firstZero = word::npos;
for (auto n = len - 1; n > dec; n--)
@ -123,44 +139,50 @@ pFlow::word pFlow::removeDecimalZeros(const word& str)
}
}
if(firstZero == dec+1) firstZero = dec;
if (firstZero == dec + 1)
firstZero = dec;
return str.substr(0, firstZero);
}
pFlow::word pFlow::real2FixedStripZeros(const real & v, int32 numPrecision)
pFlow::word
pFlow::real2FixedStripZeros(const real& v, int32 numPrecision)
{
word strVal = real2Fixed(v, numPrecision);
return removeDecimalZeros(strVal);
}
pFlow::word pFlow::angleBracketsNames(const word& w1, const word& w2)
pFlow::word
pFlow::angleBracketsNames(const word& w1, const word& w2)
{
return w1 + "<" + w2 + ">";
}
pFlow::word pFlow::angleBracketsNames2
(
const word& base,
const word& w1,
const word& w2
)
pFlow::word
pFlow::angleBracketsNames2(const word& base, const word& w1, const word& w2)
{
return base + "<" + w1 + "," + w2 + ">";
}
pFlow::word pFlow::angleBracketsNames3(const word& base, const word& w1, const word& w2, const word& w3)
pFlow::word
pFlow::angleBracketsNames3(
const word& base,
const word& w1,
const word& w2,
const word& w3
)
{
return base + "<" + w1 + "," + w2 + "," + w3 + ">";
}
pFlow::word pFlow::groupNames(const word& bw, const word& tw, char sep)
pFlow::word
pFlow::groupNames(const word& bw, const word& tw, char sep)
{
return bw + sep + tw;
}
pFlow::word pFlow::baseName(const word& w, char sep)
pFlow::word
pFlow::baseName(const word& w, char sep)
{
if (auto pos = w.find_last_of(sep); pos != word::npos)
{
@ -172,7 +194,8 @@ pFlow::word pFlow::baseName(const word& w, char sep)
}
}
pFlow::word pFlow::tailName(const word& w, char sep)
pFlow::word
pFlow::tailName(const word& w, char sep)
{
if (auto pos = w.find_last_of(sep); pos != word::npos)
{
@ -184,12 +207,11 @@ pFlow::word pFlow::tailName(const word& w, char sep)
}
}
bool pFlow::validWord(char c)
bool
pFlow::validWord(char c)
{
return
(
!isspace(c)
&& c != '"' // string quote
return (
!isspace(c) && c != '"' // string quote
&& c != '\'' // string quote
//&& c != '/' // path separator
&& c != ';' // end statement
@ -198,40 +220,45 @@ bool pFlow::validWord(char c)
);
}
bool pFlow::validWordWithQuote(char c)
bool
pFlow::validWordWithQuote(char c)
{
return
(
!isspace(c)
&& c != ';' // end statement
return (
!isspace(c) && c != ';' // end statement
&& c != '{' // beg subdict
&& c != '}' // end subdict
);
}
bool pFlow::validWord(const word& w)
bool
pFlow::validWord(const word& w)
{
for (auto wi : w)
{
char c = wi;
if ( !validWord(c) ) return false;
if (!validWord(c))
return false;
}
return true;
}
bool pFlow::validWordWithQuote(const word& w)
bool
pFlow::validWordWithQuote(const word& w)
{
for (auto wi : w)
{
char c = wi;
if ( !validWordWithQuote(c) ) return false;
if (!validWordWithQuote(c))
return false;
}
return true;
}
bool pFlow::readUint32( const word& w, uint32 & val)
bool
pFlow::readUint32(const word& w, uint32& val)
{
try
{
try{
val = std::stoul(w);
}
catch (...)
@ -241,15 +268,18 @@ bool pFlow::readUint32( const word& w, uint32 & val)
return true;
}
bool pFlow::readUint32( const char* buf, uint32 & val)
bool
pFlow::readUint32(const char* buf, uint32& val)
{
word w(buf);
return readUint32(w, val);
}
bool pFlow::readInt64( const word& w, int64 & val)
bool
pFlow::readInt64(const word& w, int64& val)
{
try
{
try{
val = std::stoll(w);
}
catch (...)
@ -259,15 +289,18 @@ bool pFlow::readInt64( const word& w, int64 & val)
return true;
}
bool pFlow::readInt64( const char* buf, int64 & val)
bool
pFlow::readInt64(const char* buf, int64& val)
{
word w(buf);
return readInt64(w, val);
}
bool pFlow::readInt32( const word& w, int32 & val)
bool
pFlow::readInt32(const word& w, int32& val)
{
try
{
try{
val = std::stoi(w);
}
catch (...)
@ -277,15 +310,18 @@ bool pFlow::readInt32( const word& w, int32 & val)
return true;
}
bool pFlow::readInt32( const char* buf, int32 & val)
bool
pFlow::readInt32(const char* buf, int32& val)
{
word w(buf);
return readInt32(w, val);
}
bool pFlow::readInt8( const word& w, int8 & val)
bool
pFlow::readInt8(const word& w, int8& val)
{
try
{
try{
val = std::stoi(w);
}
catch (...)
@ -295,30 +331,34 @@ bool pFlow::readInt8( const word& w, int8 & val)
return true;
}
bool pFlow::readInt8( const char* buf, int8 & val)
bool
pFlow::readInt8(const char* buf, int8& val)
{
word w(buf);
return readInt8(w, val);
}
// #include <iostream>
bool pFlow::readReal( const word& w, real & val)
bool
pFlow::readReal(const word& w, real& val)
{
try
{
try{
val = std::stod(w);
}
catch (std::out_of_range& e)
{
val = static_cast<real>(std::stold(w));
}
catch (...){
catch (...)
{
return false;
}
return true;
}
bool pFlow::readReal( const char* buf, real & val )
bool
pFlow::readReal(const char* buf, real& val)
{
char* c;
@ -337,8 +377,8 @@ bool pFlow::readReal( const char* buf, real & val )
return true;
}
bool pFlow::readBoolian_Str( const word& w, bool & val)
bool
pFlow::readBoolian_Str(const word& w, bool& val)
{
if (bool t = isYes(w); t)
{
@ -353,7 +393,8 @@ bool pFlow::readBoolian_Str( const word& w, bool & val)
return false;
}
bool pFlow::readBoolian_Str( const char* buf, bool & val)
bool
pFlow::readBoolian_Str(const char* buf, bool& val)
{
word w(buf);
return readBoolian_Str(w, val);

View File

@ -25,12 +25,10 @@ Licence:
#ifndef __bTypesFunctions_hpp__
#define __bTypesFunctions_hpp__
#include "pFlowMacros.hpp"
#include "numericConstants.hpp"
#include "builtinTypes.hpp"
#include "math.hpp"
#include "numericConstants.hpp"
#include "pFlowMacros.hpp"
namespace pFlow
{
@ -54,196 +52,236 @@ inline const word nullWord;
inline const word whiteSpace(" \t\n\v\f\r");
/// Count numer of chars c in a word
int32 countChar (const word& s, const char c);
int32
countChar(const word& s, const char c);
/// Count numer of chars c in a char string
int32 countChar(const char* s, const char c);
int32
countChar(const char* s, const char c);
/// convert a word to all caps
word toUpper(const word & inStr);
word
toUpper(const word& inStr);
word firstCapital(const word& inStr);
word
firstCapital(const word& inStr);
/// Check if str equals "Yes", "Y", "True", "Ok", "ON", or "T"
bool isYes(const word & str);
bool
isYes(const word& str);
/// Check if str equals "No", "N", "False", or "Off"
bool isNo(const word & str);
bool
isNo(const word& str);
/// Convert floating point variable to string with fixed number of precisions
word real2Fixed(const real & v, int32 numPrecision = 6);
word
real2Fixed(const real& v, int32 numPrecision = 6);
/// Convert floating point variable to string with general format
word real2Word(const real & v, int32 numPrecision = 6);
word
real2Word(const real& v, int32 numPrecision = 6);
/// Convert int32 to word
word int322Word(const int32 & v);
word
int322Word(const int32& v);
/// Remove zeros from decimal part of a string number
word removeDecimalZeros(const word& str);
word
removeDecimalZeros(const word& str);
/// Convert to fixed point variable and remove zeros
word real2FixedStripZeros(const real & v, int32 numPrecision = 6);
word
real2FixedStripZeros(const real& v, int32 numPrecision = 6);
/// Output <w1,w2>
word angleBracketsNames(const word& w1, const word& w2);
word
angleBracketsNames(const word& w1, const word& w2);
/// Output base<w1,w2>
word angleBracketsNames2(const word& base, const word& w1, const word& w2);
word
angleBracketsNames2(const word& base, const word& w1, const word& w2);
/// Output base<w1,sw2,w3>
word angleBracketsNames3(const word& base, const word& w1, const word& w2, const word& w3);
word
angleBracketsNames3(
const word& base,
const word& w1,
const word& w2,
const word& w3
);
/// Group words and output bw.tw
word groupNames(const word& bw, const word& tw, char sep = '.');
word
groupNames(const word& bw, const word& tw, char sep = '.');
/// Find the base in a group separated by "." and return it.
word baseName(const word& w, char sep = '.');
word
baseName(const word& w, char sep = '.');
/// Find tail name in a group separated by "." and return it.
word tailName(const word& w, char sep = '.');
word
tailName(const word& w, char sep = '.');
/// Is the character valid for a word name?
bool validWord(char c);
bool
validWord(char c);
/// Is c a valid character including quote?
bool validWordWithQuote(char c);
bool
validWordWithQuote(char c);
/// Is a valid word?
bool validWord(const word& w);
bool
validWord(const word& w);
/// Is a valid word with qoute?
bool validWordWithQuote(const word& c);
bool
validWordWithQuote(const word& c);
/// Convert word to uint32
bool readUint32( const word& w, uint32 & val);
bool
readUint32(const word& w, uint32& val);
/// Convert char string to uint32
bool readUint32( const char* buf, uint32 & val);
bool
readUint32(const char* buf, uint32& val);
/// Convert word to int64
bool readInt64( const word& w, int64 & val);
bool
readInt64(const word& w, int64& val);
/// Convert char string to int64
bool readInt64( const char* buf, int64 & val);
bool
readInt64(const char* buf, int64& val);
/// Convert word to int32
bool readInt32( const word& w, int32 & val);
bool
readInt32(const word& w, int32& val);
/// Convert char string to int32
bool readInt32( const char* buf, int32 & val);
bool
readInt32(const char* buf, int32& val);
/// Convert word to int8
bool readInt8( const word& w, int8 & val);
bool
readInt8(const word& w, int8& val);
/// Convert char string to int8
bool readInt8( const char* buf, int8 & val);
bool
readInt8(const char* buf, int8& val);
/// Convert word to real
bool readReal( const word& w, real & val);
bool
readReal(const word& w, real& val);
/// Convert char string to real
bool readReal( const char* buf, real & val );
bool
readReal(const char* buf, real& val);
/// Convert word to bool
bool readBoolian_Str( const word& w, bool & val);
bool
readBoolian_Str(const word& w, bool& val);
/// Convert char string to bool
bool readBoolian_Str( const char* buf, bool & val);
bool
readBoolian_Str(const char* buf, bool& val);
inline
bool readValue(const word& w, real& val)
inline bool
readValue(const word& w, real& val)
{
return readReal(w, val);
}
inline
bool readValue(const word& w, uint32& val)
inline bool
readValue(const word& w, uint32& val)
{
return readUint32(w, val);
}
inline
bool readValue(const word& w, int64& val)
inline bool
readValue(const word& w, int64& val)
{
return readInt64(w, val);
}
inline
bool readValue(const word& w, int32& val)
inline bool
readValue(const word& w, int32& val)
{
return readInt32(w, val);
}
inline
bool readValue(const word& w, int8& val)
inline bool
readValue(const word& w, int8& val)
{
return readInt8(w, val);
}
inline
bool readValue(const word& w, bool& val)
inline bool
readValue(const word& w, bool& val)
{
return readBoolian_Str(w, val);
}
INLINE_FUNCTION_HD
bool equal(const real& s1, const real& s2, real tol = smallValue)
bool
equal(const real& s1, const real& s2, real tol = smallValue)
{
return abs(s1 - s2) <= tol;
}
INLINE_FUNCTION_HD
bool equal(const int64& s1, const int64& s2)
bool
equal(const int64& s1, const int64& s2)
{
return s1 == s2;
}
INLINE_FUNCTION_HD
bool equal(const int32& s1, const int32& s2)
bool
equal(const int32& s1, const int32& s2)
{
return s1 == s2;
}
INLINE_FUNCTION_HD
bool equal(const int8& s1, const int8& s2)
bool
equal(const int8& s1, const int8& s2)
{
return s1 == s2;
}
INLINE_FUNCTION_HD
bool equal(const uint32& s1, const uint32& s2)
bool
equal(const uint32& s1, const uint32& s2)
{
return s1 == s2;
}
/// Are two words equal (host only)?
INLINE_FUNCTION
bool equal(const word& s1, const word& s2)
bool
equal(const word& s1, const word& s2)
{
return s1 == s2;
}
/// Convert degree to radians
INLINE_FUNCTION_HD
real degree2Radian(const real &theta)
real
degree2Radian(const real& theta)
{
return theta / 180.0 * Pi;
}
/// Convert radians to degree
INLINE_FUNCTION_HD
real radian2Degree(const real &phi)
real
radian2Degree(const real& phi)
{
return phi / Pi * 180.0;
}
} // end of pFlow
#endif //__bTypesFunctions_hpp__

View File

@ -38,7 +38,6 @@ inline const char* floatingPointType__ = "float";
inline const bool usingDouble__ = false;
#endif
// scalars
#if useDouble
using real = double;
@ -66,8 +65,8 @@ using word = std::string;
inline const int numBytesForReal__ = sizeof(real);
inline
word floatingPointDescription()
inline word
floatingPointDescription()
{
return word("In this build, ") + word(floatingPointType__) +
word(" is used for floating point operations.");
@ -75,5 +74,4 @@ word floatingPointDescription()
} // end of pFlow
#endif

View File

@ -21,17 +21,14 @@ Licence:
#ifndef __math_hpp__
#define __math_hpp__
#ifdef __CUDACC__
#include "math.h"
#else
#include <cmath>
#endif
#include "pFlowMacros.hpp"
#include "builtinTypes.hpp"
#include "pFlowMacros.hpp"
//* * * * * * * * * * * List of functinos * * * * * * * * //
// abs, mod, exp, log, log10, pow, sqrt, cbrt
@ -43,9 +40,9 @@ Licence:
namespace pFlow
{
INLINE_FUNCTION_HD
real abs(real x)
real
abs(real x)
{
#ifdef __CUDACC__
return ::fabs(x);
@ -56,21 +53,23 @@ real abs(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
int64 abs(int64 x)
int64
abs(int64 x)
{
return std::abs(x);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD int32 abs(int32 x)
INLINE_FUNCTION_HD int32
abs(int32 x)
{
return std::abs(x);
}
#endif
INLINE_FUNCTION_HD real mod(real x, real y)
INLINE_FUNCTION_HD real
mod(real x, real y)
{
#ifdef __CUDACC__
return ::fmod(x, y);
@ -79,28 +78,33 @@ INLINE_FUNCTION_HD real mod(real x, real y)
#endif
}
INLINE_FUNCTION_HD int64 mod(int64 x, int64 y)
INLINE_FUNCTION_HD int64
mod(int64 x, int64 y)
{
return x % y;
}
INLINE_FUNCTION_HD int32 mod(int32 x, int32 y)
INLINE_FUNCTION_HD int32
mod(int32 x, int32 y)
{
return x % y;
}
INLINE_FUNCTION_HD int64 mod(uint64 x, uint64 y)
INLINE_FUNCTION_HD int64
mod(uint64 x, uint64 y)
{
return x % y;
}
INLINE_FUNCTION_HD auto mod(uint32 x, uint32 y)
INLINE_FUNCTION_HD auto
mod(uint32 x, uint32 y)
{
return x % y;
}
#ifndef __CUDACC__
INLINE_FUNCTION_HD real remainder(real x, real y)
INLINE_FUNCTION_HD real
remainder(real x, real y)
{
return std::remainder(x, y);
}
@ -108,7 +112,8 @@ INLINE_FUNCTION_HD real remainder(real x, real y)
#ifndef __CUDACC__
INLINE_FUNCTION_H
real exp(real x)
real
exp(real x)
{
return std::exp(x);
}
@ -116,7 +121,8 @@ real exp(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real log(real x)
real
log(real x)
{
return std::log(x);
}
@ -124,7 +130,8 @@ real log(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real log10(real x)
real
log10(real x)
{
return std::log10(x);
}
@ -132,7 +139,8 @@ real log10(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real pow(real x, real y)
real
pow(real x, real y)
{
return std::pow(x, y);
}
@ -140,7 +148,8 @@ real pow(real x, real y)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real sqrt(real x)
real
sqrt(real x)
{
return std::sqrt(x);
}
@ -148,7 +157,8 @@ real sqrt(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real cbrt (real x)
real
cbrt(real x)
{
return std::cbrt(x);
}
@ -156,7 +166,8 @@ real cbrt (real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real sin(real x)
real
sin(real x)
{
return std::sin(x);
}
@ -164,7 +175,8 @@ real sin(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real cos(real x)
real
cos(real x)
{
return std::cos(x);
}
@ -172,7 +184,8 @@ real cos(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real tan(real x)
real
tan(real x)
{
return std::tan(x);
}
@ -180,7 +193,8 @@ real tan(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real asin(real x)
real
asin(real x)
{
return std::asin(x);
}
@ -188,7 +202,8 @@ real asin(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real acos(real x)
real
acos(real x)
{
return std::acos(x);
}
@ -196,7 +211,8 @@ real acos(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real atan(real x)
real
atan(real x)
{
return std::atan(x);
}
@ -212,7 +228,8 @@ atan2(real y, real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real sinh(real x)
real
sinh(real x)
{
return std::sinh(x);
}
@ -220,13 +237,15 @@ real sinh(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real cosh(real x)
real
cosh(real x)
{
return std::cosh(x);
}
#endif
INLINE_FUNCTION_HD real tanh(real x)
INLINE_FUNCTION_HD real
tanh(real x)
{
#ifdef __CUDACC__
return ::tanh(x);
@ -235,7 +254,8 @@ INLINE_FUNCTION_HD real tanh(real x)
#endif
}
INLINE_FUNCTION_HD real asinh(real x)
INLINE_FUNCTION_HD real
asinh(real x)
{
#ifdef __CUDACC__
return ::asinh(x);
@ -244,7 +264,8 @@ INLINE_FUNCTION_HD real asinh(real x)
#endif
}
INLINE_FUNCTION_HD real acosh(real x)
INLINE_FUNCTION_HD real
acosh(real x)
{
#ifdef __CUDACC__
return ::acosh(x);
@ -255,14 +276,15 @@ INLINE_FUNCTION_HD real acosh(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real atanh(real x)
real
atanh(real x)
{
return std::atanh(x);
}
#endif
INLINE_FUNCTION_HD real min(real x, real y)
INLINE_FUNCTION_HD real
min(real x, real y)
{
#ifdef __CUDACC__
return ::fmin(x, y);
@ -273,7 +295,8 @@ INLINE_FUNCTION_HD real min(real x, real y)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
int64 min(int32 x, int32 y)
int64
min(int32 x, int32 y)
{
return std::min(x, y);
}
@ -281,7 +304,8 @@ int64 min(int32 x, int32 y)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
int64 min(int64 x, int64 y)
int64
min(int64 x, int64 y)
{
return std::min(x, y);
}
@ -289,21 +313,23 @@ int64 min(int64 x, int64 y)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
uint64 min(uint64 x, uint64 y)
uint64
min(uint64 x, uint64 y)
{
return std::min(x, y);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD uint32 min(uint32 x, uint32 y)
INLINE_FUNCTION_HD uint32
min(uint32 x, uint32 y)
{
return std::min(x, y);
}
#endif
INLINE_FUNCTION_HD real max(real x, real y)
INLINE_FUNCTION_HD real
max(real x, real y)
{
#ifdef __CUDACC__
return ::fmax(x, y);
@ -312,38 +338,38 @@ INLINE_FUNCTION_HD real max(real x, real y)
#endif
}
#ifndef __CUDACC__
INLINE_FUNCTION_HD int64 max(int64 x, int64 y)
INLINE_FUNCTION_HD int64
max(int64 x, int64 y)
{
return std::max(x, y);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD int32 max(int32 x, int32 y)
INLINE_FUNCTION_HD int32
max(int32 x, int32 y)
{
return std::max(x, y);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD uint64 max(uint64 x, uint64 y)
INLINE_FUNCTION_HD uint64
max(uint64 x, uint64 y)
{
return std::max(x, y);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD uint32 max(uint32 x, uint32 y)
INLINE_FUNCTION_HD uint32
max(uint32 x, uint32 y)
{
return std::max(x, y);
}
#endif
} // pFlow
#endif // __math_hpp__

View File

@ -21,10 +21,8 @@ Licence:
#ifndef __numericConstants_hpp__
#define __numericConstants_hpp__
#include <limits>
#include "builtinTypes.hpp"
#include <limits>
namespace pFlow
{
@ -37,20 +35,23 @@ namespace pFlow
// - largest negative value
template<typename T>
constexpr inline T largestNegative()
constexpr T
largestNegative()
{
return std::numeric_limits<T>::lowest();
}
template<typename T>
constexpr inline T epsilonValue()
constexpr T
epsilonValue()
{
return std::numeric_limits<T>::min();
}
// largest positive value
template<typename T>
constexpr inline T largestPositive()
constexpr T
largestPositive()
{
return std::numeric_limits<T>::max();
}
@ -65,8 +66,6 @@ namespace pFlow
const inline real largestPosREAL = largestPositive<real>();
const inline real epsilonREAL = epsilonValue<real>();
} // end of pFlow
#endif //__numericConstants_hpp__

View File

@ -21,25 +21,24 @@ Licence:
#ifndef __quadruple_hpp__
#define __quadruple_hpp__
#include "uniquePtr.hpp"
#include "triple.hpp"
#include "iOstream.hpp"
#include "iIstream.hpp"
#include "token.hpp"
#include "error.hpp"
#include "iIstream.hpp"
#include "iOstream.hpp"
#include "token.hpp"
#include "triple.hpp"
#include "uniquePtr.hpp"
namespace pFlow
{
template<typename T> class quadruple;
template<typename T>
class quadruple;
class iIstream;
#include "quadrupleFwd.hpp"
// you can see it as a sequence of four elements (w,x,y,z) or an (scalar and vector)
// you can see it as a sequence of four elements (w,x,y,z) or an (scalar and
// vector)
template<typename T>
class quadruple
{
@ -47,40 +46,41 @@ public:
T s_;
triple<T> v_;
public:
//// constructors
INLINE_FUNCTION_HD
quadruple()
{}
{
}
//// Constructors
INLINE_FUNCTION_HD
quadruple(const T& w, const T& x, const T& y, const T& z)
:
s_(w),
: s_(w),
v_(x, y, z)
{}
{
}
INLINE_FUNCTION_HD
quadruple(const T& s, const triple<T> v)
:
s_(s),
: s_(s),
v_(v)
{}
{
}
INLINE_FUNCTION_HD
quadruple(const T& val)
:
s_(val),
: s_(val),
v_(val)
{}
{
}
// type conversion trough assignment
template<typename T2>
INLINE_FUNCTION_HD
quadruple<T> & operator = (const quadruple<T2> & rhs)
INLINE_FUNCTION_HD quadruple<T>& operator=(const quadruple<T2>& rhs)
{
this->v_ = rhs.v_;
this->s_ = static_cast<T>(rhs.s_);
@ -89,11 +89,11 @@ public:
// type casting through copy constructor
template<typename T2>
INLINE_FUNCTION_HD
quadruple(const quadruple<T2> &src):
s_(static_cast<T>(src.s_)),
INLINE_FUNCTION_HD quadruple(const quadruple<T2>& src)
: s_(static_cast<T>(src.s_)),
v_(src.v_)
{}
{
}
// copy construct
INLINE_FUNCTION_HD
@ -126,74 +126,120 @@ public:
// Access
INLINE_FUNCTION_HD
T & w(){ return s_; }
T& w()
{
return s_;
}
INLINE_FUNCTION_HD
const T & w()const { return s_; }
const T& w() const
{
return s_;
}
INLINE_FUNCTION_HD
T & x(){ return v_.x(); }
T& x()
{
return v_.x();
}
INLINE_FUNCTION_HD
const T & x()const { return v_.x(); }
const T& x() const
{
return v_.x();
}
INLINE_FUNCTION_HD
T & y(){ return v_.y(); }
T& y()
{
return v_.y();
}
INLINE_FUNCTION_HD
const T & y()const { return v_.y(); }
const T& y() const
{
return v_.y();
}
INLINE_FUNCTION_HD
T & z(){ return v_.z(); }
T& z()
{
return v_.z();
}
INLINE_FUNCTION_HD
const T & z()const { return v_.z(); }
const T& z() const
{
return v_.z();
}
INLINE_FUNCTION_HD
T & s(){ return s_; }
T& s()
{
return s_;
}
INLINE_FUNCTION_HD
const T & s()const { return s_; }
const T& s() const
{
return s_;
}
INLINE_FUNCTION_HD
triple<T> v() {return v_;}
triple<T> v()
{
return v_;
}
INLINE_FUNCTION_HD
const triple<T> v() const {return v_;}
const triple<T> v() const
{
return v_;
}
// methods
friend FUNCTION_HD T dot <T> (const quadruple<T> & oprnd1, const quadruple<T> & oprnd2);
friend FUNCTION_HD T
dot<T>(const quadruple<T>& oprnd1, const quadruple<T>& oprnd2);
INLINE_FUNCTION_HD T length() const;
INLINE_FUNCTION_HD void normalize();
//// operators
// + operator
friend FUNCTION_HD quadruple<T> operator+ <T> (const quadruple<T> & oprnd1, const quadruple<T> & oprnd2);
friend FUNCTION_HD quadruple<T> operator+
<T>(const quadruple<T>& oprnd1, const quadruple<T>& oprnd2);
friend FUNCTION_HD quadruple<T> operator+ <T> (const quadruple<T> & oprnd1, const T & oprnd2);
friend FUNCTION_HD quadruple<T> operator+
<T>(const quadruple<T>& oprnd1, const T& oprnd2);
friend FUNCTION_HD quadruple<T> operator+ <T> (const T & oprnd1, const quadruple<T> & oprnd2);
friend FUNCTION_HD quadruple<T> operator+
<T>(const T& oprnd1, const quadruple<T>& oprnd2);
// - operator
friend FUNCTION_HD quadruple<T> operator - <T> (const quadruple<T> & oprnd1, const quadruple<T> & oprnd2);
friend FUNCTION_HD quadruple<T> operator-
<T>(const quadruple<T>& oprnd1, const quadruple<T>& oprnd2);
friend FUNCTION_HD quadruple<T> operator - <T> (const quadruple<T> & oprnd1, const T & oprnd2);
friend FUNCTION_HD quadruple<T> operator-
<T>(const quadruple<T>& oprnd1, const T& oprnd2);
friend FUNCTION_HD quadruple<T> operator - <T> (const T & oprnd1, const quadruple<T> & oprnd2);
friend FUNCTION_HD quadruple<T> operator-
<T>(const T& oprnd1, const quadruple<T>& oprnd2);
// * operators
friend FUNCTION_HD quadruple<T> operator * <T> (const quadruple<T> & oprnd1, const quadruple<T> & oprnd2);
friend FUNCTION_HD quadruple<T> operator*
<T>(const quadruple<T>& oprnd1, const quadruple<T>& oprnd2);
friend FUNCTION_HD quadruple<T> operator * <T> (const quadruple<T> & oprnd1, const T & oprnd2);
friend FUNCTION_HD quadruple<T> operator*
<T>(const quadruple<T>& oprnd1, const T& oprnd2);
friend FUNCTION_HD quadruple<T> operator * <T> (const T & oprnd1, const quadruple<T> & oprnd2);
friend FUNCTION_HD quadruple<T> operator*
<T>(const T& oprnd1, const quadruple<T>& oprnd2);
// / operators
friend FUNCTION_HD quadruple<T> operator / <T> (const quadruple<T> & oprnd1, const quadruple<T> & oprnd2);
friend FUNCTION_HD quadruple<T> operator/
<T>(const quadruple<T>& oprnd1, const quadruple<T>& oprnd2);
friend FUNCTION_HD quadruple<T> operator / <T> (const quadruple<T> & oprnd1, const T & oprnd2);
friend FUNCTION_HD quadruple<T> operator / <T> (const T & oprnd1, const quadruple<T> & oprnd2);
friend FUNCTION_HD quadruple<T> operator/
<T>(const quadruple<T>& oprnd1, const T& oprnd2);
friend FUNCTION_HD quadruple<T> operator/
<T>(const T& oprnd1, const quadruple<T>& oprnd2);
INLINE_FUNCTION_HD
void operator+=(const quadruple& oprnd2);
@ -207,7 +253,6 @@ public:
INLINE_FUNCTION_HD
void operator/=(const quadruple& oprnd2);
// unary negate operator
INLINE_FUNCTION_HD
quadruple operator-() const;
@ -216,24 +261,22 @@ public:
INLINE_FUNCTION_HD
quadruple operator+() const;
friend FUNCTION_HD bool operator == <T> (const quadruple<T> &opr1, const quadruple<T> &opr2);
friend FUNCTION_HD bool operator==
<T>(const quadruple<T>& opr1, const quadruple<T>& opr2);
// << operator
friend FUNCTION_H iOstream& operator<< <T> (iOstream& str, const quadruple<T> & ov);
friend FUNCTION_H iOstream&
operator<< <T>(iOstream& str, const quadruple<T>& ov);
// >> operator
friend FUNCTION_H iIstream& operator>> <T>(iIstream& str, quadruple<T>& iv);
// same as >> operator, but faster, good for mass read
friend FUNCTION_H void readIstream<T>(iIstream& str, quadruple<T>& iv);
};
} // pFlow
#include "quadrupleI.hpp"
// #include "quadrupleMath.hpp"

View File

@ -19,123 +19,69 @@ Licence:
-----------------------------------------------------------------------------*/
template<typename T>
INLINE_FUNCTION_HD T dot
(
const quadruple<T> & oprnd1,
const quadruple<T> & oprnd2
);
INLINE_FUNCTION_HD T
dot(const quadruple<T>& oprnd1, const quadruple<T>& oprnd2);
template<typename T>
INLINE_FUNCTION_HD quadruple<T> operator +
(
const quadruple<T> & oprnd1,
const quadruple<T> & oprnd2
);
INLINE_FUNCTION_HD quadruple<T>
operator+(const quadruple<T>& oprnd1, const quadruple<T>& oprnd2);
template<typename T>
INLINE_FUNCTION_HD quadruple<T> operator+
(
const quadruple<T> & oprnd1,
const T & oprnd2
);
INLINE_FUNCTION_HD quadruple<T>
operator+(const quadruple<T>& oprnd1, const T& oprnd2);
template<typename T>
INLINE_FUNCTION_HD quadruple<T> operator+
(
const T & oprnd2,
const quadruple<T> & oprnd1
);
INLINE_FUNCTION_HD quadruple<T>
operator+(const T& oprnd2, const quadruple<T>& oprnd1);
template<typename T>
INLINE_FUNCTION_HD quadruple<T> operator-
(
const quadruple<T> & oprnd1,
const quadruple<T> & oprnd2
);
INLINE_FUNCTION_HD quadruple<T>
operator-(const quadruple<T>& oprnd1, const quadruple<T>& oprnd2);
template<typename T>
INLINE_FUNCTION_HD quadruple<T> operator-
(
const quadruple<T> & oprnd1,
const T & oprnd2
);
INLINE_FUNCTION_HD quadruple<T>
operator-(const quadruple<T>& oprnd1, const T& oprnd2);
template<typename T>
INLINE_FUNCTION_HD quadruple<T> operator-
(
const T & oprnd1,
const quadruple<T> & oprnd2
);
INLINE_FUNCTION_HD quadruple<T>
operator-(const T& oprnd1, const quadruple<T>& oprnd2);
template<typename T>
INLINE_FUNCTION_HD quadruple<T> operator*
(
const quadruple<T> & oprnd1,
const quadruple<T> & oprnd2
);
INLINE_FUNCTION_HD quadruple<T>
operator*(const quadruple<T>& oprnd1, const quadruple<T>& oprnd2);
template<typename T>
INLINE_FUNCTION_HD quadruple<T> operator*
(
const quadruple<T> & oprnd1,
const T & oprnd2
);
INLINE_FUNCTION_HD quadruple<T>
operator*(const quadruple<T>& oprnd1, const T& oprnd2);
template<typename T>
INLINE_FUNCTION_HD quadruple<T> operator*
(
const T & oprnd1,
const quadruple<T> & oprnd2
);
INLINE_FUNCTION_HD quadruple<T>
operator*(const T& oprnd1, const quadruple<T>& oprnd2);
template<typename T>
INLINE_FUNCTION_HD quadruple<T> operator/
(
const quadruple<T> & oprnd1,
const quadruple<T> & oprnd2
);
INLINE_FUNCTION_HD quadruple<T>
operator/(const quadruple<T>& oprnd1, const quadruple<T>& oprnd2);
template<typename T>
INLINE_FUNCTION_HD quadruple<T> operator/
(
const quadruple<T> & oprnd1,
const T & oprnd2
);
INLINE_FUNCTION_HD quadruple<T>
operator/(const quadruple<T>& oprnd1, const T& oprnd2);
template<typename T>
INLINE_FUNCTION_HD quadruple<T> operator/
(
const T & oprnd1,
const quadruple<T> & oprnd2
);
INLINE_FUNCTION_HD quadruple<T>
operator/(const T& oprnd1, const quadruple<T>& oprnd2);
template<typename T>
INLINE_FUNCTION_HD bool operator ==
(
const quadruple<T> &opr1,
const quadruple<T> &opr2
);
INLINE_FUNCTION_HD bool
operator==(const quadruple<T>& opr1, const quadruple<T>& opr2);
template<typename T>
INLINE_FUNCTION_H iOstream& operator<<
(
iOstream& str,
const quadruple<T> & ov
);
INLINE_FUNCTION_H iOstream&
operator<<(iOstream& str, const quadruple<T>& ov);
template<typename T>
INLINE_FUNCTION_H iIstream& operator>>
(
iIstream& str,
quadruple<T> & iv
);
INLINE_FUNCTION_H iIstream&
operator>>(iIstream& str, quadruple<T>& iv);
template<typename T>
INLINE_FUNCTION_H void readIstream
(
iIstream& str,
quadruple<T> & iv
);
INLINE_FUNCTION_H void
readIstream(iIstream& str, quadruple<T>& iv);

View File

@ -19,28 +19,22 @@ Licence:
-----------------------------------------------------------------------------*/
template<typename T>
INLINE_FUNCTION_HD T pFlow::dot
(
const quadruple<T> & oprnd1,
const quadruple<T> & oprnd2
)
INLINE_FUNCTION_HD T
pFlow::dot(const quadruple<T>& oprnd1, const quadruple<T>& oprnd2)
{
return oprnd1.s_ * oprnd2.s_ +
dot(oprnd1.v(), oprnd2.v()) ;
return oprnd1.s_ * oprnd2.s_ + dot(oprnd1.v(), oprnd2.v());
}
template<typename T>
INLINE_FUNCTION_HD T pFlow::quadruple<T>::length
(
)const
INLINE_FUNCTION_HD T
pFlow::quadruple<T>::length() const
{
return sqrt(dot(*this, *this));
}
template<typename T>
INLINE_FUNCTION_HD void pFlow::quadruple<T>::normalize
(
)
INLINE_FUNCTION_HD void
pFlow::quadruple<T>::normalize()
{
T l = length();
if (static_cast<real>(l) > smallValue)
@ -50,249 +44,148 @@ INLINE_FUNCTION_HD void pFlow::quadruple<T>::normalize
}
template<typename T>
INLINE_FUNCTION_HD pFlow::quadruple<T> pFlow::operator+
(
const quadruple<T> & oprnd1,
const quadruple<T> & oprnd2
)
INLINE_FUNCTION_HD pFlow::quadruple<T>
pFlow::operator+(const quadruple<T>& oprnd1, const quadruple<T>& oprnd2)
{
return quadruple<T>(
oprnd1.s_ + oprnd2.s_,
oprnd1.v_ + oprnd2.v_
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::quadruple<T> pFlow::operator+
(
const quadruple<T> & oprnd1,
const T & oprnd2
)
{
return quadruple<T>(
oprnd1.s_ + oprnd2,
oprnd1.v_ + oprnd2
);
return quadruple<T>(oprnd1.s_ + oprnd2.s_, oprnd1.v_ + oprnd2.v_);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::quadruple<T> pFlow::operator+
(
const T & oprnd1,
const quadruple<T> & oprnd2
)
INLINE_FUNCTION_HD pFlow::quadruple<T>
pFlow::operator+(const quadruple<T>& oprnd1, const T& oprnd2)
{
return quadruple<T>(
oprnd1 + oprnd2.s_,
oprnd1 + oprnd2.v_
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::quadruple<T> pFlow::operator-
(
const quadruple<T> & oprnd1,
const quadruple<T> & oprnd2
)
{
return quadruple<T>(
oprnd1.s_ - oprnd2.s_,
oprnd1.v_ - oprnd2.v_
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::quadruple<T> pFlow::operator-
(
const quadruple<T> & oprnd1,
const T & oprnd2
)
{
return quadruple<T>(
oprnd1.s_ - oprnd2,
oprnd1.v_ - oprnd2
);
return quadruple<T>(oprnd1.s_ + oprnd2, oprnd1.v_ + oprnd2);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::quadruple<T> pFlow::operator-
(
const T & oprnd1,
const quadruple<T> & oprnd2
)
INLINE_FUNCTION_HD pFlow::quadruple<T>
pFlow::operator+(const T& oprnd1, const quadruple<T>& oprnd2)
{
return quadruple<T>(
oprnd1 - oprnd2.s_,
oprnd1 - oprnd2.v_
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::quadruple<T> pFlow::operator*
(
const quadruple<T> & oprnd1,
const quadruple<T> & oprnd2
)
{
return quadruple<T>(
oprnd1.s_ * oprnd2.s_,
oprnd1.v_ * oprnd2.v_
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::quadruple<T> pFlow::operator*
(
const quadruple<T> & oprnd1,
const T & oprnd2
)
{
return quadruple<T>(
oprnd1.s_ * oprnd2,
oprnd1.v_ * oprnd2
);
return quadruple<T>(oprnd1 + oprnd2.s_, oprnd1 + oprnd2.v_);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::quadruple<T> pFlow::operator*
(
const T & oprnd1,
const quadruple<T> & oprnd2
)
INLINE_FUNCTION_HD pFlow::quadruple<T>
pFlow::operator-(const quadruple<T>& oprnd1, const quadruple<T>& oprnd2)
{
return quadruple<T>(
oprnd1 * oprnd2.s_,
oprnd1 * oprnd2.v_
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::quadruple<T> pFlow::operator/
(
const quadruple<T> & oprnd1,
const quadruple<T> & oprnd2
)
{
return quadruple<T>(
oprnd1.s_ / oprnd2.s_,
oprnd1.v_ / oprnd2.v_
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::quadruple<T> pFlow::operator/
(
const quadruple<T> & oprnd1,
const T & oprnd2
)
{
return quadruple<T>(
oprnd1.s_ / oprnd2,
oprnd1.v_ / oprnd2
);
return quadruple<T>(oprnd1.s_ - oprnd2.s_, oprnd1.v_ - oprnd2.v_);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::quadruple<T> pFlow::operator/
(
const T & oprnd1,
const quadruple<T> & oprnd2
)
INLINE_FUNCTION_HD pFlow::quadruple<T>
pFlow::operator-(const quadruple<T>& oprnd1, const T& oprnd2)
{
return quadruple<T>(
oprnd1 / oprnd2.s_,
oprnd1 / oprnd2.v_
);
return quadruple<T>(oprnd1.s_ - oprnd2, oprnd1.v_ - oprnd2);
}
template<typename T>
INLINE_FUNCTION_HD void pFlow::quadruple<T>::operator+=
(
const quadruple<T> & oprnd2
)
INLINE_FUNCTION_HD pFlow::quadruple<T>
pFlow::operator-(const T& oprnd1, const quadruple<T>& oprnd2)
{
return quadruple<T>(oprnd1 - oprnd2.s_, oprnd1 - oprnd2.v_);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::quadruple<T>
pFlow::operator*(const quadruple<T>& oprnd1, const quadruple<T>& oprnd2)
{
return quadruple<T>(oprnd1.s_ * oprnd2.s_, oprnd1.v_ * oprnd2.v_);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::quadruple<T>
pFlow::operator*(const quadruple<T>& oprnd1, const T& oprnd2)
{
return quadruple<T>(oprnd1.s_ * oprnd2, oprnd1.v_ * oprnd2);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::quadruple<T>
pFlow::operator*(const T& oprnd1, const quadruple<T>& oprnd2)
{
return quadruple<T>(oprnd1 * oprnd2.s_, oprnd1 * oprnd2.v_);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::quadruple<T>
pFlow::operator/(const quadruple<T>& oprnd1, const quadruple<T>& oprnd2)
{
return quadruple<T>(oprnd1.s_ / oprnd2.s_, oprnd1.v_ / oprnd2.v_);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::quadruple<T>
pFlow::operator/(const quadruple<T>& oprnd1, const T& oprnd2)
{
return quadruple<T>(oprnd1.s_ / oprnd2, oprnd1.v_ / oprnd2);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::quadruple<T>
pFlow::operator/(const T& oprnd1, const quadruple<T>& oprnd2)
{
return quadruple<T>(oprnd1 / oprnd2.s_, oprnd1 / oprnd2.v_);
}
template<typename T>
INLINE_FUNCTION_HD void
pFlow::quadruple<T>::operator+=(const quadruple<T>& oprnd2)
{
this->s_ += oprnd2.s_;
this->v_ += oprnd2.v_;
}
template<typename T>
INLINE_FUNCTION_HD void pFlow::quadruple<T>::operator-=
(
const quadruple<T> & oprnd2
)
INLINE_FUNCTION_HD void
pFlow::quadruple<T>::operator-=(const quadruple<T>& oprnd2)
{
this->s_ -= oprnd2.s_;
this->v_ -= oprnd2.v_;
}
template<typename T>
INLINE_FUNCTION_HD void pFlow::quadruple<T>::operator*=
(
const quadruple<T> & oprnd2
)
INLINE_FUNCTION_HD void
pFlow::quadruple<T>::operator*=(const quadruple<T>& oprnd2)
{
this->s_ *= oprnd2.s_;
this->v_ *= oprnd2.v_;
}
template<typename T>
INLINE_FUNCTION_HD void pFlow::quadruple<T>::operator/=
(
const quadruple<T> & oprnd2
)
INLINE_FUNCTION_HD void
pFlow::quadruple<T>::operator/=(const quadruple<T>& oprnd2)
{
this->s_ /= oprnd2.s_;
this->v_ /= oprnd2.v_;
}
template<typename T>
INLINE_FUNCTION_HD pFlow::quadruple<T> pFlow::quadruple<T>::operator-
(
) const
INLINE_FUNCTION_HD pFlow::quadruple<T>
pFlow::quadruple<T>::operator-() const
{
return quadruple<T>(-this->s_, -this->v_);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::quadruple<T> pFlow::quadruple<T>::operator+
(
) const
INLINE_FUNCTION_HD pFlow::quadruple<T>
pFlow::quadruple<T>::operator+() const
{
return *this;
}
template<typename T>
INLINE_FUNCTION_HD bool pFlow::operator ==
(
const quadruple<T> &opr1,
const quadruple<T> &opr2
){
INLINE_FUNCTION_HD bool
pFlow::operator==(const quadruple<T>& opr1, const quadruple<T>& opr2)
{
return equal(opr1.s_, opr2.s_) && equal(opr1.v_, opr2.v_);
};
template<typename T>
INLINE_FUNCTION_H pFlow::iOstream& pFlow::operator <<
(
iOstream & str,
const quadruple<T> & ov
)
INLINE_FUNCTION_H pFlow::iOstream&
pFlow::operator<<(iOstream& str, const quadruple<T>& ov)
{
str << token::BEGIN_LIST << ov.w()
<< token::SPACE << ov.x()
<< token::SPACE << ov.y()
<< token::SPACE << ov.z()
<< token::END_LIST;
str << token::BEGIN_LIST << ov.w() << token::SPACE << ov.x() << token::SPACE
<< ov.y() << token::SPACE << ov.z() << token::END_LIST;
str.check(FUNCTION_NAME);
@ -300,13 +193,9 @@ INLINE_FUNCTION_H pFlow::iOstream& pFlow::operator <<
}
template<typename T>
INLINE_FUNCTION_H pFlow::iIstream& pFlow::operator >>
(
iIstream & str,
quadruple<T> & iv
)
INLINE_FUNCTION_H pFlow::iIstream&
pFlow::operator>>(iIstream& str, quadruple<T>& iv)
{
str.readBegin("quadruple<T>");
str >> iv.w();
@ -322,13 +211,9 @@ INLINE_FUNCTION_H pFlow::iIstream& pFlow::operator >>
}
template<typename T>
INLINE_FUNCTION_H void pFlow::readIstream
(
iIstream & str,
quadruple<T> & iv
)
INLINE_FUNCTION_H void
pFlow::readIstream(iIstream& str, quadruple<T>& iv)
{
str.readBegin("quadruple<T>");
T val;
@ -347,5 +232,4 @@ INLINE_FUNCTION_H void pFlow::readIstream
str.readEnd("quadruple<T>");
str.check(FUNCTION_NAME);
}

View File

@ -27,9 +27,13 @@ inline pFlow::quadruple<T> pFlow::fnName(const quadruple<T>& q) \
#define Q4Func2(fnName) \
template<typename T> \
inline pFlow::quadruple<T> pFlow::fnName(const quadruple<T>& arg1, const quadruple<T>& arg2) \
inline pFlow::quadruple<T> pFlow::fnName( \
const quadruple<T>& arg1, const quadruple<T>& arg2 \
) \
{ \
return quadruple<T>(fnName(arg1.s_, arg2.s_), fnName(arg1.v_,arg2.v_)); \
return quadruple<T>( \
fnName(arg1.s_, arg2.s_), fnName(arg1.v_, arg2.v_) \
); \
}
//* * * * * * * * * * * List of functinos * * * * * * * * //
@ -39,7 +43,6 @@ inline pFlow::quadruple<T> pFlow::fnName(const quadruple<T>& arg1, const quadrup
// min, max
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * //
Q4Func(abs);
Q4Func2(mod);
Q4Func(exp);
@ -64,28 +67,28 @@ Q4Func(atanh);
Q4Func2(min);
Q4Func2(max);
template<typename T>
inline pFlow::quadruple<T> pFlow::pow(const quadruple<T>& q4, T e)
inline pFlow::quadruple<T>
pFlow::pow(const quadruple<T>& q4, T e)
{
return quadruple<T>(pow(q4.s_, e), pow(q4.v_, e));
}
// return the min of 3 elements x, y, z
template<typename T>
inline T pFlow::min(const quadruple<T>& q4)
inline T
pFlow::min(const quadruple<T>& q4)
{
return min(min(q4.v_), q4.s_);
}
// return the max of 3 elements x, y, z
template<typename T>
inline T pFlow::max(const quadruple<T>& q4)
inline T
pFlow::max(const quadruple<T>& q4)
{
return max(max(q4.v_), q4.s_);
}
#undef Q4Func
#undef Q4Func2

View File

@ -27,14 +27,12 @@ Licence:
#include "iIstream.hpp"
#include "error.hpp"
namespace pFlow
{
/// - Forward
template<typename T> class triple;
template<typename T>
class triple;
#include "tripleFwd.hpp"
@ -55,26 +53,28 @@ struct triple
/// Initilize to zero
INLINE_FUNCTION_HD
triple():
x_(0),
y_(0),
z_(0)
{}
triple()
: x_(),
y_(),
z_()
{
}
/// Construct from x, y, z
INLINE_FUNCTION_HD
triple(const T &x, const T &y, const T &z):
x_(x),
triple(const T& x, const T& y, const T& z)
: x_(x),
y_(y),
z_(z)
{}
{
}
/// Construct from v
INLINE_FUNCTION_HD
triple(const T &v):
triple(v, v, v)
{}
triple(const T& v)
: triple(v, v, v)
{
}
/// Type conversion trough assignment
template<typename T2>
@ -89,18 +89,16 @@ struct triple
/// Type casting through copy constructor
template<typename T2>
INLINE_FUNCTION_HD triple(const triple<T2>& src)
:
x_(static_cast<T>(src.x_)),
: x_(static_cast<T>(src.x_)),
y_(static_cast<T>(src.y_)),
z_(static_cast<T>(src.z_))
{}
{
}
/// Copy construct
INLINE_FUNCTION_HD
triple(const triple<T>& src) = default;
/// Move construct
INLINE_FUNCTION_HD
triple(triple<T>&& src) = default;
@ -129,48 +127,86 @@ struct triple
////// member methods
/// access component
INLINE_FUNCTION_HD T & x(){ return x_; }
INLINE_FUNCTION_HD T& x()
{
return x_;
}
/// access component
INLINE_FUNCTION_HD const T & x()const { return x_; }
INLINE_FUNCTION_HD const T& x() const
{
return x_;
}
/// access component
INLINE_FUNCTION_HD T & y(){ return y_; }
INLINE_FUNCTION_HD T& y()
{
return y_;
}
/// access component
INLINE_FUNCTION_HD const T & y()const { return y_; }
INLINE_FUNCTION_HD const T& y() const
{
return y_;
}
/// access component
INLINE_FUNCTION_HD T & z(){ return z_; }
INLINE_FUNCTION_HD T& z()
{
return z_;
}
/// access component
INLINE_FUNCTION_HD const T & z()const { return z_; }
INLINE_FUNCTION_HD const T& z() const
{
return z_;
}
/// access component
INLINE_FUNCTION_HD T & comp1(){ return x_; }
INLINE_FUNCTION_HD T& comp1()
{
return x_;
}
/// access component
INLINE_FUNCTION_HD const T & comp1()const { return x_; }
INLINE_FUNCTION_HD const T& comp1() const
{
return x_;
}
/// access component
INLINE_FUNCTION_HD T & comp2(){ return y_; }
INLINE_FUNCTION_HD T& comp2()
{
return y_;
}
/// access component
INLINE_FUNCTION_HD const T & comp2()const { return y_; }
INLINE_FUNCTION_HD const T& comp2() const
{
return y_;
}
/// access component
INLINE_FUNCTION_HD T & comp3(){ return z_; }
INLINE_FUNCTION_HD T& comp3()
{
return z_;
}
/// access component
INLINE_FUNCTION_HD const T & comp3()const { return z_; }
INLINE_FUNCTION_HD const T& comp3() const
{
return z_;
}
//// methods
/// Dot product of two vectors
friend FUNCTION_HD T dot <T> (const triple<T> & oprnd1, const triple<T> & oprnd2);
friend FUNCTION_HD T
dot<T>(const triple<T>& oprnd1, const triple<T>& oprnd2);
/// Cross product of two vectors
friend FUNCTION_HD triple<T> cross <T>(const triple<T> & v1, const triple<T> & v2);
friend FUNCTION_HD triple<T>
cross<T>(const triple<T>& v1, const triple<T>& v2);
/// Length of the vector
INLINE_FUNCTION_HD T length() const;
@ -181,33 +217,44 @@ struct triple
//// operators
/// + operator
friend FUNCTION_HD triple<T> operator+ <T> (const triple<T> & oprnd1, const triple<T> & oprnd2);
friend FUNCTION_HD triple<T> operator+
<T>(const triple<T>& oprnd1, const triple<T>& oprnd2);
friend FUNCTION_HD triple<T> operator+ <T> (const triple<T> & oprnd1, const T & oprnd2);
friend FUNCTION_HD triple<T> operator+
<T>(const triple<T>& oprnd1, const T& oprnd2);
friend FUNCTION_HD triple<T> operator+ <T> (const T & oprnd1, const triple<T> & oprnd2);
friend FUNCTION_HD triple<T> operator+
<T>(const T& oprnd1, const triple<T>& oprnd2);
/// - operator
friend FUNCTION_HD triple<T> operator - <T> (const triple<T> & oprnd1, const triple<T> & oprnd2);
friend FUNCTION_HD triple<T> operator-
<T>(const triple<T>& oprnd1, const triple<T>& oprnd2);
friend FUNCTION_HD triple<T> operator - <T> (const triple<T> & oprnd1, const T & oprnd2);
friend FUNCTION_HD triple<T> operator-
<T>(const triple<T>& oprnd1, const T& oprnd2);
friend FUNCTION_HD triple<T> operator - <T> (const T & oprnd1, const triple<T> & oprnd2);
friend FUNCTION_HD triple<T> operator-
<T>(const T& oprnd1, const triple<T>& oprnd2);
/// * operators
friend FUNCTION_HD triple<T> operator * <T> (const triple<T> & oprnd1, const triple<T> & oprnd2);
friend FUNCTION_HD triple<T> operator*
<T>(const triple<T>& oprnd1, const triple<T>& oprnd2);
friend FUNCTION_HD triple<T> operator * <T> (const triple<T> & oprnd1, const T & oprnd2);
friend FUNCTION_HD triple<T> operator*
<T>(const triple<T>& oprnd1, const T& oprnd2);
friend FUNCTION_HD triple<T> operator * <T> (const T & oprnd1, const triple<T> & oprnd2);
friend FUNCTION_HD triple<T> operator*
<T>(const T& oprnd1, const triple<T>& oprnd2);
/// / operators
friend FUNCTION_HD triple<T> operator / <T> (const triple<T> & oprnd1, const triple<T> & oprnd2);
friend FUNCTION_HD triple<T> operator/
<T>(const triple<T>& oprnd1, const triple<T>& oprnd2);
friend FUNCTION_HD triple<T> operator / <T> (const triple<T> & oprnd1, const T & oprnd2);
friend FUNCTION_HD triple<T> operator / <T> (const T & oprnd1, const triple<T> & oprnd2);
friend FUNCTION_HD triple<T> operator/
<T>(const triple<T>& oprnd1, const T& oprnd2);
friend FUNCTION_HD triple<T> operator/
<T>(const T& oprnd1, const triple<T>& oprnd2);
INLINE_FUNCTION_HD void operator+=(const triple& oprnd2);
@ -217,23 +264,26 @@ struct triple
INLINE_FUNCTION_HD void operator/=(const triple& oprnd2);
/// unary negate operator
INLINE_FUNCTION_HD triple operator-() const;
/// unary plus operator
INLINE_FUNCTION_HD triple operator+() const;
friend FUNCTION_HD bool operator==
<T>(const triple<T>& opr1, const triple<T>& opr2);
friend FUNCTION_HD bool operator == <T> (const triple<T> &opr1, const triple<T> &opr2);
friend FUNCTION_HD bool
operator< <T>(const triple<T>& opr1, const triple<T>& opr2);
friend FUNCTION_HD bool operator < <T> (const triple<T> &opr1, const triple<T> &opr2);
friend FUNCTION_HD bool operator>
<T>(const triple<T>& opr1, const triple<T>& opr2);
friend FUNCTION_HD bool operator > <T> (const triple<T> &opr1, const triple<T> &opr2);
friend FUNCTION_HD bool operator>=
<T>(const triple<T>& opr1, const triple<T>& opr2);
friend FUNCTION_HD bool operator >= <T> (const triple<T> &opr1, const triple<T> &opr2);
friend FUNCTION_HD bool operator <= <T> (const triple<T> &opr1, const triple<T> &opr2);
friend FUNCTION_HD bool operator<=
<T>(const triple<T>& opr1, const triple<T>& opr2);
//// IO operators
@ -245,27 +295,22 @@ struct triple
/// same as >> operator, but faster, good for mass read
friend void readIstream<T>(iIstream& str, triple<T>& iv);
};
template<typename T>
bool INLINE_FUNCTION_HD equal( const triple<T>& opr1, const triple<T>& opr2);
bool INLINE_FUNCTION_HD
equal(const triple<T>& opr1, const triple<T>& opr2);
bool
INLINE_FUNCTION_HD
bool INLINE_FUNCTION_HD
equal(const triple<real>& opr1, const triple<real>& opr2, real tol)
{
return equal( opr1.x(), opr2.x(), tol ) &&
equal( opr1.y(), opr2.y(), tol ) &&
return equal(opr1.x(), opr2.x(), tol) && equal(opr1.y(), opr2.y(), tol) &&
equal(opr1.z(), opr2.z(), tol);
}
} /// end of pFlow
#include "tripleI.hpp"
#include "tripleMath.hpp"
#endif

View File

@ -19,171 +19,97 @@ Licence:
-----------------------------------------------------------------------------*/
template<typename T>
INLINE_FUNCTION_HD T dot
(
const triple<T> & oprnd1,
const triple<T> & oprnd2
);
INLINE_FUNCTION_HD T
dot(const triple<T>& oprnd1, const triple<T>& oprnd2);
template<typename T>
INLINE_FUNCTION_HD triple<T> cross
(
const triple<T> & v1,
const triple<T> & v2
);
INLINE_FUNCTION_HD triple<T>
cross(const triple<T>& v1, const triple<T>& v2);
template<typename T>
INLINE_FUNCTION_HD T length
(
const triple<T> & v1
);
INLINE_FUNCTION_HD T
length(const triple<T>& v1);
template<typename T>
INLINE_FUNCTION_HD triple<T> normalize
(
const triple<T>& v1
);
INLINE_FUNCTION_HD triple<T>
normalize(const triple<T>& v1);
template<typename T>
INLINE_FUNCTION_HD triple<T> operator +
(
const triple<T> & oprnd1,
const triple<T> & oprnd2
);
INLINE_FUNCTION_HD triple<T>
operator+(const triple<T>& oprnd1, const triple<T>& oprnd2);
template<typename T>
INLINE_FUNCTION_HD triple<T> operator+
(
const triple<T> & oprnd1,
const T & oprnd2
);
INLINE_FUNCTION_HD triple<T>
operator+(const triple<T>& oprnd1, const T& oprnd2);
template<typename T>
INLINE_FUNCTION_HD triple<T> operator+
(
const T & oprnd2,
const triple<T> & oprnd1
);
INLINE_FUNCTION_HD triple<T>
operator+(const T& oprnd2, const triple<T>& oprnd1);
template<typename T>
INLINE_FUNCTION_HD triple<T> operator-
(
const triple<T> & oprnd1,
const triple<T> & oprnd2
);
INLINE_FUNCTION_HD triple<T>
operator-(const triple<T>& oprnd1, const triple<T>& oprnd2);
template<typename T>
INLINE_FUNCTION_HD triple<T> operator-
(
const triple<T> & oprnd1,
const T & oprnd2
);
INLINE_FUNCTION_HD triple<T>
operator-(const triple<T>& oprnd1, const T& oprnd2);
template<typename T>
INLINE_FUNCTION_HD triple<T> operator-
(
const T & oprnd1,
const triple<T> & oprnd2
);
INLINE_FUNCTION_HD triple<T>
operator-(const T& oprnd1, const triple<T>& oprnd2);
template<typename T>
INLINE_FUNCTION_HD triple<T> operator*
(
const triple<T> & oprnd1,
const triple<T> & oprnd2
);
INLINE_FUNCTION_HD triple<T>
operator*(const triple<T>& oprnd1, const triple<T>& oprnd2);
template<typename T>
INLINE_FUNCTION_HD triple<T> operator*
(
const triple<T> & oprnd1,
const T & oprnd2
);
INLINE_FUNCTION_HD triple<T>
operator*(const triple<T>& oprnd1, const T& oprnd2);
template<typename T>
INLINE_FUNCTION_HD triple<T> operator*
(
const T & oprnd1,
const triple<T> & oprnd2
);
INLINE_FUNCTION_HD triple<T>
operator*(const T& oprnd1, const triple<T>& oprnd2);
template<typename T>
INLINE_FUNCTION_HD triple<T> operator/
(
const triple<T> & oprnd1,
const triple<T> & oprnd2
);
INLINE_FUNCTION_HD triple<T>
operator/(const triple<T>& oprnd1, const triple<T>& oprnd2);
template<typename T>
INLINE_FUNCTION_HD triple<T> operator/
(
const triple<T> & oprnd1,
const T & oprnd2
);
INLINE_FUNCTION_HD triple<T>
operator/(const triple<T>& oprnd1, const T& oprnd2);
template<typename T>
INLINE_FUNCTION_HD triple<T> operator/
(
const T & oprnd1,
const triple<T> & oprnd2
);
INLINE_FUNCTION_HD triple<T>
operator/(const T& oprnd1, const triple<T>& oprnd2);
template<typename T>
INLINE_FUNCTION_HD bool operator ==
(
const triple<T> &opr1,
const triple<T> &opr2
);
INLINE_FUNCTION_HD bool
operator==(const triple<T>& opr1, const triple<T>& opr2);
template<typename T>
INLINE_FUNCTION_HD bool operator >
(
const triple<T> &opr1,
const triple<T> &opr2
);
INLINE_FUNCTION_HD bool
operator>(const triple<T>& opr1, const triple<T>& opr2);
template<typename T>
INLINE_FUNCTION_HD bool operator <
(
const triple<T> &opr1,
const triple<T> &opr2
);
INLINE_FUNCTION_HD bool
operator<(const triple<T>& opr1, const triple<T>& opr2);
template<typename T>
INLINE_FUNCTION_HD bool operator <=
(
const triple<T> &opr1,
const triple<T> &opr2
);
INLINE_FUNCTION_HD bool
operator<=(const triple<T>& opr1, const triple<T>& opr2);
template<typename T>
INLINE_FUNCTION_HD bool operator >=
(
const triple<T> &opr1,
const triple<T> &opr2
);
INLINE_FUNCTION_HD bool
operator>=(const triple<T>& opr1, const triple<T>& opr2);
template<typename T>
INLINE_FUNCTION iOstream& operator<<
(
iOstream& str,
const triple<T> & ov
);
INLINE_FUNCTION iOstream&
operator<<(iOstream& str, const triple<T>& ov);
template<typename T>
INLINE_FUNCTION iIstream& operator>>
(
iIstream& str,
triple<T> & iv
);
INLINE_FUNCTION iIstream&
operator>>(iIstream& str, triple<T>& iv);
template<typename T>
INLINE_FUNCTION void readIstream
(
iIstream& str,
triple<T> & iv
);
INLINE_FUNCTION void
readIstream(iIstream& str, triple<T>& iv);

View File

@ -19,23 +19,16 @@ Licence:
-----------------------------------------------------------------------------*/
template<typename T>
INLINE_FUNCTION_HD T pFlow::dot
(
const triple<T> & oprnd1,
const triple<T> & oprnd2
)
INLINE_FUNCTION_HD T
pFlow::dot(const triple<T>& oprnd1, const triple<T>& oprnd2)
{
return oprnd1.x_ * oprnd2.x_ +
oprnd1.y_ * oprnd2.y_ +
return oprnd1.x_ * oprnd2.x_ + oprnd1.y_ * oprnd2.y_ +
oprnd1.z_ * oprnd2.z_;
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T> pFlow::cross
(
const triple<T> & v1,
const triple<T> & v2
)
INLINE_FUNCTION_HD pFlow::triple<T>
pFlow::cross(const triple<T>& v1, const triple<T>& v2)
{
return triple<T>(
v1.y_ * v2.z_ - v1.z_ * v2.y_,
@ -45,216 +38,144 @@ INLINE_FUNCTION_HD pFlow::triple<T> pFlow::cross
}
template<typename T>
INLINE_FUNCTION_HD T pFlow::length
(
const triple<T> & v1
)
INLINE_FUNCTION_HD T
pFlow::length(const triple<T>& v1)
{
return v1.length();
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T> pFlow::normalize(const triple<T>& v1)
INLINE_FUNCTION_HD pFlow::triple<T>
pFlow::normalize(const triple<T>& v1)
{
return v1 / max(length(v1), verySmallValue);
}
template<typename T>
INLINE_FUNCTION_HD T pFlow::triple<T>::length
(
)const
INLINE_FUNCTION_HD T
pFlow::triple<T>::length() const
{
return sqrt(dot(*this, *this));
}
template<typename T>
INLINE_FUNCTION_HD void pFlow::triple<T>::normalize
(
)
INLINE_FUNCTION_HD void
pFlow::triple<T>::normalize()
{
*this = *this / max(length(), verySmallValue);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator+
(
const triple<T> & oprnd1,
const triple<T> & oprnd2
)
INLINE_FUNCTION_HD pFlow::triple<T>
pFlow::operator+(const triple<T>& oprnd1, const triple<T>& oprnd2)
{
return triple<T>(
oprnd1.x_ + oprnd2.x_,
oprnd1.y_ + oprnd2.y_,
oprnd1.z_ + oprnd2.z_
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator+
(
const triple<T> & oprnd1,
const T & oprnd2
)
{
return triple<T>(
oprnd1.x_ + oprnd2,
oprnd1.y_ + oprnd2,
oprnd1.z_ + oprnd2
oprnd1.x_ + oprnd2.x_, oprnd1.y_ + oprnd2.y_, oprnd1.z_ + oprnd2.z_
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator+
(
const T & oprnd1,
const triple<T> & oprnd2
)
INLINE_FUNCTION_HD pFlow::triple<T>
pFlow::operator+(const triple<T>& oprnd1, const T& oprnd2)
{
return triple<T>(
oprnd1 + oprnd2.x_,
oprnd1 + oprnd2.y_,
oprnd1 + oprnd2.z_
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator-
(
const triple<T> & oprnd1,
const triple<T> & oprnd2
)
{
return triple<T>(
oprnd1.x_ - oprnd2.x_,
oprnd1.y_ - oprnd2.y_,
oprnd1.z_ - oprnd2.z_
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator-
(
const triple<T> & oprnd1,
const T & oprnd2
)
{
return triple<T>(
oprnd1.x_ - oprnd2,
oprnd1.y_ - oprnd2,
oprnd1.z_ - oprnd2
oprnd1.x_ + oprnd2, oprnd1.y_ + oprnd2, oprnd1.z_ + oprnd2
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator-
(
const T & oprnd1,
const triple<T> & oprnd2
)
INLINE_FUNCTION_HD pFlow::triple<T>
pFlow::operator+(const T& oprnd1, const triple<T>& oprnd2)
{
return triple<T>(
oprnd1 - oprnd2.x_,
oprnd1 - oprnd2.y_,
oprnd1 - oprnd2.z_
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator*
(
const triple<T> & oprnd1,
const triple<T> & oprnd2
)
{
return triple<T>(
oprnd1.x_ * oprnd2.x_,
oprnd1.y_ * oprnd2.y_,
oprnd1.z_ * oprnd2.z_
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator*
(
const triple<T> & oprnd1,
const T & oprnd2
)
{
return triple<T>(
oprnd1.x_ * oprnd2,
oprnd1.y_ * oprnd2,
oprnd1.z_ * oprnd2
oprnd1 + oprnd2.x_, oprnd1 + oprnd2.y_, oprnd1 + oprnd2.z_
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator*
(
const T & oprnd1,
const triple<T> & oprnd2
)
INLINE_FUNCTION_HD pFlow::triple<T>
pFlow::operator-(const triple<T>& oprnd1, const triple<T>& oprnd2)
{
return triple<T>(
oprnd1 * oprnd2.x_,
oprnd1 * oprnd2.y_,
oprnd1 * oprnd2.z_
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator/
(
const triple<T> & oprnd1,
const triple<T> & oprnd2
)
{
return triple<T>(
oprnd1.x_ / oprnd2.x_,
oprnd1.y_ / oprnd2.y_,
oprnd1.z_ / oprnd2.z_
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator/
(
const triple<T> & oprnd1,
const T & oprnd2
)
{
return triple<T>(
oprnd1.x_ / oprnd2,
oprnd1.y_ / oprnd2,
oprnd1.z_ / oprnd2
oprnd1.x_ - oprnd2.x_, oprnd1.y_ - oprnd2.y_, oprnd1.z_ - oprnd2.z_
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T> pFlow::operator/
(
const T & oprnd1,
const triple<T> & oprnd2
)
INLINE_FUNCTION_HD pFlow::triple<T>
pFlow::operator-(const triple<T>& oprnd1, const T& oprnd2)
{
return triple<T>(
oprnd1 / oprnd2.x_,
oprnd1 / oprnd2.y_,
oprnd1 / oprnd2.z_
oprnd1.x_ - oprnd2, oprnd1.y_ - oprnd2, oprnd1.z_ - oprnd2
);
}
template<typename T>
INLINE_FUNCTION_HD void pFlow::triple<T>::operator+=
(
const triple<T> & oprnd2
)
INLINE_FUNCTION_HD pFlow::triple<T>
pFlow::operator-(const T& oprnd1, const triple<T>& oprnd2)
{
return triple<T>(
oprnd1 - oprnd2.x_, oprnd1 - oprnd2.y_, oprnd1 - oprnd2.z_
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T>
pFlow::operator*(const triple<T>& oprnd1, const triple<T>& oprnd2)
{
return triple<T>(
oprnd1.x_ * oprnd2.x_, oprnd1.y_ * oprnd2.y_, oprnd1.z_ * oprnd2.z_
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T>
pFlow::operator*(const triple<T>& oprnd1, const T& oprnd2)
{
return triple<T>(
oprnd1.x_ * oprnd2, oprnd1.y_ * oprnd2, oprnd1.z_ * oprnd2
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T>
pFlow::operator*(const T& oprnd1, const triple<T>& oprnd2)
{
return triple<T>(
oprnd1 * oprnd2.x_, oprnd1 * oprnd2.y_, oprnd1 * oprnd2.z_
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T>
pFlow::operator/(const triple<T>& oprnd1, const triple<T>& oprnd2)
{
return triple<T>(
oprnd1.x_ / oprnd2.x_, oprnd1.y_ / oprnd2.y_, oprnd1.z_ / oprnd2.z_
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T>
pFlow::operator/(const triple<T>& oprnd1, const T& oprnd2)
{
return triple<T>(
oprnd1.x_ / oprnd2, oprnd1.y_ / oprnd2, oprnd1.z_ / oprnd2
);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T>
pFlow::operator/(const T& oprnd1, const triple<T>& oprnd2)
{
return triple<T>(
oprnd1 / oprnd2.x_, oprnd1 / oprnd2.y_, oprnd1 / oprnd2.z_
);
}
template<typename T>
INLINE_FUNCTION_HD void
pFlow::triple<T>::operator+=(const triple<T>& oprnd2)
{
this->x_ = this->x_ + oprnd2.x_;
this->y_ = this->y_ + oprnd2.y_;
@ -262,10 +183,8 @@ INLINE_FUNCTION_HD void pFlow::triple<T>::operator+=
}
template<typename T>
INLINE_FUNCTION_HD void pFlow::triple<T>::operator-=
(
const triple<T> & oprnd2
)
INLINE_FUNCTION_HD void
pFlow::triple<T>::operator-=(const triple<T>& oprnd2)
{
this->x_ = this->x_ - oprnd2.x_;
this->y_ = this->y_ - oprnd2.y_;
@ -273,10 +192,8 @@ INLINE_FUNCTION_HD void pFlow::triple<T>::operator-=
}
template<typename T>
INLINE_FUNCTION_HD void pFlow::triple<T>::operator*=
(
const triple<T> & oprnd2
)
INLINE_FUNCTION_HD void
pFlow::triple<T>::operator*=(const triple<T>& oprnd2)
{
this->x_ = this->x_ * oprnd2.x_;
this->y_ = this->y_ * oprnd2.y_;
@ -284,10 +201,8 @@ INLINE_FUNCTION_HD void pFlow::triple<T>::operator*=
}
template<typename T>
INLINE_FUNCTION_HD void pFlow::triple<T>::operator/=
(
const triple<T> & oprnd2
)
INLINE_FUNCTION_HD void
pFlow::triple<T>::operator/=(const triple<T>& oprnd2)
{
this->x_ = this->x_ / oprnd2.x_;
this->y_ = this->y_ / oprnd2.y_;
@ -295,37 +210,29 @@ INLINE_FUNCTION_HD void pFlow::triple<T>::operator/=
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T> pFlow::triple<T>::operator-
(
) const
INLINE_FUNCTION_HD pFlow::triple<T>
pFlow::triple<T>::operator-() const
{
return triple<T>(-this->x_, -this->y_, -this->z_);
}
template<typename T>
INLINE_FUNCTION_HD pFlow::triple<T> pFlow::triple<T>::operator+
(
) const
INLINE_FUNCTION_HD pFlow::triple<T>
pFlow::triple<T>::operator+() const
{
return *this;
}
template<typename T>
INLINE_FUNCTION_HD bool pFlow::operator ==
(
const triple<T> &opr1,
const triple<T> &opr2
){
INLINE_FUNCTION_HD bool
pFlow::operator==(const triple<T>& opr1, const triple<T>& opr2)
{
return equal(opr1, opr2);
};
template<typename T>
INLINE_FUNCTION_HD bool pFlow::operator <
(
const triple<T> &opr1,
const triple<T> &opr2
)
INLINE_FUNCTION_HD bool
pFlow::operator<(const triple<T>& opr1, const triple<T>& opr2)
{
if (opr1.x_ < opr2.x_ && opr1.y_ < opr2.y_ && opr1.z_ < opr2.z_)
{
@ -338,11 +245,8 @@ INLINE_FUNCTION_HD bool pFlow::operator <
};
template<typename T>
INLINE_FUNCTION_HD bool pFlow::operator >
(
const triple<T> &opr1,
const triple<T> &opr2
)
INLINE_FUNCTION_HD bool
pFlow::operator>(const triple<T>& opr1, const triple<T>& opr2)
{
if (opr1.x_ > opr2.x_ && opr1.y_ > opr2.y_ && opr1.z_ > opr2.z_)
{
@ -355,11 +259,8 @@ INLINE_FUNCTION_HD bool pFlow::operator >
};
template<typename T>
INLINE_FUNCTION_HD bool pFlow::operator <=
(
const triple<T> &opr1,
const triple<T> &opr2
)
INLINE_FUNCTION_HD bool
pFlow::operator<=(const triple<T>& opr1, const triple<T>& opr2)
{
if (opr1.x_ <= opr2.x_ && opr1.y_ <= opr2.y_ && opr1.z_ <= opr2.z_)
{
@ -371,13 +272,9 @@ INLINE_FUNCTION_HD bool pFlow::operator <=
}
}
template<typename T>
INLINE_FUNCTION_HD bool pFlow::operator >=
(
const triple<T> &opr1,
const triple<T> &opr2
)
INLINE_FUNCTION_HD bool
pFlow::operator>=(const triple<T>& opr1, const triple<T>& opr2)
{
if (opr1.x_ >= opr2.x_ && opr1.y_ >= opr2.y_ && opr1.z_ >= opr2.z_)
{
@ -389,19 +286,12 @@ INLINE_FUNCTION_HD bool pFlow::operator >=
}
}
template<typename T>
INLINE_FUNCTION pFlow::iOstream& pFlow::operator <<
(
iOstream & str,
const triple<T> & ov
)
INLINE_FUNCTION pFlow::iOstream&
pFlow::operator<<(iOstream& str, const triple<T>& ov)
{
str << token::BEGIN_LIST << ov.x_
<< token::SPACE << ov.y_
<< token::SPACE << ov.z_
<< token::END_LIST;
str << token::BEGIN_LIST << ov.x_ << token::SPACE << ov.y_ << token::SPACE
<< ov.z_ << token::END_LIST;
str.check(FUNCTION_NAME);
@ -409,20 +299,15 @@ INLINE_FUNCTION pFlow::iOstream& pFlow::operator <<
}
template<typename T>
INLINE_FUNCTION pFlow::iIstream& pFlow::operator >>
(
iIstream & str,
triple<T> & iv
)
INLINE_FUNCTION pFlow::iIstream&
pFlow::operator>>(iIstream& str, triple<T>& iv)
{
str.readBegin("triple<T>");
str >> iv.x_;
str >> iv.y_;
str >> iv.z_;
str.readEnd("triple<T>");
str.check(FUNCTION_NAME);
@ -431,13 +316,9 @@ INLINE_FUNCTION pFlow::iIstream& pFlow::operator >>
}
template<typename T>
INLINE_FUNCTION void pFlow::readIstream
(
iIstream & str,
triple<T> & iv
)
INLINE_FUNCTION void
pFlow::readIstream(iIstream& str, triple<T>& iv)
{
str.readBegin("triple<T>");
T val;
@ -453,15 +334,12 @@ INLINE_FUNCTION void pFlow::readIstream
str.readEnd("triple<T>");
str.check(FUNCTION_NAME);
}
template<typename T>
bool INLINE_FUNCTION_HD pFlow::equal
(
const triple<T>& opr1,
const triple<T>& opr2
)
bool INLINE_FUNCTION_HD
pFlow::equal(const triple<T>& opr1, const triple<T>& opr2)
{
return equal( opr1.x(), opr2.x() ) && equal( opr1.y(), opr2.y() ) && equal( opr1.z(), opr2.z() );
return equal(opr1.x(), opr2.x()) && equal(opr1.y(), opr2.y()) &&
equal(opr1.z(), opr2.z());
}

View File

@ -31,9 +31,15 @@ INLINE_FUNCTION_HD triple<T> fnName(const triple<T>& v) \
#define T3Func2(fnName) \
template<typename T> \
INLINE_FUNCTION_HD triple<T> fnName(const triple<T>& arg1, const triple<T>& arg2) \
INLINE_FUNCTION_HD triple<T> fnName( \
const triple<T>& arg1, const triple<T>& arg2 \
) \
{ \
return triple<T>(fnName(arg1.x_, arg2.x_), fnName(arg1.y_,arg2.y_), fnName(arg1.z_, arg2.z_)); \
return triple<T>( \
fnName(arg1.x_, arg2.x_), \
fnName(arg1.y_, arg2.y_), \
fnName(arg1.z_, arg2.z_) \
); \
}
//* * * * * * * * * * * List of functinos * * * * * * * * //
@ -43,7 +49,6 @@ INLINE_FUNCTION_HD triple<T> fnName(const triple<T>& arg1, const triple<T>& arg2
// min, max
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * //
T3Func(abs);
T3Func2(mod);
T3Func(exp);
@ -72,27 +77,28 @@ T3Func2(max);
// elements of t3 raised by e
template<typename T>
INLINE_FUNCTION_HD triple<T> pow(const triple<T>& t3, T e)
INLINE_FUNCTION_HD triple<T>
pow(const triple<T>& t3, T e)
{
return triple<T>(pow(t3.x_, e), pow(t3.y_, e), pow(t3.z_, e));
}
// return the min of 3 elements x, y, z
template<typename T>
INLINE_FUNCTION_HD T min(const triple<T>& t3)
INLINE_FUNCTION_HD T
min(const triple<T>& t3)
{
return min(min(t3.x_, t3.y_), t3.z_);
}
// return the max of 3 elements x, y, z
template<typename T>
INLINE_FUNCTION_HD T max(const triple<T>& t3)
INLINE_FUNCTION_HD T
max(const triple<T>& t3)
{
return max(max(t3.x_, t3.y_), t3.z_);
}
#undef T3Func
#undef T3Func2

View File

@ -31,5 +31,4 @@ namespace pFlow
const realx4 zero4(zero);
} // pFlow

View File

@ -21,7 +21,6 @@ Licence:
#ifndef __types_hpp__
#define __types_hpp__
#include "bTypes.hpp"
#include "bTypesFunctions.hpp"
@ -32,7 +31,6 @@ Licence:
#include "typeInfo.hpp"
namespace pFlow
{
@ -52,48 +50,93 @@ using realx4 = quadruple<real>;
using realx4x3 = quadruple<realx3>;
template<>
inline word
basicTypeName<int8x3>()
{
return "int8x3";
}
template<>
inline word basicTypeName<int8x3>(){ return "int8x3"; }
inline word
basicTypeName<int32x3>()
{
return "int32x3";
}
template<>
inline word basicTypeName<int32x3>(){ return "int32x3"; }
inline word
basicTypeName<int64x3>()
{
return "int64x3";
}
template<>
inline word basicTypeName<int64x3>(){ return "int64x3"; }
inline word
basicTypeName<uint8x3>()
{
return "uint8x3";
}
template<>
inline word basicTypeName<uint8x3>(){ return "uint8x3"; }
inline word
basicTypeName<uint32x3>()
{
return "uint32x3";
}
template<>
inline word basicTypeName<uint32x3>(){ return "uint32x3"; }
inline word
basicTypeName<uint64x3>()
{
return "unit64x3";
}
template<>
inline word basicTypeName<uint64x3>(){ return "unit64x3"; }
inline word
basicTypeName<realx3>()
{
return "realx3";
}
template<>
inline word basicTypeName<realx3>(){ return "realx3"; }
inline word
basicTypeName<int32x3x3>()
{
return "int32x3x3";
}
template<>
inline word basicTypeName<int32x3x3>(){ return "int32x3x3"; }
inline word
basicTypeName<uint32x3x3>()
{
return "uint32x3x3";
}
template<>
inline word basicTypeName<uint32x3x3>(){ return "uint32x3x3"; }
inline word
basicTypeName<realx3x3>()
{
return "realx3x3";
}
template<>
inline word basicTypeName<realx3x3>(){ return "realx3x3"; }
inline word
basicTypeName<realx4>()
{
return "realx4";
}
template<>
inline word basicTypeName<realx4>(){ return "realx4"; }
template<>
inline word basicTypeName<realx4x3>(){ return "realx4x3"; }
inline word
basicTypeName<realx4x3>()
{
return "realx4x3";
}
extern const realx3 zero3;
extern const realx3 one3;
extern const realx3x3 zero33;
extern const realx3x3 one33;
@ -101,5 +144,4 @@ extern const realx4 zero4;
} // pFlow
#endif //__types_hpp__