Merge pull request #136 from PhasicFlow/develop

sphereDEMSystem is updated for version 1.0
This commit is contained in:
PhasicFlow 2024-12-26 22:59:03 +03:30 committed by GitHub
commit 46e862c5e5
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
10 changed files with 151 additions and 97 deletions

View File

@ -3,7 +3,7 @@ set(SourceFiles
domainDistribute/domainDistribute.cpp domainDistribute/domainDistribute.cpp
DEMSystem/DEMSystem.cpp DEMSystem/DEMSystem.cpp
sphereDEMSystem/sphereFluidParticles.cpp sphereDEMSystem/sphereFluidParticles.cpp
#sphereDEMSystem/sphereDEMSystem.cpp sphereDEMSystem/sphereDEMSystem.cpp
# #
) )

View File

@ -61,6 +61,7 @@ public:
DEMSystem(const DEMSystem&)=delete; DEMSystem(const DEMSystem&)=delete;
/// @brief no assignment
DEMSystem& operator = (const DEMSystem&)=delete; DEMSystem& operator = (const DEMSystem&)=delete;
create_vCtor( create_vCtor(
@ -118,7 +119,7 @@ public:
span<const int32> parIndexInDomain(int32 domIndx)const = 0; span<const int32> parIndexInDomain(int32 domIndx)const = 0;
virtual virtual
span<real> parDiameter() = 0; span<real> diameter() = 0;
virtual virtual
span<realx3> acceleration()=0; span<realx3> acceleration()=0;

View File

@ -33,7 +33,7 @@ void pFlow::domainDistribute::clcDomains(const std::vector<box>& domains)
pFlow::domainDistribute::domainDistribute( pFlow::domainDistribute::domainDistribute(
const Vector<box>& domains, const std::vector<box>& domains,
real maxBoundingBox) real maxBoundingBox)
: :
numDomains_(domains.size()), numDomains_(domains.size()),

View File

@ -52,7 +52,7 @@ protected:
public: public:
domainDistribute( domainDistribute(
const Vector<box>& domains, const std::vector<box>& domains,
real maxBoundingBox); real maxBoundingBox);
~domainDistribute()=default; ~domainDistribute()=default;

View File

@ -19,6 +19,7 @@ Licence:
-----------------------------------------------------------------------------*/ -----------------------------------------------------------------------------*/
#include "sphereDEMSystem.hpp" #include "sphereDEMSystem.hpp"
#include "vocabs.hpp"
bool pFlow::sphereDEMSystem::loop() bool pFlow::sphereDEMSystem::loop()
{ {
@ -26,16 +27,15 @@ bool pFlow::sphereDEMSystem::loop()
do do
{ {
// //
if(! insertion_().insertParticles( if(! insertion_().insertParticles(
Control().time().currentIter(),
Control().time().currentTime(), Control().time().currentTime(),
Control().time().dt() ) ) Control().time().dt() ) )
{ {
fatalError<< fatalError<<
"particle insertion failed in sphereDFlow solver.\n"; "particle insertion failed in sphereDEMSystem.\n";
return false; return false;
} }
geometry_->beforeIteration(); geometry_->beforeIteration();
@ -63,29 +63,31 @@ pFlow::sphereDEMSystem::sphereDEMSystem(
word demSystemName, word demSystemName,
const std::vector<box>& domains, const std::vector<box>& domains,
int argc, int argc,
char* argv[]) char* argv[],
bool requireRVel)
: :
DEMSystem(demSystemName, domains, argc, argv) DEMSystem(demSystemName, domains, argc, argv),
requireRVel_(requireRVel)
{ {
REPORT(0)<<"\nReading proprties . . . "<<endREPORT; REPORT(0)<<"\nReading proprties . . . "<<END_REPORT;
property_ = makeUnique<property>( property_ = makeUnique<property>(
Control().caseSetup().path()+propertyFile__); propertyFile__,
Control().caseSetup().path());
REPORT(0)<< "\nCreating surface geometry for sphereDEMSystem . . . "<<endREPORT; REPORT(0)<< "\nCreating surface geometry for sphereDEMSystem . . . "<<END_REPORT;
geometry_ = geometry::create(Control(), Property()); geometry_ = geometry::create(Control(), Property());
REPORT(0)<<"\nReading sphere particles . . ."<<endREPORT; REPORT(0)<<"\nReading sphere particles . . ."<<END_REPORT;
particles_ = makeUnique<sphereFluidParticles>(Control(), Property()); particles_ = makeUnique<sphereFluidParticles>(Control(), Property());
insertion_ = makeUnique<sphereInsertion>( insertion_ = makeUnique<sphereInsertion>(
Control().caseSetup().path()+insertionFile__,
particles_(), particles_(),
particles_().shapes()); particles_().spheres());
REPORT(0)<<"\nCreating interaction model for sphere-sphere contact and sphere-wall contact . . ."<<endREPORT; REPORT(0)<<"\nCreating interaction model for sphere-sphere contact and sphere-wall contact . . ."<<END_REPORT;
interaction_ = interaction::create( interaction_ = interaction::create(
Control(), Control(),
Particles(), Particles(),
@ -98,6 +100,7 @@ pFlow::sphereDEMSystem::sphereDEMSystem(
} }
pFlow::sphereDEMSystem::~sphereDEMSystem() pFlow::sphereDEMSystem::~sphereDEMSystem()
{ {
@ -119,8 +122,8 @@ bool pFlow::sphereDEMSystem::updateParticleDistribution(
} }
if(!particleDistribution_->locateParticles( if(!particleDistribution_->locateParticles(
parPosition_, positionHost_,
particles_->pStruct().activePointsMaskH())) particles_->pStruct().activePointsMaskHost()))
{ {
fatalErrorInFunction<< fatalErrorInFunction<<
"error in locating particles among sub-domains"<<endl; "error in locating particles among sub-domains"<<endl;
@ -137,7 +140,7 @@ pFlow::int32
} }
std::vector<pFlow::int32> std::vector<pFlow::int32>
pFlow::sphereDEMSystem::numParInDomain()const pFlow::sphereDEMSystem::numParInDomains()const
{ {
const auto& distribute = particleDistribution_(); const auto& distribute = particleDistribution_();
int32 numDomains = distribute.numDomains(); int32 numDomains = distribute.numDomains();
@ -156,31 +159,51 @@ pFlow::sphereDEMSystem::parIndexInDomain(int32 di)const
return particleDistribution_->particlesInDomain(di); return particleDistribution_->particlesInDomain(di);
} }
pFlow::span<pFlow::real> pFlow::sphereDEMSystem::parDiameter() pFlow::span<pFlow::real> pFlow::sphereDEMSystem::diameter()
{ {
return span<real>(parDiameter_.data(), parDiameter_.size()); return span<real>(diameterHost_.data(), diameterHost_.size());
} }
pFlow::span<pFlow::realx3> pFlow::sphereDEMSystem::parVelocity() pFlow::span<pFlow::realx3> pFlow::sphereDEMSystem::acceleration()
{ {
return span<realx3>(parVelocity_.data(), parVelocity_.size()); return span<realx3>(nullptr, 0);
} }
pFlow::span<pFlow::realx3> pFlow::sphereDEMSystem::parPosition() pFlow::span<pFlow::realx3> pFlow::sphereDEMSystem::velocity()
{ {
return span<realx3>(parPosition_.data(), parPosition_.size()); return span<realx3>(velocityHost_.data(), velocityHost_.size());
}
pFlow::span<pFlow::realx3> pFlow::sphereDEMSystem::position()
{
return span<realx3>(positionHost_.data(), positionHost_.size());
}
pFlow::span<pFlow::realx3> pFlow::sphereDEMSystem::rAcceleration()
{
return span<realx3>(nullptr, 0);
}
pFlow::span<pFlow::realx3> pFlow::sphereDEMSystem::rVelocity()
{
return span<realx3>(rVelocityHost_.data(), rVelocityHost_.size());
}
pFlow::span<pFlow::realx3> pFlow::sphereDEMSystem::rPosition()
{
return span<realx3>(nullptr, 0);
} }
pFlow::span<pFlow::realx3> pFlow::sphereDEMSystem::parFluidForce() pFlow::span<pFlow::realx3> pFlow::sphereDEMSystem::parFluidForce()
{ {
auto& hVec = particles_->fluidForceHostAll(); auto& hVec = particles_->fluidForceHost();
return span<realx3>(hVec.data(), hVec.size()); return span<realx3>(hVec.data(), hVec.size());
} }
pFlow::span<pFlow::realx3> pFlow::sphereDEMSystem::parFluidTorque() pFlow::span<pFlow::realx3> pFlow::sphereDEMSystem::parFluidTorque()
{ {
auto& hVec = particles_->fluidTorqueHostAll(); auto& hVec = particles_->fluidTorqueHost();
return span<realx3>(hVec.data(), hVec.size()); return span<realx3>(hVec.data(), hVec.size());
} }
@ -198,9 +221,14 @@ bool pFlow::sphereDEMSystem::sendFluidTorqueToDEM()
bool pFlow::sphereDEMSystem::beforeIteration() bool pFlow::sphereDEMSystem::beforeIteration()
{ {
parVelocity_ = particles_->dynPointStruct().velocityHostAll(); velocityHost_ = std::as_const(particles_()).velocity().hostView();
parPosition_ = particles_->dynPointStruct().pointPositionHostAll(); positionHost_ = std::as_const(particles_()).pointPosition().hostView();
parDiameter_ = particles_->diameter().hostVectorAll(); diameterHost_ = particles_->diameter().hostView();
if(requireRVel_)
rVelocityHost_ = std::as_const(particles_()).rVelocity().hostView();
return true; return true;
} }

View File

@ -42,24 +42,29 @@ protected:
// protected members // protected members
uniquePtr<property> property_ = nullptr; uniquePtr<property> property_ = nullptr;
uniquePtr<geometry> geometry_ = nullptr; uniquePtr<geometry> geometry_ = nullptr;
uniquePtr<sphereFluidParticles> particles_ = nullptr; uniquePtr<sphereFluidParticles> particles_ = nullptr;
uniquePtr<sphereInsertion> insertion_ = nullptr; uniquePtr<sphereInsertion> insertion_ = nullptr;
uniquePtr<interaction> interaction_ = nullptr; uniquePtr<interaction> interaction_ = nullptr;
uniquePtr<domainDistribute> particleDistribution_=nullptr; uniquePtr<domainDistribute> particleDistribution_=nullptr;
// to be used for CPU communications // to be used for CPU communications
ViewType1D<realx3, HostSpace> parVelocity_; ViewType1D<realx3, HostSpace> velocityHost_;
ViewType1D<realx3, HostSpace> parPosition_; ViewType1D<realx3, HostSpace> positionHost_;
ViewType1D<real, HostSpace> diameterHost_;
bool requireRVel_ = false;
ViewType1D<realx3, HostSpace> rVelocityHost_;
ViewType1D<real, HostSpace> parDiameter_;
// protected member functions // protected member functions
auto& Property() auto& Property()
@ -92,7 +97,8 @@ public:
word demSystemName, word demSystemName,
const std::vector<box>& domains, const std::vector<box>& domains,
int argc, int argc,
char* argv[]); char* argv[],
bool requireRVel=false);
virtual ~sphereDEMSystem(); virtual ~sphereDEMSystem();
@ -110,15 +116,23 @@ public:
int32 numParInDomain(int32 di)const override; int32 numParInDomain(int32 di)const override;
std::vector<int32> numParInDomain()const override; std::vector<int32> numParInDomains()const override;
span<const int32> parIndexInDomain(int32 di)const override; span<const int32> parIndexInDomain(int32 di)const override;
span<real> parDiameter() override; span<real> diameter() override;
span<realx3> parVelocity() override; span<realx3> acceleration() override;
span<realx3> parPosition() override; span<realx3> velocity() override;
span<realx3> position() override;
span<realx3> rAcceleration() override;
span<realx3> rVelocity() override;
span<realx3> rPosition() override;
span<realx3> parFluidForce() override; span<realx3> parFluidForce() override;

View File

@ -29,29 +29,25 @@ pFlow::sphereFluidParticles::sphereFluidParticles(
: :
sphereParticles(control, prop), sphereParticles(control, prop),
fluidForce_( fluidForce_(
this->time().emplaceObject<realx3PointField_HD>( objectFile(
objectFile( "fluidForce",
"fluidForce", "",
"", objectFile::READ_IF_PRESENT,
objectFile::READ_IF_PRESENT, objectFile::WRITE_ALWAYS
objectFile::WRITE_ALWAYS ),
), dynPointStruct(),
pStruct(), zero3
zero3 ),
)
),
fluidTorque_( fluidTorque_(
this->time().emplaceObject<realx3PointField_HD>( objectFile(
objectFile( "fluidTorque",
"fluidTorque", "",
"", objectFile::READ_IF_PRESENT,
objectFile::READ_IF_PRESENT, objectFile::WRITE_NEVER
objectFile::WRITE_ALWAYS ),
), dynPointStruct(),
pStruct(), zero3
zero3 )
)
)
{} {}
bool pFlow::sphereFluidParticles::beforeIteration() bool pFlow::sphereFluidParticles::beforeIteration()
@ -64,42 +60,40 @@ bool pFlow::sphereFluidParticles::beforeIteration()
bool pFlow::sphereFluidParticles::iterate() bool pFlow::sphereFluidParticles::iterate()
{ {
accelerationTimer_.start(); accelerationTimer().start();
pFlow::sphereFluidParticlesKernels::acceleration( pFlow::sphereFluidParticlesKernels::acceleration(
control().g(), control().g(),
mass().deviceVectorAll(), mass().deviceViewAll(),
contactForce().deviceVectorAll(), contactForce().deviceViewAll(),
fluidForce().deviceVectorAll(), fluidForce_.deviceViewAll(),
I().deviceVectorAll(), I().deviceViewAll(),
contactTorque().deviceVectorAll(), contactTorque().deviceViewAll(),
fluidTorque().deviceVectorAll(), fluidTorque_.deviceViewAll(),
pStruct().activePointsMaskD(), pStruct().activePointsMaskDevice(),
accelertion().deviceVectorAll(), accelertion().deviceViewAll(),
rAcceleration().deviceVectorAll() 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; return true;
} }
void pFlow::sphereFluidParticles::fluidForceHostUpdatedSync() void pFlow::sphereFluidParticles::fluidForceHostUpdatedSync()
{ {
fluidForce_.modifyOnHost(); copy(fluidForce_.deviceView(), fluidForceHost_);
fluidForce_.syncViews();
return; return;
} }
void pFlow::sphereFluidParticles::fluidTorqueHostUpdatedSync() void pFlow::sphereFluidParticles::fluidTorqueHostUpdatedSync()
{ {
fluidTorque_.modifyOnHost(); copy(fluidTorque_.deviceView(), fluidTorqueHost_);
fluidTorque_.syncViews();
return; return;
} }

View File

@ -43,12 +43,15 @@ class sphereFluidParticles
protected: protected:
/// pointField of rotational acceleration of particles on device /// pointField of rotational acceleration of particles on device
realx3PointField_HD& fluidForce_; realx3PointField_D fluidForce_;
realx3PointField_HD& fluidTorque_; hostViewType1D<realx3> fluidForceHost_;
realx3PointField_D fluidTorque_;
void zeroFluidForce_H() hostViewType1D<realx3> fluidTorqueHost_;
/*void zeroFluidForce_H()
{ {
fluidForce_.fillHost(zero3); fluidForce_.fillHost(zero3);
} }
@ -56,7 +59,7 @@ protected:
void zeroFluidTorque_H() void zeroFluidTorque_H()
{ {
fluidTorque_.fillHost(zero3); fluidTorque_.fillHost(zero3);
} }*/
public: 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 fluidForceHostUpdatedSync();
void fluidTorqueHostUpdatedSync(); void fluidTorqueHostUpdatedSync();

View File

@ -46,7 +46,7 @@ void acceleration(
{ {
auto activeRange = incld.activeRange(); auto activeRange = incld.activeRange();
if(incld.allActive()) if(incld.isAllActive())
{ {
Kokkos::parallel_for( Kokkos::parallel_for(
"pFlow::sphereParticlesKernels::acceleration", "pFlow::sphereParticlesKernels::acceleration",

View File

@ -105,7 +105,22 @@ private:
virtual uniquePtr<List<eventObserver*>> getFieldObjectList()const override; virtual uniquePtr<List<eventObserver*>> getFieldObjectList()const override;
*/ */
protected:
Timer& accelerationTimer()
{
return accelerationTimer_;
}
Timer& intCorrectTimer()
{
return intCorrectTimer_;
}
integration& rVelIntegration()
{
return rVelIntegration_();
}
public: public:
/// construct from systemControl and property /// construct from systemControl and property