From 9c86fe8f31b45744fef9e1149ba2ed4b39d4110d Mon Sep 17 00:00:00 2001 From: Hamidreza Norouzi Date: Sun, 21 Jan 2024 13:26:23 -0800 Subject: [PATCH 01/57] refactor up to particles.hpp --- .gitignore | 1 - CMakeLists.txt | 2 +- src/CMakeLists.txt | 6 +- .../AdamsBashforth2/AdamsBashforth2.cpp | 143 ++++++++---- .../AdamsBashforth2/AdamsBashforth2.hpp | 91 ++------ src/Integration/CMakeLists.txt | 12 +- src/Integration/integration/integration.cpp | 30 +-- src/Integration/integration/integration.hpp | 56 +++-- src/Particles/CMakeLists.txt | 16 +- .../dynamicPointStructure.cpp | 100 ++++---- .../dynamicPointStructure.hpp | 83 ++----- src/Particles/particles/particles.cpp | 206 +++++++---------- src/Particles/particles/particles.hpp | 217 ++++++++---------- src/Property/property.cpp | 108 +++++---- src/Property/property.hpp | 58 ++--- src/phasicFlow/CMakeLists.txt | 31 ++- src/phasicFlow/containers/Vector/Vector.hpp | 2 +- .../containers/pointField/internalField.hpp | 15 ++ .../containers/pointField/pointField.cpp | 29 ++- .../containers/pointField/pointField.hpp | 6 + .../containers/pointField/pointFields.hpp | 58 ++--- src/phasicFlow/dictionary/fileDictionary.cpp | 2 +- .../repository/IOobject/IOPattern.hpp | 15 +- .../repository/IOobject/IOfileHeader.cpp | 11 +- .../repository/IOobject/IOobject.cpp | 101 ++++---- .../repository/IOobject/IOobject.hpp | 4 +- .../repository/IOobject/objectFile.hpp | 22 +- src/phasicFlow/repository/Time/Time.cpp | 17 +- src/phasicFlow/repository/Time/Time.hpp | 16 +- src/phasicFlow/smartPointers/uniquePtr.hpp | 3 +- .../boundaries/boundaryNone/boundaryNone.cpp | 58 +++++ .../boundaries/boundaryNone/boundaryNone.hpp | 64 ++++++ .../domain/regularSimulationDomain.hpp | 5 + .../domain/simulationDomain.hpp | 3 + .../pointStructure/pointFlag.hpp | 2 +- utilities/Utilities/readFromTimeFolder.hpp | 64 +++--- .../particlesPhasicFlow.cpp | 52 +---- .../positionParticles/positionParticles.cpp | 14 +- 38 files changed, 868 insertions(+), 855 deletions(-) create mode 100644 src/phasicFlow/structuredData/boundaries/boundaryNone/boundaryNone.cpp create mode 100644 src/phasicFlow/structuredData/boundaries/boundaryNone/boundaryNone.hpp diff --git a/.gitignore b/.gitignore index 54081c4f..d18b66f0 100644 --- a/.gitignore +++ b/.gitignore @@ -38,7 +38,6 @@ bin/** lib/** test*/** **/**notnow -**/MPIParallel*/** doc/code-documentation/ doc/DTAGS # all possible time folders diff --git a/CMakeLists.txt b/CMakeLists.txt index 233e18aa..8cd85bfa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -73,7 +73,7 @@ add_subdirectory(src) #add_subdirectory(solvers) -#add_subdirectory(utilities) +add_subdirectory(utilities) #add_subdirectory(DEMSystems) add_subdirectory(testIO) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 31049334..235f17a2 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,11 +1,11 @@ add_subdirectory(phasicFlow) -#add_subdirectory(Integration) +add_subdirectory(Integration) -#add_subdirectory(Property) +add_subdirectory(Property) -#add_subdirectory(Particles) +add_subdirectory(Particles) #add_subdirectory(Interaction) diff --git a/src/Integration/AdamsBashforth2/AdamsBashforth2.cpp b/src/Integration/AdamsBashforth2/AdamsBashforth2.cpp index 09a4eaa0..4c6a05cc 100644 --- a/src/Integration/AdamsBashforth2/AdamsBashforth2.cpp +++ b/src/Integration/AdamsBashforth2/AdamsBashforth2.cpp @@ -19,36 +19,107 @@ Licence: -----------------------------------------------------------------------------*/ #include "AdamsBashforth2.hpp" +#include "pointStructure.hpp" +#include "Time.hpp" +#include "vocabs.hpp" + +namespace pFlow +{ + +/// Range policy for integration kernel (alias) +using rpIntegration = Kokkos::RangePolicy< + DefaultExecutionSpace, + Kokkos::Schedule, + Kokkos::IndexType + >; + +bool intAllActive( + real dt, + realx3PointField_D& y, + realx3PointField_D& dy, + realx3PointField_D& dy1) +{ + + auto d_dy = dy.fieldDevice(); + auto d_y = y.fieldDevice(); + auto d_dy1= dy1.fieldDevice(); + auto activeRng = dy1.activeRange(); + + Kokkos::parallel_for( + "AdamsBashforth2::correct", + rpIntegration (activeRng.start(), activeRng.end()), + LAMBDA_HD(int32 i){ + d_y[i] += dt*(static_cast(1.5) * d_dy[i] - static_cast(0.5) * d_dy1[i]); + d_dy1[i] = d_dy[i]; + }); + Kokkos::fence(); + + return true; +} + +bool intScattered +( + real dt, + realx3PointField_D& y, + realx3PointField_D& dy, + realx3PointField_D& dy1 +) +{ + + auto d_dy = dy.fieldDevice(); + auto d_y = y.fieldDevice(); + auto d_dy1 = dy1.fieldDevice(); + auto activeRng = dy1.activeRange(); + const auto& activeP = dy1.activePointsMaskDevice(); + + Kokkos::parallel_for( + "AdamsBashforth2::correct", + rpIntegration (activeRng.start(), activeRng.end()), + LAMBDA_HD(int32 i){ + if( activeP(i)) + { + d_y[i] += dt*(static_cast(1.5) * d_dy[i] - static_cast(0.5) * d_dy1[i]); + d_dy1[i] = d_dy[i]; + } + }); + Kokkos::fence(); + + + return true; +} + +} + -//const real AB2_coef[] = { 3.0 / 2.0, 1.0 / 2.0}; pFlow::AdamsBashforth2::AdamsBashforth2 ( const word& baseName, - repository& owner, - const pointStructure& pStruct, - const word& method + pointStructure& pStruct, + const word& method, + const realx3Field_D& initialValField ) : - integration(baseName, owner, pStruct, method), - dy1_( - owner.emplaceObject( - objectFile( - groupNames(baseName,"dy1"), - "", - objectFile::READ_IF_PRESENT, - objectFile::WRITE_ALWAYS), - pStruct, - zero3)) -{ - -} + integration(baseName, pStruct, method, initialValField), + realx3PointField_D + ( + objectFile + ( + groupNames(baseName,"dy1"), + pStruct.time().integrationFolder(), + objectFile::READ_IF_PRESENT, + objectFile::WRITE_ALWAYS + ), + pStruct, + zero3 + ) +{} bool pFlow::AdamsBashforth2::predict ( real UNUSED(dt), - realx3Vector_D& UNUSED(y), - realx3Vector_D& UNUSED(dy) + realx3PointField_D& UNUSED(y), + realx3PointField_D& UNUSED(dy) ) { @@ -58,17 +129,19 @@ bool pFlow::AdamsBashforth2::predict bool pFlow::AdamsBashforth2::correct ( real dt, - realx3Vector_D& y, - realx3Vector_D& dy + realx3PointField_D& y, + realx3PointField_D& dy ) { - if(this->pStruct().allActive()) + auto& dy1l = dy1(); + + if(dy1l.isAllActive()) { - return intAll(dt, y, dy, this->pStruct().activeRange()); + return intAllActive(dt, y, dy, dy1l); } else { - return intRange(dt, y, dy, this->pStruct().activePointsMaskD()); + return intScattered(dt, y, dy, dy1l); } return true; @@ -81,25 +154,3 @@ bool pFlow::AdamsBashforth2::setInitialVals( return true; } -bool pFlow::AdamsBashforth2::intAll( - real dt, - realx3Vector_D& y, - realx3Vector_D& dy, - range activeRng) -{ - - auto d_dy = dy.deviceVectorAll(); - auto d_y = y.deviceVectorAll(); - auto d_dy1= dy1_.deviceVectorAll(); - - Kokkos::parallel_for( - "AdamsBashforth2::correct", - rpIntegration (activeRng.first, activeRng.second), - LAMBDA_HD(int32 i){ - d_y[i] += dt*(static_cast(3.0 / 2.0) * d_dy[i] - static_cast(1.0 / 2.0) * d_dy1[i]); - d_dy1[i] = d_dy[i]; - }); - Kokkos::fence(); - - return true; -} \ No newline at end of file diff --git a/src/Integration/AdamsBashforth2/AdamsBashforth2.hpp b/src/Integration/AdamsBashforth2/AdamsBashforth2.hpp index 6e2a8892..54e1c421 100644 --- a/src/Integration/AdamsBashforth2/AdamsBashforth2.hpp +++ b/src/Integration/AdamsBashforth2/AdamsBashforth2.hpp @@ -36,20 +36,16 @@ namespace pFlow */ class AdamsBashforth2 : - public integration + public integration, + public realx3PointField_D { -protected: +private: - /// dy at t-dt - realx3PointField_D& dy1_; - - /// Range policy for integration kernel (alias) - using rpIntegration = Kokkos::RangePolicy< - DefaultExecutionSpace, - Kokkos::Schedule, - Kokkos::IndexType - >; + auto& dy1() + { + return static_cast(*this); + } public: /// Type info @@ -60,17 +56,12 @@ public: /// Construct from components AdamsBashforth2( const word& baseName, - repository& owner, - const pointStructure& pStruct, - const word& method); - - uniquePtr clone()const override - { - return makeUnique(*this); - } + pointStructure& pStruct, + const word& method, + const realx3Field_D& initialValField); /// Destructor - virtual ~AdamsBashforth2()=default; + ~AdamsBashforth2()final = default; /// Add this to the virtual constructor table add_vCtor( @@ -80,71 +71,33 @@ public: // - Methods + /// return integration method + word method()const override + { + return "AdamsBashforth2"; + } bool predict( real UNUSED(dt), - realx3Vector_D& UNUSED(y), - realx3Vector_D& UNUSED(dy)) override; + realx3PointField_D& UNUSED(y), + realx3PointField_D& UNUSED(dy)) final; bool correct( real dt, - realx3Vector_D& y, - realx3Vector_D& dy) override; + realx3PointField_D& y, + realx3PointField_D& dy) final; bool setInitialVals( const int32IndexContainer& newIndices, - const realx3Vector& y) override; + const realx3Vector& y) final; - bool needSetInitialVals()const override + bool needSetInitialVals()const final { return false; } - - /// Integrate on all points in the active range - bool intAll( - real dt, - realx3Vector_D& y, - realx3Vector_D& dy, - range activeRng); - - /// Integrate on active points in the active range - template - bool intRange( - real dt, - realx3Vector_D& y, - realx3Vector_D& dy, - activeFunctor activeP ); }; -template -bool pFlow::AdamsBashforth2::intRange( - real dt, - realx3Vector_D& y, - realx3Vector_D& dy, - activeFunctor activeP ) -{ - - auto d_dy = dy.deviceVectorAll(); - auto d_y = y.deviceVectorAll(); - auto d_dy1= dy1_.deviceVectorAll(); - auto activeRng = activeP.activeRange(); - - Kokkos::parallel_for( - "AdamsBashforth2::correct", - rpIntegration (activeRng.first, activeRng.second), - LAMBDA_HD(int32 i){ - if( activeP(i)) - { - d_y[i] += dt*(static_cast(3.0 / 2.0) * d_dy[i] - static_cast(1.0 / 2.0) * d_dy1[i]); - d_dy1[i] = d_dy[i]; - } - }); - Kokkos::fence(); - - - return true; -} } // pFlow diff --git a/src/Integration/CMakeLists.txt b/src/Integration/CMakeLists.txt index f3a03112..fca650cd 100644 --- a/src/Integration/CMakeLists.txt +++ b/src/Integration/CMakeLists.txt @@ -1,13 +1,13 @@ list(APPEND SourceFiles integration/integration.cpp -AdamsBashforth5/AdamsBashforth5.cpp -AdamsBashforth4/AdamsBashforth4.cpp -AdamsBashforth3/AdamsBashforth3.cpp AdamsBashforth2/AdamsBashforth2.cpp -AdamsMoulton3/AdamsMoulton3.cpp -AdamsMoulton4/AdamsMoulton4.cpp -AdamsMoulton5/AdamsMoulton5.cpp +#AdamsBashforth5/AdamsBashforth5.cpp +#AdamsBashforth4/AdamsBashforth4.cpp +#AdamsBashforth3/AdamsBashforth3.cpp +#AdamsMoulton3/AdamsMoulton3.cpp +#AdamsMoulton4/AdamsMoulton4.cpp +#AdamsMoulton5/AdamsMoulton5.cpp ) set(link_libs Kokkos::kokkos phasicFlow) diff --git a/src/Integration/integration/integration.cpp b/src/Integration/integration/integration.cpp index 6e48ddaf..f3126e1e 100644 --- a/src/Integration/integration/integration.cpp +++ b/src/Integration/integration/integration.cpp @@ -19,33 +19,35 @@ Licence: -----------------------------------------------------------------------------*/ #include "integration.hpp" +#include "pointStructure.hpp" +#include "repository.hpp" pFlow::integration::integration ( const word& baseName, - repository& owner, - const pointStructure& pStruct, - const word& method + pointStructure& pStruct, + const word&, + const realx3Field_D& ) : - owner_(owner), - baseName_(baseName), - pStruct_(pStruct) -{ - CONSUME_PARAM(method); -} + owner_(*pStruct.owner()), + pStruct_(pStruct), + baseName_(baseName) +{} pFlow::uniquePtr - pFlow::integration::create( + pFlow::integration::create +( const word& baseName, - repository& owner, - const pointStructure& pStruct, - const word& method) + pointStructure& pStruct, + const word& method, + const realx3Field_D& initialValField +) { if( wordvCtorSelector_.search(method) ) { - return wordvCtorSelector_[method] (baseName, owner, pStruct, method); + return wordvCtorSelector_[method] (baseName, pStruct, method, initialValField); } else { diff --git a/src/Integration/integration/integration.hpp b/src/Integration/integration/integration.hpp index 3cca58c2..334e328e 100644 --- a/src/Integration/integration/integration.hpp +++ b/src/Integration/integration/integration.hpp @@ -23,14 +23,16 @@ Licence: #include "virtualConstructor.hpp" -#include "Vectors.hpp" -#include "pointStructure.hpp" -#include "repository.hpp" +#include "pointFields.hpp" namespace pFlow { +// - Forward +class repository; +class pointStructure; + /** * Base class for integrating the first order ODE (IVP) * @@ -48,19 +50,19 @@ namespace pFlow */ class integration { -protected: +private: // - Protected data members /// The owner repository that all fields are storred in repository& owner_; - /// The base name for integration - const word baseName_; - /// A reference to pointStructure const pointStructure& pStruct_; + /// The base name for integration + const word baseName_; + public: /// Type info @@ -72,9 +74,9 @@ public: /// Construct from components integration( const word& baseName, - repository& owner, - const pointStructure& pStruct, - const word& method); + pointStructure& pStruct, + const word& method, + const realx3Field_D& initialValField); /// Copy constructor integration(const integration&) = default; @@ -88,22 +90,22 @@ public: /// Move assignment integration& operator = (integration&&) = default; - /// Polymorphic copy/cloning - virtual - uniquePtr clone()const=0; - /// Destructor virtual ~integration()=default; /// Add a virtual constructor - create_vCtor( + create_vCtor + ( integration, word, - (const word& baseName, - repository& owner, - const pointStructure& pStruct, - const word& method), - (baseName, owner, pStruct, method) ); + ( + const word& baseName, + pointStructure& pStruct, + const word& method, + const realx3Field_D& initialValField + ), + (baseName, pStruct, method, initialValField) + ); // - Methods @@ -129,13 +131,17 @@ public: return owner_; } + /// return integration method + virtual + word method()const = 0 ; + /// Prediction step in integration virtual - bool predict(real dt, realx3Vector_D& y, realx3Vector_D& dy) = 0; + bool predict(real dt, realx3PointField_D& y, realx3PointField_D& dy) = 0; /// Correction/main integration step virtual - bool correct(real dt, realx3Vector_D& y, realx3Vector_D& dy) = 0; + bool correct(real dt, realx3PointField_D& y, realx3PointField_D& dy) = 0; /// Set the initial values for new indices virtual @@ -152,9 +158,9 @@ public: static uniquePtr create( const word& baseName, - repository& owner, - const pointStructure& pStruct, - const word& method); + pointStructure& pStruct, + const word& method, + const realx3Field_D& initialValField); }; // integration diff --git a/src/Particles/CMakeLists.txt b/src/Particles/CMakeLists.txt index 9c23631f..42ac0ea8 100644 --- a/src/Particles/CMakeLists.txt +++ b/src/Particles/CMakeLists.txt @@ -2,14 +2,14 @@ set(SourceFiles dynamicPointStructure/dynamicPointStructure.cpp particles/particles.cpp -particles/particleIdHandler.cpp -SphereParticles/sphereShape/sphereShape.cpp -SphereParticles/sphereParticles/sphereParticles.cpp -Insertion/shapeMixture/shapeMixture.cpp -Insertion/insertion/insertion.cpp -Insertion/Insertion/Insertions.cpp -Insertion/insertionRegion/insertionRegion.cpp -Insertion/insertionRegion/timeFlowControl.cpp +#particles/particleIdHandler.cpp +#SphereParticles/sphereShape/sphereShape.cpp +#SphereParticles/sphereParticles/sphereParticles.cpp +#Insertion/shapeMixture/shapeMixture.cpp +#Insertion/insertion/insertion.cpp +#Insertion/Insertion/Insertions.cpp +#Insertion/insertionRegion/insertionRegion.cpp +#Insertion/insertionRegion/timeFlowControl.cpp ) set(link_libs Kokkos::kokkos phasicFlow Integration Property) diff --git a/src/Particles/dynamicPointStructure/dynamicPointStructure.cpp b/src/Particles/dynamicPointStructure/dynamicPointStructure.cpp index 16e5b849..d99766e2 100644 --- a/src/Particles/dynamicPointStructure/dynamicPointStructure.cpp +++ b/src/Particles/dynamicPointStructure/dynamicPointStructure.cpp @@ -19,57 +19,40 @@ Licence: -----------------------------------------------------------------------------*/ #include "dynamicPointStructure.hpp" - +#include "systemControl.hpp" pFlow::dynamicPointStructure::dynamicPointStructure ( - Time& time, - const word& integrationMethod + systemControl& control ) : - time_(time), - integrationMethod_(integrationMethod), - pStruct_( - time_.emplaceObject( - objectFile( - pointStructureFile__, - "", - objectFile::READ_ALWAYS, - objectFile::WRITE_ALWAYS - ) - ) - ), - velocity_( - time_.emplaceObject( - objectFile( - "velocity", - "", - objectFile::READ_ALWAYS, - objectFile::WRITE_ALWAYS - ), - pStruct(), - zero3 - ) - ) - + pointStructure(control), + velocity_ + ( + objectFile( + "velocity", + "", + objectFile::READ_ALWAYS, + objectFile::WRITE_ALWAYS + ), + *this, + zero3 + ), + integrationMethod_ + ( + control.settingsDict().getVal("integrationMethod") + ) { - - this->subscribe(pStruct()); - REPORT(1)<< "Creating integration method "<< - greenText(integrationMethod_)<<" for dynamicPointStructure."<needSetInitialVals()) return; + /*if(!integrationPos_->needSetInitialVals()) return; @@ -107,14 +100,13 @@ pFlow::dynamicPointStructure::dynamicPointStructure vel.push_back( hVel[index(i)]); } - //output<< "pos "<< pos<setInitialVals(indexHD, pos); REPORT(2)<< "Initializing the required vectors for velocity integratoin\n "<setInitialVals(indexHD, vel); + integrationVel_->setInitialVals(indexHD, vel);*/ + } bool pFlow::dynamicPointStructure::predict @@ -123,10 +115,10 @@ bool pFlow::dynamicPointStructure::predict realx3PointField_D& acceleration ) { - auto& pos = pStruct().pointPosition(); + //auto& pos = pStruct().pointPosition(); - if(!integrationPos_().predict(dt, pos.VectorField(), velocity_.VectorField() ))return false; - if(!integrationVel_().predict(dt, velocity_.VectorField(), acceleration.VectorField()))return false; + //if(!integrationPos_().predict(dt, pos.VectorField(), velocity_.VectorField() ))return false; + //if(!integrationVel_().predict(dt, velocity_.VectorField(), acceleration.VectorField()))return false; return true; } @@ -137,11 +129,11 @@ bool pFlow::dynamicPointStructure::correct realx3PointField_D& acceleration ) { - auto& pos = pStruct().pointPosition(); + //auto& pos = pStruct().pointPosition(); - if(!integrationPos_().correct(dt, pos.VectorField(), velocity_.VectorField() ))return false; + //if(!integrationPos_().correct(dt, pos.VectorField(), velocity_.VectorField() ))return false; - if(!integrationVel_().correct(dt, velocity_.VectorField(), acceleration.VectorField()))return false; + //if(!integrationVel_().correct(dt, velocity_.VectorField(), acceleration.VectorField()))return false; return true; } @@ -178,7 +170,7 @@ pFlow::uniquePtr pFlow::dynamicPointStructure::inser }*/ -bool pFlow::dynamicPointStructure::update( +/*bool pFlow::dynamicPointStructure::update( const eventMessage& msg) { if( msg.isInsert()) @@ -215,4 +207,4 @@ bool pFlow::dynamicPointStructure::update( } return true; -} \ No newline at end of file +}*/ \ No newline at end of file diff --git a/src/Particles/dynamicPointStructure/dynamicPointStructure.hpp b/src/Particles/dynamicPointStructure/dynamicPointStructure.hpp index 843a3c46..d2e72659 100644 --- a/src/Particles/dynamicPointStructure/dynamicPointStructure.hpp +++ b/src/Particles/dynamicPointStructure/dynamicPointStructure.hpp @@ -30,98 +30,65 @@ Licence: namespace pFlow { +class systemControl; + class dynamicPointStructure : - //public pointStructure -public eventObserver + public pointStructure { -protected: +private: - Time& time_; + realx3PointField_D velocity_; - word integrationMethod_; + uniquePtr integrationPos_ = nullptr; - pointStructure& pStruct_; + uniquePtr integrationVel_ = nullptr; - realx3PointField_D& velocity_; - - uniquePtr integrationPos_; - - uniquePtr integrationVel_; + /// @brief integration method for velocity and position + word integrationMethod_; public: TypeInfo("dynamicPointStructure"); - dynamicPointStructure(Time& time, const word& integrationMethod); - - dynamicPointStructure(const dynamicPointStructure& ps) = default; + dynamicPointStructure(systemControl& control); + dynamicPointStructure(const dynamicPointStructure& ps) = delete; - // - no move construct + // - no move construct dynamicPointStructure(dynamicPointStructure&&) = delete; - // - copy assignment - // - // should be changed, may causs undefined behavior - ////////////////////////////////////////////////////////////// - dynamicPointStructure& operator=(const dynamicPointStructure&) = default; + /// + dynamicPointStructure& operator=(const dynamicPointStructure&) = delete; // - no move assignment dynamicPointStructure& operator=(dynamicPointStructure&&) = delete; // - destructor - virtual ~dynamicPointStructure() = default; + ~dynamicPointStructure() override = default; - inline pointStructure& pStruct() - { - return pStruct_; - } - - inline const pointStructure& pStruct() const - { - return pStruct_; - } - - inline const realx3PointField_D& velocity()const + inline + const realx3PointField_D& velocity()const { return velocity_; } - inline auto velocityHostAll() + inline + realx3PointField_D& velocity() + { + return velocity_; + } + + /*inline auto velocityHostAll() { return velocity_.hostVectorAll(); - } - - inline auto pointPositionHostAll() - { - return pStruct_.pointPositionHostAll(); - } - - auto markDeleteOutOfBox(const box& domain) - { - return pStruct_.markDeleteOutOfBox(domain); - } + }*/ bool predict(real dt, realx3PointField_D& acceleration); bool correct(real dt, realx3PointField_D& acceleration); - - // - update data structure by inserting/setting new points - // Notifies all the fields in the registered list of data structure - // and exclude the fields that re in the exclusionList - // retrun nullptr if it fails - /*FUNCTION_H - virtual uniquePtr insertPoints( - const realx3Vector& pos, - const List& exclusionList={nullptr} - )override;*/ - - bool update(const eventMessage& msg) override; - - }; } diff --git a/src/Particles/particles/particles.cpp b/src/Particles/particles/particles.cpp index d5c3bb45..23250718 100644 --- a/src/Particles/particles/particles.cpp +++ b/src/Particles/particles/particles.cpp @@ -24,135 +24,107 @@ Licence: pFlow::particles::particles ( - systemControl& control, - const word& integrationMethod + systemControl& control ) : - demParticles(control), - time_(control.time()), - integrationMethod_(integrationMethod), - /*dynPointStruct_( - time_.emplaceObject( - objectFile( - pointStructureFile__, - "", - objectFile::READ_ALWAYS, - objectFile::WRITE_ALWAYS - ), - control.time(), - integrationMethod - ) - ),*/ - dynPointStruct_( - control.time(), - integrationMethod), - shapeName_( - control.time().emplaceObject( - objectFile( - "shapeName", - "", - objectFile::READ_ALWAYS, - objectFile::WRITE_ALWAYS, - false - ), - pStruct(), - word("NO_NAME_SHAPE") - ) + observer(), + demComponent("particles", control), + dynPointStruct_(control), + id_ + ( + objectFile + ( + "id", + "", + objectFile::READ_IF_PRESENT, + objectFile::WRITE_ALWAYS ), - id_( - control.time().emplaceObject( - objectFile( - "id", - "", - objectFile::READ_IF_PRESENT, - objectFile::WRITE_ALWAYS - ), - pStruct(), - static_cast(-1) - ) + dynPointStruct_, + static_cast(-1) + ), + propertyId_ + ( + objectFile + ( + "propertyId", + "", + objectFile::READ_NEVER, + objectFile::WRITE_NEVER ), - propertyId_( - control.time().emplaceObject( - objectFile( - "propertyId", - "", - objectFile::READ_NEVER, - objectFile::WRITE_NEVER - ), - pStruct(), - static_cast(0) - ) + dynPointStruct_, + static_cast(0) + ), + diameter_ + ( + objectFile + ( + "diameter", + "", + objectFile::READ_NEVER, + objectFile::WRITE_ALWAYS ), - diameter_( - control.time().emplaceObject( - objectFile( - "diameter", - "", - objectFile::READ_NEVER, - objectFile::WRITE_ALWAYS - ), - pStruct(), - static_cast(0.00000000001) - ) + dynPointStruct_, + 0.00000000001 + ), + mass_ + ( + objectFile + ( + "mass", + "", + objectFile::READ_NEVER, + objectFile::WRITE_ALWAYS ), - mass_( - control.time().emplaceObject( - objectFile( - "mass", - "", - objectFile::READ_NEVER, - objectFile::WRITE_ALWAYS - ), - pStruct(), - static_cast(0.0000000001) - ) + dynPointStruct_, + 0.0000000001 + ), + accelertion_ + ( + objectFile + ( + "accelertion", + "", + objectFile::READ_IF_PRESENT, + objectFile::WRITE_ALWAYS + ), + dynPointStruct_, + zero3 + ), + contactForce_ + ( + objectFile + ( + "contactForce", + "", + objectFile::READ_IF_PRESENT, + objectFile::WRITE_ALWAYS ), - accelertion_( - control.time().emplaceObject( - objectFile( - "accelertion", - "", - objectFile::READ_IF_PRESENT, - objectFile::WRITE_ALWAYS - ), - pStruct(), - zero3 - ) + dynPointStruct_, + zero3 + ), + contactTorque_ + ( + + objectFile + ( + "contactTorque", + "", + objectFile::READ_IF_PRESENT, + objectFile::WRITE_ALWAYS ), - contactForce_( - control.time().emplaceObject( - objectFile( - "contactForce", - "", - objectFile::READ_IF_PRESENT, - objectFile::WRITE_ALWAYS - ), - pStruct(), - zero3 - ) - ), - contactTorque_( - control.time().emplaceObject( - objectFile( - "contactTorque", - "", - objectFile::READ_IF_PRESENT, - objectFile::WRITE_ALWAYS - ), - pStruct(), - zero3 - ) - ), - idHandler_(id_) + dynPointStruct_, + zero3 + ) { - this->subscribe(pStruct()); + WARNING<<"Subscribe particles"<subscribe(pStruct()); } bool pFlow::particles::beforeIteration() { - auto domain = this->control().domain(); + /*auto domain = this->control().domain(); auto numMarked = dynPointStruct_.markDeleteOutOfBox(domain); @@ -174,12 +146,12 @@ bool pFlow::particles::beforeIteration() } this->zeroForce(); - this->zeroTorque(); + this->zeroTorque();*/ return true; } -pFlow::uniquePtr> +/*pFlow::uniquePtr> pFlow::particles::getFieldObjectList()const { auto objListPtr = makeUnique>(); @@ -199,4 +171,4 @@ pFlow::particles::getFieldObjectList()const static_cast(&shapeName_) ); return objListPtr; -} +}*/ diff --git a/src/Particles/particles/particles.hpp b/src/Particles/particles/particles.hpp index 7b207c50..554c9a85 100644 --- a/src/Particles/particles/particles.hpp +++ b/src/Particles/particles/particles.hpp @@ -23,66 +23,75 @@ Licence: #define __particles_hpp__ #include "dynamicPointStructure.hpp" -#include "particleIdHandler.hpp" -#include "demParticles.hpp" +#include "demComponent.hpp" + namespace pFlow { -class setFieldList; class particles : - public eventObserver, - public demParticles + public observer, + public demComponent { -protected: +private: - // owner repository - Time& time_; - - const word integrationMethod_; - - // dynamic point structure for particles + /// dynamic point structure for particles center mass dynamicPointStructure dynPointStruct_; // - name of shapes - this is managed by particles - wordPointField& shapeName_; + //wordPointField& shapeName_; // id of particles on host - int32PointField_HD& id_; + int32PointField_D id_; // property id on device - int8PointField_D& propertyId_; + int8PointField_D propertyId_; // diameter / boundig sphere size of particles on device - realPointField_D& diameter_; + realPointField_D diameter_; - // mass on device - realPointField_D& mass_; + // mass of particles field + realPointField_D mass_; // - acceleration on device - realx3PointField_D& accelertion_; + realx3PointField_D accelertion_; + /// contact force field + realx3PointField_D contactForce_; - realx3PointField_D& contactForce_; - - - realx3PointField_D& contactTorque_; + /// contact torque field + realx3PointField_D contactTorque_; - // - object handling particle id - particleIdHandler idHandler_; - - virtual uniquePtr> getFieldObjectList()const; - + void zeroForce() { - contactForce_.fill(zero3); + WARNING<<"fill contactTorque"<("materials"); + materials_ = getVal("materials"); - densities_ = dict.getVal("densities"); + densities_ = getVal("densities"); if(materials_.size() != densities_.size() ) { fatalErrorInFunction<< " number of elements in material ("<(materials_.size()); return true; } pFlow::property::property ( + const word& name, const wordVector& materials, - const realVector& densities + const realVector& densities, + repository* owner ) : + fileDictionary + ( + objectFile + ( + name, + "", + objectFile::READ_NEVER, + objectFile::WRITE_NEVER + ), + owner + ), materials_(materials), densities_(densities) { + + if(!writeDictionary()) + { + fatalExit; + } + if(!makeNameIndex()) { fatalErrorInFunction<< - " error in the input parameters of constructor. \n"; + "error in the input parameters of constructor. \n"; fatalExit; } } pFlow::property::property ( -const fileSystem& file + const word& fileName, + repository* owner ) : - dict_ + fileDictionary ( - makeUnique - ("property", true) - ) -{ - iFstream dictStream(file); - - if(!dict_().read(dictStream)) - { - ioErrorInFile(dictStream.name(), dictStream.lineNumber()); - fatalExit; - } - - if(!readDictionary(dict_())) - { - fatalExit; - } - -} - -pFlow::property::property -( - const dictionary& dict -) -: - dict_ - ( - makeUnique(dict) + objectFile + ( + fileName, + "", + objectFile::READ_ALWAYS, + objectFile::WRITE_NEVER + ), + owner ) { - if(!readDictionary(dict_())) + if(!readDictionary()) { fatalExit; } + + if(!makeNameIndex()) + { + fatalErrorInFunction<< + "error in dictionary "<< globalName()< dict_ = nullptr; - /// list of name of materials wordVector materials_; @@ -62,10 +61,10 @@ protected: // - protected member functions /// read from dict - bool readDictionary(const dictionary& dict); + bool readDictionary(); /// write to dict - bool writeDictionary(dictionary& dict)const; + bool writeDictionary(); /// creates a mapp bool makeNameIndex(); @@ -73,22 +72,19 @@ protected: public: /// Type info - TypeInfoNV("property"); + TypeInfo("property"); - // - Constructors - /// Emptry constructor, used for reading from a file - property(){} - - /// Constructe from materials and densities - property(const wordVector& materials, const realVector& densities); - - /// Construct from file - property(const fileSystem& file); - - /// Construct from dictionary dict - property(const dictionary& dict); + explicit + property( + const word& fileName, + repository* owner=nullptr); + + property(const word& name, + const wordVector& materials, + const realVector& densities, + repository* owner=nullptr); /// Default copy property(const property& ) = default; @@ -103,17 +99,11 @@ public: property& operator= (property&&) = default; /// Default destructor - ~property() = default; + ~property() override = default; // - Methods - /// Return dictionary - inline const auto& dict()const - { - return dict_(); - } - /// Return number of materials inline auto numMaterials()const { @@ -190,20 +180,6 @@ public: } } - //// - IO operatoins - - /// Read from dictionary - bool read(const dictionary& dict) - { - return readDictionary(dict); - } - - /// Write to dictionary - bool write(dictionary& dict)const - { - return writeDictionary(dict); - } - }; } diff --git a/src/phasicFlow/CMakeLists.txt b/src/phasicFlow/CMakeLists.txt index 805a55d0..23ee3e13 100644 --- a/src/phasicFlow/CMakeLists.txt +++ b/src/phasicFlow/CMakeLists.txt @@ -34,18 +34,6 @@ dictionary/entry/iEntry.cpp dictionary/entry/dataEntry.cpp dictionary/twoPartEntry/twoPartEntry.cpp -containers/Vector/Vectors.cpp -containers/VectorHD/VectorSingles.cpp -containers/Field/Fields.cpp -containers/List/anyList/anyList.cpp -containers/pointField/pointFields.cpp - -#setFieldList/setFieldList.cpp -#setFieldList/setFieldEntry.cpp - -Timer/Timer.cpp -Timer/Timers.cpp - repository/IOobject/objectFile.cpp repository/IOobject/IOfileHeader.cpp repository/IOobject/IOobject.cpp @@ -62,6 +50,24 @@ eventManagement/observer.cpp demComponent/demComponent.cpp +containers/Vector/Vectors.cpp +containers/VectorHD/VectorSingles.cpp +containers/Field/Fields.cpp +containers/List/anyList/anyList.cpp +containers/pointField/pointFields.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 @@ -73,6 +79,7 @@ structuredData/pointStructure/internalPoints.cpp structuredData/pointStructure/pointStructure.cpp structuredData/boundaries/boundaryBase/boundaryBase.cpp structuredData/boundaries/boundaryExit/boundaryExit.cpp +structuredData/boundaries/boundaryNone/boundaryNone.cpp structuredData/pointStructure/boundaryList.cpp commandLine/commandLine.cpp diff --git a/src/phasicFlow/containers/Vector/Vector.hpp b/src/phasicFlow/containers/Vector/Vector.hpp index 32d2f115..f2511fd5 100644 --- a/src/phasicFlow/containers/Vector/Vector.hpp +++ b/src/phasicFlow/containers/Vector/Vector.hpp @@ -322,7 +322,7 @@ public: { return readStdVector(is, vectorField()); } - bool write(iOstream& os) + bool write(iOstream& os)const { return writeStdVector(os, vectorField()); } diff --git a/src/phasicFlow/containers/pointField/internalField.hpp b/src/phasicFlow/containers/pointField/internalField.hpp index 9783fdbc..30e08bc4 100644 --- a/src/phasicFlow/containers/pointField/internalField.hpp +++ b/src/phasicFlow/containers/pointField/internalField.hpp @@ -86,6 +86,21 @@ public: return field_.hostVector(); } + const FieldType& field()const + { + return field_; + } + + const pFlagTypeDevice& activePointsMaskDevice()const + { + return internalPoints_.activePointsMaskDevice(); + } + + const pFlagTypeHost& activePointsMaskHost()const + { + return internalPoints_.activePointsMaskHost(); + } + FieldTypeHost activeValuesHost()const; inline diff --git a/src/phasicFlow/containers/pointField/pointField.cpp b/src/phasicFlow/containers/pointField/pointField.cpp index 28bc8c73..edc42ce1 100644 --- a/src/phasicFlow/containers/pointField/pointField.cpp +++ b/src/phasicFlow/containers/pointField/pointField.cpp @@ -41,9 +41,32 @@ pFlow::pointField::pointField boundaryFieldList_(pStruct.boundaries(), *this), pStruct_(pStruct), defaultValue_(defVal) -{ - -} +{} + +template +pFlow::pointField::pointField +( + const objectFile& objf, + repository* owner, + pointStructure& pStruct, + const T& defVal +) +: + IOobject + ( + objf, + pStruct.ioPattern(), + owner + ), + InternalFieldType + ( + objf.name(), + pStruct + ), + boundaryFieldList_(pStruct.boundaries(), *this), + pStruct_(pStruct), + defaultValue_(defVal) +{} template pFlow::pointField::pointField diff --git a/src/phasicFlow/containers/pointField/pointField.hpp b/src/phasicFlow/containers/pointField/pointField.hpp index 5ebb015d..ffc315c5 100644 --- a/src/phasicFlow/containers/pointField/pointField.hpp +++ b/src/phasicFlow/containers/pointField/pointField.hpp @@ -81,6 +81,12 @@ public: pointStructure& pStruct, const T& defVal); + pointField( + const objectFile& objf, + repository* owner, + pointStructure& pStruct, + const T& defVal); + pointField( const objectFile& objf, pointStructure& pStruct, diff --git a/src/phasicFlow/containers/pointField/pointFields.hpp b/src/phasicFlow/containers/pointField/pointFields.hpp index 2dc5242a..d3435812 100644 --- a/src/phasicFlow/containers/pointField/pointFields.hpp +++ b/src/phasicFlow/containers/pointField/pointFields.hpp @@ -36,57 +36,39 @@ template using pointField_D = pointField; -using int8PointField_D = pointField; +using int8PointField_D = pointField_D; +using int8PointField_H = pointField_H; -using int8PointField_H = pointField; +using uint8PointField_D = pointField_D; +using uint8PointField_H = pointField_H; -using realPointField_D = pointField; +using int32PointField_D = pointField_D; +using int32PointField_H = pointField_H; -using realPointField_H = pointField; +using uint32PointField_D = pointField_D; +using uint32PointField_H = pointField_H; -//using int32PointField_D = pointField; +using int64PointField_D = pointField_D; +using int63PointField_H = pointField_H; -/*using int32PointField_H = pointField; +using uint64PointField_D = pointField_D; +using uint64PointField_H = pointField_H; -using int64PointField_D = pointField; +using int32PointField_D = pointField_D; +using int32PointField_H = pointField_H; -using int64PointField_H = pointField; +using realPointField_D = pointField_D; +using realPointField_H = pointField_H; -using uint32PointField_D = pointField; +using realx3PointField_D = pointField_D; +using realx3PointField_H = pointField_H; -using uint32PointField_H = pointField; +using realx4PointField_D = pointField_D; +using realx4PointField_H = pointField_H; -using labelPointField_D = pointField; -using labelPointField_H = pointField; -using realPointField_D = pointField; -using realPointField_H = pointField; - -using realx3PointField_D = pointField ; - -using realx3PointField_H = pointField; - -using wordPointField_H = pointField; - -using int8PointField_HD = pointField; - -using int16PointField_HD = pointField; - -using int32PointField_HD = pointField; - -using int64PointField_HD = pointField; - -using uint32PointField_HD = pointField; - -using labelPointField_HD = pointField; - -using realPointField_HD = pointField; - -using realx3PointField_HD = pointField; - -using wordPointField = pointField>;*/ } diff --git a/src/phasicFlow/dictionary/fileDictionary.cpp b/src/phasicFlow/dictionary/fileDictionary.cpp index 14012165..62bd3b2d 100644 --- a/src/phasicFlow/dictionary/fileDictionary.cpp +++ b/src/phasicFlow/dictionary/fileDictionary.cpp @@ -10,7 +10,7 @@ pFlow::fileDictionary::fileDictionary IOobject ( of, - IOPattern::IOPattern::AllProcessorsSimilar, + IOPattern::AllProcessorsSimilar, owner ), dictionary diff --git a/src/phasicFlow/repository/IOobject/IOPattern.hpp b/src/phasicFlow/repository/IOobject/IOPattern.hpp index 9f8f3124..9bd46e09 100644 --- a/src/phasicFlow/repository/IOobject/IOPattern.hpp +++ b/src/phasicFlow/repository/IOobject/IOPattern.hpp @@ -58,7 +58,7 @@ public: // standard input and output streams }; -protected: +private: IOType ioType_; @@ -72,12 +72,16 @@ protected: public: - IOPattern( IOType iotype); + IOPattern( IOPattern::IOType iotype); IOPattern(const IOPattern&)=default; + IOPattern(IOPattern&&) = default; + IOPattern& operator=(const IOPattern&)=default; + IOPattern& operator=(IOPattern&&)=default; + ~IOPattern() = default; inline @@ -123,6 +127,13 @@ public: return true; } + inline + bool thisCallWrite()const + { + if(isMasterProcessorOnly()&& !isMaster())return false; + return true; + } + inline bool thisProcReadData()const { diff --git a/src/phasicFlow/repository/IOobject/IOfileHeader.cpp b/src/phasicFlow/repository/IOobject/IOfileHeader.cpp index 15fda4fb..440a1ab6 100644 --- a/src/phasicFlow/repository/IOobject/IOfileHeader.cpp +++ b/src/phasicFlow/repository/IOobject/IOfileHeader.cpp @@ -36,7 +36,7 @@ pFlow::uniquePtr pFlow::IOfileHeader::outStream()const if(osPtr && owner()) { auto outPrecision = owner()->outFilePrecision(); - osPtr->precision(outPrecision); + osPtr->precision(static_cast(outPrecision)); } return osPtr; @@ -62,7 +62,7 @@ pFlow::fileSystem pFlow::IOfileHeader::path() const { f = localPath(); } - f += name_; + f += name(); return f; } @@ -146,11 +146,8 @@ bool pFlow::IOfileHeader::writeHeader ) const { - if(!forceWrite) - { - if(!writeHeader()) return true; - } - + if(!forceWrite && !writeHeader()) return true; + writeBanner(os); os.writeWordEntry("objectType", typeName ); diff --git a/src/phasicFlow/repository/IOobject/IOobject.cpp b/src/phasicFlow/repository/IOobject/IOobject.cpp index 39e3090c..2cd77a9f 100644 --- a/src/phasicFlow/repository/IOobject/IOobject.cpp +++ b/src/phasicFlow/repository/IOobject/IOobject.cpp @@ -64,60 +64,56 @@ pFlow::repository* pFlow::IOobject::releaseOwner bool pFlow::IOobject::readObject(bool rdHdr) { - - if( implyRead() ) - { - if( rdHdr & ioPattern().thisCallRead()) - { - if( auto ptrIS = inStream(); ptrIS ) - { - if(!readHeader(ptrIS()))return false; - } - else - { - warningInFunction<< - "could not open file " << path() <writeHeader() && ioPattern().thisProcWriteHeader()) writeHeader(os, typeName()); - if(ioPattern().thisProcWriteData()) - { //return (object_->write_object_t(os, ioPattern_) && writeSeparator(os)); - notImplementedFunction; - //return object_->read_object_t(is, ioPattern_); - return false; + if(ioPattern().thisCallWrite()) + { + return write(os, ioPattern() ); } else return true; diff --git a/src/phasicFlow/repository/IOobject/IOobject.hpp b/src/phasicFlow/repository/IOobject/IOobject.hpp index 952498c5..f2eaaba7 100644 --- a/src/phasicFlow/repository/IOobject/IOobject.hpp +++ b/src/phasicFlow/repository/IOobject/IOobject.hpp @@ -36,7 +36,7 @@ class IOobject : public IOfileHeader { -protected: +private: IOPattern ioPattern_; @@ -57,7 +57,7 @@ public: const IOPattern& iop, repository* owner); - ~IOobject(); + ~IOobject() override; // - copy construct IOobject(const IOobject& src)=delete; diff --git a/src/phasicFlow/repository/IOobject/objectFile.hpp b/src/phasicFlow/repository/IOobject/objectFile.hpp index 8bb5cb5f..dfe93fd2 100644 --- a/src/phasicFlow/repository/IOobject/objectFile.hpp +++ b/src/phasicFlow/repository/IOobject/objectFile.hpp @@ -45,16 +45,16 @@ public: }; -protected: +private: /// Name of the entity word name_; /// Read flag - readFlag rFlag_ = READ_NEVER; + readFlag rFlag_ = readFlag::READ_NEVER; /// Write flag - writeFlag wFlag_ = WRITE_NEVER; + writeFlag wFlag_ = writeFlag::WRITE_NEVER; /// Local path of entity fileSystem localPath_ = ""; @@ -70,7 +70,7 @@ public: // constructors - objectFile + explicit objectFile ( const word& name ); @@ -80,8 +80,8 @@ public: ( const word& name, const fileSystem& localPath, - const readFlag& rf = READ_NEVER, - const writeFlag& wf = WRITE_NEVER, + const readFlag& rf = readFlag::READ_NEVER, + const writeFlag& wf = writeFlag::WRITE_NEVER, bool rwHeader = true ); @@ -122,31 +122,31 @@ public: inline bool isReadAlways()const { - return rFlag_ == READ_ALWAYS; + return rFlag_ == readFlag::READ_ALWAYS; } inline bool isReadNever()const { - return rFlag_ == READ_NEVER; + return rFlag_ == readFlag::READ_NEVER; } inline bool isReadIfPresent()const { - return rFlag_ == READ_IF_PRESENT; + return rFlag_ == readFlag::READ_IF_PRESENT; } inline bool isWriteAlways()const { - return wFlag_ == WRITE_ALWAYS; + return wFlag_ == writeFlag::WRITE_ALWAYS; } inline bool isWriteNever()const { - return wFlag_ == WRITE_NEVER; + return wFlag_ == writeFlag::WRITE_NEVER; } inline diff --git a/src/phasicFlow/repository/Time/Time.cpp b/src/phasicFlow/repository/Time/Time.cpp index 693dcd85..234dcfd0 100644 --- a/src/phasicFlow/repository/Time/Time.cpp +++ b/src/phasicFlow/repository/Time/Time.cpp @@ -55,12 +55,6 @@ pFlow::Time::Time geometryRepository_, geometryFolder__, this - ), - integration_ - ( - integrationRepository__, - integrationFolder__, - this ) { @@ -90,12 +84,6 @@ pFlow::Time::Time( geometryRepository_, geometryFolder__, this - ), - integration_ - ( - integrationRepository__, - integrationFolder__, - this ) { if(!readDictionary(setiingsDict)) @@ -109,6 +97,11 @@ pFlow::fileSystem pFlow::Time::localPath()const return fileSystem(timeName()); } +pFlow::fileSystem pFlow::Time::integrationFolder() const +{ + return integrationFolder__; +} + bool pFlow::Time::write ( bool verbose diff --git a/src/phasicFlow/repository/Time/Time.hpp b/src/phasicFlow/repository/Time/Time.hpp index 7bdf7091..6cafa87b 100644 --- a/src/phasicFlow/repository/Time/Time.hpp +++ b/src/phasicFlow/repository/Time/Time.hpp @@ -28,7 +28,7 @@ Licence: #include "timeControl.hpp" #include "repository.hpp" - +#include "fileSystem.hpp" namespace pFlow @@ -49,10 +49,6 @@ protected: // - geometry folder/repository repository geometry_; - // - integration folder/repository - repository integration_; - - bool readDictionary(const dictionary& dict); public: @@ -84,15 +80,7 @@ public: return geometry_; } - const repository& integration()const - { - return integration_; - } - - repository& integration() - { - return integration_; - } + fileSystem integrationFolder()const; /// Write to the file with binary format? bool outFileBinary()const override diff --git a/src/phasicFlow/smartPointers/uniquePtr.hpp b/src/phasicFlow/smartPointers/uniquePtr.hpp index 373a043b..c1363cde 100644 --- a/src/phasicFlow/smartPointers/uniquePtr.hpp +++ b/src/phasicFlow/smartPointers/uniquePtr.hpp @@ -18,7 +18,6 @@ Licence: -----------------------------------------------------------------------------*/ - #ifndef __uniquePtr_hpp__ #define __uniquePtr_hpp__ @@ -47,7 +46,7 @@ class uniquePtr { public: - typedef std::unique_ptr uniquePtrType; + using uniquePtrType = std::unique_ptr; // using base constructors using uniquePtrType::unique_ptr; diff --git a/src/phasicFlow/structuredData/boundaries/boundaryNone/boundaryNone.cpp b/src/phasicFlow/structuredData/boundaries/boundaryNone/boundaryNone.cpp new file mode 100644 index 00000000..e3362956 --- /dev/null +++ b/src/phasicFlow/structuredData/boundaries/boundaryNone/boundaryNone.cpp @@ -0,0 +1,58 @@ +/*------------------------------- phasicFlow --------------------------------- + O C enter of + O O E ngineering and + O O M ultiscale modeling of + OOOOOOO F luid flow +------------------------------------------------------------------------------ + Copyright (C): www.cemf.ir + email: hamid.r.norouzi AT gmail.com +------------------------------------------------------------------------------ +Licence: + This file is part of phasicFlow code. It is a free software for simulating + granular and multiphase flows. You can redistribute it and/or modify it under + the terms of GNU General Public License v3 or any other later versions. + + phasicFlow is distributed to help others in their research in the field of + granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +-----------------------------------------------------------------------------*/ + +#include "boundaryNone.hpp" + +pFlow::boundaryNone::boundaryNone +( + const dictionary& dict, + const plane& bplane, + internalPoints& internal +) +: + boundaryBase(dict, bplane, internal) +{} + +bool pFlow::boundaryNone::beforeIteratoin +( + uint32 iterNum, + real t +) +{ + return true; +} + +bool pFlow::boundaryNone::iterate +( + uint32 iterNum, + real t +) +{ + return true; +} + +bool pFlow::boundaryNone::afterIteration +( + uint32 iterNum, + real t +) +{ + return true; +} \ No newline at end of file diff --git a/src/phasicFlow/structuredData/boundaries/boundaryNone/boundaryNone.hpp b/src/phasicFlow/structuredData/boundaries/boundaryNone/boundaryNone.hpp new file mode 100644 index 00000000..da93977e --- /dev/null +++ b/src/phasicFlow/structuredData/boundaries/boundaryNone/boundaryNone.hpp @@ -0,0 +1,64 @@ +/*------------------------------- 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 __boundaryNone_hpp__ +#define __boundaryNone_hpp__ + + +#include "boundaryBase.hpp" + +namespace pFlow +{ + +class boundaryNone +: + public boundaryBase +{ + +public: + + TypeInfo("boundary"); + + boundaryNone( + const dictionary& dict, + const plane& bplane, + internalPoints& internal); + + ~boundaryNone() override= default; + + add_vCtor + ( + boundaryBase, + boundaryNone, + dictionary + ); + + bool beforeIteratoin(uint32 iterNum, real t) override; + + bool iterate(uint32 iterNum, real t) override; + + bool afterIteration(uint32 iterNum, real t) override; + + +}; + +} + +#endif \ No newline at end of file diff --git a/src/phasicFlow/structuredData/domain/regularSimulationDomain.hpp b/src/phasicFlow/structuredData/domain/regularSimulationDomain.hpp index 86fdf02e..7eeb888a 100644 --- a/src/phasicFlow/structuredData/domain/regularSimulationDomain.hpp +++ b/src/phasicFlow/structuredData/domain/regularSimulationDomain.hpp @@ -39,6 +39,11 @@ public: uint32 initialNumberInThis()const override; + bool initialThisDomainActive()const override + { + return true; + } + /*bool updateDomains( span pointPos, pFlagTypeHost flags) override;*/ diff --git a/src/phasicFlow/structuredData/domain/simulationDomain.hpp b/src/phasicFlow/structuredData/domain/simulationDomain.hpp index 205f1c75..35718798 100644 --- a/src/phasicFlow/structuredData/domain/simulationDomain.hpp +++ b/src/phasicFlow/structuredData/domain/simulationDomain.hpp @@ -97,6 +97,9 @@ public: virtual uint32 initialNumberInThis()const = 0; + virtual + bool initialThisDomainActive()const = 0; + virtual bool initialTransferBlockData( span src, diff --git a/src/phasicFlow/structuredData/pointStructure/pointFlag.hpp b/src/phasicFlow/structuredData/pointStructure/pointFlag.hpp index cbf1f539..83dbcec9 100644 --- a/src/phasicFlow/structuredData/pointStructure/pointFlag.hpp +++ b/src/phasicFlow/structuredData/pointStructure/pointFlag.hpp @@ -172,7 +172,7 @@ public: INLINE_FUNCTION_HD - bool operator()(uint32 i) + bool operator()(uint32 i)const { return isActive(i); } diff --git a/utilities/Utilities/readFromTimeFolder.hpp b/utilities/Utilities/readFromTimeFolder.hpp index 75559780..a0d3b93d 100644 --- a/utilities/Utilities/readFromTimeFolder.hpp +++ b/utilities/Utilities/readFromTimeFolder.hpp @@ -42,7 +42,7 @@ protected: public: - readFromTimeFolder(repository& rep); + explicit readFromTimeFolder(repository& rep); auto path()const { @@ -65,9 +65,9 @@ public: bool pointFieldGetType(word& typeName)const { word fieldTYPENAME = pointField_H::TYPENAME(); - word fldType{}, space{}; + word fldType{}; - if( !pFlow::utilities::pointFieldGetType( + if(word space{}; !pFlow::utilities::pointFieldGetType( fieldTYPENAME, fldType, space) ) { fatalErrorInFunction<< @@ -81,18 +81,19 @@ public: } template - bool pointFieldGetCheckType(word fieldName, word& typeName) const + bool pointFieldGetCheckType(word const& fieldName, word& typeName) const { word fieldTYPENAME = pointField_H::TYPENAME(); - word flType{},fldType{}; - + + word flType{}; if(!pointFieldFileGetType( fieldName, flType)) { fatalExit; return false; } - + + word fldType{}; if( !pointFieldGetType(fldType) ) { fatalExit; @@ -112,7 +113,7 @@ public: } template - pointField_H& createUniformPointField_H(word name, T value) + uniquePtr> createUniformPointField_H(word const& name, T value) { if( !checkForPointStructure() ) { @@ -120,29 +121,28 @@ public: "cannot find " << pointStructureFile__ << " in repository "<< repository_.name()<(pointStructureFile__); - word fType; - pointFieldGetType(fType); - word newName = name + fType; - auto& field = repository_.emplaceReplaceObject>( - objectFile( + auto Ptr = makeUnique> + ( + objectFile + ( name, "", objectFile::READ_NEVER, objectFile::WRITE_NEVER - ), + ), pStruct, + T{}, value - ); - - return field; - + ); + return Ptr; } template - pointField_H& readPointField_H(word name) + uniquePtr> readPointField_H(word const& name) { if( !checkForPointStructure() ) { @@ -152,23 +152,25 @@ public: } auto& pStruct = repository_.lookupObject(pointStructureFile__); - auto& field = repository_.emplaceObjectOrGet>( - objectFile( + auto Ptr = makeUnique> + ( + objectFile + ( name, "", objectFile::READ_IF_PRESENT, objectFile::WRITE_ALWAYS - ), + ), pStruct, T{} - ); + ); - return field; + return Ptr; } template - pointField_D& readPointField_D(word name) + uniquePtr> readPointField_D(word const& name) { if( !checkForPointStructure() ) { @@ -178,18 +180,20 @@ public: } auto& pStruct = repository_.lookupObject(pointStructureFile__); - auto& field = repository_.emplaceObjectOrGet>( - objectFile( + auto Ptr = makeUnique> + ( + objectFile + ( name, "", objectFile::READ_IF_PRESENT, objectFile::WRITE_ALWAYS - ), + ), pStruct, T{} - ); + ); - return field; + return Ptr; } }; diff --git a/utilities/particlesPhasicFlow/particlesPhasicFlow.cpp b/utilities/particlesPhasicFlow/particlesPhasicFlow.cpp index 8d568a52..1e3351b5 100755 --- a/utilities/particlesPhasicFlow/particlesPhasicFlow.cpp +++ b/utilities/particlesPhasicFlow/particlesPhasicFlow.cpp @@ -72,21 +72,10 @@ int main( int argc, char* argv[] ) // this should be palced in each main #include "initialize_Control.hpp" - auto objCPDict = IOobject::make - ( - objectFile - ( - "particlesDict", - Control.settings().path(), - objectFile::READ_ALWAYS, - objectFile::WRITE_ALWAYS - ), - "particlesDict" - ); + fileDictionary cpDict("particlesDict", Control.settings().path()); + - auto& cpDict = objCPDict().getObject(); - - pointStructure* pStructPtr = nullptr; + uniquePtr pStructPtr = nullptr; if(!setOnly) @@ -100,24 +89,11 @@ int main( int argc, char* argv[] ) auto finalPos = pointPosition().getFinalPosition(); - - auto& pStruct = Control.time().emplaceObject - ( - objectFile - ( - pointStructureFile__, - Control.time().path(), - objectFile::READ_NEVER, - objectFile::WRITE_ALWAYS - ), - Control, - finalPos - ); + pStructPtr = makeUnique(Control, finalPos); - pStructPtr = &pStruct; - REPORT(1)<< "Created pStruct with "<< pStruct.size() << " points and capacity "<< - pStruct.capacity()<<" . . ."<< END_REPORT; + REPORT(1)<< "Created pStruct with "<< pStructPtr().size() << " points and capacity "<< + pStructPtr().capacity()<<" . . ."<< END_REPORT; //REPORT(1)<< "Writing pStruct to " << Control.time().path()+ pointStructureFile__<< END_REPORT< - ( - objectFile - ( - pointStructureFile__, - Control.time().path(), - objectFile::READ_NEVER, - objectFile::WRITE_ALWAYS - ), - Control - ); - - pStructPtr = &pStruct; + // read the content of pStruct from 0/pStructure + pStructPtr = makeUnique(Control); } diff --git a/utilities/particlesPhasicFlow/positionParticles/positionParticles.cpp b/utilities/particlesPhasicFlow/positionParticles/positionParticles.cpp index 7ad046f6..a7d3879a 100755 --- a/utilities/particlesPhasicFlow/positionParticles/positionParticles.cpp +++ b/utilities/particlesPhasicFlow/positionParticles/positionParticles.cpp @@ -19,6 +19,7 @@ Licence: -----------------------------------------------------------------------------*/ #include "positionParticles.hpp" +#include "vocabs.hpp" #include "box.hpp" #include "cylinder.hpp" #include "sphere.hpp" @@ -101,7 +102,18 @@ pFlow::positionParticles::positionParticles } else { - region_ = makeUnique>( control.domainDict().subDict("globalBox")); + fileDictionary domainDict + ( + objectFile + { + domainFile__, + "", + objectFile::READ_ALWAYS, + objectFile::WRITE_NEVER + }, + &control.settings() + ); + region_ = makeUnique>( domainDict.subDict("globalBox")); } } From 20be76aed0511b9bd32d774b0f7244558be1d825 Mon Sep 17 00:00:00 2001 From: Hamidreza Norouzi Date: Thu, 25 Jan 2024 03:07:59 -0800 Subject: [PATCH 02/57] Particle base class and sphereParticle class have been updated --- src/Particles/CMakeLists.txt | 6 +- .../sphereParticles/sphereParticles.cpp | 271 ++++++++++------ .../sphereParticles/sphereParticles.hpp | 106 +++---- .../sphereShape/sphereShape.cpp | 293 +++++++++--------- .../sphereShape/sphereShape.hpp | 146 +++------ src/Particles/particles/baseShapeNames.cpp | 114 +++++++ src/Particles/particles/baseShapeNames.hpp | 128 ++++++++ src/Particles/particles/particles.cpp | 185 ++++++----- src/Particles/particles/particles.hpp | 66 ++-- src/Particles/particles/shape.cpp | 76 +++++ src/Particles/particles/shape.hpp | 183 +++++++++++ 11 files changed, 1051 insertions(+), 523 deletions(-) create mode 100644 src/Particles/particles/baseShapeNames.cpp create mode 100644 src/Particles/particles/baseShapeNames.hpp create mode 100644 src/Particles/particles/shape.cpp create mode 100644 src/Particles/particles/shape.hpp diff --git a/src/Particles/CMakeLists.txt b/src/Particles/CMakeLists.txt index 42ac0ea8..1b01ef94 100644 --- a/src/Particles/CMakeLists.txt +++ b/src/Particles/CMakeLists.txt @@ -1,10 +1,12 @@ set(SourceFiles dynamicPointStructure/dynamicPointStructure.cpp +particles/baseShapeNames.cpp +particles/shape.cpp particles/particles.cpp #particles/particleIdHandler.cpp -#SphereParticles/sphereShape/sphereShape.cpp -#SphereParticles/sphereParticles/sphereParticles.cpp +SphereParticles/sphereShape/sphereShape.cpp +SphereParticles/sphereParticles/sphereParticles.cpp #Insertion/shapeMixture/shapeMixture.cpp #Insertion/insertion/insertion.cpp #Insertion/Insertion/Insertions.cpp diff --git a/src/Particles/SphereParticles/sphereParticles/sphereParticles.cpp b/src/Particles/SphereParticles/sphereParticles/sphereParticles.cpp index f1d71012..04f4f19c 100644 --- a/src/Particles/SphereParticles/sphereParticles/sphereParticles.cpp +++ b/src/Particles/SphereParticles/sphereParticles/sphereParticles.cpp @@ -19,10 +19,12 @@ Licence: -----------------------------------------------------------------------------*/ #include "sphereParticles.hpp" -#include "setFieldList.hpp" -#include "sphereParticlesKernels.hpp" +#include "systemControl.hpp" +#include "vocabs.hpp" +//#include "setFieldList.hpp" +//#include "sphereParticlesKernels.hpp" -pFlow::uniquePtr> +/*pFlow::uniquePtr> pFlow::sphereParticles::getFieldObjectList()const { auto objListPtr = particles::getFieldObjectList(); @@ -78,10 +80,10 @@ bool pFlow::sphereParticles::initializeParticles() static_cast(shapeName_.size())); return insertSphereParticles(shapeName_, indices, false); -} +}*/ -bool pFlow::sphereParticles::beforeIteration() +/*bool pFlow::sphereParticles::beforeIteration() { particles::beforeIteration(); @@ -98,45 +100,19 @@ bool pFlow::sphereParticles::beforeIteration() intPredictTimer_.end(); return true; -} +}*/ -bool pFlow::sphereParticles::iterate() -{ - - accelerationTimer_.start(); - //INFO<<"before accelerationTimer_ "<dt(), accelertion_); - - rVelIntegration_().correct(this->dt(), rVelocity_, rAcceleration_); - - intCorrectTimer_.end(); - - return true; -} -bool pFlow::sphereParticles::afterIteration() + +/*bool pFlow::sphereParticles::afterIteration() { return true; -} +}*/ -bool pFlow::sphereParticles::insertSphereParticles( +/*bool pFlow::sphereParticles::insertSphereParticles( const wordVector& names, const int32IndexContainer& indices, bool setId @@ -219,6 +195,39 @@ bool pFlow::sphereParticles::insertSphereParticles( return true; +}*/ + +bool pFlow::sphereParticles::initInertia() +{ + + using exeSpace = typename realPointField_D::execution_space; + using policy = Kokkos::RangePolicy< + exeSpace, + Kokkos::IndexType>; + + auto aPointsMask = dynPointStruct().activePointsMaskDevice(); + auto aRange = aPointsMask.activeRange(); + + auto field_I = I_.fieldDevice(); + auto field_shapeIndex = shapeIndex().fieldDevice(); + + const auto& shp = getShapes(); + realVector_D I ("I", shp.Inertia()); + auto d_I = I.deviceVector(); + + Kokkos::parallel_for( + "particles::initInertia", + policy(aRange.start(), aRange.end()), + LAMBDA_HD(uint32 i) + { + if(aPointsMask(i)) + { + uint32 index = field_shapeIndex[i]; + field_I[i] = d_I[index]; + } + }); + Kokkos::fence(); + return true; } @@ -227,78 +236,67 @@ pFlow::sphereParticles::sphereParticles( const property& prop ) : - particles( - control, - control.settingsDict().getValOrSet( - "integrationMethod", - word("AdamsBashforth3") - ) + particles(control), + spheres_ + ( + shapeFile__, + &control.caseSetup(), + prop + ), + I_ + ( + objectFile + ( + "I", + "", + objectFile::READ_NEVER, + objectFile::WRITE_NEVER ), - property_(prop), - shapes_( - control.caseSetup().emplaceObjectOrGet( - objectFile( - sphereShapeFile__, - "", - objectFile::READ_ALWAYS, - objectFile::WRITE_NEVER - ) - ) - ), - I_( - this->time().emplaceObject( - objectFile( - "I", - "", - objectFile::READ_NEVER, - objectFile::WRITE_ALWAYS - ), - pStruct(), - static_cast(0.0000000001) - ) - ), - rVelocity_( - this->time().emplaceObject( - objectFile( - "rVelocity", - "", - objectFile::READ_IF_PRESENT, - objectFile::WRITE_ALWAYS - ), - pStruct(), - zero3 - ) - ), - rAcceleration_( - this->time().emplaceObject( - objectFile( - "rAcceleration", - "", - objectFile::READ_IF_PRESENT, - objectFile::WRITE_ALWAYS - ), - pStruct(), - zero3 - ) + dynPointStruct(), + static_cast(0.0000000001) + ), + rVelocity_ + ( + objectFile + ( + "rVelocity", + "", + objectFile::READ_IF_PRESENT, + objectFile::WRITE_ALWAYS ), + dynPointStruct(), + zero3 + ), + rAcceleration_ + ( + objectFile( + "rAcceleration", + "", + objectFile::READ_IF_PRESENT, + objectFile::WRITE_ALWAYS + ), + dynPointStruct(), + zero3 + ), accelerationTimer_( "Acceleration", &this->timers() ), intPredictTimer_( "Integration-predict", &this->timers() ), intCorrectTimer_( "Integration-correct", &this->timers() ) - { - REPORT(1)<<"Creating integration method "<integrationMethod()) - << " for rotational velocity."<("integrationMethod"); + REPORT(1)<<"Creating integration method "<time().integration(), - this->pStruct(), - this->integrationMethod()); + dynPointStruct(), + intMethod, + rVelocity_.field() + ); if( !rVelIntegration_ ) { @@ -307,7 +305,8 @@ pFlow::sphereParticles::sphereParticles( fatalExit; } - if(rVelIntegration_->needSetInitialVals()) + WARNING<<"setFields for rVelIntegration_"<needSetInitialVals()) { auto [minInd, maxInd] = pStruct().activeRange(); @@ -327,17 +326,17 @@ pFlow::sphereParticles::sphereParticles( REPORT(2)<< "Initializing the required vectors for rotational velocity integratoin\n "<setInitialVals(indexHD, rvel); - } + }*/ - if(!initializeParticles()) + if(!initInertia()) { fatalExit; } } -bool pFlow::sphereParticles::update(const eventMessage& msg) +/*bool pFlow::sphereParticles::update(const eventMessage& msg) { if(rVelIntegration_->needSetInitialVals()) @@ -362,9 +361,9 @@ bool pFlow::sphereParticles::update(const eventMessage& msg) } return true; -} +}*/ -bool pFlow::sphereParticles::insertParticles +/*bool pFlow::sphereParticles::insertParticles ( const realx3Vector& position, const wordVector& shapes, @@ -419,4 +418,70 @@ bool pFlow::sphereParticles::insertParticles return true; -} \ No newline at end of file +}*/ + +bool pFlow::sphereParticles::beforeIteration() +{ + particles::beforeIteration(); + intPredictTimer_.start(); + dynPointStruct().predict(dt(), accelertion()); + rVelIntegration_().predict(dt(),rVelocity_, rAcceleration_); + intPredictTimer_.end(); + + WARNING<<"pFlow::sphereParticles::beforeIteration()"< rVelIntegration_ = nullptr; @@ -73,9 +72,9 @@ protected: /// timer for integration computations (correction step) Timer intCorrectTimer_; - bool diameterMassInertiaPropId(const word& shName, real& diam, real& mass, real& I, int8& propIdx); + bool initInertia(); - bool initializeParticles(); + /*bool initializeParticles(); bool insertSphereParticles( const wordVector& names, @@ -83,25 +82,17 @@ protected: bool setId = true); virtual uniquePtr> getFieldObjectList()const override; + */ public: /// construct from systemControl and property - sphereParticles(systemControl &control, const property& prop); + sphereParticles( + systemControl &control, + const property& prop); - /// no copy constructor - sphereParticles(const sphereParticles&) = delete; - /// move constructor - sphereParticles(sphereParticles&&) = default; - - /// no copy-assignement - sphereParticles& operator=(const sphereParticles&) = delete; - - /// move-assignement - sphereParticles& operator=(sphereParticles&&) = default; - - virtual ~sphereParticles()=default; + ~sphereParticles()override=default; /** * Insert new particles in position with specified shapes @@ -112,17 +103,17 @@ public: * \param shape shape of new particles * \param setField initial value of the selected fields for new particles */ - bool insertParticles + /*bool insertParticles ( const realx3Vector& position, const wordVector& shapes, const setFieldList& setField - ) override ; + ) override ;*/ /// const reference to shapes object - const auto& shapes()const + const auto& spheres()const { - return shapes_; + return spheres_; } /// const reference to inertia pointField @@ -137,41 +128,29 @@ public: return I_; } - const realx3Vector_D rVelocity()const + const auto& rVelocity()const { return rVelocity_; } - const realVector_D& boundingSphere()const override - { - return this->diameter(); + auto& rVelocity() + { + return rVelocity_; } - word shapeTypeName() const override + bool hearChanges + ( + real t, + real dt, + uint32 iter, + const message& msg, + const anyList& varList + ) override { - return "sphere"; - } - - void boundingSphereMinMax( - real& minDiam, - real& maxDiam )const override - { - shapes_.diameterMinMax(minDiam, maxDiam); - } - - bool update(const eventMessage& msg) override; - - - realx3PointField_D& rAcceleration() override - { - return rAcceleration_; + notImplementedFunction; + return false; } - const realx3PointField_D& rAcceleration() const override - { - return rAcceleration_; - } - /// before iteration step bool beforeIteration() override; @@ -180,8 +159,25 @@ public: /// after iteration step bool afterIteration() override; - + realx3PointField_D& rAcceleration() override + { + return rAcceleration_; + } + + const realx3PointField_D& rAcceleration() const override + { + return rAcceleration_; + } + + const realPointField_D& boundingSphere()const override + { + return diameter(); + } + + word shapeTypeName()const override; + + const shape& getShapes()const override; }; //sphereParticles diff --git a/src/Particles/SphereParticles/sphereShape/sphereShape.cpp b/src/Particles/SphereParticles/sphereShape/sphereShape.cpp index 7723f039..f07942ce 100644 --- a/src/Particles/SphereParticles/sphereShape/sphereShape.cpp +++ b/src/Particles/SphereParticles/sphereShape/sphereShape.cpp @@ -19,186 +19,177 @@ Licence: -----------------------------------------------------------------------------*/ #include "sphereShape.hpp" -#include "dictionary.hpp" -#include "vocabs.hpp" -#include "streams.hpp" -bool pFlow::sphereShape::insertNames -( - const wordVector& names -) +bool pFlow::sphereShape::readDictionary() { - names_.clear(); - uint32 i=0; - for(const auto& nm:names) - { - if(!names_.insertIf(nm, i)) - { - fatalErrorInFunction<< - " repeated name in the list of sphere names: " << names; - return false; - } - i++; - } - names_.rehash(0); - numShapes_ = names_.size(); - - return true; -} + diameters_ = getVal("diameters"); - -bool pFlow::sphereShape::readDictionary -( - const dictionary& dict -) -{ - diameters_ = dict.getVal("diameters"); - materials_ = dict.getVal("materials"); - auto names = dict.getVal("names"); - - if(diameters_.size() != materials_.size() ) + if(diameters_.size() != numShapes() ) { - fatalErrorInFunction<< - " number of elements in diameters and properties are not the same in "<< dict.globalName()< names_; +protected: - size_t numShapes_; - - - bool insertNames(const wordVector& names); - - bool readDictionary(const dictionary& dict); - - bool writeDictionary(dictionary& dict)const; + bool writeToDict(dictionary& dict)const override; public: // - type info - TypeInfoNV("sphereShape"); + TypeInfo("shape"); + sphereShape( + const word& fileName, + repository* owner, + const property& prop); - sphereShape(){} - - sphereShape( - const realVector& diameter, - const wordVector& property, - const wordVector& name - ); - - sphereShape(const sphereShape&) = default; - - sphereShape(sphereShape&&) = default; - - sphereShape& operator=(const sphereShape&) = default; - - sphereShape& operator=(sphereShape&&) = default; - - auto clone()const - { - return makeUnique(*this); - } - - sphereShape* clonePtr()const - { - return new sphereShape(*this); - } - - ~sphereShape() = default; + + ~sphereShape() override = default; //// - Methods - const auto& names()const{ - return names_; - } - const auto& diameters()const{ - return diameters_; - } + real maxBoundingSphere()const override; - const auto& materials()const{ - return materials_; - } + real minBoundingSphere()const override; - const auto diameter(label i)const{ - return diameters_[i]; - } + bool boundingDiameter(uint32 index, real& bDiam)const override; - const auto material(label i)const{ - return materials_[i]; - } + real boundingDiameter(uint32 index)const override; + realVector boundingDiameter()const override; - // name to index - bool nameToIndex(const word& name, uint32& index)const - { - if(auto[iter, found] = names_.findIf(name); found ) - { - index = iter->second; - return true; - } - else - { - index = 0; - return false; - } - } + bool mass(uint32 index, real& m)const override; - uint32 nameToIndex(const word& name)const - { - return names_.at(name); - } + real mass(uint32 index) const override; - bool indexToName(uint32 i, word& name)const - { - for(auto& nm: names_) - { - if(nm.second == i) - { - name = nm.first; - return true; - } - } - name = ""; - return false; - } + realVector mass()const override; - bool shapeToDiameter(wordVector& names, realVector& diams)const; + realVector density() const override; - void diameterMinMax(real& minD, real& maxD)const - { - minD = min(diameters_); - maxD = max(diameters_); - } + bool Inertia(uint32 index, real& I)const override; - //// - IO operatoin + real Inertia(uint32 index)const override; - // - read from stream/file - bool read(iIstream& is); + realVector Inertia()const override; + + bool Inertia_xx(uint32 index, real& Ixx)const override; - // - write to stream/file - bool write(iOstream& os)const; + real Inertial_xx(uint32 index)const override; + + bool Inertia_yy(uint32 index, real& Iyy)const override; - // - read from dictionary - bool read(const dictionary& dict) - { - return readDictionary(dict); - } + real Inertial_yy(uint32 index)const override; - // - write to dictionary - bool write(dictionary& dict)const - { - return writeDictionary(dict); - } + bool Inertia_zz(uint32 index, real& Izz)const override; + real Inertial_zz(uint32 index)const override; }; diff --git a/src/Particles/particles/baseShapeNames.cpp b/src/Particles/particles/baseShapeNames.cpp new file mode 100644 index 00000000..c8200f0c --- /dev/null +++ b/src/Particles/particles/baseShapeNames.cpp @@ -0,0 +1,114 @@ +/*------------------------------- phasicFlow --------------------------------- + O C enter of + O O E ngineering and + O O M ultiscale modeling of + OOOOOOO F luid flow +------------------------------------------------------------------------------ + Copyright (C): www.cemf.ir + email: hamid.r.norouzi AT gmail.com +------------------------------------------------------------------------------ +Licence: + This file is part of phasicFlow code. It is a free software for simulating + granular and multiphase flows. You can redistribute it and/or modify it under + the terms of GNU General Public License v3 or any other later versions. + + phasicFlow is distributed to help others in their research in the field of + granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the + implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. + +-----------------------------------------------------------------------------*/ + +#include "baseShapeNames.hpp" + +bool pFlow::baseShapeNames::createHashNames() +{ + hashNames_.clear(); + uint32 i=0; + for(const auto& nm:shapeNames_) + { + if(!hashNames_.insertIf(nm, i)) + { + fatalErrorInFunction<< + " repeated name in the list of shape names: " << shapeNames_; + return false; + } + i++; + } + hashNames_.rehash(0); + + return true; +} + + +bool pFlow::baseShapeNames::readFromDictionary() +{ + + shapeNames_ = getVal("names"); + numShapes_ = shapeNames_.size(); + + return true; +} + + +pFlow::baseShapeNames::baseShapeNames +( + const word &fileName, + repository *owner +) +: + fileDictionary + ( + objectFile + ( + fileName, + "", + objectFile::READ_ALWAYS, + objectFile::WRITE_ALWAYS + ), + owner + ) +{ + + if( !readFromDictionary() ) + { + fatalExit; + } + + if( !createHashNames()) + { + fatalExit; + } + +} + +bool pFlow::baseShapeNames::writeToDict(dictionary &dict)const +{ + + if( !dict.add("names", shapeNames_) ) + { + fatalErrorInFunction<< + " Error in writing names to dictionary "<< dict.globalName()< hashNames_; + + /// list of shape names + wordVector shapeNames_; + + bool createHashNames(); + + bool readFromDictionary(); + +protected: + + virtual + bool writeToDict(dictionary& dict)const; + +public: + + TypeInfo("baseShapeNames"); + + baseShapeNames( + const word& fileName, + repository* owner); + + ~baseShapeNames() override=default; + + + inline + const wordVector& shapeNames()const + { + return shapeNames_; + } + + inline + wordList shapeNameList()const + { + wordList wl; + wl.insert(wl.begin(), shapeNames_.begin(), shapeNames_.end()); + return wl; + } + + inline + size_t numShapes()const + { + return numShapes_; + } + + // name to index + inline + bool shapeNameToIndex(const word& name, uint32& index)const + { + if(auto[iter, found] = hashNames_.findIf(name); found ) + { + index = iter->second; + return true; + } + else + { + index = 0; + return false; + } + } + + inline + bool indexToShapeName(uint32 i, word& name)const + { + if( i < numShapes_) + { + name = shapeNames_[i]; + return true; + } + return false; + } + + inline + bool indexValid(uint32 index)const + { + return index < numShapes_; + } + + // - IO + + bool write(iOstream& os)const override; + +}; + +} + +#endif //__shapeNames_hpp__ \ No newline at end of file diff --git a/src/Particles/particles/particles.cpp b/src/Particles/particles/particles.cpp index 23250718..ff32aa4f 100644 --- a/src/Particles/particles/particles.cpp +++ b/src/Particles/particles/particles.cpp @@ -21,17 +21,71 @@ Licence: #include "particles.hpp" +bool pFlow::particles::initMassDiameter()const +{ + + auto [minIndex, maxIndex] = minMax(shapeIndex_.internal()); + + const auto& shp = getShapes(); + + if( !shp.indexValid(maxIndex) ) + { + fatalErrorInFunction<< + "the maximum value of shape index is "<< maxIndex << + " which is not valid."<>; + + auto field_diameter = diameter_.fieldDevice(); + auto field_mass = mass_.fieldDevice(); + auto field_propId = propertyId_.fieldDevice(); + auto field_shapeIndex = shapeIndex_.fieldDevice(); + + auto d_d = d.deviceVector(); + auto d_mass = mass.deviceVector(); + auto d_propId = propId.deviceVector(); + + Kokkos::parallel_for( + "particles::initMassDiameter", + policy(aRange.start(), aRange.end()), + LAMBDA_HD(uint32 i) + { + if(aPointsMask(i)) + { + uint32 index = field_shapeIndex[i]; + field_diameter[i] = d_d[index]; + field_mass[i] = d_mass[index]; + field_propId[i] = d_propId[index]; + } + }); + Kokkos::fence(); + + return true; +} pFlow::particles::particles ( - systemControl& control + systemControl &control ) -: - observer(), +: + observer(defaultMessage_), demComponent("particles", control), dynPointStruct_(control), id_ - ( + ( objectFile ( "id", @@ -48,127 +102,108 @@ pFlow::particles::particles ( "propertyId", "", - objectFile::READ_NEVER, + objectFile::READ_ALWAYS, objectFile::WRITE_NEVER ), dynPointStruct_, static_cast(0) ), - diameter_ + shapeIndex_ ( objectFile ( + "shapeIndex", + "", + objectFile::READ_ALWAYS, + objectFile::WRITE_ALWAYS + ), + dynPointStruct_, + 0 + ), + diameter_ + ( + objectFile( "diameter", "", objectFile::READ_NEVER, - objectFile::WRITE_ALWAYS - ), + objectFile::WRITE_NEVER), dynPointStruct_, 0.00000000001 ), mass_ ( - objectFile - ( + objectFile( "mass", "", objectFile::READ_NEVER, - objectFile::WRITE_ALWAYS - ), + objectFile::WRITE_NEVER), dynPointStruct_, 0.0000000001 ), accelertion_ ( - objectFile - ( + objectFile( "accelertion", "", objectFile::READ_IF_PRESENT, - objectFile::WRITE_ALWAYS - ), + objectFile::WRITE_ALWAYS), dynPointStruct_, zero3 ), - contactForce_ - ( - objectFile - ( + contactForce_( + objectFile( "contactForce", "", objectFile::READ_IF_PRESENT, - objectFile::WRITE_ALWAYS - ), + objectFile::WRITE_ALWAYS), dynPointStruct_, - zero3 - ), - contactTorque_ - ( - - objectFile - ( + zero3), + contactTorque_( + objectFile( "contactTorque", "", objectFile::READ_IF_PRESENT, - objectFile::WRITE_ALWAYS - ), + objectFile::WRITE_ALWAYS), dynPointStruct_, - zero3 - ) + zero3) { - WARNING<<"Subscribe particles"<subscribe(pStruct()); + this->addToSubscriber(dynPointStruct_); + + if(!initMassDiameter()) + { + fatalExit; + } } bool pFlow::particles::beforeIteration() { - /*auto domain = this->control().domain(); - - auto numMarked = dynPointStruct_.markDeleteOutOfBox(domain); - if(time_.sortTime()) - { - real min_dx, max_dx; - boundingSphereMinMax(min_dx, max_dx); - Timer t; - t.start(); - REPORT(0)<<"Performing morton sorting on particles ...."<zeroForce(); - this->zeroTorque();*/ + dynPointStruct_.beforeIteration(); + zeroForce(); + zeroTorque(); return true; } -/*pFlow::uniquePtr> -pFlow::particles::getFieldObjectList()const +bool pFlow::particles::iterate() { - auto objListPtr = makeUnique>(); - objListPtr().push_back( - static_cast(&id_) ); - - objListPtr().push_back( - static_cast(&propertyId_) ); + return dynPointStruct_.iterate(); +} - objListPtr().push_back( - static_cast(&diameter_) ); +bool pFlow::particles::afterIteration() +{ + return dynPointStruct_.afterIteration(); +} - objListPtr().push_back( - static_cast(&mass_) ); - - objListPtr().push_back( - static_cast(&shapeName_) ); - - return objListPtr; -}*/ +void pFlow::particles::boundingSphereMinMax +( + real &minDiam, + real &maxDiam +) const +{ + auto& shp = getShapes(); + minDiam = shp.minBoundingSphere(); + maxDiam = shp.maxBoundingSphere(); +} \ No newline at end of file diff --git a/src/Particles/particles/particles.hpp b/src/Particles/particles/particles.hpp index 554c9a85..5f9e7ea8 100644 --- a/src/Particles/particles/particles.hpp +++ b/src/Particles/particles/particles.hpp @@ -24,6 +24,7 @@ Licence: #include "dynamicPointStructure.hpp" #include "demComponent.hpp" +#include "shape.hpp" namespace pFlow { @@ -39,43 +40,51 @@ private: /// dynamic point structure for particles center mass dynamicPointStructure dynPointStruct_; - // - name of shapes - this is managed by particles - //wordPointField& shapeName_; + /// id of particles on host + uint32PointField_D id_; - // id of particles on host - int32PointField_D id_; + /// property id on device + uint8PointField_D propertyId_; - // property id on device - int8PointField_D propertyId_; + /// property id on device + uint32PointField_D shapeIndex_; - // diameter / boundig sphere size of particles on device + /// diameter / boundig sphere size of particles on device realPointField_D diameter_; - // mass of particles field + /// mass of particles field realPointField_D mass_; - // - acceleration on device - realx3PointField_D accelertion_; + /// acceleration on device + realx3PointField_D accelertion_; /// contact force field realx3PointField_D contactForce_; /// contact torque field - realx3PointField_D contactTorque_; + realx3PointField_D contactTorque_; + static inline + const message defaultMessage_ = + ( + message::CAP_CHANGED+ + message::SIZE_CHANGED+ + message::ITEM_INSERT+ + message::ITEM_DELETE + ); + bool initMassDiameter()const; void zeroForce() { - WARNING<<"fill contactTorque"<(propId); + } + else + { + fatalErrorInFunction<<"Material name "<< materialNames_[i]<< + "is not valid in dictionary "<("materials"); + + if(materialNames_.size() != numShapes() ) + { + fatalErrorInFunction<< + " number of elements in materials and names are not the same in "<< globalName()<(propId) < property_.numMaterials(); + } + + + inline + bool indexToDensity(uint32 index, real& rho)const + { + if(indexValid(index)) + return property_.density(shapePropertyIds_[index], rho); + return false; + } + + inline + real indexToDensity(uint32 index)const + { + if(indexValid(index)) + { + return property_.density(shapePropertyIds_[index]); + } + + fatalExit; + return 0.0; + } + + virtual + real maxBoundingSphere()const = 0; + + virtual + real minBoundingSphere()const = 0; + + virtual + bool boundingDiameter(uint32 index, real& bDiam)const =0; + + virtual + real boundingDiameter(uint32 index)const = 0; + + virtual + realVector boundingDiameter()const = 0; + + virtual + bool mass(uint32 index, real& m)const = 0; + + virtual + real mass(uint32 index) const =0; + + virtual + realVector mass()const =0; + + virtual + realVector density()const =0; + + virtual + bool Inertia(uint32 index, real& I)const = 0; + + virtual + real Inertia(uint32 index)const = 0; + + virtual + realVector Inertia()const=0; + + virtual + bool Inertia_xx(uint32 index, real& Ixx)const = 0; + + virtual + real Inertial_xx(uint32 index)const =0; + + virtual + bool Inertia_yy(uint32 index, real& Iyy)const = 0; + + virtual + real Inertial_yy(uint32 index)const = 0; + + virtual + bool Inertia_zz(uint32 index, real& Izz)const = 0; + + virtual + real Inertial_zz(uint32 index)const = 0; + +}; + +} + +#endif //__shape_hpp__ \ No newline at end of file From 8dc8009311813854c1be32380c5e2c1754161108 Mon Sep 17 00:00:00 2001 From: Hamidreza Norouzi Date: Thu, 25 Jan 2024 03:09:08 -0800 Subject: [PATCH 03/57] properry class refactored --- src/Property/property.cpp | 4 ++-- src/Property/property.hpp | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Property/property.cpp b/src/Property/property.cpp index e87de71e..25573665 100644 --- a/src/Property/property.cpp +++ b/src/Property/property.cpp @@ -82,7 +82,7 @@ bool pFlow::property::makeNameIndex() pFlow::property::property ( - const word& name, + const word& fileName, const wordVector& materials, const realVector& densities, repository* owner @@ -92,7 +92,7 @@ pFlow::property::property ( objectFile ( - name, + fileName, "", objectFile::READ_NEVER, objectFile::WRITE_NEVER diff --git a/src/Property/property.hpp b/src/Property/property.hpp index bba952ab..e60cbbbf 100644 --- a/src/Property/property.hpp +++ b/src/Property/property.hpp @@ -81,7 +81,7 @@ public: const word& fileName, repository* owner=nullptr); - property(const word& name, + property(const word& fileName, const wordVector& materials, const realVector& densities, repository* owner=nullptr); From ab6308bb0aabe39c2ec6c491ba2f41c2c29a2511 Mon Sep 17 00:00:00 2001 From: Hamidreza Norouzi Date: Thu, 25 Jan 2024 03:10:44 -0800 Subject: [PATCH 04/57] code refactor upto pointFields and insertion etc. --- src/phasicFlow/CMakeLists.txt | 12 +- src/phasicFlow/containers/Field/Field.hpp | 22 +- .../containers/List/ListPtr/ListPtr.hpp | 24 +- src/phasicFlow/containers/Set/Set.hpp | 5 + .../containers/VectorHD/VectorSingle.cpp | 72 +++++- .../containers/VectorHD/VectorSingle.hpp | 8 + .../VectorHD/VectorSingleAlgorithms.hpp | 4 - .../containers/pointField/boundaryField.cpp | 2 +- .../containers/pointField/boundaryField.hpp | 18 ++ .../pointField/boundaryFieldList.hpp | 8 + .../pointField/exitBoundaryField.hpp | 3 + .../containers/pointField/internalField.cpp | 2 +- .../containers/pointField/internalField.hpp | 22 +- .../pointField/internalFieldAlgorithms.hpp | 205 ++++++++++++++++++ .../containers/pointField/pointField.hpp | 65 +----- .../containers/pointField/pointFields.cpp | 74 ++++--- .../containers/pointField/pointFields.hpp | 9 +- src/phasicFlow/demComponent/demComponent.cpp | 11 +- src/phasicFlow/demComponent/demComponent.hpp | 19 +- src/phasicFlow/dictionary/dictionary.hpp | 11 +- src/phasicFlow/eventManagement/observer.cpp | 46 ++-- src/phasicFlow/eventManagement/observer.hpp | 19 +- src/phasicFlow/eventManagement/subscriber.cpp | 12 +- src/phasicFlow/eventManagement/subscriber.hpp | 7 +- src/phasicFlow/globals/error.hpp | 2 +- src/phasicFlow/globals/vocabs.hpp | 4 +- ...andomInt32.hpp => uniformRandomUint32.hpp} | 22 +- .../repository/IOobject/IOfileHeader.cpp | 2 + .../repository/IOobject/IOfileHeader.hpp | 12 + .../repository/IOobject/IOobject.cpp | 15 ++ .../repository/IOobject/IOobject.hpp | 6 + .../repository/IOobject/objectFile.hpp | 6 +- .../repository/repository/repository.cpp | 3 +- .../repository/repository/repository.hpp | 17 ++ .../repository/repositoryTemplates.cpp | 118 +--------- .../systemControl/systemControl.cpp | 49 +++-- .../systemControl/systemControl.hpp | 38 +++- src/phasicFlow/setFieldList/setFieldEntry.cpp | 123 +++++++---- src/phasicFlow/setFieldList/setFieldEntry.hpp | 32 +-- .../setFieldList/setFieldEntryTemplates.cpp | 70 ++---- .../streams/dataIO/dataIOTemplate.cpp | 19 +- .../pStructSelector/pStructSelector.hpp | 4 +- .../selectors/selectBox/selectBox.hpp | 6 +- .../selectors/selectRandom/selectRandom.cpp | 22 +- .../selectors/selectRandom/selectRandom.hpp | 12 +- .../selectors/selectRange/selectRange.cpp | 16 +- .../selectors/selectRange/selectRange.hpp | 12 +- 47 files changed, 814 insertions(+), 476 deletions(-) create mode 100644 src/phasicFlow/containers/pointField/internalFieldAlgorithms.hpp rename src/phasicFlow/random/randomInt32/{uniformRandomInt32.hpp => uniformRandomUint32.hpp} (77%) 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