containers are modified for errors

This commit is before the first release of phasicFlow from develop to main (version 1.0)
This commit is contained in:
Hamidreza Norouzi 2024-03-24 01:56:49 -07:00
parent 0aa7f2dba9
commit 57850119ba
19 changed files with 291 additions and 74 deletions

View File

@ -188,6 +188,11 @@ public:
{ {
this->fill(span, val); this->fill(span, val);
} }
void fillField(const T& val)
{
this->fill(val);
}
//// - IO operations //// - IO operations

View File

@ -51,7 +51,9 @@ protected:
anyListType anyList_; anyListType anyList_;
/// List of variable names in anyList_ /// List of variable names in anyList_
wordList names_; wordList names_;
wordList types_;
public: public:
@ -89,6 +91,7 @@ public:
fatalExit; fatalExit;
} }
names_.push_back(name); names_.push_back(name);
types_.push_back(getTypeName<T>());
return anyList_.emplace_back( return anyList_.emplace_back(
std::in_place_type<T>, std::in_place_type<T>,
std::forward<Args>(args)...); std::forward<Args>(args)...);
@ -106,6 +109,7 @@ public:
fatalExit; fatalExit;
} }
names_.push_back(name); names_.push_back(name);
types_.push_back(getTypeName<T>());
return anyList_.emplace_back(std::in_place_type<T>, other); return anyList_.emplace_back(std::in_place_type<T>, other);
} }
@ -121,6 +125,7 @@ public:
fatalExit; fatalExit;
} }
names_.push_back(name); names_.push_back(name);
types_.push_back(getTypeName<T>());
return anyList_.emplace_back(std::in_place_type<T>, std::move(other)); return anyList_.emplace_back(std::in_place_type<T>, std::move(other));
} }

View File

@ -43,6 +43,8 @@ public:
using hashmapType = std::unordered_map<Key, T, Hash>; using hashmapType = std::unordered_map<Key, T, Hash>;
using hasher = typename hashmapType::hasher;
using iterator = typename hashmapType::iterator; using iterator = typename hashmapType::iterator;
using constIterator = typename hashmapType::const_iterator; using constIterator = typename hashmapType::const_iterator;
@ -75,46 +77,24 @@ public:
{} {}
// - Copy construct // - Copy construct
hashMap(const hashMapType & src) hashMap(const hashMapType & src) = default;
:
hashmapType(src)
{}
// - Move construct // - Move construct
hashMap( hashMapType&& src) hashMap( hashMapType&& src) = default;
:
hashmapType(std::move(src))
{}
// - Copy assignment // - Copy assignment
hashMapType& operator=(const hashMapType& rhs) hashMapType& operator=(const hashMapType& rhs) = default;
{
hashmapType::operator=(rhs);
return *this;
}
// - Move assignment // - Move assignment
hashMapType& operator=(hashMapType&& rhs) hashMapType& operator=(hashMapType&& rhs) = default;
{
hashmapType::operator=( std::move(rhs));
return *this;
}
uniquePtr<hashMapType> clone()const uniquePtr<hashMapType> clone()const
{ {
return makeUnique<hashMapType>(*this); return makeUnique<hashMapType>(*this);
} }
hashMapType* clonePtr()const ~hashMap() = default;
{
return new hashMapType(*this);
}
~hashMap()
{
this->clear();
}
//// - Methods //// - Methods

View File

