www.cemf.ir
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 "fileDictionary.hpp"
26 #include "iFstream.hpp"
27 
28 namespace pFlow
29 {
30 
37 class property
38 :
39  public fileDictionary
40 {
41 private:
42 
43  // - protected data members
44 
47 
50 
53 
54 
57 
58 
59  // - protected member functions
60 
62  bool readDictionary();
63 
65  bool writeDictionary();
66 
68  bool makeNameIndex();
69 
70 public:
71 
73  TypeInfo("property");
74 
75  // - Constructors
76 
77  explicit
78  property(
79  const word& fileName,
80  repository* owner=nullptr);
81 
82  property(
83  const word& fileName,
84  const fileSystem& dir
85  );
86 
87  property(const word& fileName,
88  const wordVector& materials,
89  const realVector& densities,
90  repository* owner=nullptr);
91 
93  property(const property& ) = default;
94 
96  property(property&& ) = default;
97 
99  property& operator= (const property&) = default;
100 
102  property& operator= (property&&) = default;
103 
105  ~property() override = default;
106 
107 
108  // - Methods
109 
111  inline auto numMaterials()const
112  {
113  return numMaterials_;
114  }
115 
117  inline const auto& materials()const{
118  return materials_;
119  }
120 
122  inline const auto& densities()const{
123  return densities_;
124  }
125 
127  inline const word& material(uint32 i)const
128  {
129  return materials_[i];
130  }
131 
134  inline bool material(uint32 i, word& name)const
135  {
136  if(i<numMaterials_)
137  {
138  name = material(i);
139  return true;
140  }
141  else
142  {
143  name.clear();
144  return false;
145  }
146  }
147 
149  inline real density(uint32 i)const
150  {
151  return densities_[i];
152  }
153 
156  inline bool density(uint32 i, real& rho)const
157  {
158  if(i<numMaterials_)
159  {
160  rho = density(i);
161  return true;
162  }
163  else
164  {
165  rho = 0.00001;
166  return false;
167  }
168  }
169 
172  inline bool nameToIndex(const word& name, uint32& idx)const
173  {
174  if(auto[iter, found] = nameIndex_.findIf(name); found )
175  {
176  idx = iter->second;
177  return true;
178  }
179  else
180  {
181  idx = 0;
182  return false;
183  }
184  }
185 
186 
187 
188 };
189 
190 }
191 
192 #endif // __property_hpp__
pFlow::property::densities_
realVector densities_
list of density of materials
Definition: property.hpp:49
hashMap.hpp
pFlow::property::makeNameIndex
bool makeNameIndex()
creates a mapp
Definition: property.cpp:63
pFlow::property::readDictionary
bool readDictionary()
read from dict
Definition: property.cpp:24
pFlow::real
float real
Definition: builtinTypes.hpp:45
pFlow::property::materials_
wordVector materials_
list of name of materials
Definition: property.hpp:46
pFlow::hashMap
Definition: hashMap.hpp:36
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:56
pFlow::word
std::string word
Definition: builtinTypes.hpp:64
pFlow::property::~property
~property() override=default
Default destructor.
pFlow::property::densities
const auto & densities() const
Return the list of densities.
Definition: property.hpp:122
pFlow::property::property
property(const word &fileName, repository *owner=nullptr)
Definition: property.cpp:122
Vectors.hpp
pFlow::property::material
const word & material(uint32 i) const
Return the material name of material i.
Definition: property.hpp:127
pFlow
Definition: demGeometry.hpp:27
pFlow::fileSystem
Manages file pathes, manupulate and combines them.
Definition: fileSystem.hpp:71
pFlow::property::materials
const auto & materials() const
Return list of material names.
Definition: property.hpp:117
pFlow::property::writeDictionary
bool writeDictionary()
write to dict
Definition: property.cpp:43
pFlow::property::material
bool material(uint32 i, word &name) const
Get the name of material i.
Definition: property.hpp:134
pFlow::property::nameIndex_
wordHashMap< uint32 > nameIndex_
rapid mapping from name to index
Definition: property.hpp:52
pFlow::property::operator=
property & operator=(const property &)=default
Default copy assignment.
pFlow::IOobject::owner
const repository * owner() const override
Definition: IOobject.hpp:76
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:172
pFlow::property::numMaterials
auto numMaterials() const
Return number of materials.
Definition: property.hpp:111
pFlow::iEntry::name
virtual word name() const
name/keyword of entry
Definition: iEntry.hpp:100
pFlow::property
property holds the pure properties of materials.
Definition: property.hpp:37
pFlow::property::density
bool density(uint32 i, real &rho) const
Get the density of material i.
Definition: property.hpp:156
fileDictionary.hpp
pFlow::fileDictionary
Definition: fileDictionary.hpp:29
pFlow::property::numMaterials_
uint32 numMaterials_
number of materials
Definition: property.hpp:56
pFlow::repository
Definition: repository.hpp:34
pFlow::property::density
real density(uint32 i) const
Return density of material i.
Definition: property.hpp:149
iFstream.hpp
pFlow::Vector< word >
pFlow::property::TypeInfo
TypeInfo("property")
Type info.