format clang-format

This commit is contained in:
Hamidreza Norouzi
2024-04-08 12:33:08 -07:00
parent a9290e911b
commit ff8968e595
36 changed files with 3353 additions and 3505 deletions

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,113 +60,102 @@ 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> >;
Kokkos::IndexType<pFlow::uint32>>;
using hostRPolicyStatic =
Kokkos::RangePolicy<
using hostRPolicyStatic = Kokkos::RangePolicy<
Kokkos::DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Static>,
Kokkos::IndexType<pFlow::uint32> >;
Kokkos::IndexType<pFlow::uint32>>;
using deviceRPolicyDynamic =
Kokkos::RangePolicy<
using deviceRPolicyDynamic = Kokkos::RangePolicy<
Kokkos::DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Dynamic>,
Kokkos::IndexType<pFlow::uint32> >;
Kokkos::IndexType<pFlow::uint32>>;
using hostRPolicyDynamic =
Kokkos::RangePolicy<
using hostRPolicyDynamic = Kokkos::RangePolicy<
Kokkos::DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Dynamic>,
Kokkos::IndexType<pFlow::uint32> >;
Kokkos::IndexType<pFlow::uint32>>;
/// Pair of two variables
template<typename T1, typename T2>
using Pair = Kokkos::pair<T1,T2>;
using Pair = Kokkos::pair<T1, T2>;
/// View for a scalar
template<typename T, typename... properties>
using ViewTypeScalar = Kokkos::View<T,properties...>;
using ViewTypeScalar = Kokkos::View<T, properties...>;
/// 1D veiw as a vector
template<typename T, typename... properties>
using ViewType1D = Kokkos::View<T*,properties...>;
using ViewType1D = Kokkos::View<T*, properties...>;
/// 2D view as an array
template<typename T, typename... properties>
using ViewType2D = Kokkos::View<T**,properties...>;
using ViewType2D = Kokkos::View<T**, properties...>;
/// 3D view as an array
template<typename T, typename... properties>
using ViewType3D = Kokkos::View<T***,properties...>;
using ViewType3D = Kokkos::View<T***, properties...>;
/// 1D dual view as a vector
template<typename T, typename... properties>
using DualViewType1D = Kokkos::DualView<T*,properties...>;
using DualViewType1D = Kokkos::DualView<T*, properties...>;
/// unordered map
template<typename Key, typename Value, typename... properties>
using unorderedMap = Kokkos::UnorderedMap<Key, Value, properties...>;
using unorderedMap = Kokkos::UnorderedMap<Key, Value, properties...>;
/// unordered set
template<typename Key, typename... properties>
using unorderedSet = Kokkos::UnorderedMap<Key, void, properties...>;
using unorderedSet = Kokkos::UnorderedMap<Key, void, properties...>;
/// Scalar on device
template<typename T>
using deviceViewTypeScalar = Kokkos::View<T>;
using deviceViewTypeScalar = Kokkos::View<T>;
/// 1D array (vector) with default device (memory space and execution space)
template<typename T>
using deviceViewType1D = Kokkos::View<T*>;
using deviceViewType1D = Kokkos::View<T*>;
/// 2D view on device as an array on device
template<typename T, typename Layout=void>
using deviceViewType2D = Kokkos::View<T**,Layout, void>;
template<typename T, typename Layout = void>
using deviceViewType2D = Kokkos::View<T**, Layout, void>;
/// 3D view on device as an array on device
template<typename T, typename Layout=void>
using deviceViewType3D = Kokkos::View<T***,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>;
using hostViewTypeScalar = Kokkos::View<T, Kokkos::HostSpace>;
/// 1D array (vector with host memeory space)
template<typename T>
using hostViewType1D = Kokkos::View<T*, Kokkos::HostSpace>;
using hostViewType1D = Kokkos::View<T*, Kokkos::HostSpace>;
/// 2D array on host
template<typename T, typename Layout=void>
using hostViewType2D = Kokkos::View<T**,Layout, Kokkos::HostSpace>;
template<typename T, typename Layout = void>
using hostViewType2D = Kokkos::View<T**, Layout, Kokkos::HostSpace>;
/// 3D array on host
template<typename T, typename Layout=void>
using hostViewType3D = Kokkos::View<T***,Layout, Kokkos::HostSpace>;
template<typename T, typename Layout = void>
using hostViewType3D = Kokkos::View<T***, Layout, Kokkos::HostSpace>;
/// 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,209 +21,205 @@ 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;
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;
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<<')';
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;
os << spn;
return os;
}
} // pFlow
#endif //__KokkosUtilities_hpp__

View File

