From 16f8ab45726d1f1d539c306d274a447883539548 Mon Sep 17 00:00:00 2001 From: HRN Date: Thu, 26 Dec 2024 19:07:39 +0330 Subject: [PATCH] sphereDEMSystem is updated for version 1.0 --- DEMSystems/CMakeLists.txt | 2 +- DEMSystems/DEMSystem/DEMSystem.hpp | 3 +- .../domainDistribute/domainDistribute.cpp | 2 +- .../domainDistribute/domainDistribute.hpp | 2 +- .../sphereDEMSystem/sphereDEMSystem.cpp | 84 ++++++++++++------- .../sphereDEMSystem/sphereDEMSystem.hpp | 42 ++++++---- .../sphereDEMSystem/sphereFluidParticles.cpp | 76 ++++++++--------- .../sphereDEMSystem/sphereFluidParticles.hpp | 20 +++-- .../sphereFluidParticlesKernels.hpp | 2 +- .../sphereParticles/sphereParticles.hpp | 15 ++++ 10 files changed, 151 insertions(+), 97 deletions(-) diff --git a/DEMSystems/CMakeLists.txt b/DEMSystems/CMakeLists.txt index f768a0c4..fba75be5 100644 --- a/DEMSystems/CMakeLists.txt +++ b/DEMSystems/CMakeLists.txt @@ -3,7 +3,7 @@ set(SourceFiles domainDistribute/domainDistribute.cpp DEMSystem/DEMSystem.cpp sphereDEMSystem/sphereFluidParticles.cpp -#sphereDEMSystem/sphereDEMSystem.cpp +sphereDEMSystem/sphereDEMSystem.cpp # ) diff --git a/DEMSystems/DEMSystem/DEMSystem.hpp b/DEMSystems/DEMSystem/DEMSystem.hpp index c6f37591..2ad2e23d 100644 --- a/DEMSystems/DEMSystem/DEMSystem.hpp +++ b/DEMSystems/DEMSystem/DEMSystem.hpp @@ -61,6 +61,7 @@ public: DEMSystem(const DEMSystem&)=delete; + /// @brief no assignment DEMSystem& operator = (const DEMSystem&)=delete; create_vCtor( @@ -118,7 +119,7 @@ public: span parIndexInDomain(int32 domIndx)const = 0; virtual - span parDiameter() = 0; + span diameter() = 0; virtual span acceleration()=0; diff --git a/DEMSystems/domainDistribute/domainDistribute.cpp b/DEMSystems/domainDistribute/domainDistribute.cpp index b5fee194..8a595e2e 100644 --- a/DEMSystems/domainDistribute/domainDistribute.cpp +++ b/DEMSystems/domainDistribute/domainDistribute.cpp @@ -33,7 +33,7 @@ void pFlow::domainDistribute::clcDomains(const std::vector& domains) pFlow::domainDistribute::domainDistribute( - const Vector& domains, + const std::vector& domains, real maxBoundingBox) : numDomains_(domains.size()), diff --git a/DEMSystems/domainDistribute/domainDistribute.hpp b/DEMSystems/domainDistribute/domainDistribute.hpp index 86581601..aaec7a0f 100644 --- a/DEMSystems/domainDistribute/domainDistribute.hpp +++ b/DEMSystems/domainDistribute/domainDistribute.hpp @@ -52,7 +52,7 @@ protected: public: domainDistribute( - const Vector& domains, + const std::vector& domains, real maxBoundingBox); ~domainDistribute()=default; diff --git a/DEMSystems/sphereDEMSystem/sphereDEMSystem.cpp b/DEMSystems/sphereDEMSystem/sphereDEMSystem.cpp index 37f7529f..ddf21f9e 100644 --- a/DEMSystems/sphereDEMSystem/sphereDEMSystem.cpp +++ b/DEMSystems/sphereDEMSystem/sphereDEMSystem.cpp @@ -19,6 +19,7 @@ Licence: -----------------------------------------------------------------------------*/ #include "sphereDEMSystem.hpp" +#include "vocabs.hpp" bool pFlow::sphereDEMSystem::loop() { @@ -26,16 +27,15 @@ bool pFlow::sphereDEMSystem::loop() do { // - if(! insertion_().insertParticles( + Control().time().currentIter(), Control().time().currentTime(), Control().time().dt() ) ) { fatalError<< - "particle insertion failed in sphereDFlow solver.\n"; + "particle insertion failed in sphereDEMSystem.\n"; return false; - } - + } geometry_->beforeIteration(); @@ -63,29 +63,31 @@ pFlow::sphereDEMSystem::sphereDEMSystem( word demSystemName, const std::vector& domains, int argc, - char* argv[]) + char* argv[], + bool requireRVel) : - DEMSystem(demSystemName, domains, argc, argv) + DEMSystem(demSystemName, domains, argc, argv), + requireRVel_(requireRVel) { - REPORT(0)<<"\nReading proprties . . . "<( - Control().caseSetup().path()+propertyFile__); + propertyFile__, + Control().caseSetup().path()); - REPORT(0)<< "\nCreating surface geometry for sphereDEMSystem . . . "<(Control(), Property()); - insertion_ = makeUnique( - Control().caseSetup().path()+insertionFile__, + insertion_ = makeUnique( particles_(), - particles_().shapes()); + particles_().spheres()); - REPORT(0)<<"\nCreating interaction model for sphere-sphere contact and sphere-wall contact . . ."<locateParticles( - parPosition_, - particles_->pStruct().activePointsMaskH())) + positionHost_, + particles_->pStruct().activePointsMaskHost())) { fatalErrorInFunction<< "error in locating particles among sub-domains"< - pFlow::sphereDEMSystem::numParInDomain()const + pFlow::sphereDEMSystem::numParInDomains()const { const auto& distribute = particleDistribution_(); int32 numDomains = distribute.numDomains(); @@ -156,31 +159,51 @@ pFlow::sphereDEMSystem::parIndexInDomain(int32 di)const return particleDistribution_->particlesInDomain(di); } -pFlow::span pFlow::sphereDEMSystem::parDiameter() +pFlow::span pFlow::sphereDEMSystem::diameter() { - return span(parDiameter_.data(), parDiameter_.size()); + return span(diameterHost_.data(), diameterHost_.size()); } -pFlow::span pFlow::sphereDEMSystem::parVelocity() +pFlow::span pFlow::sphereDEMSystem::acceleration() { - return span(parVelocity_.data(), parVelocity_.size()); + return span(nullptr, 0); } -pFlow::span pFlow::sphereDEMSystem::parPosition() +pFlow::span pFlow::sphereDEMSystem::velocity() { - return span(parPosition_.data(), parPosition_.size()); + return span(velocityHost_.data(), velocityHost_.size()); +} + +pFlow::span pFlow::sphereDEMSystem::position() +{ + return span(positionHost_.data(), positionHost_.size()); +} + +pFlow::span pFlow::sphereDEMSystem::rAcceleration() +{ + return span(nullptr, 0); +} + +pFlow::span pFlow::sphereDEMSystem::rVelocity() +{ + return span(rVelocityHost_.data(), rVelocityHost_.size()); +} + +pFlow::span pFlow::sphereDEMSystem::rPosition() +{ + return span(nullptr, 0); } pFlow::span pFlow::sphereDEMSystem::parFluidForce() { - auto& hVec = particles_->fluidForceHostAll(); + auto& hVec = particles_->fluidForceHost(); return span(hVec.data(), hVec.size()); } pFlow::span pFlow::sphereDEMSystem::parFluidTorque() { - auto& hVec = particles_->fluidTorqueHostAll(); + auto& hVec = particles_->fluidTorqueHost(); return span(hVec.data(), hVec.size()); } @@ -198,9 +221,14 @@ bool pFlow::sphereDEMSystem::sendFluidTorqueToDEM() bool pFlow::sphereDEMSystem::beforeIteration() { - parVelocity_ = particles_->dynPointStruct().velocityHostAll(); - parPosition_ = particles_->dynPointStruct().pointPositionHostAll(); - parDiameter_ = particles_->diameter().hostVectorAll(); + velocityHost_ = std::as_const(particles_()).velocity().hostView(); + positionHost_ = std::as_const(particles_()).pointPosition().hostView(); + diameterHost_ = particles_->diameter().hostView(); + + if(requireRVel_) + rVelocityHost_ = std::as_const(particles_()).rVelocity().hostView(); + + return true; } diff --git a/DEMSystems/sphereDEMSystem/sphereDEMSystem.hpp b/DEMSystems/sphereDEMSystem/sphereDEMSystem.hpp index a7015a36..029ec46d 100644 --- a/DEMSystems/sphereDEMSystem/sphereDEMSystem.hpp +++ b/DEMSystems/sphereDEMSystem/sphereDEMSystem.hpp @@ -42,24 +42,29 @@ protected: // protected members - uniquePtr property_ = nullptr; + uniquePtr property_ = nullptr; - uniquePtr geometry_ = nullptr; + uniquePtr geometry_ = nullptr; - uniquePtr particles_ = nullptr; + uniquePtr particles_ = nullptr; - uniquePtr insertion_ = nullptr; + uniquePtr insertion_ = nullptr; - uniquePtr interaction_ = nullptr; + uniquePtr interaction_ = nullptr; - uniquePtr particleDistribution_=nullptr; + uniquePtr particleDistribution_=nullptr; // to be used for CPU communications - ViewType1D parVelocity_; + ViewType1D velocityHost_; - ViewType1D parPosition_; + ViewType1D positionHost_; + + ViewType1D diameterHost_; + + bool requireRVel_ = false; + + ViewType1D rVelocityHost_; - ViewType1D parDiameter_; // protected member functions auto& Property() @@ -92,7 +97,8 @@ public: word demSystemName, const std::vector& domains, int argc, - char* argv[]); + char* argv[], + bool requireRVel=false); virtual ~sphereDEMSystem(); @@ -110,15 +116,23 @@ public: int32 numParInDomain(int32 di)const override; - std::vector numParInDomain()const override; + std::vector numParInDomains()const override; span parIndexInDomain(int32 di)const override; - span parDiameter() override; + span diameter() override; - span parVelocity() override; + span acceleration() override; - span parPosition() override; + span velocity() override; + + span position() override; + + span rAcceleration() override; + + span rVelocity() override; + + span rPosition() override; span parFluidForce() override; diff --git a/DEMSystems/sphereDEMSystem/sphereFluidParticles.cpp b/DEMSystems/sphereDEMSystem/sphereFluidParticles.cpp index e1dfd357..4866bb5b 100644 --- a/DEMSystems/sphereDEMSystem/sphereFluidParticles.cpp +++ b/DEMSystems/sphereDEMSystem/sphereFluidParticles.cpp @@ -29,29 +29,25 @@ pFlow::sphereFluidParticles::sphereFluidParticles( : sphereParticles(control, prop), fluidForce_( - this->time().emplaceObject( - objectFile( - "fluidForce", - "", - objectFile::READ_IF_PRESENT, - objectFile::WRITE_ALWAYS - ), - pStruct(), - zero3 - ) - ), + objectFile( + "fluidForce", + "", + objectFile::READ_IF_PRESENT, + objectFile::WRITE_ALWAYS + ), + dynPointStruct(), + zero3 + ), fluidTorque_( - this->time().emplaceObject( - objectFile( - "fluidTorque", - "", - objectFile::READ_IF_PRESENT, - objectFile::WRITE_ALWAYS - ), - pStruct(), - zero3 - ) - ) + objectFile( + "fluidTorque", + "", + objectFile::READ_IF_PRESENT, + objectFile::WRITE_NEVER + ), + dynPointStruct(), + zero3 + ) {} bool pFlow::sphereFluidParticles::beforeIteration() @@ -64,42 +60,40 @@ bool pFlow::sphereFluidParticles::beforeIteration() bool pFlow::sphereFluidParticles::iterate() { - accelerationTimer_.start(); + accelerationTimer().start(); pFlow::sphereFluidParticlesKernels::acceleration( control().g(), - mass().deviceVectorAll(), - contactForce().deviceVectorAll(), - fluidForce().deviceVectorAll(), - I().deviceVectorAll(), - contactTorque().deviceVectorAll(), - fluidTorque().deviceVectorAll(), - pStruct().activePointsMaskD(), - accelertion().deviceVectorAll(), - rAcceleration().deviceVectorAll() + mass().deviceViewAll(), + contactForce().deviceViewAll(), + fluidForce_.deviceViewAll(), + I().deviceViewAll(), + contactTorque().deviceViewAll(), + fluidTorque_.deviceViewAll(), + pStruct().activePointsMaskDevice(), + accelertion().deviceViewAll(), + rAcceleration().deviceViewAll() ); - accelerationTimer_.end(); + accelerationTimer().end(); - intCorrectTimer_.start(); + intCorrectTimer().start(); - dynPointStruct_.correct(this->dt(), accelertion_); + dynPointStruct().correct(this->dt(), accelertion()); - rVelIntegration_().correct(this->dt(), rVelocity_, rAcceleration_); + rVelIntegration().correct(this->dt(), rVelocity(), rAcceleration()); - intCorrectTimer_.end(); + intCorrectTimer().end(); return true; } void pFlow::sphereFluidParticles::fluidForceHostUpdatedSync() { - fluidForce_.modifyOnHost(); - fluidForce_.syncViews(); + copy(fluidForce_.deviceView(), fluidForceHost_); return; } void pFlow::sphereFluidParticles::fluidTorqueHostUpdatedSync() { - fluidTorque_.modifyOnHost(); - fluidTorque_.syncViews(); + copy(fluidTorque_.deviceView(), fluidTorqueHost_); return; } \ No newline at end of file diff --git a/DEMSystems/sphereDEMSystem/sphereFluidParticles.hpp b/DEMSystems/sphereDEMSystem/sphereFluidParticles.hpp index 9890dac8..db92b6d2 100644 --- a/DEMSystems/sphereDEMSystem/sphereFluidParticles.hpp +++ b/DEMSystems/sphereDEMSystem/sphereFluidParticles.hpp @@ -43,12 +43,15 @@ class sphereFluidParticles protected: /// pointField of rotational acceleration of particles on device - realx3PointField_HD& fluidForce_; + realx3PointField_D fluidForce_; - realx3PointField_HD& fluidTorque_; + hostViewType1D fluidForceHost_; + realx3PointField_D fluidTorque_; - void zeroFluidForce_H() + hostViewType1D fluidTorqueHost_; + + /*void zeroFluidForce_H() { fluidForce_.fillHost(zero3); } @@ -56,7 +59,7 @@ protected: void zeroFluidTorque_H() { fluidTorque_.fillHost(zero3); - } + }*/ public: @@ -81,17 +84,16 @@ public: } - auto& fluidForceHostAll() + auto& fluidForceHost() { - return fluidForce_.hostVectorAll(); + return fluidForceHost_; } - auto& fluidTorqueHostAll() + auto& fluidTorqueHost() { - return fluidTorque_.hostVectorAll(); + return fluidTorqueHost_; } - void fluidForceHostUpdatedSync(); void fluidTorqueHostUpdatedSync(); diff --git a/DEMSystems/sphereDEMSystem/sphereFluidParticlesKernels.hpp b/DEMSystems/sphereDEMSystem/sphereFluidParticlesKernels.hpp index a8277894..b6743819 100644 --- a/DEMSystems/sphereDEMSystem/sphereFluidParticlesKernels.hpp +++ b/DEMSystems/sphereDEMSystem/sphereFluidParticlesKernels.hpp @@ -46,7 +46,7 @@ void acceleration( { auto activeRange = incld.activeRange(); - if(incld.allActive()) + if(incld.isAllActive()) { Kokkos::parallel_for( "pFlow::sphereParticlesKernels::acceleration", diff --git a/src/Particles/SphereParticles/sphereParticles/sphereParticles.hpp b/src/Particles/SphereParticles/sphereParticles/sphereParticles.hpp index 9b3bddbc..7033d800 100644 --- a/src/Particles/SphereParticles/sphereParticles/sphereParticles.hpp +++ b/src/Particles/SphereParticles/sphereParticles/sphereParticles.hpp @@ -105,7 +105,22 @@ private: virtual uniquePtr> getFieldObjectList()const override; */ +protected: + Timer& accelerationTimer() + { + return accelerationTimer_; + } + Timer& intCorrectTimer() + { + return intCorrectTimer_; + } + + integration& rVelIntegration() + { + return rVelIntegration_(); + } + public: /// construct from systemControl and property