sphereShape.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 
21 #ifndef __sphereShape_hpp__
22 #define __sphereShape_hpp__
23 
24 #include "Vectors.hpp"
25 #include "hashMap.hpp"
26 
27 namespace pFlow
28 {
29 
30 class dictionary;
31 
33 {
34 protected:
35 
36  // - diameter of spheres
38 
39  // - property name of spheres
41 
42  // - hashed list of spheres names
44 
45  size_t numShapes_;
46 
47 
48  bool insertNames(const wordVector& names);
49 
50  bool readDictionary(const dictionary& dict);
51 
52  bool writeDictionary(dictionary& dict)const;
53 
54 public:
55 
56  // - type info
57  TypeInfoNV("sphereShape");
58 
59 
61 
63  const realVector& diameter,
64  const wordVector& property,
65  const wordVector& name
66  );
67 
68  sphereShape(const sphereShape&) = default;
69 
70  sphereShape(sphereShape&&) = default;
71 
72  sphereShape& operator=(const sphereShape&) = default;
73 
74  sphereShape& operator=(sphereShape&&) = default;
75 
76  auto clone()const
77  {
78  return makeUnique<sphereShape>(*this);
79  }
80 
82  {
83  return new sphereShape(*this);
84  }
85 
86  ~sphereShape() = default;
87 
89  const auto& names()const{
90  return names_;
91  }
92 
93  const auto& diameters()const{
94  return diameters_;
95  }
96 
97  const auto& materials()const{
98  return materials_;
99  }
100 
101  const auto diameter(label i)const{
102  return diameters_[i];
103  }
104 
105  const auto material(label i)const{
106  return materials_[i];
107  }
108 
109 
110  // name to index
111  bool nameToIndex(const word& name, uint32& index)const
112  {
113  if(auto[iter, found] = names_.findIf(name); found )
114  {
115  index = iter->second;
116  return true;
117  }
118  else
119  {
120  index = 0;
121  return false;
122  }
123  }
124 
125  uint32 nameToIndex(const word& name)const
126  {
127  return names_.at(name);
128  }
129 
130  bool indexToName(uint32 i, word& name)const
131  {
132  for(auto& nm: names_)
133  {
134  if(nm.second == i)
135  {
136  name = nm.first;
137  return true;
138  }
139  }
140  name = "";
141  return false;
142  }
143 
144  bool shapeToDiameter(wordVector& names, realVector& diams)const;
145 
146  void diameterMinMax(real& minD, real& maxD)const
147  {
148  minD = min(diameters_);
149  maxD = max(diameters_);
150  }
151 
153 
154  // - read from stream/file
155  bool read(iIstream& is);
156 
157  // - write to stream/file
158  bool write(iOstream& os)const;
159 
160  // - read from dictionary
161  bool read(const dictionary& dict)
162  {
163  return readDictionary(dict);
164  }
165 
166  // - write to dictionary
167  bool write(dictionary& dict)const
168  {
169  return writeDictionary(dict);
170  }
171 
172 
173 };
174 
175 } // pFlow
176 
177 #endif //__sphereShape_hpp__
pFlow::sphereShape::diameter
const auto diameter(label i) const
Definition: sphereShape.hpp:101
pFlow::sphereShape::write
bool write(dictionary &dict) const
Definition: sphereShape.hpp:167
hashMap.hpp
pFlow::real
float real
Definition: builtinTypes.hpp:46
pFlow::sphereShape
Definition: sphereShape.hpp:32
pFlow::sphereShape::diameters
const auto & diameters() const
Definition: sphereShape.hpp:93
pFlow::hashMap
Definition: hashMap.hpp:36
pFlow::sphereShape::write
bool write(iOstream &os) const
Definition: sphereShape.cpp:186
pFlow::uint32
unsigned int uint32
Definition: builtinTypes.hpp:59
pFlow::word
std::string word
Definition: builtinTypes.hpp:63
pFlow::sphereShape::numShapes_
size_t numShapes_
Definition: sphereShape.hpp:45
pFlow::sphereShape::~sphereShape
~sphereShape()=default
Vectors.hpp
pFlow::sphereShape::clone
auto clone() const
Definition: sphereShape.hpp:76
pFlow::sphereShape::materials
const auto & materials() const
Definition: sphereShape.hpp:97
pFlow::sphereShape::names_
wordHashMap< uint32 > names_
Definition: sphereShape.hpp:43
pFlow::sphereShape::diameters_
realVector diameters_
Definition: sphereShape.hpp:37
pFlow
Definition: demComponent.hpp:28
pFlow::sphereShape::nameToIndex
uint32 nameToIndex(const word &name) const
Definition: sphereShape.hpp:125
pFlow::sphereShape::read
bool read(const dictionary &dict)
Definition: sphereShape.hpp:161
pFlow::sphereShape::read
bool read(iIstream &is)
Definition: sphereShape.cpp:166
pFlow::sphereShape::indexToName
bool indexToName(uint32 i, word &name) const
Definition: sphereShape.hpp:130
pFlow::sphereShape::names
const auto & names() const
Definition: sphereShape.hpp:89
pFlow::iIstream
Definition: iIstream.hpp:33
pFlow::sphereShape::clonePtr
sphereShape * clonePtr() const
Definition: sphereShape.hpp:81
pFlow::sphereShape::sphereShape
sphereShape()
Definition: sphereShape.hpp:60
pFlow::sphereShape::writeDictionary
bool writeDictionary(dictionary &dict) const
Definition: sphereShape.cpp:85
pFlow::sphereShape::operator=
sphereShape & operator=(const sphereShape &)=default
pFlow::sphereShape::nameToIndex
bool nameToIndex(const word &name, uint32 &index) const
Definition: sphereShape.hpp:111
pFlow::max
T max(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:164
pFlow::property
property holds the pure properties of materials.
Definition: property.hpp:40
pFlow::sphereShape::TypeInfoNV
TypeInfoNV("sphereShape")
pFlow::sphereShape::insertNames
bool insertNames(const wordVector &names)
Definition: sphereShape.cpp:28
pFlow::label
std::size_t label
Definition: builtinTypes.hpp:61
pFlow::sphereShape::readDictionary
bool readDictionary(const dictionary &dict)
Definition: sphereShape.cpp:53
pFlow::Vector< real >
pFlow::iOstream
Definition: iOstream.hpp:53
pFlow::sphereShape::shapeToDiameter
bool shapeToDiameter(wordVector &names, realVector &diams) const
Definition: sphereShape.cpp:144
pFlow::min
T min(const Vector< T, Allocator > &v)
Definition: VectorMath.hpp:138
pFlow::dictionary
Definition: dictionary.hpp:38
pFlow::sphereShape::diameterMinMax
void diameterMinMax(real &minD, real &maxD) const
Definition: sphereShape.hpp:146
pFlow::sphereShape::materials_
wordVector materials_
Definition: sphereShape.hpp:40
pFlow::sphereShape::material
const auto material(label i) const
Definition: sphereShape.hpp:105