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

@ -2,17 +2,17 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -22,155 +22,141 @@ Licence:
/**
* \file KokkosType.hpp
*
* \brief name aliases and typedesf for Kokkos entities that are
*
* \brief name aliases and typedesf for Kokkos entities that are
* frequently used in PhasicFlow.
*
*
*/
#include <Kokkos_Core.hpp>
#include <Kokkos_DualView.hpp>
#include <Kokkos_UnorderedMap.hpp>
#include "builtinTypes.hpp"
namespace pFlow
{
/// Host memory space
using HostSpace = Kokkos::HostSpace;
/// Host memory space
using HostSpace = Kokkos::HostSpace;
/// Serial execution space
using Serial = Kokkos::Serial;
/// Serial execution space
using Serial = Kokkos::Serial;
#ifdef _OPENMP
/// OpenMp execution space
using OpenMP = Kokkos::OpenMP;
/// OpenMp execution space
using OpenMP = Kokkos::OpenMP;
#endif
#ifdef __CUDACC__
/// Cuda execution space
using Cuda = Kokkos::Cuda;
/// Cuda execution space
using Cuda = Kokkos::Cuda;
#endif
/// Default Host execution space, on top of all host execution spaces
using DefaultHostExecutionSpace = Kokkos::DefaultHostExecutionSpace;
/// Default Host execution space, on top of all host execution spaces
using DefaultHostExecutionSpace = Kokkos::DefaultHostExecutionSpace;
/// Default execution space, it can be device exe. space, if a device space is
/// activated.
using DefaultExecutionSpace = Kokkos::DefaultExecutionSpace;
/// Default execution space, it can be device exe. space, if a device space is
/// activated.
using DefaultExecutionSpace = Kokkos::DefaultExecutionSpace;
using deviceRPolicyStatic = Kokkos::RangePolicy<
Kokkos::DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Static>,
Kokkos::IndexType<pFlow::uint32>>;
using deviceRPolicyStatic =
Kokkos::RangePolicy<
Kokkos::DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Static>,
Kokkos::IndexType<pFlow::uint32> >;
using hostRPolicyStatic = Kokkos::RangePolicy<
Kokkos::DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Static>,
Kokkos::IndexType<pFlow::uint32>>;
using deviceRPolicyDynamic = Kokkos::RangePolicy<
Kokkos::DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Dynamic>,
Kokkos::IndexType<pFlow::uint32>>;
using hostRPolicyStatic =
Kokkos::RangePolicy<
Kokkos::DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Static>,
Kokkos::IndexType<pFlow::uint32> >;
using deviceRPolicyDynamic =
Kokkos::RangePolicy<
Kokkos::DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Dynamic>,
Kokkos::IndexType<pFlow::uint32> >;
using hostRPolicyDynamic =
Kokkos::RangePolicy<
Kokkos::DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Dynamic>,
Kokkos::IndexType<pFlow::uint32> >;
using hostRPolicyDynamic = Kokkos::RangePolicy<
Kokkos::DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Dynamic>,
Kokkos::IndexType<pFlow::uint32>>;
/// Pair of two variables
template<typename T1, typename T2>
using Pair = Kokkos::pair<T1,T2>;
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
/// 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
/// 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
/// unordered set
template<typename Key, typename... properties>
using unorderedSet = Kokkos::UnorderedMap<Key, void, properties...>;
using unorderedSet = Kokkos::UnorderedMap<Key, void, properties...>;
/// Scalar on device
/// 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*>;
/// 2D view on device as an array on device
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>;
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>;
/// 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>
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>;
/// 2D array on host
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<
T*,
Kokkos::MemoryTraits<std::is_same<DefaultExecutionSpace,Serial>::value?0:Kokkos::Atomic>>;
using deviceAtomicViewType1D = Kokkos::View<
T*,
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<
T***,
Kokkos::MemoryTraits<std::is_same<DefaultExecutionSpace,Serial>::value?0:Kokkos::Atomic>>;
using deviceAtomicViewType3D = Kokkos::View<
T***,
Kokkos::MemoryTraits<
std::is_same_v<DefaultExecutionSpace, Serial> ? 0 : Kokkos::Atomic>>;
} // pFlow
#endif //__KokkosTypes_hpp__
#endif //__KokkosTypes_hpp__

View File

@ -2,17 +2,17 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -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)
{
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
reallocInit(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
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)
{
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)
{
Kokkos::realloc(Kokkos::WithoutInitializing, view, len1, 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);
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);
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__
#endif //__KokkosUtilities_hpp__

View File

@ -2,17 +2,17 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -20,140 +20,132 @@ 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
//// - Constructors
/// Default
INLINE_FUNCTION_HD
Range(){}
/// Default
INLINE_FUNCTION_HD Range()
{
}
/// From end, set start to 0
INLINE_FUNCTION_HD
Range(const T& e)
:
Range(0,e)
{}
/// From componeents
INLINE_FUNCTION_HD
Range(const T& s, const T& e)
:
Range::Pair(s,e)
{}
/// From end, set start to 0
INLINE_FUNCTION_HD
Range(const T& e)
: Range(0, e)
{
}
/// From pair
INLINE_FUNCTION_HD
Range(const Range::Pair &src )
:
Range::Pair(src)
{}
/// From componeents
INLINE_FUNCTION_HD
Range(const T& s, const T& e)
: Range::Pair(s, e)
{
}
/// Copy
INLINE_FUNCTION_HD
Range(const Range&) = default;
/// From pair
INLINE_FUNCTION_HD
Range(const Range::Pair& src)
: Range::Pair(src)
{
}
/// Move
INLINE_FUNCTION_HD
Range(Range&&) = default;
/// Copy
INLINE_FUNCTION_HD
Range(const Range&) = default;
/// Copy assignment
INLINE_FUNCTION_HD
Range& operator=(const Range&) = default;
/// Move
INLINE_FUNCTION_HD
Range(Range&&) = default;
/// Move assignment
INLINE_FUNCTION_HD
Range& operator=(Range&&) = default;
/// Copy assignment
INLINE_FUNCTION_HD
Range& operator=(const Range&) = default;
/// Destructor
INLINE_FUNCTION_HD
~Range()=default;
/// Move assignment
INLINE_FUNCTION_HD
Range& operator=(Range&&) = default;
/// Destructor
INLINE_FUNCTION_HD
~Range() = default;
//// - Methods
/// Start
INLINE_FUNCTION_HD
T& start()
{
return this->first;
}
/// Start
INLINE_FUNCTION_HD
T& start()
{
return this->first;
}
/// End
INLINE_FUNCTION_HD
T& end()
{
return this->second;
}
/// End
INLINE_FUNCTION_HD
T& end()
{
return this->second;
}
INLINE_FUNCTION_HD
const T& start()const
{
return this->first;
}
INLINE_FUNCTION_HD
const T& start() const
{
return this->first;
}
INLINE_FUNCTION_HD
const T& end()const
{
return this->second;
}
INLINE_FUNCTION_HD
const T& end() const
{
return this->second;
}
INLINE_FUNCTION_HD
T numElements()
{
return end()-start();
}
INLINE_FUNCTION_HD
auto getPair()const
{
return Pair(this->first, this->second);
}
INLINE_FUNCTION_HD
T numElements()
{
return end() - start();
}
INLINE_FUNCTION_HD
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;
}
using range32 = Range<int32>;
using range32 = Range<int32>;
using range64 = Range<int64>;
using range64 = Range<int64>;
using rangeU32 = Range<uint32>;
using rangeU64 = Range<uint64>;
using rangeU32 = Range<uint32>;
using rangeU64 = Range<uint64>;
} // pFlow
#endif //__KokkosTypes_hpp__
#endif //__KokkosTypes_hpp__

View File

