www.cemf.ir
shapeMixture.cpp
Go to the documentation of this file.
1 /*------------------------------- phasicFlow ---------------------------------
2  O C enter of
3  O O E ngineering and
4  O O M ultiscale modeling of
5  OOOOOOO F luid flow
6 ------------------------------------------------------------------------------
7  Copyright (C): www.cemf.ir
8  email: hamid.r.norouzi AT gmail.com
9 ------------------------------------------------------------------------------
10 Licence:
11  This file is part of phasicFlow code. It is a free software for simulating
12  granular and multiphase flows. You can redistribute it and/or modify it under
13  the terms of GNU General Public License v3 or any other later versions.
14 
15  phasicFlow is distributed to help others in their research in the field of
16  granular and multiphase flows, but WITHOUT ANY WARRANTY; without even the
17  implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
18 
19 -----------------------------------------------------------------------------*/
20 
21 #include "shapeMixture.hpp"
22 #include "dictionary.hpp"
23 
25  const dictionary& dict,
26  const wordList& validNames
27 )
28 {
29  if (!read(dict))
30  {
31  fatalExit;
32  }
33 
34  for (const auto& rN : names_)
35  {
36  bool found = false;
37  for (const auto& vN : validNames)
38  {
39  if (rN == vN)
40  {
41  found = true;
42  break;
43  }
44  }
45 
46  if (!found)
47  {
49  << "Shape name " << rN << " provided in mixture dictionary "
50  << dict.globalName() << " is invalid. \n Valid names are "
51  << validNames << endl;
52  }
53  }
54 }
55 
58 {
59  ForAll(i, names_)
60  {
61  if (current_[i] < number_[i])
62  {
63  current_[i]++;
64  numberInserted_[i]++;
65  return names_[i];
66  }
67  }
68 
69  fill(current_, static_cast<uint32>(0));
70  return getNextShapeName();
71 }
72 
73 void
75 {
76  names.clear();
77 
78  for (size_t i = 0u; i < n; ++i)
79  {
80  names.push_back(getNextShapeName());
81  }
82 }
83 
84 bool
86 {
87  bool containNumberIneserted = false;
88 
89  auto shNames = dict.dataEntryKeywords();
90 
91  for (auto nm = shNames.begin(); nm != shNames.end();)
92  {
93  if (*nm == "numberInserted")
94  {
95  nm = shNames.erase(nm);
96  containNumberIneserted = true;
97  }
98  else
99  ++nm;
100  }
101 
102  for (const auto& nm : shNames)
103  {
104  names_.push_back(nm);
105  uint32 num = dict.getVal<uint32>(nm);
106  if (num <= 0)
107  {
108  fatalErrorInFunction << " number inserte in front of " << nm
109  << " is invalid: " << num << endl
110  << " in dictionary " << dict.globalName()
111  << endl;
112  return false;
113  }
114  number_.push_back(num);
115  }
116 
117  if (containNumberIneserted)
118  {
119  numberInserted_ = dict.getVal<uint32Vector>("numberInserted");
120  }
121  else
122  {
123  numberInserted_ =
124  uint32Vector(numberInserted_.name(), size(), static_cast<uint32>(0));
125  }
126 
127  if (numberInserted_.size() != names_.size())
128  {
130  << " number of elements in numberInserted ("
131  << numberInserted_.size()
132  << ") is not equal to the number of shape names: " << names_ << endl;
133  return false;
134  }
135 
136  current_.clear();
137  ForAll(i, numberInserted_)
138  {
139  current_.push_back(numberInserted_[i] % number_[i]);
140  }
141 
142  return true;
143 }
144 
145 bool
147 {
148  ForAll(i, names_)
149  {
150  if (!dict.add(names_[i], number_[i]))
151  {
152  fatalErrorInFunction << " error in writing " << names_[i]
153  << " to dictionary " << dict.globalName()
154  << endl;
155  return false;
156  }
157  }
158 
159  if (!dict.add("numberInserted", numberInserted_))
160  {
162  << " error in writing numberInserted to dictionary "
163  << dict.globalName() << endl;
164  return false;
165  }
166 
167  return true;
168 }
pFlow::shapeMixture::names_
wordVector names_
List of shape names.
Definition: shapeMixture.hpp:52
pFlow::List< word >
pFlow::fill
void fill(Vector< T, Allocator > &vec, const T &val)
Definition: VectorAlgorithm.hpp:44
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::dictionary::globalName
virtual word globalName() const
global name of entry, separated with dots
Definition: dictionary.cpp:356
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::shapeMixture::write
bool write(dictionary &dict) const
Definition: shapeMixture.cpp:146
shapeMixture.hpp
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
dictionary.hpp
ForAll
#define ForAll(i, container)
Definition: pFlowMacros.hpp:75
pFlow::dictionary::getVal
T getVal(const word &keyword) const
get the value of data entry
Definition: dictionary.hpp:379
pFlow::shapeMixture::getNextShapeNameN
void getNextShapeNameN(size_t n, wordVector &names)
The name of the n next shapes that should be inserted.
Definition: shapeMixture.cpp:74
n
uint32 n
Definition: NBSLoop.hpp:24
pFlow::shapeMixture::read
bool read(const dictionary &dict)
Definition: shapeMixture.cpp:85
pFlow::shapeMixture::getNextShapeName
word getNextShapeName()
The name of the next shape that should be inserted.
Definition: shapeMixture.cpp:57
pFlow::shapeMixture::shapeMixture
shapeMixture(const dictionary &dict, const wordList &validNames)
Construct from dictionary.
Definition: shapeMixture.cpp:24
pFlow::Vector< word >
pFlow::uint32Vector
Vector< uint32 > uint32Vector
Definition: Vectors.hpp:40
pFlow::dictionary::dataEntryKeywords
wordList dataEntryKeywords() const
return a list of all dataEntries (non-nullptr) keywords
Definition: dictionary.cpp:719
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