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.
fluid_calculation_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
11 //
12 
13 #if !defined(KRATOS_FLUID_CALCULATION_UTILITIES_H)
14 #define KRATOS_FLUID_CALCULATION_UTILITIES_H
15 
16 // system includes
17 #include <tuple>
18 #include <type_traits>
19 
20 // External includes
21 
22 // Project includes
23 #include "geometries/geometry.h"
24 #include "includes/node.h"
26 
27 namespace Kratos
28 {
31 
34 
35 class KRATOS_API(FLUID_DYNAMICS_APPLICATION) FluidCalculationUtilities
36 {
37 public:
40 
41  using IndexType = std::size_t;
42 
43  using NodeType = Node;
44 
46 
47  template<class TDataType>
48  using ComponentDataType = std::tuple<TDataType&, const TDataType&>;
49 
53 
74  template <class... TRefVariableValuePairArgs>
75  static void EvaluateInPoint(
76  const GeometryType& rGeometry,
77  const Vector& rShapeFunction,
78  const int Step,
79  const TRefVariableValuePairArgs&... rValueVariablePairs)
80  {
82 
83  const auto& r_node = rGeometry[0];
84  const double shape_function_value = rShapeFunction[0];
85 
86  (std::apply([&](auto&&... args) {((std::get<0>(args) = std::get<1>(args) * shape_function_value), ...);}, GetComponentsArray(std::get<0>(rValueVariablePairs), r_node.FastGetSolutionStepValue(std::get<1>(rValueVariablePairs), Step))), ...);
87 
88  for (IndexType c = 1; c < rGeometry.PointsNumber(); ++c) {
89  const auto& r_node = rGeometry[c];
90  const double shape_function_value = rShapeFunction[c];
91 
92  (std::apply([&](auto&&... args) {((std::get<0>(args) += std::get<1>(args) * shape_function_value), ...);}, GetComponentsArray(std::get<0>(rValueVariablePairs), r_node.FastGetSolutionStepValue(std::get<1>(rValueVariablePairs), Step))), ...);
93  }
94 
95  KRATOS_CATCH("");
96  }
97 
117  template <class... TRefVariableValuePairArgs>
118  static void inline EvaluateInPoint(
119  const GeometryType& rGeometry,
120  const Vector& rShapeFunction,
121  const TRefVariableValuePairArgs&... rValueVariablePairs)
122  {
123  EvaluateInPoint<TRefVariableValuePairArgs...>(
124  rGeometry, rShapeFunction, 0, rValueVariablePairs...);
125  }
126 
146  template <class... TRefVariableValuePairArgs>
148  const GeometryType& rGeometry,
149  const Vector& rShapeFunction,
150  const TRefVariableValuePairArgs&... rValueVariablePairs)
151  {
152  KRATOS_TRY
153 
154  const auto& r_node = rGeometry[0];
155  const double shape_function_value = rShapeFunction[0];
156 
157  (std::apply([&](auto&&... args) {((std::get<0>(args) = std::get<1>(args) * shape_function_value), ...);}, GetComponentsArray(std::get<0>(rValueVariablePairs), r_node.GetValue(std::get<1>(rValueVariablePairs)))), ...);
158 
159  for (IndexType c = 1; c < rGeometry.PointsNumber(); ++c) {
160  const auto& r_node = rGeometry[c];
161  const double shape_function_value = rShapeFunction[c];
162 
163  (std::apply([&](auto&&... args) {((std::get<0>(args) += std::get<1>(args) * shape_function_value), ...);}, GetComponentsArray(std::get<0>(rValueVariablePairs), r_node.GetValue(std::get<1>(rValueVariablePairs)))), ...);
164  }
165 
166  KRATOS_CATCH("");
167  }
168 
195  template <class... TRefVariableValuePairArgs>
197  const GeometryType& rGeometry,
198  const Matrix& rShapeFunctionDerivatives,
199  const int Step,
200  const TRefVariableValuePairArgs&... rValueVariablePairs)
201  {
202  KRATOS_TRY
203 
204  const auto& r_node = rGeometry[0];
205  const Vector& shape_function_derivative = row(rShapeFunctionDerivatives, 0);
206 
207  for (IndexType i = 0; i < rShapeFunctionDerivatives.size2(); ++i) {
208  (std::apply([&](auto&&... args) {((std::get<0>(args) = std::get<1>(args) * shape_function_derivative[i]), ...);}, GetComponentsArray(std::get<0>(rValueVariablePairs), r_node.FastGetSolutionStepValue(std::get<1>(rValueVariablePairs), Step), i)), ...);
209  }
210 
211  for (IndexType c = 1; c < rGeometry.PointsNumber(); ++c) {
212  const auto& r_node = rGeometry[c];
213  const Vector& shape_function_derivative = row(rShapeFunctionDerivatives, c);
214 
215  for (IndexType i = 0; i < rShapeFunctionDerivatives.size2(); ++i) {
216  (std::apply([&](auto&&... args) {((std::get<0>(args) += std::get<1>(args) * shape_function_derivative[i]), ...);}, GetComponentsArray(std::get<0>(rValueVariablePairs), r_node.FastGetSolutionStepValue(std::get<1>(rValueVariablePairs), Step), i)), ...);
217  }
218  }
219 
220  KRATOS_CATCH("");
221  }
222 
249  template <class... TRefVariableValuePairArgs>
250  static void inline EvaluateGradientInPoint(
251  const GeometryType& rGeometry,
252  const Matrix& rShapeFunctionDerivatives,
253  const TRefVariableValuePairArgs&... rValueVariablePairs)
254  {
255  EvaluateGradientInPoint<TRefVariableValuePairArgs...>(
256  rGeometry, rShapeFunctionDerivatives, 0, rValueVariablePairs...);
257  }
258 
284  template <class... TRefVariableValuePairArgs>
286  const GeometryType& rGeometry,
287  const Matrix& rShapeFunctionDerivatives,
288  const TRefVariableValuePairArgs&... rValueVariablePairs)
289  {
290  KRATOS_TRY
291 
292  const auto& r_node = rGeometry[0];
293  const Vector& shape_function_derivative = row(rShapeFunctionDerivatives, 0);
294 
295  for (IndexType i = 0; i < rShapeFunctionDerivatives.size2(); ++i) {
296  (std::apply([&](auto&&... args) {((std::get<0>(args) = std::get<1>(args) * shape_function_derivative[i]), ...);}, GetComponentsArray(std::get<0>(rValueVariablePairs), r_node.GetValue(std::get<1>(rValueVariablePairs)), i)), ...);
297  }
298 
299  for (IndexType c = 1; c < rGeometry.PointsNumber(); ++c) {
300  const auto& r_node = rGeometry[c];
301  const Vector& shape_function_derivative = row(rShapeFunctionDerivatives, c);
302 
303  for (IndexType i = 0; i < rShapeFunctionDerivatives.size2(); ++i) {
304  (std::apply([&](auto&&... args) {((std::get<0>(args) += std::get<1>(args) * shape_function_derivative[i]), ...);}, GetComponentsArray(std::get<0>(rValueVariablePairs), r_node.GetValue(std::get<1>(rValueVariablePairs)), i)), ...);
305  }
306  }
307 
308  KRATOS_CATCH("");
309  }
310 
322  template <unsigned int TSize>
323  static void ReadSubVector(
325  const Vector& rInput,
326  const IndexType Position)
327  {
328  KRATOS_TRY
329 
330  KRATOS_DEBUG_ERROR_IF(rInput.size() < Position + TSize)
331  << "rInput size is not enough for sub vector retireval. [ "
332  "rInput.size() = "
333  << rInput.size() << ", Requested Position = " << Position
334  << ", Requested vector size = " << TSize << " ].\n";
335 
336  for (IndexType i = 0; i < TSize; ++i) {
337  rOutput[i] = rInput[Position + i];
338  }
339 
340  KRATOS_CATCH("");
341  }
342 
357  template<unsigned int TSize>
358  static void AddSubVector(
359  Matrix& rOutput,
360  const BoundedVector<double, TSize>& rInput,
361  const unsigned int RowIndex,
362  const unsigned int ColumnIndex)
363  {
364  KRATOS_TRY
365 
366  KRATOS_DEBUG_ERROR_IF(RowIndex >= rOutput.size1())
367  << "RowIndex is larger than or equal to rOutput number of rows. [ "
368  "rOutput.size1() = "
369  << rOutput.size1() << ", RowIndex = " << RowIndex << " ].\n";
370 
371  KRATOS_DEBUG_ERROR_IF(ColumnIndex + TSize > rOutput.size2())
372  << "rOutput matrix does not have sufficient number of columns [ "
373  "rOutput.size2() = "
374  << rOutput.size2() << ", ColumnIndex = " << ColumnIndex
375  << ", TSize = " << TSize << " ].\n";
376 
377  for (unsigned int i = 0; i < TSize; ++i) {
378  rOutput(RowIndex, ColumnIndex + i) += rInput[i];
379  }
380 
381  KRATOS_CATCH("");
382  }
383 
400  static double CalculateLogarithmicYPlusLimit(
401  const double Kappa,
402  const double Beta,
403  const int MaxIterations = 20,
404  const double Tolerance = 1e-6);
405 
443  static double CalculateLogarithmicYPlus(
444  const double WallVelocityMagnitude,
445  const double WallHeight,
446  const double KinematicViscosity,
447  const double Kappa,
448  const double Beta,
449  const double YPlusLimit,
450  const int MaxIterations = 20,
451  const double Tolerance = 1e-6);
452 
454 
455 private:
458 
459  // gauss point evaluation templates
460  static auto inline GetComponentsArray(double& rOutput, const double& rInput) { return std::array<ComponentDataType<double>, 1>{std::tie(rOutput, rInput)};}
461  static auto inline GetComponentsArray(array_1d<double, 2>& rOutput, const array_1d<double, 3>& rInput) { return std::array<ComponentDataType<double>, 2>{std::tie(rOutput[0], rInput[0]), std::tie(rOutput[1], rInput[1])};}
462  static auto inline GetComponentsArray(array_1d<double, 3>& rOutput, const array_1d<double, 3>& rInput) { return std::array<ComponentDataType<double>, 3>{std::tie(rOutput[0], rInput[0]), std::tie(rOutput[1], rInput[1]), std::tie(rOutput[2], rInput[2])};}
463  static auto inline GetComponentsArray(Vector& rOutput, const Vector& rInput) { return std::array<ComponentDataType<Vector>, 1>{std::tie(rOutput, rInput)};}
464  static auto inline GetComponentsArray(Matrix& rOutput, const Matrix& rInput) { return std::array<ComponentDataType<Matrix>, 1>{std::tie(rOutput, rInput)};}
465 
466  // gauss point gradient evaluation templates
467  static auto inline GetComponentsArray(array_1d<double, 2>& rOutput, const double& rInput, const IndexType DerivativeIndex) { return std::array<ComponentDataType<double>, 1>{std::tie(rOutput[DerivativeIndex], rInput)};}
468  static auto inline GetComponentsArray(array_1d<double, 3>& rOutput, const double& rInput, const IndexType DerivativeIndex) { return std::array<ComponentDataType<double>, 1>{std::tie(rOutput[DerivativeIndex], rInput)};}
469  static auto inline GetComponentsArray(BoundedMatrix<double, 2, 2>& rOutput, const array_1d<double, 3>& rInput, const IndexType DerivativeIndex) { return std::array<ComponentDataType<double>, 2>{std::tie(rOutput(0, DerivativeIndex), rInput[0]), std::tie(rOutput(1, DerivativeIndex), rInput[1])};}
470  static auto inline GetComponentsArray(BoundedMatrix<double, 3, 3>& rOutput, const array_1d<double, 3>& rInput, const IndexType DerivativeIndex) { return std::array<ComponentDataType<double>, 3>{std::tie(rOutput(0, DerivativeIndex), rInput[0]), std::tie(rOutput(1, DerivativeIndex), rInput[1]), std::tie(rOutput(2, DerivativeIndex), rInput[2])};}
471 
473 };
474 
476 
477 } // namespace Kratos
478 
479 #endif // KRATOS_FLUID_CALCULATION_UTILITIES_H
Definition: fluid_calculation_utilities.h:36
Geometry base class.
Definition: geometry.h:71
SizeType PointsNumber() const
Definition: geometry.h:528
This class defines the node.
Definition: node.h:65
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
static void EvaluateGradientInPoint(const GeometryType &rGeometry, const Matrix &rShapeFunctionDerivatives, const TRefVariableValuePairArgs &... rValueVariablePairs)
Evaluates gradients of given list of variable pairs at gauss point locations at current step.
Definition: fluid_calculation_utilities.h:250
static void EvaluateNonHistoricalInPoint(const GeometryType &rGeometry, const Vector &rShapeFunction, const TRefVariableValuePairArgs &... rValueVariablePairs)
Evaluates given list of non historical variable pairs at gauss point locations.
Definition: fluid_calculation_utilities.h:147
static void EvaluateInPoint(const GeometryType &rGeometry, const Vector &rShapeFunction, const int Step, const TRefVariableValuePairArgs &... rValueVariablePairs)
Evaluates given list of variable pairs at gauss point locations at step.
Definition: fluid_calculation_utilities.h:75
static void AddSubVector(Matrix &rOutput, const BoundedVector< double, TSize > &rInput, const unsigned int RowIndex, const unsigned int ColumnIndex)
Adds values of a vector to a given matrix.
Definition: fluid_calculation_utilities.h:358
std::size_t IndexType
Definition: fluid_calculation_utilities.h:41
static void EvaluateNonHistoricalGradientInPoint(const GeometryType &rGeometry, const Matrix &rShapeFunctionDerivatives, const TRefVariableValuePairArgs &... rValueVariablePairs)
Evaluates non historical gradients of given list of variable pairs at gauss point locations.
Definition: fluid_calculation_utilities.h:285
static void EvaluateInPoint(const GeometryType &rGeometry, const Vector &rShapeFunction, const TRefVariableValuePairArgs &... rValueVariablePairs)
Evaluates given list of variable pairs at gauss point locations at current step.
Definition: fluid_calculation_utilities.h:118
std::tuple< TDataType &, const TDataType & > ComponentDataType
Definition: fluid_calculation_utilities.h:48
static void EvaluateGradientInPoint(const GeometryType &rGeometry, const Matrix &rShapeFunctionDerivatives, const int Step, const TRefVariableValuePairArgs &... rValueVariablePairs)
Evaluates gradients of given list of variable pairs at gauss point locations at step.
Definition: fluid_calculation_utilities.h:196
static void ReadSubVector(BoundedVector< double, TSize > &rOutput, const Vector &rInput, const IndexType Position)
Get a sub vector from a vector.
Definition: fluid_calculation_utilities.h:323
std::size_t IndexType
The definition of the index type.
Definition: key_hash.h:35
#define KRATOS_DEBUG_ERROR_IF(conditional)
Definition: exception.h:171
double CalculateLogarithmicYPlusLimit(const double Kappa, const double Beta, const int MaxIterations, const double Tolerance)
Definition: rans_calculation_utilities.cpp:168
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
Internals::Matrix< double, AMatrix::dynamic, 1 > Vector
Definition: amatrix_interface.h:472
Internals::Matrix< double, AMatrix::dynamic, AMatrix::dynamic > Matrix
Definition: amatrix_interface.h:470
AMatrix::MatrixRow< const TExpressionType > row(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression, std::size_t RowIndex)
Definition: amatrix_interface.h:649
args
Definition: generate_gid_list_file.py:37
Kappa
Definition: generate_hyper_elastic_simo_taylor_neo_hookean.py:11
c
Definition: generate_weakly_compressible_navier_stokes_element.py:108
def Beta(n, j)
Definition: quadrature.py:104
integer i
Definition: TensorModule.f:17
e
Definition: run_cpp_mpi_tests.py:31