# PhasicFlow: src/Particles/particles/shape/baseShapeNames.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.

baseShapeNames.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 "baseShapeNames.hpp"
bool pFlow::baseShapeNames::createHashNames()
{
hashNames_.clear();
hashes_.clear();
std::hash<word> hasher;
uint32 i=0;
for(const auto& nm:shapeNames_)
{
if(!hashNames_.insertIf(nm, i))
{
fatalErrorInFunction<<
" repeated name in the list of shape names: " << shapeNames_;
return false;
}
hashes_.push_back(hasher(nm));
i++;
}
hashNames_.rehash(0);
return true;
}
bool pFlow::baseShapeNames::readFromDictionary1()
{
shapeNames_ = getVal<wordVector>("names");
numShapes_ = shapeNames_.size();
return true;
}
pFlow::baseShapeNames::baseShapeNames
(
const word &fileName,
repository *owner
)
:
fileDictionary
(
objectFile
(
fileName,
"",
objectFile::READ_ALWAYS,
objectFile::WRITE_ALWAYS
),
owner
)
{
if( !readFromDictionary1() )
{
fatalErrorInFunction;
fatalExit;
}
if( !createHashNames())
{
fatalErrorInFunction;
fatalExit;
}
}
bool pFlow::baseShapeNames::writeToDict(dictionary &dict)const
{
if( !dict.add("names", shapeNames_) )
{
fatalErrorInFunction<<
" Error in writing names to dictionary "<< dict.globalName()<<endl;
return false;
}
return true;
}
bool pFlow::baseShapeNames::write(iOstream &os) const
{
dictionary newDict(fileDictionary::dictionary::name(), true);
if( !writeToDict(newDict) )
{
return false;
}
if( !newDict.write(os) )
{
fatalErrorInFunction<<"Error in writing dictionary "<< globalName()<<
"to stream "<< os.name()<<endl;
return false;
}
return true;
}
pFlow::baseShapeNames::hashNames_
wordHashMap< uint32 > hashNames_
Definition: baseShapeNames.hpp:42
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::baseShapeNames::baseShapeNames
baseShapeNames(const word &fileName, repository *owner)
Definition: baseShapeNames.cpp:59
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::baseShapeNames::hashes_
Vector< size_t > hashes_
hash for names
Definition: baseShapeNames.hpp:48
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
baseShapeNames.hpp
pFlow::dictionary::globalName
virtual word globalName() const
global name of entry, separated with dots
Definition: dictionary.cpp:356
pFlow::objectFile::WRITE_ALWAYS
@ WRITE_ALWAYS
Definition: objectFile.hpp:43
pFlow::dictionary::add
bool add(const word &keyword, const float &v)
add a float dataEntry
Definition: dictionary.cpp:435
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::baseShapeNames::hasher
typename wordHashMap< uint32 >::hasher hasher
Definition: baseShapeNames.hpp:54
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::baseShapeNames::readFromDictionary1
bool readFromDictionary1()
Definition: baseShapeNames.cpp:48
pFlow::objectFile::READ_ALWAYS
@ READ_ALWAYS
Definition: objectFile.hpp:36
pFlow::dictionary::write
bool write(iOstream &os) const override
write to stream
Definition: dictionary.cpp:793
pFlow::baseShapeNames::createHashNames
bool createHashNames()
Definition: baseShapeNames.cpp:23
pFlow::objectFile
Definition: objectFile.hpp:30
pFlow::IOstream::name
virtual const word & name() const
Return the name of the stream.
Definition: IOstream.cpp:31
pFlow::fileDictionary
Definition: fileDictionary.hpp:29
pFlow::repository
Definition: repository.hpp:34
pFlow::baseShapeNames::shapeNames_
wordVector shapeNames_
list of shape names
Definition: baseShapeNames.hpp:45
pFlow::baseShapeNames::write
bool write(iOstream &os) const override
write to stream
Definition: baseShapeNames.cpp:105
pFlow::iOstream
Interface class for any output stream.
Definition: iOstream.hpp:59
pFlow::baseShapeNames::writeToDict
virtual bool writeToDict(dictionary &dict) const
Definition: baseShapeNames.cpp:92
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