@ -2,17 +2,17 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -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(
const ViewType1D<T, properties...>& view,
uint32 start,
uint32 end,
const T& val)
{
using ExecutionSpace = typename ViewType1D<T, properties...>::execution_space;
uint32 numElems = end-start;
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 uint32
count(
const ViewType1D<T, properties...>& view,
uint32 start,
uint32 end,
const T& val
)
{
using ExecutionSpace =
typename ViewType1D<T, properties...>::execution_space;
uint32 numElems = end - start;
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)
{
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,29 +71,23 @@ 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
(
ViewType3D<T, properties...>& view,
rangeU32 range1,
rangeU32 range2,
rangeU32 range3,
const T& val
void
fill(
ViewType3D<T, properties...>& view,
rangeU32 range1,
rangeU32 range2,
rangeU32 range3,
const T& val
)
{
static_assert(std::is_trivially_copyable_v<T>, "Not valid type for fill");
@ -111,222 +96,201 @@ 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(
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;
pFlow::algorithms::KOKKOS::fillSequence<Type, ExecutionSpace>(
view.data()+start,
numElems,
startVal);
return ;
}
template<
typename Type,
typename... properties,
typename indexType,
typename... indexProperties>
bool fillSelected
(
ViewType1D<Type, properties...> view,
ViewType1D<indexType, indexProperties...> indices,
uint32 numElems,
Type val
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 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");
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
);
return;
}
template<
typename Type,
typename... properties,
typename indexType,
typename... indexProperties>
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(
areAccessible<
typename ViewType1D<Type, properties...>::execution_space,
typename ViewType1D<indexType, indexProperties...>::memory_space>(),
"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),
LAMBDA_HD(uint32 i){
//view[indices[i]]= val;
});
"ViewAlgorithms::fillSelected",
policy(0, numElems),
LAMBDA_HD(uint32 i){
// view[indices[i]]= val;
}
);
Kokkos::fence();
return true;
}
template<
typename Type,
typename... properties,
typename indexType,
typename... indexProperties>
bool fillSelected(
ViewType1D<Type, properties...> view,
const ViewType1D<indexType, indexProperties...> indices,
const ViewType1D<Type, properties...> vals,
const uint32 numElems )
typename Type,
typename... properties,
typename indexType,
typename... indexProperties>
bool
fillSelected(
ViewType1D<Type, properties...> view,
const ViewType1D<indexType, indexProperties...> indices,
const ViewType1D<Type, properties...> vals,
const uint32 numElems
)
{
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");
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"
);
using ExecutionSpace =
typename ViewType1D<Type, properties...>::execution_space;
using ExecutionSpace = typename ViewType1D<Type, properties...>::execution_space;
pFlow::algorithms::KOKKOS::fillSelected<Type, indexType, ExecutionSpace>(
view.data(),
indices.data(),
vals.data(),
numElems
);
view.data(), indices.data(), vals.data(), numElems
);
return true;
}
template<typename T, typename... properties>
INLINE_FUNCTION_H
T min(
const ViewType1D<T, properties...>& view,
uint32 start,
uint32 end)
INLINE_FUNCTION_H T
min(const ViewType1D<T, properties...>& view, uint32 start, uint32 end)
{
using ExecutionSpace =
typename ViewType1D<T, properties...>::execution_space;
using ExecutionSpace = typename ViewType1D<T, properties...>::execution_space;
uint32 numElems = end-start;
return
pFlow::algorithms::KOKKOS::min<T, ExecutionSpace>(
view.data()+start,
numElems);
uint32 numElems = end - start;
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);
}
template <
typename dType,
typename... dProperties,
typename sType,
typename... sProperties>
INLINE_FUNCTION_H
void copy(
const ViewType1D<dType, dProperties...>& dst,
const ViewType1D<sType, sProperties...>& src
)
{
Kokkos::deep_copy(dst,src);
return pFlow::algorithms::KOKKOS::max<T, ExecutionSpace>(
view.data() + start, numElems
);
}
template <
typename dType,
typename... dProperties,
typename sType,
typename... sProperties>
INLINE_FUNCTION_H
void copy(
const ViewType1D<dType, dProperties...>& dst,
uint32 dStart,
const ViewType1D<sType, sProperties...>& src,
uint32 sStart,
uint32 sEnd
)
template<
typename dType,
typename... dProperties,
typename sType,
typename... sProperties>
INLINE_FUNCTION_H void
copy(
const ViewType1D<dType, dProperties...>& dst,
const ViewType1D<sType, sProperties...>& src
)
{
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(dst, src);
}
template <
typename Type,
typename... sProperties>
INLINE_FUNCTION_H
void getNth(
Type& dst,
const ViewType1D<Type, sProperties...>& src,
const uint32 n
)
template<
typename dType,
typename... dProperties,
typename sType,
typename... sProperties>
INLINE_FUNCTION_H void
copy(
const ViewType1D<dType, dProperties...>& dst,
uint32 dStart,
const ViewType1D<sType, sProperties...>& src,
uint32 sStart,
uint32 sEnd
)
{
auto subV = Kokkos::subview(src, Kokkos::make_pair(n,n+1));
hostViewType1D<Type> dstView("getNth",1);
//hostViewTypeScalar
Kokkos::deep_copy(dstView,subV);
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);
}
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);
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;
uint32 numElems = end-start;
using ExecutionSpace =
typename ViewType1D<T, properties...>::execution_space;
if constexpr( isHostAccessible<ExecutionSpace>())
{
pFlow::algorithms::STD::sort<T,true>(
view.data()+start,
numElems);
uint32 numElems = end - start;
if constexpr (isHostAccessible<ExecutionSpace>())
{
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(
ViewType1D<T, properties...>& view,
uint32 start,
uint32 end,
CompareFunc compare)
INLINE_FUNCTION_H void
sort(
ViewType1D<T, properties...>& view,
uint32 start,
uint32 end,
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);
return;
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!");
@ -372,163 +335,157 @@ void sort(
}
template<
typename Type,
typename... properties,
typename permType,
typename... permProperties>
void permuteSort(
const ViewType1D<Type, properties...>& view,
uint32 start,
uint32 end,
ViewType1D<permType, permProperties...>& permuteView,
uint32 permStart )
typename Type,
typename... properties,
typename permType,
typename... permProperties>
void
permuteSort(
const ViewType1D<Type, properties...>& view,
uint32 start,
uint32 end,
ViewType1D<permType, permProperties...>& permuteView,
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");
areAccessible<
typename ViewType1D<Type, properties...>::execution_space,
typename ViewType1D<permType, permProperties...>::memory_space>(),
"In permuteSort, view and permuteView should have the same space"
);
using ExecutionSpace = typename ViewType1D<Type, properties...>::execution_space;
uint32 numElems = end-start;
pFlow::algorithms::STD::permuteSort<Type,permType,true>(
view.data()+start,
permuteView.data()+permStart,
numElems);
using ExecutionSpace =
typename ViewType1D<Type, properties...>::execution_space;
uint32 numElems = end - start;
pFlow::algorithms::STD::permuteSort<Type, permType, true>(
view.data() + start, permuteView.data() + permStart, numElems
);
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;
int low = 0;
int high = length - 1;
if (length <= 0)
return -1;
while (low <= high)
{
int mid = low + (high - low)/2;
if ( array[mid] > val)
{
high = mid - 1;
}
else if ( array[mid] < val)
{
low = mid + 1;
}
else
{
return mid;
}
}
int low = 0;
int high = length - 1;
return -1; // val not found in array[0, length)
while (low <= high)
{
int mid = low + (high - low) / 2;
if (array[mid] > val)
{
high = mid - 1;
}
else if (array[mid] < val)
{
low = mid + 1;
}
else
{
return mid;
}
}
return -1; // val not found in array[0, length)
}
/// On DEVICE and HOST calls
template<
typename Type,
typename... properties>
INLINE_FUNCTION_HD
uint32 binarySearch(
const ViewType1D<Type, properties...>& view,
uint32 start,
uint32 end,
const Type& val)
/// On DEVICE and HOST calls
template<typename Type, typename... properties>
INLINE_FUNCTION_HD uint32
binarySearch(
const ViewType1D<Type, properties...>& view,
uint32 start,
uint32 end,
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(
const ViewType1D<Type, properties...>& view,
uint32 start,
uint32 end,
ViewType1D<Type, dProperties...>& dView,
uint32 dStart )
template<typename Type, typename... properties, typename... dProperties>
void
exclusiveScan(
const ViewType1D<Type, properties...>& view,
uint32 start,
uint32 end,
ViewType1D<Type, dProperties...>& dView,
uint32 dStart
)
{
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"
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"
);
using ExecutionSpace = typename ViewType1D<Type, properties...>::execution_space;
uint32 numElems = end-start;
pFlow::algorithms::KOKKOS::exclusiveScan<Type,ExecutionSpace>(
view.data()+start,
dView.data()+dStart,
numElems);
using ExecutionSpace =
typename ViewType1D<Type, properties...>::execution_space;
uint32 numElems = end - start;
pFlow::algorithms::KOKKOS::exclusiveScan<Type, ExecutionSpace>(
view.data() + start, dView.data() + dStart, numElems
);
}
template<
typename Type,
typename... properties,
typename... dProperties>
void inclusiveScan(
const ViewType1D<Type, properties...>& view,
uint32 start,
uint32 end,
ViewType1D<Type, dProperties...>& dView,
uint32 dStart)
template<typename Type, typename... properties, typename... dProperties>
void
inclusiveScan(
const ViewType1D<Type, properties...>& view,
uint32 start,
uint32 end,
ViewType1D<Type, dProperties...>& dView,
uint32 dStart
)
{
using ExecutionSpace = typename ViewType1D<Type, properties...>::execution_space;
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"
using ExecutionSpace =
typename ViewType1D<Type, properties...>::execution_space;
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

@ -2,50 +2,50 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
template<typename T, typename... properties>
void insertSetElementH
(
ViewType1D<T, properties...>& view,
hostViewType1D<label>& selected,
T val
void
insertSetElementH(
ViewType1D<T, properties...>& view,
hostViewType1D<label>& selected,
T val
);
template<typename T, typename... properties>
void insertSetElementH
(
ViewType1D<T, properties...>& view,
hostViewType1D<label>& selected,
hostViewType1D<T>& vals
void
insertSetElementH(
ViewType1D<T, properties...>& view,
hostViewType1D<label>& selected,
hostViewType1D<T>& vals
);
template<typename T, typename... properties>
void insertSetElementD
(
ViewType1D<T, properties...>& view,
deviceViewType1D<label>& selected,
T val
void
insertSetElementD(
ViewType1D<T, properties...>& view,
deviceViewType1D<label>& selected,
T val
);
template<typename T, typename... properties>
void insertSetElementD
(
ViewType1D<T, properties...>& view,
deviceViewType1D<label>& selected,
deviceViewType1D<T>& vals
void
insertSetElementD(
ViewType1D<T, properties...>& view,
deviceViewType1D<label>& selected,
deviceViewType1D<T>& vals
);

View File

@ -2,17 +2,17 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -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;
@ -31,81 +30,80 @@ namespace pFlow
{
// counts the number of elements that matches val
// the execution space is selected based on the View::execution_spcae
// the execution space is selected based on the View::execution_spcae
/*template<typename T, typename... properties>
INLINE_FUNCTION_H
size_t count(
const ViewType1D<T, properties...>& view,
size_t start,
size_t end,
const T& val
)
const ViewType1D<T, properties...>& view,
size_t start,
size_t end,
const T& val
)
{
auto RP = Kokkos::RangePolicy<
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space >(start, end);
auto RP = Kokkos::RangePolicy<
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space >(start, end);
size_t totalNum=0;
Kokkos::parallel_reduce(
"baseAlgorithms-count",
RP,
LAMBDA_HD(label i, size_t & valueToUpdate){
if( equal(view[i], val) ) valueToUpdate += 1;
}, totalNum );
size_t totalNum=0;
Kokkos::parallel_reduce(
"baseAlgorithms-count",
RP,
LAMBDA_HD(label i, size_t & valueToUpdate){
if( equal(view[i], val) ) valueToUpdate += 1;
}, totalNum );
return totalNum;
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>();
T minValue = largestPositive<T>();
auto RP = Kokkos::RangePolicy<
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space >(start, end);
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space>(start, end);
Kokkos::parallel_reduce("baseAlgorithms-min",
RP,
LAMBDA_HD(label i, T& valueToUpdate){
valueToUpdate = min(view[i],valueToUpdate);
},
Kokkos :: Min < T >( minValue )
);
Kokkos::parallel_reduce(
"baseAlgorithms-min",
RP,
LAMBDA_HD(label i, T & valueToUpdate) {
valueToUpdate = min(view[i], valueToUpdate);
},
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>();
T maxValue = largestNegative<T>();
auto RP = Kokkos::RangePolicy<
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space >(start, end);
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space>(start, end);
Kokkos::parallel_reduce("baseAlgorithms-max",
RP,
LAMBDA_HD(label i, T& valueToUpdate){
valueToUpdate = max(view[i],valueToUpdate);
},
Kokkos::Max<T>( maxValue )
);
Kokkos::parallel_reduce(
"baseAlgorithms-max",
RP,
LAMBDA_HD(label i, T & valueToUpdate) {
valueToUpdate = max(view[i], valueToUpdate);
},
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,116 +111,113 @@ 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)
{
auto RP = Kokkos::RangePolicy<
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space >(start, end);
Kokkos::parallel_for("baseAlgorithms-for_each",
RP,
LAMBDA_HD(label i){
view[i] = func(i);
}
);
}
template<typename T, typename... properties>
void insertSetElementH
(
ViewType1D<T, properties...>& view,
hostViewType1D<label>& selected,
T val
void
apply_to_each(
const ViewType1D<T, properties...>& view,
size_t start,
size_t end,
UnaryFunction func
)
{
for(auto i=0; i<selected.size();++i)
auto RP = Kokkos::RangePolicy<
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space>(start, end);
Kokkos::parallel_for(
"baseAlgorithms-for_each", RP, LAMBDA_HD(label i) { view[i] = func(i); }
);
}
template<typename T, typename... properties>
void
insertSetElementH(
ViewType1D<T, properties...>& view,
hostViewType1D<label>& selected,
T val
)
{
for (auto i = 0; i < selected.size(); ++i)
{
view[selected[i]] = val;
}
}
template<typename T, typename... properties>
void insertSetElementH
(
ViewType1D<T, properties...>& view,
hostViewType1D<label>& selected,
hostViewType1D<T>& vals
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
(
ViewType1D<T, properties...>& view,
deviceViewType1D<label>& selected,
T val
void
insertSetElementD(
ViewType1D<T, properties...>& view,
deviceViewType1D<label>& selected,
T val
)
{
auto RP = Kokkos::RangePolicy<
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space >(0, selected.size());
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space>(
0, selected.size()
);
Kokkos::parallel_for(
"baseAlgorithms-insertSetElementD",
RP,
LAMBDA_D(size_t i) {
view[selected[i]] = val; } );
"baseAlgorithms-insertSetElementD",
RP,
LAMBDA_D(size_t i) { view[selected[i]] = val; }
);
}
template<typename T, typename... properties>
void insertSetElementD
(
ViewType1D<T, properties...>& view,
deviceViewType1D<label>& selected,
deviceViewType1D<T>& vals
void
insertSetElementD(
ViewType1D<T, properties...>& view,
deviceViewType1D<label>& selected,
deviceViewType1D<T>& vals
)
{
auto RP = Kokkos::RangePolicy<
Kokkos::IndexType<size_t>,
typename ViewType1D<T, properties...>::execution_space >(0, selected.size());
Kokkos::IndexType<size_t>,
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]; } );
"baseAlgorithms-insertSetElementD",
RP,
LAMBDA_D(size_t i) { view[selected[i]] = vals[i]; }
);
}
template<typename T, typename... properties>
void fill
(
ViewType3D<T, properties...>& view,
range range1,
range range2,
range range3,
T val
void
fill(
ViewType3D<T, properties...>& view,
range range1,
range range2,
range range3,
T val
)
{
auto subV = Kokkos::subview(view, range1, range2, range3);
@ -231,5 +226,4 @@ void fill
}
#endif // __VectorSingleMath_hpp__

View File

@ -2,17 +2,17 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -23,81 +23,72 @@ Licence:
#include "streams.hpp"
pFlow::Timer::Timer(const word& name, Timers* parrent)
:
name_(name),
parrent_(parrent)
: 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++)
{
os<<"";
for (int32 l = 1; l < lvl; l++)
{
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<<"⊿ ";
if(lvl==0)
os<<greenColor<<boldChar;
else if(master())
os<<yellowColor;
; // os<<"⊿ ";
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

@ -2,40 +2,35 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __Timerr_hpp__
#define __Timerr_hpp__
#include <chrono>
#include "types.hpp"
namespace pFlow
{
// forward
// forward
class Timers;
class Timer
{
protected:
@ -43,25 +38,26 @@ protected:
using timer = std::chrono::high_resolution_clock;
/// start time
timer::time_point start_;
timer::time_point start_;
/// number of times start() and end() are called
int32 numIteration_ = 0;
/// number of times start() and end() are called
int32 numIteration_ = 0;
/// sum of time duratios (in seconds) between all start() and end() calls
real accTime_ = 0.0;
/// sum of time duratios (in seconds) between all start() and end() calls
real accTime_ = 0.0;
/// last time duration
real lastTime_ = 0.0;
/// last time duration
real lastTime_ = 0.0;
/// @brief Accumulative duration for multiple steps between start() and end()
real stepAccTime_ = 0.0;
/// @brief Accumulative duration for multiple steps between start() and
/// end()
real stepAccTime_ = 0.0;
/// name for the timer
word name_ = "noNameTimer";
/// name for the timer
word name_ = "noNameTimer";
/// @brief parrent of timer
Timers* parrent_ = nullptr;
/// @brief parrent of timer
Timers* parrent_ = nullptr;
public:
@ -70,45 +66,45 @@ 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_;
}
virtual ~Timer();
virtual void removeParrent()
{
parrent_ = nullptr;
}
virtual int32 level()const;
virtual int32 level() const;
virtual bool master()const
virtual bool master() const
{
return false;
}
void start()
{
start_ = timer::now();
start_ = timer::now();
stepAccTime_ = 0;
}
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()
@ -119,46 +115,40 @@ public:
void end()
{
pause();
lastTime_ = stepAccTime_;
lastTime_ = stepAccTime_;
numIteration_++;
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

@ -2,22 +2,21 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __createBoundaryFields_hpp__
#define __createBoundaryFields_hpp__
@ -26,19 +25,16 @@ Licence:
#include "periodicBoundaryField/periodicBoundaryField.hpp"
#include "reflectiveBoundaryField/reflectiveBoundaryField.hpp"
#define createDerivedBoundary(DataType, MemorySpaceType) \
template class pFlow::exitBoundaryField<DataType, MemorySpaceType>; \
#define createDerivedBoundary(DataType, MemorySpaceType) \
template class pFlow::exitBoundaryField<DataType, MemorySpaceType>; \
template class pFlow::periodicBoundaryField<DataType, MemorySpaceType>; \
template class pFlow::reflectiveBoundaryField<DataType, MemorySpaceType>;
#define createBaseBoundary(DataType, MemorySpaceType) \
#define createBaseBoundary(DataType, MemorySpaceType) \
template class pFlow::boundaryField<DataType, MemorySpaceType>;
#define createBoundaryFields(DataType, MemorySpaceType) \
createBaseBoundary(DataType, MemorySpaceType); \
#define createBoundaryFields(DataType, MemorySpaceType) \
createBaseBoundary(DataType, MemorySpaceType); \
createDerivedBoundary(DataType, MemorySpaceType);
#endif //__createBoundaryFields_hpp__

View File

@ -2,17 +2,17 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -21,86 +21,102 @@ Licence:
#include <iostream>
#include <stdlib.h>
#include <Kokkos_Core.hpp>
#include "error.hpp"
#include "processors.hpp"
#include "streams.hpp"
// static pFlow::Ostream& errorStream = pFlow::errReport;
static pFlow::Ostream& errorStream = pFlow::pOutput;
//static pFlow::Ostream& errorStream = pFlow::errReport;
static pFlow::Ostream& errorStream = pFlow::pOutput;
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';
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& 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

@ -2,17 +2,17 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -21,62 +21,80 @@ Licence:
#ifndef __error_hpp__
#define __error_hpp__
#include "builtinTypes.hpp"
//- Forward decleartions
//- Forward decleartions
namespace pFlow
{
class iOstream;
class iOstream;
}
//- Decleartions
//- Decleartions
/// Take actions to fatal exit phasicFlow
int fatalExitPhasicFlow(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);
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__)
/// Report a fatal error and exit the applicaiton
#define fatalError \
fatalErrorMessage(__FILE__, __LINE__)
/// Report a fatal error and supplied function name and exit the application
#define fatalErrorIn(functionName) \
fatalErrorInMessage((functionName), __FILE__, __LINE__)
/// Report a fatal error and supplied function name and exit the application
#define fatalErrorIn( functionName ) \
fatalErrorInMessage((functionName), __FILE__, __LINE__ )
/// Report a fatal error and function name and exit the application
/// 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__ )
/// Report that a function is yet not implemented with supplied function name.
#define Not_Implemented(functionName) \
notImplementedErrorMessage((functionName), __FILE__, __LINE__)
/// Report that a function is yet not implemented.
/// 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__ )
/// Report an error in file operation with supplied fileName and lineNumber.
#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()
/// Fatal exit
#define fatalExit reportAndExit()
#endif

View File

@ -2,17 +2,17 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -21,40 +21,36 @@ Licence:
#ifndef __vocabs_hpp__
#define __vocabs_hpp__
namespace pFlow
{
// folders / repositories
const inline char* settingsFolder__ = "settings";
const inline char* settingsRepository__ = "settings";
const inline char* caseSetupFolder__ = "caseSetup";
const inline char* caseSetupRepository__ = "caseSetup";
const inline char* geometryFolder__ = "geometry";
const inline char* geometryRepository_ = "geometry";
const inline char* integrationRepository__ = "integration";
const inline char* integrationFolder__ = "integration";
// folders / repositories
const inline char* settingsFolder__ = "settings";
const inline char* settingsRepository__ = "settings";
const inline char* caseSetupFolder__ = "caseSetup";
const inline char* caseSetupRepository__ = "caseSetup";
const inline char* geometryFolder__ = "geometry";
const inline char* geometryRepository_ = "geometry";
const inline char* integrationRepository__ = "integration";
const inline char* integrationFolder__ = "integration";
// file names
const inline char* settingsFile__ = "settingsDict";
const inline char* domainFile__ = "domainDict";
const inline char* insertionFile__ = "particleInsertion";
const inline char* shapeFile__ = "shapes";
const inline char* pointStructureFile__ = "pStructure";
const inline char* triSurfaceFile__ = "triSurface";
const inline char* createParticles__ = "createParticles";
const inline char* motionModelFile__ = "motionModel";
const inline char* contactSearchFile__ = "contactSearch";
const inline char* propertyFile__ = "interaction";
const inline char* interactionFile__ = "interaction";
const inline char* settingsFile__ = "settingsDict";
const inline char* domainFile__ = "domainDict";
const inline char* insertionFile__ = "particleInsertion";
const inline char* shapeFile__ = "shapes";
const inline char* pointStructureFile__ = "pStructure";
const inline char* triSurfaceFile__ = "triSurface";
const inline char* createParticles__ = "createParticles";
const inline char* motionModelFile__ = "motionModel";
const inline char* contactSearchFile__ = "contactSearch";
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";
const inline char* uniform__ = "uniform";
const inline char* nonUniform__ = "nonUniform";
}
#endif // __vocabs_hpp__

View File

@ -2,114 +2,93 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#include "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
pFlow::Time::Time(repository* owner, const dictionary& setiingsDict)
: repository("Time", "", owner),
timeControl(setiingsDict),
geometry_(geometryRepository_, geometryFolder__, this)
{
if (!readDictionary(setiingsDict))
{
fatalExit;
}
}
pFlow::Time::Time(
repository* owner,
dictionary& setiingsDict,
real startTime,
real endTime,
real saveInterval,
word startTimeName
)
:
repository("Time", "", owner),
timeControl(setiingsDict),
geometry_
(
geometryRepository_,
geometryFolder__,
this
)
: repository("Time", "", owner),
timeControl(setiingsDict, startTime, endTime, saveInterval, startTimeName),
geometry_(geometryRepository_, geometryFolder__, this)
{
if(!readDictionary(setiingsDict))
if (!readDictionary(setiingsDict))
{
fatalExit;
}
}
pFlow::Time::Time(
repository* owner,
dictionary& setiingsDict,
real startTime,
real endTime,
real saveInterval,
word startTimeName)
:
repository("Time", "", owner),
timeControl(
setiingsDict,
startTime,
endTime,
saveInterval,
startTimeName),
geometry_
(
geometryRepository_,
geometryFolder__,
this
)
pFlow::fileSystem
pFlow::Time::localPath() const
{
if(!readDictionary(setiingsDict))
{
fatalExit;
}
return fileSystem(timeName());
}
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

@ -2,34 +2,31 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __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,63 +34,59 @@ namespace pFlow
class dictionary;
class Time
:
public repository,
public timeControl
: public repository
, public timeControl
{
private:
protected:
bool outFormatBinary_ = false;
bool outFormatBinary_ = false;
// - geometry folder/repository
repository geometry_;
// - geometry folder/repository
repository geometry_;
bool readDictionary(const dictionary& dict);
bool readDictionary(const dictionary& dict);
public:
// Constructor with owner and settings dict
Time( repository* owner, const dictionary& setiingsDict);
Time(
repository* owner,
dictionary& setiingsDict,
real startTime,
real endTime,
real saveInterval,
word startTimeName);
Time(repository* owner, const dictionary& setiingsDict);
Time(
repository* owner,
dictionary& setiingsDict,
real startTime,
real endTime,
real saveInterval,
word startTimeName
);
//// - Methods
fileSystem localPath()const override;
// - geometry repository
const repository& geometry()const
{
return geometry_;
}
fileSystem localPath() const override;
repository& geometry()
{
return geometry_;
}
// - geometry repository
const repository& geometry() const
{
return geometry_;
}
fileSystem integrationFolder()const;
/// Write to the file with binary format?
bool outFileBinary()const override
{
return outFormatBinary_;
}
repository& geometry()
{
return geometry_;
}
// override the base write to manage write operation
// based on the valid write time intervals
virtual bool write(bool verbose = false) const;
fileSystem integrationFolder() const;
/// Write to the file with binary format?
bool outFileBinary() const override
{
return outFormatBinary_;
}
// 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

@ -44,10 +44,29 @@ public:
const dictionary& dict,
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

@ -2,48 +2,44 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#include "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,228 +47,149 @@ 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('/');
auto last = wPath.find_last_of('/');
if (first == word::npos)
{
fatalErrorInFunction << "path is empty \n";
fatalExit;
}
if (last == wPath.size() - 1)
{
wPath = wPath.substr(0, last);
last = wPath.find_last_of('/');
}
word rName = wPath.substr(last + 1);
if( first == word::npos)
{
fatalErrorInFunction <<
"path is empty \n";
fatalExit;
}
if( last == wPath.size()-1)
{
wPath = wPath.substr(0,last);
last = wPath.find_last_of('/');
}
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('/');
auto last = wPath.find_last_of('/');
if( first == word::npos)
{
fatalErrorInFunction <<
"path is empty \n";
fatalExit;
}
if (first == word::npos)
{
fatalErrorInFunction << "path is empty \n";
fatalExit;
}
if( last == wPath.size()-1)
{
wPath = wPath.substr(0,last);
last = wPath.find_last_of('/');
}
if (last == wPath.size() - 1)
{
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
(
"systemControl",
path, // local path
nullptr // no owner
),
runName_
(
getRunName(path)
),
topLevelFolder_
(
getTopFolder(path)
),
settingsDict_
(
makeUnique<fileDictionary>
(
objectFile
(
settingsFile__,
settingsFolder__,
objectFile::READ_ALWAYS,
objectFile::WRITE_NEVER
),
this
)
pFlow::systemControl::systemControl(const fileSystem path)
: repository(
"systemControl",
path, // local path
nullptr // no owner
),
Time_
(
this,
settingsDict_()
),
settings_
(
makeUnique<repository>
(
settingsRepository__,
runName_(getRunName(path)),
topLevelFolder_(getTopFolder(path)),
settingsDict_(makeUnique<fileDictionary>(
objectFile(
settingsFile__,
settingsFolder__,
this
)
objectFile::READ_ALWAYS,
objectFile::WRITE_NEVER
),
this
)),
Time_(this, settingsDict_()),
settings_(
makeUnique<repository>(settingsRepository__, settingsFolder__, this)
),
caseSetup_
(
makeUnique<repository>
(
caseSetupRepository__,
caseSetupFolder__,
this
)
),
libs_(settingsDict_()),
outFilePrecision_
(
settingsDict_().getValOrSet("outFilePrecision", static_cast<uint64>(6))
),
timers_(runName_),
timersReport_
(
settingsDict_().getValOrSet("timersReport", Logical("Yes"))
),
writeToFileTimer_("Write to file", &timers_)
caseSetup_(
makeUnique<repository>(caseSetupRepository__, caseSetupFolder__, this)
),
libs_(settingsDict_()),
outFilePrecision_(
settingsDict_().getValOrSet("outFilePrecision", static_cast<uint64>(6))
),
timers_(runName_),
timersReport_(settingsDict_().getValOrSet("timersReport", Logical("Yes"))),
writeToFileTimer_("Write to file", &timers_)
{
readIncludeExclue(settingsDict_());
readIncludeExclue(settingsDict_());
}
pFlow::systemControl::systemControl(
const real startTime,
const real endTime,
const real saveInterval,
const word startTimeName,
const fileSystem path)
:
repository
(
"systemControl",
path, // local path
nullptr // no owner
),
runName_
(
getRunName(path)
),
topLevelFolder_
(
getTopFolder(path)
),
settingsDict_
(
makeUnique<fileDictionary>
(
objectFile
(
settingsFile__,
settingsFolder__,
objectFile::READ_ALWAYS,
objectFile::WRITE_NEVER
),
this
)
const real startTime,
const real endTime,
const real saveInterval,
const word startTimeName,
const fileSystem path
)
: repository(
"systemControl",
path, // local path
nullptr // no owner
),
Time_
(
this,
settingsDict_(),
startTime,
endTime,
saveInterval,
startTimeName
),
settings_
(
makeUnique<repository>
(
settingsRepository__,
runName_(getRunName(path)),
topLevelFolder_(getTopFolder(path)),
settingsDict_(makeUnique<fileDictionary>(
objectFile(
settingsFile__,
settingsFolder__,
this
)
objectFile::READ_ALWAYS,
objectFile::WRITE_NEVER
),
this
)),
Time_(
this,
settingsDict_(),
startTime,
endTime,
saveInterval,
startTimeName
),
caseSetup_
(
makeUnique<repository>
(
caseSetupRepository__,
caseSetupFolder__,
this
)
),
libs_(settingsDict_()),
externalTimeControl_(true),
timers_(runName_),
timersReport_
(
settingsDict_->getValOrSet("timersReport", Logical("Yes"))
),
writeToFileTimer_("Write to file", &timers_)
settings_(
makeUnique<repository>(settingsRepository__, settingsFolder__, this)
),
caseSetup_(
makeUnique<repository>(caseSetupRepository__, caseSetupFolder__, this)
),
libs_(settingsDict_()),
externalTimeControl_(true),
timers_(runName_),
timersReport_(settingsDict_->getValOrSet("timersReport", Logical("Yes"))),
writeToFileTimer_("Write to file", &timers_)
{
readIncludeExclue(settingsDict_());
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() )
//- save the results to file
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;
@ -299,8 +214,6 @@ bool pFlow::systemControl::operator ++(int)
timers_.write(output, true);
}
return toContinue;
}

View File

@ -2,207 +2,266 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#ifndef __typeInfo_hpp__
#define __typeInfo_hpp__
#include <typeinfo>
#include <cxxabi.h>
#include <typeinfo>
#include "bTypes.hpp"
#define has_static_member(name) \
template<typename, typename> \
struct has_static_member_##name; \
\
template<typename testType, typename Ret, typename... Args> \
struct has_static_member_##name<testType, Ret(Args...)> { \
template<typename U, U> struct Check; \
\
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; \
};
#define has_static_member(name) \
template <typename, typename> \
struct has_static_member_##name; \
\
template <typename testType, typename Ret, typename... Args> \
struct has_static_member_##name<testType, Ret(Args...)> \
{ \
template <typename U, U> \
struct Check; \
\
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
{
has_static_member(TYPENAME);
static constexpr
bool hasMember()
{
return has_static_member_TYPENAME<T,word(void)>::value;
}
};
//
template <typename T>
struct checkStatic
{
has_static_member(TYPENAME);
template <typename T>
inline word basicTypeName()
static constexpr bool hasMember()
{
int status;
auto& ti = typeid(T);
char* realname = abi::__cxa_demangle(ti.name(), nullptr, nullptr, &status);
word name(realname);
free(realname);
return name;
return has_static_member_TYPENAME<T, word(void)>::value;
}
};
template<>
inline word basicTypeName<word>(){ return "word"; }
template <typename T>
inline word basicTypeName()
{
int 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<int64>(){ return "int64"; }
template <>
inline word basicTypeName<word>()
{
return "word";
}
template<>
inline word basicTypeName<int32>(){ return "int32"; }
template <>
inline word basicTypeName<int64>()
{
return "int64";
}
template<>
inline word basicTypeName<int8>(){ return "int8"; }
template <>
inline word basicTypeName<int32>()
{
return "int32";
}
template<>
inline word basicTypeName<uint64>(){ return "uint64"; }
template <>
inline word basicTypeName<int8>()
{
return "int8";
}
template<>
inline word basicTypeName<uint32>(){ return "uint32"; }
template <>
inline word basicTypeName<uint64>()
{
return "uint64";
}
template<>
inline word basicTypeName<uint8>(){ return "uint8"; }
template <>
inline word basicTypeName<uint32>()
{
return "uint32";
}
template<>
inline word basicTypeName<real>(){ return "real"; }
template <>
inline word basicTypeName<uint8>()
{
return "uint8";
}
template<typename T>
word constexpr getTypeName()
template <>
inline word basicTypeName<real>()
{
return "real";
}
template <typename T>
word constexpr getTypeName()
{
if constexpr (checkStatic<T>::hasMember())
{
if constexpr ( checkStatic<T>::hasMember() )
{
return T::TYPENAME();
}else
{
return basicTypeName<T>();
}
return T::TYPENAME();
}
template<typename T>
word constexpr getTypeName(const T&)
else
{
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();
return basicTypeName<T>();
}
}
template <typename T>
word constexpr getTypeName(const T &)
{
if constexpr (checkStatic<T>::hasMember())
{
return T::TYPENAME();
}
else
{
return basicTypeName<T>();
}
}
#define TypeInfo(tName) \
inline static word TYPENAME() {return tName; } \
virtual word typeName() const {return TYPENAME();}
// 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();
}
#define TypeInfoNV(tName) \
inline static word TYPENAME() {return tName; } \
word typeName() const {return 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(); \
}
#define TypeInfoTemplate11(tName, Type) \
inline static word TYPENAME() \
{ \
return word(tName)+"<"+getTypeName<Type>()+">"; \
} \
virtual word typeName() const { return TYPENAME();}
#define TypeInfoNV(tName) \
inline static word TYPENAME() \
{ \
return tName; \
} \
word typeName() const \
{ \
return TYPENAME(); \
}
#define TypeInfoTemplate12(tName, Type1, Type2) \
inline static word TYPENAME() \
{ \
return word(tName)+"<"+getTypeName<Type1>()+","+getTypeName<Type2>()+">"; \
} \
virtual word typeName() const { return TYPENAME();}
#define TypeInfoTemplate11(tName, Type) \
inline static word TYPENAME() \
{ \
return word(tName) + "<" + getTypeName<Type>() + ">"; \
} \
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>()+">";\
} \
virtual word typeName() const { return TYPENAME();}
#define TypeInfoTemplate12(tName, Type1, Type2) \
inline static word TYPENAME() \
{ \
return word(tName) + "<" + getTypeName<Type1>() + "," + \
getTypeName<Type2>() + ">"; \
} \
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>() + ">"; \
} \
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>()+">"; \
} \
inline word typeName() const { return TYPENAME();}
#define TypeInfoTemplateNV11(tName, Type) \
inline static word TYPENAME() \
{ \
return word(tName) + "<" + getTypeName<Type>() + ">"; \
} \
inline word typeName() const \
{ \
return TYPENAME(); \
}
#define TypeInfoTemplateNV111(tName, Type, tName2) \
inline static word TYPENAME() \
{ \
return word(tName) + "<" + getTypeName<Type>() + "," + word(tName2) + \
">"; \
} \
inline word typeName() const \
{ \
return TYPENAME(); \
}
#define TypeInfoTemplateNV111(tName, Type, tName2) \
inline static word TYPENAME() \
{ \
return word(tName)+"<"+getTypeName<Type>()+","+word(tName2)+">"; \
} \
inline word typeName() const { return TYPENAME();}
#define TypeInfoTemplate111(tName, Type, tName2) \
inline static word TYPENAME() \
{ \
return word(tName) + "<" + getTypeName<Type>() + "," + word(tName2) + \
">"; \
} \
virtual word typeName() const \
{ \
return TYPENAME(); \
}
#define TypeInfoTemplate111(tName, Type, tName2) \
inline static word TYPENAME() \
{ \
return word(tName)+"<"+getTypeName<Type>()+","+word(tName2)+">"; \
} \
virtual word typeName() const { return TYPENAME();}
#define TypeInfoTemplate211(tBase,tName1, Type, tName3) \
inline static word TYPENAME() \
{ \
return word(tBase)+"<"+word(tName1)+","+getTypeName<Type>()+","+word(tName3)+">"; \
} \
virtual word typeName() const { return TYPENAME();}
#define TypeInfoTemplate22(tBase,tName1, Type1, Type2) \
inline static word TYPENAME() \
{ \
return word(tBase)+"<"+word(tName1)+","+getTypeName<Type1>()+","+getTypeName<Type2>()+">"; \
} \
virtual word typeName() const { return TYPENAME();}
#define TypeInfoTemplate211(tBase, tName1, Type, tName3) \
inline static word TYPENAME() \
{ \
return word(tBase) + "<" + word(tName1) + "," + getTypeName<Type>() + \
"," + word(tName3) + ">"; \
} \
virtual word typeName() const \
{ \
return TYPENAME(); \
}
#define TypeInfoTemplate22(tBase, tName1, Type1, Type2) \
inline static word TYPENAME() \
{ \
return word(tBase) + "<" + word(tName1) + "," + getTypeName<Type1>() + \
"," + getTypeName<Type2>() + ">"; \
} \
virtual word typeName() const \
{ \
return TYPENAME(); \
}
#endif

View File

@ -2,17 +2,17 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -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) \
\
typedef std::function< uniquePtr<baseClass> argList > selectorName##FunctionType; \
typedef wordMap<selectorName##FunctionType> selectorName##vCtorSelectorType; \
\
inline static selectorName##vCtorSelectorType selectorName##vCtorSelector_; \
\
\
template<typename dType> \
class create##selectorName##Callback \
{ \
public: \
create##selectorName##Callback () \
{ \
auto success = \
selectorName##vCtorSelector_.insertIf \
( \
word(dType::TYPENAME()), \
[&] argList -> uniquePtr<baseClass> \
{ \
return uniquePtr<baseClass> \
( \
new dType args \
); \
} \
); \
\
if( !success ) \
{ \
fatalErrorInFunction \
<< "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; \
};
#define add_vCtor(baseClass, derivedClass, selectorName) \
\
inline static typename baseClass::template create##selectorName##Callback<derivedClass> baseClass##derivedClass##selectorName##_;
#define create_vCtor(baseClass, selectorName, argList, args) \
\
typedef std::function<uniquePtr<baseClass> argList> \
selectorName##FunctionType; \
typedef wordMap<selectorName##FunctionType> \
selectorName##vCtorSelectorType; \
\
inline static selectorName##vCtorSelectorType \
selectorName##vCtorSelector_; \
\
template<typename dType> \
class create##selectorName##Callback \
{ \
public: \
\
create##selectorName##Callback() \
{ \
auto success = selectorName##vCtorSelector_.insertIf( \
word(dType::TYPENAME()), \
[&] argList -> uniquePtr<baseClass> \
{ return uniquePtr<baseClass>(new dType args); } \
); \
\
if (!success) \
{ \
fatalErrorInFunction \
<< "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; \
};
#define add_vCtor(baseClass, derivedClass, selectorName) \
\
inline static typename baseClass::template create##selectorName##Callback< \
derivedClass> \
baseClass##derivedClass##selectorName##_;
#endif // __virtualConstructor_hpp__

View File

@ -2,17 +2,17 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -23,37 +23,36 @@ 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;
b = true;
yesNoSet = i;
return true;
}
else if( toUpper(YesNo__[i][1]) == Ul )
else if (toUpper(YesNo__[i][1]) == Ul)
{
b = false;
b = false;
yesNoSet = i;
return true;
}
@ -62,66 +61,66 @@ 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;
if (!t.good())
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Bad token - could not get Logical value";
is.setBad();
return false;
}
if (t.isString())
{
w = t.stringToken();
}
else if(t.isWord() )
{
w = t.wordToken();
}
else
{
ioErrorInFile(is.name(), is.lineNumber())
<< "Wrong token type - expected Logical value, found "
<< t;
is.setBad();
return false;
}
return evaluteWord(w, s_, yesNoSet_);
}
bool pFlow::Logical::write
(
iOstream& os
)const
{
if(s_)
word w;
if (!t.good())
{
os<< YesNo__[yesNoSet_][0];
ioErrorInFile(is.name(), is.lineNumber())
<< "Bad token - could not get Logical value";
is.setBad();
return false;
}
if (t.isString())
{
w = t.stringToken();
}
else if (t.isWord())
{
w = t.wordToken();
}
else
{
os<< YesNo__[yesNoSet_][1];
ioErrorInFile(is.name(), is.lineNumber())
<< "Wrong token type - expected Logical value, found " << t;
is.setBad();
return false;
}
return os.check(FUNCTION_NAME);
}
pFlow::iIstream& pFlow::operator>>( iIstream& is, Logical& L)
{
if(!L.read(is))
{
fatalExit;
}
return is;
return evaluteWord(w, s_, yesNoSet_);
}
pFlow::iOstream& pFlow::operator<< ( iOstream& os, const Logical& L)
bool
pFlow::Logical::write(iOstream& os) const
{
if(!L.write(os))
if (s_)
{
os << YesNo__[yesNoSet_][0];
}
else
{
os << YesNo__[yesNoSet_][1];
}
return os.check(FUNCTION_NAME);
}
pFlow::iIstream&
pFlow::operator>>(iIstream& is, Logical& L)
{
if (!L.read(is))
{
fatalExit;
}
return is;
}
pFlow::iOstream&
pFlow::operator<<(iOstream& os, const Logical& L)
{
if (!L.write(os))
{
fatalExit;
}

View File

@ -2,17 +2,17 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -28,112 +28,115 @@ Licence:
namespace pFlow
{
//- Forward
//- Forward
class iIstream;
class iOstream;
/**
* Holds a bool value and converts strings to bool
*
* Holds a bool value and converts strings to bool
*
*/
class Logical
{
protected:
private:
/// bool value
bool s_ = false;
/// bool value
bool s_ = false;
/// Set numbe of of Yes or No
int yesNoSet_ = 0;
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
/// Construct from bool and set number
inline explicit Logical(bool s, int yns)
:
s_(s),
yesNoSet_(yns)
{}
: s_(s),
yesNoSet_(yns)
{
}
public:
/// Type info
TypeInfoNV("Logical");
//// Constructors
/// Default constructor
inline Logical(){}
/// Construct from bool
inline explicit Logical(bool s)
:
s_(s)
{}
//// Constructors
/// Construct from word
Logical(const word& l);
/// Construct from char string
Logical(const char* ch);
/// Default constructor
inline Logical() = default;
/// Copy
Logical(const Logical&) = default;
/// Construct from bool
inline explicit Logical(bool s)
: s_(s)
{
}
/// Move
Logical(Logical&&) = default;
/// Construct from word
Logical(const word& l);
/// Copy assignment
Logical& operator=(const Logical&) = default;
/// Construct from char string
Logical(const char* ch);
/// Move assignment
Logical& operator=(Logical&&) = default;
/// Copy
Logical(const Logical&) = default;
/// Assignment with bool
inline Logical& operator=(const bool& b)
{
s_ = b;
yesNoSet_ = 0;
return *this;
}
//// Methods
/// () operator, return bool value
inline bool operator()() const
{
return s_;
}
/// Return bool value
inline explicit operator bool() const
{
return s_;
}
/// Move
Logical(Logical&&) = default;
/// Not operator
inline Logical operator!()const
{
return Logical(!s_, yesNoSet_);
}
/// Copy assignment
Logical& operator=(const Logical&) = default;
/// Move assignment
Logical& operator=(Logical&&) = default;
/// Assignment with bool
inline Logical& operator=(const bool& b)
{
s_ = b;
yesNoSet_ = 0;
return *this;
}
//// Methods
/// () operator, return bool value
inline bool operator()() const
{
return s_;
}
/// Return bool value
inline explicit operator bool() const
{
return s_;
}
/// Not operator
inline Logical operator!() const
{
return Logical(!s_, yesNoSet_);
}
//// IO operations
bool read(iIstream& is);
bool write(iOstream& os)const;
bool read(iIstream& is);
//// Static members
bool write(iOstream& os) const;
bool static evaluteWord(const word& l, bool& b, int& yesNoSet );
//// Static members
bool static evaluteWord(const word& l, bool& b, int& yesNoSet);
};
iIstream& operator>>( iIstream& is, Logical& L);
iIstream&
operator>>(iIstream& is, Logical& L);
iOstream& operator<<( iOstream& os, const Logical& L);
iOstream&
operator<<(iOstream& os, const Logical& L);
} // pFlow

View File

@ -2,359 +2,400 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#include <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);
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
: std::count(s, (s + std::char_traits<char>::length(s)), c)
);
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;
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;
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);
word s = toUpper(str);
if( s == "YES" || s=="Y" || s == "OK" || s == "TRUE" || s == "ON" || s=="T") return true;
return false;
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);
word s = toUpper(str);
if( s == "NO" || s == "N" || "FALSE" || s == "OFF" || s == "F") return true;
return false;
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;
std::stringstream ss;
ss << std::fixed << std::setprecision(numPrecision) << v;
return ss.str();
ss << std::fixed << std::setprecision(numPrecision) << v;
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 )
{
ss <<"0";
}
else
{
ss << std::setprecision(numPrecision) << v;
}
return ss.str();
std::stringstream ss;
if (abs(v) < verySmallValue)
{
ss << "0";
}
else
{
ss << std::setprecision(numPrecision) << v;
}
return ss.str();
}
pFlow::word pFlow::int322Word(const int32 & v)
pFlow::word
pFlow::int322Word(const int32& v)
{
std::stringstream ss;
std::stringstream ss;
ss << v;
return ss.str();
ss << 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;
auto len = str.size();
if(len == word::npos) return str;
auto firstZero = word::npos;
for(auto n=len-1; n>dec;n--)
{
if( str[n] == '0' )
{
firstZero = n;
}
else
{
break;
}
}
auto dec = str.find('.');
if (dec == word::npos)
return str;
if(firstZero == dec+1) firstZero = dec;
return str.substr(0,firstZero);
auto len = str.size();
if (len == word::npos)
return str;
auto firstZero = word::npos;
for (auto n = len - 1; n > dec; n--)
{
if (str[n] == '0')
{
firstZero = n;
}
else
{
break;
}
}
if (firstZero == dec + 1)
firstZero = dec;
return str.substr(0, firstZero);
}
pFlow::word pFlow::real2FixedStripZeros(const real & v, int32 numPrecision)
pFlow::word
pFlow::real2FixedStripZeros(const real& v, int32 numPrecision)
{
word strVal = real2Fixed(v, numPrecision);
return removeDecimalZeros(strVal);
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
(
const word& base,
const word& w1,
const word& w2
pFlow::word
pFlow::angleBracketsNames2(const word& base, const word& w1, const word& w2)
{
return base + "<" + w1 + "," + w2 + ">";
}
pFlow::word
pFlow::angleBracketsNames3(
const word& base,
const word& w1,
const word& w2,
const word& w3
)
{
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)
pFlow::word
pFlow::groupNames(const word& bw, const word& tw, char sep)
{
return base+"<"+w1+","+w2+","+w3+">";
return bw + sep + tw;
}
pFlow::word pFlow::groupNames(const word& bw, const word& tw, char sep)
pFlow::word
pFlow::baseName(const word& w, char sep)
{
return bw + sep + tw;
if (auto pos = w.find_last_of(sep); pos != word::npos)
{
return w.substr(0, pos);
}
else
{
return w;
}
}
pFlow::word pFlow::baseName(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)
{
return w.substr(0,pos);
}
else
{
return w;
}
if (auto pos = w.find_last_of(sep); pos != word::npos)
{
return w.substr(pos + 1);
}
else
{
return nullWord;
}
}
pFlow::word pFlow::tailName(const word& w, char sep)
bool
pFlow::validWord(char c)
{
if( auto pos = w.find_last_of(sep); pos != word::npos)
{
return w.substr(pos+1);
}
else
{
return nullWord;
}
return (
!isspace(c) && c != '"' // string quote
&& c != '\'' // string quote
//&& c != '/' // path separator
&& c != ';' // end statement
&& c != '{' // beg subdict
&& c != '}' // end subdict
);
}
bool pFlow::validWord(char c)
bool
pFlow::validWordWithQuote(char c)
{
return
(
!isspace(c)
&& c != '"' // string quote
&& c != '\'' // string quote
//&& c != '/' // path separator
&& c != ';' // end statement
&& c != '{' // beg subdict
&& c != '}' // end subdict
);
return (
!isspace(c) && c != ';' // end statement
&& c != '{' // beg subdict
&& c != '}' // end subdict
);
}
bool pFlow::validWordWithQuote(char c)
bool
pFlow::validWord(const word& w)
{
return
(
!isspace(c)
&& c != ';' // end statement
&& c != '{' // beg subdict
&& c != '}' // end subdict
);
for (auto wi : w)
{
char c = wi;
if (!validWord(c))
return false;
}
return true;
}
bool pFlow::validWord(const word& w)
bool
pFlow::validWordWithQuote(const word& w)
{
for(auto wi:w)
{
char c = wi;
if ( !validWord(c) ) return false;
}
return true;
for (auto wi : w)
{
char c = wi;
if (!validWordWithQuote(c))
return false;
}
return true;
}
bool pFlow::validWordWithQuote(const word& w)
bool
pFlow::readUint32(const word& w, uint32& val)
{
for(auto wi:w)
{
char c = wi;
if ( !validWordWithQuote(c) ) return false;
}
return true;
try
{
val = std::stoul(w);
}
catch (...)
{
return false;
}
return true;
}
bool pFlow::readUint32( const word& w, uint32 & val)
bool
pFlow::readUint32(const char* buf, uint32& val)
{
try{
val = std::stoul(w);
}
catch (...)
{
return false;
}
return true;
word w(buf);
return readUint32(w, val);
}
bool pFlow::readUint32( const char* buf, uint32 & val)
bool
pFlow::readInt64(const word& w, int64& val)
{
word w(buf);
return readUint32(w, val);
try
{
val = std::stoll(w);
}
catch (...)
{
return false;
}
return true;
}
bool pFlow::readInt64( const word& w, int64 & val)
bool
pFlow::readInt64(const char* buf, int64& val)
{
try{
val = std::stoll(w);
}
catch (...)
{
return false;
}
return true;
word w(buf);
return readInt64(w, val);
}
bool pFlow::readInt64( const char* buf, int64 & val)
bool
pFlow::readInt32(const word& w, int32& val)
{
word w(buf);
return readInt64(w, val);
try
{
val = std::stoi(w);
}
catch (...)
{
return false;
}
return true;
}
bool pFlow::readInt32( const word& w, int32 & val)
bool
pFlow::readInt32(const char* buf, int32& val)
{
try{
val = std::stoi(w);
}
catch (...)
{
return false;
}
return true;
word w(buf);
return readInt32(w, val);
}
bool pFlow::readInt32( const char* buf, int32 & val)
bool
pFlow::readInt8(const word& w, int8& val)
{
word w(buf);
return readInt32(w, val);
try
{
val = std::stoi(w);
}
catch (...)
{
return false;
}
return true;
}
bool pFlow::readInt8( const word& w, int8 & val)
bool
pFlow::readInt8(const char* buf, int8& val)
{
try{
val = std::stoi(w);
}
catch (...)
{
return false;
}
return true;
word w(buf);
return readInt8(w, val);
}
bool pFlow::readInt8( const char* buf, int8 & val)
// #include <iostream>
bool
pFlow::readReal(const word& w, real& val)
{
word w(buf);
return readInt8(w, val);
try
{
val = std::stod(w);
}
catch (std::out_of_range& e)
{
val = static_cast<real>(std::stold(w));
}
catch (...)
{
return false;
}
return true;
}
//#include <iostream>
bool pFlow::readReal( const word& w, real & val)
bool
pFlow::readReal(const char* buf, real& val)
{
try{
val = std::stod(w);
}
catch (std:: out_of_range& e)
{
val = static_cast<real>( std::stold(w) );
}
catch (...){
return false;
}
return true;
char* c;
val = std::strtod(buf, &c);
if (val == HUGE_VAL)
{
val = static_cast<real>(std::strtold(buf, &c));
if (val == HUGE_VAL || c == buf)
return false;
}
else if (c == buf)
{
return false;
}
return true;
}
bool pFlow::readReal( const char* buf, real & val )
bool
pFlow::readBoolian_Str(const word& w, bool& val)
{
char* c;
val = std::strtod(buf, &c);
if(val == HUGE_VAL)
{
val = static_cast<real>( std::strtold(buf, &c) );
if(val == HUGE_VAL || c==buf)
return false;
}
else if(c == buf)
{
return false;
}
return true;
if (bool t = isYes(w); t)
{
val = true;
return true;
}
if (bool f = isNo(w); f)
{
val = false;
return true;
}
return false;
}
bool pFlow::readBoolian_Str( const word& w, bool & val)
bool
pFlow::readBoolian_Str(const char* buf, bool& val)
{
if( bool t = isYes(w); t )
{
val = true;
return true;
}
if( bool f = isNo(w); f )
{
val = false;
return true;
}
return false;
}
bool pFlow::readBoolian_Str( const char* buf, bool & val)
{
word w(buf);
return readBoolian_Str(w, val);
word w(buf);
return readBoolian_Str(w, val);
}

View File

@ -2,248 +2,286 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
/*! \file bTypeFunctions.hpp
\brief Helper functions for built-in types.
*/
\brief Helper functions for built-in types.
*/
#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
{
/// Zero real variable
/// Zero real variable
inline const real zero = 0.0;
/// one real variable
inline const real one = 1.0;
/// one real variable
inline const real one = 1.0;
/// zero int32 variable
inline const int32 zero32 = 0;
/// zero int32 variable
inline const int32 zero32 = 0;
/// one int32 variable
inline const int32 one32 = 1;
/// one int32 variable
inline const int32 one32 = 1;
/// null/empty word
inline const word nullWord;
/// null/empty word
inline const word nullWord;
/// white space
inline const word whiteSpace(" \t\n\v\f\r");
/// white space
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);
/// Convert floating point variable to string with fixed number of precisions
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);
/// Convert floating point variable to string with general format
word
real2Word(const real& v, int32 numPrecision = 6);
/// Convert int32 to word
word int322Word(const int32 & v);
/// Convert int32 to word
word
int322Word(const int32& v);
/// Remove zeros from decimal part of a string number
word removeDecimalZeros(const word& str);
/// Remove zeros from decimal part of a string number
word
removeDecimalZeros(const word& str);
/// Convert to fixed point variable and remove zeros
word real2FixedStripZeros(const real & v, int32 numPrecision = 6);
/// Output <w1,w2>
word angleBracketsNames(const word& w1, const word& w2);
/// Convert to fixed point variable and remove zeros
word
real2FixedStripZeros(const real& v, int32 numPrecision = 6);
/// Output <w1,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 = '.');
/// Find the base in a group separated by "." and return it.
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 = '.');
/// Find tail name in a group separated by "." and return it.
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);
/// Convert word to real
bool
readReal(const word& w, real& val);
/// Convert char string to real
bool readReal( const char* buf, real & val );
/// Convert char string to real
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);
/// Convert char string to bool
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)
INLINE_FUNCTION_HD
bool
equal(const real& s1, const real& s2, real tol = smallValue)
{
return abs(s1 - s2) <= tol;
return abs(s1 - s2) <= tol;
}
INLINE_FUNCTION_HD
bool equal(const int64& s1, const int64& s2)
{
return s1 == s2;
}
INLINE_FUNCTION_HD
bool equal(const int32& s1, const int32& s2)
INLINE_FUNCTION_HD
bool
equal(const int64& s1, const int64& s2)
{
return s1 == s2;
}
INLINE_FUNCTION_HD
bool equal(const int8& s1, const int8& s2)
INLINE_FUNCTION_HD
bool
equal(const int32& s1, const int32& s2)
{
return s1 == s2;
return s1 == s2;
}
INLINE_FUNCTION_HD
bool equal(const uint32& s1, const uint32& s2)
INLINE_FUNCTION_HD
bool
equal(const int8& s1, const int8& s2)
{
return s1 == s2;
return s1 == s2;
}
INLINE_FUNCTION_HD
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)
INLINE_FUNCTION
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)
INLINE_FUNCTION_HD
real
degree2Radian(const real& theta)
{
return theta / 180.0 * Pi;
return theta / 180.0 * Pi;
}
/// Convert radians to degree
INLINE_FUNCTION_HD
real radian2Degree(const real &phi)
INLINE_FUNCTION_HD
real
radian2Degree(const real& phi)
{
return phi / Pi * 180.0;
return phi / Pi * 180.0;
}
} // end of pFlow
#endif //__bTypesFunctions_hpp__

