Files
phasicFlow/src/Particles/Insertion/shapeMixture/shapeMixture.cpp

168 lines
3.7 KiB
C++
Raw Normal View History

2022-09-05 01:56:29 +04:30
/*------------------------------- phasicFlow ---------------------------------
O C enter of
O O E ngineering and
O O M ultiscale modeling of
OOOOOOO F luid flow
2022-09-05 01:56:29 +04:30
------------------------------------------------------------------------------
Copyright (C): www.cemf.ir
email: hamid.r.norouzi AT gmail.com
------------------------------------------------------------------------------
2022-09-05 01:56:29 +04:30
Licence:
This file is part of phasicFlow code. It is a free software for simulating
2022-09-05 01:56:29 +04:30
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
2022-09-05 01:56:29 +04:30
granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
-----------------------------------------------------------------------------*/
2022-12-10 01:32:54 +03:30
#include "shapeMixture.hpp"
#include "dictionary.hpp"
2022-09-05 01:56:29 +04:30
pFlow::shapeMixture::shapeMixture(
const dictionary& dict,
const wordList& validNames
2022-09-05 01:56:29 +04:30
)
{
if (!read(dict))
2022-09-05 01:56:29 +04:30
{
fatalExit;
}
for (const auto& rN : names_)
{
bool found = false;
for (const auto& vN : validNames)
{
if (rN == vN)
{
found = true;
break;
}
}
if (!found)
{
fatalErrorInFunction
<< "Shape name " << rN << " provided in mixture dictionary "
<< dict.globalName() << " is invalid. \n Valid names are "
<< validNames << endl;
}
}
2022-09-05 01:56:29 +04:30
}
pFlow::word
pFlow::shapeMixture::getNextShapeName()
2022-09-05 01:56:29 +04:30
{
ForAll(i, names_)
2022-09-05 01:56:29 +04:30
{
if (current_[i] < number_[i])
2022-09-05 01:56:29 +04:30
{
current_[i]++;
numberInserted_[i]++;
return names_[i];
}
}
2022-09-05 01:56:29 +04:30
fill(current_, static_cast<uint32>(0));
return getNextShapeName();
}
void
pFlow::shapeMixture::getNextShapeNameN(size_t n, wordVector& names)
2022-09-05 01:56:29 +04:30
{
names.clear();
for (size_t i = 0u; i < n; ++i)
2022-09-05 01:56:29 +04:30
{
names.push_back(getNextShapeName());
2022-09-05 01:56:29 +04:30
}
}
bool
pFlow::shapeMixture::read(const dictionary& dict)
2022-09-05 01:56:29 +04:30
{
bool containNumberIneserted = false;
2022-09-05 01:56:29 +04:30
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)
2022-09-05 01:56:29 +04:30
{
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(numberInserted_.name(), 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;
2022-09-05 01:56:29 +04:30
}
bool
pFlow::shapeMixture::write(dictionary& dict) const
2022-09-05 01:56:29 +04:30
{
ForAll(i, names_)
2022-09-05 01:56:29 +04:30
{
if (!dict.add(names_[i], number_[i]))
2022-09-05 01:56:29 +04:30
{
fatalErrorInFunction << " error in writing " << names_[i]
<< " to dictionary " << dict.globalName()
<< endl;
2022-09-05 01:56:29 +04:30
return false;
}
}
if (!dict.add("numberInserted", numberInserted_))
2022-09-05 01:56:29 +04:30
{
fatalErrorInFunction
<< " error in writing numberInserted to dictionary "
<< dict.globalName() << endl;
2022-09-05 01:56:29 +04:30
return false;
}
2022-09-05 01:56:29 +04:30
return true;
}