property.hpp
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 #ifndef __property_hpp__
21 #define __property_hpp__
22 
23 #include "Vectors.hpp"
24 #include "hashMap.hpp"
25 #include "fileSystem.hpp"
26 #include "iFstream.hpp"
27 
28 namespace pFlow
29 {
30 
31 // forward
32 class dictionary;
33 
40 class property
41 {
42 protected:
43 
44  // - protected data members
45 
48 
51 
54 
57 
60 
61 
62  // - protected member functions
63 
65  bool readDictionary(const dictionary& dict);
66 
68  bool writeDictionary(dictionary& dict)const;
69 
71  bool makeNameIndex();
72 
73 public:
74 
76  TypeInfoNV("property");
77 
78 
79  // - Constructors
80 
83 
86 
88  property(const fileSystem& file);
89 
91  property(const dictionary& dict);
92 
94  property(const property& ) = default;
95 
97  property(property&& ) = default;
98 
100  property& operator= (const property&) = default;
101 
103  property& operator= (property&&) = default;
104 
106  ~property() = default;
107 
108 
109  // - Methods
110 
112  inline const auto& dict()const
113  {
114  return dict_();
115  }
116 
118  inline auto numMaterials()const
119  {
120  return numMaterials_;
121  }
122 
124  inline const auto& materials()const{
125  return materials_;
126  }
127 
129  inline const auto& densities()const{
130  return densities_;
131  }
132 
134  inline const word& material(uint32 i)const
135  {
136  return materials_[i];
137  }
138 
141  inline bool material(uint32 i, word& name)const
142  {
143  if(i<numMaterials_)
144  {
145  name = material(i);
146  return true;
147  }
148  else
149  {
150  name.clear();
151  return false;
152  }
153  }
154 
156  inline real density(uint32 i)const
157  {
158  return densities_[i];
159  }
160 
163  inline bool density(uint32 i, real& rho)const
164  {
165  if(i<numMaterials_)
166  {
167  rho = density(i);
168  return true;
169  }
170  else
171  {
172  rho = 0.00001;
173  return false;
174  }
175  }
176 
179  inline bool nameToIndex(const word& name, uint32& idx)const
180  {
181  if(auto[iter, found] = nameIndex_.findIf(name); found )
182  {
183  idx = iter->second;
184  return true;
185  }
186  else
187  {
188  idx = 0;
189  return false;
190  }
191  }
192 
194 
196  bool read(const dictionary& dict)
197  {
198  return readDictionary(dict);
199  }
200 
202  bool write(dictionary& dict)const
203  {
204  return writeDictionary(dict);
205  }
206 
207 };
208 
209 }
210 
211 #endif // __property_hpp__
pFlow::property::dict_
uniquePtr< dictionary > dict_
pointer to the dictionary, if it is constructed from a file/dictionary
Definition: property.hpp:47
pFlow::property::densities_
realVector densities_
list of density of materials
Definition: property.hpp:53
hashMap.hpp
pFlow::property::makeNameIndex
bool makeNameIndex()
creates a mapp
Definition: property.cpp:76
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::property::materials_
wordVector materials_
list of name of materials
Definition: property.hpp:50
pFlow::property::writeDictionary
bool writeDictionary(dictionary &dict) const
write to dict
Definition: property.cpp:54
pFlow::hashMap
Definition: hashMap.hpp:36
pFlow::property::dict
const auto & dict() const
Return dictionary.
Definition: property.hpp:112
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::property::densities
const auto & densities() const
Return the list of densities.
Definition: property.hpp:129
Vectors.hpp
pFlow::property::material
const word & material(uint32 i) const
Return the material name of material i.
Definition: property.hpp:134
pFlow::property::read
bool read(const dictionary &dict)
Read from dictionary.
Definition: property.hpp:196
fileSystem.hpp
pFlow
Definition: demComponent.hpp:28
pFlow::fileSystem
Definition: fileSystem.hpp:63
pFlow::property::materials
const auto & materials() const
Return list of material names.
Definition: property.hpp:124
pFlow::property::readDictionary
bool readDictionary(const dictionary &dict)
read from dict
Definition: property.cpp:26
pFlow::property::material
bool material(uint32 i, word &name) const
Get the name of material i.
Definition: property.hpp:141
pFlow::property::nameIndex_
wordHashMap< uint32 > nameIndex_
rapid mapping from name to index
Definition: property.hpp:56
pFlow::property::operator=
property & operator=(const property &)=default
Default copy assignment.
pFlow::property::nameToIndex
bool nameToIndex(const word &name, uint32 &idx) const
Get the name of material in index idx Return true, if the name found, otherwise false.
Definition: property.hpp:179
pFlow::property::~property
~property()=default
Default destructor.
pFlow::property::numMaterials
auto numMaterials() const
Return number of materials.
Definition: property.hpp:118
pFlow::property::property
property()
Emptry constructor, used for reading from a file.
Definition: property.hpp:82
pFlow::property::TypeInfoNV
TypeInfoNV("property")
Type info.
pFlow::property
property holds the pure properties of materials.
Definition: property.hpp:40
pFlow::property::density
bool density(uint32 i, real &rho) const
Get the density of material i.
Definition: property.hpp:163
pFlow::uniquePtr
Definition: uniquePtr.hpp:44
pFlow::property::numMaterials_
uint32 numMaterials_
number of materials
Definition: property.hpp:59
pFlow::property::density
real density(uint32 i) const
Return density of material i.
Definition: property.hpp:156
iFstream.hpp
pFlow::Vector< word >
pFlow::dictionary
Definition: dictionary.hpp:38
pFlow::property::write
bool write(dictionary &dict) const
Write to dictionary.
Definition: property.hpp:202