View File

@ -2,17 +2,17 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -28,52 +28,50 @@ Licence:
namespace pFlow
{
#ifdef pFlow_Build_Double
#define useDouble 1
#ifdef pFlow_Build_Double
#define useDouble 1
inline const char* floatingPointType__ = "double";
inline const bool usingDouble__ = true;
inline const bool usingDouble__ = true;
#else
#define useDouble 0
#define useDouble 0
inline const char* floatingPointType__ = "float";
inline const bool usingDouble__ = false;
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;
using int8 = signed char;
using int32 = int;
using int32 = int;
using int64 = long long int;
using int64 = long long int;
using uint8 = unsigned char ;
using uint8 = unsigned char;
using uint32 = unsigned int;
using uint32 = unsigned int;
using uint64 = unsigned long long int;
using uint64 = unsigned long long int;
using id_t = uint32;
using id_t = uint32;
using size_t = std::size_t;
using size_t = std::size_t;
using word = std::string;
using word = std::string;
inline const int numBytesForReal__ = sizeof(real);
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.");
return word("In this build, ") + word(floatingPointType__) +
word(" is used for floating point operations.");
}
} // end of pFlow
#endif

View File

@ -2,17 +2,17 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -21,31 +21,28 @@ 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
// sin, cos, tan, asin, acos, atan, atan2
// sinh, cosh, tanh, asinh, acosh, atanh
// sinh, cosh, tanh, asinh, acosh, atanh
// min, max
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * //
namespace pFlow
{
INLINE_FUNCTION_HD
real abs(real x)
INLINE_FUNCTION_HD
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,131 +78,148 @@ 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)
INLINE_FUNCTION_H
real
exp(real x)
{
return std::exp(x);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real log(real x)
INLINE_FUNCTION_HD
real
log(real x)
{
return std::log(x);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real log10(real x)
INLINE_FUNCTION_HD
real
log10(real x)
{
return std::log10(x);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real pow(real x, real y)
INLINE_FUNCTION_HD
real
pow(real x, real y)
{
return std::pow(x, y);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real sqrt(real x)
INLINE_FUNCTION_HD
real
sqrt(real x)
{
return std::sqrt(x);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real cbrt (real x)
INLINE_FUNCTION_HD
real
cbrt(real x)
{
return std::cbrt (x);
return std::cbrt(x);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real sin(real x)
INLINE_FUNCTION_HD
real
sin(real x)
{
return std::sin(x);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real cos(real x)
INLINE_FUNCTION_HD
real
cos(real x)
{
return std::cos(x);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real tan(real x)
INLINE_FUNCTION_HD
real
tan(real x)
{
return std::tan(x);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real asin(real x)
INLINE_FUNCTION_HD
real
asin(real x)
{
return std::asin(x);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real acos(real x)
INLINE_FUNCTION_HD
real
acos(real x)
{
return std::acos(x);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real atan(real x)
INLINE_FUNCTION_HD
real
atan(real x)
{
return std::atan(x);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD real
INLINE_FUNCTION_HD real
atan2(real y, real x)
{
return std::atan2(y, x);
@ -211,22 +227,25 @@ atan2(real y, real x)
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real sinh(real x)
INLINE_FUNCTION_HD
real
sinh(real x)
{
return std::sinh(x);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real cosh(real x)
INLINE_FUNCTION_HD
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);
@ -254,96 +275,101 @@ INLINE_FUNCTION_HD real acosh(real x)
}
#ifndef __CUDACC__
INLINE_FUNCTION_HD
real atanh(real x)
INLINE_FUNCTION_HD
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)
INLINE_FUNCTION_HD
int64
min(int32 x, int32 y)
{
return std::min(x, y);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD
int64 min(int64 x, int64 y)
INLINE_FUNCTION_HD
int64
min(int64 x, int64 y)
{
return std::min(x, y);
}
#endif
#ifndef __CUDACC__
INLINE_FUNCTION_HD
uint64 min(uint64 x, uint64 y)
INLINE_FUNCTION_HD
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

@ -2,17 +2,17 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -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()
{
return std::numeric_limits<T>::lowest();
}
// - largest negative value
template<typename T>
constexpr T
largestNegative()
{
return std::numeric_limits<T>::lowest();
}
template<typename T>
constexpr inline T epsilonValue()
{
return std::numeric_limits<T>::min();
}
template<typename T>
constexpr T
epsilonValue()
{
return std::numeric_limits<T>::min();
}
// largest positive value
template<typename T>
constexpr inline T largestPositive()
{
return std::numeric_limits<T>::max();
}
// 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 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 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

@ -2,17 +2,17 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -21,79 +21,79 @@ 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
{
public:
T s_;
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),
v_(x, y, z)
{}
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),
v_(v)
{}
: s_(s),
v_(v)
{
}
INLINE_FUNCTION_HD
quadruple(const T &val)
:
s_(val),
v_(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)
// type conversion trough assignment
template<typename T2>
INLINE_FUNCTION_HD quadruple<T>& operator=(const quadruple<T2>& rhs)
{
this->v_ = rhs.v_;
this->s_ = static_cast<T>(rhs.s_);
return *this;
}
// type casting through copy constructor
// type casting through copy constructor
template<typename T2>
INLINE_FUNCTION_HD
quadruple(const quadruple<T2> &src):
s_(static_cast<T>(src.s_)),
v_(src.v_)
{}
INLINE_FUNCTION_HD quadruple(const quadruple<T2>& src)
: s_(static_cast<T>(src.s_)),
v_(src.v_)
{
}
// copy construct
INLINE_FUNCTION_HD
@ -111,130 +111,173 @@ public:
INLINE_FUNCTION_HD
quadruple<T>& operator=(quadruple<T>&& src) = default;
// clone
// 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(); }
INLINE_FUNCTION_HD
T & y(){ return v_.y(); }
INLINE_FUNCTION_HD
const T & y()const { return v_.y(); }
const T& x() const
{
return v_.x();
}
INLINE_FUNCTION_HD
T & z(){ return v_.z(); }
T& y()
{
return v_.y();
}
INLINE_FUNCTION_HD
const T & z()const { return v_.z(); }
INLINE_FUNCTION_HD
T & s(){ return s_; }
INLINE_FUNCTION_HD
const T & s()const { return s_; }
INLINE_FUNCTION_HD
triple<T> v() {return v_;}
INLINE_FUNCTION_HD
const triple<T> v() const {return v_;}
const T& y() const
{
return v_.y();
}
INLINE_FUNCTION_HD
T& z()
{
return v_.z();
}
INLINE_FUNCTION_HD
const T& z() const
{
return v_.z();
}
INLINE_FUNCTION_HD
T& s()
{
return s_;
}
INLINE_FUNCTION_HD
const T& s() const
{
return s_;
}
INLINE_FUNCTION_HD
triple<T> v()
{
return v_;
}
INLINE_FUNCTION_HD
const triple<T> v() const
{
return v_;
}
// methods
friend FUNCTION_HD T dot <T> (const quadruple<T> & oprnd1, const quadruple<T> & oprnd2);
INLINE_FUNCTION_HD T length() const;
friend FUNCTION_HD T
dot<T>(const quadruple<T>& oprnd1, const quadruple<T>& oprnd2);
INLINE_FUNCTION_HD void normalize();
INLINE_FUNCTION_HD T length() const;
INLINE_FUNCTION_HD void normalize();
//// operators
//// 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 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 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);
// - 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 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 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 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);
// / 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 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 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);
// unary negate operator
INLINE_FUNCTION_HD
quadruple operator- ()const;
// unary plus operator
INLINE_FUNCTION_HD
quadruple operator+ ()const;
void operator/=(const quadruple& oprnd2);
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);
// >> operator
friend FUNCTION_H iIstream& operator >> <T> (iIstream & str, quadruple<T> & iv);
// unary negate operator
INLINE_FUNCTION_HD
quadruple operator-() const;
// unary plus operator
INLINE_FUNCTION_HD
quadruple operator+() const;
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);
// >> operator
friend FUNCTION_H iIstream& operator>> <T>(iIstream& str, quadruple<T>& iv);
// same as >> operator, but faster, good for mass read
friend FUNCTION_H void readIstream <T>( iIstream& str, quadruple<T> &iv);
friend FUNCTION_H void readIstream<T>(iIstream& str, quadruple<T>& iv);
};
} // pFlow
#include "quadrupleI.hpp"
//#include "quadrupleMath.hpp"
// #include "quadrupleMath.hpp"
#endif

View File

@ -2,140 +2,86 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
template<typename T>
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 T
dot(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 quadruple<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 quadruple<T>& oprnd1, const T& oprnd2);
template<typename T>
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
);
template<typename T>
INLINE_FUNCTION_HD quadruple<T> operator-
(
const T & oprnd1,
const quadruple<T> & oprnd2
);
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
);
template<typename T>
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 quadruple<T>& oprnd1, const quadruple<T>& oprnd2);
template<typename T>
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
);
template<typename T>
INLINE_FUNCTION_HD quadruple<T> operator/
(
const T & oprnd1,
const quadruple<T> & oprnd2
);
INLINE_FUNCTION_HD quadruple<T>
operator-(const quadruple<T>& oprnd1, const T& oprnd2);
template<typename T>
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
);
template<typename T>
INLINE_FUNCTION_H iIstream& operator>>
(
iIstream& str,
quadruple<T> & iv
);
INLINE_FUNCTION_HD quadruple<T>
operator-(const T& oprnd1, const quadruple<T>& oprnd2);
template<typename T>
INLINE_FUNCTION_H void readIstream
(
iIstream& str,
quadruple<T> & iv
);
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);
template<typename T>
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);
template<typename T>
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);
template<typename T>
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);
template<typename T>
INLINE_FUNCTION_H iIstream&
operator>>(iIstream& str, quadruple<T>& iv);
template<typename T>
INLINE_FUNCTION_H void
readIstream(iIstream& str, quadruple<T>& iv);