@ -20,60 +20,54 @@ 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>;
using Pair = Kokkos::pair<T, T>;
TypeInfoTemplateNV11("Range", 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(const Range::Pair& src)
: Range::Pair(src)
{
}
/// Copy
INLINE_FUNCTION_HD
@ -93,7 +87,7 @@ public Kokkos::pair<T,T>
/// Destructor
INLINE_FUNCTION_HD
~Range()=default;
~Range() = default;
//// - Methods
@ -112,13 +106,13 @@ public Kokkos::pair<T,T>
}
INLINE_FUNCTION_HD
const T& start()const
const T& start() const
{
return this->first;
}
INLINE_FUNCTION_HD
const T& end()const
const T& end() const
{
return this->second;
}
@ -126,22 +120,21 @@ public Kokkos::pair<T,T>
INLINE_FUNCTION_HD
T numElements()
{
return end()-start();
return end() - start();
}
INLINE_FUNCTION_HD
auto getPair()const
auto getPair() const
{
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()<<")";
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,57 +21,48 @@ 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;
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() );
if constexpr ( std::is_trivially_copyable_v<T>)
auto subV = Kokkos::subview(view, span.getPair());
if constexpr (std::is_trivially_copyable_v<T>)
{
Kokkos::deep_copy(subV, val);
}
else if constexpr( isHostAccessible<exe_space>())
else if constexpr (isHostAccessible<exe_space>())
{
for(auto i=span.start(); i<span.end(); i++ )
for (auto i = span.start(); i < span.end(); i++)
{
view[i] = val;
}
@ -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);
fill(view, rangeU32(start, end), val);
}
template<typename T, typename... properties>
void fill
(
void
fill(
ViewType3D<T, properties...>& view,
rangeU32 range1,
rangeU32 range2,
@ -111,69 +96,69 @@ 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;
uint32 numElems = end-start;
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 ;
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> >;
using policy = Kokkos::RangePolicy<ExSpace, Kokkos::IndexType<uint32>>;
Kokkos::parallel_for(
"ViewAlgorithms::fillSelected",
policy(0,numElems),
policy(0, numElems),
LAMBDA_HD(uint32 i){
//view[indices[i]]= val;
});
// view[indices[i]]= val;
}
);
Kokkos::fence();
return true;
@ -184,149 +169,128 @@ 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;
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;
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 <
template<
typename dType,
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
)
)
{
Kokkos::deep_copy(dst,src);
Kokkos::deep_copy(dst, src);
}
template <
template<
typename dType,
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,
uint32 sStart,
uint32 sEnd
)
)
{
range32 sSpan(sStart,sEnd);
range32 dSpan(dStart,dStart+(sEnd-sStart));
range32 sSpan(sStart, sEnd);
range32 dSpan(dStart, dStart + (sEnd - sStart));
auto srcSub = Kokkos::subview(src, sSpan);
auto dstSub = Kokkos::subview(dst, dSpan);
Kokkos::deep_copy(dstSub,srcSub);
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
Kokkos::deep_copy(dstView,subV);
auto subV = Kokkos::subview(src, Kokkos::make_pair(n, n + 1));
hostViewType1D<Type> dstView("getNth", 1);
// hostViewTypeScalar
Kokkos::deep_copy(dstView, subV);
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;
uint32 numElems = end - start;
if constexpr( isHostAccessible<ExecutionSpace>())
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;
uint32 numElems = end-start;
if constexpr( isHostAccessible<ExecutionSpace>())
if constexpr (isHostAccessible<ExecutionSpace>())
{
pFlow::algorithms::STD::sort<T,CompareFunc,true>(
view.data()+start,
numElems,
compare);
pFlow::algorithms::STD::sort<T, CompareFunc, true>(
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,61 +339,62 @@ 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;
uint32 numElems = end - start;
pFlow::algorithms::STD::permuteSort<Type,permType,true>(
view.data()+start,
permuteView.data()+permStart,
numElems);
pFlow::algorithms::STD::permuteSort<Type, permType, true>(
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;
while (low <= high)
{
int mid = low + (high - low)/2;
int mid = low + (high - low) / 2;
if ( array[mid] > val)
if (array[mid] > val)
{
high = mid - 1;
}
else if ( array[mid] < val)
else if (array[mid] < val)
{
low = mid + 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) {
return res+start;
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;
uint32 numElems = end - start;
pFlow::algorithms::KOKKOS::exclusiveScan<Type,ExecutionSpace>(
view.data()+start,
dView.data()+dStart,
numElems);
pFlow::algorithms::KOKKOS::exclusiveScan<Type, ExecutionSpace>(
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;
uint32 numElems = end-start;
pFlow::algorithms::KOKKOS::inclusiveScan<Type,ExecutionSpace>(
view.data()+start,
dView.data()+dStart,
numElems);
pFlow::algorithms::KOKKOS::inclusiveScan<Type, ExecutionSpace>(
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,55 +56,54 @@ 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);
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);
LAMBDA_HD(label i, T & valueToUpdate) {
valueToUpdate = min(view[i], valueToUpdate);
},
Kokkos :: Min < T >( minValue )
Kokkos ::Min<T>(minValue)
);
return minValue;
}
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);
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);
LAMBDA_HD(label i, T & valueToUpdate) {
valueToUpdate = max(view[i], valueToUpdate);
},
Kokkos::Max<T>( maxValue )
Kokkos::Max<T>(maxValue)
);
return maxValue;
}
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)
for (label i = start; i < end; ++i)
{
minValue = min(minValue, view[i]);
}
@ -113,69 +111,66 @@ 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)
for (label i = start; i < end; ++i)
{
maxValue = max(maxValue, view[i]);
}
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);
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)
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)
for (auto i = 0; i < selected.size(); ++i)
{
view[selected[i]] = static_cast<const T&>(vals[i]);
}
}
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,81 +23,72 @@ Licence:
#include "streams.hpp"
pFlow::Timer::Timer(const word& name, Timers* parrent)
:
name_(name),
: name_(name),
parrent_(parrent)
{
if(parrent_)
if (parrent_)
parrent_->addToList(this);
}
pFlow::Timer::~Timer()
{
if(parrent_)
if (parrent_)
{
parrent_->removeFromList(this);
}
}
pFlow::int32 pFlow::Timer::level()const
pFlow::int32 pFlow::Timer::level() const
{
if(parrent_)
return parrent_->level()+1;
if (parrent_)
return parrent_->level() + 1;
else
return 0;
}
bool pFlow::Timer::write(iOstream& os, bool subTree)const
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++)
for (int32 l = 1; l < lvl; l++)
{
os<<"";
os << "";
}
if(lvl>0)
if (lvl > 0)
{
if(master())
os<<"┣━━ ";
if (master())
os << "┣━━ ";
else if (lvl == 1)
os << "┃└─ ";
else
if(lvl==1)
os<<"┃└─ ";
else
os<<" └─ ";
os << " └─ ";
}
else
; //os<<"⊿ ";
; // os<<"⊿ ";
if(lvl==0)
os<<greenColor<<boldChar;
else if(master())
os<<yellowColor;
if (lvl == 0)
os << greenColor << boldChar;
else if (master())
os << yellowColor;
os<<name_;
os << name_;
auto tt = accTimersTotal();
if(abs(tt)>smallValue)
if (abs(tt) > smallValue)
{
os<<" execution time (s): total ("<<
tt<<")";
os << " execution time (s): total (" << tt << ")";
if(!master())
if (!master())
{
os<<", av. ("<<
averageTime()<<").";
os << ", av. (" << averageTime() << ").";
}
}
os<<defaultColor;
os<<'\n';
os << defaultColor;
os << '\n';
return true;
}

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,15 +66,13 @@ public:
Timer() = default;
explicit Timer(const word& name)
:
name_(name)
{}
: name_(name)
{
}
Timer(const word& name, Timers* parrent);
const word& name()const
const word& name() const
{
return name_;
}
@ -90,10 +84,9 @@ public:
parrent_ = nullptr;
}
virtual int32 level()const;
virtual int32 level() const;
virtual bool master()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,40 +121,34 @@ public:
accTime_ += lastTime_;
}
inline
bool timerActive()const
inline bool timerActive() const
{
return numIteration_!=0;
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);
return accTime_ / max(numIteration_, 1);
}
virtual
real accTimersTotal()const
virtual real accTimersTotal() const
{
return totalTime();
}
//// - IO operations
virtual bool write(iOstream& os, bool subTree)const;
virtual bool write(iOstream& os, bool subTree) const;
virtual bool read(iIstream& is)
{
@ -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

@ -17,7 +17,6 @@ Licence:
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __createBoundaryFields_hpp__
#define __createBoundaryFields_hpp__
@ -34,11 +33,8 @@ Licence:
#define createBaseBoundary(DataType, MemorySpaceType) \
template class pFlow::boundaryField<DataType, MemorySpaceType>;
#define createBoundaryFields(DataType, MemorySpaceType) \
createBaseBoundary(DataType, MemorySpaceType); \
createDerivedBoundary(DataType, MemorySpaceType);
#endif //__createBoundaryFields_hpp__

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::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";
errorStream<<" Function "<< Red_Text(fnName) << " has not been implemented yet!\n" <<
" File "<< Yellow_Text(fileName) <<
" at line "<< Yellow_Text(lineNumber) <<'\n';
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& ioErrorMessage(const char* fileName, int fileLineNumber, const char* fnName, const char* fName, int lNumber)
pFlow::iOstream&
notImplementedErrorMessage(
const char* fnName,
const char* fileName,
int lineNumber
)
{
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 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';
return errorStream;
}
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
)
{
return ioErrorMessage( fileName.c_str(), fileLineNumber, fnName, fName, lNumber);
}
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>>> 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& reportAndExit(int errorCode)
pFlow::iOstream&
ioErrorMessage(
const pFlow::word& fileName,
int fileLineNumber,
const char* fnName,
const char* fName,
int lNumber
)
{
errorStream<<"\n>>> phasicFlow is exiting . . ." << pFlow::endl;
return ioErrorMessage(
fileName.c_str(), fileLineNumber, fnName, fName, lNumber
);
}
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';
return errorStream;
}
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,62 +21,80 @@ Licence:
#ifndef __error_hpp__
#define __error_hpp__
#include "builtinTypes.hpp"
//- Forward decleartions
namespace pFlow
{
class iOstream;
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 ) \
fatalErrorInMessage((functionName), __FILE__, __LINE__ )
#define fatalErrorIn(functionName) \
fatalErrorInMessage((functionName), __FILE__, __LINE__)
/// Report a fatal error and function name and exit the application
#define fatalErrorInFunction fatalErrorIn(FUNCTION_NAME)
/// Report that a function is yet not implemented with supplied function name.
#define Not_Implemented(functionName) \
notImplementedErrorMessage ((functionName), __FILE__, __LINE__ )
notImplementedErrorMessage((functionName), __FILE__, __LINE__)
/// Report that a function is yet not implemented.
#define notImplementedFunction Not_Implemented(FUNCTION_NAME)
/// Report an error in file operation with supplied fileName and lineNumber.
#define ioErrorInFile( fileName, lineNumber) \
ioErrorMessage( fileName, lineNumber, FUNCTION_NAME, __FILE__, __LINE__ )
#define ioErrorInFile(fileName, lineNumber) \
ioErrorMessage(fileName, lineNumber, FUNCTION_NAME, __FILE__, __LINE__)
/// Report a warning with supplied function name
#define warningIn( functionName ) \
warningMessage((functionName), __FILE__, __LINE__ )
#define warningIn(functionName) \
warningMessage((functionName), __FILE__, __LINE__)
/// Report a warning
#define warningInFunction warningIn(FUNCTION_NAME)
/// Fatal exit
#define fatalExit \
reportAndExit()
#define fatalExit reportAndExit()
#endif

