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.
variable_data.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 
14 
15 
16 #if !defined(KRATOS_VARIABLE_DATA_H_INCLUDED )
17 #define KRATOS_VARIABLE_DATA_H_INCLUDED
18 
19 
20 
21 // System includes
22 #include <string>
23 #include <iostream>
24 #include <cstddef>
25 
26 
27 // External includes
28 
29 
30 // Project includes
31 #include "includes/define.h"
32 #include "utilities/counter.h"
33 #include "includes/serializer.h"
34 
35 
36 namespace Kratos
37 {
40 
43 
45 
48 class KRATOS_API(KRATOS_CORE) VariableData
49 {
50 public:
53 
56 
57  typedef std::size_t KeyType;
58 
62 
64  VariableData(const VariableData& rOtherVariable);
65 
67  virtual ~VariableData() {}
68 
69 
73 
76  operator size_t() const
77  {
78  return mKey;
79  }
80 
84 
92  virtual void* Clone(const void* pSource) const;
93 
102  virtual void* Copy(const void* pSource, void* pDestination) const;
103 
111  virtual void Assign(const void* pSource, void* pDestination) const;
112 
118  virtual void AssignZero(void* pDestination) const;
119 
126  virtual void Delete(void* pSource) const;
127 
134  virtual void Destruct(void* pSource) const;
135 
144  virtual void Print(const void* pSource, std::ostream& rOStream) const;
145 
154  virtual void PrintData(const void* pSource, std::ostream& rOStream) const;
155 
160  virtual void Allocate(void** pData) const;
161 
167  virtual void Save(Serializer& rSerializer, void* pData) const;
168 
174  virtual void Load(Serializer& rSerializer, void* pData) const;
175 
179 
180  KeyType HashKey() const
181  {
182  KeyType key = mKey;// >> 8;
183  key &= 0xFFFFFFFF00;
184  return key;
185  }
186 
187  KeyType Key() const
188  {
189  return mKey;
190  }
191 
193  {
194  return mpSourceVariable->mKey;
195  }
196 
199  void SetKey(KeyType NewKey);
200 
201  const std::string& Name() const
202  {
203  return mName;
204  }
205 
206  std::size_t Size() const
207  {
208  return mSize;
209  }
210 
211  bool IsComponent() const
212  {
213  return mIsComponent;
214  }
215 
216  bool IsNotComponent() const
217  {
218  return !mIsComponent;
219  }
220 
222 
228  constexpr KeyType first_7_bits=127;
229  return (mKey & first_7_bits);
230  }
231 
233  {
234  KRATOS_DEBUG_ERROR_IF(mpSourceVariable == nullptr) << "No source variable is defined for the component" << std::endl;
235  return *mpSourceVariable;
236  }
237 
238  virtual const void* pZero() const {
239  KRATOS_ERROR << "Calling base class method." << std::endl;
240  }
241 
242 
246 
247 
251 
253  virtual std::string Info() const;
254 
256  virtual void PrintInfo(std::ostream& rOStream) const;
257 
259  virtual void PrintData(std::ostream& rOStream) const;
260 
264 
266 
276  static KeyType GenerateKey(const std::string& Name, std::size_t Size, bool IsComponent, char ComponentIndex);
277 
281 
282  friend bool operator==(const VariableData& rFirstVariable, const VariableData& rSecondVariable)
283  {
284  return (rFirstVariable.mKey == rSecondVariable.mKey);
285  }
286 
288 
289 protected:
292 
293 
297 
298  VariableData& operator=(const VariableData& rOtherVariable)
299  {
300  mName = rOtherVariable.mName;
301  mKey = rOtherVariable.mKey;
302  mSize = rOtherVariable.mSize;
303  mpSourceVariable = rOtherVariable.mpSourceVariable;
304  mIsComponent = rOtherVariable.mIsComponent;
305 
306  return *this;
307  }
308 
312 
314  VariableData(const std::string& NewName, std::size_t NewSize);
315 
317  VariableData(const std::string& NewName, std::size_t NewSize, const VariableData* pSourceVariable, char ComponentIndex);
318 
319 
323 
325 
326 private:
329 
330  std::string mName;
331 
334  KeyType mKey;
335 
336  std::size_t mSize;
337 
338  const VariableData* mpSourceVariable;
339 
340  bool mIsComponent;
341 
345 
346  friend class Serializer;
347 
348  virtual void save(Serializer& rSerializer) const;
349 
350  virtual void load(Serializer& rSerializer);
351 
353 
354 }; // Class VariableData
355 
356 
360 
361 
363 inline std::istream& operator >> (std::istream& rIStream,
364  VariableData& rThis);
365 
367 inline std::ostream& operator << (std::ostream& rOStream,
368  const VariableData& rThis)
369 {
370  rThis.PrintInfo(rOStream);
371  rThis.PrintData(rOStream);
372 
373  return rOStream;
374 }
376 
378 
379 
380 } // namespace Kratos.
381 
382 #endif // KRATOS_VARIABLE_DATA_H_INCLUDED defined
383 
384 
std::string Info() const override
Turn back information as a string.
Definition: periodic_interface_process.hpp:93
The serialization consists in storing the state of an object into a storage format like data file or ...
Definition: serializer.h:123
This class is the base of variables and variable's components which contains their common data.
Definition: variable_data.h:49
KeyType HashKey() const
Definition: variable_data.h:180
virtual void PrintData(const void *pSource, std::ostream &rOStream) const
Definition: variable_data.cpp:80
virtual const void * pZero() const
Definition: variable_data.h:238
KRATOS_CLASS_POINTER_DEFINITION(VariableData)
Pointer definition of VariableData.
KeyType GetComponentIndex() const
Returns the component index.
Definition: variable_data.h:227
virtual ~VariableData()
Destructor.
Definition: variable_data.h:67
KeyType SourceKey() const
Definition: variable_data.h:192
friend bool operator==(const VariableData &rFirstVariable, const VariableData &rSecondVariable)
Definition: variable_data.h:282
std::size_t Size() const
Definition: variable_data.h:206
VariableData & operator=(const VariableData &rOtherVariable)
Definition: variable_data.h:298
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: variable_data.cpp:111
VariableData()
Definition: variable_data.h:322
bool IsNotComponent() const
Definition: variable_data.h:216
const VariableData & GetSourceVariable() const
Definition: variable_data.h:232
bool IsComponent() const
Definition: variable_data.h:211
const std::string & Name() const
Definition: variable_data.h:201
KeyType Key() const
Definition: variable_data.h:187
std::size_t KeyType
Definition: variable_data.h:57
#define KRATOS_ERROR
Definition: exception.h:161
#define KRATOS_DEBUG_ERROR_IF(conditional)
Definition: exception.h:171
TSpaceType::IndexType Size(TSpaceType &dummy, typename TSpaceType::VectorType const &rV)
Definition: add_strategies_to_python.cpp:111
void Assign(const Expression &rExpression, const IndexType EntityIndex, const IndexType EntityDataBeginIndex, TDataType &rValue, std::index_sequence< TIndex... >)
Definition: variable_expression_data_io.cpp:41
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