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

sphereShape.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 "sphereShape.hpp"
#include "dictionary.hpp"
#include "vocabs.hpp"
#include "streams.hpp"
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;
}
pFlow::sphereShapeFile__
const char * sphereShapeFile__
Definition: vocabs.hpp:41
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::dictionary::write
virtual bool write(iOstream &os) const
Definition: dictionary.cpp:780
pFlow::dictionary::read
virtual bool read(iIstream &is)
Definition: dictionary.cpp:759
pFlow::sphereShape::write
bool write(iOstream &os) const
Definition: sphereShape.cpp:186
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::dictionary::globalName
virtual word globalName() const
Definition: dictionary.cpp:349
pFlow::Vector::size
auto size() const
Definition: Vector.hpp:299
pFlow::dictionary::add
bool add(const word &keyword, const float &v)
Definition: dictionary.cpp:422
pFlow::endl
iOstream & endl(iOstream &os)
Definition: iOstream.hpp:312
pFlow::sphereShape::read
bool read(iIstream &is)
Definition: sphereShape.cpp:166
sphereShape.hpp
n
int32 n
Definition: NBSCrossLoop.hpp:24
pFlow::iIstream
Definition: iIstream.hpp:33
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::sphereShape::sphereShape
sphereShape()
Definition: sphereShape.hpp:60
dictionary.hpp
pFlow::sphereShape::writeDictionary
bool writeDictionary(dictionary &dict) const
Definition: sphereShape.cpp:85
pFlow::IOstream::name
virtual const word & name() const
Definition: IOstream.cpp:31
streams.hpp
pFlow::dictionary::getVal
T getVal(const word &keyword) const
Definition: dictionary.hpp:309
pFlow::property
property holds the pure properties of materials.
Definition: property.hpp:40
pFlow::Vector::clear
auto clear()
Definition: Vector.hpp:248
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
pFlow::sphereShape::insertNames
bool insertNames(const wordVector &names)
Definition: sphereShape.cpp:28
pFlow::label
std::size_t label
Definition: builtinTypes.hpp:61
pFlow::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
pFlow::sphereShape::readDictionary
bool readDictionary(const dictionary &dict)
Definition: sphereShape.cpp:53
vocabs.hpp
pFlow::Vector< word >
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::sphereShape::shapeToDiameter
bool shapeToDiameter(wordVector &names, realVector &diams) const
Definition: sphereShape.cpp:144
pFlow::dictionary
Definition: dictionary.hpp:38