View File

@ -21,11 +21,10 @@ Licence:
#ifndef __vocabs_hpp__
#define __vocabs_hpp__
namespace pFlow
{
// folders / repositories
// folders / repositories
const inline char* settingsFolder__ = "settings";
const inline char* settingsRepository__ = "settings";
const inline char* caseSetupFolder__ = "caseSetup";
@ -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,47 +18,35 @@ 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"));
if(wF == "ASCII")
if (wF == "ASCII")
outFormatBinary_ = false;
else if(wF == "BINARY")
else if (wF == "BINARY")
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))
if (!readDictionary(setiingsDict))
{
fatalExit;
}
@ -70,46 +58,37 @@ 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))
if (!readDictionary(setiingsDict))
{
fatalExit;
}
}
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())
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;
@ -54,7 +49,7 @@ protected:
public:
// Constructor with owner and settings dict
Time( repository* owner, const dictionary& setiingsDict);
Time(repository* owner, const dictionary& setiingsDict);
Time(
repository* owner,
@ -62,15 +57,14 @@ public:
real startTime,
real endTime,
real saveInterval,
word startTimeName);
word startTimeName
);
//// - Methods
fileSystem localPath()const override;
fileSystem localPath() const override;
// - geometry repository
const repository& geometry()const
const repository& geometry() const
{
return geometry_;
}
@ -80,10 +74,10 @@ public:
return geometry_;
}
fileSystem integrationFolder()const;
fileSystem integrationFolder() const;
/// Write to the file with binary format?
bool outFileBinary()const override
bool outFileBinary() const override
{
return outFormatBinary_;
}
@ -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

