# PhasicFlow: src/Particles/Insertion/insertionRegion/insertionRegion.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.

insertionRegion.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 "insertionRegion.hpp"
#include "dictionary.hpp"
#include "insertion.hpp"
#include "particles.hpp"
#include "twoPartEntry.hpp"
#include "types.hpp"
namespace pFlow
{
template<typename T>
bool
setOneEntry(const twoPartEntry& tpEntry, anyList& varList)
{
if (getTypeName<T>() != tpEntry.firstPart())
return false;
T val = tpEntry.secondPartVal<T>();
varList.emplaceBack(tpEntry.keyword(), val);
return true;
}
bool
readOneEtrty(const dataEntry& entry, anyList& varList)
{
twoPartEntry stField(entry);
if (!(setOneEntry<real>(stField, varList) ||
setOneEntry<realx3>(stField, varList) ||
setOneEntry<realx4>(stField, varList) ||
setOneEntry<int8>(stField, varList) ||
setOneEntry<uint8>(stField, varList) ||
setOneEntry<uint32>(stField, varList) ||
setOneEntry<uint64>(stField, varList) ||
setOneEntry<int32>(stField, varList) ||
setOneEntry<int64>(stField, varList)))
{
fatalErrorInFunction << "un-supported data type " << stField.firstPart()
<< endl;
return false;
}
return true;
}
}
bool
pFlow::insertionRegion::readInsertionRegion(const dictionary& dict)
{
type_ = dict.getVal<word>("regionType");
rate_ = dict.getVal<real>("rate");
pRegion_ = peakableRegion::create(type_, dict.subDict(type_ + "Info"));
mixture_ = makeUnique<shapeMixture>(
dict.subDict("mixture"),
insertion_.Particles().getShapes().shapeNameList()
);
numInserted_ = mixture_().totalInserted();
if (dict.containsDictionay("setFields"))
{
setFieldDict_ =
makeUnique<dictionary>("setFields", dict, dict.subDict("setFields"));
}
if (setFieldDict_)
{
if (!readSetFieldDict())
{
fatalErrorInFunction << "Error in reading dictionary "
<< setFieldDict_().globalName() << endl;
return false;
}
}
return true;
}
bool
pFlow::insertionRegion::writeInsertionRegion(dictionary& dict) const
{
if(!dict.add("rate", rate_))
return false;
if(!tControl_.write(dict))
return false;
if (!dict.add("regionType", type_))
return false;
if (pRegion_)
{
auto& prDict = dict.subDictOrCreate(type_ + "Info");
if (!pRegion_().write(prDict))
return false;
}
if (mixture_)
{
auto& mixDict = dict.subDictOrCreate("mixture");
if (!mixture_().write(mixDict))
return false;
}
if(setFieldDict_)
{
if(!dict.addDict("setFields", setFieldDict_()))
return false;
}
return true;
}
bool
pFlow::insertionRegion::readSetFieldDict()
{
wordList Keys = setFieldDict_().dataEntryKeywords();
for (const auto& key : Keys)
{
if (!readOneEtrty(setFieldDict_().dataEntryRef(key), setFieldList_))
{
return false;
}
}
return true;
}
pFlow::insertionRegion::insertionRegion(
const word& name,
const insertion& instn
)
: name_(name),
dict_(instn.subDict(name)),
insertion_(instn),
tControl_(dict_, "insertion")
{
if (!readInsertionRegion(dict_))
{
fatalExit;
}
}
const pFlow::pointStructure&
pFlow::insertionRegion::pStruct() const
{
return Insertion().pStruct();
}
pFlow::uint32
pFlow::insertionRegion::numberToBeInserted(uint32 iter, real t, real dt)
{
if (!tControl_.isInRange(iter, t, dt))
return 0u;
if (tControl_.isTimeStep())
{
return static_cast< uint32 >(
(iter - tControl_.startIter() + tControl_.iInterval()) * dt * rate_ -
numInserted_
);
}
else
{
return static_cast< uint32 >(
(t - tControl_.startTime() + tControl_.rInterval()) * rate_ -
numInserted_
);
}
}
twoPartEntry.hpp
pFlow::insertionRegion::numInserted_
uint32 numInserted_
number of inserted particles
Definition: insertionRegion.hpp:106
pFlow::List< word >
pFlow::insertion::pStruct
const pointStructure & pStruct() const
Definition: insertion.cpp:72
pFlow::insertionRegion::type_
word type_
type of insertion region
Definition: insertionRegion.hpp:109
pFlow::real
float real
Definition: builtinTypes.hpp:45
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::insertionRegion::numberToBeInserted
uint32 numberToBeInserted(uint32 iter, real t, real dt)
Definition: insertionRegion.cpp:174
types.hpp
insertion.hpp
pFlow::insertionRegion::insertionRegion
insertionRegion(const word &name, const insertion &instn)
Construct from a dictionary.
Definition: insertionRegion.cpp:152
pFlow::insertionRegion::pStruct
const pointStructure & pStruct() const
Definition: insertionRegion.cpp:168
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::twoPartEntry
Definition: twoPartEntry.hpp:36
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::baseShapeNames::shapeNameList
wordList shapeNameList() const
Definition: baseShapeNames.hpp:79
particles.hpp
pFlow::dictionary::subDictOrCreate
dictionary & subDictOrCreate(const word &keyword)
search for a sub-dict with keyword create a new sub-dict if not found and return a ref to it fatalExi...
Definition: dictionary.cpp:647
pFlow::dictionary::add
bool add(const word &keyword, const float &v)
add a float dataEntry
Definition: dictionary.cpp:435
pFlow::insertion::Particles
particles & Particles()
Definition: insertion.hpp:90
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::insertionRegion::mixture_
uniquePtr< shapeMixture > mixture_
mixture of shapes
Definition: insertionRegion.hpp:115
pFlow
Definition: demGeometry.hpp:27
pFlow::insertionRegion::setFieldDict_
uniquePtr< dictionary > setFieldDict_
dictionary for set field
Definition: insertionRegion.hpp:118
pFlow::pointStructure
Definition: pointStructure.hpp:34
pFlow::anyList
Definition: anyList.hpp:35
pFlow::dataEntry
Data entry to be used in dictionries.
Definition: dataEntry.hpp:48
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
pFlow::insertionRegion::insertion_
const insertion & insertion_
ref to insertion
Definition: insertionRegion.hpp:97
dictionary.hpp
pFlow::particles::getShapes
virtual const shape & getShapes() const =0
insertionRegion.hpp
pFlow::insertionRegion::dict_
const dictionary & dict_
insertion region dictionary
Definition: insertionRegion.hpp:94
pFlow::peakableRegion::create
static uniquePtr< peakableRegion > create(const word &type, const dictionary &dict)
Definition: peakableRegion.cpp:36
pFlow::twoPartEntry::keyword
const word & keyword() const
Definition: twoPartEntry.hpp:46
pFlow::insertionRegion::writeInsertionRegion
bool writeInsertionRegion(dictionary &dict) const
write to dictionary
Definition: insertionRegion.cpp:102
pFlow::insertionRegion::dict
const auto & dict() const
Definition: insertionRegion.hpp:162
pFlow::readOneEtrty
bool readOneEtrty(const dataEntry &entry, anyList &varList)
Definition: insertionRegion.cpp:44
pFlow::insertionRegion::pRegion_
uniquePtr< peakableRegion > pRegion_
peakable region of points
Definition: insertionRegion.hpp:112
pFlow::twoPartEntry::firstPart
const word & firstPart() const
Definition: twoPartEntry.hpp:51
pFlow::dictionary::addDict
bool addDict(const word &keyword, const dictionary &dict)
add a dictionary with the specifiedd keyword, if it exists, replace it.
Definition: dictionary.cpp:526
pFlow::insertionRegion::readSetFieldDict
bool readSetFieldDict()
Definition: insertionRegion.cpp:137
pFlow::Insertion
This class manages all the insertion regions for particles insertion in the simulation.
Definition: Insertion.hpp:56
pFlow::insertionRegion::rate_
real rate_
rate of insertion
Definition: insertionRegion.hpp:103
pFlow::insertionRegion::readInsertionRegion
bool readInsertionRegion(const dictionary &dict)
read from dictionary
Definition: insertionRegion.cpp:67
pFlow::anyList::emplaceBack
reference emplaceBack(const word &name, Args &&... args)
Create variable using constructor in-place.
Definition: anyList.hpp:84
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
pFlow::setOneEntry
bool setOneEntry(const twoPartEntry &tpEntry, anyList &varList)
Definition: insertionRegion.cpp:32
pFlow::twoPartEntry::secondPartVal
T secondPartVal() const
Definition: twoPartEntry.hpp:62
pFlow::insertion
Base class for particle insertion.
Definition: insertion.hpp:35