# PhasicFlow: src/Particles/Insertion/shapeMixture/shapeMixture.cpp Source File

shapeMixture.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 "shapeMixture.hpp"
#include "dictionary.hpp"
pFlow::shapeMixture::shapeMixture
(
const dictionary & dict
)
{
if( !read(dict))
{
fatalExit;
}
}
pFlow::word pFlow::shapeMixture::getNextShapeName()
{
ForAll(i, names_)
{
if(current_[i]< number_[i])
{
current_[i]++;
numberInserted_[i]++;
return names_[i];
}
}
fill(current_, static_cast< uint32 >(0));
return getNextShapeName();
}
void pFlow::shapeMixture::getNextShapeNameN
(
size_t n,
wordVector& names
)
{
names.clear();
for(label i=0; i<n; ++i)
{
names.push_back( getNextShapeName() );
}
}
bool pFlow::shapeMixture::read(const dictionary& dict)
{
bool containNumberIneserted = false;
auto shNames = dict.dataEntryKeywords();
for (auto nm = shNames.begin(); nm != shNames.end(); )
{
if ( *nm == "numberInserted")
{
nm = shNames.erase(nm);
containNumberIneserted = true;
}
else
++nm;
}
for(const auto& nm:shNames)
{
names_.push_back(nm);
uint32 num = dict.getVal<uint32>(nm);
if( num <= 0 )
{
fatalErrorInFunction<<
" number inserte in front of "<< nm << " is invalid: "<< num<<endl<<
" in dictionary "<<dict.globalName()<<endl;
return false;
}
number_.push_back( num );
}
if(containNumberIneserted)
{
numberInserted_ = dict.getVal<uint32Vector>("numberInserted");
}
else
{
numberInserted_ = uint32Vector(size(), static_cast< uint32 >(0));
}
if(numberInserted_.size() != names_.size() )
{
fatalErrorInFunction<<
" number of elements in numberInserted ("<<numberInserted_.size()<<
") is not equal to the number of shape names: "<< names_<<endl;
return false;
}
current_.clear();
ForAll(i, numberInserted_)
{
current_.push_back(numberInserted_[i]%number_[i]);
}
return true;
}
bool pFlow::shapeMixture::write
(
dictionary& dict
) const
{
ForAll(i, names_)
{
if(!dict.add(names_[i],number_[i]))
{
fatalErrorInFunction<<
" error in writing "<< names_[i] << " to dictionary "<<dict.globalName()<<endl;
return false;
}
}
if(!dict.add("numberInserted", numberInserted_))
{
fatalErrorInFunction<<
" error in writing numberInserted to dictionary "<< dict.globalName()<<endl;
return false;
}
return true;
}
pFlow::shapeMixture::names_
wordVector names_
Definition: shapeMixture.hpp:37
pFlow::fill
void fill(Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:44
fatalExit
#define fatalExit
Definition: error.hpp:57
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::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::shapeMixture::write
bool write(dictionary &dict) const
Definition: shapeMixture.cpp:128
pFlow::shapeMixture::number_
uint32Vector number_
Definition: shapeMixture.hpp:40
shapeMixture.hpp
n
int32 n
Definition: NBSCrossLoop.hpp:24
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
dictionary.hpp
pFlow::shapeMixture::current_
uint32Vector current_
Definition: shapeMixture.hpp:45
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:71
pFlow::dictionary::getVal
T getVal(const word &keyword) const
Definition: dictionary.hpp:309
pFlow::Vector::clear
auto clear()
Definition: Vector.hpp:248
pFlow::shapeMixture::getNextShapeNameN
void getNextShapeNameN(size_t n, wordVector &names)
Definition: shapeMixture.cpp:55
pFlow::shapeMixture::read
bool read(const dictionary &dict)
Definition: shapeMixture.cpp:69
pFlow::shapeMixture::numberInserted_
uint32Vector numberInserted_
Definition: shapeMixture.hpp:43
pFlow::label
std::size_t label
Definition: builtinTypes.hpp:61
pFlow::shapeMixture::getNextShapeName
word getNextShapeName()
Definition: shapeMixture.cpp:37
pFlow::Vector< word >
pFlow::uint32Vector
Vector< uint32 > uint32Vector
Definition: Vectors.hpp:40
pFlow::shapeMixture::shapeMixture
shapeMixture(const dictionary &dict)
Definition: shapeMixture.cpp:27
pFlow::dictionary::dataEntryKeywords
wordList dataEntryKeywords() const
Definition: dictionary.cpp:706
pFlow::dictionary
Definition: dictionary.hpp:38