View File

@ -2,297 +2,190 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
template<typename T>
INLINE_FUNCTION_HD T pFlow::dot
(
const quadruple<T> & oprnd1,
const quadruple<T> & oprnd2
)
template<typename T>
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
)
{
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 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
)
{
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 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,52 +193,43 @@ 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();
str >> iv.x();
str >> iv.y();
str >> iv.z();
str >> iv.x();
str >> iv.y();
str >> iv.z();
str.readEnd("quadruple<T>");
str.readEnd("quadruple<T>");
str.check(FUNCTION_NAME);
str.check(FUNCTION_NAME);
return str;
}
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;
readIstream(str, val);
iv.w() = val;
readIstream(str, val);
iv.w() = val;
readIstream(str, val);
iv.x() = val;
readIstream(str, val);
iv.y() = val;
readIstream(str, val);
iv.x() = val;
readIstream(str, val);
iv.z() = val;
str.readEnd("quadruple<T>");
readIstream(str, val);
iv.y() = val;
str.check(FUNCTION_NAME);
readIstream(str, val);
iv.z() = val;
str.readEnd("quadruple<T>");
str.check(FUNCTION_NAME);
}

View File

@ -2,44 +2,47 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
#define Q4Func(fnName) \
template<typename T> \
inline pFlow::quadruple<T> pFlow::fnName(const quadruple<T>& q) \
{ \
return quadruple<T>(fnName(q.s_), fnName(q.v_)); \
}
#define Q4Func(fnName) \
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_)); \
}
#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_) \
); \
}
//* * * * * * * * * * * List of functinos * * * * * * * * //
// abs, mod, exp, log, log10, pow, sqrt, cbrt
// sin, cos, tan, asin, acos, atan, atan2
// sinh, cosh, tanh, asinh, acosh, atanh
// sinh, cosh, tanh, asinh, acosh, atanh
// 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

