mirror of
https://github.com/PhasicFlow/phasicFlow.git
synced 2025-06-22 16:28:30 +00:00
Particle base class and sphereParticle class have been updated
This commit is contained in:
@ -19,186 +19,177 @@ Licence:
|
||||
-----------------------------------------------------------------------------*/
|
||||
|
||||
#include "sphereShape.hpp"
|
||||
#include "dictionary.hpp"
|
||||
#include "vocabs.hpp"
|
||||
#include "streams.hpp"
|
||||
|
||||
|
||||
bool pFlow::sphereShape::insertNames
|
||||
(
|
||||
const wordVector& names
|
||||
)
|
||||
bool pFlow::sphereShape::readDictionary()
|
||||
{
|
||||
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;
|
||||
}
|
||||
diameters_ = getVal<realVector>("diameters");
|
||||
|
||||
|
||||
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() )
|
||||
if(diameters_.size() != numShapes() )
|
||||
{
|
||||
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();
|
||||
fatalErrorInFunction<<
|
||||
" number of elements in diameters in "<< globalName()<<" is not consistent"<<endl;
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
bool pFlow::sphereShape::writeDictionary
|
||||
(
|
||||
dictionary& dict
|
||||
)const
|
||||
bool pFlow::sphereShape::writeToDict(dictionary& dict)const
|
||||
{
|
||||
|
||||
if(!shape::writeToDict(dict))return false;
|
||||
|
||||
if( !dict.add("diamters", diameters_) )
|
||||
if( !dict.add("diameters", diameters_) )
|
||||
{
|
||||
fatalErrorInFunction<<
|
||||
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
|
||||
const word& fileName,
|
||||
repository* owner,
|
||||
const property& prop
|
||||
)
|
||||
:
|
||||
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)
|
||||
shape(fileName, owner, prop)
|
||||
{
|
||||
|
||||
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
|
||||
pFlow::real pFlow::sphereShape::maxBoundingSphere() 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;
|
||||
return max(diameters_);
|
||||
}
|
||||
|
||||
pFlow::real pFlow::sphereShape::minBoundingSphere() const
|
||||
{
|
||||
return min(diameters_);
|
||||
}
|
||||
|
||||
bool pFlow::sphereShape::boundingDiameter(uint32 index, real &bDiam) const
|
||||
{
|
||||
if( indexValid(index))
|
||||
{
|
||||
bDiam = diameters_[index];
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
pFlow::real pFlow::sphereShape::boundingDiameter(uint32 index) const
|
||||
{
|
||||
if(indexValid(index))
|
||||
{
|
||||
return diameters_[index];
|
||||
}
|
||||
fatalErrorInFunction<<"Invalid index for diameter "<<
|
||||
index<<endl;
|
||||
fatalExit;
|
||||
return 0.0;
|
||||
}
|
||||
|
||||
pFlow::realVector pFlow::sphereShape::boundingDiameter() const
|
||||
{
|
||||
return diameters_;
|
||||
}
|
||||
|
||||
bool pFlow::sphereShape::mass(uint32 index, real &m) const
|
||||
{
|
||||
if( indexValid(index) )
|
||||
{
|
||||
real d = diameters_[index];
|
||||
real rho = indexToDensity(index);
|
||||
m = Pi/6.0*pow(d,3)*rho;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
pFlow::real pFlow::sphereShape::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::sphereShape::mass() const
|
||||
{
|
||||
return realVector ("mass", Pi/6*pow(diameters_,(real)3.0)*density());
|
||||
}
|
||||
|
||||
pFlow::realVector pFlow::sphereShape::density()const
|
||||
{
|
||||
auto pids = shapePropertyIds();
|
||||
realVector rho("rho", numShapes());
|
||||
ForAll(i, pids)
|
||||
{
|
||||
rho[i] = properties().density(pids[i]);
|
||||
}
|
||||
return rho;
|
||||
}
|
||||
|
||||
bool pFlow::sphereShape::Inertia(uint32 index, real &I) const
|
||||
{
|
||||
if( indexValid(index) )
|
||||
{
|
||||
I = 0.4 * mass(index) * pow(diameters_[index]/2.0,2.0);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
pFlow::real pFlow::sphereShape::Inertia(uint32 index) const
|
||||
{
|
||||
if(real I; Inertia(index, I))
|
||||
{
|
||||
return I;
|
||||
}
|
||||
fatalExit;
|
||||
return 0;
|
||||
}
|
||||
|
||||
pFlow::realVector pFlow::sphereShape::Inertia() const
|
||||
{
|
||||
return realVector("I", 0.4*mass()*pow(0.5*diameters_,(real)2.0));
|
||||
}
|
||||
|
||||
bool pFlow::sphereShape::Inertia_xx(uint32 index, real &Ixx) const
|
||||
{
|
||||
return Inertia(index,Ixx);
|
||||
}
|
||||
|
||||
pFlow::real pFlow::sphereShape::Inertial_xx(uint32 index) const
|
||||
{
|
||||
return Inertia(index);
|
||||
}
|
||||
|
||||
bool pFlow::sphereShape::Inertia_yy(uint32 index, real &Iyy) const
|
||||
{
|
||||
return Inertia(index,Iyy);
|
||||
}
|
||||
|
||||
pFlow::real pFlow::sphereShape::Inertial_yy(uint32 index) const
|
||||
{
|
||||
return Inertia(index);
|
||||
}
|
||||
|
||||
bool pFlow::sphereShape::Inertia_zz(uint32 index, real &Izz) const
|
||||
{
|
||||
return Inertia(index,Izz);
|
||||
}
|
||||
|
||||
pFlow::real pFlow::sphereShape::Inertial_zz(uint32 index) const
|
||||
{
|
||||
return Inertia(index);
|
||||
}
|
||||
|
@ -21,154 +21,78 @@ Licence:
|
||||
#ifndef __sphereShape_hpp__
|
||||
#define __sphereShape_hpp__
|
||||
|
||||
#include "Vectors.hpp"
|
||||
#include "hashMap.hpp"
|
||||
#include "shape.hpp"
|
||||
|
||||
namespace pFlow
|
||||
{
|
||||
|
||||
class dictionary;
|
||||
|
||||
|
||||
class sphereShape
|
||||
:
|
||||
public shape
|
||||
{
|
||||
protected:
|
||||
private:
|
||||
|
||||
// - diameter of spheres
|
||||
realVector diameters_;
|
||||
|
||||
// - property name of spheres
|
||||
wordVector materials_;
|
||||
bool readDictionary();
|
||||
|
||||
// - hashed list of spheres names
|
||||
wordHashMap<uint32> names_;
|
||||
protected:
|
||||
|
||||
size_t numShapes_;
|
||||
|
||||
|
||||
bool insertNames(const wordVector& names);
|
||||
|
||||
bool readDictionary(const dictionary& dict);
|
||||
|
||||
bool writeDictionary(dictionary& dict)const;
|
||||
bool writeToDict(dictionary& dict)const override;
|
||||
|
||||
public:
|
||||
|
||||
// - type info
|
||||
TypeInfoNV("sphereShape");
|
||||
TypeInfo("shape<sphere>");
|
||||
|
||||
sphereShape(
|
||||
const word& fileName,
|
||||
repository* owner,
|
||||
const property& prop);
|
||||
|
||||
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;
|
||||
|
||||
~sphereShape() override = default;
|
||||
|
||||
//// - Methods
|
||||
const auto& names()const{
|
||||
return names_;
|
||||
}
|
||||
|
||||
const auto& diameters()const{
|
||||
return diameters_;
|
||||
}
|
||||
real maxBoundingSphere()const override;
|
||||
|
||||
const auto& materials()const{
|
||||
return materials_;
|
||||
}
|
||||
real minBoundingSphere()const override;
|
||||
|
||||
const auto diameter(label i)const{
|
||||
return diameters_[i];
|
||||
}
|
||||
bool boundingDiameter(uint32 index, real& bDiam)const override;
|
||||
|
||||
const auto material(label i)const{
|
||||
return materials_[i];
|
||||
}
|
||||
real boundingDiameter(uint32 index)const override;
|
||||
|
||||
realVector boundingDiameter()const override;
|
||||
|
||||
// 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;
|
||||
}
|
||||
}
|
||||
bool mass(uint32 index, real& m)const override;
|
||||
|
||||
uint32 nameToIndex(const word& name)const
|
||||
{
|
||||
return names_.at(name);
|
||||
}
|
||||
real mass(uint32 index) const override;
|
||||
|
||||
bool indexToName(uint32 i, word& name)const
|
||||
{
|
||||
for(auto& nm: names_)
|
||||
{
|
||||
if(nm.second == i)
|
||||
{
|
||||
name = nm.first;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
name = "";
|
||||
return false;
|
||||
}
|
||||
realVector mass()const override;
|
||||
|
||||
bool shapeToDiameter(wordVector& names, realVector& diams)const;
|
||||
realVector density() const override;
|
||||
|
||||
void diameterMinMax(real& minD, real& maxD)const
|
||||
{
|
||||
minD = min(diameters_);
|
||||
maxD = max(diameters_);
|
||||
}
|
||||
bool Inertia(uint32 index, real& I)const override;
|
||||
|
||||
//// - IO operatoin
|
||||
real Inertia(uint32 index)const override;
|
||||
|
||||
// - read from stream/file
|
||||
bool read(iIstream& is);
|
||||
realVector Inertia()const override;
|
||||
|
||||
bool Inertia_xx(uint32 index, real& Ixx)const override;
|
||||
|
||||
// - write to stream/file
|
||||
bool write(iOstream& os)const;
|
||||
real Inertial_xx(uint32 index)const override;
|
||||
|
||||
bool Inertia_yy(uint32 index, real& Iyy)const override;
|
||||
|
||||
// - read from dictionary
|
||||
bool read(const dictionary& dict)
|
||||
{
|
||||
return readDictionary(dict);
|
||||
}
|
||||
real Inertial_yy(uint32 index)const override;
|
||||
|
||||
// - write to dictionary
|
||||
bool write(dictionary& dict)const
|
||||
{
|
||||
return writeDictionary(dict);
|
||||
}
|
||||
bool Inertia_zz(uint32 index, real& Izz)const override;
|
||||
|
||||
real Inertial_zz(uint32 index)const override;
|
||||
|
||||
};
|
||||
|
||||
|
Reference in New Issue
Block a user