@ -18,32 +18,28 @@ 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"))
if (dict.containsDataEntry("includeObjects"))
{
wordList incld = dict.getVal<wordList>("includeObjects");
for(auto& nm:incld)
for (auto& nm : incld)
{
includeList_.insert(nm);
}
}
if(dict.containsDataEntry("excludeObjects"))
if (dict.containsDataEntry("excludeObjects"))
{
wordList excld = dict.getVal<wordList>("excludeObjects");
for(auto& nm:excld)
for (auto& nm : excld)
{
excludeList_.insert(nm);
}
@ -51,136 +47,87 @@ 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()+"/";
word wPath = path.canonical().wordPath() + "/";
auto first = wPath.find_first_of('/');
auto last = wPath.find_last_of('/');
if( first == word::npos)
if (first == word::npos)
{
fatalErrorInFunction <<
"path is empty \n";
fatalErrorInFunction << "path is empty \n";
fatalExit;
}
if( last == wPath.size()-1)
if (last == wPath.size() - 1)
{
wPath = wPath.substr(0,last);
wPath = wPath.substr(0, last);
last = wPath.find_last_of('/');
}
word rName = wPath.substr(last+1);
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();
auto first = wPath.find_first_of('/');
auto last = wPath.find_last_of('/');
if( first == word::npos)
if (first == word::npos)
{
fatalErrorInFunction <<
"path is empty \n";
fatalErrorInFunction << "path is empty \n";
fatalExit;
}
if( last == wPath.size()-1)
if (last == wPath.size() - 1)
{
wPath = wPath.substr(0,last);
wPath = wPath.substr(0, last);
last = wPath.find_last_of('/');
}
word tFolder = wPath.substr(0,last);
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,49 +164,32 @@ 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)
bool pFlow::systemControl::operator++(int)
{
auto toContinue = time()++;
if(toContinue)
if (toContinue)
{
writeToFileTimer_.start();
//if(time().currentIter() != 0 )
// if(time().currentIter() != 0 )
{
//- save the results to file
if( !time().write() )
if (!time().write())
{
fatalErrorInFunction;
return false;
@ -280,17 +197,15 @@ bool pFlow::systemControl::operator ++(int)
}
writeToFileTimer_.end();
if( time().timersReportTime() &&
timersReport() )
if (time().timersReportTime() && timersReport())
{
timers_.write(output, true);
}
}
else if (time().finalTime())
{
writeToFileTimer_.start();
if( !time().write() )
if (!time().write())
{
fatalErrorInFunction;
return false;
@ -302,5 +217,3 @@ bool pFlow::systemControl::operator ++(int)
return toContinue;
}

View File

@ -18,191 +18,250 @@ 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> \
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; \
template <typename testType, typename Ret, typename... Args> \
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>*); \
template<typename U> \
template <typename U> \
static std::true_type Test(Check<Ret (*)(Args...), &U::name> *); \
template <typename U> \
static std::false_type Test(...); \
static const bool value = decltype(Test<testType>(0))::value; \
};
};
namespace pFlow
{
//
template<typename T>
struct checkStatic
{
//
template <typename T>
struct checkStatic
{
has_static_member(TYPENAME);
static constexpr
bool hasMember()
static constexpr bool hasMember()
{
return has_static_member_TYPENAME<T,word(void)>::value;
return has_static_member_TYPENAME<T, word(void)>::value;
}
};
};
template <typename T>
inline word basicTypeName()
{
template <typename T>
inline word basicTypeName()
{
int status;
auto& ti = typeid(T);
char* realname = abi::__cxa_demangle(ti.name(), nullptr, nullptr, &status);
auto &ti = typeid(T);
char *realname = abi::__cxa_demangle(ti.name(), nullptr, nullptr, &status);
word name(realname);
free(realname);
return name;
}
}
template<>
inline word basicTypeName<word>(){ return "word"; }
template <>
inline word basicTypeName<word>()
{
return "word";
}
template<>
inline word basicTypeName<int64>(){ return "int64"; }
template <>
inline word basicTypeName<int64>()
{
return "int64";
}
template<>
inline word basicTypeName<int32>(){ return "int32"; }
template <>
inline word basicTypeName<int32>()
{
return "int32";
}
template<>
inline word basicTypeName<int8>(){ return "int8"; }
template <>
inline word basicTypeName<int8>()
{
return "int8";
}
template<>
inline word basicTypeName<uint64>(){ return "uint64"; }
template <>
inline word basicTypeName<uint64>()
{
return "uint64";
}
template<>
inline word basicTypeName<uint32>(){ return "uint32"; }
template <>
inline word basicTypeName<uint32>()
{
return "uint32";
}
template<>
inline word basicTypeName<uint8>(){ return "uint8"; }
template <>
inline word basicTypeName<uint8>()
{
return "uint8";
}
template<>
inline word basicTypeName<real>(){ return "real"; }
template <>
inline word basicTypeName<real>()
{
return "real";
}
template<typename T>
word constexpr getTypeName()
{
if constexpr ( checkStatic<T>::hasMember() )
template <typename T>
word constexpr getTypeName()
{
if constexpr (checkStatic<T>::hasMember())
{
return T::TYPENAME();
}else
}
else
{
return basicTypeName<T>();
}
}
template<typename T>
word constexpr getTypeName(const T&)
{
if constexpr ( checkStatic<T>::hasMember() )
{
return T::TYPENAME();
}else
{
return basicTypeName<T>();
}
}
// compare the overriden typeName of object with concrete TYPENAME
// of Type1
template <typename Type1, typename Type2>
bool checkType(Type2* object)
{
return getTypeName<Type1>() == object->typeName();
}
template <typename Type1, typename Type2>
bool checkType(Type2& object)
{
return getTypeName<Type1>() == object.typeName();
}
}
template <typename T>
word constexpr getTypeName(const T &)
{
if constexpr (checkStatic<T>::hasMember())
{
return T::TYPENAME();
}
else
{
return basicTypeName<T>();
}
}
// compare the overriden typeName of object with concrete TYPENAME
// of Type1
template <typename Type1, typename Type2>
bool checkType(Type2 *object)
{
return getTypeName<Type1>() == object->typeName();
}
template <typename Type1, typename Type2>
bool checkType(Type2 &object)
{
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>()+">"; \
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) \
inline static word TYPENAME() \
{ \
return word(tName)+"<"+getTypeName<Type>()+">"; \
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) \
#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) \
#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,60 +23,52 @@ 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) \
#define create_vCtor(baseClass, selectorName, argList, args) \
\
typedef std::function< uniquePtr<baseClass> argList > selectorName##FunctionType; \
typedef wordMap<selectorName##FunctionType> selectorName##vCtorSelectorType; \
typedef std::function<uniquePtr<baseClass> argList> \
selectorName##FunctionType; \
typedef wordMap<selectorName##FunctionType> \
selectorName##vCtorSelectorType; \
\
inline static selectorName##vCtorSelectorType selectorName##vCtorSelector_; \
inline static selectorName##vCtorSelectorType \
selectorName##vCtorSelector_; \
\
\
template<typename dType> \
class create##selectorName##Callback \
{ \
public: \
create##selectorName##Callback () \
template<typename dType> \
class create##selectorName##Callback \
{ \
auto success = \
selectorName##vCtorSelector_.insertIf \
( \
public: \
\
create##selectorName##Callback() \
{ \
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 ) \
if (!success) \
{ \
fatalErrorInFunction \
<< "Duplicate entry "<< dType::TYPENAME() \
<< " in virtual constructor table of "<< #baseClass \
<< " with selector name " << #selectorName <<endl; \
<< "Duplicate entry " << dType::TYPENAME() \
<< " 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,35 +23,34 @@ Licence:
#include "iIstream.hpp"
#include "iOstream.hpp"
pFlow::Logical::Logical(const word& l)
{
if(!evaluteWord(l, s_, yesNoSet_ ))
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);
for(int i=0; i<4; ++i)
for (int i = 0; i < 4; ++i)
{
if(toUpper(YesNo__[i][0]) == Ul)
if (toUpper(YesNo__[i][0]) == Ul)
{
b = true;
yesNoSet = i;
return true;
}
else if( toUpper(YesNo__[i][1]) == Ul )
else if (toUpper(YesNo__[i][1]) == Ul)
{
b = false;
yesNoSet = i;
@ -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;
@ -78,15 +78,14 @@ bool pFlow::Logical::read(iIstream& is)
{
w = t.stringToken();
}
else if(t.isWord() )
else if (t.isWord())
{
w = t.wordToken();
}
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,34 +93,34 @@ 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_)
if (s_)
{
os<< YesNo__[yesNoSet_][0];
os << YesNo__[yesNoSet_][0];
}
else
{
os<< YesNo__[yesNoSet_][1];
os << YesNo__[yesNoSet_][1];
}
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))
if (!L.read(is))
{
fatalExit;
}
return is;
}
pFlow::iOstream& pFlow::operator<< ( iOstream& os, const Logical& L)
pFlow::iOstream&
pFlow::operator<<(iOstream& os, const Logical& L)
{
if(!L.write(os))
if (!L.write(os))
{
fatalExit;
}

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);
@ -113,7 +116,7 @@ public:
}
/// Not operator
inline Logical operator!()const
inline Logical operator!() const
{
return Logical(!s_, yesNoSet_);
}
@ -122,18 +125,18 @@ public:
bool read(iIstream& is);
bool write(iOstream& os)const;
bool write(iOstream& os) const;
//// Static members
bool static evaluteWord(const word& l, bool& b, int& yesNoSet );
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,12 +90,13 @@ 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 )
if (abs(v) < verySmallValue)
{
ss <<"0";
ss << "0";
}
else
{
@ -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,18 +115,21 @@ 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--)
for (auto n = len - 1; n > dec; n--)
{
if( str[n] == '0' )
if (str[n] == '0')
{
firstZero = n;
}
@ -123,48 +139,54 @@ pFlow::word pFlow::removeDecimalZeros(const word& str)
}
}
if(firstZero == dec+1) firstZero = dec;
if (firstZero == dec + 1)
firstZero = dec;
return str.substr(0,firstZero);
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+">";
return w1 + "<" + w2 + ">";
}
pFlow::word pFlow::angleBracketsNames2
(
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& w2,
const word& w3
)
{
return base+"<"+w1+","+w2+">";
return base + "<" + w1 + "," + w2 + "," + 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)
if (auto pos = w.find_last_of(sep); pos != word::npos)
{
return w.substr(0,pos);
return w.substr(0, pos);
}
else
{
@ -172,11 +194,12 @@ 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)
if (auto pos = w.find_last_of(sep); pos != word::npos)
{
return w.substr(pos+1);
return w.substr(pos + 1);
}
else
{
@ -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)
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)
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,41 +331,45 @@ 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)
// #include <iostream>
bool
pFlow::readReal(const word& w, real& val)
{
try{
val = std::stod(w);
}
catch (std:: out_of_range& e)
try
{
val = static_cast<real>( std::stold(w) );
val = std::stod(w);
}
catch (...){
catch (std::out_of_range& e)
{
val = static_cast<real>(std::stold(w));
}
catch (...)
{
return false;
}
return true;
}
bool pFlow::readReal( const char* buf, real & val )
bool
pFlow::readReal(const char* buf, real& val)
{
char* c;
val = std::strtod(buf, &c);
if(val == HUGE_VAL)
if (val == HUGE_VAL)
{
val = static_cast<real>( std::strtold(buf, &c) );
if(val == HUGE_VAL || c==buf)
val = static_cast<real>(std::strtold(buf, &c));
if (val == HUGE_VAL || c == buf)
return false;
}
else if(c == buf)
else if (c == buf)
{
return false;
}
@ -337,15 +377,15 @@ 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 )
if (bool t = isYes(w); t)
{
val = true;
return true;
}
if( bool f = isNo(w); f )
if (bool f = isNo(w); f)
{
val = false;
return true;
@ -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);
return readReal(w, val);
}
inline
bool readValue(const word& w, uint32& val)
inline bool
readValue(const word& w, uint32& val)
{
return readUint32(w,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);
return readInt64(w, val);
}
inline
bool readValue(const word& w, int32& val)
inline bool
readValue(const word& w, int32& val)
{
return readInt32(w,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);
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);
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;
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

