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.
properties_layout.hpp
Go to the documentation of this file.
1 //
2 // Project Name: KratosConstitutiveModelsApplication $
3 // Created by: $Author: JMCarbonell $
4 // Last modified by: $Co-Author: $
5 // Date: $Date: October 2018 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 
11 #if !defined(KRATOS_PROPERTIES_LAYOUT_H_INCLUDED )
12 #define KRATOS_PROPERTIES_LAYOUT_H_INCLUDED
13 
14 // System includes
15 
16 // External includes
17 
18 // Project includes
19 #include "geometries/geometry.h"
20 #include "includes/properties.h"
22 #include "custom_utilities/properties_extensions.hpp"
23 
24 namespace Kratos
25 {
26 
29 
33 
37 
41 
45 
47 
51 {
52  public:
55 
58 
59 #ifdef _WIN32 // work around for windows int64_t error
60  typedef __int64 int64_t;
61 #endif
62 
65 
66  typedef Node NodeType;
67 
69 
71 
74 
75  typedef std::unordered_map<std::size_t, TableType> TablesContainerType;
76 
77  typedef std::pair<std::size_t, double> VariableKeyArgumentsType;
78 
79  typedef std::pair<std::size_t, VariableKeyArgumentsType> ScalarTableArgumentsType;
80 
81  typedef std::vector<ScalarTableArgumentsType> ScalarTableArgumentsContainerType;
82 
86 
89  {
90  mpData = nullptr;
91  mpTables = nullptr;
92  }
93 
96  :mpData(rOther.mpData)
97  ,mpTables(rOther.mpTables)
98  ,mTableVariables(rOther.mTableVariables)
99  ,mTableArguments(rOther.mTableArguments)
100  {}
101 
103  PropertiesLayout::Pointer Clone() const
104  {
105  return Kratos::make_shared< PropertiesLayout >(*this);
106  }
107 
110 
114 
117  {
118  mpData = rOther.mpData;
119  mpTables = rOther.mpTables;
120  mTableVariables = rOther.mTableVariables;
121  mTableArguments = rOther.mTableArguments;
122 
123  return *this;
124  }
125 
129 
130  void RegisterTable(const Variable<double>& rXVariable, const Variable<double>& rYVariable)
131  {
132  mTableVariables.RegisterTable(rXVariable,rYVariable);
133  }
134 
135  void Configure(const Properties& rProperties, const GeometryType& rGeometry, const Vector& rShapeFunctions);
136 
137 
138  template<class TVariableType>
139  void GetValue(const TVariableType& rVariable, typename TVariableType::Type& rValue) const
140  {
141  typename ScalarTableArgumentsContainerType::const_iterator i;
142 
143  if((i = std::find_if(mTableArguments.begin(), mTableArguments.end(), VariableKeyCheck(rVariable.Key()))) != mTableArguments.end())
144  {
145  rValue = static_cast<const typename TVariableType::Type>(mpTables->at((i->first))[(i->second).second]);
146  }
147  else
148  rValue = mpData->GetValue(rVariable);
149  }
150 
151  template<class TVariableType>
152  void GetValue(const TVariableType& rVariable, typename TVariableType::Type& rValue)
153  {
154  typename ScalarTableArgumentsContainerType::const_iterator i;
155 
156  if((i = std::find_if(mTableArguments.begin(), mTableArguments.end(), VariableKeyCheck(rVariable.Key()))) != mTableArguments.end())
157  {
158  rValue = static_cast<const typename TVariableType::Type>(mpTables->at((i->first))[(i->second).second]);
159  }
160  else
161  rValue = mpData->GetValue(rVariable);
162  }
163 
164  bool HasVariables() const
165  {
166  return !mpData->IsEmpty();
167  }
168 
169  bool HasTables() const
170  {
171  return !mpTables->empty();
172  }
173 
174  bool IsEmpty() const
175  {
176  return !( HasVariables() || HasTables() );
177  }
178 
182 
186 
190 
192  std::string Info() const
193  {
194  return "PropertiesLayout";
195  }
196 
198  void PrintInfo(std::ostream& rOStream) const
199  {
200  rOStream << "PropertiesLayout";
201  }
202 
204  void PrintData(std::ostream& rOStream) const
205  {
206  if(mpData != nullptr)
207  mpData->PrintData(rOStream);
208  if(mpTables != nullptr)
209  rOStream << "This properties contains " << mpTables->size() << " tables";
210  }
211 
215 
217 
218  protected:
221 
225 
229 
233 
237 
241 
245 
247 
248  private:
251 
255 
256  const ContainerType* mpData;
257 
258  const TablesContainerType* mpTables;
259 
260  TableKeyVariables<double,double> mTableVariables;
261 
262  ScalarTableArgumentsContainerType mTableArguments; // all table variable Keys and table arguments considered as "double" type
263 
264 
268 
272 
273  class VariableKeyCheck
274  {
275  std::size_t mI;
276  public:
277  VariableKeyCheck(std::size_t I) : mI(I) {}
278  bool operator()(const ScalarTableArgumentsType& I)
279  {
280  return I.first == mI;
281  }
282  };
283 
287 
288  friend class Serializer;
289 
290  void save(Serializer& rSerializer) const
291  {
292  rSerializer.save("mTableVariables", mTableVariables);
293  rSerializer.save("mTableArguments", mTableArguments);
294  }
295 
296  void load(Serializer& rSerializer)
297  {
298  rSerializer.load("mTableVariables", mTableVariables);
299  rSerializer.load("mTableArguments", mTableArguments);
300  }
301 
305 
306 
310 
311 
315 
317 
318  public:
319 
322 
323 }; // Class PropertiesLayout
324 
326 
329 
330 
334 
335 
337 inline std::istream& operator >> (std::istream& rIStream,
338  PropertiesLayout& rThis);
339 
341 inline std::ostream& operator << (std::ostream& rOStream,
342  const PropertiesLayout& rThis)
343 {
344  rThis.PrintInfo(rOStream);
345  rOStream << std::endl;
346  rThis.PrintData(rOStream);
347 
348  return rOStream;
349 }
351 
352 
353 } // namespace Kratos.
354 
355 #endif // KRATOS_PROPERTIES_LAYOUT_H_INCLUDED defined
#define DECLARE_ADD_THIS_TYPE_TO_PROPERTIES
Definition: properties_extensions.hpp:14
#define DECLARE_GET_THIS_TYPE_FROM_PROPERTIES
Definition: properties_extensions.hpp:29
Container for storing data values associated with variables.
Definition: data_value_container.h:63
virtual void PrintData(std::ostream &rOStream) const
Outputs the detailed data contents of the data value container to a given stream.
Definition: data_value_container.h:423
TDataType & GetValue(const Variable< TDataType > &rThisVariable)
Gets the value associated with a given variable.
Definition: data_value_container.h:268
bool IsEmpty() const
Checks if the data container is empty.
Definition: data_value_container.h:391
Geometry base class.
Definition: geometry.h:71
This class defines the node.
Definition: node.h:65
std::size_t IndexType
The index type.
Definition: node.h:86
Properties encapsulates data shared by different Elements or Conditions. It can store any type of dat...
Definition: properties.h:69
PropertiesLayout.
Definition: properties_layout.hpp:51
~PropertiesLayout()
Destructor.
Definition: properties_layout.hpp:109
void RegisterTable(const Variable< double > &rXVariable, const Variable< double > &rYVariable)
Definition: properties_layout.hpp:130
void GetValue(const TVariableType &rVariable, typename TVariableType::Type &rValue)
Definition: properties_layout.hpp:152
DataValueContainer ContainerType
Type of container used for variables.
Definition: properties_layout.hpp:64
bool HasTables() const
Definition: properties_layout.hpp:169
Table< double > TableType
Type of container used for tables.
Definition: properties_layout.hpp:73
bool HasVariables() const
Definition: properties_layout.hpp:164
PropertiesLayout::Pointer Clone() const
Clone.
Definition: properties_layout.hpp:103
PropertiesLayout(const PropertiesLayout &rOther)
Copy constructor.
Definition: properties_layout.hpp:95
void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: properties_layout.hpp:204
Node NodeType
Definition: properties_layout.hpp:66
void Configure(const Properties &rProperties, const GeometryType &rGeometry, const Vector &rShapeFunctions)
Definition: properties_layout.cpp:23
void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: properties_layout.hpp:198
std::string Info() const
Turn back information as a string.
Definition: properties_layout.hpp:192
std::pair< std::size_t, double > VariableKeyArgumentsType
Definition: properties_layout.hpp:77
void GetValue(const TVariableType &rVariable, typename TVariableType::Type &rValue) const
Definition: properties_layout.hpp:139
bool IsEmpty() const
Definition: properties_layout.hpp:174
PropertiesLayout()
Default constructor.
Definition: properties_layout.hpp:88
PropertiesLayout & operator=(PropertiesLayout const &rOther)
Assignment operator.
Definition: properties_layout.hpp:116
KRATOS_CLASS_POINTER_DEFINITION(PropertiesLayout)
Pointer definition of PropertiesLayout.
Geometry< NodeType > GeometryType
Definition: properties_layout.hpp:68
std::unordered_map< std::size_t, TableType > TablesContainerType
Definition: properties_layout.hpp:75
std::vector< ScalarTableArgumentsType > ScalarTableArgumentsContainerType
Definition: properties_layout.hpp:81
NodeType::IndexType IndexType
Definition: properties_layout.hpp:70
std::pair< std::size_t, VariableKeyArgumentsType > ScalarTableArgumentsType
Definition: properties_layout.hpp:79
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
void RegisterTable(const XVariableType &rXVariable, const YVariableType &rYVariable)
Definition: table_key_variables.hpp:100
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
Configure::ContainerType ContainerType
Definition: transfer_utility.h:247