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.
method_utilities.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: Suneth Warnakulasuriya (https://github.com/sunethwarna)
11 //
12 
13 #if !defined(KRATOS_METHOD_UTILITIES_H_INCLUDED)
14 #define KRATOS_METHOD_UTILITIES_H_INCLUDED
15 
16 // System includes
17 #include <functional>
18 
19 // External includes
20 
21 // Project includes
22 #include "includes/model_part.h"
23 
24 // Application includes
25 
26 #ifndef ADD_TEMPORAL_VALUE_METHOD_ONE_OUTPUT_VARIABLE_OBJECT
27 #define ADD_TEMPORAL_VALUE_METHOD_ONE_OUTPUT_VARIABLE_OBJECT( \
28  model_part, norm_type, input_variable, echo_level, output_variable, object_list, method) \
29  { \
30  if (KratosComponents<Variable<double>>::Has(input_variable)) \
31  { \
32  const Variable<double>& r_variable_input = \
33  KratosComponents<Variable<double>>::Get(input_variable); \
34  const Variable<double>& r_variable_output = \
35  KratosComponents<Variable<double>>::Get(output_variable); \
36  object_list.push_back(std::make_shared<method<double>>( \
37  model_part, norm_type, r_variable_input, echo_level, r_variable_output)); \
38  } \
39  else if (KratosComponents<Variable<array_1d<double, 3>>>::Has(input_variable)) \
40  { \
41  const Variable<array_1d<double, 3>>& r_variable_input = \
42  KratosComponents<Variable<array_1d<double, 3>>>::Get(input_variable); \
43  const Variable<array_1d<double, 3>>& r_variable_output = \
44  KratosComponents<Variable<array_1d<double, 3>>>::Get(output_variable); \
45  object_list.push_back(std::make_shared<method<array_1d<double, 3>>>( \
46  model_part, norm_type, r_variable_input, echo_level, r_variable_output)); \
47  } \
48  else if (KratosComponents<Variable<Vector>>::Has(input_variable)) \
49  { \
50  const Variable<Vector>& r_variable_input = \
51  KratosComponents<Variable<Vector>>::Get(input_variable); \
52  const Variable<Vector>& r_variable_output = \
53  KratosComponents<Variable<Vector>>::Get(output_variable); \
54  object_list.push_back(std::make_shared<method<Vector>>( \
55  model_part, norm_type, r_variable_input, echo_level, r_variable_output)); \
56  } \
57  else if (KratosComponents<Variable<Matrix>>::Has(input_variable)) \
58  { \
59  const Variable<Matrix>& r_variable_input = \
60  KratosComponents<Variable<Matrix>>::Get(input_variable); \
61  const Variable<Matrix>& r_variable_output = \
62  KratosComponents<Variable<Matrix>>::Get(output_variable); \
63  object_list.push_back(std::make_shared<method<Matrix>>( \
64  model_part, norm_type, r_variable_input, echo_level, r_variable_output)); \
65  } \
66  else \
67  { \
68  KRATOS_ERROR \
69  << "Input variable not found in Double, Array3D, Vector or " \
70  "Matrix variables list. [ input_variable = " \
71  << input_variable << " ]\n"; \
72  } \
73  }
74 #endif
75 
76 #ifndef ADD_TEMPORAL_NORM_METHOD_ONE_OUTPUT_VARIABLE_OBJECT
77 #define ADD_TEMPORAL_NORM_METHOD_ONE_OUTPUT_VARIABLE_OBJECT( \
78  model_part, norm_type, input_variable, echo_level, output_variable, object_list, method) \
79  { \
80  if (KratosComponents<Variable<double>>::Has(input_variable)) \
81  { \
82  const Variable<double>& r_variable_input = \
83  KratosComponents<Variable<double>>::Get(input_variable); \
84  const Variable<double>& r_variable_output = \
85  KratosComponents<Variable<double>>::Get(output_variable); \
86  object_list.push_back(std::make_shared<method<double>>( \
87  model_part, norm_type, r_variable_input, echo_level, r_variable_output)); \
88  } \
89  else if (KratosComponents<Variable<array_1d<double, 3>>>::Has(input_variable)) \
90  { \
91  const Variable<array_1d<double, 3>>& r_variable_input = \
92  KratosComponents<Variable<array_1d<double, 3>>>::Get(input_variable); \
93  const Variable<double>& r_variable_output = \
94  KratosComponents<Variable<double>>::Get(output_variable); \
95  object_list.push_back(std::make_shared<method<array_1d<double, 3>>>( \
96  model_part, norm_type, r_variable_input, echo_level, r_variable_output)); \
97  } \
98  else if (KratosComponents<Variable<Vector>>::Has(input_variable)) \
99  { \
100  const Variable<Vector>& r_variable_input = \
101  KratosComponents<Variable<Vector>>::Get(input_variable); \
102  const Variable<double>& r_variable_output = \
103  KratosComponents<Variable<double>>::Get(output_variable); \
104  object_list.push_back(std::make_shared<method<Vector>>( \
105  model_part, norm_type, r_variable_input, echo_level, r_variable_output)); \
106  } \
107  else if (KratosComponents<Variable<Matrix>>::Has(input_variable)) \
108  { \
109  const Variable<Matrix>& r_variable_input = \
110  KratosComponents<Variable<Matrix>>::Get(input_variable); \
111  const Variable<double>& r_variable_output = \
112  KratosComponents<Variable<double>>::Get(output_variable); \
113  object_list.push_back(std::make_shared<method<Matrix>>( \
114  model_part, norm_type, r_variable_input, echo_level, r_variable_output)); \
115  } \
116  else \
117  { \
118  KRATOS_ERROR \
119  << "Input variable not found in Double, Array3D, Vector or " \
120  "Matrix variables list. [ input_variable = " \
121  << input_variable << " ]\n"; \
122  } \
123  }
124 #endif
125 
126 #ifndef ADD_TEMPORAL_VALUE_METHOD_TWO_OUTPUT_VARIABLE_OBJECT
127 #define ADD_TEMPORAL_VALUE_METHOD_TWO_OUTPUT_VARIABLE_OBJECT( \
128  model_part, norm_type, input_variable, echo_level, output_variable_1, \
129  output_variable_2, object_list, method) \
130  { \
131  if (KratosComponents<Variable<double>>::Has(input_variable)) \
132  { \
133  const Variable<double>& r_variable_input = \
134  KratosComponents<Variable<double>>::Get(input_variable); \
135  const Variable<double>& r_variable_output_1 = \
136  KratosComponents<Variable<double>>::Get(output_variable_1); \
137  const Variable<double>& r_variable_output_2 = \
138  KratosComponents<Variable<double>>::Get(output_variable_2); \
139  object_list.push_back(std::make_shared<method<double>>( \
140  model_part, norm_type, r_variable_input, echo_level, \
141  r_variable_output_1, r_variable_output_2)); \
142  } \
143  else if (KratosComponents<Variable<array_1d<double, 3>>>::Has(input_variable)) \
144  { \
145  const Variable<array_1d<double, 3>>& r_variable_input = \
146  KratosComponents<Variable<array_1d<double, 3>>>::Get(input_variable); \
147  const Variable<array_1d<double, 3>>& r_variable_output_1 = \
148  KratosComponents<Variable<array_1d<double, 3>>>::Get(output_variable_1); \
149  const Variable<array_1d<double, 3>>& r_variable_output_2 = \
150  KratosComponents<Variable<array_1d<double, 3>>>::Get(output_variable_2); \
151  object_list.push_back(std::make_shared<method<array_1d<double, 3>>>( \
152  model_part, norm_type, r_variable_input, echo_level, \
153  r_variable_output_1, r_variable_output_2)); \
154  } \
155  else if (KratosComponents<Variable<Vector>>::Has(input_variable)) \
156  { \
157  const Variable<Vector>& r_variable_input = \
158  KratosComponents<Variable<Vector>>::Get(input_variable); \
159  const Variable<Vector>& r_variable_output_1 = \
160  KratosComponents<Variable<Vector>>::Get(output_variable_1); \
161  const Variable<Vector>& r_variable_output_2 = \
162  KratosComponents<Variable<Vector>>::Get(output_variable_2); \
163  object_list.push_back(std::make_shared<method<Vector>>( \
164  model_part, norm_type, r_variable_input, echo_level, \
165  r_variable_output_1, r_variable_output_2)); \
166  } \
167  else if (KratosComponents<Variable<Matrix>>::Has(input_variable)) \
168  { \
169  const Variable<Matrix>& r_variable_input = \
170  KratosComponents<Variable<Matrix>>::Get(input_variable); \
171  const Variable<Matrix>& r_variable_output_1 = \
172  KratosComponents<Variable<Matrix>>::Get(output_variable_1); \
173  const Variable<Matrix>& r_variable_output_2 = \
174  KratosComponents<Variable<Matrix>>::Get(output_variable_2); \
175  object_list.push_back(std::make_shared<method<Matrix>>( \
176  model_part, norm_type, r_variable_input, echo_level, \
177  r_variable_output_1, r_variable_output_2)); \
178  } \
179  else \
180  { \
181  KRATOS_ERROR \
182  << "Input variable not found in Double, Array3D, Vector or " \
183  "Matrix variables list. [ input_variable = " \
184  << input_variable << " ]\n"; \
185  } \
186  }
187 #endif
188 
189 #ifndef ADD_TEMPORAL_NORM_METHOD_TWO_OUTPUT_VARIABLE_OBJECT
190 #define ADD_TEMPORAL_NORM_METHOD_TWO_OUTPUT_VARIABLE_OBJECT( \
191  model_part, norm_type, input_variable, echo_level, output_variable_1, \
192  output_variable_2, object_list, method) \
193  { \
194  if (KratosComponents<Variable<double>>::Has(input_variable)) \
195  { \
196  const Variable<double>& r_variable_input = \
197  KratosComponents<Variable<double>>::Get(input_variable); \
198  const Variable<double>& r_variable_output_1 = \
199  KratosComponents<Variable<double>>::Get(output_variable_1); \
200  const Variable<double>& r_variable_output_2 = \
201  KratosComponents<Variable<double>>::Get(output_variable_2); \
202  object_list.push_back(std::make_shared<method<double>>( \
203  model_part, norm_type, r_variable_input, echo_level, \
204  r_variable_output_1, r_variable_output_2)); \
205  } \
206  else if (KratosComponents<Variable<array_1d<double, 3>>>::Has(input_variable)) \
207  { \
208  const Variable<array_1d<double, 3>>& r_variable_input = \
209  KratosComponents<Variable<array_1d<double, 3>>>::Get(input_variable); \
210  const Variable<double>& r_variable_output_1 = \
211  KratosComponents<Variable<double>>::Get(output_variable_1); \
212  const Variable<double>& r_variable_output_2 = \
213  KratosComponents<Variable<double>>::Get(output_variable_2); \
214  object_list.push_back(std::make_shared<method<array_1d<double, 3>>>( \
215  model_part, norm_type, r_variable_input, echo_level, \
216  r_variable_output_1, r_variable_output_2)); \
217  } \
218  else if (KratosComponents<Variable<Vector>>::Has(input_variable)) \
219  { \
220  const Variable<Vector>& r_variable_input = \
221  KratosComponents<Variable<Vector>>::Get(input_variable); \
222  const Variable<double>& r_variable_output_1 = \
223  KratosComponents<Variable<double>>::Get(output_variable_1); \
224  const Variable<double>& r_variable_output_2 = \
225  KratosComponents<Variable<double>>::Get(output_variable_2); \
226  object_list.push_back(std::make_shared<method<Vector>>( \
227  model_part, norm_type, r_variable_input, echo_level, \
228  r_variable_output_1, r_variable_output_2)); \
229  } \
230  else if (KratosComponents<Variable<Matrix>>::Has(input_variable)) \
231  { \
232  const Variable<Matrix>& r_variable_input = \
233  KratosComponents<Variable<Matrix>>::Get(input_variable); \
234  const Variable<double>& r_variable_output_1 = \
235  KratosComponents<Variable<double>>::Get(output_variable_1); \
236  const Variable<double>& r_variable_output_2 = \
237  KratosComponents<Variable<double>>::Get(output_variable_2); \
238  object_list.push_back(std::make_shared<method<Matrix>>( \
239  model_part, norm_type, r_variable_input, echo_level, \
240  r_variable_output_1, r_variable_output_2)); \
241  } \
242  else \
243  { \
244  KRATOS_ERROR \
245  << "Input variable not found in Double, Array3D, Vector or " \
246  "Matrix variables list. [ input_variable = " \
247  << input_variable << " ]\n"; \
248  } \
249  }
250 #endif
251 
252 namespace Kratos
253 {
256 
259 
260 namespace MethodUtilities
261 {
265 
269 
270 template <class TDataType>
271 KRATOS_API(STATISTICS_APPLICATION)
272 TDataType RaiseToPower(const TDataType& rData, const double Power);
273 
274 template <class TContainerItemType>
276 {
277 public:
278  template <class TDataType>
279  TDataType& operator()(TContainerItemType& rDataItem, const Variable<TDataType>& rVariable) const
280  {
281  return rDataItem.GetValue(rVariable);
282  }
283 
284  template <class TDataType>
285  TDataType operator()(const TContainerItemType& rDataItem, const Variable<TDataType>& rVariable) const
286  {
287  return rDataItem.GetValue(rVariable);
288  }
289 
290  template <class TDataType>
291  void operator()(TContainerItemType& rDataItem, const Variable<TDataType>& rVariable, const TDataType& rValue) const
292  {
293  rDataItem.SetValue(rVariable, rValue);
294  }
295 };
296 
297 template <class TContainerItemType>
299 {
300 public:
301  template <class TDataType>
302  TDataType& operator()(TContainerItemType& rDataItem, const Variable<TDataType>& rVariable) const
303  {
304  KRATOS_TRY
305 
306  return rDataItem.FastGetSolutionStepValue(rVariable);
307 
308  KRATOS_CATCH("");
309  }
310 
311  template <class TDataType>
312  TDataType operator()(const TContainerItemType& rDataItem, const Variable<TDataType>& rVariable) const
313  {
314  KRATOS_TRY
315 
316  return rDataItem.FastGetSolutionStepValue(rVariable);
317 
318  KRATOS_CATCH("");
319  }
320 
321  template <class TDataType>
322  void operator()(TContainerItemType& rDataItem, const Variable<TDataType>& rVariable, const TDataType& rValue) const
323  {
324  KRATOS_TRY
325 
326  rDataItem.FastGetSolutionStepValue(rVariable) = rValue;
327 
328  KRATOS_CATCH("");
329  }
330 };
331 
332 KRATOS_API(STATISTICS_APPLICATION)
333 double GetDoubleValue(const std::string& rInput);
334 
335 KRATOS_API(STATISTICS_APPLICATION)
336 int GetIntegerValue(const std::string& rInput);
337 
338 KRATOS_API(STATISTICS_APPLICATION)
339 void SplitString(std::string& rOutput1, std::string& rOutput2, const std::string& rInput);
340 
341 template <class TDataType>
342 KRATOS_API(STATISTICS_APPLICATION)
343 void DataTypeSizeInitializer(TDataType& rData, const TDataType& rReferenceData);
344 
345 template <class TDataType>
346 KRATOS_API(STATISTICS_APPLICATION)
347 void DataTypeSizeChecker(const TDataType& rData, const TDataType& rReferenceData);
348 
349 template <class TContainerType>
350 KRATOS_API(STATISTICS_APPLICATION)
351 TContainerType& GetLocalDataContainer(ModelPart& rModelPart);
352 
353 template <class TContainerType>
354 KRATOS_API(STATISTICS_APPLICATION)
355 const TContainerType& GetLocalDataContainer(const ModelPart& rModelPart);
356 
357 template <class TContainerType>
358 KRATOS_API(STATISTICS_APPLICATION)
359 TContainerType& GetDataContainer(ModelPart& rModelPart);
360 
361 template <class TContainerType>
362 KRATOS_API(STATISTICS_APPLICATION)
363 const TContainerType& GetDataContainer(const ModelPart& rModelPart);
364 
365 template <class TDataType>
366 KRATOS_API(STATISTICS_APPLICATION)
367 const std::function<double(const TDataType&)> GetNormMethod(
368  const Variable<TDataType>& rVariable, const std::string& rNormType);
369 
370 template <class TDataType>
371 KRATOS_API(STATISTICS_APPLICATION)
373 
374 template <class TDataType>
375 KRATOS_API(STATISTICS_APPLICATION)
376 void CheckVariableType(const std::vector<std::string>& rVariableNamesList);
377 
378 KRATOS_API(STATISTICS_APPLICATION)
380  const std::vector<std::string>& rInputVariableNamesList,
381  const std::vector<std::string>& rOutputVariableNamesList);
382 
383 KRATOS_API(STATISTICS_APPLICATION)
384 std::vector<double> SortSortedValuesList(const std::vector<std::vector<double>>& rValues);
385 
386 } // namespace MethodUtilities
387 
391 
395 
399 
403 
405 
408 
412 
414 
416 
417 } // namespace Kratos.
418 
419 #endif // KRATOS_METHOD_UTILITIES_H_INCLUDED defined
Base class for all Conditions.
Definition: condition.h:59
Base class for all Elements.
Definition: element.h:60
TDataType & operator()(TContainerItemType &rDataItem, const Variable< TDataType > &rVariable) const
Definition: method_utilities.h:302
void operator()(TContainerItemType &rDataItem, const Variable< TDataType > &rVariable, const TDataType &rValue) const
Definition: method_utilities.h:322
TDataType operator()(const TContainerItemType &rDataItem, const Variable< TDataType > &rVariable) const
Definition: method_utilities.h:312
TDataType operator()(const TContainerItemType &rDataItem, const Variable< TDataType > &rVariable) const
Definition: method_utilities.h:285
void operator()(TContainerItemType &rDataItem, const Variable< TDataType > &rVariable, const TDataType &rValue) const
Definition: method_utilities.h:291
TDataType & operator()(TContainerItemType &rDataItem, const Variable< TDataType > &rVariable) const
Definition: method_utilities.h:279
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
MeshType::ConditionsContainerType ConditionsContainerType
Condintions container. A vector set of Conditions with their Id's as key.
Definition: model_part.h:183
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
Element ElementType
Definition: model_part.h:120
Node NodeType
Definition: model_part.h:117
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
Condition ConditionType
Definition: model_part.h:121
This class defines the node.
Definition: node.h:65
Variable class contains all information needed to store and retrive data from a data container.
Definition: variable.h:63
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
#define KRATOS_API(...)
Definition: kratos_export_api.h:40
NodesContainerType & GetLocalDataContainer(ModelPart &rModelPart)
Definition: method_utilities.cpp:167
ModelPart::NodesContainerType NodesContainerType
Definition: method_utilities.h:266
std::vector< double > SortSortedValuesList(const std::vector< std::vector< double >> &rValues)
Definition: method_utilities.cpp:725
const std::function< double(const TDataType &)> GetNormMethod(const Variable< TDataType > &rVariable, const std::string &rNormType)
Definition: method_utilities.cpp:313
void DataTypeSizeChecker(const TDataType &rData, const TDataType &rReferenceData)
Definition: method_utilities.cpp:131
int GetIntegerValue(const std::string &rInput)
Definition: method_utilities.cpp:274
TDataType RaiseToPower(const TDataType &rData, const double Power)
Definition: method_utilities.cpp:34
std::string GetVariableTypeName()
ModelPart::ElementsContainerType ElementsContainerType
Definition: method_utilities.h:268
void CheckVariableType(const std::vector< std::string > &rVariableNamesList)
Definition: method_utilities.cpp:664
void CheckInputOutputVariables(const std::vector< std::string > &rInputVariableNamesList, const std::vector< std::string > &rOutputVariableNamesList)
Definition: method_utilities.cpp:678
void SplitString(std::string &rOutput1, std::string &rOutput2, const std::string &rInput)
Definition: method_utilities.cpp:295
double GetDoubleValue(const std::string &rInput)
Definition: method_utilities.cpp:249
void DataTypeSizeInitializer(TDataType &rData, const TDataType &rReferenceData)
Definition: method_utilities.cpp:82
ModelPart::ConditionsContainerType ConditionsContainerType
Definition: method_utilities.h:267
NodesContainerType & GetDataContainer(ModelPart &rModelPart)
Definition: method_utilities.cpp:209
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
TABLE_NUMBER_ANGULAR_VELOCITY TABLE_NUMBER_MOMENT I33 BEAM_INERTIA_ROT_UNIT_LENGHT_Y KRATOS_DEFINE_APPLICATION_VARIABLE(DEM_APPLICATION, double, BEAM_INERTIA_ROT_UNIT_LENGHT_Z) typedef std double
Definition: DEM_application_variables.h:182
tuple const
Definition: ode_solve.py:403
namespace
Definition: array_1d.h:793