@ -509,7 +509,7 @@ void pFlow::VectorSingle<T,MemorySpace>::assign
template<typename T, typename MemorySpace> template<typename T, typename MemorySpace>
INLINE_FUNCTION_H INLINE_FUNCTION_H
void pFlow::VectorSingle<T,MemorySpace>::assign(const VectorTypeHost& src) void pFlow::VectorSingle<T,MemorySpace>::assignFromHost(const VectorTypeHost& src)
{ {
uint32 srcSize = src.size(); uint32 srcSize = src.size();
uint32 srcCap = src.capacity(); uint32 srcCap = src.capacity();
@ -540,7 +540,45 @@ void pFlow::VectorSingle<T,MemorySpace>::assign(const VectorTypeHost& src)
} }
} }
template<typename T, typename MemorySpace>
INLINE_FUNCTION_H
void pFlow::VectorSingle<T,MemorySpace>::assign
(
const VectorType& src,
bool srcCapacity
)
{
uint32 srcSize = src.size();
uint32 srcCap = src.capacity();
if(srcCapacity && srcCap != capacity())
{
reallocateCapacitySize(srcCap, srcSize);
}
else
{
setSize(srcSize);
}
if constexpr(isTriviallyCopyable_)
{
copy(deviceView(), src.deviceView());
}
else if constexpr( isHostAccessible_)
{
for(auto i=0u; i<src.size(); i++)
{
view_[i] = src.view_[i];
}
}
else
{
static_assert("Not a valid operation for this data type on device memory");
}
}
template <typename T, typename MemorySpace> template <typename T, typename MemorySpace>
INLINE_FUNCTION_H
void pFlow::VectorSingle<T, MemorySpace>::append void pFlow::VectorSingle<T, MemorySpace>::append
( (
const std::vector<T> &appVec const std::vector<T> &appVec
@ -575,6 +613,41 @@ void pFlow::VectorSingle<T, MemorySpace>::append
} }
template <typename T, typename MemorySpace>
INLINE_FUNCTION_H
void pFlow::VectorSingle<T, MemorySpace>::append
(
const VectorType& appVec
)
{
uint32 appSize = appVec.size();
if(appSize == 0) return;
uint32 oldS = size();
uint32 newSize = oldS + appSize;
setSize(newSize);
auto appendView = Kokkos::subview(
view_,
Kokkos::make_pair<uint32>(oldS, newSize));
if constexpr( isTriviallyCopyable_)
{
copy(appendView, appVec.deviceView());
}
else if constexpr( isHostAccessible_)
{
for(auto i=0u; i<appVec.size(); i++)
{
appendView[i] = appVec.view_[i];
}
}
else
{
static_assert("not a valid operation for this data type on device memory");
}
}
template <typename T, typename MemorySpace> template <typename T, typename MemorySpace>
INLINE_FUNCTION_H auto pFlow::VectorSingle<T, MemorySpace>::getSpan() INLINE_FUNCTION_H auto pFlow::VectorSingle<T, MemorySpace>::getSpan()
{ {

View File

@ -284,10 +284,16 @@ public:
/// The size of *this becomes the size of src. /// The size of *this becomes the size of src.
/// The capacity of *this becomes the capacity of src. /// The capacity of *this becomes the capacity of src.
INLINE_FUNCTION_H INLINE_FUNCTION_H
void assign(const VectorTypeHost& src); void assignFromHost(const VectorTypeHost& src);
INLINE_FUNCTION_H
void assign(const VectorType& src, bool srcCapacity = true);
INLINE_FUNCTION_H INLINE_FUNCTION_H
void append(const std::vector<T>& appVec); void append(const std::vector<T>& appVec);
INLINE_FUNCTION_H
void append(const VectorType& appVec);
INLINE_FUNCTION_H INLINE_FUNCTION_H
auto getSpan(); auto getSpan();

View File

@ -52,10 +52,8 @@ protected:
static inline static inline
const message defaultMessage_ = const message defaultMessage_ =
( (
message::CAP_CHANGED+ message::BNDR_RESET+
message::SIZE_CHANGED+ message::BNDR_REARRANGE
message::ITEM_INSERT+
message::ITEM_DELETE
); );
public: public:
@ -95,8 +93,16 @@ public:
const anyList& varList const anyList& varList
) override ) override
{ {
notImplementedFunction;
return false; if(msg.equivalentTo(message::BNDR_REARRANGE))
{
// do nothing
}
if(msg.equivalentTo(message::BNDR_RESET))
{
//do nothing
}
return true;
} }
auto size()const auto size()const

View File

@ -70,8 +70,14 @@ public:
const anyList& varList const anyList& varList
) override ) override
{ {
notImplementedFunction; BoundaryFieldType::hearChanges(t,dt,iter, msg,varList);
return false;
if(msg.equivalentTo(message::BNDR_DELETE))
{
// do nothing;
}
return true;
} }
}; };

View File

