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 
22 #include "property.hpp"
23 #include "dictionary.hpp"
24 
26 (
27  const dictionary& dict
28 )
29 {
30 
31  materials_ = dict.getVal<wordVector>("materials");
32 
33  densities_ = dict.getVal<realVector>("densities");
34 
35  if(materials_.size() != densities_.size() )
36  {
38  " number of elements in material ("<<materials_.size()<<
39  ") is not equal to number of elements in densities ("<<densities_.size()<<
40  ") in dictionary "<< dict.globalName()<<endl;
41  return false;
42  }
43 
44  if(!makeNameIndex())
45  {
47  " error in dictionary "<< dict.globalName()<<endl;
48  return false;
49  }
50  return true;
51 }
52 
54 (
55  dictionary& dict
56 )const
57 {
58 
59  if(!dict.add("materials", materials_))
60  {
62  " error in writing materials to dictionary "<< dict.globalName()<<endl;
63  return false;
64  }
65 
66  if(!dict.add("densities", densities_))
67  {
69  " error in writing densities to dictionary "<< dict.globalName()<<endl;
70  return false;
71  }
72 
73  return true;
74 }
75 
77 {
78  nameIndex_.clear();
79 
80  uint32 i=0;
81  for(auto& nm:materials_)
82  {
83  if(!nameIndex_.insertIf(nm, i++))
84  {
86  " repeated material name in the list of materials: " << materials_;
87  return false;
88  }
89  }
90  nameIndex_.rehash(0);
92  return true;
93 }
94 
95 
97 (
98  const wordVector& materials,
99  const realVector& densities
100 )
101 :
102  materials_(materials),
103  densities_(densities)
104 {
105  if(!makeNameIndex())
106  {
108  " error in the input parameters of constructor. \n";
109  fatalExit;
110  }
111 }
112 
114 (
115 const fileSystem& file
116 )
117 :
118  dict_
119  (
120  makeUnique<dictionary>
121  ("property", true)
122  )
123 {
124  iFstream dictStream(file);
125 
126  if(!dict_().read(dictStream))
127  {
128  ioErrorInFile(dictStream.name(), dictStream.lineNumber());
129  fatalExit;
130  }
131 
132  if(!readDictionary(dict_()))
133  {
134  fatalExit;
135  }
136 
137 }
138 
140 (
141  const dictionary& dict
142 )
143 :
144  dict_
145  (
146  makeUnique<dictionary>(dict)
147  )
148 {
149 
150  if(!readDictionary(dict_()))
151  {
152  fatalExit;
153  }
154 }
155 
pFlow::property::makeNameIndex
bool makeNameIndex()
creates a mapp
Definition: property.cpp:76
fatalExit
#define fatalExit
Definition: error.hpp:57
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::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::dictionary::globalName
virtual word globalName() const
Definition: dictionary.cpp:349
pFlow::Istream::name
virtual const word & name() const
Definition: Istream.hpp:78
pFlow::Vector::size
auto size() const
Definition: Vector.hpp:299
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::iFstream
Definition: iFstream.hpp:35
pFlow::fileSystem
Definition: fileSystem.hpp:63
fatalErrorInFunction
#define fatalErrorInFunction
Definition: error.hpp:42
pFlow::property::readDictionary
bool readDictionary(const dictionary &dict)
read from dict
Definition: property.cpp:26
dictionary.hpp
pFlow::property::nameIndex_
wordHashMap< uint32 > nameIndex_
rapid mapping from name to index
Definition: property.hpp:56
pFlow::property::property
property()
Emptry constructor, used for reading from a file.
Definition: property.hpp:82
pFlow::dictionary::getVal
T getVal(const word &keyword) const
Definition: dictionary.hpp:309
ioErrorInFile
#define ioErrorInFile(fileName, lineNumber)
Definition: error.hpp:49
pFlow::property::numMaterials_
uint32 numMaterials_
number of materials
Definition: property.hpp:59
pFlow::IOstream::lineNumber
int32 lineNumber() const
Definition: IOstream.hpp:187
property.hpp
pFlow::Vector< word >
pFlow::dictionary
Definition: dictionary.hpp:38