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.
structural_mechanics_math_utilities.hpp
Go to the documentation of this file.
1 // KRATOS ___| | | |
2 // \___ \ __| __| | | __| __| | | __| _` | |
3 // | | | | | ( | | | | ( | |
4 // _____/ \__|_| \__,_|\___|\__|\__,_|_| \__,_|_| MECHANICS
5 //
6 // License: BSD License
7 // license: StructuralMechanicsApplication/license.txt
8 //
9 // Main authors: Vicente Mataix Ferrandiz
10 //
11 
12 #pragma once
13 
14 // System includes
15 
16 // External includes
17 
18 // Project includes
19 #include "includes/variables.h"
20 #include "utilities/math_utils.h"
21 
22 namespace Kratos
23 {
27 
28 #if !defined(INITIAL_CURRENT)
29 #define INITIAL_CURRENT
30  enum Configuration {Initial = 0, Current = 1};
31 #endif
32 
34 {
35 public:
36 
39 
40  typedef long double RealType;
41 
42  typedef Node NodeType;
43 
45 
49 
55  static inline void Comp_Orthonor_Vect(
59  const array_1d<double, 3 > & vxe,
60  const array_1d<double, 3 > & vye
61  )
62  {
63  double n;
64 
65  MathUtils<double>::CrossProduct(t3g, vxe, vye);
66  n = norm_2(t3g);
67  t3g /= n;
68 
69  MathUtils<double>::CrossProduct(t2g, t3g, vxe);
70  n = norm_2(t2g);
71  t2g /= n;
72 
73  MathUtils<double>::CrossProduct(t1g, t2g, t3g);
74  n = norm_2(t1g);
75  t1g /= n;
76  }
77 
84  static inline void Comp_Orthonor_Base(
88  const array_1d<double, 3 > & vxe,
89  const array_1d<double, 3 > & Xdxi,
90  const array_1d<double, 3 > & Xdeta
91  )
92  {
93  double n;
94 
95  MathUtils<double>::CrossProduct(t3g, Xdxi, Xdeta);
96  n = norm_2(t3g);
97  t3g /= n;
98 
99  MathUtils<double>::CrossProduct(t2g, t3g, vxe);
100  n = norm_2(t2g);
101  t2g /= n;
102 
103  MathUtils<double>::CrossProduct(t1g, t2g, t3g);
104  n = norm_2(t1g);
105  t1g /= n;
106  }
107 
108  static inline void Comp_Orthonor_Base(
110  const array_1d<double, 3 > & vxe,
111  const array_1d<double, 3 > & Xdxi,
112  const array_1d<double, 3 > & Xdeta
113  )
114  {
115  double n;
116 
117  array_1d<double, 3 > t1g, t2g, t3g;
118 
119  MathUtils<double>::CrossProduct(t3g, Xdxi, Xdeta);
120 
121  n = norm_2(t3g);
122  t3g /= n;
123 
124  MathUtils<double>::CrossProduct(t2g, t3g, vxe);
125  n = norm_2(t2g);
126  t2g /= n;
127 
128  MathUtils<double>::CrossProduct(t1g, t2g, t3g);
129  n = norm_2(t1g);
130  t1g /= n;
131 
132  for (std::size_t i = 0; i < 3; ++i) {
133  t(0, i) = t1g[i];
134  t(1, i) = t2g[i];
135  t(2, i) = t3g[i];
136  }
137  }
138 
144  static inline Matrix InterpolPrismGiD(const int nG)
145  {
146  Matrix interpol;
147  interpol.resize(nG, 6, false);
148 
149  /* Assigning values to the vectors */
150  if (nG == 1)
151  {
152  for (unsigned int i = 0; i < 6; i++)
153  {
154  interpol(0, i) = 1.0;
155  }
156  }
157  else if (nG == 2)
158  {
159  for (unsigned int i = 0; i < 3; i++)
160  {
161  interpol(0, i) = 1.0;
162  interpol(1, i) = 0.0;
163  }
164  for (unsigned int i = 3; i < 6; i++)
165  {
166  interpol(0, i) = 0.0;
167  interpol(1, i) = 1.0;
168  }
169  }
170  else if (nG == 3)
171  {
172  for (unsigned int i = 0; i < 3; i++)
173  {
174  interpol(0, i) = 0.745326;
175  interpol(1, i) = 0.254644;
176  interpol(2, i) = 0.0;
177  }
178  for (unsigned int i = 3; i < 6; i++)
179  {
180  interpol(0, i) = 0.0;
181  interpol(1, i) = 0.254644;
182  interpol(2, i) = 0.745326;
183  }
184  }
185  else if (nG == 4)
186  {
187  for (unsigned int i = 0; i < 3; i++)
188  {
189  interpol(0, i) = 0.455467382132614037538;
190  interpol(1, i) = 0.544532617867385962462;
191  interpol(2, i) = 0.0;
192  interpol(3, i) = 0.0;
193  }
194  for (unsigned int i = 3; i < 6; i++)
195  {
196  interpol(0, i) = 0.0;
197  interpol(1, i) = 0.0;
198  interpol(2, i) = 0.544532617867385962462;
199  interpol(3, i) = 0.455467382132614037538;
200  }
201  }
202  else if (nG == 5)
203  {
204  for (unsigned int i = 0; i < 3; i++)
205  {
206  interpol(0, i) = 0.062831503549096234958;
207  interpol(1, i) = 0.907868;
208  interpol(2, i) = 0.0293;
209  interpol(3, i) = 0.0;
210  interpol(4, i) = 0.0;
211  }
212  for (unsigned int i = 3; i < 6; i++)
213  {
214  interpol(0, i) = 0.0;
215  interpol(1, i) = 0.0;
216  interpol(2, i) = 0.0293;
217  interpol(3, i) = 0.907868;
218  interpol(4, i) = 0.062831503549096234958;
219  }
220  }
221  else if (nG == 7)
222  {
223  for (unsigned int i = 0; i < 3; i++)
224  {
225  interpol(0, i) = 0.0;
226  interpol(1, i) = 0.51090930312223869755;
227  interpol(2, i) = 0.48909069687776130245;
228  interpol(3, i) = 0.0;
229  interpol(4, i) = 0.0;
230  interpol(5, i) = 0.0;
231  interpol(6, i) = 0.0;
232  }
233  for (unsigned int i = 3; i < 6; i++)
234  {
235  interpol(0, i) = 0.0;
236  interpol(1, i) = 0.0;
237  interpol(2, i) = 0.0;
238  interpol(3, i) = 0.0;
239  interpol(4, i) = 0.48909069687776130245;
240  interpol(5, i) = 0.51090930312223869755;
241  interpol(6, i) = 0.0;
242  }
243  }
244  else if (nG == 11)
245  {
246  for (unsigned int i = 0; i < 3; i++)
247  {
248  interpol( 0, i) = 0.0;
249  interpol( 1, i) = 0.0;
250  interpol( 2, i) = 0.27601287860590845062;
251  interpol( 3, i) = 0.72398712139409154938;
252  interpol( 4, i) = 0.0;
253  interpol( 5, i) = 0.0;
254  interpol( 6, i) = 0.0;
255  interpol( 7, i) = 0.0;
256  interpol( 8, i) = 0.0;
257  interpol( 9, i) = 0.0;
258  interpol(10, i) = 0.0;
259  }
260  for (unsigned int i = 3; i < 6; i++)
261  {
262  interpol( 0, i) = 0.0;
263  interpol( 1, i) = 0.0;
264  interpol( 2, i) = 0.0;
265  interpol( 3, i) = 0.0;
266  interpol( 4, i) = 0.0;
267  interpol( 5, i) = 0.0;
268  interpol( 6, i) = 0.0;
269  interpol( 7, i) = 0.72398712139409154938;
270  interpol( 8, i) = 0.27601287860590845062;
271  interpol( 9, i) = 0.0;
272  interpol(10, i) = 0.0;
273  }
274  }
275  return interpol;
276  }
277 
287  static inline bool SolveSecondOrderEquation(
288  const RealType& a,
289  const RealType& b,
290  const RealType& c,
291  std::vector<RealType>& solution
292  )
293  {
294  const RealType disc = b*b - 4.00*a*c;
295  RealType q = 0.0;
296 
297  solution.resize(2, false);
298 
299  if (b > 0.00)
300  {
301  q = -0.5 * (b + std::sqrt(disc));
302  }
303  else
304  {
305  q = -0.5 * (b - std::sqrt(disc));
306  }
307 
308  solution[0] = q / a;
309  solution[1] = c / q;
310 
311  return true;
312  }
313 
321  static inline double CalculateRadius(
322  const Vector& N,
323  const GeometryType& Geom,
324  const Configuration ThisConfiguration = Current
325  )
326  {
327  double Radius = 0.0;
328 
329  for (unsigned int iNode = 0; iNode < Geom.size(); iNode++)
330  {
331  // Displacement from the reference to the current configuration
332  if (ThisConfiguration == Current)
333  {
334  const array_1d<double, 3 > CurrentPosition = Geom[iNode].Coordinates();
335  Radius += CurrentPosition[0] * N[iNode];
336  }
337  else
338  {
339  const array_1d<double, 3 > DeltaDisplacement = Geom[iNode].FastGetSolutionStepValue(DISPLACEMENT) - Geom[iNode].FastGetSolutionStepValue(DISPLACEMENT,1);
340  const array_1d<double, 3 > CurrentPosition = Geom[iNode].Coordinates();
341  const array_1d<double, 3 > ReferencePosition = CurrentPosition - DeltaDisplacement;
342  Radius += ReferencePosition[0] * N[iNode];
343  }
344  }
345 
346  return Radius;
347  }
348 
355  static inline double CalculateRadiusPoint(
356  const GeometryType& Geom,
357  const Configuration ThisConfiguration = Current
358  )
359  {
360  // Displacement from the reference to the current configuration
361  if (ThisConfiguration == Current)
362  {
363  const array_1d<double, 3 > CurrentPosition = Geom[0].Coordinates();
364  return CurrentPosition[0];
365  }
366  else
367  {
368  const array_1d<double, 3 > DeltaDisplacement = Geom[0].FastGetSolutionStepValue(DISPLACEMENT) - Geom[0].FastGetSolutionStepValue(DISPLACEMENT,1);
369  const array_1d<double, 3 > CurrentPosition = Geom[0].Coordinates();
370  const array_1d<double, 3 > ReferencePosition = CurrentPosition - DeltaDisplacement;
371  return ReferencePosition[0];
372  }
373  }
374 
384  template<int TDim>
385  static inline void TensorTransformation(
386  BoundedMatrix<double,TDim,TDim>& rOriginLeft,
387  BoundedMatrix<double,TDim,TDim>& rOriginRight,
388  BoundedMatrix<double,TDim,TDim>& rTargetLeft,
389  BoundedMatrix<double,TDim,TDim>& rTargetRight,
391  {
392  // metric computation (of the target systems)
393  BoundedMatrix<double,TDim,TDim> metric_left = ZeroMatrix(TDim,TDim);
394  BoundedMatrix<double,TDim,TDim> metric_right = ZeroMatrix(TDim,TDim);
395  for(int i=0;i<TDim;i++){
396  for(int j=0;j<TDim;j++){
397  metric_left(i,j) += inner_prod(column(rTargetLeft,i),column(rTargetLeft,j));
398  metric_right(i,j) += inner_prod(column(rTargetRight,i),column(rTargetRight,j));
399  }
400  }
401 
402  // invert metric
403  double det;
404  Matrix inv_metric_left = Matrix(TDim,TDim);
405  Matrix inv_metric_right = Matrix(TDim,TDim);
406  MathUtils<double>::InvertMatrix(Matrix(metric_left),inv_metric_left,det);
407  MathUtils<double>::InvertMatrix(metric_right,inv_metric_right,det);
408 
409  // Compute dual target base vectors
410  BoundedMatrix<double,TDim,TDim> target_left_dual = ZeroMatrix(TDim,TDim); // Anna noalias?
411  BoundedMatrix<double,TDim,TDim> target_right_dual = ZeroMatrix(TDim,TDim); // Anna noalias?
412  for(int i=0;i<TDim;i++){
413  for(int j=0;j<TDim;j++){
414  column(target_left_dual,i) += inv_metric_left(i,j)*column(rTargetLeft,j);
415  column(target_right_dual,i) += inv_metric_right(i,j)*column(rTargetRight,j);
416  }
417  }
418 
419  // Tensor transformation
420  BoundedMatrix<double, TDim, TDim> transformed_tensor = ZeroMatrix(TDim, TDim); // Anna noalias?
421  for(int k=0;k<TDim;k++){
422  for(int l=0;l<TDim;l++){
423  for(int i=0;i<TDim;i++){
424  for(int j=0;j<TDim;j++){
425  transformed_tensor(k,l) += rTensor(i,j)*inner_prod(column(target_left_dual,k),column(rOriginLeft,i))*inner_prod(column(target_right_dual,l),column(rOriginRight,j));
426  }
427  }
428  }
429  }
430  rTensor = transformed_tensor;
431  }
432 
433 private:
434 };// class StructuralMechanicsMathUtilities
435 }
436 
Geometry base class.
Definition: geometry.h:71
SizeType size() const
Definition: geometry.h:518
Definition: amatrix_interface.h:41
void resize(std::size_t NewSize1, std::size_t NewSize2, bool preserve=0)
Definition: amatrix_interface.h:224
static T CrossProduct(const T &a, const T &b)
Performs the vector product of the two input vectors a,b.
Definition: math_utils.h:762
static BoundedMatrix< double, TDim, TDim > InvertMatrix(const BoundedMatrix< double, TDim, TDim > &rInputMatrix, double &rInputMatrixDet, const double Tolerance=ZeroTolerance)
Calculates the inverse of a 2x2, 3x3 and 4x4 matrices (using bounded matrix for performance)
Definition: math_utils.h:197
This class defines the node.
Definition: node.h:65
Definition: structural_mechanics_math_utilities.hpp:34
Geometry< NodeType > GeometryType
Definition: structural_mechanics_math_utilities.hpp:44
Node NodeType
Definition: structural_mechanics_math_utilities.hpp:42
static void Comp_Orthonor_Vect(array_1d< double, 3 > &t1g, array_1d< double, 3 > &t2g, array_1d< double, 3 > &t3g, const array_1d< double, 3 > &vxe, const array_1d< double, 3 > &vye)
Definition: structural_mechanics_math_utilities.hpp:55
static void TensorTransformation(BoundedMatrix< double, TDim, TDim > &rOriginLeft, BoundedMatrix< double, TDim, TDim > &rOriginRight, BoundedMatrix< double, TDim, TDim > &rTargetLeft, BoundedMatrix< double, TDim, TDim > &rTargetRight, BoundedMatrix< double, TDim, TDim > &rTensor)
Definition: structural_mechanics_math_utilities.hpp:385
static bool SolveSecondOrderEquation(const RealType &a, const RealType &b, const RealType &c, std::vector< RealType > &solution)
Definition: structural_mechanics_math_utilities.hpp:287
static double CalculateRadiusPoint(const GeometryType &Geom, const Configuration ThisConfiguration=Current)
Definition: structural_mechanics_math_utilities.hpp:355
static void Comp_Orthonor_Base(BoundedMatrix< double, 3, 3 > &t, const array_1d< double, 3 > &vxe, const array_1d< double, 3 > &Xdxi, const array_1d< double, 3 > &Xdeta)
Definition: structural_mechanics_math_utilities.hpp:108
static Matrix InterpolPrismGiD(const int nG)
Definition: structural_mechanics_math_utilities.hpp:144
long double RealType
Definition: structural_mechanics_math_utilities.hpp:40
static void Comp_Orthonor_Base(array_1d< double, 3 > &t1g, array_1d< double, 3 > &t2g, array_1d< double, 3 > &t3g, const array_1d< double, 3 > &vxe, const array_1d< double, 3 > &Xdxi, const array_1d< double, 3 > &Xdeta)
Definition: structural_mechanics_math_utilities.hpp:84
static double CalculateRadius(const Vector &N, const GeometryType &Geom, const Configuration ThisConfiguration=Current)
Definition: structural_mechanics_math_utilities.hpp:321
solution
Definition: KratosDEM.py:9
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
Configuration
Definition: structural_mechanics_math_utilities.hpp:30
@ Current
Definition: structural_mechanics_math_utilities.hpp:30
@ Initial
Definition: structural_mechanics_math_utilities.hpp:30
TExpressionType::data_type norm_2(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:625
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
Internals::Matrix< double, AMatrix::dynamic, AMatrix::dynamic > Matrix
Definition: amatrix_interface.h:470
TExpression1Type::data_type inner_prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:592
AMatrix::MatrixColumn< const TExpressionType > column(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression, std::size_t ColumnIndex)
Definition: amatrix_interface.h:637
q
Definition: generate_convection_diffusion_explicit_element.py:109
a
Definition: generate_stokes_twofluid_element.py:77
b
Definition: generate_total_lagrangian_mixed_volumetric_strain_element.py:31
c
Definition: generate_weakly_compressible_navier_stokes_element.py:108
int t
Definition: ode_solve.py:392
int n
manufactured solution and derivatives (u=0 at z=0 dudz=0 at z=domain_height)
Definition: ode_solve.py:402
int k
Definition: quadrature.py:595
int j
Definition: quadrature.py:648
N
Definition: sensitivityMatrix.py:29
integer i
Definition: TensorModule.f:17
integer l
Definition: TensorModule.f:17