www.cemf.ir
property.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 "property.hpp"
22 #include "dictionary.hpp"
23 
25 {
26 
27  materials_ = getVal<wordVector>("materials");
28 
29  densities_ = getVal<realVector>("densities");
30 
31  if(materials_.size() != densities_.size() )
32  {
34  " number of elements in material ("<<materials_.size()<<
35  ") is not equal to number of elements in densities ("<<densities_.size()<<
36  ") in dictionary "<< globalName()<<endl;
37  return false;
38  }
39 
40  return true;
41 }
42 
44 {
45 
46  if(!add("materials", materials_))
47  {
49  " error in writing materials to dictionary "<< globalName()<<endl;
50  return false;
51  }
52 
53  if(!add("densities", densities_))
54  {
56  " error in writing densities to dictionary "<< globalName()<<endl;
57  return false;
58  }
59 
60  return true;
61 }
62 
64 {
65  nameIndex_.clear();
66 
67 
68  uint32 i=0;
69  for(auto const& nm:materials_)
70  {
71  if(!nameIndex_.insertIf(nm, i))
72  {
74  " repeated material name in the list of materials: " << materials_;
75  return false;
76  }
77  i++;
78  }
79  nameIndex_.rehash(0);
80  numMaterials_ = static_cast<uint32>(materials_.size());
81  return true;
82 }
83 
84 
86 (
87  const word& fileName,
88  const wordVector& materials,
89  const realVector& densities,
90  repository* owner
91 )
92 :
94  (
96  (
97  fileName,
98  "",
101  ),
102  owner
103  ),
104  materials_(materials),
105  densities_(densities)
106 {
107 
108  if(!writeDictionary())
109  {
110  fatalExit;
111  }
112 
113  if(!makeNameIndex())
114  {
116  "error in the input parameters of constructor. \n";
117  fatalExit;
118  }
119 }
120 
122 (
123  const word& fileName,
124  repository* owner
125 )
126 :
128  (
129  objectFile
130  (
131  fileName,
132  "",
135  ),
136  owner
137  )
138 {
139 
140  if(!readDictionary())
141  {
142  fatalExit;
143  }
144 
145  if(!makeNameIndex())
146  {
148  "error in dictionary "<< globalName()<<endl;
149  fatalExit;
150  }
151 
152 }
153 
155 (
156  const word &fileName,
157  const fileSystem &dir
158 )
159 :
161  (
162  objectFile
163  (
164  fileName,
165  dir,
168  ),
169  nullptr
170  )
171 {
172  if(!readDictionary())
173  {
174  fatalExit;
175  }
176 
177  if(!makeNameIndex())
178  {
180  "error in dictionary "<< globalName()<<endl;
181  fatalExit;
182  }
183 }
pFlow::property::densities_
realVector densities_
list of density of materials
Definition: property.hpp:49
pFlow::property::makeNameIndex
bool makeNameIndex()
creates a mapp
Definition: property.cpp:63
pFlow::property::readDictionary
bool readDictionary()
read from dict
Definition: property.cpp:24
fatalExit
#define fatalExit
Fatal exit.
Definition: error.hpp:98
pFlow::property::materials_
wordVector materials_
list of name of materials
Definition: property.hpp:46
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::property::property
property(const word &fileName, repository *owner=nullptr)
Definition: property.cpp:122
pFlow::dictionary::globalName
virtual word globalName() const
global name of entry, separated with dots
Definition: dictionary.cpp:356
pFlow::Vector::size
auto size() const
Size of the vector.
Definition: Vector.hpp:265
pFlow::endl
iOstream & endl(iOstream &os)
Add newline and flush stream.
Definition: iOstream.hpp:341
pFlow::objectFile::WRITE_NEVER
@ WRITE_NEVER
Definition: objectFile.hpp:44
pFlow::fileSystem
Manages file pathes, manupulate and combines them.
Definition: fileSystem.hpp:71
fatalErrorInFunction
#define fatalErrorInFunction
Report a fatal error and function name and exit the application.
Definition: error.hpp:77
dictionary.hpp
pFlow::objectFile::READ_ALWAYS
@ READ_ALWAYS
Definition: objectFile.hpp:36
pFlow::property::writeDictionary
bool writeDictionary()
write to dict
Definition: property.cpp:43
pFlow::objectFile
Definition: objectFile.hpp:30
pFlow::objectFile::READ_NEVER
@ READ_NEVER
Definition: objectFile.hpp:37
pFlow::fileDictionary
Definition: fileDictionary.hpp:29
pFlow::repository
Definition: repository.hpp:34
property.hpp
pFlow::Vector< word >