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.
mapping_variables.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: Vicente Mataix Ferrandiz
11 //
12 
13 #if !defined(KRATOS_MAPPING_VARIABLES_H_INCLUDED)
14 #define KRATOS_MAPPING_VARIABLES_H_INCLUDED
15 
16 // System includes
17 #include <unordered_set>
18 #include <unordered_map>
19 
20 // External includes
21 
22 // Project includes
23 #include "includes/condition.h"
24 #include "includes/define.h"
25 #include "includes/key_hash.h"
26 #include "containers/variable.h"
27 
28 #undef KRATOS_EXPORT_MACRO
29 #define KRATOS_EXPORT_MACRO KRATOS_API
30 
31 namespace Kratos
32 {
35 
39 
40  typedef std::size_t IndexType;
41 
45 
49 
53 
61  {
62  public:
67 
71 
74 
76  virtual ~IndexDatabase(){}
77 
81 
85 
91  virtual bool Has(const IndexType IndexOrigin) {return false;}
92 
98  virtual void AddId(
99  const IndexType IndexOrigin,
100  const IndexType IndexNewEntity = 0
101  ) {}
102 
107  virtual void RemoveId(const IndexType IndexOrigin) {}
108 
114  virtual IndexType GetNewEntityId(const IndexType IndexOrigin) {return 0;}
115 
121  virtual void SetNewEntityId(
122  const IndexType IndexOrigin,
123  const IndexType IndexNewEntity = 0
124  ) {}
125 
129  virtual std::string Info() const {return "IndexDatabase";}
130 
131  virtual void save( Serializer& rSerializer ) const {}
132 
133  virtual void load( Serializer& rSerializer ) {}
134  }; // Class IndexDatabase
135 
143  class IndexSet
144  : public std::unordered_set<IndexType>, public IndexDatabase
145  {
146  public:
151 
152  typedef std::unordered_set<IndexType> BaseType;
153  typedef iterator IteratorType;
154 
158 
161 
163  virtual ~IndexSet(){}
164 
168 
172 
179  {
180  return *ThisIterator;
181  }
182 
189  {
190  return 0;
191  }
192 
198  bool Has(const IndexType IndexOrigin) override
199  {
200  BaseType::iterator set = find(IndexOrigin);
201  if(set != end())
202  return true;
203 
204  return false;
205  }
206 
212  void AddId(
213  const IndexType IndexOrigin,
214  const IndexType IndexNewEntity = 0
215  ) override
216  {
217  insert({IndexOrigin});
218  }
219 
224  void RemoveId(const IndexType IndexOrigin) override
225  {
226  BaseType::iterator set = find(IndexOrigin);
227  if(set != end())
228  erase(set);
229  }
230 
234  std::string Info() const override
235  {
236  std::stringstream buffer;
237  for ( auto it = begin(); it != end(); ++it )
238  buffer << "The condition " << *it << std::endl;
239  return buffer.str();
240  }
241 
242  void save( Serializer& rSerializer ) const override
243  {
244 // KRATOS_SERIALIZE_SAVE_BASE_CLASS( rSerializer, BaseType );
245  }
246 
247  void load( Serializer& rSerializer ) override
248  {
249 // KRATOS_SERIALIZE_LOAD_BASE_CLASS( rSerializer, BaseType );
250  }
251  }; // Class IndexSet
252 
260  class IndexMap
261  : public std::unordered_map<IndexType, IndexType>, public IndexDatabase
262  {
263  public:
268 
269  typedef std::unordered_map<IndexType, IndexType> BaseType;
270  typedef iterator IteratorType;
271 
275 
278 
280  virtual ~IndexMap(){}
281 
285 
289 
296  {
297  return ThisIterator->first;
298  }
299 
306  {
307  return ThisIterator->second;
308  }
309 
315  bool Has(const IndexType IndexOrigin) override
316  {
317  BaseType::iterator map = find(IndexOrigin);
318  if(map != end())
319  return true;
320 
321  return false;
322  }
323 
329  void AddId(
330  const IndexType IndexOrigin,
331  const IndexType IndexNewEntity = 0
332  ) override
333  {
334  insert({IndexOrigin, IndexNewEntity});
335  }
336 
341  void RemoveId(const IndexType IndexOrigin) override
342  {
343  BaseType::iterator map = find(IndexOrigin);
344  if(map != end())
345  erase(map);
346  }
347 
353  IndexType GetNewEntityId(const IndexType IndexOrigin) override
354  {
355  BaseType::iterator map = find(IndexOrigin);
356  if(map != end())
357  return map->second;
358 
359  return 0;
360  }
361 
368  const IndexType IndexOrigin,
369  const IndexType IndexNewEntity
370  ) override
371  {
372  BaseType::iterator map = find(IndexOrigin);
373  if(map != end())
374  map->second = IndexNewEntity;
375  }
376 
380  std::string Info() const override
381  {
382  std::stringstream buffer;
383  for ( auto it = begin(); it != end(); ++it )
384  buffer << "The condition " << it->first << " related with the new condition " << it->second << std::endl;
385  return buffer.str();
386  }
387 
388  void save( Serializer& rSerializer ) const override
389  {
390 // KRATOS_SERIALIZE_SAVE_BASE_CLASS( rSerializer, BaseType );
391  }
392 
393  void load( Serializer& rSerializer ) override
394  {
395 // KRATOS_SERIALIZE_LOAD_BASE_CLASS( rSerializer, BaseType );
396  }
397  }; // Class IndexMap
398 
399  KRATOS_DEFINE_VARIABLE( IndexSet::Pointer, INDEX_SET ) // An unordened set of which contains the indexes with the paired
400  KRATOS_DEFINE_VARIABLE( IndexMap::Pointer, INDEX_MAP ) // An unordened map of which contains the indexes with the paired
401  KRATOS_DEFINE_VARIABLE( double, TANGENT_FACTOR ) // The factor between the tangent and normal behaviour
402 
403 } // namespace Kratos
404 
405 #undef KRATOS_EXPORT_MACRO
406 #define KRATOS_EXPORT_MACRO KRATOS_NO_EXPORT
407 
408 #endif // KRATOS_MAPPING_VARIABLES_H_INCLUDED defined
Base class to derive common methods.
Definition: mapping_variables.h:61
virtual std::string Info() const
Turn back information as a string.
Definition: mapping_variables.h:129
KRATOS_CLASS_POINTER_DEFINITION(IndexDatabase)
IndexDatabase()
Default constructors.
Definition: mapping_variables.h:73
virtual void load(Serializer &rSerializer)
Definition: mapping_variables.h:133
virtual void SetNewEntityId(const IndexType IndexOrigin, const IndexType IndexNewEntity=0)
It sets the new created entity ID.
Definition: mapping_variables.h:121
virtual ~IndexDatabase()
Destructor.
Definition: mapping_variables.h:76
virtual IndexType GetNewEntityId(const IndexType IndexOrigin)
It returns the new created entity ID.
Definition: mapping_variables.h:114
virtual void AddId(const IndexType IndexOrigin, const IndexType IndexNewEntity=0)
It adds a new ID to the map.
Definition: mapping_variables.h:98
virtual void RemoveId(const IndexType IndexOrigin)
It removes one particular pair from the map.
Definition: mapping_variables.h:107
virtual bool Has(const IndexType IndexOrigin)
It checks if an ID exists in the map.
Definition: mapping_variables.h:91
virtual void save(Serializer &rSerializer) const
Definition: mapping_variables.h:131
Custom unordered map container to be used by the mapper.
Definition: mapping_variables.h:262
virtual ~IndexMap()
Destructor.
Definition: mapping_variables.h:280
void save(Serializer &rSerializer) const override
Definition: mapping_variables.h:388
void RemoveId(const IndexType IndexOrigin) override
It removes one particular pair from the map.
Definition: mapping_variables.h:341
IndexType GetOtherId(IteratorType ThisIterator)
Returns the new entity id corresponding a iterator.
Definition: mapping_variables.h:305
bool Has(const IndexType IndexOrigin) override
It checks if an ID exists in the map.
Definition: mapping_variables.h:315
IndexType GetId(IteratorType ThisIterator)
Returns the id corresponding a iterator.
Definition: mapping_variables.h:295
std::string Info() const override
Turn back information as a string.
Definition: mapping_variables.h:380
KRATOS_CLASS_POINTER_DEFINITION(IndexMap)
iterator IteratorType
Definition: mapping_variables.h:270
IndexMap()
Default constructors.
Definition: mapping_variables.h:277
void AddId(const IndexType IndexOrigin, const IndexType IndexNewEntity=0) override
It adds a new ID to the map.
Definition: mapping_variables.h:329
void load(Serializer &rSerializer) override
Definition: mapping_variables.h:393
std::unordered_map< IndexType, IndexType > BaseType
Definition: mapping_variables.h:269
void SetNewEntityId(const IndexType IndexOrigin, const IndexType IndexNewEntity) override
It sets the new created entity ID.
Definition: mapping_variables.h:367
IndexType GetNewEntityId(const IndexType IndexOrigin) override
It returns the new created entity ID.
Definition: mapping_variables.h:353
Custom unordered set container to be used by the mapper.
Definition: mapping_variables.h:145
bool Has(const IndexType IndexOrigin) override
It checks if an ID exists in the map.
Definition: mapping_variables.h:198
void load(Serializer &rSerializer) override
Definition: mapping_variables.h:247
std::string Info() const override
Turn back information as a string.
Definition: mapping_variables.h:234
virtual ~IndexSet()
Destructor.
Definition: mapping_variables.h:163
IndexType GetId(IteratorType ThisIterator)
Returns the id corresponding a iterator.
Definition: mapping_variables.h:178
KRATOS_CLASS_POINTER_DEFINITION(IndexSet)
IndexSet()
Default constructors.
Definition: mapping_variables.h:160
iterator IteratorType
Definition: mapping_variables.h:153
void AddId(const IndexType IndexOrigin, const IndexType IndexNewEntity=0) override
It adds a new ID to the map.
Definition: mapping_variables.h:212
void RemoveId(const IndexType IndexOrigin) override
It removes one particular pair from the map.
Definition: mapping_variables.h:224
IndexType GetOtherId(IteratorType ThisIterator)
Returns the new entity id corresponding a iterator.
Definition: mapping_variables.h:188
std::unordered_set< IndexType > BaseType
Definition: mapping_variables.h:152
void save(Serializer &rSerializer) const override
Definition: mapping_variables.h:242
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
std::size_t IndexType
The definition of the index type.
Definition: key_hash.h:35
end
Definition: DEM_benchmarks.py:180
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
KRATOS_DEFINE_VARIABLE(Vector, BIOT_STRAIN_VECTOR)