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.
geometry_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 //
12 //
13 
14 #pragma once
15 
16 // System includes
17 
18 // External includes
19 
20 // Project includes
21 #include "geometries/geometry.h"
22 #include "includes/node.h"
23 
24 namespace Kratos
25 {
33 class KRATOS_API(KRATOS_CORE) GeometryUtils
34 {
35 public:
38 
40  using SizeType = std::size_t;
41 
43  using IndexType = std::size_t;
44 
47 
51 
56  static std::string GetGeometryName(const GeometryData::KratosGeometryType TypeOfGeometry);
57 
66  template<class TGeometryType>
68  const TGeometryType& rGeometry,
69  typename TGeometryType::CoordinatesArrayType& rResult,
70  const typename TGeometryType::CoordinatesArrayType& rPoint
71  )
72  {
73  // Debug check that it is at least a tetrahedra
74  KRATOS_DEBUG_ERROR_IF_NOT(rGeometry.GetGeometryFamily() == GeometryData::KratosGeometryFamily::Kratos_Tetrahedra) << "Geometry should be a tetrahedra in order to use PointLocalCoordinatesPlanarFaceTetrahedra" << std::endl;
75 
76  // Compute RHS
78  X[0] = 1.0;
79  X[1] = rPoint[0];
80  X[2] = rPoint[1];
81  X[3] = rPoint[2];
82 
83  // Auxiliary coordinates
84  const auto& r_coordinates_0 = rGeometry[0].Coordinates();
85  const auto& r_coordinates_1 = rGeometry[1].Coordinates();
86  const auto& r_coordinates_2 = rGeometry[2].Coordinates();
87  const auto& r_coordinates_3 = rGeometry[3].Coordinates();
88  const double x1 = r_coordinates_0[0];
89  const double y1 = r_coordinates_0[1];
90  const double z1 = r_coordinates_0[2];
91  const double x2 = r_coordinates_1[0];
92  const double y2 = r_coordinates_1[1];
93  const double z2 = r_coordinates_1[2];
94  const double x3 = r_coordinates_2[0];
95  const double y3 = r_coordinates_2[1];
96  const double z3 = r_coordinates_2[2];
97  const double x4 = r_coordinates_3[0];
98  const double y4 = r_coordinates_3[1];
99  const double z4 = r_coordinates_3[2];
100 
101  // Auxiliary diff
102  const double x12 = x1 - x2;
103  const double x13 = x1 - x3;
104  const double x14 = x1 - x4;
105  const double x21 = x2 - x1;
106  const double x24 = x2 - x4;
107  const double x31 = x3 - x1;
108  const double x32 = x3 - x2;
109  const double x34 = x3 - x4;
110  const double x42 = x4 - x2;
111  const double x43 = x4 - x3;
112  const double y12 = y1 - y2;
113  const double y13 = y1 - y3;
114  const double y14 = y1 - y4;
115  const double y21 = y2 - y1;
116  const double y24 = y2 - y4;
117  const double y31 = y3 - y1;
118  const double y32 = y3 - y2;
119  const double y34 = y3 - y4;
120  const double y42 = y4 - y2;
121  const double y43 = y4 - y3;
122  const double z12 = z1 - z2;
123  const double z13 = z1 - z3;
124  const double z14 = z1 - z4;
125  const double z21 = z2 - z1;
126  const double z24 = z2 - z4;
127  const double z31 = z3 - z1;
128  const double z32 = z3 - z2;
129  const double z34 = z3 - z4;
130  const double z42 = z4 - z2;
131  const double z43 = z4 - z3;
132 
133  // Compute LHS
135  const double aux_volume = 1.0/(6.0*rGeometry.Volume());
136  invJ(0,0) = aux_volume * (x2*(y3*z4-y4*z3)+x3*(y4*z2-y2*z4)+x4*(y2*z3-y3*z2));
137  invJ(1,0) = aux_volume * (x1*(y4*z3-y3*z4)+x3*(y1*z4-y4*z1)+x4*(y3*z1-y1*z3));
138  invJ(2,0) = aux_volume * (x1*(y2*z4-y4*z2)+x2*(y4*z1-y1*z4)+x4*(y1*z2-y2*z1));
139  invJ(3,0) = aux_volume * (x1*(y3*z2-y2*z3)+x2*(y1*z3-y3*z1)+x3*(y2*z1-y1*z2));
140  invJ(0,1) = aux_volume * (y42*z32 - y32*z42);
141  invJ(1,1) = aux_volume * (y31*z43 - y34*z13);
142  invJ(2,1) = aux_volume * (y24*z14 - y14*z24);
143  invJ(3,1) = aux_volume * (y13*z21 - y12*z31);
144  invJ(0,2) = aux_volume * (x32*z42 - x42*z32);
145  invJ(1,2) = aux_volume * (x43*z31 - x13*z34);
146  invJ(2,2) = aux_volume * (x14*z24 - x24*z14);
147  invJ(3,2) = aux_volume * (x21*z13 - x31*z12);
148  invJ(0,3) = aux_volume * (x42*y32 - x32*y42);
149  invJ(1,3) = aux_volume * (x31*y43 - x34*y13);
150  invJ(2,3) = aux_volume * (x24*y14 - x14*y24);
151  invJ(3,3) = aux_volume * (x13*y21 - x12*y31);
152 
153  // Compute result
154  const array_1d<double,4> result = prod(invJ, X);
155 
156  // Resize if needed
157  if (rResult.size() != 3) {
158  rResult.resize(3,false);
159  }
160 
161  // Copy result
162  rResult[0] = result[1];
163  rResult[1] = result[2];
164  rResult[2] = result[3];
165 
166  return rResult;
167  }
168 
176  static inline void CalculateGeometryData(
177  const GeometryType& rGeometry,
179  array_1d<double,4>& rN,
180  double& rVolume
181  )
182  {
183  const double x10 = rGeometry[1].X() - rGeometry[0].X();
184  const double y10 = rGeometry[1].Y() - rGeometry[0].Y();
185  const double z10 = rGeometry[1].Z() - rGeometry[0].Z();
186 
187  const double x20 = rGeometry[2].X() - rGeometry[0].X();
188  const double y20 = rGeometry[2].Y() - rGeometry[0].Y();
189  const double z20 = rGeometry[2].Z() - rGeometry[0].Z();
190 
191  const double x30 = rGeometry[3].X() - rGeometry[0].X();
192  const double y30 = rGeometry[3].Y() - rGeometry[0].Y();
193  const double z30 = rGeometry[3].Z() - rGeometry[0].Z();
194 
195  const double detJ = x10 * y20 * z30 - x10 * y30 * z20 + y10 * z20 * x30 - y10 * x20 * z30 + z10 * x20 * y30 - z10 * y20 * x30;
196 
197  rDN_DX(0,0) = -y20 * z30 + y30 * z20 + y10 * z30 - z10 * y30 - y10 * z20 + z10 * y20;
198  rDN_DX(0,1) = -z20 * x30 + x20 * z30 - x10 * z30 + z10 * x30 + x10 * z20 - z10 * x20;
199  rDN_DX(0,2) = -x20 * y30 + y20 * x30 + x10 * y30 - y10 * x30 - x10 * y20 + y10 * x20;
200  rDN_DX(1,0) = y20 * z30 - y30 * z20;
201  rDN_DX(1,1) = z20 * x30 - x20 * z30;
202  rDN_DX(1,2) = x20 * y30 - y20 * x30;
203  rDN_DX(2,0) = -y10 * z30 + z10 * y30;
204  rDN_DX(2,1) = x10 * z30 - z10 * x30;
205  rDN_DX(2,2) = -x10 * y30 + y10 * x30;
206  rDN_DX(3,0) = y10 * z20 - z10 * y20;
207  rDN_DX(3,1) = -x10 * z20 + z10 * x20;
208  rDN_DX(3,2) = x10 * y20 - y10 * x20;
209 
210  rDN_DX /= detJ;
211 
212  rN[0] = 0.25;
213  rN[1] = 0.25;
214  rN[2] = 0.25;
215  rN[3] = 0.25;
216 
217  rVolume = detJ*0.1666666666666666666667;
218  }
219 
225  KRATOS_DEPRECATED_MESSAGE("Please use the Volume() method from the geometry")
226  static inline double CalculateVolume3D(const GeometryType& rGeometry)
227  {
228  const double x10 = rGeometry[1].X() - rGeometry[0].X();
229  const double y10 = rGeometry[1].Y() - rGeometry[0].Y();
230  const double z10 = rGeometry[1].Z() - rGeometry[0].Z();
231 
232  const double x20 = rGeometry[2].X() - rGeometry[0].X();
233  const double y20 = rGeometry[2].Y() - rGeometry[0].Y();
234  const double z20 = rGeometry[2].Z() - rGeometry[0].Z();
235 
236  const double x30 = rGeometry[3].X() - rGeometry[0].X();
237  const double y30 = rGeometry[3].Y() - rGeometry[0].Y();
238  const double z30 = rGeometry[3].Z() - rGeometry[0].Z();
239 
240  const double detJ = x10 * y20 * z30 - x10 * y30 * z20 + y10 * z20 * x30 - y10 * x20 * z30 + z10 * x20 * y30 - z10 * y20 * x30;
241  return detJ*0.1666666666666666666667;
242  }
243 
251  static inline void CalculateGeometryData(
252  const GeometryType& rGeometry,
255  double& rArea
256  )
257  {
258  const double x10 = rGeometry[1].X() - rGeometry[0].X();
259  const double y10 = rGeometry[1].Y() - rGeometry[0].Y();
260 
261  const double x20 = rGeometry[2].X() - rGeometry[0].X();
262  const double y20 = rGeometry[2].Y() - rGeometry[0].Y();
263 
264  //Jacobian is calculated:
265  // |dx/dxi dx/deta| |x1-x0 x2-x0|
266  //J=| |= | |
267  // |dy/dxi dy/deta| |y1-y0 y2-y0|
268 
269  double detJ = x10 * y20-y10 * x20;
270 
271  DN_DX(0,0) = -y20 + y10;
272  DN_DX(0,1) = x20 - x10;
273  DN_DX(1,0) = y20 ;
274  DN_DX(1,1) = -x20 ;
275  DN_DX(2,0) = -y10 ;
276  DN_DX(2,1) = x10 ;
277 
278  DN_DX /= detJ;
279  N[0] = 0.333333333333333;
280  N[1] = 0.333333333333333;
281  N[2] = 0.333333333333333;
282 
283  rArea = 0.5*detJ;
284  }
285 
291  KRATOS_DEPRECATED_MESSAGE("Please use the Area() method from the geometry")
292  static inline double CalculateVolume2D(const GeometryType& rGeometry)
293  {
294  double x10 = rGeometry[1].X() - rGeometry[0].X();
295  double y10 = rGeometry[1].Y() - rGeometry[0].Y();
296 
297  double x20 = rGeometry[2].X() - rGeometry[0].X();
298  double y20 = rGeometry[2].Y() - rGeometry[0].Y();
299 
300  double detJ = x10 * y20-y10 * x20;
301  return 0.5*detJ;
302  }
303 
311  static inline void SideLenghts2D(
312  const GeometryType& rGeometry,
313  double& hmin,
314  double& hmax
315  )
316  {
317  const double x10 = rGeometry[1].X() - rGeometry[0].X();
318  const double y10 = rGeometry[1].Y() - rGeometry[0].Y();
319 
320  const double x20 = rGeometry[2].X() - rGeometry[0].X();
321  const double y20 = rGeometry[2].Y() - rGeometry[0].Y();
322 
323  double l = std::pow(x20, 2) + std::pow(y20, 2);
324  hmax = l;
325  hmin = l;
326 
327  if(l>hmax) hmax = l;
328  else if(l<hmin) hmin = l;
329 
330  l = (x20-x10)*(x20-x10) + (y20-y10)*(y20-y10);
331  if(l>hmax) hmax = l;
332  else if(l<hmin) hmin = l;
333 
334  hmax = std::sqrt(hmax);
335  hmin = std::sqrt(hmin);
336  }
337 
345  static inline void CalculateGeometryData(
346  const GeometryType& rGeometry,
348  array_1d<double,2>& rN,
349  double& rLength
350  )
351  {
352  const double lx = rGeometry[0].X() - rGeometry[1].X();
353  const double ly = rGeometry[0].Y() - rGeometry[1].Y();
354  const double detJ = 0.5 * std::sqrt(std::pow(lx, 2) + std::pow(ly, 2));
355 
356  rDN_DX(0,0) = -0.5;
357  rDN_DX(1,0) = 0.5;
358  rDN_DX /= detJ;
359 
360  rN[0] = 0.5;
361  rN[1] = 0.5;
362 
363  rLength = 2.0 * detJ;
364  }
365 
371  template<std::size_t TSize>
373  const GeometryType& rGeometry, array_1d<double, TSize>& rDistances)
374  {
375  // Calculating the intersection points
376  array_1d<Point, 4> intersection_points;
377  int number_of_intersection_points = CalculateTetrahedraIntersectionPoints(rGeometry, rDistances, intersection_points);
378 
379  if(number_of_intersection_points == 0) {
380  KRATOS_WARNING("CalculateTetrahedraDistances") << "WARNING:: The intersection with interface hasn't found!" << std::endl << "The distances are: " << rDistances << std::endl;
381  } else if(number_of_intersection_points == 1) {
382  // There is one point with zero distance. The distance of the nodes are their distance to this point
384  // Loop over nodes to calculate their distance to the zero distance node.
385  for(unsigned int i_node = 0; i_node < rGeometry.size() ; ++i_node) {
386  noalias(temp) = intersection_points[0] - rGeometry[i_node];
387  rDistances[i_node] = norm_2(temp);
388  }
389  } else if(number_of_intersection_points == 2) {
390  // Loop over nodes to calculate their distance to the zero distance line.
391  for(unsigned int i_node = 0; i_node < rGeometry.size() ; ++i_node) {
392  rDistances[i_node] = PointDistanceToLineSegment3D(intersection_points[0], intersection_points[1], rGeometry[i_node]);
393  }
394  } else if(number_of_intersection_points == 3) {
395  // Loop over nodes to calculate their distance to the zero distance triangle.
396  for(unsigned int i_node = 0; i_node < rGeometry.size() ; ++i_node) {
397  rDistances[i_node] = PointDistanceToTriangle3D(intersection_points[0], intersection_points[1], intersection_points[2], rGeometry[i_node]);
398 // rDistances[i_node] = std::abs(rGeometry[i_node].Z()); // TODO: To be removed. Pooyan.
399  }
400 
401  } else if(number_of_intersection_points == 4) {
402  // Loop over nodes to calculate their distance to the each zero distance triangle.
403  for(unsigned int i_node = 0; i_node < rGeometry.size() ; ++i_node) {
404  // Here I'm taking in account the order of edges where I'm looking for intersection
405  double d1 = PointDistanceToTriangle3D(intersection_points[0], intersection_points[1], intersection_points[3], rGeometry[i_node]);
406  double d2 = PointDistanceToTriangle3D(intersection_points[0], intersection_points[3], intersection_points[2], rGeometry[i_node]);
407 
408  rDistances[i_node] = (d1 > d2) ? d2 : d1;
409  }
410  }
411  }
412 
418  template<std::size_t TSize>
420  const GeometryType& rGeometry,
421  array_1d<double, TSize>& rDistances
422  )
423  {
424  // Calculating the intersection points
425  array_1d<Point, 4> intersection_points;
426  int number_of_intersection_points = CalculateTetrahedraIntersectionPoints(rGeometry, rDistances, intersection_points);
427 
428  if(number_of_intersection_points == 0) {
429  KRATOS_WARNING("CalculateTriangleDistances") << "WARNING:: The intersection with interface hasn't found!" << std::endl << "The distances are: " << rDistances << std::endl;
430  } else if(number_of_intersection_points == 1) { // There is one point with zero distance. The distance of the nodes are their distance to this point
432  // Loop over nodes to calculate their distance to the zero distance node.
433  for(unsigned int i_node = 0; i_node < rGeometry.size() ; ++i_node) {
434  noalias(temp) = intersection_points[0] - rGeometry[i_node];
435  rDistances[i_node] = norm_2(temp);
436  }
437  } else if(number_of_intersection_points == 2) {
438  // loop over nodes to calculate their distance to the zero distance line.
439  for(unsigned int i_node = 0; i_node < rGeometry.size() ; ++i_node) {
440  rDistances[i_node] = PointDistanceToLineSegment3D(intersection_points[0], intersection_points[1], rGeometry[i_node]);
441  }
442  } else {
443  KRATOS_WARNING("CalculateTriangleDistances") << "WARNING:: This is a triangle with more than two intersections!" << std::endl << "Too many intersections: " << number_of_intersection_points << std::endl << "The distances are: " << rDistances << std::endl;
444  }
445  }
446 
453  template<std::size_t TSize>
455  const GeometryType& rThisGeometry,
456  array_1d<double, TSize>& rDistances
457  )
458  {
459  array_1d<Point, TSize> intersection_points;
460  int number_of_intersection_points = CalculateTetrahedraIntersectionPoints(rThisGeometry, rDistances, intersection_points);
461 
462  if(number_of_intersection_points == 0) {
463  KRATOS_WARNING("GeometryUtilities") << "Warning: The intersection with interface hasn't found! The distances are" << rDistances << std::endl;
464  } else {
465  BoundedMatrix<double,TSize,TSize-1> DN_DX;
467  double volume;
468  GeometryUtils::CalculateGeometryData(rThisGeometry, DN_DX, N, volume);
469  array_1d<double, TSize-1> distance_gradient = prod(trans(DN_DX), rDistances);
470  double distance_gradient_norm = norm_2(distance_gradient);
471  if (distance_gradient_norm < 1e-15) distance_gradient_norm = 1e-15; //avoid division by zero
472  distance_gradient /= distance_gradient_norm;
473  // We use the first intersection point as reference
474  const auto &ref_point = intersection_points[0].Coordinates();
475  for (unsigned int i = 0; i < TSize; i++) {
476  double d = 0.0;
477  const auto &i_coords = rThisGeometry[i].Coordinates();
478  for (unsigned int Dim = 0; Dim < TSize - 1; Dim++) {
479  d += (i_coords[Dim] - ref_point[Dim]) * distance_gradient[Dim];
480  }
481  d = std::abs(d);
482  rDistances[i] = std::min(std::abs(rDistances[i]), d);
483  }
484  }
485  }
486 
494  template<std::size_t TSize1, std::size_t TSize2>
496  const GeometryType& rGeometry,
497  array_1d<double, TSize1>& rDistances,
498  array_1d<Point, TSize2>& rIntersectionPoints
499  )
500  {
501  const double epsilon = 1e-15; //1.00e-9;
502 
503  int number_of_intersection_points = 0;
504  for(unsigned int i = 0 ; i < TSize1 ; i++) {
505  if(std::abs(rDistances[i]) < epsilon) {
506  noalias(rIntersectionPoints[number_of_intersection_points].Coordinates()) = rGeometry[i].Coordinates();
507 
508  number_of_intersection_points++;
509  continue;
510  }
511  for(unsigned int j = i + 1 ; j < TSize1 ; j++) {
512  if(std::abs(rDistances[j]) < epsilon)
513  continue; // we will add it to the intersections by the i index to be unique
514 
515  if(rDistances[i] * rDistances[j] < 0.00) { // The interface passes through the edge
516  const double delta_d = std::abs(rDistances[i]) + std::abs(rDistances[j]); // we know that both distances are greater than epsilon.
517 
518  const double di = std::abs(rDistances[i]) / delta_d;
519  const double dj = std::abs(rDistances[j]) / delta_d;
520 
521  noalias(rIntersectionPoints[number_of_intersection_points].Coordinates()) = dj * rGeometry[i].Coordinates();
522  noalias(rIntersectionPoints[number_of_intersection_points].Coordinates()) += di * rGeometry[j].Coordinates();
523 
524  number_of_intersection_points++;
525  }
526  }
527  }
528 
529  return number_of_intersection_points;
530  }
531 
539  static double PointDistanceToLineSegment3D(
540  const Point& rLinePoint1,
541  const Point& rLinePoint2,
542  const Point& rToPoint
543  );
544 
555  static double PointDistanceToTriangle3D(
556  const Point& rTrianglePoint1,
557  const Point& rTrianglePoint2,
558  const Point& rTrianglePoint3,
559  const Point& rPoint
560  );
561 
574  static double PointDistanceToTriangle3D(
575  const Point& rTrianglePoint1,
576  const Point& rTrianglePoint2,
577  const Point& rTrianglePoint3,
578  const Point& rTrianglePoint4,
579  const Point& rTrianglePoint5,
580  const Point& rTrianglePoint6,
581  const Point& rPoint
582  );
583 
594  static double PointDistanceToQuadrilateral3D(
595  const Point& rQuadrilateralPoint1,
596  const Point& rQuadrilateralPoint2,
597  const Point& rQuadrilateralPoint3,
598  const Point& rQuadrilateralPoint4,
599  const Point& rPoint
600  );
601 
608  template<class TMatrix1, class TMatrix2, class TMatrix3>
610  TMatrix1 const& rDN_De,
611  TMatrix2 const& rInvJ,
612  TMatrix3& rDN_DX
613  )
614  {
615  if (rDN_DX.size1() != rDN_De.size1() || rDN_DX.size2() != rInvJ.size2())
616  rDN_DX.resize(rDN_De.size1(), rInvJ.size2(), false);
617 
618  noalias(rDN_DX) = prod(rDN_De, rInvJ);
619  }
620 
628  template<class TMatrix1, class TMatrix2, class TMatrix3>
629  static void DeformationGradient(
630  TMatrix1 const& rJ,
631  TMatrix2 const& rInvJ0,
632  TMatrix3& rF
633  )
634  {
635  if (rF.size1() != rJ.size1() || rF.size2() != rInvJ0.size2())
636  rF.resize(rJ.size1(), rInvJ0.size2(), false);
637 
638  noalias(rF) = prod(rJ, rInvJ0);
639  }
640 
648  GeometryType const& rGeom,
649  GeometryType::CoordinatesArrayType const& rCoords,
650  Matrix& rJ0
651  )
652  {
653  Matrix delta_position(rGeom.PointsNumber(), rGeom.WorkingSpaceDimension());
654  for (std::size_t i = 0; i < rGeom.PointsNumber(); ++i)
655  for (std::size_t j = 0; j < rGeom.WorkingSpaceDimension(); ++j)
656  delta_position(i, j) = rGeom[i].Coordinates()[j] -
657  rGeom[i].GetInitialPosition().Coordinates()[j];
658  rGeom.Jacobian(rJ0, rCoords, delta_position);
659  }
660 
667  template<class TMatrix>
669  GeometryType const& rGeometry,
670  GeometryType::CoordinatesArrayType const& rCoords,
671  TMatrix& rJ
672  )
673  {
674  const SizeType working_space_dimension = rGeometry.WorkingSpaceDimension();
675  const SizeType local_space_dimension = rGeometry.LocalSpaceDimension();
676  const SizeType points_number = rGeometry.PointsNumber();
677 
678  Matrix shape_functions_gradients(points_number, local_space_dimension);
679  rGeometry.ShapeFunctionsLocalGradients( shape_functions_gradients, rCoords );
680 
681  rJ.clear();
682  for (IndexType i = 0; i < points_number; ++i ) {
683  const array_1d<double, 3>& r_coordinates = rGeometry[i].Coordinates();
684  for(IndexType j = 0; j< working_space_dimension; ++j) {
685  const double value = r_coordinates[j];
686  for(IndexType m = 0; m < local_space_dimension; ++m) {
687  rJ(j,m) += value * shape_functions_gradients(i,m);
688  }
689  }
690  }
691  }
692 
700  template<class TMatrix>
702  GeometryType const& rGeometry,
703  TMatrix& rJ0,
704  const IndexType PointNumber,
705  const GeometryType::IntegrationMethod& rIntegrationMethod
706  )
707  {
708  const SizeType working_space_dimension = rGeometry.WorkingSpaceDimension();
709  const SizeType local_space_dimension = rGeometry.LocalSpaceDimension();
710  const SizeType points_number = rGeometry.PointsNumber();
711 
712  const Matrix& rDN_De = rGeometry.ShapeFunctionsLocalGradients(rIntegrationMethod)[PointNumber];
713 
714  rJ0.clear();
715  for (IndexType i = 0; i < points_number; ++i ) {
716  const array_1d<double, 3>& r_coordinates = rGeometry[i].GetInitialPosition().Coordinates();
717  for(IndexType j = 0; j< working_space_dimension; ++j) {
718  const double value = r_coordinates[j];
719  for(IndexType m = 0; m < local_space_dimension; ++m) {
720  rJ0(j,m) += value * rDN_De(i,m);
721  }
722  }
723  }
724  }
725 
738  template <class TDataType>
739  static void EvaluateHistoricalVariableValueAtGaussPoint(
740  TDataType& rOutput,
741  const GeometryType& rGeometry,
742  const Variable<TDataType>& rVariable,
743  const Vector& rGaussPointShapeFunctionValues,
744  const int Step = 0);
745 
758  static void EvaluateHistoricalVariableGradientAtGaussPoint(
759  array_1d<double, 3>& rOutput,
760  const GeometryType& rGeometry,
761  const Variable<double>& rVariable,
762  const Matrix& rGaussPointShapeFunctionDerivativeValues,
763  const int Step = 0);
764 
781  static void EvaluateHistoricalVariableGradientAtGaussPoint(
783  const GeometryType& rGeometry,
784  const Variable<array_1d<double, 3>>& rVariable,
785  const Matrix& rGaussPointShapeFunctionDerivativeValues,
786  const int Step = 0);
787 
792  static void ShapeFunctionsSecondDerivativesTransformOnAllIntegrationPoints(
794  const GeometryType& rGeometry,
795  const GeometryType::IntegrationMethod& rIntegrationMethod );
796 
797 
804  static void ShapeFunctionsSecondDerivativesTransformOnIntegrationPoint(
805  const Matrix& DN_DX,
806  const GeometryType& rGeometry,
807  const GeometryType::CoordinatesArrayType& rLocalIntegrationPointCoordinates,
808  DenseVector<Matrix>& rResult);
809 
818  static bool ProjectedIsInside(
819  const GeometryType& rGeometry,
820  const GeometryType::CoordinatesArrayType& rPointGlobalCoordinates,
822  const double Tolerance = std::numeric_limits<double>::epsilon()
823  );
824 
834  template <class TGeometryType>
836  const TGeometryType& rGeometry,
837  const typename TGeometryType::CoordinatesArrayType& rPointGlobalCoordinates,
838  const double Tolerance = std::numeric_limits<double>::epsilon()
839  )
840  {
841  typename TGeometryType::CoordinatesArrayType aux_coordinates;
842  if (rGeometry.IsInside(rPointGlobalCoordinates, aux_coordinates, Tolerance)) {
843  return 0.0;
844  }
845 
846  // Generate faces
847  std::vector<double> distances(rGeometry.FacesNumber());
848  unsigned int i = 0;
849  for (auto& r_face : rGeometry.GenerateFaces()) {
850  distances[i] = r_face.CalculateDistance(rPointGlobalCoordinates, Tolerance);
851  ++i;
852  }
853  const auto min = std::min_element(distances.begin(), distances.end());
854  return *min;
855  }
856 };
857 
858 } // namespace Kratos.
859 
860 
KratosGeometryType
Definition: geometry_data.h:110
IntegrationMethod
Definition: geometry_data.h:76
Geometry base class.
Definition: geometry.h:71
SizeType PointsNumber() const
Definition: geometry.h:528
SizeType size() const
Definition: geometry.h:518
SizeType LocalSpaceDimension() const
Definition: geometry.h:1300
const ShapeFunctionsGradientsType & ShapeFunctionsLocalGradients() const
Definition: geometry.h:3539
JacobiansType & Jacobian(JacobiansType &rResult) const
Definition: geometry.h:2901
SizeType WorkingSpaceDimension() const
Definition: geometry.h:1287
This function provides basic routines for working with simplicial meshes.
Definition: geometry_utilities.h:34
static TGeometryType::CoordinatesArrayType & PointLocalCoordinatesPlanarFaceTetrahedra(const TGeometryType &rGeometry, typename TGeometryType::CoordinatesArrayType &rResult, const typename TGeometryType::CoordinatesArrayType &rPoint)
Returns the local coordinates of a given arbitrary point for a given linear tetrahedra.
Definition: geometry_utilities.h:67
static void CalculateTriangleDistances(const GeometryType &rGeometry, array_1d< double, TSize > &rDistances)
Calculate the exact distances to the interface SEGMENT defined by a set of initial distances.
Definition: geometry_utilities.h:419
static void CalculateExactDistancesToPlane(const GeometryType &rThisGeometry, array_1d< double, TSize > &rDistances)
Calculate the exact distances to the plane interface defined by a set of initial distances.
Definition: geometry_utilities.h:454
static void SideLenghts2D(const GeometryType &rGeometry, double &hmin, double &hmax)
This function compute the maximum and minimum edge lenghts.
Definition: geometry_utilities.h:311
std::size_t SizeType
The size type definition.
Definition: geometry_utilities.h:40
std::size_t IndexType
The index type definition.
Definition: geometry_utilities.h:43
static void CalculateGeometryData(const GeometryType &rGeometry, BoundedMatrix< double, 2, 1 > &rDN_DX, array_1d< double, 2 > &rN, double &rLength)
This function is designed to compute the shape function derivatives, shape functions and length.
Definition: geometry_utilities.h:345
static void DeformationGradient(TMatrix1 const &rJ, TMatrix2 const &rInvJ0, TMatrix3 &rF)
Calculate the deformation gradient.
Definition: geometry_utilities.h:629
static void CalculateTetrahedraDistances(const GeometryType &rGeometry, array_1d< double, TSize > &rDistances)
Calculate the exact distances to the interface TRIANGLE defined by a set of initial distances.
Definition: geometry_utilities.h:372
static void ShapeFunctionsGradients(TMatrix1 const &rDN_De, TMatrix2 const &rInvJ, TMatrix3 &rDN_DX)
Calculate the gradients of shape functions.
Definition: geometry_utilities.h:609
static int CalculateTetrahedraIntersectionPoints(const GeometryType &rGeometry, array_1d< double, TSize1 > &rDistances, array_1d< Point, TSize2 > &rIntersectionPoints)
This function calculates the coordinates of the intersecion points between edges of tetrahedra and a ...
Definition: geometry_utilities.h:495
static void JacobianOnInitialConfiguration(GeometryType const &rGeom, GeometryType::CoordinatesArrayType const &rCoords, Matrix &rJ0)
Calculate the Jacobian on the initial configuration.
Definition: geometry_utilities.h:647
static void CalculateGeometryData(const GeometryType &rGeometry, BoundedMatrix< double, 3, 2 > &DN_DX, array_1d< double, 3 > &N, double &rArea)
This function is designed to compute the shape function derivatives, shape functions and area of a tr...
Definition: geometry_utilities.h:251
static double CalculateDistanceFrom3DGeometry(const TGeometryType &rGeometry, const typename TGeometryType::CoordinatesArrayType &rPointGlobalCoordinates, const double Tolerance=std::numeric_limits< double >::epsilon())
Computes the distance between an point in global coordinates and the closest point of this geometry.
Definition: geometry_utilities.h:835
static void DirectJacobianOnInitialConfiguration(GeometryType const &rGeometry, TMatrix &rJ0, const IndexType PointNumber, const GeometryType::IntegrationMethod &rIntegrationMethod)
Calculate the Jacobian on the initial configuration.
Definition: geometry_utilities.h:701
static void CalculateGeometryData(const GeometryType &rGeometry, BoundedMatrix< double, 4, 3 > &rDN_DX, array_1d< double, 4 > &rN, double &rVolume)
This function is designed to compute the shape function derivatives, shape functions and volume in 3D...
Definition: geometry_utilities.h:176
static void DirectJacobianOnCurrentConfiguration(GeometryType const &rGeometry, GeometryType::CoordinatesArrayType const &rCoords, TMatrix &rJ)
Calculate the Jacobian on the initial configuration.
Definition: geometry_utilities.h:668
Definition: amatrix_interface.h:41
void clear()
Definition: amatrix_interface.h:284
Point class.
Definition: point.h:59
Variable class contains all information needed to store and retrive data from a data container.
Definition: variable.h:63
#define KRATOS_DEBUG_ERROR_IF_NOT(conditional)
Definition: exception.h:172
#define KRATOS_WARNING(label)
Definition: logger.h:265
static double min(double a, double b)
Definition: GeometryFunctions.h:71
typename Point::CoordinatesArrayType CoordinatesArrayType
Definition: add_geometries_to_python.cpp:63
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
TExpressionType::data_type norm_2(AMatrix::MatrixExpression< TExpressionType, TCategory > const &TheExpression)
Definition: amatrix_interface.h:625
AMatrix::MatrixProductExpression< TExpression1Type, TExpression2Type > prod(AMatrix::MatrixExpression< TExpression1Type, TCategory1 > const &First, AMatrix::MatrixExpression< TExpression2Type, TCategory2 > const &Second)
Definition: amatrix_interface.h:568
namespace KRATOS_DEPRECATED_MESSAGE("Please use std::filesystem directly") filesystem
Definition: kratos_filesystem.h:33
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
AMatrix::TransposeMatrix< const T > trans(const T &TheMatrix)
Definition: amatrix_interface.h:486
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
x2
Definition: generate_frictional_mortar_condition.py:122
x1
Definition: generate_frictional_mortar_condition.py:121
tuple const
Definition: ode_solve.py:403
int d
Definition: ode_solve.py:397
int j
Definition: quadrature.py:648
float temp
Definition: rotating_cone.py:85
int m
Definition: run_marine_rain_substepping.py:8
N
Definition: sensitivityMatrix.py:29
volume
Definition: sp_statistics.py:15
integer i
Definition: TensorModule.f:17
subroutine d1(DSTRAN, D, dtime, NDI, NSHR, NTENS)
Definition: TensorModule.f:594
integer l
Definition: TensorModule.f:17
e
Definition: run_cpp_mpi_tests.py:31