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.
geometrical_object.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 // Riccardo Rossi
12 //
13 
14 #pragma once
15 
16 // System includes
17 #include <atomic>
18 
19 // External includes
20 
21 // Project includes
22 #include "includes/define.h"
23 #include "includes/node.h"
24 #include "containers/flags.h"
25 #include "geometries/geometry.h"
27 
28 namespace Kratos
29 {
30 
33 
37 
41 
45 
49 
57 class KRATOS_API(KRATOS_CORE) GeometricalObject : public IndexedObject, public Flags
58 {
59 public:
62 
65 
67  typedef Node NodeType;
68 
71 
73  typedef std::size_t IndexType;
74 
76  typedef std::size_t result_type;
77 
81 
83  explicit GeometricalObject(IndexType NewId = 0)
84  : IndexedObject(NewId),
85  Flags(),
86  mpGeometry()
87  {}
88 
90  GeometricalObject(IndexType NewId, GeometryType::Pointer pGeometry)
91  : IndexedObject(NewId),
92  Flags(),
93  mpGeometry(pGeometry)
94  {}
95 
97  ~GeometricalObject() override {}
98 
101  : IndexedObject(rOther.Id()),
102  Flags(rOther),
103  mpGeometry(rOther.mpGeometry)
104  {}
105 
106 
110 
113  {
114  IndexedObject::operator=(rOther);
115  Flags::operator =(rOther);
116  return *this;
117  }
118 
122 
126 
131  virtual void SetGeometry(GeometryType::Pointer pGeometry)
132  {
133  mpGeometry = pGeometry;
134  }
135 
140  GeometryType::Pointer pGetGeometry()
141  {
142  return mpGeometry;
143  }
144 
149  const GeometryType::Pointer pGetGeometry() const
150  {
151  return mpGeometry;
152  }
153 
159  {
160  return *mpGeometry;
161  }
162 
167  GeometryType const& GetGeometry() const
168  {
169  return *mpGeometry;
170  }
171 
177  {
178  return *this;
179  }
180 
185  Flags const& GetFlags() const
186  {
187  return *this;
188  }
189 
194  void SetFlags(Flags const& rThisFlags)
195  {
196  Flags::operator=(rThisFlags);
197  }
198 
202 
206  KRATOS_DEPRECATED_MESSAGE("This method is deprecated. Use 'GetData()' instead.")
208  {
209  return pGetGeometry()->GetData();
210  }
211 
213  {
214  return pGetGeometry()->GetData();
215  }
216 
218  {
219  return GetGeometry().GetData();
220  }
221 
222  void SetData(DataValueContainer const& rThisData)
223  {
224  return GetGeometry().SetData(rThisData);
225  }
226 
230  template<class TDataType> bool Has(const Variable<TDataType>& rThisVariable) const
231  {
232  return GetData().Has(rThisVariable);
233  }
234 
238  template<class TVariableType> void SetValue(
239  const TVariableType& rThisVariable,
240  typename TVariableType::Type const& rValue)
241  {
242  GetData().SetValue(rThisVariable, rValue);
243  }
244 
248  template<class TVariableType> typename TVariableType::Type& GetValue(
249  const TVariableType& rThisVariable)
250  {
251  return GetData().GetValue(rThisVariable);
252  }
253 
254  template<class TVariableType> typename TVariableType::Type const& GetValue(
255  const TVariableType& rThisVariable) const
256  {
257  return GetData().GetValue(rThisVariable);
258  }
259 
263 
268  bool IsActive() const;
269 
274  inline static bool HasSameType(const GeometricalObject& rLHS, const GeometricalObject& rRHS) {
275  return (typeid(rLHS) == typeid(rRHS));
276  }
277 
282  inline static bool HasSameType(const GeometricalObject * rLHS, const GeometricalObject* rRHS) {
283  return GeometricalObject::HasSameType(*rLHS, *rRHS);
284  }
285 
290  inline static bool HasSameGeometryType(const GeometricalObject& rLHS, const GeometricalObject& rRHS) {
291  return (rLHS.GetGeometry().GetGeometryType() == rRHS.GetGeometry().GetGeometryType());
292  }
293 
298  inline static bool HasSameGeometryType(const GeometricalObject* rLHS, const GeometricalObject* rRHS) {
299  return GeometricalObject::HasSameGeometryType(*rLHS, *rRHS);
300  }
301 
306  inline static bool IsSame(const GeometricalObject& rLHS, const GeometricalObject& rRHS) {
308  }
309 
314  inline static bool IsSame(const GeometricalObject* rLHS, const GeometricalObject* rRHS) {
315  return GeometricalObject::HasSameType(*rLHS, *rRHS) && GeometricalObject::HasSameGeometryType(*rLHS, *rRHS);
316  }
317 
321 
323  std::string Info() const override
324  {
325  std::stringstream buffer;
326  buffer << "Geometrical object # "
327  << Id();
328  return buffer.str();
329  }
330 
332  void PrintInfo(std::ostream& rOStream) const override
333  {
334  rOStream << Info();
335  }
336 
338  void PrintData(std::ostream& rOStream) const override
339  {
340  }
341 
342  //*********************************************
343  //public API of intrusive_ptr
344  unsigned int use_count() const noexcept
345  {
346  return mReferenceCounter;
347  }
348  //*********************************************
349 
353 
354 
356 
357 protected:
360 
361 
365 
366 
370 
371 
375 
376 
380 
381 
385 
386 
390 
391 
393 
394 private:
397 
398 
402 
403  GeometryType::Pointer mpGeometry;
404 
408 
409  //*********************************************
410  //this block is needed for refcounting
411  mutable std::atomic<int> mReferenceCounter{0};
412 
414  {
415  x->mReferenceCounter.fetch_add(1, std::memory_order_relaxed);
416  }
417 
419  {
420  if (x->mReferenceCounter.fetch_sub(1, std::memory_order_release) == 1) {
421  std::atomic_thread_fence(std::memory_order_acquire);
422  delete x;
423  }
424  }
425  //*********************************************
426 
427 
431 
432 
436 
437  friend class Serializer;
438 
439  void save(Serializer& rSerializer) const override
440  {
443  rSerializer.save("Geometry",mpGeometry);
444  }
445 
446  void load(Serializer& rSerializer) override
447  {
450  rSerializer.load("Geometry",mpGeometry);
451  }
452 
453 
457 
458 
462 
463 
467 
468 
470 
471 }; // Class GeometricalObject
472 
474 
477 
478 
482 
483 
485 inline std::istream& operator >> (std::istream& rIStream,
486  GeometricalObject& rThis);
487 
489 inline std::ostream& operator << (std::ostream& rOStream,
490  const GeometricalObject& rThis)
491 {
492  rThis.PrintInfo(rOStream);
493  rOStream << std::endl;
494  rThis.PrintData(rOStream);
495 
496  return rOStream;
497 }
499 
500 
501 } // namespace Kratos.
502 
503 
std::string Info() const override
Turn back information as a string.
Definition: periodic_interface_process.hpp:93
Container for storing data values associated with variables.
Definition: data_value_container.h:63
Definition: flags.h:58
std::size_t IndexType
Definition: flags.h:74
Flags & operator=(Flags const &rOther)
Assignment operator.
Definition: flags.h:151
This defines the geometrical object, base definition of the element and condition entities.
Definition: geometrical_object.h:58
GeometryType const & GetGeometry() const
Returns the reference of the geometry (const version)
Definition: geometrical_object.h:167
static bool HasSameGeometryType(const GeometricalObject &rLHS, const GeometricalObject &rRHS)
Checks if two GeometricalObject have the same geometry type.
Definition: geometrical_object.h:290
GeometricalObject(GeometricalObject const &rOther)
Copy constructor.
Definition: geometrical_object.h:100
friend void intrusive_ptr_release(const GeometricalObject *x)
Definition: geometrical_object.h:418
GeometryType::Pointer pGetGeometry()
Returns the pointer to the geometry.
Definition: geometrical_object.h:140
TVariableType::Type & GetValue(const TVariableType &rThisVariable)
Definition: geometrical_object.h:248
Flags & GetFlags()
Returns the flags of the object.
Definition: geometrical_object.h:176
std::string Info() const override
Turn back information as a string.
Definition: geometrical_object.h:323
void SetData(DataValueContainer const &rThisData)
Definition: geometrical_object.h:222
void SetFlags(Flags const &rThisFlags)
Sets the flags of the object.
Definition: geometrical_object.h:194
virtual void SetGeometry(GeometryType::Pointer pGeometry)
Sets the pointer to the geometry.
Definition: geometrical_object.h:131
Geometry< NodeType > GeometryType
The geometry type definition.
Definition: geometrical_object.h:70
GeometryType & GetGeometry()
Returns the reference of the geometry.
Definition: geometrical_object.h:158
Node NodeType
Definition of the node type.
Definition: geometrical_object.h:67
static bool IsSame(const GeometricalObject *rLHS, const GeometricalObject *rRHS)
Checks if two GeometricalObject are the same (pointer version)
Definition: geometrical_object.h:314
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: geometrical_object.h:338
GeometricalObject & operator=(GeometricalObject const &rOther)
Assignment operator.
Definition: geometrical_object.h:112
Flags const & GetFlags() const
Returns the flags of the object (const version)
Definition: geometrical_object.h:185
GeometricalObject(IndexType NewId=0)
Default constructor.
Definition: geometrical_object.h:83
KRATOS_CLASS_INTRUSIVE_POINTER_DEFINITION(GeometricalObject)
Pointer definition of GeometricalObject.
DataValueContainer const & GetData() const
Definition: geometrical_object.h:217
const GeometryType::Pointer pGetGeometry() const
Returns the pointer to the geometry (const version)
Definition: geometrical_object.h:149
static bool HasSameGeometryType(const GeometricalObject *rLHS, const GeometricalObject *rRHS)
Checks if two GeometricalObject have the same geometry type (pointer version)
Definition: geometrical_object.h:298
static bool HasSameType(const GeometricalObject *rLHS, const GeometricalObject *rRHS)
Checks if two GeometricalObject have the same type (pointer version)
Definition: geometrical_object.h:282
bool Has(const Variable< TDataType > &rThisVariable) const
Definition: geometrical_object.h:230
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: geometrical_object.h:332
GeometricalObject(IndexType NewId, GeometryType::Pointer pGeometry)
Default constructor.
Definition: geometrical_object.h:90
std::size_t IndexType
Defines the index type.
Definition: geometrical_object.h:73
DataValueContainer & GetData()
Definition: geometrical_object.h:212
~GeometricalObject() override
Destructor.
Definition: geometrical_object.h:97
void SetValue(const TVariableType &rThisVariable, typename TVariableType::Type const &rValue)
Definition: geometrical_object.h:238
unsigned int use_count() const noexcept
Definition: geometrical_object.h:344
static bool IsSame(const GeometricalObject &rLHS, const GeometricalObject &rRHS)
Checks if two GeometricalObject are the same.
Definition: geometrical_object.h:306
std::size_t result_type
Defines the result type.
Definition: geometrical_object.h:76
TVariableType::Type const & GetValue(const TVariableType &rThisVariable) const
Definition: geometrical_object.h:254
static bool HasSameType(const GeometricalObject &rLHS, const GeometricalObject &rRHS)
Checks if two GeometricalObject have the same type.
Definition: geometrical_object.h:274
friend void intrusive_ptr_add_ref(const GeometricalObject *x)
Definition: geometrical_object.h:413
Geometry base class.
Definition: geometry.h:71
virtual GeometryData::KratosGeometryType GetGeometryType() const
Definition: geometry.h:381
This object defines an indexed object.
Definition: indexed_object.h:54
IndexedObject & operator=(IndexedObject const &rOther)
Assignment operator.
Definition: indexed_object.h:86
This class defines the node.
Definition: node.h:65
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
Variable class contains all information needed to store and retrive data from a data container.
Definition: variable.h:63
#define KRATOS_SERIALIZE_SAVE_BASE_CLASS(Serializer, BaseType)
Definition: define.h:812
#define KRATOS_SERIALIZE_LOAD_BASE_CLASS(Serializer, BaseType)
Definition: define.h:815
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
namespace KRATOS_DEPRECATED_MESSAGE("Please use std::filesystem directly") filesystem
Definition: kratos_filesystem.h:33
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
tuple const
Definition: ode_solve.py:403
x
Definition: sensitivityMatrix.py:49