# PhasicFlow: src/Particles/GrainParticles/grainShape/grainShape.cpp Source File
PhasicFlow is an open-source parallel DEM (discrete element method) package for simulating granular flow. It is developed in C++ and can be exectued on both GPU (like CUDA) and CPU.

grainShape.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 "grainShape.hpp"
bool pFlow::grainShape::readFromDictionary3()
{
grainDiameters_ = getVal<realVector>("grainDiameters");
sphereDiameters_ = getVal<realVector>("sphereDiameters");
coarseGrainFactor_ = grainDiameters_ / sphereDiameters_ ;
if(grainDiameters_.size() != numShapes() )
{
fatalErrorInFunction<<
" number of elements in grain diameters in "<< globalName()<<" is not consistent"<<endl;
return false;
}
if(sphereDiameters_.size() != numShapes() )
{
fatalErrorInFunction<<
" number of elements in sphere diameters in "<< globalName()<<" is not consistent"<<endl;
return false;
}
return true;
}
bool pFlow::grainShape::writeToDict(dictionary& dict)const
{
if(!shape::writeToDict(dict))return false;
return true;
}
pFlow::grainShape::grainShape
(
const word& fileName,
repository* owner,
const property& prop
)
:
shape(fileName, owner, prop)
{
if(!readFromDictionary3())
{
fatalExit;
fatalErrorInFunction;
}
}
pFlow::real pFlow::grainShape::maxBoundingSphere() const
{
return max(grainDiameters_);
}
pFlow::real pFlow::grainShape::minBoundingSphere() const
{
return min(grainDiameters_);
}
bool pFlow::grainShape::boundingDiameter(uint32 index, real &bDiam) const
{
if( indexValid(index))
{
bDiam = grainDiameters_[index];
return true;
}
return false;
}
pFlow::real pFlow::grainShape::boundingDiameter(uint32 index) const
{
if(indexValid(index))
{
return grainDiameters_[index];
}
fatalErrorInFunction<<"Invalid index for diameter "<<
index<<endl;
fatalExit;
return 0.0;
}
pFlow::realVector pFlow::grainShape::boundingDiameter() const
{
return grainDiameters_;
}
pFlow::real pFlow::grainShape::coarseGrainFactor(uint32 index) const
{
if(indexValid(index))
{
return coarseGrainFactor_[index];
}
fatalErrorInFunction<<"Invalid index for coarse Grain Factor "<<
index<<endl;
fatalExit;
return 0.0;
}
pFlow::realVector pFlow::grainShape::coarseGrainFactor() const
{
return coarseGrainFactor_;
}
pFlow::real pFlow::grainShape::orginalDiameter(uint32 index) const
{
if(indexValid(index))
{
return sphereDiameters_[index];
}
fatalErrorInFunction<<"Invalid index for sphere diameter "<<
index<<endl;
fatalExit;
return 0.0;
}
pFlow::realVector pFlow::grainShape::orginalDiameter() const
{
return sphereDiameters_;
}
bool pFlow::grainShape::mass(uint32 index, real &m) const
{
if( indexValid(index) )
{
real d = grainDiameters_[index];
real rho = indexToDensity(index);
m = Pi/6.0*pow(d,3)*rho;
return true;
}
return false;
}
pFlow::real pFlow::grainShape::mass(uint32 index) const
{
if(real m; mass(index, m))
{
return m;
}
fatalErrorInFunction<<"bad index for mass "<< index<<endl;
fatalExit;
return 0;
}
pFlow::realVector pFlow::grainShape::mass() const
{
return realVector ("mass", Pi/6*pow(grainDiameters_,(real)3.0)*density());
}
pFlow::realVector pFlow::grainShape::density()const
{
auto pids = shapePropertyIds();
realVector rho("rho", numShapes());
ForAll(i, pids)
{
rho[i] = properties().density(pids[i]);
}
return rho;
}
bool pFlow::grainShape::Inertia(uint32 index, real &I) const
{
if( indexValid(index) )
{
I = 0.4 * mass(index) * pow(grainDiameters_[index]/2.0,2.0);
return true;
}
return false;
}
pFlow::real pFlow::grainShape::Inertia(uint32 index) const
{
if(real I; Inertia(index, I))
{
return I;
}
fatalExit;
return 0;
}
pFlow::realVector pFlow::grainShape::Inertia() const
{
return realVector("I", (real)0.4*mass()*pow((real)0.5*grainDiameters_,(real)2.0));
}
bool pFlow::grainShape::Inertia_xx(uint32 index, real &Ixx) const
{
return Inertia(index,Ixx);
}
pFlow::real pFlow::grainShape::Inertial_xx(uint32 index) const
{
return Inertia(index);
}
bool pFlow::grainShape::Inertia_yy(uint32 index, real &Iyy) const
{
return Inertia(index,Iyy);
}
pFlow::real pFlow::grainShape::Inertial_yy(uint32 index) const
{
return Inertia(index);
}
bool pFlow::grainShape::Inertia_zz(uint32 index, real &Izz) const
{
return Inertia(index,Izz);
}
pFlow::real pFlow::grainShape::Inertial_zz(uint32 index) const
{
return Inertia(index);
}
pFlow::realVector
Vector< real > realVector
Definition: Vectors.hpp:46
pFlow::grainShape::writeToDict
bool writeToDict(dictionary &dict) const override
Definition: grainShape.cpp:51
pFlow::real
float real
Definition: builtinTypes.hpp:45
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::pow
Vector< T, Allocator > pow(const Vector< T, Allocator > &v1, const Vector< T, Allocator > &v2)
Definition: VectorMath.hpp:89
pFlow::grainShape::mass
realVector mass() const override
Definition: grainShape.cpp:173
pFlow::grainShape::Inertial_zz
real Inertial_zz(uint32 index) const override
Definition: grainShape.cpp:239
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::grainShape::Inertial_yy
real Inertial_yy(uint32 index) const override
Definition: grainShape.cpp:229
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::max
T max(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:79
pFlow::grainShape::coarseGrainFactor
realVector coarseGrainFactor() const
Definition: grainShape.cpp:126
pFlow::dictionary::globalName
virtual word globalName() const
global name of entry, separated with dots
Definition: dictionary.cpp:356
pFlow::grainShape::Inertia_xx
bool Inertia_xx(uint32 index, real &Ixx) const override
Definition: grainShape.cpp:214
pFlow::Vector::size
auto size() const
Size of the vector.
Definition: Vector.hpp:265
pFlow::baseShapeNames::numShapes
size_t numShapes() const
Definition: baseShapeNames.hpp:93
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::grainShape::orginalDiameter
realVector orginalDiameter() const
Definition: grainShape.cpp:145
pFlow::shape::writeToDict
bool writeToDict(dictionary &dict) const override
Definition: shape.cpp:65
pFlow::grainShape::grainShape
grainShape(const word &fileName, repository *owner, const property &prop)
Definition: grainShape.cpp:60
pFlow::grainShape::density
realVector density() const override
Definition: grainShape.cpp:178
pFlow::grainShape::sphereDiameters_
realVector sphereDiameters_
Definition: grainShape.hpp:37
pFlow::grainShape::readFromDictionary3
bool readFromDictionary3()
Definition: grainShape.cpp:24
grainShape.hpp
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::grainShape::Inertial_xx
real Inertial_xx(uint32 index) const override
Definition: grainShape.cpp:219
pFlow::shape
Definition: shape.hpp:30
pFlow::grainShape::grainDiameters_
realVector grainDiameters_
Definition: grainShape.hpp:36
pFlow::grainShape::minBoundingSphere
real minBoundingSphere() const override
Definition: grainShape.cpp:81
pFlow::grainShape::Inertia_zz
bool Inertia_zz(uint32 index, real &Izz) const override
Definition: grainShape.cpp:234
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:75
pFlow::min
T min(const internalField< T, MemorySpace > &iField)
Definition: internalFieldAlgorithms.hpp:28
pFlow::property
property holds the pure properties of materials.
Definition: property.hpp:37
pFlow::grainShape::boundingDiameter
realVector boundingDiameter() const override
Definition: grainShape.cpp:108
pFlow::grainShape::Inertia
realVector Inertia() const override
Definition: grainShape.cpp:209
pFlow::grainShape::maxBoundingSphere
real maxBoundingSphere() const override
Definition: grainShape.cpp:76
pFlow::Pi
const real Pi
Definition: numericConstants.hpp:30
pFlow::repository
Definition: repository.hpp:34
pFlow::grainShape::Inertia_yy
bool Inertia_yy(uint32 index, real &Iyy) const override
Definition: grainShape.cpp:224
pFlow::Vector< real >
m
uint32 m
Definition: NBSLoop.hpp:22
pFlow::grainShape::coarseGrainFactor_
realVector coarseGrainFactor_
Definition: grainShape.hpp:38
pFlow::dictionary
Dictionary holds a set of data entries or sub-dictionaries that are enclosed in a curely braces or ar...
Definition: dictionary.hpp:67