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.
integration_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: Riccardo Rossi
11 // Vicente Mataix Ferrandiz
12 //
13 
14 #pragma once
15 
16 // System includes
17 
18 // External includes
19 
20 // Project includes
21 #include "geometries/geometry.h"
23 namespace Kratos
24 {
25 
33 {
34 public:
41  template<class TPointType>
43  {
44  GeometryData::IntegrationMethod integration_method = rGeometry.GetDefaultIntegrationMethod();
45  if (integration_method == GeometryData::IntegrationMethod::GI_GAUSS_1)
47  else if(integration_method == GeometryData::IntegrationMethod::GI_GAUSS_2)
49  else if(integration_method == GeometryData::IntegrationMethod::GI_GAUSS_3)
51  else if(integration_method == GeometryData::IntegrationMethod::GI_GAUSS_4)
53  return integration_method;
54  }
55 
62  template<class TGeometryType>
63  static inline double ComputeDomainSize(const TGeometryType& rGeometry)
64  {
65  const auto& r_integration_points = rGeometry.IntegrationPoints();
66  const auto number_gp = r_integration_points.size();
67  Vector temp(number_gp);
68  temp = rGeometry.DeterminantOfJacobian(temp);
69  double domain_size = 0.0;
70  for (unsigned int i = 0; i < number_gp; ++i) {
71  domain_size += temp[i] * r_integration_points[i].Weight();
72  }
73  return domain_size;
74  }
75 
83  template<class TPointType>
84  static inline double ComputeDomainSize(
85  const Geometry<TPointType>& rGeometry,
87  )
88  {
89  const auto& r_integration_points = rGeometry.IntegrationPoints( IntegrationMethod );
90  const auto number_gp = r_integration_points.size();
91  Vector temp(number_gp);
93  double domain_size = 0.0;
94  for (unsigned int i = 0; i < number_gp; ++i) {
95  domain_size += temp[i] * r_integration_points[i].Weight();
96  }
97  return domain_size;
98  }
99 
106  template<class TPointType>
107  static inline double ComputeArea2DGeometry(const Geometry<TPointType>& rGeometry)
108  {
109  const auto integration_method = rGeometry.GetDefaultIntegrationMethod();
110  const auto& r_integration_points = rGeometry.IntegrationPoints( integration_method );
111  double volume = 0.0;
112  Matrix J(2, 2);
113  for ( unsigned int i = 0; i < r_integration_points.size(); i++ ) {
114  rGeometry.Jacobian( J, i, integration_method);
115  volume += MathUtils<double>::Det2(J) * r_integration_points[i].Weight();
116  }
117 
118  return volume;
119  }
120 
130  template<class TPointType>
131  static inline double ComputeArea2DGeometryDerivative(
132  const unsigned int DerivativeNodeIndex,
133  const unsigned int DerivativeDirectionIndex,
134  const Geometry<TPointType>& rGeometry)
135  {
136  const auto integration_method = rGeometry.GetDefaultIntegrationMethod();
137  const auto& r_integration_points = rGeometry.IntegrationPoints( integration_method );
138 
139  Matrix jacobian(2, 2);
140  Matrix shape_function_local_gradients(rGeometry.size(), 2), rdNdXDerivative;
141  double detJ_derivative;
142  ShapeParameter shape_param;
143 
144  shape_param.NodeIndex = DerivativeNodeIndex;
145  shape_param.Direction = DerivativeDirectionIndex;
146 
147  double area_derivative = 0.0;
148  for (unsigned int g = 0; g < r_integration_points.size(); g++) {
149  noalias(shape_function_local_gradients) = rGeometry.ShapeFunctionLocalGradient(g, integration_method);
150  rGeometry.Jacobian(jacobian, g, integration_method);
151 
152  GeometricalSensitivityUtility geometrical_sensitivity_utility(jacobian, shape_function_local_gradients);
153  geometrical_sensitivity_utility.CalculateSensitivity(shape_param, detJ_derivative, rdNdXDerivative);
154 
155  area_derivative += detJ_derivative * r_integration_points[g].Weight();
156  }
157 
158  return area_derivative;
159  }
160 
167  template<class TPointType>
168  static inline double ComputeVolume3DGeometry(const Geometry<TPointType>& rGeometry)
169  {
170  const auto integration_method = rGeometry.GetDefaultIntegrationMethod();
171  const auto& r_integration_points = rGeometry.IntegrationPoints( integration_method );
172  double volume = 0.0;
173  Matrix J(3, 3);
174  for ( unsigned int i = 0; i < r_integration_points.size(); i++ ) {
175  rGeometry.Jacobian( J, i, integration_method);
176  volume += MathUtils<double>::Det3(J) * r_integration_points[i].Weight();
177  }
178 
179  return volume;
180  }
181 
191  template<class TPointType>
192  static inline double ComputeVolume3DGeometryDerivative(
193  const unsigned int DerivativeNodeIndex,
194  const unsigned int DerivativeDirectionIndex,
195  const Geometry<TPointType>& rGeometry)
196  {
197  const auto integration_method = rGeometry.GetDefaultIntegrationMethod();
198  const auto& r_integration_points = rGeometry.IntegrationPoints( integration_method );
199 
200  Matrix jacobian(3, 3);
201  Matrix shape_function_local_gradients(rGeometry.size(), 3), rdNdXDerivative;
202  double detJ_derivative;
203  ShapeParameter shape_param;
204 
205  shape_param.NodeIndex = DerivativeNodeIndex;
206  shape_param.Direction = DerivativeDirectionIndex;
207 
208  double volume_derivative = 0.0;
209  for (unsigned int g = 0; g < r_integration_points.size(); g++) {
210  noalias(shape_function_local_gradients) = rGeometry.ShapeFunctionLocalGradient(g, integration_method);
211  rGeometry.Jacobian(jacobian, g, integration_method);
212 
213  GeometricalSensitivityUtility geometrical_sensitivity_utility(jacobian, shape_function_local_gradients);
214  geometrical_sensitivity_utility.CalculateSensitivity(shape_param, detJ_derivative, rdNdXDerivative);
215 
216  volume_derivative += detJ_derivative * r_integration_points[g].Weight();
217  }
218 
219  return volume_derivative;
220  }
221 
222 };
223 
224 } // namespace Kratos.
Definition: geometrical_sensitivity_utility.h:79
void CalculateSensitivity(ShapeParameter Deriv, double &rDetJ_Deriv, ShapeFunctionsGradientType &rDN_DX_Deriv) const
Definition: geometrical_sensitivity_utility.cpp:52
IntegrationMethod
Definition: geometry_data.h:76
Geometry base class.
Definition: geometry.h:71
SizeType size() const
Definition: geometry.h:518
Vector & DeterminantOfJacobian(Vector &rResult) const
Definition: geometry.h:3154
IntegrationMethod GetDefaultIntegrationMethod() const
Definition: geometry.h:2004
const Matrix & ShapeFunctionLocalGradient(IndexType IntegrationPointIndex) const
Definition: geometry.h:3592
const IntegrationPointsArrayType & IntegrationPoints() const
Definition: geometry.h:2284
JacobiansType & Jacobian(JacobiansType &rResult) const
Definition: geometry.h:2901
Utilities to integrate in different cases.
Definition: integration_utilities.h:33
static double ComputeVolume3DGeometry(const Geometry< TPointType > &rGeometry)
This method calculates and returns the volume of the geometry from a 3D geometry.
Definition: integration_utilities.h:168
static double ComputeArea2DGeometryDerivative(const unsigned int DerivativeNodeIndex, const unsigned int DerivativeDirectionIndex, const Geometry< TPointType > &rGeometry)
This method calculates derivative of the area for a 2D geometry.
Definition: integration_utilities.h:131
static double ComputeDomainSize(const TGeometryType &rGeometry)
This method calculates and returns the domain size of the geometry from any geometry in a generic man...
Definition: integration_utilities.h:63
static double ComputeArea2DGeometry(const Geometry< TPointType > &rGeometry)
This method calculates and returns the volume of the geometry from a 3D geometry.
Definition: integration_utilities.h:107
static double ComputeDomainSize(const Geometry< TPointType > &rGeometry, const typename Geometry< TPointType >::IntegrationMethod IntegrationMethod)
This method calculates and returns the domain size of the geometry from any geometry in a generic man...
Definition: integration_utilities.h:84
static double ComputeVolume3DGeometryDerivative(const unsigned int DerivativeNodeIndex, const unsigned int DerivativeDirectionIndex, const Geometry< TPointType > &rGeometry)
This method calculates derivative of the volume for a 3D geometry.
Definition: integration_utilities.h:192
static GeometryData::IntegrationMethod GetIntegrationMethodForExactMassMatrixEvaluation(const Geometry< TPointType > &rGeometry)
This method returns the integration order for the exact mass matrix evaluation.
Definition: integration_utilities.h:42
static double Det3(const TMatrixType &rA)
Calculates the determinant of a matrix of dimension 3*3 (no check performed on matrix size)
Definition: math_utils.h:562
static double Det2(const TMatrixType &rA)
Calculates the determinant of a matrix of dimension 2x2 (no check performed on matrix size)
Definition: math_utils.h:549
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
int domain_size
Definition: face_heat.py:4
float temp
Definition: rotating_cone.py:85
J
Definition: sensitivityMatrix.py:58
volume
Definition: sp_statistics.py:15
integer i
Definition: TensorModule.f:17
Definition: geometrical_sensitivity_utility.h:33
std::size_t NodeIndex
Definition: geometrical_sensitivity_utility.h:34
std::size_t Direction
Definition: geometrical_sensitivity_utility.h:35