diff --git a/DEMSystems/DEMSystem/DEMSystem.cpp b/DEMSystems/DEMSystem/DEMSystem.cpp index 9c9b0c02..7616ff35 100644 --- a/DEMSystems/DEMSystem/DEMSystem.cpp +++ b/DEMSystems/DEMSystem/DEMSystem.cpp @@ -21,9 +21,8 @@ Licence: #include "DEMSystem.hpp" -pFlow::coupling::DEMSystem::DEMSystem( +pFlow::DEMSystem::DEMSystem( word demSystemName, - int32 numDomains, const std::vector& domains, int argc, char* argv[]) @@ -39,16 +38,17 @@ pFlow::coupling::DEMSystem::DEMSystem( ControlDict_.saveInterval(), ControlDict_.startTimeName()); + timers_ = makeUnique(demSystemName, &Control_().timers()); + } -pFlow::coupling::DEMSystem::~DEMSystem() +pFlow::DEMSystem::~DEMSystem() {} -pFlow::uniquePtr - pFlow::coupling::DEMSystem::create( +pFlow::uniquePtr + pFlow::DEMSystem::create( word demSystemName, - int32 numDomains, const std::vector& domains, int argc, char* argv[] @@ -56,7 +56,7 @@ pFlow::uniquePtr { if( wordvCtorSelector_.search(demSystemName) ) { - return wordvCtorSelector_[demSystemName] (demSystemName, numDomains, domains, argc, argv); + return wordvCtorSelector_[demSystemName] (demSystemName, domains, argc, argv); } else { diff --git a/DEMSystems/DEMSystem/DEMSystem.hpp b/DEMSystems/DEMSystem/DEMSystem.hpp index a2731261..02c62bff 100644 --- a/DEMSystems/DEMSystem/DEMSystem.hpp +++ b/DEMSystems/DEMSystem/DEMSystem.hpp @@ -24,13 +24,14 @@ Licence: #include #include "types.hpp" +#include "span.hpp" #include "virtualConstructor.hpp" #include "uniquePtr.hpp" #include "systemControl.hpp" #include "readControlDict.hpp" -namespace pFlow::coupling +namespace pFlow { @@ -44,6 +45,7 @@ protected: std::vector domains_; + uniquePtr timers_; // methods auto& Control() @@ -58,7 +60,6 @@ public: DEMSystem( word demSystemName, - int32 numDomains, const std::vector& domains, int argc, char* argv[]); @@ -74,14 +75,12 @@ public: word, ( word demSystemName, - int32 numDomains, const std::vector& domains, int argc, char* argv[] ), ( demSystemName, - numDomains, domains, argc, argv @@ -97,6 +96,11 @@ public: return pFlow::usingDouble__; } + Timers& timers() + { + return Control_->timers(); + } + virtual int32 numParInDomain(int32 di)const = 0; @@ -104,16 +108,26 @@ public: std::vector numParInDomain()const = 0; virtual - bool iterate(int32 n, real timeToWrite, word timeName) = 0; + span parIndexInDomain(int32 di)const = 0; + + virtual + bool changeDomainsSizeUpdateParticles(const std::vector& domains) = 0; + + virtual + bool updateParticles() = 0; virtual real maxBounndingSphereSize()const = 0; + virtual + bool iterate(int32 n, real timeToWrite, word timeName) = 0; + + + static uniquePtr create( word demSystemName, - int32 numDomains, const std::vector& domains, int argc, char* argv[]); diff --git a/DEMSystems/domainDistribute/domainDistribute.cpp b/DEMSystems/domainDistribute/domainDistribute.cpp index 18e43832..5c53ca4d 100644 --- a/DEMSystems/domainDistribute/domainDistribute.cpp +++ b/DEMSystems/domainDistribute/domainDistribute.cpp @@ -21,81 +21,98 @@ Licence: #include "domainDistribute.hpp" - -pFlow::coupling::domainDistribute::domainDistribute( - int32 numDomains, - const Vector& domains_, - real maxBoundingBox) -: -numDomains_(numDomains), -extDomains_("extDomains", numDomains), -particlesInDomains_("particlesInDomains", numDomains), -numParInDomain_("numParInDomain", numDomains, 0), -maxBoundingBoxSize_(maxBoundingBox) +void pFlow::domainDistribute::clcDomains(const std::vector& domains) { - realx3 dl = domainExtension_ * maxBoundingBoxSize_; for(int32 i=0; i& domains, + real maxBoundingBox) +: +numDomains_(domains.size()), +extDomains_("extDomains", numDomains_), +particlesInDomains_("particlesInDomains", numDomains_), +numParInDomain_("numParInDomain", numDomains_, 0), +maxBoundingBoxSize_(maxBoundingBox) +{ + + clcDomains(domains); +} + +bool pFlow::domainDistribute::locateParticles( ViewType1D points, includeMask mask) +{ + range active = mask.activeRange(); + auto numInDomain = numParInDomain_.deviceVectorAll(); + auto numDomains = numDomains_; + + using policy = Kokkos::RangePolicy< + DefaultHostExecutionSpace, + Kokkos::IndexType >; + + Kokkos::parallel_for("locateParticles", + policy(active.first, active.second), + LAMBDA_HD(int32 i){ + if(mask(i)) + { + for(int32 di=0; di >; + numParInDomain_.fill(0); - Kokkos::parallel_for("locateParticles", - policy(active.first, active.second), - LAMBDA_HD(int32 i){ - if(mask(i)) + auto particlesInDomainsPtr = particlesInDomains_.data(); + + Kokkos::parallel_for("locateParticles", + policy(active.first, active.second), + LAMBDA_HD(int32 i){ + if(mask(i)) + { + for(int32 di=0; di& domains) +{ + if(domains.size()!= numDomains_) + { + fatalErrorInFunction<<"number of new domians differs"<& domains); + public: domainDistribute( - int32 numDomains, - const Vector& domains_, - real maxBoundinBox); + const Vector& domains, + real maxBoundingBox); ~domainDistribute()=default; @@ -77,6 +74,18 @@ public: return numParInDomain_[di]; } + span particlesInDomain(int32 di)const + { + return + span( + particlesInDomains_[di].hostVectorAll().data(), + numParInDomain_[di] + ); + } + + bool changeDomainsSize(const std::vector& domains); + + //template bool locateParticles( ViewType1D points, includeMask mask); diff --git a/DEMSystems/sphereDEMSystem/sphereDEMSystem.cpp b/DEMSystems/sphereDEMSystem/sphereDEMSystem.cpp index 14139f18..2f720849 100644 --- a/DEMSystems/sphereDEMSystem/sphereDEMSystem.cpp +++ b/DEMSystems/sphereDEMSystem/sphereDEMSystem.cpp @@ -21,14 +21,13 @@ Licence: #include "sphereDEMSystem.hpp" -pFlow::coupling::sphereDEMSystem::sphereDEMSystem( +pFlow::sphereDEMSystem::sphereDEMSystem( word demSystemName, - int32 numDomains, const std::vector& domains, int argc, char* argv[]) : - DEMSystem(demSystemName, numDomains, domains, argc, argv) + DEMSystem(demSystemName, domains, argc, argv) { REPORT(0)<<"Initializing host/device execution spaces . . . \n"; @@ -51,19 +50,6 @@ pFlow::coupling::sphereDEMSystem::sphereDEMSystem( particles_ = makeUnique(Control(), Property()); - //REPORT(0)<<"\nCreating particle insertion for spheres. . ."<( - objectFile( - insertionFile__, - "", - objectFile::READ_ALWAYS, - objectFile::WRITE_ALWAYS - ), - sphParticles, - sphParticles.shapes() - );*/ - REPORT(0)<<"\nCreating interaction model for sphere-sphere contact and sphere-wall contact . . ."<boundingSphereMinMax(minD, maxD); - particleDistribution_ = makeUnique(numDomains, domains, maxD); + particleDistribution_ = makeUnique(domains, maxD); } -pFlow::coupling::sphereDEMSystem::~sphereDEMSystem() +pFlow::sphereDEMSystem::~sphereDEMSystem() { interaction_.reset(); insertion_.reset(); @@ -93,13 +79,13 @@ pFlow::coupling::sphereDEMSystem::~sphereDEMSystem() pFlow::int32 - pFlow::coupling::sphereDEMSystem::numParInDomain(int32 di)const + pFlow::sphereDEMSystem::numParInDomain(int32 di)const { return particleDistribution_().numParInDomain(di); } std::vector - pFlow::coupling::sphereDEMSystem::numParInDomain()const + pFlow::sphereDEMSystem::numParInDomain()const { const auto& distribute = particleDistribution_(); int32 numDomains = distribute.numDomains(); @@ -112,8 +98,31 @@ std::vector return nums; } +pFlow::span +pFlow::sphereDEMSystem::parIndexInDomain(int32 di)const +{ + return particleDistribution_->particlesInDomain(di); +} -bool pFlow::coupling::sphereDEMSystem::iterate( +bool pFlow::sphereDEMSystem::changeDomainsSizeUpdateParticles( + const std::vector& domains) +{ + if( !particleDistribution_->changeDomainsSize(domains)) + return false; + + // should update list of particles here + //************************************************************************************************ + notImplementedFunction; + return false; +} + +bool pFlow::sphereDEMSystem::updateParticles() +{ + notImplementedFunction; + return false; +} + +bool pFlow::sphereDEMSystem::iterate( int32 n, real timeToWrite, word timeName) @@ -122,7 +131,7 @@ bool pFlow::coupling::sphereDEMSystem::iterate( } pFlow::real - pFlow::coupling::sphereDEMSystem::maxBounndingSphereSize()const + pFlow::sphereDEMSystem::maxBounndingSphereSize()const { real minD, maxD; particles_->boundingSphereMinMax(minD, maxD); diff --git a/DEMSystems/sphereDEMSystem/sphereDEMSystem.hpp b/DEMSystems/sphereDEMSystem/sphereDEMSystem.hpp index 5ddc04e5..abf86742 100644 --- a/DEMSystems/sphereDEMSystem/sphereDEMSystem.hpp +++ b/DEMSystems/sphereDEMSystem/sphereDEMSystem.hpp @@ -31,7 +31,7 @@ Licence: #include "domainDistribute.hpp" -namespace pFlow::coupling +namespace pFlow { class sphereDEMSystem @@ -81,7 +81,6 @@ public: sphereDEMSystem( word demSystemName, - int32 numDomains, const std::vector& domains, int argc, char* argv[]); @@ -100,15 +99,17 @@ public: int32 numParInDomain(int32 di)const override; - std::vector numParInDomain()const override; - - - virtual + + span parIndexInDomain(int32 di)const override; + + bool changeDomainsSizeUpdateParticles(const std::vector& domains) override; + + bool updateParticles() override; + bool iterate(int32 n, real timeToWrite, word timeName) override; - virtual real maxBounndingSphereSize()const override; }; diff --git a/src/phasicFlow/containers/span/span.hpp b/src/phasicFlow/containers/span/span.hpp index 5e68603e..ec10297a 100644 --- a/src/phasicFlow/containers/span/span.hpp +++ b/src/phasicFlow/containers/span/span.hpp @@ -133,25 +133,25 @@ public: INLINE_FUNCTION_HD T& operator[](int32 i) { - data_[i]; + return data_[i]; } INLINE_FUNCTION_HD const T& operator[](int32 i)const { - data_[i]; + return data_[i]; } INLINE_FUNCTION_HD T& operator[](label i) { - data_[i]; + return data_[i]; } INLINE_FUNCTION_HD const T& operator[](label i)const { - data_[i]; + return data_[i]; } };