@ -2,17 +2,17 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -27,23 +27,21 @@ Licence:
#include "iIstream.hpp"
#include "error.hpp"
namespace pFlow
{
/// - Forward
template<typename T> class triple;
template<typename T>
class triple;
#include "tripleFwd.hpp"
/**
* A set of 3 variables that can be used for vector variables.
* The template parameter should be numeric type only.
*
*
*/
template <typename T>
template<typename T>
struct triple
{
/// data members
@ -53,219 +51,266 @@ struct triple
//// Constructors
/// Initilize to zero
INLINE_FUNCTION_HD
triple():
x_(0),
y_(0),
z_(0)
{}
/// Initilize to zero
INLINE_FUNCTION_HD
triple()
: x_(),
y_(),
z_()
{
}
/// Construct from x, y, z
INLINE_FUNCTION_HD
triple(const T &x, const T &y, const T &z):
x_(x),
y_(y),
z_(z)
{}
/// Construct from x, y, z
INLINE_FUNCTION_HD
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)
{}
/// Construct from v
INLINE_FUNCTION_HD
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)
{
this->x_ = static_cast<T>(rhs.x_);
this->y_ = static_cast<T>(rhs.y_);
this->z_ = static_cast<T>(rhs.z_);
return *this;
}
/// Type conversion trough assignment
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_);
this->z_ = static_cast<T>(rhs.z_);
return *this;
}
/// Type casting through copy constructor
template<typename T2>
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;
/// Type casting through copy constructor
template<typename T2>
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;
/// Move construct
INLINE_FUNCTION_HD
triple(triple<T>&& src) = default;
/// copy assignment
INLINE_FUNCTION_HD
triple<T>& operator=(const triple<T>& src) = default;
/// copy assignment
INLINE_FUNCTION_HD
triple<T>& operator=(const triple<T>& src) = default;
/// move assignment
INLINE_FUNCTION_HD
triple<T>& operator=(triple<T>&& src) = default;
/// move assignment
INLINE_FUNCTION_HD
triple<T>& operator=(triple<T>&& src) = default;
/// clone
INLINE_FUNCTION
uniquePtr<triple<T>> clone() const
{
return makeUnique<triple<T>>(*this);
}
/// clone
INLINE_FUNCTION
uniquePtr<triple<T>> clone() const
{
return makeUnique<triple<T>>(*this);
}
INLINE_FUNCTION
triple<T>* clonePtr()const
{
return new triple<T>(*this);
}
INLINE_FUNCTION
triple<T>* clonePtr() const
{
return new triple<T>(*this);
}
////// member methods
/// access component
INLINE_FUNCTION_HD T & x(){ return x_; }
/// access component
INLINE_FUNCTION_HD T& x()
{
return x_;
}
/// access component
INLINE_FUNCTION_HD const T & x()const { return x_; }
/// access component
INLINE_FUNCTION_HD T & y(){ return y_; }
/// access component
INLINE_FUNCTION_HD const T & y()const { return y_; }
/// access component
INLINE_FUNCTION_HD const T& x() const
{
return x_;
}
/// access component
INLINE_FUNCTION_HD T & z(){ return z_; }
/// access component
INLINE_FUNCTION_HD const T & z()const { return z_; }
/// access component
INLINE_FUNCTION_HD T& y()
{
return y_;
}
/// access component
INLINE_FUNCTION_HD T & comp1(){ return x_; }
/// access component
INLINE_FUNCTION_HD const T& y() const
{
return y_;
}
/// access component
INLINE_FUNCTION_HD const T & comp1()const { return x_; }
/// access component
INLINE_FUNCTION_HD T & comp2(){ return y_; }
/// access component
INLINE_FUNCTION_HD const T & comp2()const { return y_; }
/// access component
INLINE_FUNCTION_HD T& z()
{
return z_;
}
/// access component
INLINE_FUNCTION_HD T & comp3(){ return z_; }
/// access component
INLINE_FUNCTION_HD const T & comp3()const { return z_; }
/// access component
INLINE_FUNCTION_HD const T& z() const
{
return z_;
}
/// access component
INLINE_FUNCTION_HD T& comp1()
{
return x_;
}
/// access component
INLINE_FUNCTION_HD const T& comp1() const
{
return x_;
}
/// access component
INLINE_FUNCTION_HD T& comp2()
{
return y_;
}
/// access component
INLINE_FUNCTION_HD const T& comp2() const
{
return y_;
}
/// access component
INLINE_FUNCTION_HD T& comp3()
{
return z_;
}
/// access component
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);
/// Cross product of two vectors
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;
/// Dot product of two vectors
friend FUNCTION_HD T
dot<T>(const triple<T>& oprnd1, const triple<T>& oprnd2);
/// Normalize the vector
INLINE_FUNCTION_HD void normalize();
/// Cross product of two vectors
friend FUNCTION_HD triple<T>
cross<T>(const triple<T>& v1, const triple<T>& v2);
//// operators
/// + operator
friend FUNCTION_HD triple<T> operator+ <T> (const triple<T> & oprnd1, const triple<T> & oprnd2);
/// Length of the vector
INLINE_FUNCTION_HD T length() const;
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);
/// - 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 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 T & oprnd2);
friend FUNCTION_HD triple<T> operator * <T> (const T & oprnd1, const triple<T> & oprnd2);
/// Normalize the vector
INLINE_FUNCTION_HD void normalize();
/// / 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 T & oprnd2);
friend FUNCTION_HD triple<T> operator / <T> (const T & oprnd1, const triple<T> & oprnd2);
//// operators
/// + operator
friend FUNCTION_HD triple<T> operator+
<T>(const triple<T>& oprnd1, const triple<T>& oprnd2);
INLINE_FUNCTION_HD void operator+= (const triple & oprnd2);
friend FUNCTION_HD triple<T> operator+
<T>(const triple<T>& oprnd1, const T& oprnd2);
INLINE_FUNCTION_HD void operator-= (const triple & oprnd2);
friend FUNCTION_HD triple<T> operator+
<T>(const T& oprnd1, const triple<T>& oprnd2);
INLINE_FUNCTION_HD void operator*= (const triple & oprnd2);
/// - operator
friend FUNCTION_HD triple<T> operator-
<T>(const triple<T>& oprnd1, const triple<T>& oprnd2);
INLINE_FUNCTION_HD void operator/= (const triple & oprnd2);
/// unary negate operator
INLINE_FUNCTION_HD triple operator- ()const;
/// unary plus operator
INLINE_FUNCTION_HD triple operator+ ()const;
friend FUNCTION_HD triple<T> operator-
<T>(const triple<T>& oprnd1, const T& oprnd2);
friend FUNCTION_HD bool operator == <T> (const triple<T> &opr1, const triple<T> &opr2);
friend FUNCTION_HD triple<T> operator-
<T>(const T& oprnd1, const triple<T>& oprnd2);
friend FUNCTION_HD bool operator < <T> (const triple<T> &opr1, const triple<T> &opr2);
/// * operators
friend FUNCTION_HD triple<T> operator*
<T>(const triple<T>& oprnd1, const triple<T>& oprnd2);
friend FUNCTION_HD bool operator > <T> (const triple<T> &opr1, const triple<T> &opr2);
friend FUNCTION_HD triple<T> operator*
<T>(const triple<T>& oprnd1, const T& oprnd2);
friend FUNCTION_HD bool operator >= <T> (const triple<T> &opr1, const triple<T> &opr2);
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 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);
/// unary negate operator
INLINE_FUNCTION_HD triple operator-() const;
/// unary plus operator
INLINE_FUNCTION_HD triple operator+() const;
friend FUNCTION_HD bool operator==
<T>(const triple<T>& opr1, const triple<T>& opr2);
friend FUNCTION_HD bool
operator< <T>(const triple<T>& opr1, const triple<T>& opr2);
friend FUNCTION_HD bool operator>
<T>(const triple<T>& opr1, const triple<T>& opr2);
friend FUNCTION_HD bool operator>=
<T>(const triple<T>& opr1, const triple<T>& opr2);
friend FUNCTION_HD bool operator<=
<T>(const triple<T>& opr1, const triple<T>& opr2);
friend FUNCTION_HD bool operator <= <T> (const triple<T> &opr1, const triple<T> &opr2);
//// IO operators
/// << operator
friend iOstream& operator<< <T> (iOstream& str, const triple<T> & ov);
/// >> operator
friend iIstream& operator >> <T> (iIstream & str, triple<T> & iv);
/// << operator
friend iOstream& operator<< <T>(iOstream& str, const triple<T>& ov);
/// same as >> operator, but faster, good for mass read
friend void readIstream <T>( iIstream& str, triple<T> &iv);
/// >> operator
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);
};
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

