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.
mortar_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: Vicente Mataix Ferrandiz
11 //
12 
13 #if !defined(KRATOS_MORTAR_UTILITIES)
14 #define KRATOS_MORTAR_UTILITIES
15 
16 // System includes
17 #include <numeric>
18 #include <unordered_map>
19 
20 // External includes
21 
22 // Project includes
23 #include "includes/variables.h"
24 #include "includes/node.h"
25 #include "geometries/geometry.h"
26 
27 namespace Kratos
28 {
31 
35 
39 
43 
47 
48 class ModelPart; // forward-declaring to not having to include it here
49 
54 {
55  // Defining clearer options
56  constexpr static bool SaveAsHistoricalVariable = true;
57  constexpr static bool SaveAsNonHistoricalVariable = false;
58 };
59 
70 namespace MortarUtilities
71 {
74 
75  // Some geometrical definitions
76  typedef Node NodeType;
77  typedef Point PointType;
79 
83 
85  typedef std::size_t IndexType;
86 
88  typedef std::size_t SizeType;
89 
91  typedef std::unordered_map<IndexType, IndexType> IntMap;
92 
96 
103  bool KRATOS_API(KRATOS_CORE) LengthCheck(
104  const GeometryPointType& rGeometryLine,
105  const double Tolerance = 1.0e-6
106  );
107 
113  bool KRATOS_API(KRATOS_CORE) HeronCheck(const GeometryPointType& rGeometryTriangle);
114 
122  bool KRATOS_API(KRATOS_CORE) HeronCheck(
123  const PointType& rPointOrig1,
124  const PointType& rPointOrig2,
125  const PointType& rPointOrig3
126  );
127 
136  void KRATOS_API(KRATOS_CORE) RotatePoint(
137  PointType& rPointToRotate,
138  const PointType& rPointReferenceRotation,
139  const array_1d<double, 3>& rSlaveTangentXi,
140  const array_1d<double, 3>& rSlaveTangentEta,
141  const bool Inversed
142  );
143 
151  const Vector& rN,
152  const GeometryType& rGeometry
153  );
154 
160  template <typename TType>
161  std::vector<std::size_t> SortIndexes(const std::vector<TType> &rThisVector) {
162  // Initialize original index locations
163  std::vector<std::size_t> idx(rThisVector.size());
164  iota(idx.begin(), idx.end(), 0);
165 
166  // Sort indexes based on comparing values in rThisVector
167  std::sort(idx.begin(), idx.end(),
168  [&rThisVector](std::size_t i1, std::size_t i2) {return rThisVector[i1] < rThisVector[i2];});
169 
170  return idx;
171  }
172 
179  ModelPart& rModelPart,
180  const bool ComputeConditions = true
181  );
182 
190  void KRATOS_API(KRATOS_CORE) ComputeNodesTangentModelPart(
191  ModelPart& rModelPart,
192  const Variable<array_1d<double, 3>>* pSlipVariable = NULL,
193  const double SlipCoefficient = 1.0,
194  const bool SlipAlways = false
195  );
196 
201  void KRATOS_API(KRATOS_CORE) ComputeNodesTangentFromNormalModelPart(ModelPart& rModelPart);
202 
209  void KRATOS_API(KRATOS_CORE) ComputeTangentsFromNormal(
210  NodeType& rNode,
211  const array_1d<double, 3>& rNormal,
212  const std::size_t Dimension = 3
213  );
214 
224  NodeType& rNode,
225  const std::size_t StepLM = 0,
226  const Variable<array_1d<double, 3>>* pSlipVariable = NULL,
227  const double SlipCoefficient = 1.0,
228  const std::size_t Dimension = 3
229  );
230 
239  void KRATOS_API(KRATOS_CORE) ComputeTangentNodeWithSlip(
240  NodeType& rNode,
241  const std::size_t StepLM = 0,
242  const Variable<array_1d<double, 3>>* pSlipVariable = NULL,
243  const double SlipCoefficient = 1.0,
244  const std::size_t Dimension = 3
245  );
246 
252  template<class TContainerType>
254  TContainerType& rContainer,
255  const Flags Flag
256  )
257  {
258  bool to_invert = false;
259  const auto it_cont_begin = rContainer.begin();
260  #pragma omp parallel for firstprivate(to_invert)
261  for(int i = 0; i < static_cast<int>(rContainer.size()); ++i) {
262  auto it_cont = it_cont_begin + i;
263  to_invert = Flag == Flags() ? true : it_cont->IsDefined(Flag) ? it_cont->Is(Flag) : false;
264 
265  if (to_invert) {
266  GeometryType& r_geometry = it_cont->GetGeometry();
267 
268  auto& data_geom = r_geometry.GetContainer();
269  std::reverse(data_geom.begin(), data_geom.end());
270  }
271  }
272  }
273 
278  template<class TContainerType>
279  void InvertNormal(TContainerType& rContainer)
280  {
281  InvertNormalForFlag(rContainer, Flags());
282  }
283 
292  template< SizeType TDim, SizeType TNumNodes>
294  const GeometryType& rGeometry,
295  const bool Current = true,
296  const IndexType Step = 0
297  ) {
298  /* DEFINITIONS */
300  array_1d<double, 3> coord;
301 
302  for (IndexType i_node = 0; i_node < TNumNodes; ++i_node) {
303  if (Current) {
304  coord = rGeometry[i_node].Coordinates();
305  } else {
306  coord = rGeometry[i_node].GetInitialPosition();
307 
308  if (Step > 0)
309  coord += rGeometry[i_node].FastGetSolutionStepValue(DISPLACEMENT, Step);
310  }
311 
312  for (IndexType i_dof = 0; i_dof < TDim; ++i_dof)
313  coordinates(i_node, i_dof) = coord[i_dof];
314  }
315 
316  return coordinates;
317  }
318 
324  template< SizeType TNumNodes, SizeType TDim>
326  {
327  // Tangent matrix
329 
330  for (IndexType i_node = 0; i_node < TNumNodes; ++i_node) {
331  const auto& r_node = rGeometry[i_node];
332  const auto& r_tangent = r_node.GetValue(TANGENT_XI);
333  for (std::size_t i_dof = 0; i_dof < TDim; ++i_dof) {
334  tangent_matrix(i_node, i_dof) = r_tangent[i_dof];
335  }
336  }
337 
338  return tangent_matrix;
339  }
340 
348  template< SizeType TNumNodes, class TVarType = Variable<double>>
350  const GeometryType& rGeometry,
351  const TVarType& rVariable,
352  const IndexType Step
353  ) {
354  /* DEFINITIONS */
355  array_1d<double, TNumNodes> var_vector;
356 
357  for (IndexType i_node = 0; i_node < TNumNodes; ++i_node)
358  var_vector[i_node] = rGeometry[i_node].FastGetSolutionStepValue(rVariable, Step);
359 
360  return var_vector;
361  }
362 
370  template< SizeType TNumNodes, class TVarType = Variable<double> >
372  const GeometryType& rGeometry,
373  const TVarType& rVariable,
374  const unsigned int Step
375  ) {
376  /* DEFINITIONS */
378 
379  for (IndexType i_node = 0; i_node < TNumNodes; ++i_node)
380  var_vector(i_node, 0) = rGeometry[i_node].FastGetSolutionStepValue(rVariable, Step);
381 
382  return var_vector;
383  }
384 
391  template< SizeType TNumNodes, class TVarType = Variable<double> >
393  const GeometryType& rGeometry,
394  const TVarType& rVariable
395  ) {
396  /* DEFINITIONS */
397  array_1d<double, TNumNodes> var_vector;
398 
399  for (IndexType i_node = 0; i_node < TNumNodes; ++i_node)
400  var_vector[i_node] = rGeometry[i_node].GetValue(rVariable);
401 
402  return var_vector;
403  }
404 
411  template< SizeType TNumNodes, class TVarType = Variable<double> >
413  const GeometryType& rGeometry,
414  const TVarType& rVariable
415  ) {
416  /* DEFINITIONS */
418 
419  for (IndexType i_node = 0; i_node < TNumNodes; ++i_node)
420  var_vector(i_node, 0) = rGeometry[i_node].GetValue(rVariable);
421 
422  return var_vector;
423  }
424 
432  template< SizeType TDim, SizeType TNumNodes>
434  const GeometryType& rGeometry,
435  const Variable<array_1d<double,3> >& rVariable,
436  const unsigned int Step
437  ) {
438  /* DEFINITIONS */
440 
441  for (IndexType i_node = 0; i_node < TNumNodes; ++i_node) {
442  const array_1d<double, 3>& value = rGeometry[i_node].FastGetSolutionStepValue(rVariable, Step);
443  for (IndexType i_dof = 0; i_dof < TDim; ++i_dof)
444  var_matrix(i_node, i_dof) = value[i_dof];
445  }
446 
447  return var_matrix;
448  }
449 
456  template< SizeType TDim, SizeType TNumNodes>
458  const GeometryType& rGeometry,
459  const Variable<array_1d<double,3> >& rVariable
460  ) {
461  /* DEFINITIONS */
463 
464  for (IndexType i_node = 0; i_node < TNumNodes; ++i_node) {
465  const array_1d<double, 3>& value = rGeometry[i_node].GetValue(rVariable);
466  for (IndexType i_dof = 0; i_dof < TDim; ++i_dof)
467  var_matrix(i_node, i_dof) = value[i_dof];
468  }
469 
470  return var_matrix;
471  }
472 
478  template< SizeType TDim, SizeType TNumNodes>
480  /* DEFINITIONS */
482 
483  for (IndexType i_node = 0; i_node < TNumNodes; ++i_node) {
484  for (IndexType i_dof = 0; i_dof < TDim; ++i_dof)
485  AbsMatrix(i_node, i_dof) = std::abs(rInputMatrix(i_node, i_dof));
486  }
487 
488  return AbsMatrix;
489  }
490 
494  template< SizeType TDim, class TVarType>
495  unsigned int SizeToCompute()
496  {
497  if (typeid(TVarType) == typeid(Variable<array_1d<double, 3>>))
498  return TDim;
499 
500  return 1;
501  }
502 
508  template< class TVarType, bool THistorical>
509  void KRATOS_API(KRATOS_CORE) ResetValue(
510  ModelPart& rThisModelPart,
511  const TVarType& rThisVariable
512  );
513 
518  template< class TVarType>
519  void KRATOS_API(KRATOS_CORE) ResetAuxiliarValue(ModelPart& rThisModelPart);
520 
525  template< class TVarType>
526  const std::string KRATOS_API(KRATOS_CORE) GetAuxiliarVariable();
527 
534  template< class TVarType>
535  double KRATOS_API(KRATOS_CORE) GetAuxiliarValue(
536  NodeType& rThisNode,
537  const std::size_t iSize
538  );
539 
546  template< class TVarType, bool THistorical>
547  void KRATOS_API(KRATOS_CORE) MatrixValue(
548  const GeometryType& rThisGeometry,
549  const TVarType& rThisVariable,
550  Matrix& rThisValue
551  );
552 
560  template< class TVarType, bool THistorical>
561  void KRATOS_API(KRATOS_CORE) AddValue(
562  GeometryType& rThisGeometry,
563  const TVarType& rThisVariable,
564  const Matrix& rThisValue
565  );
566 
572  template< class TVarType, bool THistorical>
574  NodeType& rThisNode,
575  const TVarType& rThisVariable,
576  const double RefArea = 1.0,
577  const double Tolerance = 1.0e-4
578  );
579 
588  template< class TVarType, bool THistorical>
589  void KRATOS_API(KRATOS_CORE) UpdateDatabase(
590  ModelPart& rThisModelPart,
591  const TVarType& rThisVariable,
592  Vector& rDx,
593  const std::size_t Index,
594  IntMap& rConectivityDatabase
595  );
596 };// namespace MortarUtilities
597 } // namespace Kratos
598 #endif /* KRATOS_MORTAR_UTILITIES defined */
Definition: flags.h:58
bool IsDefined(Flags const &rOther) const
Definition: flags.h:279
Geometry base class.
Definition: geometry.h:71
PointPointerContainerType & GetContainer()
‍** Gives a reference to underly normal container. *‍/
Definition: geometry.h:573
TVariableType::Type & GetValue(const TVariableType &rThisVariable)
Definition: geometry.h:627
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
This class defines the node.
Definition: node.h:65
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
Short class definition.
Definition: array_1d.h:61
#define KRATOS_API(...)
Definition: kratos_export_api.h:40
Kratos::ModelPart ModelPart
Definition: kratos_wrapper.h:31
Point PointType
Definition: mortar_utilities.h:77
std::vector< std::size_t > SortIndexes(const std::vector< TType > &rThisVector)
This function gives you the indexes needed to order a vector.
Definition: mortar_utilities.h:161
void InvertNormalForFlag(TContainerType &rContainer, const Flags Flag)
It inverts the order of the nodes in the conditions of a model part in order to invert the normal whe...
Definition: mortar_utilities.h:253
Node NodeType
Definition: mortar_utilities.h:76
void ComputeNodesMeanNormalModelPart(ModelPart &rModelPart, const bool ComputeConditions)
It computes the mean of the normal in the condition in all the nodes.
Definition: mortar_utilities.cpp:133
BoundedMatrix< double, TNumNodes, 1 > GetVariableVectorMatrix(const GeometryType &rGeometry, const TVarType &rVariable, const unsigned int Step)
It calculates the vector of an historical variable of a geometry.
Definition: mortar_utilities.h:371
double GetAuxiliarValue(NodeType &rThisNode, const std::size_t iSize)
This method returns the auxiliar variable.
BoundedMatrix< double, TNumNodes, TDim > GetCoordinates(const GeometryType &rGeometry, const bool Current=true, const IndexType Step=0)
It calculates the matrix of coordinates of a geometry.
Definition: mortar_utilities.h:293
std::size_t IndexType
Index type definition.
Definition: mortar_utilities.h:85
void ResetValue(ModelPart &rThisModelPart, const TVarType &rThisVariable)
This method resets the value.
PointType::CoordinatesArrayType CoordinatesArrayType
Definition: mortar_utilities.h:78
BoundedMatrix< double, TNumNodes, TDim > GetVariableMatrix(const GeometryType &rGeometry, const Variable< array_1d< double, 3 > > &rVariable, const unsigned int Step)
It calculates the matrix of a variable of a geometry.
Definition: mortar_utilities.h:433
BoundedMatrix< double, TNumNodes, TDim > ComputeTangentMatrix(const GeometryType &rGeometry)
It calculates the matrix containing the tangent vector TANGENT_XI.
Definition: mortar_utilities.h:325
unsigned int SizeToCompute()
This method gives the size to be computed.
Definition: mortar_utilities.h:495
std::unordered_map< IndexType, IndexType > IntMap
A map for integers.
Definition: mortar_utilities.h:91
void RotatePoint(PointType &rPointToRotate, const PointType &rPointReferenceRotation, const array_1d< double, 3 > &rSlaveTangentXi, const array_1d< double, 3 > &rSlaveTangentEta, const bool Inversed)
This function rotates to align the projected points to a parallel plane to XY.
Definition: mortar_utilities.cpp:81
void ComputeNodesTangentModelPart(ModelPart &rModelPart, const Variable< array_1d< double, 3 >> *pSlipVariable, const double SlipCoefficient, const bool SlipAlways)
It computes the tangent in all the nodes of the model part.
Definition: mortar_utilities.cpp:149
void ResetAuxiliarValue(ModelPart &rThisModelPart)
This method resets the auxiliar value.
void ComputeTangentNodeWithSlip(NodeType &rNode, const std::size_t StepLM, const Variable< array_1d< double, 3 >> *pSlipVariable, const double SlipCoefficient, const std::size_t Dimension)
It computes the tangent on the given node using the Slip direction.
Definition: mortar_utilities.cpp:295
array_1d< double, 3 > GaussPointUnitNormal(const Vector &rN, const GeometryType &rGeometry)
This function calculates the r_normal in a specific GP with a given shape function.
Definition: mortar_utilities.cpp:113
bool HeronCheck(const GeometryPointType &rGeometryTriangle)
This functions checks if the semiperimeter is smaller than any of the sides of the triangle.
Definition: mortar_utilities.cpp:45
void AddAreaWeightedNodalValue(NodeType &rThisNode, const TVarType &rThisVariable, const double RefArea=1.0, const double Tolerance=1.0e-4)
This method adds the value.
void ComputeNodesTangentFromNormalModelPart(ModelPart &rModelPart)
It computes the tangent in all the nodes of the model part from its normal.
Definition: mortar_utilities.cpp:185
array_1d< double, TNumNodes > GetVariableVector(const GeometryType &rGeometry, const TVarType &rVariable, const IndexType Step)
It calculates the vector of an historical variable of a geometry.
Definition: mortar_utilities.h:349
void UpdateDatabase(ModelPart &rThisModelPart, const TVarType &rThisVariable, Vector &rDx, const std::size_t Index, IntMap &rConectivityDatabase)
This method updates the database in the amster side.
Geometry< NodeType > GeometryType
Definition of geometries.
Definition: mortar_utilities.h:81
BoundedMatrix< double, TNumNodes, TDim > GetAbsMatrix(const BoundedMatrix< double, TNumNodes, TDim > &rInputMatrix)
It calculates the matrix containing the absolute value of another matrix.
Definition: mortar_utilities.h:479
bool LengthCheck(const GeometryPointType &rGeometryLine, const double Tolerance)
This functions checks if the length of the line is to short, with the potential of provoque ill condi...
Definition: mortar_utilities.cpp:30
void AddValue(GeometryType &rThisGeometry, const TVarType &rThisVariable, const Matrix &rThisValue)
This method adds the value.
void InvertNormal(TContainerType &rContainer)
It inverts the order of the nodes in the conditions of a model part in order to invert the normal.
Definition: mortar_utilities.h:279
void MatrixValue(const GeometryType &rThisGeometry, const TVarType &rThisVariable, Matrix &rThisValue)
This method adds the value.
Geometry< PointType > GeometryPointType
Definition: mortar_utilities.h:82
void ComputeTangentsFromNormal(NodeType &rNode, const array_1d< double, 3 > &rNormal, const std::size_t Dimension)
It computes the tangent on the given node using the normal provided.
Definition: mortar_utilities.cpp:210
void ComputeTangentNodeWithLMAndSlip(NodeType &rNode, const std::size_t StepLM, const Variable< array_1d< double, 3 >> *pSlipVariable, const double SlipCoefficient, const std::size_t Dimension)
It computes the tangent on the given node using the LM direction and Slip direction.
Definition: mortar_utilities.cpp:237
std::size_t SizeType
Size type definition.
Definition: mortar_utilities.h:88
const std::string GetAuxiliarVariable()
This method returns the auxiliar variable.
Parameters GetValue(Parameters &rParameters, const std::string &rEntry)
Definition: add_kratos_parameters_to_python.cpp:53
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
This is a class that provides auxiliar utilities for the mortar integration.
def Index()
Definition: hdf5_io_tools.py:38
integer i
Definition: TensorModule.f:17
@ Current
Definition: particle_mechanics_math_utilities.h:39
This struct is used in order to identify when using the historical and non historical variables.
Definition: mortar_utilities.h:54
constexpr static bool SaveAsNonHistoricalVariable
Definition: mortar_utilities.h:57
constexpr static bool SaveAsHistoricalVariable
Definition: mortar_utilities.h:56