modification for coupling, data transfer

This commit is contained in:
hamidrezanorouzi
2023-01-02 14:31:40 +03:30
parent 7e858a116f
commit fef0c4fe96
14 changed files with 499 additions and 67 deletions

View File

@ -28,17 +28,8 @@ pFlow::sphereDEMSystem::sphereDEMSystem(
char* argv[])
:
DEMSystem(demSystemName, domains, argc, argv)
{
REPORT(0)<<"Initializing host/device execution spaces . . . \n";
REPORT(1)<<"Host execution space is "<< greenText(DefaultHostExecutionSpace::name())<<endREPORT;
REPORT(1)<<"Device execution space is "<<greenText(DefaultExecutionSpace::name())<<endREPORT;
// initialize Kokkos
Kokkos::initialize( argc, argv );
{
REPORT(0)<<"\nReading proprties . . . "<<endREPORT;
property_ = makeUnique<property>(
Control().caseSetup().path()+propertyFile__);
@ -47,7 +38,7 @@ pFlow::sphereDEMSystem::sphereDEMSystem(
geometry_ = geometry::create(Control(), Property());
REPORT(0)<<"\nReading sphere particles . . ."<<endREPORT;
particles_ = makeUnique<sphereParticles>(Control(), Property());
particles_ = makeUnique<sphereFluidParticles>(Control(), Property());
REPORT(0)<<"\nCreating interaction model for sphere-sphere contact and sphere-wall contact . . ."<<endREPORT;
@ -65,18 +56,35 @@ pFlow::sphereDEMSystem::sphereDEMSystem(
pFlow::sphereDEMSystem::~sphereDEMSystem()
{
interaction_.reset();
insertion_.reset();
particles_.reset();
geometry_.reset();
property_.reset();
Control_.reset();
output<< "\nFinalizing host/device execution space ...."<<endl;
Kokkos::finalize();
}
bool pFlow::sphereDEMSystem::updateParticleDistribution(
real extentFraction,
const std::vector<box> domains)
{
if(!particleDistribution_->changeDomainsSize(
extentFraction,
maxBounndingSphereSize(),
domains))
{
fatalErrorInFunction<<
"cannot change the domain size"<<endl;
return false;
}
if(!particleDistribution_->locateParticles(
parPosition_,
particles_->pStruct().activePointsMaskH()))
{
fatalErrorInFunction<<
"error in locating particles among sub-domains"<<endl;
return false;
}
return true;
}
pFlow::int32
pFlow::sphereDEMSystem::numParInDomain(int32 di)const
@ -104,24 +112,54 @@ pFlow::sphereDEMSystem::parIndexInDomain(int32 di)const
return particleDistribution_->particlesInDomain(di);
}
bool pFlow::sphereDEMSystem::changeDomainsSizeUpdateParticles(
const std::vector<box>& domains)
{
if( !particleDistribution_->changeDomainsSize(domains))
return false;
// should update list of particles here
//************************************************************************************************
notImplementedFunction;
return false;
pFlow::span<pFlow::real> pFlow::sphereDEMSystem::parDiameter()
{
return span<real>(parDiameter_.data(), parDiameter_.size());
}
bool pFlow::sphereDEMSystem::updateParticles()
pFlow::span<pFlow::realx3> pFlow::sphereDEMSystem::parVelocity()
{
notImplementedFunction;
return false;
return span<realx3>(parVelocity_.data(), parVelocity_.size());
}
pFlow::span<pFlow::realx3> pFlow::sphereDEMSystem::parPosition()
{
return span<realx3>(parPosition_.data(), parPosition_.size());
}
pFlow::span<pFlow::realx3> pFlow::sphereDEMSystem::parFluidForce()
{
auto& hVec = particles_->fluidTorqueHostAll();
return span<realx3>(hVec.data(), hVec.size());
}
pFlow::span<pFlow::realx3> pFlow::sphereDEMSystem::parFluidTorque()
{
auto& hVec = particles_->fluidForceHostAll();
return span<realx3>(hVec.data(), hVec.size());
}
bool pFlow::sphereDEMSystem::sendFluidForceToDEM()
{
particles_->fluidForceHostUpdatedSync();
return true;
}
bool pFlow::sphereDEMSystem::sendFluidTorqueToDEM()
{
particles_->fluidTorqueHostUpdatedSync();
return true;
}
bool pFlow::sphereDEMSystem::beforeIteration()
{
parVelocity_ = particles_->dynPointStruct().velocityHostAll();
parPosition_ = particles_->dynPointStruct().pointPositionHostAll();
parDiameter_ = particles_->diameter().hostVectorAll();
return true;
}
bool pFlow::sphereDEMSystem::iterate(
int32 n,
real timeToWrite,

View File

@ -25,7 +25,7 @@ Licence:
#include "property.hpp"
#include "uniquePtr.hpp"
#include "geometry.hpp"
#include "sphereParticles.hpp"
#include "sphereFluidParticles.hpp"
#include "interaction.hpp"
#include "Insertions.hpp"
#include "domainDistribute.hpp"
@ -46,7 +46,7 @@ protected:
uniquePtr<geometry> geometry_ = nullptr;
uniquePtr<sphereParticles> particles_ = nullptr;
uniquePtr<sphereFluidParticles> particles_ = nullptr;
uniquePtr<sphereInsertion> insertion_ = nullptr;
@ -54,6 +54,13 @@ protected:
uniquePtr<domainDistribute> particleDistribution_=nullptr;
// to be used for CPU communications
ViewType1D<realx3, HostSpace> parVelocity_;
ViewType1D<realx3, HostSpace> parPosition_;
ViewType1D<real, HostSpace> parDiameter_;
// protected member functions
auto& Property()
{
@ -97,6 +104,7 @@ public:
word);
bool updateParticleDistribution(real extentFraction, const std::vector<box> domains) override;
int32 numParInDomain(int32 di)const override;
@ -104,9 +112,21 @@ public:
span<const int32> parIndexInDomain(int32 di)const override;
bool changeDomainsSizeUpdateParticles(const std::vector<box>& domains) override;
span<real> parDiameter() override;
bool updateParticles() override;
span<realx3> parVelocity() override;
span<realx3> parPosition() override;
span<realx3> parFluidForce() override;
span<realx3> parFluidTorque() override;
bool sendFluidForceToDEM() override;
bool sendFluidTorqueToDEM() override;
bool beforeIteration() override;
bool iterate(int32 n, real timeToWrite, word timeName) override;

View File

@ -0,0 +1,100 @@
/*------------------------------- 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 "sphereFluidParticles.hpp"
#include "sphereFluidParticlesKernels.hpp"
pFlow::sphereFluidParticles::sphereFluidParticles(
systemControl &control,
const property& prop
)
:
sphereParticles(control, prop),
fluidForce_(
this->time().emplaceObject<realx3PointField_HD>(
objectFile(
"fluidForce",
"",
objectFile::READ_IF_PRESENT,
objectFile::WRITE_ALWAYS
),
pStruct(),
zero3
)
),
fluidTorque_(
this->time().emplaceObject<realx3PointField_HD>(
objectFile(
"fluidTorque",
"",
objectFile::READ_IF_PRESENT,
objectFile::WRITE_ALWAYS
),
pStruct(),
zero3
)
)
{}
bool pFlow::sphereFluidParticles::iterate()
{
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()
);
accelerationTimer_.end();
intCorrectTimer_.start();
dynPointStruct_.correct(this->dt(), accelertion_);
rVelIntegration_().correct(this->dt(), rVelocity_, rAcceleration_);
intCorrectTimer_.end();
return true;
}
void pFlow::sphereFluidParticles::fluidForceHostUpdatedSync()
{
fluidForce_.modifyOnHost();
fluidForce_.syncViews();
return;
}
void pFlow::sphereFluidParticles::fluidTorqueHostUpdatedSync()
{
fluidTorque_.modifyOnHost();
fluidTorque_.syncViews();
return;
}

View File

@ -0,0 +1,91 @@
/*------------------------------- 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.
-----------------------------------------------------------------------------*/
/*!
@class pFlow::sphereParticles
@brief Class for managing spherical particles
This is a top-level class that contains the essential components for
defining spherical prticles in a DEM simulation.
*/
#ifndef __sphereFluidParticles_hpp__
#define __sphereFluidParticles_hpp__
#include "sphereParticles.hpp"
namespace pFlow
{
class sphereFluidParticles
:
public sphereParticles
{
protected:
/// pointField of rotational acceleration of particles on device
realx3PointField_HD& fluidForce_;
realx3PointField_HD& fluidTorque_;
public:
/// construct from systemControl and property
sphereFluidParticles(systemControl &control, const property& prop);
/// iterate particles
bool iterate() override;
auto& fluidForce()
{
return fluidForce_;
}
auto& fluidTorque()
{
return fluidTorque_;
}
auto& fluidForceHostAll()
{
return fluidForce_.hostVectorAll();
}
auto& fluidTorqueHostAll()
{
return fluidTorque_.hostVectorAll();
}
void fluidForceHostUpdatedSync();
void fluidTorqueHostUpdatedSync();
}; //sphereFluidParticles
} // pFlow
#endif //__sphereFluidParticles_hpp__

View File

@ -0,0 +1,79 @@
/*------------------------------- 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 __sphereFluidParticlesKernels_hpp__
#define __sphereFluidParticlesKernels_hpp__
namespace pFlow::sphereFluidParticlesKernels
{
using rpAcceleration = Kokkos::RangePolicy<
DefaultExecutionSpace,
Kokkos::Schedule<Kokkos::Static>,
Kokkos::IndexType<int32>
>;
template<typename IncludeFunctionType>
void acceleration(
realx3 g,
deviceViewType1D<real> mass,
deviceViewType1D<realx3> force,
deviceViewType1D<realx3> fluidForce,
deviceViewType1D<real> I,
deviceViewType1D<realx3> torque,
deviceViewType1D<realx3> fluidTorque,
IncludeFunctionType incld,
deviceViewType1D<realx3> lAcc,
deviceViewType1D<realx3> rAcc
)
{
auto activeRange = incld.activeRange();
if(incld.allActive())
{
Kokkos::parallel_for(
"pFlow::sphereParticlesKernels::acceleration",
rpAcceleration(activeRange.first, activeRange.second),
LAMBDA_HD(int32 i){
lAcc[i] = (force[i]+fluidForce[i])/mass[i] + g;
rAcc[i] = (torque[i]+fluidTorque[i])/I[i];
});
}
else
{
Kokkos::parallel_for(
"pFlow::sphereParticlesKernels::acceleration",
rpAcceleration(activeRange.first, activeRange.second),
LAMBDA_HD(int32 i){
if(incld(i))
{
lAcc[i] = (force[i]+fluidForce[i])/mass[i] + g;
rAcc[i] = (torque[i]+fluidTorque[i])/I[i];
}
});
}
Kokkos::fence();
}
}
#endif