# PhasicFlow: src/Particles/SphereParticles/sphereParticles/sphereParticles.cpp Source File

sphereParticles.cpp
Go to the documentation of this file.
/*------------------------------- 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 "sphereParticles.hpp"
#include "setFieldList.hpp"
#include "sphereParticlesKernels.hpp"
pFlow::uniquePtr<pFlow::List<pFlow::eventObserver*>>
pFlow::sphereParticles::getFieldObjectList()const
{
auto objListPtr = particles::getFieldObjectList();
objListPtr().push_back(
static_cast< eventObserver*>(&I_) );
return objListPtr;
}
bool pFlow::sphereParticles::diameterMassInertiaPropId
(
const word& shName,
real& diam,
real& mass,
real& I,
int8& propIdx
)
{
uint32 idx;
if( !shapes_.nameToIndex(shName, idx) )
{
printKeys(fatalErrorInFunction<<
" wrong shape name in the input: "<< shName<<endl<<
" available shape names are: ", shapes_.names())<<endl;
return false;
}
diam = shapes_.diameter(idx);
word materialName = shapes_.material(idx);
uint32 pIdx;
if( !property_.nameToIndex(materialName, pIdx) )
{
fatalErrorInFunction <<
" wrong material name "<< materialName <<" specified for shape "<< shName<<
" in the sphereShape dictionary.\n"<<
" available materials are "<< property_.materials()<<endl;
return false;
}
real rho = property_.density(pIdx);
mass = Pi/6.0*pow(diam,3.0)*rho;
I = 0.4 * mass * pow(diam/2.0,2.0);
propIdx= static_cast< int8 >(pIdx);
return true;
}
bool pFlow::sphereParticles::initializeParticles()
{
int32IndexContainer indices(
0,
static_cast< int32 >(shapeName_.size()));
return insertSphereParticles(shapeName_, indices);
}
bool pFlow::sphereParticles::beforeIteration()
{
particles::beforeIteration();
intPredictTimer_.start();
//INFO<<"before dyn predict"<<endINFO;
dynPointStruct_.predict(this->dt(), accelertion_);
//INFO<<"after dyn predict"<<endINFO;
//INFO<<"before revel predict"<<endINFO;
rVelIntegration_().predict(this->dt(),rVelocity_, rAcceleration_);
//INFO<<"after rvel predict"<<endINFO;
intPredictTimer_.end();
return true;
}
bool pFlow::sphereParticles::iterate()
{
accelerationTimer_.start();
//INFO<<"before accelerationTimer_ "<<endINFO;
pFlow::sphereParticlesKernels::acceleration(
control().g(),
mass().deviceVectorAll(),
contactForce().deviceVectorAll(),
I().deviceVectorAll(),
contactTorque().deviceVectorAll(),
pStruct().activePointsMaskD(),
accelertion().deviceVectorAll(),
rAcceleration().deviceVectorAll()
);
accelerationTimer_.end();
intCorrectTimer_.start();
//INFO<<"before correct dyn "<<endINFO;
dynPointStruct_.correct(this->dt(), accelertion_);
//INFO<<"after correct dyn "<<endINFO;
rVelIntegration_().correct(this->dt(), rVelocity_, rAcceleration_);
//INFO<<"after correct rvel "<<endINFO;
intCorrectTimer_.end();
return true;
}
bool pFlow::sphereParticles::afterIteration()
{
return true;
}
bool pFlow::sphereParticles::insertSphereParticles(
const wordVector& names,
const int32IndexContainer& indices
)
{
if(names.size()!= indices.size())
{
fatalErrorInFunction <<
"sizes of names ("<<names.size()<<") and indices ("
<< indices.size()<<") do not match \n";
return false;
}
auto len = names.size();
realVector diamVec(len, RESERVE());
realVector massVec(len, RESERVE());
realVector IVec(len, RESERVE());
int8Vector pIdVec(len, RESERVE());
int32Vector IdVec(len, RESERVE());
real d, m, I;
int8 pId;
ForAll(i, names )
{
if (diameterMassInertiaPropId(names[i], d, m, I, pId))
{
diamVec.push_back(d);
massVec.push_back(m);
IVec.push_back(I);
pIdVec.push_back(pId);
IdVec.push_back(idHandler_.getNextId());
}
else
{
fatalErrorInFunction<< "failed to calculate properties of shape " <<
names[i]<<endl;
return false;
}
}
if(!diameter_.insertSetElement(indices, diamVec))
{
fatalErrorInFunction<< " failed to insert diameters to the diameter field. \n";
return false;
}
if(!mass_.insertSetElement(indices, massVec))
{
fatalErrorInFunction<< " failed to insert mass to the mass field. \n";
return false;
}
if(!I_.insertSetElement(indices, IVec))
{
fatalErrorInFunction<< " failed to insert I to the I field. \n";
return false;
}
if(!propertyId_.insertSetElement(indices, pIdVec))
{
fatalErrorInFunction<< " failed to insert propertyId to the propertyId field. \n";
return false;
}
if(!id_.insertSetElement(indices, IdVec))
{
fatalErrorInFunction<< " failed to insert id to the id field. \n";
return false;
}
return true;
}
pFlow::sphereParticles::sphereParticles(
systemControl &control,
const property& prop
)
:
particles(
control,
control.settingsDict().getValOrSet(
"integrationMethod",
word("AdamsBashforth3")
)
),
property_(prop),
shapes_(
control.caseSetup().emplaceObjectOrGet<sphereShape>(
objectFile(
sphereShapeFile__,
"",
objectFile::READ_ALWAYS,
objectFile::WRITE_NEVER
)
)
),
I_(
this->time().emplaceObject<realPointField_D>(
objectFile(
"I",
"",
objectFile::READ_NEVER,
objectFile::WRITE_ALWAYS
),
pStruct(),
static_cast<real>(0.0000000001)
)
),
rVelocity_(
this->time().emplaceObject<realx3PointField_D>(
objectFile(
"rVelocity",
"",
objectFile::READ_IF_PRESENT,
objectFile::WRITE_ALWAYS
),
pStruct(),
zero3
)
),
rAcceleration_(
this->time().emplaceObject<realx3PointField_D>(
objectFile(
"rAcceleration",
"",
objectFile::READ_IF_PRESENT,
objectFile::WRITE_ALWAYS
),
pStruct(),
zero3
)
),
accelerationTimer_(
"Acceleration", &this->timers() ),
intPredictTimer_(
"Integration-predict", &this->timers() ),
intCorrectTimer_(
"Integration-correct", &this->timers() )
{
REPORT(1)<<"Creating integration method "<<greenText(this->integrationMethod())
<< " for rotational velocity."<<endREPORT;
rVelIntegration_ =
integration::create(
"rVelocity",
this->time().integration(),
this->pStruct(),
this->integrationMethod());
if( !rVelIntegration_ )
{
fatalErrorInFunction<<
" error in creating integration object for rVelocity. \n";
fatalExit;
}
if(rVelIntegration_->needSetInitialVals())
{
auto [minInd, maxInd] = pStruct().activeRange();
int32IndexContainer indexHD(minInd, maxInd);
auto n = indexHD.size();
auto index = indexHD.indicesHost();
realx3Vector rvel(n,RESERVE());
const auto hrVel = rVelocity_.hostVector();
for(auto i=0; i<n; i++)
{
rvel.push_back( hrVel[index(i)]);
}
REPORT(2)<< "Initializing the required vectors for rotational velocity integratoin\n "<<endREPORT;
rVelIntegration_->setInitialVals(indexHD, rvel);
}
if(!initializeParticles())
{
fatalExit;
}
}
bool pFlow::sphereParticles::update(const eventMessage& msg)
{
if(rVelIntegration_->needSetInitialVals())
{
auto indexHD = pStruct().insertedPointIndex();
auto n = indexHD.size();
auto index = indexHD.indicesHost();
realx3Vector rvel(n,RESERVE());
const auto hrVel = rVelocity_.hostVector();
for(auto i=0; i<n; i++)
{
rvel.push_back( hrVel[index(i)]);
}
rVelIntegration_->setInitialVals(indexHD, rvel);
}
return true;
}
bool pFlow::sphereParticles::insertParticles
(
const realx3Vector& position,
const wordVector& shapes,
const setFieldList& setField
)
{
if( position.size() != shapes.size() )
{
fatalErrorInFunction<<
" size of vectors position ("<<position.size()<<
") and shapes ("<<shapes.size()<<") are not the same. \n";
return false;
}
auto exclusionListAllPtr = getFieldObjectList();
auto newInsertedPtr = pStruct().insertPoints( position, setField, time(), exclusionListAllPtr());
if(!newInsertedPtr)
{
fatalErrorInFunction<<
" error in inserting points into pStruct. \n";
return false;
}
auto& newInserted = newInsertedPtr();
if(!shapeName_.insertSetElement(newInserted, shapes))
{
fatalErrorInFunction<<
" error in inserting shapes into sphereParticles system.\n";
return false;
}
if( !insertSphereParticles(shapes, newInserted) )
{
fatalErrorInFunction<<
"error in inserting shapes into the sphereParticles. \n";
return false;
}
auto activeR = this->activeRange();
REPORT(1)<< "Active range is "<<yellowText("["<<activeR.first<<", "<<activeR.second<<")")<<
" and number of active points is "<< cyanText(this->numActive())<<
" and pointStructure capacity is "<<cyanText(this->capacity())<<endREPORT;
return true;
}
pFlow::sphereShapeFile__
const char * sphereShapeFile__
Definition: vocabs.hpp:41
pFlow::particles::beforeIteration
bool beforeIteration() override
Definition: particles.hpp:244
endREPORT
#define endREPORT
Definition: streams.hpp:41
setFieldList.hpp
pFlow::real
float real
Definition: builtinTypes.hpp:46
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::eventMessage
Definition: eventMessage.hpp:29
pFlow::sphereShape
Definition: sphereShape.hpp:32
REPORT
#define REPORT(n)
Definition: streams.hpp:40
pFlow::sphereParticles::diameterMassInertiaPropId
bool diameterMassInertiaPropId(const word &shName, real &diam, real &mass, real &I, int8 &propIdx)
Definition: sphereParticles.cpp:37
cyanText
#define cyanText(text)
Definition: streams.hpp:34
pFlow::sphereParticles::insertSphereParticles
bool insertSphereParticles(const wordVector &names, const int32IndexContainer &indices)
Definition: sphereParticles.cpp:139
pFlow::integration
Definition: integration.hpp:35
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::sphereParticles::sphereParticles
sphereParticles(systemControl &control, const property &prop)
construct from systemControl and property
Definition: sphereParticles.cpp:219
pFlow::systemControl
Definition: systemControl.hpp:41
pFlow::printKeys
iOstream & printKeys(iOstream &os, const wordHashMap< T > &m)
pFlow::indexContainer::size
INLINE_FUNCTION_HD size_t size() const
Definition: indexContainer.hpp:107
pFlow::zero3
const realx3 zero3(0.0)
Definition: types.hpp:97
pFlow::Vector::size
auto size() const
Definition: Vector.hpp:299
pFlow::sphereParticlesKernels::acceleration
void acceleration(realx3 g, deviceViewType1D< real > mass, deviceViewType1D< realx3 > force, deviceViewType1D< real > I, deviceViewType1D< realx3 > torque, IncludeFunctionType incld, deviceViewType1D< realx3 > lAcc, deviceViewType1D< realx3 > rAcc)
Definition: sphereParticlesKernels.hpp:34
pFlow::eventObserver
Definition: eventObserver.hpp:33
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow::particles::integrationMethod
auto integrationMethod() const
Definition: particles.hpp:103
pFlow::sphereParticles::getFieldObjectList
virtual uniquePtr< List< eventObserver * > > getFieldObjectList() const override
Definition: sphereParticles.cpp:26
greenText
#define greenText(text)
Definition: streams.hpp:32
pFlow::sphereParticles::update
bool update(const eventMessage &msg) override
Definition: sphereParticles.cpp:334
pFlow::sphereParticles::afterIteration
bool afterIteration() override
after iteration step
Definition: sphereParticles.cpp:133
pFlow::particles::time
const auto & time() const
Definition: particles.hpp:95
sphereParticlesKernels.hpp
pFlow::sphereParticles::insertParticles
bool insertParticles(const realx3Vector &position, const wordVector &shapes, const setFieldList &setField) override
Insert new particles in position with specified shapes.
Definition: sphereParticles.cpp:362
RESERVE
Definition: Vector.hpp:38
pFlow::pointField
Definition: pointField.hpp:35
n
int32 n
Definition: NBSCrossLoop.hpp:24
pFlow::particles
Definition: particles.hpp:33
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::int32
int int32
Definition: builtinTypes.hpp:53
pFlow::particles::pStruct
const auto & pStruct() const
Definition: particles.hpp:118
pFlow::sphereParticles::I_
realPointField_D & I_
pointField of inertial of particles
Definition: sphereParticles.hpp:57
pFlow::setFieldList
Definition: setFieldList.hpp:32
pFlow::pow
Vector< T, Allocator > pow(const Vector< T, Allocator > &v, T e)
Definition: VectorMath.hpp:109
pFlow::particles::getFieldObjectList
virtual uniquePtr< List< eventObserver * > > getFieldObjectList() const
Definition: particles.cpp:154
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:71
pFlow::indexContainer::indicesHost
auto indicesHost() const
Definition: indexContainer.hpp:153
pFlow::sphereParticles::iterate
bool iterate() override
iterate particles
Definition: sphereParticles.cpp:104
pFlow::objectFile
Definition: objectFile.hpp:33
pFlow::integration::create
static uniquePtr< integration > create(const word &baseName, repository &owner, const pointStructure &pStruct, const word &method)
Definition: integration.cpp:40
pFlow::sphereParticles::initializeParticles
bool initializeParticles()
Definition: sphereParticles.cpp:73
pFlow::sphereParticles::beforeIteration
bool beforeIteration() override
before iteration step
Definition: sphereParticles.cpp:84
pStruct
auto & pStruct
Definition: setPointStructure.hpp:24
pFlow::property
property holds the pure properties of materials.
Definition: property.hpp:40
pFlow::sphereParticles::rVelocity_
realx3PointField_D & rVelocity_
pointField of rotational Velocity of particles on device
Definition: sphereParticles.hpp:60
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
sphereParticles.hpp
pFlow::Pi
const real Pi
Definition: numericConstants.hpp:32
pFlow::int8
signed char int8
Definition: builtinTypes.hpp:49
pFlow::sphereParticles::rVelIntegration_
uniquePtr< integration > rVelIntegration_
rotational velocity integrator
Definition: sphereParticles.hpp:66
yellowText
#define yellowText(text)
Definition: streams.hpp:30
pFlow::Vector< word >
m
int32 m
Definition: NBSCrossLoop.hpp:22
pFlow::indexContainer< int32 >