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.
container_expression_utils.h
Go to the documentation of this file.
1 // | / |
2 // ' / __| _` | __| _ \ __|
3 // . \ | ( | | ( |\__ `
4 // _|\_\_| \__,_|\__|\___/ ____/
5 // Multi-Physics
6 //
7 // License: BSD License
8 // license: OptimizationApplication/license.txt
9 //
10 // Main author: Suneth Warnakulasuriya
11 //
12 
13 #pragma once
14 
15 // System includes
16 
17 // Project includes
18 #include "includes/define.h"
19 #include "spaces/ublas_space.h"
23 #include "collective_expression.h"
24 
25 // Application includes
26 
27 namespace Kratos
28 {
29 
32 
33 class KRATOS_API(OPTIMIZATION_APPLICATION) ContainerExpressionUtils
34 {
35 public:
38 
39  using IndexType = std::size_t;
40 
42 
44 
48 
61  template<class TContainerType>
62  static double EntityMaxNormL2(const ContainerExpression<TContainerType>& rContainer);
63 
76  static double InnerProduct(
77  const CollectiveExpression& rContainer1,
78  const CollectiveExpression& rContainer2);
79 
94  template<class TContainerType>
95  static void ProductWithEntityMatrix(
97  const SparseMatrixType& rMatrix,
99 
114  template<class TContainerType>
115  static void ProductWithEntityMatrix(
117  const Matrix& rMatrix,
119 
128  static void Transpose(
129  Matrix& rOutput,
130  const Matrix& rInput);
131 
140  static void Transpose(
141  SparseMatrixType& rOutput,
142  const SparseMatrixType& rInput);
143 
155  template<class TContainerType>
156  static void ComputeNumberOfNeighbourEntities(
158 
174  template<class TContainerType>
175  static void MapContainerVariableToNodalVariable(
178  const ContainerExpression<ModelPart::NodesContainerType>& rNeighbourEntities);
179 
193  template<class TContainerType>
194  static void MapNodalVariableToContainerVariable(
197 
215  template<class TContainerType>
216  static void ComputeNodalVariableProductWithEntityMatrix(
219  const Variable<Matrix>& rMatrixVariable,
220  TContainerType& rEntities);
221 
225 
226  #ifndef KRATOS_OPTAPP_EXPRESSION_UTILS_CEXP_METHOD_1
227  #define KRATOS_OPTAPP_EXPRESSION_UTILS_CEXP_METHOD_1(METHOD_NAME) \
228  static CollectiveExpression METHOD_NAME(const CollectiveExpression& rCollectiveExpression) \
229  { \
230  KRATOS_TRY \
231  auto result = rCollectiveExpression; \
232  auto r_list_of_container_expressions = result.GetContainerExpressions(); \
233  for (IndexType i = 0; i < r_list_of_container_expressions.size(); ++i) { \
234  std::visit( \
235  [](auto& pResult) { \
236  *pResult = ExpressionUtils::METHOD_NAME(*pResult); \
237  }, \
238  r_list_of_container_expressions[i]); \
239  } \
240  return result; \
241  KRATOS_CATCH(""); \
242  }
243  #endif
244 
245  #ifndef KRATOS_OPTAPP_EXPRESSION_UTILS_CEXP_METHOD_2
246  #define KRATOS_OPTAPP_EXPRESSION_UTILS_CEXP_METHOD_2(METHOD_NAME) \
247  static double METHOD_NAME(const CollectiveExpression& rCollectiveExpression) \
248  { \
249  KRATOS_TRY \
250  double value = 0.0; \
251  auto r_list_of_container_expressions = \
252  rCollectiveExpression.GetContainerExpressions(); \
253  for (IndexType i = 0; i < r_list_of_container_expressions.size(); ++i) { \
254  value += std::visit( \
255  [](const auto& pResult) { \
256  return ExpressionUtils::METHOD_NAME(*pResult); \
257  }, \
258  r_list_of_container_expressions[i]); \
259  } \
260  return value; \
261  KRATOS_CATCH(""); \
262  }
263  #endif
264 
265  #ifndef KRATOS_OPTAPP_EXPRESSION_UTILS_CEXP_METHOD_3
266  #define KRATOS_OPTAPP_EXPRESSION_UTILS_CEXP_METHOD_3(METHOD_NAME) \
267  static CollectiveExpression METHOD_NAME( \
268  const CollectiveExpression& rCollectiveExpression, const double V) \
269  { \
270  KRATOS_TRY \
271  auto result = rCollectiveExpression; \
272  auto r_list_of_container_expressions = result.GetContainerExpressions(); \
273  for (IndexType i = 0; i < r_list_of_container_expressions.size(); ++i) { \
274  std::visit( \
275  [V](auto& pResult) { \
276  *pResult = ExpressionUtils::METHOD_NAME(*pResult, V); \
277  }, \
278  r_list_of_container_expressions[i]); \
279  } \
280  return result; \
281  KRATOS_CATCH(""); \
282  } \
283  static CollectiveExpression METHOD_NAME( \
284  const CollectiveExpression& rCollectiveExpression1, \
285  const CollectiveExpression& rCollectiveExpression2) \
286  { \
287  KRATOS_TRY \
288  \
289  KRATOS_ERROR_IF_NOT(rCollectiveExpression1.IsCompatibleWith(rCollectiveExpression2)) \
290  << "Unsupported collective variable data holders provided for " \
291  "\"" \
292  << #METHOD_NAME << "\"." \
293  << "\nLeft operand : " << rCollectiveExpression1 \
294  << "\nRight operand: " << rCollectiveExpression2 << std::endl; \
295  \
296  auto result = rCollectiveExpression1; \
297  auto r_list_of_container_expressions = result.GetContainerExpressions(); \
298  const auto& r_right_container_expressions = \
299  rCollectiveExpression2.GetContainerExpressions(); \
300  for (IndexType i = 0; i < r_list_of_container_expressions.size(); ++i) { \
301  std::visit( \
302  [&r_right_container_expressions, i](auto& pResult) { \
303  auto p_right = std::get<std::decay_t<decltype(pResult)>>( \
304  r_right_container_expressions[i]); \
305  *pResult = ExpressionUtils::METHOD_NAME(*pResult, *p_right); \
306  }, \
307  r_list_of_container_expressions[i]); \
308  } \
309  return result; \
310  \
311  KRATOS_CATCH(""); \
312  }
313  #endif
314 
325 
326  #undef KRATOS_OPTAPP_EXPRESSION_UTILS_CEXP_METHOD_1
327  #undef KRATOS_OPTAPP_EXPRESSION_UTILS_CEXP_METHOD_2
328  #undef KRATOS_OPTAPP_EXPRESSION_UTILS_CEXP_METHOD_3
329 
331 };
332 
334 }
Construct a new CollectiveExpression instance.
Definition: collective_expression.h:41
Container variable data holder.
Definition: container_expression.h:80
Definition: container_expression_utils.h:34
SparseSpaceType::MatrixType SparseMatrixType
Definition: container_expression_utils.h:43
std::size_t IndexType
Definition: container_expression_utils.h:39
A class template for handling data types, matrices, and vectors in a Ublas space.
Definition: ublas_space.h:121
TMatrixType MatrixType
The matrix type considered.
Definition: ublas_space.h:133
Variable class contains all information needed to store and retrive data from a data container.
Definition: variable.h:63
#define KRATOS_OPTAPP_EXPRESSION_UTILS_CEXP_METHOD_3(METHOD_NAME)
Definition: container_expression_utils.h:266
#define KRATOS_OPTAPP_EXPRESSION_UTILS_CEXP_METHOD_2(METHOD_NAME)
Definition: container_expression_utils.h:246
#define KRATOS_OPTAPP_EXPRESSION_UTILS_CEXP_METHOD_1(METHOD_NAME)
Definition: container_expression_utils.h:227
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21