# PhasicFlow: src/Property/property.cpp Source File

property.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 "property.hpp"
#include "dictionary.hpp"
bool pFlow::property::readDictionary
(
const dictionary& dict
)
{
materials_ = dict.getVal<wordVector>("materials");
densities_ = dict.getVal<realVector>("densities");
if(materials_.size() != densities_.size() )
{
fatalErrorInFunction<<
" number of elements in material ("<<materials_.size()<<
") is not equal to number of elements in densities ("<<densities_.size()<<
") in dictionary "<< dict.globalName()<<endl;
return false;
}
if(!makeNameIndex())
{
fatalErrorInFunction<<
" error in dictionary "<< dict.globalName()<<endl;
return false;
}
return true;
}
bool pFlow::property::writeDictionary
(
dictionary& dict
)const
{
if(!dict.add("materials", materials_))
{
fatalErrorInFunction<<
" error in writing materials to dictionary "<< dict.globalName()<<endl;
return false;
}
if(!dict.add("densities", densities_))
{
fatalErrorInFunction<<
" error in writing densities to dictionary "<< dict.globalName()<<endl;
return false;
}
return true;
}
bool pFlow::property::makeNameIndex()
{
nameIndex_.clear();
uint32 i=0;
for(auto& nm:materials_)
{
if(!nameIndex_.insertIf(nm, i++))
{
fatalErrorInFunction<<
" repeated material name in the list of materials: " << materials_;
return false;
}
}
nameIndex_.rehash(0);
numMaterials_ = materials_.size();
return true;
}
pFlow::property::property
(
const wordVector& materials,
const realVector& densities
)
:
materials_(materials),
densities_(densities)
{
if(!makeNameIndex())
{
fatalErrorInFunction<<
" error in the input parameters of constructor. \n";
fatalExit;
}
}
pFlow::property::property
(
const fileSystem& file
)
:
dict_
(
makeUnique<dictionary>
("property", true)
)
{
iFstream dictStream(file);
if(!dict_().read(dictStream))
{
ioErrorInFile(dictStream.name(), dictStream.lineNumber());
fatalExit;
}
if(!readDictionary(dict_()))
{
fatalExit;
}
}
pFlow::property::property
(
const dictionary& dict
)
:
dict_
(
makeUnique<dictionary>(dict)
)
{
if(!readDictionary(dict_()))
{
fatalExit;
}
}
pFlow::property::makeNameIndex
bool makeNameIndex()
creates a mapp
Definition: property.cpp:76
fatalExit
#define fatalExit
Definition: error.hpp:57
pFlow::property::materials_
wordVector materials_
list of name of materials
Definition: property.hpp:50
pFlow::property::writeDictionary
bool writeDictionary(dictionary &dict) const
write to dict
Definition: property.cpp:54
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::dictionary::globalName
virtual word globalName() const
Definition: dictionary.cpp:349
pFlow::Istream::name
virtual const word & name() const
Definition: Istream.hpp:78
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::iFstream
Definition: iFstream.hpp:35
pFlow::fileSystem
Definition: fileSystem.hpp:63
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::property::readDictionary
bool readDictionary(const dictionary &dict)
read from dict
Definition: property.cpp:26
dictionary.hpp
pFlow::property::nameIndex_
wordHashMap< uint32 > nameIndex_
rapid mapping from name to index
Definition: property.hpp:56
pFlow::property::property
property()
Emptry constructor, used for reading from a file.
Definition: property.hpp:82
pFlow::dictionary::getVal
T getVal(const word &keyword) const
Definition: dictionary.hpp:309
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
pFlow::property::numMaterials_
uint32 numMaterials_
number of materials
Definition: property.hpp:59
pFlow::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
property.hpp
pFlow::Vector< word >
pFlow::dictionary
Definition: dictionary.hpp:38