mirror of
https://github.com/PhasicFlow/phasicFlow.git
synced 2025-06-22 16:28:30 +00:00
src folder
This commit is contained in:
353
src/Particles/SphereParticles/sphereParticles/sphereParticles.C
Normal file
353
src/Particles/SphereParticles/sphereParticles/sphereParticles.C
Normal file
@ -0,0 +1,353 @@
|
||||
/*------------------------------- 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.H"
|
||||
#include "setFieldList.H"
|
||||
#include "sphereParticlesKernels.H"
|
||||
|
||||
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, shapeName_.size());
|
||||
return insertSphereParticles(shapeName_, indices);
|
||||
}
|
||||
|
||||
|
||||
bool pFlow::sphereParticles::beforeIteration()
|
||||
{
|
||||
particles::beforeIteration();
|
||||
|
||||
intPredictTimer_.start();
|
||||
dynPointStruct_.predict(this->dt(), accelertion_);
|
||||
rVelIntegration_().predict(this->dt(),rVelocity_, rAcceleration_);
|
||||
intPredictTimer_.end();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool pFlow::sphereParticles::iterate()
|
||||
{
|
||||
accelerationTimer_.start();
|
||||
pFlow::sphereParticlesKernels::acceleration(
|
||||
control().g(),
|
||||
mass().deviceVectorAll(),
|
||||
contactForce().deviceVectorAll(),
|
||||
I().deviceVectorAll(),
|
||||
contactTorque().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;
|
||||
}
|
||||
|
||||
|
||||
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(!initializeParticles())
|
||||
{
|
||||
fatalExit;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
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, 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;
|
||||
}
|
||||
|
||||
for(auto sfEntry:setField)
|
||||
{
|
||||
if(!sfEntry.setPointFieldSelectedAll( time(), newInserted, false ))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;
|
||||
|
||||
}
|
191
src/Particles/SphereParticles/sphereParticles/sphereParticles.H
Normal file
191
src/Particles/SphereParticles/sphereParticles/sphereParticles.H
Normal file
@ -0,0 +1,191 @@
|
||||
/*------------------------------- 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 __sphereParticles_H__
|
||||
#define __sphereParticles_H__
|
||||
|
||||
#include "systemControl.H"
|
||||
#include "particles.H"
|
||||
#include "sphereShape.H"
|
||||
#include "property.H"
|
||||
#include "indexContainer.H"
|
||||
|
||||
|
||||
|
||||
namespace pFlow
|
||||
{
|
||||
|
||||
class sphereParticles
|
||||
:
|
||||
public particles
|
||||
{
|
||||
protected:
|
||||
|
||||
/// reference to material properties
|
||||
const property& property_;
|
||||
|
||||
/// reference to shapes
|
||||
sphereShape& shapes_;
|
||||
|
||||
/// pointField of inertial of particles
|
||||
realPointField_D& I_;
|
||||
|
||||
/// pointField of rotational Velocity of particles on device
|
||||
realx3PointField_D& rVelocity_;
|
||||
|
||||
/// pointField of rotational acceleration of particles on device
|
||||
realx3PointField_D& rAcceleration_;
|
||||
|
||||
/// rotational velocity integrator
|
||||
uniquePtr<integration> rVelIntegration_ = nullptr;
|
||||
|
||||
/// timer for acceleration computations
|
||||
Timer accelerationTimer_;
|
||||
|
||||
/// timer for integration computations (prediction step)
|
||||
Timer intPredictTimer_;
|
||||
|
||||
/// timer for integration computations (correction step)
|
||||
Timer intCorrectTimer_;
|
||||
|
||||
bool diameterMassInertiaPropId(const word& shName, real& diam, real& mass, real& I, int8& propIdx);
|
||||
|
||||
bool initializeParticles();
|
||||
|
||||
bool insertSphereParticles(const wordVector& names, const int32IndexContainer& indices);
|
||||
|
||||
virtual uniquePtr<List<eventObserver*>> getFieldObjectList()const override;
|
||||
|
||||
public:
|
||||
|
||||
/// construct from systemControl and property
|
||||
sphereParticles(systemControl &control, const property& prop);
|
||||
|
||||
/// no copy constructor
|
||||
sphereParticles(const sphereParticles&) = delete;
|
||||
|
||||
/// move constructor
|
||||
sphereParticles(sphereParticles&&) = default;
|
||||
|
||||
/// no copy-assignement
|
||||
sphereParticles& operator=(const sphereParticles&) = delete;
|
||||
|
||||
/// move-assignement
|
||||
sphereParticles& operator=(sphereParticles&&) = default;
|
||||
|
||||
virtual ~sphereParticles()=default;
|
||||
|
||||
/**
|
||||
* Insert new particles in position with specified shapes
|
||||
*
|
||||
* This function is involked by inserted object to insert new set of particles
|
||||
* into the simulation.
|
||||
* \param position position of new particles
|
||||
* \param shape shape of new particles
|
||||
* \param setField initial value of the selected fields for new particles
|
||||
*/
|
||||
bool insertParticles
|
||||
(
|
||||
const realx3Vector& position,
|
||||
const wordVector& shapes,
|
||||
const setFieldList& setField
|
||||
) override ;
|
||||
|
||||
/// const reference to shapes object
|
||||
const auto& shapes()const
|
||||
{
|
||||
return shapes_;
|
||||
}
|
||||
|
||||
/// const reference to inertia pointField
|
||||
const auto& I()const
|
||||
{
|
||||
return I_;
|
||||
}
|
||||
|
||||
/// reference to inertia pointField
|
||||
auto& I()
|
||||
{
|
||||
return I_;
|
||||
}
|
||||
|
||||
const realx3Vector_D rVelocity()const
|
||||
{
|
||||
return rVelocity_;
|
||||
}
|
||||
|
||||
const realVector_D& boundingSphere()const override
|
||||
{
|
||||
return this->diameter();
|
||||
}
|
||||
|
||||
word shapeTypeName() const override
|
||||
{
|
||||
return "sphere";
|
||||
}
|
||||
|
||||
void boundingSphereMinMax(
|
||||
real& minDiam,
|
||||
real& maxDiam )const override
|
||||
{
|
||||
shapes_.diameterMinMax(minDiam, maxDiam);
|
||||
}
|
||||
|
||||
bool update(const eventMessage& msg) override
|
||||
{
|
||||
CONSUME_PARAM(msg);
|
||||
return true;
|
||||
}
|
||||
|
||||
realx3PointField_D& rAcceleration() override
|
||||
{
|
||||
return rAcceleration_;
|
||||
}
|
||||
|
||||
const realx3PointField_D& rAcceleration() const override
|
||||
{
|
||||
return rAcceleration_;
|
||||
}
|
||||
|
||||
/// before iteration step
|
||||
bool beforeIteration() override;
|
||||
|
||||
/// iterate particles
|
||||
bool iterate() override;
|
||||
|
||||
/// after iteration step
|
||||
bool afterIteration() override;
|
||||
|
||||
|
||||
|
||||
}; //sphereParticles
|
||||
|
||||
} // pFlow
|
||||
|
||||
#endif //__sphereParticles_H__
|
@ -0,0 +1,77 @@
|
||||
/*------------------------------- 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 __sphereParticlesKernels_H__
|
||||
#define __sphereParticlesKernels_H__
|
||||
|
||||
namespace pFlow::sphereParticlesKernels
|
||||
{
|
||||
|
||||
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<real> I,
|
||||
deviceViewType1D<realx3> torque,
|
||||
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]/mass[i] + g;
|
||||
rAcc[i] = torque[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]/mass[i] + g;
|
||||
rAcc[i] = torque[i]/I[i];
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
Kokkos::fence();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
#endif
|
204
src/Particles/SphereParticles/sphereShape/sphereShape.C
Normal file
204
src/Particles/SphereParticles/sphereShape/sphereShape.C
Normal file
@ -0,0 +1,204 @@
|
||||
/*------------------------------- 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 "sphereShape.H"
|
||||
#include "dictionary.H"
|
||||
#include "vocabs.H"
|
||||
#include "streams.H"
|
||||
|
||||
|
||||
bool pFlow::sphereShape::insertNames
|
||||
(
|
||||
const wordVector& names
|
||||
)
|
||||
{
|
||||
names_.clear();
|
||||
uint32 i=0;
|
||||
for(const auto& nm:names)
|
||||
{
|
||||
if(!names_.insertIf(nm, i))
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
" repeated name in the list of sphere names: " << names;
|
||||
return false;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
names_.rehash(0);
|
||||
|
||||
numShapes_ = names_.size();
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool pFlow::sphereShape::readDictionary
|
||||
(
|
||||
const dictionary& dict
|
||||
)
|
||||
{
|
||||
diameters_ = dict.getVal<realVector>("diameters");
|
||||
materials_ = dict.getVal<wordVector>("materials");
|
||||
auto names = dict.getVal<wordVector>("names");
|
||||
|
||||
if(diameters_.size() != materials_.size() )
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
" number of elements in diameters and properties are not the same in "<< dict.globalName()<<endl;
|
||||
return false;
|
||||
}
|
||||
else if(diameters_.size() != names.size() )
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
" number of elements in diameters and names are not the same in "<< dict.globalName()<<endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !insertNames(names) )
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
" error in reading dictionary "<< dict.globalName();
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pFlow::sphereShape::writeDictionary
|
||||
(
|
||||
dictionary& dict
|
||||
)const
|
||||
{
|
||||
|
||||
if( !dict.add("diamters", diameters_) )
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
" Error in writing diameters to dictionary "<< dict.globalName()<<endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !dict.add("properties", materials_) )
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
" Error in writing properties to dictionary "<< dict.globalName()<<endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
size_t n = names_.size();
|
||||
wordVector names(n);
|
||||
names.clear();
|
||||
word nm;
|
||||
|
||||
for(label i=0; i<n; i++)
|
||||
{
|
||||
indexToName(i, nm);
|
||||
names.push_back(nm);
|
||||
}
|
||||
|
||||
if( !dict.add("names", names) )
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
" Error in writing names to dictionary "<< dict.globalName()<<endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
|
||||
pFlow::sphereShape::sphereShape
|
||||
(
|
||||
const realVector& diameter,
|
||||
const wordVector& property,
|
||||
const wordVector& name
|
||||
)
|
||||
:
|
||||
diameters_(diameter),
|
||||
materials_(property)
|
||||
{
|
||||
if( !insertNames( name) )
|
||||
{
|
||||
fatalExit;
|
||||
}
|
||||
}
|
||||
|
||||
bool pFlow::sphereShape::shapeToDiameter
|
||||
(
|
||||
wordVector& names,
|
||||
realVector& diams
|
||||
)const
|
||||
{
|
||||
diams.clear();
|
||||
uint32 idx;
|
||||
for(const auto& nm:names)
|
||||
{
|
||||
if(!nameToIndex(nm, idx))
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
" invalid shape name requested "<< nm <<endl;
|
||||
return false;
|
||||
}
|
||||
diams.push_back(diameters_[idx]);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool pFlow::sphereShape::read(iIstream& is)
|
||||
{
|
||||
|
||||
dictionary sphereDict(sphereShapeFile__, true);
|
||||
|
||||
if( !sphereDict.read(is) )
|
||||
{
|
||||
ioErrorInFile(is.name(), is.lineNumber()) <<
|
||||
" error in reading dictionray " << sphereShapeFile__ <<" from file. \n";
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !readDictionary(sphereDict) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pFlow::sphereShape::write(iOstream& os)const
|
||||
{
|
||||
|
||||
dictionary sphereDict(sphereShapeFile__, true);
|
||||
|
||||
if( !writeDictionary(sphereDict))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if( !sphereDict.write(os) )
|
||||
{
|
||||
ioErrorInFile( os.name(), os.lineNumber() )<<
|
||||
" error in writing dictionray to file. \n";
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
177
src/Particles/SphereParticles/sphereShape/sphereShape.H
Normal file
177
src/Particles/SphereParticles/sphereShape/sphereShape.H
Normal file
@ -0,0 +1,177 @@
|
||||
/*------------------------------- 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 __sphereShape_H__
|
||||
#define __sphereShape_H__
|
||||
|
||||
#include "Vectors.H"
|
||||
#include "hashMap.H"
|
||||
|
||||
namespace pFlow
|
||||
{
|
||||
|
||||
class dictionary;
|
||||
|
||||
class sphereShape
|
||||
{
|
||||
protected:
|
||||
|
||||
// - diameter of spheres
|
||||
realVector diameters_;
|
||||
|
||||
// - property name of spheres
|
||||
wordVector materials_;
|
||||
|
||||
// - hashed list of spheres names
|
||||
wordHashMap<uint32> names_;
|
||||
|
||||
size_t numShapes_;
|
||||
|
||||
|
||||
bool insertNames(const wordVector& names);
|
||||
|
||||
bool readDictionary(const dictionary& dict);
|
||||
|
||||
bool writeDictionary(dictionary& dict)const;
|
||||
|
||||
public:
|
||||
|
||||
// - type info
|
||||
TypeNameNV("sphereShape");
|
||||
|
||||
|
||||
sphereShape(){}
|
||||
|
||||
sphereShape(
|
||||
const realVector& diameter,
|
||||
const wordVector& property,
|
||||
const wordVector& name
|
||||
);
|
||||
|
||||
sphereShape(const sphereShape&) = default;
|
||||
|
||||
sphereShape(sphereShape&&) = default;
|
||||
|
||||
sphereShape& operator=(const sphereShape&) = default;
|
||||
|
||||
sphereShape& operator=(sphereShape&&) = default;
|
||||
|
||||
auto clone()const
|
||||
{
|
||||
return makeUnique<sphereShape>(*this);
|
||||
}
|
||||
|
||||
sphereShape* clonePtr()const
|
||||
{
|
||||
return new sphereShape(*this);
|
||||
}
|
||||
|
||||
~sphereShape() = default;
|
||||
|
||||
//// - Methods
|
||||
const auto& names()const{
|
||||
return names_;
|
||||
}
|
||||
|
||||
const auto& diameters()const{
|
||||
return diameters_;
|
||||
}
|
||||
|
||||
const auto& materials()const{
|
||||
return materials_;
|
||||
}
|
||||
|
||||
const auto diameter(label i)const{
|
||||
return diameters_[i];
|
||||
}
|
||||
|
||||
const auto material(label i)const{
|
||||
return materials_[i];
|
||||
}
|
||||
|
||||
|
||||
// name to index
|
||||
bool nameToIndex(const word& name, uint32& index)const
|
||||
{
|
||||
if(auto[iter, found] = names_.findIf(name); found )
|
||||
{
|
||||
index = iter->second;
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
index = 0;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
uint32 nameToIndex(const word& name)const
|
||||
{
|
||||
return names_.at(name);
|
||||
}
|
||||
|
||||
bool indexToName(uint32 i, word& name)const
|
||||
{
|
||||
for(auto& nm: names_)
|
||||
{
|
||||
if(nm.second == i)
|
||||
{
|
||||
name = nm.first;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
name = "";
|
||||
return false;
|
||||
}
|
||||
|
||||
bool shapeToDiameter(wordVector& names, realVector& diams)const;
|
||||
|
||||
void diameterMinMax(real& minD, real& maxD)const
|
||||
{
|
||||
minD = min(diameters_);
|
||||
maxD = max(diameters_);
|
||||
}
|
||||
|
||||
//// - IO operatoin
|
||||
|
||||
// - read from stream/file
|
||||
bool read(iIstream& is);
|
||||
|
||||
// - write to stream/file
|
||||
bool write(iOstream& os)const;
|
||||
|
||||
// - read from dictionary
|
||||
bool read(const dictionary& dict)
|
||||
{
|
||||
return readDictionary(dict);
|
||||
}
|
||||
|
||||
// - write to dictionary
|
||||
bool write(dictionary& dict)const
|
||||
{
|
||||
return writeDictionary(dict);
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
} // pFlow
|
||||
|
||||
#endif //__sphereShape_H__
|
Reference in New Issue
Block a user