@ -98,6 +98,46 @@ typename pFlow::internalField<T, MemorySpace>::FieldTypeHost
return aField; return aField;
} }
template <class T, class MemorySpace>
bool pFlow::internalField<T, MemorySpace>:: hearChanges
(
real t,
real dt,
uint32 iter,
const message& msg,
const anyList& varList
)
{
if(msg.equivalentTo(message::CAP_CHANGED))
{
auto newCap = varList.getObject<uint32>(
message::eventName(message::CAP_CHANGED));
field_.reserve(newCap);
}
if(msg.equivalentTo(message::SIZE_CHANGED))
{
auto newSize = varList.getObject<uint32>(
message::eventName(message::SIZE_CHANGED));
field_.resize(newSize);
}
if(msg.equivalentTo(message::ITEM_DELETE))
{
// do nothing
}
if(msg.equivalentTo(message::ITEM_REARRANGE))
{
notImplementedFunction;
return false;
}
if(msg.equivalentTo(message::ITEM_INSERT))
{
notImplementedFunction;
return false;
}
return true;
}
template<class T, class MemorySpace> template<class T, class MemorySpace>
bool pFlow::internalField<T, MemorySpace>::write bool pFlow::internalField<T, MemorySpace>::write
( (

View File

@ -24,6 +24,7 @@ Licence:
#include "Field.hpp" #include "Field.hpp"
#include "observer.hpp" #include "observer.hpp"
#include "dataIO.hpp" #include "dataIO.hpp"
#include "anyList.hpp"
namespace pFlow namespace pFlow
@ -59,6 +60,7 @@ protected:
const message defaultMessage_ = const message defaultMessage_ =
( (
message::CAP_CHANGED+ message::CAP_CHANGED+
message::SIZE_CHANGED+
message::ITEM_INSERT+ message::ITEM_INSERT+
message::ITEM_REARRANGE+ message::ITEM_REARRANGE+
message::ITEM_DELETE message::ITEM_DELETE
@ -75,6 +77,11 @@ public:
const internalPoints& internal, const internalPoints& internal,
const T& val); const T& val);
inline
const auto& deviceViewAll()const
{
return field_.deviceViewAll();
}
inline inline
auto deviceView()const auto deviceView()const
{ {
@ -166,11 +173,8 @@ public:
uint32 iter, uint32 iter,
const message& msg, const message& msg,
const anyList& varList const anyList& varList
) override ) override;
{
notImplementedFunction;
return false;
}
//// - IO //// - IO

View File

@ -194,7 +194,58 @@ Pair<T,T> minMax(const internalField<T,MemorySpace>& iField)
} }
} }
template<class T, class MemorySpace>
inline
void fillSequence(internalField<T,MemorySpace>& iField, const T& startVal)
{
using exeSpace = typename internalField<T,MemorySpace>::execution_space;
using policy = Kokkos::RangePolicy<
exeSpace,
Kokkos::IndexType<uint32> >;
if constexpr(isDeviceAccessible<exeSpace>())
{
auto maskD = iField.activePointsMaskDevice();
auto aRange = maskD.activeRange();
auto field = iField.field().deviceViewAll();
auto aPoints = maskD.getActivePoints();
exclusiveScan(aPoints,0, aRange.end(), aPoints,0);
Kokkos::parallel_for(
"internalField::fillSequence",
policy(aRange.start(), aRange.end() ),
LAMBDA_HD(uint32 i)
{
if(maskD(i))
{
field[i] = aPoints[i]+startVal;
}
});
Kokkos::fence();
}
else
{
// this is a host view
auto maskH = iField.activePointsMaskHost();
auto aRange = maskH.activeRange();
auto field = iField.field().deviceViewAll();
auto aPoints = maskH.getActivePoints();
exclusiveScan(aPoints,0, aRange.end(), aPoints,0);
Kokkos::parallel_for(
"internalField::fillSequence",
policy(aRange.start(), aRange.end() ),
LAMBDA_HD(uint32 i)
{
if(maskH(i))
{
field[i] = aPoints[i]+startVal;
}
});
Kokkos::fence();
}
}
} }

View File

@ -274,7 +274,7 @@ bool pFlow::pointField<T, MemorySpace>::readPointField
return false; return false;
} }
this->field_.assign(internal); this->field_.assignFromHost(internal);
return true; return true;
} }

View File

@ -60,6 +60,14 @@ template class pFlow::pointField<pFlow::uint32>;
createBaseBoundary(pFlow::uint32, void); createBaseBoundary(pFlow::uint32, void);
createAllBoundary(pFlow::uint32, void); createAllBoundary(pFlow::uint32, void);
template class pFlow::pointField<pFlow::uint64, pFlow::HostSpace>;
createBaseBoundary(pFlow::uint64, pFlow::HostSpace);
createAllBoundary(pFlow::uint64, pFlow::HostSpace);
template class pFlow::pointField<pFlow::uint64>;
createBaseBoundary(pFlow::uint64, void);
createAllBoundary(pFlow::uint64, void);
template class pFlow::pointField<pFlow::real, pFlow::HostSpace>; template class pFlow::pointField<pFlow::real, pFlow::HostSpace>;
createBaseBoundary(pFlow::real, pFlow::HostSpace); createBaseBoundary(pFlow::real, pFlow::HostSpace);
createAllBoundary(pFlow::real, pFlow::HostSpace); createAllBoundary(pFlow::real, pFlow::HostSpace);

