KratosMultiphysics
KRATOS Multiphysics (Kratos) is a framework for building parallel, multi-disciplinary simulation software, aiming at modularity, extensibility, and high performance. Kratos is written in C++, and counts with an extensive Python interface.
geometry_container.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // Kratos default license: kratos/license.txt
9 //
10 // Main authors: Pooyan Dadvand
11 //
12 
13 #pragma once
14 
15 // System includes
16 
17 // External includes
18 
19 // Project includes
20 #include "includes/define.h"
22 
23 
24 namespace Kratos
25 {
26 
29 
30 template<class TGeometryType>
32 {
33  class GetGeometryId
34  {
35  public:
36  std::size_t const& operator()(const TGeometryType& rGeometry) const
37  {
38  return rGeometry.Id();
39  }
40  };
41 
42 public:
45 
48 
49  typedef std::size_t IndexType;
50  typedef std::size_t SizeType;
51 
52  typedef typename TGeometryType::Pointer GeometryPointerType;
53 
54 
56  // Stores with hash of Ids to corresponding geometries.
57  typedef PointerHashMapSet<
58  TGeometryType,
59  std::hash<std::size_t>,
60  GetGeometryId,
63 
66 
69 
73 
76  : mGeometries()
77  {}
78 
81  : mGeometries(rOther.mGeometries)
82  {}
83 
86  GeometriesMapType& NewGeometries)
87  : mGeometries(NewGeometries)
88  {}
89 
91  ~GeometryContainer() = default;
92 
96 
98  {
99  typename GeometriesMapType::Pointer p_geometries(new GeometriesMapType(*mGeometries));
100 
101  return GeometryContainer(p_geometries);
102  }
103 
104  void Clear()
105  {
106  mGeometries.clear();
107  }
108 
112 
115  {
116  return mGeometries.size();
117  }
118 
122 
125  {
126  auto i = mGeometries.find(pNewGeometry->Id());
127  if (i == mGeometries.end()) {
128  return mGeometries.insert(pNewGeometry);
129  } else if (&(*i) == pNewGeometry.get()) { // check if the pointee coincides
130  return i;
131  } else {
132  KRATOS_ERROR << "Attempting to add Geometry with Id: " << pNewGeometry->Id() << ", unfortunately a (different) geometry with the same Id already exists!" << std::endl;
133  }
134  }
135 
139 
142  {
143  auto i = mGeometries.find(GeometryId);
144  KRATOS_ERROR_IF(i == mGeometries.end())
145  << " geometry index not found: " << GeometryId << ".";
146  return (i.base()->second);
147  }
148 
151  {
152  auto i = mGeometries.find(GeometryId);
153  KRATOS_ERROR_IF(i == mGeometries.end())
154  << " geometry index not found: " << GeometryId << ".";
155  return (i.base()->second);
156  }
157 
159  GeometryPointerType pGetGeometry(std::string GeometryName)
160  {
161  auto hash_index = TGeometryType::GenerateId(GeometryName);
162  auto i = mGeometries.find(hash_index);
163  KRATOS_ERROR_IF(i == mGeometries.end())
164  << " geometry index not found: " << GeometryName << ".";
165  return (i.base()->second);
166  }
167 
169  const GeometryPointerType pGetGeometry(std::string GeometryName) const
170  {
171  auto hash_index = TGeometryType::GenerateId(GeometryName);
172  auto i = mGeometries.find(hash_index);
173  KRATOS_ERROR_IF(i == mGeometries.end())
174  << " geometry index not found: " << GeometryName << ".";
175  return (i.base()->second);
176  }
177 
179  TGeometryType& GetGeometry(IndexType GeometryId)
180  {
181  return *pGetGeometry(GeometryId);
182  }
183 
185  const TGeometryType& GetGeometry(IndexType GeometryId) const
186  {
187  return *pGetGeometry(GeometryId);
188  }
189 
191  TGeometryType& GetGeometry(std::string GeometryName)
192  {
193  return *pGetGeometry(GeometryName);
194  }
195 
197  const TGeometryType& GetGeometry(std::string GeometryName) const
198  {
199  return *pGetGeometry(GeometryName);
200  }
201 
205 
207  void RemoveGeometry(IndexType GeometryId)
208  {
209  mGeometries.erase(GeometryId);
210  }
211 
213  void RemoveGeometry(std::string GeometryName)
214  {
215  auto index = TGeometryType::GenerateId(GeometryName);
216 
217  mGeometries.erase(index);
218  }
219 
223 
224  bool HasGeometry(IndexType GeometryId) const
225  {
226  return (mGeometries.find(GeometryId) != mGeometries.end());
227  }
228 
229  bool HasGeometry(std::string GeometryName) const
230  {
231  auto hash_index = TGeometryType::GenerateId(GeometryName);
232 
233  return (mGeometries.find(hash_index) != mGeometries.end());
234  }
235 
239 
241  {
242  return mGeometries.begin();
243  }
244 
246  {
247  return mGeometries.begin();
248  }
249 
251  {
252  return mGeometries.end();
253  }
254 
256  {
257  return mGeometries.end();
258  }
259 
263 
265  {
266  return mGeometries;
267  }
268 
270  {
271  return mGeometries;
272  }
273 
277 
279  std::string Info() const
280  {
281  return "GeometryContainer";
282  }
283 
285  void PrintInfo(std::ostream& rOStream) const
286  {
287  rOStream << Info();
288  }
289 
291  void PrintData(std::ostream& rOStream) const
292  {
293  rOStream << "Number of Geometries: " << mGeometries.size() << std::endl;
294  }
295 
297  virtual void PrintInfo(std::ostream& rOStream, std::string const& PrefixString) const
298  {
299  rOStream << PrefixString << Info();
300  }
301 
303  virtual void PrintData(std::ostream& rOStream, std::string const& PrefixString ) const
304  {
305  rOStream << PrefixString << "Number of Geometries: " << mGeometries.size() << std::endl;
306  }
307 
309 
310 private:
313 
315  GeometriesMapType mGeometries;
316 
320 
321  friend class Serializer;
322 
323  void save(Serializer& rSerializer) const
324  {
325  rSerializer.save("Geometries", mGeometries);
326  }
327 
328  void load(Serializer& rSerializer)
329  {
330  rSerializer.load("Geometries", mGeometries);
331  }
332 
336 
339  {
340  mGeometries = rOther.mGeometries;
341  return *this;
342  }
343 
345 
346 }; // Class GeometryContainer
347 
351 
353 template<class TGeometryType>
354 inline std::istream& operator >> (std::istream& rIStream,
356 
358 template<class TGeometryType>
359 inline std::ostream& operator << (std::ostream& rOStream,
361 {
362  rThis.PrintInfo(rOStream);
363  rOStream << std::endl;
364  rThis.PrintData(rOStream);
365 
366  return rOStream;
367 }
369 
370 } // namespace Kratos.
PeriodicInterfaceProcess & operator=(const PeriodicInterfaceProcess &)=delete
Definition: geometry_container.h:32
GeometryContainer(GeometriesMapType &NewGeometries)
Components Constructor.
Definition: geometry_container.h:85
void Clear()
Definition: geometry_container.h:104
GeometryIterator GeometriesBegin()
Definition: geometry_container.h:240
const TGeometryType & GetGeometry(IndexType GeometryId) const
Returns a const reference geometry corresponding to the id.
Definition: geometry_container.h:185
virtual void PrintData(std::ostream &rOStream, std::string const &PrefixString) const
Print object's data.
Definition: geometry_container.h:303
TGeometryType & GetGeometry(std::string GeometryName)
Returns a reference geometry corresponding to the name.
Definition: geometry_container.h:191
const GeometryPointerType pGetGeometry(IndexType GeometryId) const
Returns the const Geometry::Pointer corresponding to its Id.
Definition: geometry_container.h:150
GeometryPointerType pGetGeometry(std::string GeometryName)
Returns the Geometry::Pointer corresponding to its name.
Definition: geometry_container.h:159
bool HasGeometry(std::string GeometryName) const
Definition: geometry_container.h:229
const TGeometryType & GetGeometry(std::string GeometryName) const
Returns a const reference geometry corresponding to the name.
Definition: geometry_container.h:197
GeometryIterator GeometriesEnd()
Definition: geometry_container.h:250
std::size_t SizeType
Definition: geometry_container.h:50
PointerHashMapSet< TGeometryType, std::hash< std::size_t >, GetGeometryId, GeometryPointerType > GeometriesMapType
Geometry Hash Map Container.
Definition: geometry_container.h:62
TGeometryType & GetGeometry(IndexType GeometryId)
Returns a reference geometry corresponding to the id.
Definition: geometry_container.h:179
const GeometriesMapType & Geometries() const
Definition: geometry_container.h:269
GeometriesMapType::const_iterator GeometryConstantIterator
Const Geometry Iterator.
Definition: geometry_container.h:68
GeometriesMapType & Geometries()
Definition: geometry_container.h:264
GeometryContainer(GeometryContainer const &rOther)
Copy Constructor.
Definition: geometry_container.h:80
virtual void PrintInfo(std::ostream &rOStream, std::string const &PrefixString) const
Print information about this object.
Definition: geometry_container.h:297
GeometriesMapType::iterator GeometryIterator
Geometry Iterator.
Definition: geometry_container.h:65
void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: geometry_container.h:291
GeometryIterator AddGeometry(GeometryPointerType pNewGeometry)
Adds a geometry to the geometry container.
Definition: geometry_container.h:124
KRATOS_CLASS_POINTER_DEFINITION(GeometryContainer)
Pointer definition of GeometryContainer.
GeometryConstantIterator GeometriesEnd() const
Definition: geometry_container.h:255
bool HasGeometry(IndexType GeometryId) const
Definition: geometry_container.h:224
void RemoveGeometry(IndexType GeometryId)
Remove the geometry with given Id from geometry container.
Definition: geometry_container.h:207
GeometryPointerType pGetGeometry(IndexType GeometryId)
Returns the Geometry::Pointer corresponding to its Id.
Definition: geometry_container.h:141
TGeometryType::Pointer GeometryPointerType
Definition: geometry_container.h:52
GeometryConstantIterator GeometriesBegin() const
Definition: geometry_container.h:245
void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: geometry_container.h:285
GeometryContainer()
Default Constructor.
Definition: geometry_container.h:75
GeometryContainer Clone()
Definition: geometry_container.h:97
const GeometryPointerType pGetGeometry(std::string GeometryName) const
Returns the Geometry::Pointer corresponding to its name.
Definition: geometry_container.h:169
void RemoveGeometry(std::string GeometryName)
Remove the geometry with given name from geometry container.
Definition: geometry_container.h:213
~GeometryContainer()=default
Destructor.
std::string Info() const
Return information.
Definition: geometry_container.h:279
std::size_t IndexType
Definition: geometry_container.h:49
SizeType NumberOfGeometries() const
Return number of geometries stored inside this geometry container.
Definition: geometry_container.h:114
PointerHashMapSet is a hash implemenetation of the PointerVectorSet.
Definition: pointer_hash_map_set.h:70
void clear()
Definition: pointer_hash_map_set.h:335
iterator end()
Definition: pointer_hash_map_set.h:228
iterator begin()
Definition: pointer_hash_map_set.h:220
iterator find(const key_type &Key)
Definition: pointer_hash_map_set.h:340
iterator insert(const TOtherDataType &rData)
Definition: pointer_hash_map_set.h:295
size_type size() const
Definition: pointer_hash_map_set.h:274
iterator erase(iterator pos)
Definition: pointer_hash_map_set.h:320
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
void load(std::string const &rTag, TDataType &rObject)
Definition: serializer.h:207
void save(std::string const &rTag, std::array< TDataType, TDataSize > const &rObject)
Definition: serializer.h:545
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
def load(f)
Definition: ode_solve.py:307
integer i
Definition: TensorModule.f:17