diff --git a/src/phasicFlow/CMakeLists.txt b/src/phasicFlow/CMakeLists.txt index 23ee3e13..ae7df3ac 100644 --- a/src/phasicFlow/CMakeLists.txt +++ b/src/phasicFlow/CMakeLists.txt @@ -56,18 +56,14 @@ containers/Field/Fields.cpp containers/List/anyList/anyList.cpp containers/pointField/pointFields.cpp -#setFieldList/setFieldList.cpp -#setFieldList/setFieldEntry.cpp +setFieldList/setFieldList.cpp +setFieldList/setFieldEntry.cpp Timer/Timer.cpp Timer/Timers.cpp - - - - structuredData/box/box.cpp structuredData/line/line.cpp structuredData/infinitePlane/infinitePlane.cpp @@ -81,6 +77,10 @@ structuredData/boundaries/boundaryBase/boundaryBase.cpp structuredData/boundaries/boundaryExit/boundaryExit.cpp structuredData/boundaries/boundaryNone/boundaryNone.cpp structuredData/pointStructure/boundaryList.cpp +structuredData/pointStructure/selectors/pStructSelector/pStructSelector.cpp +structuredData/pointStructure/selectors/selectBox/selectBox.cpp +structuredData/pointStructure/selectors/selectRange/selectRange.cpp +structuredData/pointStructure/selectors/selectRandom/selectRandom.cpp commandLine/commandLine.cpp diff --git a/src/phasicFlow/containers/Field/Field.hpp b/src/phasicFlow/containers/Field/Field.hpp index 2312309c..8c1ac98c 100644 --- a/src/phasicFlow/containers/Field/Field.hpp +++ b/src/phasicFlow/containers/Field/Field.hpp @@ -158,20 +158,6 @@ public: /// Move assignment FieldType& operator = (FieldType&&) = default; - /// clone as a uniquePtr - INLINE_FUNCTION_H - uniquePtr clone() const - { - return makeUnique(*this); - } - - /// clone as a raw pointer - INLINE_FUNCTION_H - FieldType* clonePtr()const - { - return new FieldType(*this); - } - //// - Methods /// return field key @@ -184,7 +170,13 @@ public: { return VectorType::name(); } - + + + void fillField(rangeU32 span, const T& val) + { + this->fill(span, val); + } + //// - IO operations bool read(iIstream& is); diff --git a/src/phasicFlow/containers/List/ListPtr/ListPtr.hpp b/src/phasicFlow/containers/List/ListPtr/ListPtr.hpp index 649a77c0..efe0fc50 100644 --- a/src/phasicFlow/containers/List/ListPtr/ListPtr.hpp +++ b/src/phasicFlow/containers/List/ListPtr/ListPtr.hpp @@ -39,8 +39,12 @@ class ListPtr public: using ListPtrType = ListPtr ; + using listType = std::list; + using iterator = typename listType::iterator; + + using const_iterator = typename listType::const_iterator; template inline static uniquePtr makeSafe(Args&&... args) @@ -183,7 +187,25 @@ public: // - clear the ith element void clear(size_t i); - // - clone the object + iterator begin() + { + return list_.begin(); + } + + const_iterator begin()const + { + return list_.begin(); + } + + iterator end() + { + return list_.end(); + } + + const_iterator end()const + { + return list_.end(); + } }; diff --git a/src/phasicFlow/containers/Set/Set.hpp b/src/phasicFlow/containers/Set/Set.hpp index 3b6ea999..3c619f0b 100644 --- a/src/phasicFlow/containers/Set/Set.hpp +++ b/src/phasicFlow/containers/Set/Set.hpp @@ -23,6 +23,8 @@ Licence: #include +#include "types.hpp" + namespace pFlow { @@ -30,6 +32,9 @@ namespace pFlow template using Set = std::set,std::allocator>; +using wordSet = Set; + + } #endif diff --git a/src/phasicFlow/containers/VectorHD/VectorSingle.cpp b/src/phasicFlow/containers/VectorHD/VectorSingle.cpp index 6b0789b1..b469f2b8 100644 --- a/src/phasicFlow/containers/VectorHD/VectorSingle.cpp +++ b/src/phasicFlow/containers/VectorHD/VectorSingle.cpp @@ -351,6 +351,17 @@ void pFlow::VectorSingle::fill(const T& val) pFlow::fill(view_, rangeU32(0 ,size_) ,val); } +template +INLINE_FUNCTION_H +void pFlow::VectorSingle::fill +( + rangeU32 r, + const T& val +) +{ + pFlow::fill(view_, r, val); +} + template INLINE_FUNCTION_H void pFlow::VectorSingle::assign @@ -494,7 +505,7 @@ bool pFlow::VectorSingle::insertSetElement ) { - if(indices.size() == 0)return true; + if(indices.empty())return true; if(indices.size() != vals.size())return false; auto maxInd = indices.max(); @@ -518,9 +529,7 @@ bool pFlow::VectorSingle::insertSetElement Kokkos::parallel_for( "VectorSingle::insertSetElement", policy(0,indices.size()), LAMBDA_HD(int32 i){ - dVec(ind(i))= dVals(i);} - ); - + dVec(ind(i))= dVals(i);}); Kokkos::fence(); } @@ -532,9 +541,7 @@ bool pFlow::VectorSingle::insertSetElement Kokkos::parallel_for( "VectorSingle::insertSetElement", policy(0,indices.size()), LAMBDA_HD(int32 i){ - dVec(ind(i))= hVals(i);} - ); - + dVec(ind(i))= hVals(i);}); Kokkos::fence(); } @@ -542,6 +549,57 @@ bool pFlow::VectorSingle::insertSetElement return true; } +template +INLINE_FUNCTION_H +bool pFlow::VectorSingle::insertSetElement +( + uint32IndexContainer indices, + const ViewType1D vals +) +{ + if(indices.empty())return true; + if(indices.size() != vals.size())return false; + + auto maxInd = indices.max(); + + if(this->empty() || maxInd > size()-1 ) + { + resize(maxInd+1); + } + + using policy = Kokkos::RangePolicy< + execution_space, + Kokkos::IndexType>; + + if constexpr( isDeviceAccessible_ ) + { + auto dVec = view_; + auto dVals = vals; + auto ind = indices.deviceView(); + + Kokkos::parallel_for( + "VectorSingle::insertSetElement", + policy(0,indices.size()), LAMBDA_HD(int32 i){ + dVec(ind(i))= dVals(i);}); + Kokkos::fence(); + + } + else + { + auto dVec = view_; + auto hVals = vals; + auto ind = indices.hostView(); + + Kokkos::parallel_for( + "VectorSingle::insertSetElement", + policy(0,indices.size()), LAMBDA_HD(int32 i){ + dVec(ind(i))= hVals(i);}); + Kokkos::fence(); + + } + + return true; +} template INLINE_FUNCTION_H diff --git a/src/phasicFlow/containers/VectorHD/VectorSingle.hpp b/src/phasicFlow/containers/VectorHD/VectorSingle.hpp index 0876e6e5..64793c5e 100644 --- a/src/phasicFlow/containers/VectorHD/VectorSingle.hpp +++ b/src/phasicFlow/containers/VectorHD/VectorSingle.hpp @@ -256,6 +256,9 @@ public: /// Fill the range [0,size) with val INLINE_FUNCTION_H void fill(const T& val); + + INLINE_FUNCTION_H + void fill(rangeU32 r, const T& val); /// Change size of the vector and assign val to vector and INLINE_FUNCTION_H @@ -291,6 +294,11 @@ public: INLINE_FUNCTION_H bool insertSetElement(uint32IndexContainer indices, const std::vector& vals); + INLINE_FUNCTION_H + bool insertSetElement( + uint32IndexContainer indices, + const ViewType1D vals); + INLINE_FUNCTION_H bool reorderItems(uint32IndexContainer indices); diff --git a/src/phasicFlow/containers/VectorHD/VectorSingleAlgorithms.hpp b/src/phasicFlow/containers/VectorHD/VectorSingleAlgorithms.hpp index 13bce66b..893e6c1e 100644 --- a/src/phasicFlow/containers/VectorHD/VectorSingleAlgorithms.hpp +++ b/src/phasicFlow/containers/VectorHD/VectorSingleAlgorithms.hpp @@ -21,8 +21,6 @@ Licence: #define __VectorSingleMath_hpp__ - - namespace pFlow { @@ -51,8 +49,6 @@ INLINE_FUNCTION_H T max( const VectorSingle& vec) ); } - - } diff --git a/src/phasicFlow/containers/pointField/boundaryField.cpp b/src/phasicFlow/containers/pointField/boundaryField.cpp index 1b6ba9c1..b4a90c13 100644 --- a/src/phasicFlow/containers/pointField/boundaryField.cpp +++ b/src/phasicFlow/containers/pointField/boundaryField.cpp @@ -25,7 +25,7 @@ pFlow::boundaryField::boundaryField InternalFieldType& internal ) : - observer(), + observer(&boundary, defaultMessage_), boundary_(boundary), internal_(internal) {} diff --git a/src/phasicFlow/containers/pointField/boundaryField.hpp b/src/phasicFlow/containers/pointField/boundaryField.hpp index 90786cbc..9836599c 100644 --- a/src/phasicFlow/containers/pointField/boundaryField.hpp +++ b/src/phasicFlow/containers/pointField/boundaryField.hpp @@ -49,6 +49,15 @@ protected: /// @brief a ref to the internal field InternalFieldType& internal_; + static inline + const message defaultMessage_ = + ( + message::CAP_CHANGED+ + message::SIZE_CHANGED+ + message::ITEM_INSERT+ + message::ITEM_DELETE + ); + public: TypeInfo("boundaryField"); @@ -79,6 +88,9 @@ public: bool hearChanges ( + real t, + real dt, + uint32 iter, const message& msg, const anyList& varList ) override @@ -97,6 +109,12 @@ public: return boundary_.capacity(); } + virtual + void fill(const T& val) + { + return ; + } + static uniquePtr create( const boundaryBase& boundary, diff --git a/src/phasicFlow/containers/pointField/boundaryFieldList.hpp b/src/phasicFlow/containers/pointField/boundaryFieldList.hpp index 8bdf9840..4de85bf6 100644 --- a/src/phasicFlow/containers/pointField/boundaryFieldList.hpp +++ b/src/phasicFlow/containers/pointField/boundaryFieldList.hpp @@ -60,6 +60,14 @@ public: } } + void fill(const T& val) + { + for(auto& bf: *this) + { + bf->fill(val); + } + } + }; } diff --git a/src/phasicFlow/containers/pointField/exitBoundaryField.hpp b/src/phasicFlow/containers/pointField/exitBoundaryField.hpp index bcf168d7..dbc942d7 100644 --- a/src/phasicFlow/containers/pointField/exitBoundaryField.hpp +++ b/src/phasicFlow/containers/pointField/exitBoundaryField.hpp @@ -63,6 +63,9 @@ public: bool hearChanges ( + real t, + real dt, + uint32 iter, const message& msg, const anyList& varList ) override diff --git a/src/phasicFlow/containers/pointField/internalField.cpp b/src/phasicFlow/containers/pointField/internalField.cpp index c568589e..3f0ed1cc 100644 --- a/src/phasicFlow/containers/pointField/internalField.cpp +++ b/src/phasicFlow/containers/pointField/internalField.cpp @@ -64,7 +64,7 @@ pFlow::internalField::internalField ), internalPoints_(internal) { - field_.fill(val); + fillInternal(val); } diff --git a/src/phasicFlow/containers/pointField/internalField.hpp b/src/phasicFlow/containers/pointField/internalField.hpp index 30e08bc4..21213743 100644 --- a/src/phasicFlow/containers/pointField/internalField.hpp +++ b/src/phasicFlow/containers/pointField/internalField.hpp @@ -139,7 +139,26 @@ public: return internalPoints_.isAllActive(); } - bool hearChanges(const message& msg, const anyList& varList) override + inline + void fillInternal(const T& val) + { + field_.fillField(activeRange(), val); + } + + inline + bool insertSetElement(uint32IndexContainer indices, const T& val) + { + return field_.insertSetElement(indices, val); + } + + bool hearChanges + ( + real t, + real dt, + uint32 iter, + const message& msg, + const anyList& varList + ) override { notImplementedFunction; return false; @@ -171,5 +190,6 @@ iOstream& operator<< } // pFlow #include "internalField.cpp" +#include "internalFieldAlgorithms.hpp" #endif // __internalField_hpp__ \ No newline at end of file diff --git a/src/phasicFlow/containers/pointField/internalFieldAlgorithms.hpp b/src/phasicFlow/containers/pointField/internalFieldAlgorithms.hpp new file mode 100644 index 00000000..2f1f85df --- /dev/null +++ b/src/phasicFlow/containers/pointField/internalFieldAlgorithms.hpp @@ -0,0 +1,205 @@ +/*------------------------------- phasicFlow --------------------------------- + O C enter of + O O E ngineering and + O O M ultiscale modeling of + OOOOOOO F luid flow +------------------------------------------------------------------------------ + Copyright (C): www.cemf.ir + email: hamid.r.norouzi AT gmail.com +------------------------------------------------------------------------------ +Licence: + This file is part of phasicFlow code. It is a free software for simulating + granular and multiphase flows. You can redistribute it and/or modify it under + the terms of GNU General Public License v3 or any other later versions. + + phasicFlow is distributed to help others in their research in the field of + granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +-----------------------------------------------------------------------------*/ + +#ifndef __internalFieldAlgorithms_hpp__ +#define __internalFieldAlgorithms_hpp__ + +namespace pFlow +{ + +template +inline +T min(const internalField& iField) +{ + using exeSpace = typename internalField::execution_space; + + using policy = Kokkos::RangePolicy< + exeSpace, + Kokkos::IndexType >; + + if constexpr(isDeviceAccessible()) + { + // this is a device view + auto maskD = iField.activePointsMaskDevice(); + auto aRange = maskD.activeRange(); + auto filed = iField.field().deviceVectorAll(); + + T minElement; + + Kokkos::parallel_reduce( + "min(internalField)", + policy(aRange.start(), aRange.end() ), + LAMBDA_HD(uint32 i, T& minUpdate) + { + if( maskD(i) ) + if(filed[i] < minUpdate) minUpdate = filed[i]; + }, + Kokkos::Min(minElement)); + return minElement; + } + else + { + // this is a host view + auto maskH = iField.activePointsMaskHost(); + auto aRange = maskH.activeRange(); + auto filed = iField.field().deviceVectorAll(); + T minElement; + Kokkos::parallel_reduce( + "min(internalField)", + policy(aRange.start(), aRange.end()), + LAMBDA_HD(uint32 i, T& minUpdate) + { + if( maskH(i) ) + if(filed[i] < minUpdate) minUpdate = filed[i]; + }, + Kokkos::Min(minElement)); + + return minElement; + } +} + +template +inline +T max(const internalField& iField) +{ + using exeSpace = typename internalField::execution_space; + + using policy = Kokkos::RangePolicy< + exeSpace, + Kokkos::IndexType >; + + if constexpr(isDeviceAccessible()) + { + // this is a device view + auto maskD = iField.activePointsMaskDevice(); + auto aRange = maskD.activeRange(); + auto filed = iField.field().deviceVectorAll(); + + T maxElement; + + Kokkos::parallel_reduce( + "max(internalField)", + policy(aRange.start(), aRange.end() ), + LAMBDA_HD(uint32 i, T& maxUpdate) + { + if( maskD(i) ) + if( maxUpdate (maxElement)); + return maxElement; + } + else + { + // this is a host view + auto maskH = iField.activePointsMaskHost(); + auto aRange = maskH.activeRange(); + auto filed = iField.field().deviceVectorAll(); + + T maxElement; + + Kokkos::parallel_reduce( + "max(internalField)", + policy(aRange.start(), aRange.end() ), + LAMBDA_HD(uint32 i, T& maxUpdate) + { + if( maskH(i) ) + if( maxUpdate (maxElement)); + return maxElement; + } +} + + +template +inline +Pair minMax(const internalField& iField) +{ + using exeSpace = typename internalField::execution_space; + + using policy = Kokkos::RangePolicy< + exeSpace, + Kokkos::IndexType >; + + if constexpr(isDeviceAccessible()) + { + // this is a device view + auto maskD = iField.activePointsMaskDevice(); + auto aRange = maskD.activeRange(); + auto filed = iField.field().deviceVectorAll(); + + T minElement; + T maxElement; + + Kokkos::parallel_reduce( + "minMax(internalField)", + policy(aRange.start(), aRange.end() ), + LAMBDA_HD(uint32 i, T& minUpdate, T& maxUpdate) + { + if( maskD(i) ) + { + if(maxUpdate < filed[i]) maxUpdate = filed[i]; + if(filed[i] < minUpdate) minUpdate = filed[i]; + } + + }, + Kokkos::Min(minElement), + Kokkos::Max(maxElement) + ); + return {minElement, maxElement}; + } + else + { + // this is a host view + auto maskH = iField.activePointsMaskHost(); + auto aRange = maskH.activeRange(); + auto filed = iField.field().deviceVectorAll(); + + T minElement; + T maxElement; + + Kokkos::parallel_reduce( + "minMax(internalField)", + policy(aRange.start(), aRange.end() ), + LAMBDA_HD(uint32 i, T& minUpdate, T& maxUpdate) + { + if( maskH(i) ) + { + if(maxUpdate < filed[i]) maxUpdate = filed[i]; + if(filed[i] < minUpdate) minUpdate = filed[i]; + } + + }, + Kokkos::Min(minElement), + Kokkos::Max(maxElement) + ); + return {minElement, maxElement}; + } +} + + + +} + + + + + +#endif \ No newline at end of file diff --git a/src/phasicFlow/containers/pointField/pointField.hpp b/src/phasicFlow/containers/pointField/pointField.hpp index ffc315c5..9057174c 100644 --- a/src/phasicFlow/containers/pointField/pointField.hpp +++ b/src/phasicFlow/containers/pointField/pointField.hpp @@ -93,77 +93,26 @@ public: const T& defVal, const T& val); + + + //// - Methods + const auto& internal()const { return static_cast(*this); } - // - construct from iIOEntity, pointStructure and a value - /*pointField( const pointStructure& pStruct, const T& val, const T& defVal, bool subscribe = true); - - // - construct from another pointField - // subscribe to events if true - pointField( const pointField& src, bool subscribe); - - - // - copy construct - pointField(const pointField& src); - - // - no move construct - pointField(pointField&& src) = delete; - - - // assignment, only assign the VectorField and preserve other parts of this - pointField& operator = (const pointField& rhs); - - // no move assignment - pointField& operator = (pointField&&) = delete; - - - inline uniquePtr clone() const - { - return makeUnique(*this); - } - - inline pointFieldType* clonePtr()const - { - return new pointFieldType(*this); - } - - //// - Methods - // - reference to pointStructure inline const pointStructure& pStruct()const { return pStruct_; } - // if all points are active - INLINE_FUNCTION_H - bool allActive()const { - return pStruct_.allActive(); - } - - - INLINE_FUNCTION_H - bool isActive(label i)const { - return pStruct_.isActive(i); - } - - const auto& pointFlag()const + void fill(const T& val) { - return pStruct_.pointFlag(); + InternalFieldType::fillInternal(val); + boundaryFieldList_.fill(val); } - range activeRange()const - { - return pStruct_.activeRange(); - } - - // - update the field if any changes occure in pStruct - // for now it checks for deleted points - bool update(const eventMessage& msg);*/ - - //// - IO operations bool readPointField(iIstream& is, const IOPattern& iop); diff --git a/src/phasicFlow/containers/pointField/pointFields.cpp b/src/phasicFlow/containers/pointField/pointFields.cpp index cb1c8584..8e90019f 100644 --- a/src/phasicFlow/containers/pointField/pointFields.cpp +++ b/src/phasicFlow/containers/pointField/pointFields.cpp @@ -31,6 +31,31 @@ template class pFlow::pointField; createBaseBoundary(pFlow::int8, void); createBoundary(pFlow::int8, void, exit); + +template class pFlow::pointField; +createBaseBoundary(pFlow::uint8, pFlow::HostSpace); +createBoundary(pFlow::uint8, pFlow::HostSpace, exit); + +template class pFlow::pointField; +createBaseBoundary(pFlow::uint8, void); +createBoundary(pFlow::uint8, void, exit); + +template class pFlow::pointField; +createBaseBoundary(pFlow::int32, pFlow::HostSpace); +createBoundary(pFlow::int32, pFlow::HostSpace, exit); + +template class pFlow::pointField; +createBaseBoundary(pFlow::int32, void); +createBoundary(pFlow::int32, void, exit); + +template class pFlow::pointField; +createBaseBoundary(pFlow::uint32, pFlow::HostSpace); +createBoundary(pFlow::uint32, pFlow::HostSpace, exit); + +template class pFlow::pointField; +createBaseBoundary(pFlow::uint32, void); +createBoundary(pFlow::uint32, void, exit); + template class pFlow::pointField; createBaseBoundary(pFlow::real, pFlow::HostSpace); createBoundary(pFlow::real, pFlow::HostSpace, exit); @@ -40,36 +65,25 @@ template class pFlow::pointField; createBaseBoundary(pFlow::real, void); createBoundary(pFlow::real, void, exit); - -/*template class pFlow::pointField; - -template class pFlow::pointField; - -template class pFlow::pointField; - -template class pFlow::pointField; - -template class pFlow::pointField; - -template class pFlow::pointField; - -template class pFlow::pointField; - -template class pFlow::pointField; - -template class pFlow::pointField; - -template class pFlow::pointField; - -template class pFlow::pointField; - -template class pFlow::pointField; - -template class pFlow::pointField; - -template class pFlow::pointField; - -template class pFlow::pointField;*/ +template class pFlow::pointField; +createBaseBoundary(pFlow::realx3, pFlow::HostSpace); +createBoundary(pFlow::realx3, pFlow::HostSpace, exit); +template class pFlow::pointField; +createBaseBoundary(pFlow::realx3, void); +createBoundary(pFlow::realx3, void, exit); + +template class pFlow::pointField; +createBaseBoundary(pFlow::realx4, pFlow::HostSpace); +createBoundary(pFlow::realx4, pFlow::HostSpace, exit); + + +template class pFlow::pointField; +createBaseBoundary(pFlow::realx4, void); +createBoundary(pFlow::realx4, void, exit); + +template class pFlow::pointField; +createBaseBoundary(pFlow::word, pFlow::HostSpace); +createBoundary(pFlow::word, pFlow::HostSpace, exit); \ No newline at end of file diff --git a/src/phasicFlow/containers/pointField/pointFields.hpp b/src/phasicFlow/containers/pointField/pointFields.hpp index d3435812..26e0d52a 100644 --- a/src/phasicFlow/containers/pointField/pointFields.hpp +++ b/src/phasicFlow/containers/pointField/pointFields.hpp @@ -49,14 +49,11 @@ using uint32PointField_D = pointField_D; using uint32PointField_H = pointField_H; using int64PointField_D = pointField_D; -using int63PointField_H = pointField_H; +using int64PointField_H = pointField_H; using uint64PointField_D = pointField_D; using uint64PointField_H = pointField_H; -using int32PointField_D = pointField_D; -using int32PointField_H = pointField_H; - using realPointField_D = pointField_D; using realPointField_H = pointField_H; @@ -66,9 +63,7 @@ using realx3PointField_H = pointField_H; using realx4PointField_D = pointField_D; using realx4PointField_H = pointField_H; - - - +using wordPointField_H = pointField_H; } diff --git a/src/phasicFlow/demComponent/demComponent.cpp b/src/phasicFlow/demComponent/demComponent.cpp index 0307b333..9225eb17 100644 --- a/src/phasicFlow/demComponent/demComponent.cpp +++ b/src/phasicFlow/demComponent/demComponent.cpp @@ -24,10 +24,10 @@ Licence: pFlow::demComponent::demComponent(const word& name, systemControl& control) : - componentName_(name), control_(control), time_(control.time()), - timers_(name, &control.timers()) + timers_(name, &control.timers()), + componentName_(name) {} pFlow::real pFlow::demComponent::dt()const @@ -37,5 +37,10 @@ pFlow::real pFlow::demComponent::dt()const pFlow::real pFlow::demComponent::currentTime()const { - return time_.currentTime(); + return time_.currentTime(); +} + +pFlow::uint32 pFlow::demComponent::currentIter() const +{ + return time_.currentIter(); } diff --git a/src/phasicFlow/demComponent/demComponent.hpp b/src/phasicFlow/demComponent/demComponent.hpp index 35d6dc67..cbab450e 100644 --- a/src/phasicFlow/demComponent/demComponent.hpp +++ b/src/phasicFlow/demComponent/demComponent.hpp @@ -40,13 +40,9 @@ class Time; */ class demComponent { -protected: - - // - Protected data members - - /// Name of the DEM component - word componentName_; - +private: + // - Protected data members + /// Reference to systemControl systemControl& control_; @@ -55,6 +51,9 @@ protected: /// All timers (if any) of this component Timers timers_; + /// Name of the DEM component + word componentName_; + public: /// Type info @@ -102,6 +101,8 @@ public: /// Current simulation time real currentTime()const; + + uint32 currentIter()const; inline const auto& time()const @@ -134,7 +135,7 @@ public: virtual bool beforeTimeLoop() { - notImplementedFunction + notImplementedFunction; return false; } @@ -155,7 +156,7 @@ public: virtual bool afterTimeLoop() { - notImplementedFunction + notImplementedFunction; return false; } diff --git a/src/phasicFlow/dictionary/dictionary.hpp b/src/phasicFlow/dictionary/dictionary.hpp index db77733c..d09c03bc 100644 --- a/src/phasicFlow/dictionary/dictionary.hpp +++ b/src/phasicFlow/dictionary/dictionary.hpp @@ -107,11 +107,7 @@ protected: /// write dictionary to stream - with keyword bool writeDictionary(iOstream& os, bool withBlock = true)const; - /// construct an empty dictionary with keyword and make it global/fileDictionary (if true) - dictionary(const word& keyword, bool global); - - /// construct a dictionary with name and read it from file - dictionary(const word& keyword, const fileSystem& file); + public: @@ -122,7 +118,12 @@ public: TypeInfo("dictionary"); //// - Constructors + /// construct an empty dictionary with keyword and make it global/fileDictionary (if true) + dictionary(const word& keyword, bool global); + /// construct a dictionary with name and read it from file + dictionary(const word& keyword, const fileSystem& file); + /// cunstructs a null dictionary dictionary(); diff --git a/src/phasicFlow/eventManagement/observer.cpp b/src/phasicFlow/eventManagement/observer.cpp index 03621f31..d47fef24 100644 --- a/src/phasicFlow/eventManagement/observer.cpp +++ b/src/phasicFlow/eventManagement/observer.cpp @@ -21,8 +21,9 @@ Licence: #include "observer.hpp" #include "subscriber.hpp" -pFlow::observer::observer(): - subscriber_(nullptr) +pFlow::observer::observer(message msg): + subscriber_(nullptr), + message_(msg) {} pFlow::observer::observer @@ -30,30 +31,47 @@ pFlow::observer::observer const subscriber* subscrbr, message msg ) -: - subscriber_(subscrbr), - message_(msg) +{ + addToSubscriber(subscrbr, msg); +} + +pFlow::observer::~observer() { + if(subscriber_) + subscriber_->unsubscribe(this); + invalidateSubscriber(); +} + +void pFlow::observer::addToSubscriber +( + const subscriber* subscrbr, + message msg +) +{ + if(subscriber_) + subscriber_->unsubscribe(this); + invalidateSubscriber(); + + subscriber_ = subscrbr; + message_ = msg; + if(subscriber_) { - if(!subscriber_->subscribe(msg, this)) + if(!subscriber_->subscribe(message_, this)) { fatalErrorInFunction<< "error in subscribing an observer"<unsubscribe(this); - invalidateSubscriber(); + } } bool pFlow::observer::addToSubscriber(const subscriber& subscrbr) { + if(subscriber_) + subscriber_->unsubscribe(this); + invalidateSubscriber(); + subscriber_ = &subscrbr; return subscriber_->subscribe(message_, this); } \ No newline at end of file diff --git a/src/phasicFlow/eventManagement/observer.hpp b/src/phasicFlow/eventManagement/observer.hpp index 7990cd32..6b8fca11 100644 --- a/src/phasicFlow/eventManagement/observer.hpp +++ b/src/phasicFlow/eventManagement/observer.hpp @@ -39,12 +39,12 @@ protected: const subscriber* subscriber_ = nullptr; /// list of events in the message - const message message_; + message message_; public: - observer(); + observer(message msg); observer( const subscriber* subscrbr, @@ -53,12 +53,20 @@ public: virtual ~observer(); + void subscribe( + const subscriber* subscrbr, + message msg); + inline bool subscribed()const { return subscriber_!=nullptr; } + void addToSubscriber( + const subscriber* subscrbr, + message msg); + bool addToSubscriber(const subscriber& subscriber); inline void invalidateSubscriber() @@ -72,7 +80,12 @@ public: return message::numEvents(); } - virtual bool hearChanges(const message& msg, const anyList& varList)=0; + virtual bool hearChanges( + real t, + real dt, + uint32 iter, + const message& msg, + const anyList& varList)=0; }; } // pFlow diff --git a/src/phasicFlow/eventManagement/subscriber.cpp b/src/phasicFlow/eventManagement/subscriber.cpp index ea8319ee..db8009bd 100644 --- a/src/phasicFlow/eventManagement/subscriber.cpp +++ b/src/phasicFlow/eventManagement/subscriber.cpp @@ -82,6 +82,9 @@ bool pFlow::subscriber::unsubscribe bool pFlow::subscriber::notify ( + real t, + real dt, + uint32 iter, const message msg, const anyList& varList ) @@ -93,7 +96,14 @@ bool pFlow::subscriber::notify { for( auto obsvr: observerList_[i] ) { - obsvr->hearChanges(message(i), varList); + obsvr->hearChanges + ( + t, + dt, + iter, + message(i), + varList + ); } } } diff --git a/src/phasicFlow/eventManagement/subscriber.hpp b/src/phasicFlow/eventManagement/subscriber.hpp index 23570485..48143f18 100644 --- a/src/phasicFlow/eventManagement/subscriber.hpp +++ b/src/phasicFlow/eventManagement/subscriber.hpp @@ -69,7 +69,12 @@ public: - bool notify(const message msg, const anyList& varList); + bool notify( + real t, + real dt, + uint32 iter, + const message msg, + const anyList& varList); }; diff --git a/src/phasicFlow/globals/error.hpp b/src/phasicFlow/globals/error.hpp index a58a30c0..540e7719 100644 --- a/src/phasicFlow/globals/error.hpp +++ b/src/phasicFlow/globals/error.hpp @@ -62,7 +62,7 @@ pFlow::iOstream& reportAndExit(int errorCode = EXIT_FAILURE); notImplementedErrorMessage ((functionName), __FILE__, __LINE__ ) /// Report that a function is yet not implemented. -#define notImplementedFunction Not_Implemented(FUNCTION_NAME); +#define notImplementedFunction Not_Implemented(FUNCTION_NAME) /// Report an error in file operation with supplied fileName and lineNumber. #define ioErrorInFile( fileName, lineNumber) \ diff --git a/src/phasicFlow/globals/vocabs.hpp b/src/phasicFlow/globals/vocabs.hpp index 5afac001..f1ffede1 100755 --- a/src/phasicFlow/globals/vocabs.hpp +++ b/src/phasicFlow/globals/vocabs.hpp @@ -37,9 +37,9 @@ const inline char* integrationFolder__ = "integration"; // file names const inline char* settingsFile__ = "settingsDict"; -const inline char* domainFile__ = "domainDict"; +const inline char* domainFile__ = "domainDict"; const inline char* insertionFile__ = "particleInsertion"; -const inline char* sphereShapeFile__ = "sphereShape"; +const inline char* shapeFile__ = "shapes"; const inline char* pointStructureFile__ = "pStructure"; const inline char* triSurfaceFile__ = "triSurface"; const inline char* createParticles__ = "createParticles"; diff --git a/src/phasicFlow/random/randomInt32/uniformRandomInt32.hpp b/src/phasicFlow/random/randomInt32/uniformRandomUint32.hpp similarity index 77% rename from src/phasicFlow/random/randomInt32/uniformRandomInt32.hpp rename to src/phasicFlow/random/randomInt32/uniformRandomUint32.hpp index 86408dcf..86564d93 100644 --- a/src/phasicFlow/random/randomInt32/uniformRandomInt32.hpp +++ b/src/phasicFlow/random/randomInt32/uniformRandomUint32.hpp @@ -18,8 +18,8 @@ Licence: -----------------------------------------------------------------------------*/ -#ifndef __uniformRandomInt32_hpp__ -#define __uniformRandomInt32_hpp__ +#ifndef __uniformRandomUint32_hpp__ +#define __uniformRandomUint32_hpp__ #include @@ -29,35 +29,35 @@ Licence: namespace pFlow { -class uniformRandomInt32 +class uniformRandomUint32 { protected: std::mt19937_64 engineGen_; - std::uniform_int_distribution distrbution_; + std::uniform_int_distribution distrbution_; public: // type info TypeInfoNV("uniform"); - explicit uniformRandomInt32(int32 min, int32 max) + explicit uniformRandomUint32(uint32 min, uint32 max) : engineGen_(std::random_device()()), distrbution_(min, max) {} - ~uniformRandomInt32()= default; + ~uniformRandomUint32()= default; - inline real randomNumber() + inline uint32 randomNumber() { return distrbution_(engineGen_); } - inline int32x3 randomNumber3() + inline triple randomNumber3() { - return int32x3 + return triple ( randomNumber(), randomNumber(), @@ -65,9 +65,9 @@ public: ); } - inline realx3 operator()() + inline triple operator()() { - return randomNumber(); + return randomNumber3(); } diff --git a/src/phasicFlow/repository/IOobject/IOfileHeader.cpp b/src/phasicFlow/repository/IOobject/IOfileHeader.cpp index 440a1ab6..96a49f67 100644 --- a/src/phasicFlow/repository/IOobject/IOfileHeader.cpp +++ b/src/phasicFlow/repository/IOobject/IOfileHeader.cpp @@ -116,6 +116,8 @@ bool pFlow::IOfileHeader::implyRead() const bool pFlow::IOfileHeader::implyWrite() const { + if( isExcluded( name() ) ) return false; + if( isIncluded( name() ) ) return true; return isWriteAlways(); } diff --git a/src/phasicFlow/repository/IOobject/IOfileHeader.hpp b/src/phasicFlow/repository/IOobject/IOfileHeader.hpp index 4d9964f7..1d2a1e4c 100644 --- a/src/phasicFlow/repository/IOobject/IOfileHeader.hpp +++ b/src/phasicFlow/repository/IOobject/IOfileHeader.hpp @@ -81,6 +81,18 @@ public: { return nullptr; } + + virtual + bool isIncluded(const word& objName)const + { + return false; + } + + virtual + bool isExcluded(const word& objName)const + { + return false; + } // - path to file name fileSystem path() const; diff --git a/src/phasicFlow/repository/IOobject/IOobject.cpp b/src/phasicFlow/repository/IOobject/IOobject.cpp index 2cd77a9f..6745ad0b 100644 --- a/src/phasicFlow/repository/IOobject/IOobject.cpp +++ b/src/phasicFlow/repository/IOobject/IOobject.cpp @@ -62,6 +62,21 @@ pFlow::repository* pFlow::IOobject::releaseOwner return old; } +bool pFlow::IOobject::isIncluded(const word& objName)const +{ + if(owner_) + return owner_->isIncluded(objName); + return false; +} + + +bool pFlow::IOobject::isExcluded(const word& objName)const +{ + if(owner_) + return owner_->isExcluded(objName); + return false; +} + bool pFlow::IOobject::readObject(bool rdHdr) { if(!implyRead())return true; diff --git a/src/phasicFlow/repository/IOobject/IOobject.hpp b/src/phasicFlow/repository/IOobject/IOobject.hpp index f2eaaba7..36508be1 100644 --- a/src/phasicFlow/repository/IOobject/IOobject.hpp +++ b/src/phasicFlow/repository/IOobject/IOobject.hpp @@ -85,6 +85,12 @@ public: repository* releaseOwner(bool fromOwner = false); + + bool isIncluded(const word& objName)const override; + + bool isExcluded(const word& objName)const override; + + //// - IO operations // - read from file diff --git a/src/phasicFlow/repository/IOobject/objectFile.hpp b/src/phasicFlow/repository/IOobject/objectFile.hpp index dfe93fd2..ee0cf85a 100644 --- a/src/phasicFlow/repository/IOobject/objectFile.hpp +++ b/src/phasicFlow/repository/IOobject/objectFile.hpp @@ -97,12 +97,14 @@ public: virtual ~objectFile()=default; - virtual word name() const + virtual + const word& name() const { return name_; } - virtual fileSystem localPath()const + virtual + const fileSystem& localPath()const { return localPath_; } diff --git a/src/phasicFlow/repository/repository/repository.cpp b/src/phasicFlow/repository/repository/repository.cpp index d3e268ea..b555eab3 100644 --- a/src/phasicFlow/repository/repository/repository.cpp +++ b/src/phasicFlow/repository/repository/repository.cpp @@ -283,7 +283,8 @@ bool pFlow::repository::write { if(verbose) { - REPORT(1)<< "Writing to " << obj.second->path()<implyWrite()) + REPORT(1)<< "Writing to " << obj.second->path()<writeObject()) diff --git a/src/phasicFlow/repository/repository/repository.hpp b/src/phasicFlow/repository/repository/repository.hpp index cc5ec1c2..93698ab7 100644 --- a/src/phasicFlow/repository/repository/repository.hpp +++ b/src/phasicFlow/repository/repository/repository.hpp @@ -114,6 +114,23 @@ public: bool removeFromRepository(IOobject* io); repository* releaseOwner(bool fromOwner = false); + + virtual + bool isIncluded(const word& objName)const + { + if(owner_) + return owner_->isIncluded(objName); + return false; + } + + virtual + bool isExcluded(const word& objName)const + { + if(owner_) + return owner_->isExcluded(objName); + return false; + } + //// - lookups and queries // - check if name of object exists diff --git a/src/phasicFlow/repository/repository/repositoryTemplates.cpp b/src/phasicFlow/repository/repository/repositoryTemplates.cpp index 52ec9b02..a4c9ee1e 100644 --- a/src/phasicFlow/repository/repository/repositoryTemplates.cpp +++ b/src/phasicFlow/repository/repository/repositoryTemplates.cpp @@ -17,117 +17,7 @@ Licence: implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. -----------------------------------------------------------------------------*/ -/* -template -T& pFlow::repository::emplaceObject(const objectFile& objf, Args&&... args) -{ - - if( auto [iter2, success2] = objects_.findIf(objf.name()); !success2 ) - { - auto ptr = IOobject::make_object_t(std::forward(args)...); - auto [iter, success] = objects_.emplace(std::piecewise_construct, - std::forward_as_tuple(objf.name()), - std::forward_as_tuple(objf, this, std::move(ptr) ) - ); - - return iter->second.template getObject(); - } - else - { - fatalErrorInFunction<< - "IOobject " << objf.name() << " already exists in repository " << name() <second.template getObject(); - - } -} - -template -T& pFlow::repository::emplaceObjectOrGet(const objectFile& objf, Args&&... args) -{ - - if(auto [iter, success] = objects_.findIf(objf.name()); !success ) - { - return emplaceObject(objf, std::forward(args)... ); - } - else - { - // type check - if( checkForObjectType( iter->second ) ) - { - return iter->second.template getObject(); - } - else - { - fatalErrorInFunction<< - " IOobject "<< objf.name() <<" already exist in the repository "<< name() << - ". Trying to return the existing object but there is a type mismatch. \n"<< - reportTypeError( iter->second ); - fatalExit; - return iter->second.template getObject(); // this is never executed - } - } -} - -template -T& pFlow::repository::emplaceReplaceObject(const objectFile& objf, Args&&... args) -{ - - eraseObject(objf.name()); - - auto ptr = IOobject::make_object_t(std::forward(args)...); - auto [iter, success] = objects_.emplace(std::piecewise_construct, - std::forward_as_tuple(objf.name()), - std::forward_as_tuple(objf, this, std::move(ptr) ) - ); - - return iter->second.template getObject(); -} - -template -T& pFlow::repository::insertReplaceObject(uniquePtr&& ptr ) -{ - if( !ptr->owner() ) - { - eraseObject(ptr->name()); - objectFile objf( ptr() ); - - auto [iter, success] = objects_.emplace - ( - std::piecewise_construct, - std::forward_as_tuple(ptr->name()), - std::forward_as_tuple(objf, this, std::move(ptr)) - ); - return iter->second.template getObject(); - }else - { - return ptr().getObject(); - } -} - -template -T& pFlow::repository::insertReplaceObject(const objectFile& objf, uniquePtr&& ptr ) -{ - if( !ptr->owner() ) - { - eraseObject(objf.name()); - - auto [iter, success] = objects_.emplace - ( - std::piecewise_construct, - std::forward_as_tuple(objf.name()), - std::forward_as_tuple(objf, this, std::move(ptr)) - ); - return iter->second.template getObject(); - }else - { - return ptr().getObject(); - } -} - - -*/ template pFlow::word pFlow::repository::reportTypeError(IOobject& object) @@ -154,15 +44,15 @@ T& pFlow::repository::lookupObject(const word& name) if( checkType(iter->second) ) { - return static_cast(iter->second); + return static_cast(*iter->second); }else { fatalErrorInFunction << - reportTypeError(iter->second)<(*iter->second)<(iter->second); + return static_cast(*iter->second); } } @@ -172,6 +62,6 @@ T& pFlow::repository::lookupObject(const word& name) "Object with name " << name << " is not found in repository " << this->name()<second.template getObject(); + return static_cast(*iter->second); } } \ No newline at end of file diff --git a/src/phasicFlow/repository/systemControl/systemControl.cpp b/src/phasicFlow/repository/systemControl/systemControl.cpp index 77a7b684..ba96adab 100644 --- a/src/phasicFlow/repository/systemControl/systemControl.cpp +++ b/src/phasicFlow/repository/systemControl/systemControl.cpp @@ -24,25 +24,32 @@ Licence: #include "error.hpp" #include "systemControl.hpp" #include "vocabs.hpp" +#include "Lists.hpp" -/*bool pFlow::systemControl::readDomainDict() +bool pFlow::systemControl::readIncludeExclue +( + const dictionary& dict +) { - if(!domainDict_) - { - domainDict_ = makeUnique - ( - objectFile - ( - domainFile__, - "", - objectFile::READ_ALWAYS, - objectFile::WRITE_NEVER - ), - &settings() - ); - } - return true; -}*/ + if(dict.containsDataEntry("includeObjects")) + { + wordList incld = dict.getVal("includeObjects"); + for(auto& nm:incld) + { + includeList_.insert(nm); + } + } + + if(dict.containsDataEntry("excludeObjects")) + { + wordList excld = dict.getVal("excludeObjects"); + for(auto& nm:excld) + { + excludeList_.insert(nm); + } + } + return true; +} pFlow::word pFlow::systemControl::getRunName ( @@ -176,7 +183,7 @@ pFlow::systemControl::systemControl ), writeToFileTimer_("Write to file", &timers_) { - //readDomainDict(); + readIncludeExclue(settingsDict_()); } pFlow::systemControl::systemControl( @@ -250,13 +257,9 @@ pFlow::systemControl::systemControl( ), writeToFileTimer_("Write to file", &timers_) { - //readDomainDict(); + readIncludeExclue(settingsDict_()); } -/*pFlow::fileDictionary& pFlow::systemControl::domainDict() -{ - return domainDict_(); -}*/ bool pFlow::systemControl::operator ++(int) { diff --git a/src/phasicFlow/repository/systemControl/systemControl.hpp b/src/phasicFlow/repository/systemControl/systemControl.hpp index 3cf1317c..28d5542b 100644 --- a/src/phasicFlow/repository/systemControl/systemControl.hpp +++ b/src/phasicFlow/repository/systemControl/systemControl.hpp @@ -34,6 +34,7 @@ Licence: #include "box.hpp" #include "Timers.hpp" #include "dynamicLinkLibs.hpp" +#include "Set.hpp" namespace pFlow { @@ -79,7 +80,12 @@ protected: Timer writeToFileTimer_; - //bool readDomainDict(); + wordSet includeList_; + + wordSet excludeList_; + + + bool readIncludeExclue(const dictionary& dict); static word getRunName( const fileSystem& path); @@ -189,6 +195,36 @@ public: return outFilePrecision_; } + + bool isIncluded(const word& objName)const final + { + return includeList_.count(objName) == static_cast(1); + } + + + bool isExcluded(const word& objName)const final + { + return excludeList_.count(objName) == static_cast(1); + } + + void clearIncludeExclude() + { + includeList_.clear(); + excludeList_.clear(); + } + + bool addInclude(const word& objName) + { + auto [iter, success] = includeList_.insert(objName); + return success; + } + + bool addExclude(const word& objName) + { + auto [ite, success] = excludeList_.insert(objName); + return success; + } + }; diff --git a/src/phasicFlow/setFieldList/setFieldEntry.cpp b/src/phasicFlow/setFieldList/setFieldEntry.cpp index 8cb0c24f..7da664fa 100644 --- a/src/phasicFlow/setFieldList/setFieldEntry.cpp +++ b/src/phasicFlow/setFieldList/setFieldEntry.cpp @@ -39,13 +39,15 @@ bool pFlow::setFieldEntry::checkForTypeAndValueAll()const if( !( checkForTypeAndValue() || - checkForTypeAndValue() || + checkForTypeAndValue() || checkForTypeAndValue() || checkForTypeAndValue() || checkForTypeAndValue() || - checkForTypeAndValue