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 
22 #include "shapeMixture.hpp"
23 #include "dictionary.hpp"
24 
25 
27 (
28  const dictionary & dict
29 )
30 {
31  if( !read(dict))
32  {
33  fatalExit;
34  }
35 }
36 
38 {
39 
40  ForAll(i, names_)
41  {
42  if(current_[i]< number_[i])
43  {
44  current_[i]++;
45  numberInserted_[i]++;
46  return names_[i];
47  }
48  }
49 
50  fill(current_, static_cast<uint32>(0));
51  return getNextShapeName();
52 }
53 
55 (
56  size_t n,
57  wordVector& names
58 )
59 {
60  names.clear();
61 
62 
63  for(label i=0; i<n; ++i)
64  {
65  names.push_back( getNextShapeName() );
66  }
67 }
68 
70 {
71 
72  bool containNumberIneserted = false;
73 
74  auto shNames = dict.dataEntryKeywords();
75 
76  for (auto nm = shNames.begin(); nm != shNames.end(); )
77  {
78  if ( *nm == "numberInserted")
79  {
80  nm = shNames.erase(nm);
81  containNumberIneserted = true;
82  }
83  else
84  ++nm;
85  }
86 
87  for(const auto& nm:shNames)
88  {
89  names_.push_back(nm);
90  uint32 num = dict.getVal<uint32>(nm);
91  if( num <= 0 )
92  {
94  " number inserte in front of "<< nm << " is invalid: "<< num<<endl<<
95  " in dictionary "<<dict.globalName()<<endl;
96  return false;
97  }
98  number_.push_back( num );
99  }
100 
101  if(containNumberIneserted)
102  {
103  numberInserted_ = dict.getVal<uint32Vector>("numberInserted");
104  }
105  else
106  {
107  numberInserted_ = uint32Vector(size(), static_cast<uint32>(0));
108  }
109 
110  if(numberInserted_.size() != names_.size() )
111  {
113  " number of elements in numberInserted ("<<numberInserted_.size()<<
114  ") is not equal to the number of shape names: "<< names_<<endl;
115  return false;
116  }
117 
118  current_.clear();
119  ForAll(i, numberInserted_)
120  {
121  current_.push_back(numberInserted_[i]%number_[i]);
122  }
123 
124  return true;
125 }
126 
128 (
129  dictionary& dict
130 ) const
131 {
132 
133  ForAll(i, names_)
134  {
135  if(!dict.add(names_[i],number_[i]))
136  {
138  " error in writing "<< names_[i] << " to dictionary "<<dict.globalName()<<endl;
139  return false;
140  }
141  }
142 
143  if(!dict.add("numberInserted", numberInserted_))
144  {
146  " error in writing numberInserted to dictionary "<< dict.globalName()<<endl;
147  return false;
148  }
149 
150  return true;
151 }
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