@ -29,21 +29,20 @@ namespace pFlow
{
#ifdef pFlow_Build_Double
#define useDouble 1
#define useDouble 1
inline const char* floatingPointType__ = "double";
inline const bool usingDouble__ = true;
#else
#define useDouble 0
#define useDouble 0
inline const char* floatingPointType__ = "float";
inline const bool usingDouble__ = false;
#endif
// scalars
#if useDouble
using real = double;
using real = double;
#else
using real = float;
using real = float;
#endif
using int8 = signed char;
@ -52,7 +51,7 @@ using int32 = int;
using int64 = long long int;
using uint8 = unsigned char ;
using uint8 = unsigned char;
using uint32 = unsigned int;
@ -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);
@ -55,22 +52,24 @@ real abs(real x)
}
#ifndef __CUDACC__
INLINE_FUNCTION_HD
int64 abs(int64 x)
{
return std::abs(x);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD int32 abs(int32 x)
INLINE_FUNCTION_HD
int64
abs(int64 x)
{
return std::abs(x);
}
#endif
#ifndef __CUDACC__
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,36 +78,42 @@ 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;
return x % y;
}
INLINE_FUNCTION_HD int32 mod(int32 x, int32 y)
INLINE_FUNCTION_HD int32
mod(int32 x, int32 y)
{
return x%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;
return x % y;
}
INLINE_FUNCTION_HD auto mod(uint32 x, uint32 y)
INLINE_FUNCTION_HD auto
mod(uint32 x, uint32 y)
{
return x%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);
return std::remainder(x, y);
}
#endif
#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,15 +157,17 @@ real sqrt(real x)
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real cbrt (real x)
real
cbrt(real x)
{
return std::cbrt (x);
return std::cbrt(x);
}
#endif
#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,25 +276,27 @@ 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);
return ::fmin(x, y);
#else
return std::fmin(x,y);
return std::fmin(x, y);
#endif
}
#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,61 +313,63 @@ 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);
return ::fmax(x, y);
#else
return std::fmax(x,y);
return std::fmax(x, 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,51 +21,50 @@ Licence:
#ifndef __numericConstants_hpp__
#define __numericConstants_hpp__
#include <limits>
#include "builtinTypes.hpp"
#include <limits>
namespace pFlow
{
const inline real Pi = real(3.1415926535897932384626433832);
const inline real smallValue = 1.0e-15;
const inline real verySmallValue = 1.0e-30;
const inline real largeValue = 1.0e15;
const inline real veryLargeValue = 1.0e30;
const inline real Pi = real(3.1415926535897932384626433832);
const inline real smallValue = 1.0e-15;
const inline real verySmallValue = 1.0e-30;
const inline real largeValue = 1.0e15;
const inline real veryLargeValue = 1.0e30;
// - largest negative value
template<typename T>
constexpr inline T largestNegative()
{
// - largest negative value
template<typename T>
constexpr T
largestNegative()
{
return std::numeric_limits<T>::lowest();
}
}
template<typename T>
constexpr inline T epsilonValue()
{
template<typename T>
constexpr T
epsilonValue()
{
return std::numeric_limits<T>::min();
}
}
// largest positive value
template<typename T>
constexpr inline T largestPositive()
{
// largest positive value
template<typename T>
constexpr T
largestPositive()
{
return std::numeric_limits<T>::max();
}
}
const inline int32 largestNegInt32 = largestNegative<int32>();
const inline int32 largestPosInt32 = largestPositive<int32>();
const inline int64 largestNegInt64 = largestNegative<int64>();
const inline int64 largestPosInt64 = largestPositive<int64>();
const inline real largestNegREAL = largestNegative<real>();
const inline real largestPosREAL = largestPositive<real>();
const inline real epsilonREAL = epsilonValue<real>();
const inline int32 largestNegInt32 = largestNegative<int32>();
const inline int32 largestPosInt32 = largestPositive<int32>();
const inline int64 largestNegInt64 = largestNegative<int64>();
const inline int64 largestPosInt64 = largestPositive<int64>();
const inline real largestNegREAL = largestNegative<real>();
const inline real largestPosREAL = largestPositive<real>();
const inline real epsilonREAL = epsilonValue<real>();
} // end of pFlow

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),
quadruple(const T& w, const T& x, const T& y, const T& z)
: 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),
quadruple(const T& val)
: s_(val),
v_(val)
{}
{
}
// type conversion trough assignment
template <typename T2>
INLINE_FUNCTION_HD
quadruple<T> & operator = (const quadruple<T2> & rhs)
template<typename T2>
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
@ -113,128 +113,171 @@ public:
// clone
INLINE_FUNCTION_H
uniquePtr<quadruple<T>> clone()const
uniquePtr<quadruple<T>> clone() const
{
return makeUnique<quadruple<T>>(*this);
}
INLINE_FUNCTION_H
quadruple<T>* clonePtr()const
quadruple<T>* clonePtr() const
{
return new quadruple<T>(*this);
}
// 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);
void operator+=(const quadruple& oprnd2);
INLINE_FUNCTION_HD
void operator-= (const quadruple & oprnd2);
void operator-=(const quadruple& oprnd2);
INLINE_FUNCTION_HD
void operator*= (const quadruple & oprnd2);
void operator*=(const quadruple& oprnd2);
INLINE_FUNCTION_HD
void operator/= (const quadruple & oprnd2);
void operator/=(const quadruple& oprnd2);
// unary negate operator
INLINE_FUNCTION_HD
quadruple operator- ()const;
quadruple operator-() const;
// unary plus operator
INLINE_FUNCTION_HD
quadruple operator+ ()const;
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);
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);
friend FUNCTION_H void readIstream<T>(iIstream& str, quadruple<T>& iv);
};
} // pFlow
#include "quadrupleI.hpp"
//#include "quadrupleMath.hpp"
// #include "quadrupleMath.hpp"
#endif

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,280 +19,173 @@ 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));
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 )
if (static_cast<real>(l) > smallValue)
{
*this /= l;
}
}
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