@ -2,188 +2,114 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
template<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
);
template<typename T>
INLINE_FUNCTION_HD triple<T> operator +
(
const triple<T> & oprnd1,
const triple<T> & oprnd2
);
INLINE_FUNCTION_HD triple<T>
normalize(const triple<T>& v1);
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 triple<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 triple<T>& oprnd1, const T& oprnd2);
template<typename T>
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
);
template<typename T>
INLINE_FUNCTION_HD triple<T> operator-
(
const T & oprnd1,
const triple<T> & oprnd2
);
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
);
template<typename T>
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 triple<T>& oprnd1, const triple<T>& oprnd2);
template<typename T>
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
);
template<typename T>
INLINE_FUNCTION_HD triple<T> operator/
(
const T & oprnd1,
const triple<T> & oprnd2
);
INLINE_FUNCTION_HD triple<T>
operator-(const triple<T>& oprnd1, const T& oprnd2);
template<typename T>
INLINE_FUNCTION_HD bool operator ==
(
const triple<T> &opr1,
const triple<T> &opr2
);
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 triple<T>
operator*(const triple<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 triple<T>
operator*(const triple<T>& oprnd1, const T& oprnd2);
template<typename T>
INLINE_FUNCTION_HD bool operator <=
(
const triple<T> &opr1,
const triple<T> &opr2
);
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
);
template<typename T>
INLINE_FUNCTION iOstream& operator<<
(
iOstream& str,
const triple<T> & ov
);
template<typename T>
INLINE_FUNCTION iIstream& operator>>
(
iIstream& str,
triple<T> & iv
);
INLINE_FUNCTION_HD triple<T>
operator/(const triple<T>& oprnd1, const triple<T>& oprnd2);
template<typename T>
INLINE_FUNCTION void readIstream
(
iIstream& str,
triple<T> & iv
);
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);
template<typename T>
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);
template<typename T>
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);
template<typename T>
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);
template<typename T>
INLINE_FUNCTION iIstream&
operator>>(iIstream& str, triple<T>& iv);
template<typename T>
INLINE_FUNCTION void
readIstream(iIstream& str, triple<T>& iv);