View File

@ -23,22 +23,11 @@ Licence:
#include "KokkosTypes.hpp" #include "KokkosTypes.hpp"
#include "types.hpp" #include "types.hpp"
#include "typeInfo.hpp" #include "typeInfo.hpp"
#include "Vector.hpp" #include "Vector.hpp"
/*
stores the elemnt of a symetric array in the following order in a 1D vector
0 1 2 3
4 5 6
7 8
9
*/
namespace pFlow namespace pFlow
{ {
@ -52,6 +41,15 @@ void SWAP(Type &x, Type& y)
x = temp; x = temp;
} }
/*
stores the elemnt of a symetric array in the following order in a 1D vector
0 1 2 3
4 5 6
7 8
9
*/
template<typename T, typename MemorySpace=void> template<typename T, typename MemorySpace=void>
class symArray class symArray
{ {
@ -82,14 +80,14 @@ class symArray
using execution_space = typename ViewType::execution_space; using execution_space = typename ViewType::execution_space;
protected: private:
uint32 n_=0; uint32 n_= 0;
ViewType view_; ViewType view_;
constexpr static inline const char* memoerySpaceName() constexpr static const char* memoerySpaceName()
{ {
return memory_space::name(); return memory_space::name();
} }
@ -97,14 +95,14 @@ protected:
public: public:
// - type info // - type info
TypeInfoTemplateNV2("symArray", T, memoerySpaceName()); TypeInfoTemplateNV111("symArray", T, memoerySpaceName());
//// constructors //// constructors
INLINE_FUNCTION_H INLINE_FUNCTION_H
symArray(); symArray();
INLINE_FUNCTION_H INLINE_FUNCTION_H
symArray(uint32 n) explicit symArray(uint32 n)
: :
symArray("symArray",n) symArray("symArray",n)
{} {}
@ -125,7 +123,7 @@ public:
} }
INLINE_FUNCTION_H INLINE_FUNCTION_H
symArray(word name, Vector<T> src) symArray(word name, const Vector<T>& src)
: :
view_(name) view_(name)
{ {
@ -137,19 +135,19 @@ public:
} }
} }
INLINE_FUNCTION_H INLINE_FUNCTION_HD
symArray(const symArray&) = default; symArray(const symArray&) = default;
INLINE_FUNCTION_H INLINE_FUNCTION_HD
symArray& operator=(const symArray&) = default; symArray& operator=(const symArray&) = default;
INLINE_FUNCTION_H INLINE_FUNCTION_HD
symArray(symArray&&) = delete; symArray(symArray&&) = default;
INLINE_FUNCTION_H INLINE_FUNCTION_HD
symArray& operator=(symArray&&) = delete; symArray& operator=(symArray&&) = default;
INLINE_FUNCTION_H INLINE_FUNCTION_HD
~symArray()=default; ~symArray()=default;
@ -219,10 +217,10 @@ public:
bool write(iOstream& os)const bool write(iOstream& os)const
{ {
int32 s = numElem(n_); uint32 s = numElem(n_);
Vector<T, noConstructAllocator<T>> vecToFile(s); Vector<T> vecToFile(view_.label(),s);
const auto dVec = Kokkos::subview(view_, kPair<int32,int32>(0, s)); const auto dVec = Kokkos::subview(view_, Pair<uint32,uint32>(0, s));
hostViewType1D<T> mirror(vecToFile.data(), vecToFile.size()); hostViewType1D<T> mirror(vecToFile.data(), vecToFile.size());
Kokkos::deep_copy(mirror,dVec); Kokkos::deep_copy(mirror,dVec);

View File

@ -130,6 +130,41 @@ public:
field_.assign(vals, surface_.capacity()); field_.assign(vals, surface_.capacity());
} }
inline
const auto& deviceViewAll()const
{
return field_.deviceViewAll();
}
inline
auto deviceView()const
{
return field_.deviceView();
}
inline
auto hostView()const
{
return field_.hostView();
}
inline
const FieldType& field()const
{
return field_;
}
inline
FieldType& field()
{
return field_;
}
inline
void fill(const T& val)
{
field_.fillField(val);
}
bool hearChanges( bool hearChanges(
real t, real t,
real dt, real dt,