@ -19,18 +19,22 @@ Licence:
-----------------------------------------------------------------------------*/
#define Q4Func(fnName) \
template<typename T> \
inline pFlow::quadruple<T> pFlow::fnName(const quadruple<T>& q) \
{ \
template<typename T> \
inline pFlow::quadruple<T> pFlow::fnName(const quadruple<T>& q) \
{ \
return quadruple<T>(fnName(q.s_), fnName(q.v_)); \
}
}
#define Q4Func2(fnName) \
template<typename T> \
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_)); \
}
template<typename T> \
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_) \
); \
}
//* * * * * * * * * * * List of functinos * * * * * * * * //
// abs, mod, exp, log, log10, pow, sqrt, cbrt
@ -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 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 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_);
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"
@ -43,7 +41,7 @@ template<typename T> class triple;
* The template parameter should be numeric type only.
*
*/
template <typename T>
template<typename T>
struct triple
{
/// data members
@ -55,30 +53,32 @@ 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>
INLINE_FUNCTION_HD triple<T> & operator = (const triple<T2> & rhs)
template<typename T2>
INLINE_FUNCTION_HD triple<T>& operator=(const triple<T2>& rhs)
{
this->x_ = static_cast<T>(rhs.x_);
this->y_ = static_cast<T>(rhs.y_);
@ -88,19 +88,17 @@ struct triple
/// Type casting through copy constructor
template<typename T2>
INLINE_FUNCTION_HD triple(const triple<T2> &src)
:
x_(static_cast<T>(src.x_)),
INLINE_FUNCTION_HD triple(const triple<T2>& src)
: 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;
@ -121,7 +119,7 @@ struct triple
}
INLINE_FUNCTION
triple<T>* clonePtr()const
triple<T>* clonePtr() const
{
return new triple<T>(*this);
}
@ -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,91 +217,100 @@ 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 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);
INLINE_FUNCTION_HD void operator+=(const triple& oprnd2);
INLINE_FUNCTION_HD void operator+= (const triple & oprnd2);
INLINE_FUNCTION_HD void operator-=(const triple& oprnd2);
INLINE_FUNCTION_HD void operator-= (const triple & oprnd2);
INLINE_FUNCTION_HD void operator*= (const triple & oprnd2);
INLINE_FUNCTION_HD void operator/= (const triple & oprnd2);
INLINE_FUNCTION_HD void operator*=(const triple& oprnd2);
INLINE_FUNCTION_HD void operator/=(const triple& oprnd2);
/// unary negate operator
INLINE_FUNCTION_HD triple operator- ()const;
INLINE_FUNCTION_HD triple operator-() const;
/// unary plus operator
INLINE_FUNCTION_HD triple operator+ ()const;
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
/// << operator
friend iOstream& operator<< <T> (iOstream& str, const triple<T> & ov);
friend iOstream& operator<< <T>(iOstream& str, const triple<T>& ov);
/// >> operator
friend iIstream& operator >> <T> (iIstream & str, triple<T> & iv);
friend iIstream& operator>> <T>(iIstream& str, triple<T>& iv);
/// same as >> operator, but faster, good for mass read
friend void readIstream <T>( iIstream& str, triple<T> &iv);
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 ) &&
equal( opr1.z(), opr2.z(), 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,242 +19,163 @@ 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_ +
oprnd1.z_ * oprnd2.z_ ;
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_,
v1.z_*v2.x_ - v1.x_*v2.z_,
v1.x_*v2.y_ - v1.y_*v2.x_
v1.y_ * v2.z_ - v1.z_ * v2.y_,
v1.z_ * v2.x_ - v1.x_ * v2.z_,
v1.x_ * v2.y_ - v1.y_ * v2.x_
);
}
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);
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));
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);
*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,39 +210,31 @@ 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_)
if (opr1.x_ < opr2.x_ && opr1.y_ < opr2.y_ && opr1.z_ < opr2.z_)
{
return true;
}
@ -338,13 +245,10 @@ 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_)
if (opr1.x_ > opr2.x_ && opr1.y_ > opr2.y_ && opr1.z_ > opr2.z_)
{
return true;
}
@ -355,13 +259,10 @@ 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_)
if (opr1.x_ <= opr2.x_ && opr1.y_ <= opr2.y_ && opr1.z_ <= opr2.z_)
{
return true;
}
@ -371,15 +272,11 @@ 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_)
if (opr1.x_ >= opr2.x_ && opr1.y_ >= opr2.y_ && opr1.z_ >= opr2.z_)
{
return true;
}
@ -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