View File

@ -2,332 +2,239 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
template<typename T>
INLINE_FUNCTION_HD T pFlow::dot
(
const triple<T> & oprnd1,
const triple<T> & oprnd2
)
template<typename T>
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
)
{
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 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
)
{
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 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_;
this->z_ = this->z_ + oprnd2.z_;
}
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_;
this->z_ = this->z_ - oprnd2.z_;
}
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_;
this->z_ = this->z_ * oprnd2.z_;
}
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_;
this->z_ = this->z_ / oprnd2.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 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,59 +299,47 @@ 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 >> iv.x_;
str >> iv.y_;
str >> iv.z_;
str.readEnd("triple<T>");
str.readEnd("triple<T>");
str.check(FUNCTION_NAME);
str.check(FUNCTION_NAME);
return str;
}
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;
readIstream(str, val);
iv.x_ = val;
readIstream(str, val);
iv.y_ = val;
readIstream(str, val);
iv.x_ = val;
readIstream(str, val);
iv.z_ = val;
str.readEnd("triple<T>");
readIstream(str, val);
iv.y_ = val;
str.check(FUNCTION_NAME);
readIstream(str, val);
iv.z_ = val;
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

@ -2,17 +2,17 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -22,28 +22,33 @@ namespace pFlow
{
#define T3Func(fnName) \
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 T3Func(fnName) \
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_)); \
}
#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_) \
); \
}
//* * * * * * * * * * * List of functinos * * * * * * * * //
// abs, mod, exp, log, log10, pow, sqrt, cbrt
// sin, cos, tan, asin, acos, atan, atan2
// sinh, cosh, tanh, asinh, acosh, atanh
// sinh, cosh, tanh, asinh, acosh, atanh
// min, max
//* * * * * * * * * * * * * * * * * * * * * * * * * * * * //
T3Func(abs);
T3Func2(mod);
T3Func(exp);
@ -68,31 +73,32 @@ T3Func(atanh);
T3Func2(min);
T3Func2(max);
//// special forms of functions
//// special forms of functions
// 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