@ -23,18 +23,24 @@ namespace pFlow
{
#define T3Func(fnName) \
template<typename T> \
INLINE_FUNCTION_HD triple<T> fnName(const triple<T>& v) \
{ \
template<typename T> \
INLINE_FUNCTION_HD triple<T> fnName(const triple<T>& v) \
{ \
return triple<T>(fnName(v.x_), fnName(v.y_), fnName(v.z_)); \
}
}
#define T3Func2(fnName) \
template<typename T> \
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_)); \
}
template<typename T> \
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_) \
); \
}
//* * * * * * * * * * * List of functinos * * * * * * * * //
// abs, mod, exp, log, log10, pow, sqrt, cbrt
@ -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 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 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_);
return max(max(t3.x_, t3.y_), t3.z_);
}
#undef T3Func
#undef T3Func2

View File

@ -23,13 +23,12 @@ Licence:
namespace pFlow
{
const realx3 zero3(0.0);
const realx3 one3(1.0);
const realx3 zero3(0.0);
const realx3 one3(1.0);
const realx3x3 zero33(zero3);
const realx3x3 one33(one3);
const realx4 zero4(zero);
const realx3x3 zero33(zero3);
const realx3x3 one33(one3);
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
{
@ -45,55 +43,100 @@ using uint64x3 = triple<uint64>;
using realx3 = triple<real>;
using int32x3x3 = triple<int32x3>;
using uint32x3x3= triple<uint32x3>;
using uint32x3x3 = triple<uint32x3>;
using realx3x3 = triple<realx3>;
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__