@ -2,17 +2,17 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -22,14 +22,13 @@ Licence:
namespace pFlow
{
const realx3 zero3(0.0);
const realx3 one3(1.0);
const realx3x3 zero33(zero3);
const realx3x3 one33(one3);
const realx4 zero4(zero);
const realx3 zero3(0.0);
const realx3 one3(1.0);
const realx3x3 zero33(zero3);
const realx3x3 one33(one3);
const realx4 zero4(zero);
} // pFlow

View File

@ -2,17 +2,17 @@
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
OOOOOOO F luid flow
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
------------------------------------------------------------------------------
Licence:
This file is part of phasicFlow code. It is a free software for simulating
This file is part of phasicFlow code. It is a free software for simulating
granular and multiphase flows. You can redistribute it and/or modify it under
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
the terms of GNU General Public License v3 or any other later versions.
phasicFlow is distributed to help others in their research in the field of
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
@ -21,7 +21,6 @@ Licence:
#ifndef __types_hpp__
#define __types_hpp__
#include "bTypes.hpp"
#include "bTypesFunctions.hpp"
@ -32,74 +31,117 @@ Licence:
#include "typeInfo.hpp"
namespace pFlow
{
using int8x3 = triple<int8>;
using int32x3 = triple<int32>;
using int64x3 = triple<int64>;
using uint8x3 = triple<uint8>;
using uint32x3 = triple<uint32>;
using uint64x3 = triple<uint64>;
using realx3 = triple<real>;
using int8x3 = triple<int8>;
using int32x3 = triple<int32>;
using int64x3 = triple<int64>;
using uint8x3 = triple<uint8>;
using uint32x3 = triple<uint32>;
using uint64x3 = triple<uint64>;
using realx3 = triple<real>;
using int32x3x3 = triple<int32x3>;
using uint32x3x3= triple<uint32x3>;
using realx3x3 = triple<realx3>;
using int32x3x3 = triple<int32x3>;
using uint32x3x3 = triple<uint32x3>;
using realx3x3 = triple<realx3>;
using realx4 = quadruple<real>;
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"; }
extern const realx3 zero3;
extern const realx3 one3;
inline word
basicTypeName<realx4x3>()
{
return "realx4x3";
}
extern const realx3 zero3;
extern const realx3 one3;
extern const realx3x3 zero33;
extern const realx3x3 one33;
extern const realx4 zero4;
extern const realx4 zero4;
} // pFlow
#endif //__types_hpp__