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.
nodal_values_interpolation_process.h
Go to the documentation of this file.
1 // KRATOS __ __ _____ ____ _ _ ___ _ _ ____
2 // | \/ | ____/ ___|| | | |_ _| \ | |/ ___|
3 // | |\/| | _| \___ \| |_| || || \| | | _
4 // | | | | |___ ___) | _ || || |\ | |_| |
5 // |_| |_|_____|____/|_| |_|___|_| \_|\____| APPLICATION
6 //
7 // License: BSD License
8 // license: MeshingApplication/license.txt
9 //
10 // Main authors: Vicente Mataix Ferrandiz
11 //
12 
13 #pragma once
14 
15 // System includes
16 #include <unordered_set>
17 
18 // External includes
19 
20 // Project includes
22 #include "processes/process.h"
23 
24 /* Several includes */
25 #include "includes/model_part.h"
26 #include "includes/key_hash.h"
28 
29 /* Utilities */
31 
32 /* Tree structures */
33 // #include "spatial_containers/bounding_volume_tree.h" // k-DOP
34 #include "spatial_containers/spatial_containers.h" // kd-tree
35 
36 namespace Kratos
37 {
40 
44 
46  typedef std::size_t SizeType;
47  typedef std::size_t IndexType;
48 
52 
56 
57 namespace NodalInterpolationFunctions
58 {
64  void KRATOS_API(MESHING_APPLICATION) GetListNonHistoricalVariables(
65  const ModelPart& rModelPart,
66  std::unordered_set<std::string>& rVariableList
67  );
68 };
69 
73 
82  : public Point
83 {
84 public:
87 
88  typedef Point BaseType;
89 
92 
96 
99  BaseType(),
100  mpOriginCond(nullptr)
101  {}
102 
104  :BaseType(Coords),
105  mpOriginCond(nullptr)
106  {}
107 
108  PointBoundary(Condition::Pointer pCond):
109  mpOriginCond(pCond)
110  {
111  UpdatePoint();
112  }
113 
115  const array_1d<double, 3>& Coords,
116  Condition::Pointer pCond
117  ):
118  BaseType(Coords),
119  mpOriginCond(pCond)
120  {}
121 
124  BaseType(rhs),
125  mpOriginCond(rhs.mpOriginCond)
126  {
127  }
128 
130  ~PointBoundary() override= default;
131 
135 
141  {
142  BaseType Point(this->Coordinates());
143  return Point;
144  }
145 
150  void SetPoint(const BaseType Point)
151  {
152  this->Coordinates() = Point.Coordinates();
153  }
154 
159  void SetCondition(Condition::Pointer pCond)
160  {
161  mpOriginCond = pCond;
162  }
163 
168  Condition::Pointer GetCondition()
169  {
170  KRATOS_DEBUG_ERROR_IF(mpOriginCond.get() == nullptr) << "Condition no initialized in the PointBoundary class" << std::endl;
171  return mpOriginCond;
172  }
173 
177  void Check()
178  {
179  KRATOS_TRY;
180 
181  auto aux_coord = Kratos::make_shared<array_1d<double, 3>>(this->Coordinates());
182  KRATOS_ERROR_IF(!aux_coord) << "Coordinates no initialized in the PointBoundary class" << std::endl;
183  KRATOS_ERROR_IF(mpOriginCond.get() == nullptr) << "Condition no initialized in the PointBoundary class" << std::endl;
184 
185  KRATOS_CATCH("");
186  }
187 
191  void UpdatePoint()
192  {
193  noalias(this->Coordinates()) = mpOriginCond->GetGeometry().Center().Coordinates();
194  }
195 
196 private:
199  Condition::Pointer mpOriginCond;
201 
202 }; // Class PointBoundary
203 
211 template<SizeType TDim>
212 class KRATOS_API(MESHING_APPLICATION) NodalValuesInterpolationProcess
213  : public Process
214 {
215 public:
218 
219  // General type definitions
223  typedef Node NodeType;
225  typedef Point PointType;
227 
228  // Type definitions for the tree
230  typedef PointBoundaryType::Pointer PointTypePointer;
231  typedef std::vector<PointTypePointer> PointVector;
232  typedef PointVector::iterator PointIterator;
233  typedef std::vector<double> DistanceVector;
234  typedef DistanceVector::iterator DistanceIterator;
235 
236  // KDtree definitions
239 
242 
246 
250  enum class FrameworkEulerLagrange {EULERIAN = 0, LAGRANGIAN = 1, ALE = 2};
251 
255 
263  ModelPart& rOriginMainModelPart,
264  ModelPart& rDestinationMainModelPart,
265  Parameters ThisParameters = Parameters(R"({})")
266  );
267 
269  ~NodalValuesInterpolationProcess() override= default;;
270 
274 
275  void operator()()
276  {
277  Execute();
278  }
279 
283 
287  void Execute() override;
288 
292  const Parameters GetDefaultParameters() const override;
293 
297 
301 
305 
306  /************************************ GET INFO *************************************/
307  /***********************************************************************************/
308 
309  std::string Info() const override
310  {
311  return "NodalValuesInterpolationProcess";
312  }
313 
314  /************************************ PRINT INFO ***********************************/
315  /***********************************************************************************/
316 
317  void PrintInfo(std::ostream& rOStream) const override
318  {
319  rOStream << Info();
320  }
321 
325 
327 private:
330 
334 
335  ModelPart& mrOriginMainModelPart;
336  ModelPart& mrDestinationMainModelPart;
337  Parameters mThisParameters;
338  std::unordered_set<std::string> mListVariables;
339 
343 
347 
353  static inline FrameworkEulerLagrange ConvertFramework(const std::string& Str)
354  {
355  if(Str == "Lagrangian" || Str == "LAGRANGIAN")
357  else if(Str == "Eulerian" || Str == "EULERIAN")
359  else if(Str == "ALE")
361  else
363  }
364 
371  template<class TEntity>
372  void CalculateData(
373  NodeType::Pointer pNode,
374  const typename TEntity::Pointer& pEntity,
375  const Vector& rShapeFunctions
376  )
377  {
378  // The nodal data (non-historical) of each node of the original mesh
379  GeometryType& r_geometry = pEntity->GetGeometry();
380  const SizeType number_of_nodes = r_geometry.size();
381 
382  // Now we interpolate the values of each node
383  double aux_coeff = 0.0;
384  for (IndexType i = 0; i < number_of_nodes; ++i) {
385  aux_coeff += rShapeFunctions[i];
386  }
387  for (auto& r_variable_name : mListVariables) {
388  if (KratosComponents<Variable<double>>::Has(r_variable_name)) {
389  const Variable<double>& r_variable = KratosComponents<Variable<double>>::Get(r_variable_name);
390  if (std::abs(aux_coeff) > std::numeric_limits<double>::epsilon()) {
391  aux_coeff = 1.0/aux_coeff;
392  double aux_value = 0.0;
393  for (IndexType i = 0; i < number_of_nodes; ++i) {
394  if (r_geometry[i].Has(r_variable)) {
395  aux_value += rShapeFunctions[i] * r_geometry[i].GetValue(r_variable);
396  }
397  }
398  pNode->SetValue(r_variable, aux_coeff * aux_value);
399  }
400  } else if (KratosComponents<Variable<array_1d<double, 3>>>::Has(r_variable_name)) {
401  const Variable<array_1d<double, 3>>& r_variable = KratosComponents<Variable<array_1d<double, 3>>>::Get(r_variable_name);
402  if (std::abs(aux_coeff) > std::numeric_limits<double>::epsilon()) {
403  aux_coeff = 1.0/aux_coeff;
404  array_1d<double, 3> aux_value = ZeroVector(3);
405  for (IndexType i = 0; i < number_of_nodes; ++i) {
406  if (r_geometry[i].Has(r_variable)) {
407  aux_value += rShapeFunctions[i] * r_geometry[i].GetValue(r_variable);
408  }
409  }
410  pNode->SetValue(r_variable, aux_coeff * aux_value);
411  }
412  } else if (KratosComponents<Variable<Vector>>::Has(r_variable_name)) {
413  const Variable<Vector>& r_variable = KratosComponents<Variable<Vector>>::Get(r_variable_name);
414  if (std::abs(aux_coeff) > std::numeric_limits<double>::epsilon()) {
415  aux_coeff = 1.0/aux_coeff;
416  Vector aux_value = ZeroVector(r_geometry[0].GetValue(r_variable).size());
417  for (IndexType i = 0; i < number_of_nodes; ++i) {
418  if (r_geometry[i].Has(r_variable)) {
419  aux_value += rShapeFunctions[i] * r_geometry[i].GetValue(r_variable);
420  }
421  }
422  pNode->SetValue(r_variable, aux_coeff * aux_value);
423  }
424  } else if (KratosComponents<Variable<Matrix>>::Has(r_variable_name)) {
425  const Variable<Matrix>& r_variable = KratosComponents<Variable<Matrix>>::Get(r_variable_name);
426  if (std::abs(aux_coeff) > std::numeric_limits<double>::epsilon()) {
427  aux_coeff = 1.0/aux_coeff;
428  Matrix aux_value = ZeroMatrix(r_geometry[0].GetValue(r_variable).size1(), r_geometry[0].GetValue(r_variable).size2());
429  for (IndexType i = 0; i < number_of_nodes; ++i) {
430  if (r_geometry[i].Has(r_variable)) {
431  aux_value += rShapeFunctions[i] * r_geometry[i].GetValue(r_variable);
432  }
433  }
434  pNode->SetValue(r_variable, aux_coeff * aux_value);
435  }
436  }
437  }
438  }
439 
447  template<class TEntity>
448  void CalculateStepData(
449  NodeType::Pointer pNode,
450  const typename TEntity::Pointer& pEntity,
451  const Vector& rShapeFunctions,
452  const IndexType Step
453  )
454  {
455  // The nodal data (historical)
456  double* step_data = pNode->SolutionStepData().Data(Step);
457  for (int j = 0; j < mThisParameters["step_data_size"].GetInt(); ++j)
458  step_data[j] = 0;
459 
460  // The nodal data (historical) of each node of the original mesh
461  GeometryType& geom = pEntity->GetGeometry();
462  const SizeType number_of_nodes = geom.size();
463  for (IndexType i = 0; i < number_of_nodes; ++i) {
464  const double* nodal_data = geom[i].SolutionStepData().Data(Step);
465  // Now we interpolate the values of each node
466  for (int j = 0; j < mThisParameters["step_data_size"].GetInt(); ++j) {
467  step_data[j] += rShapeFunctions[i] * nodal_data[j];
468  }
469  }
470  }
471 
476  void GenerateBoundary(const std::string& rAuxiliarNameModelPart);
477 
483  void GenerateBoundaryFromElements(
484  ModelPart& rModelPart,
485  const std::string& rAuxiliarNameModelPart
486  );
487 
493  void ExtrapolateValues(
494  const std::string& rAuxiliarNameModelPart,
495  std::vector<NodeType::Pointer>& rToExtrapolateNodes
496  );
497 
502  void ComputeNormalSkin(ModelPart& rModelPart);
503 
507 
511 
515 
517 
518 }; // Class NodalValuesInterpolationProcess
519 
521 
524 
525 
529 
530 /****************************** INPUT STREAM FUNCTION ******************************/
531 /***********************************************************************************/
532 
533 // template<class TPointType, class TPointerType>
534 // inline std::istream& operator >> (std::istream& rIStream,
535 // NodalValuesInterpolationProcess& rThis);
536 
537 /***************************** OUTPUT STREAM FUNCTION ******************************/
538 /***********************************************************************************/
539 
540 // template<class TPointType, class TPointerType>
541 // inline std::ostream& operator << (std::ostream& rOStream,
542 // const NodalValuesInterpolationProcess& rThis)
543 // {
544 // return rOStream;
545 // }
546 
548 
549 } // namespace Kratos.
std::string Info() const override
Turn back information as a string.
Definition: periodic_interface_process.hpp:93
Short class definition.
Definition: bucket.h:57
Geometry base class.
Definition: geometry.h:71
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
MeshType::ConditionsContainerType ConditionsContainerType
Condintions container. A vector set of Conditions with their Id's as key.
Definition: model_part.h:183
MeshType::ElementsContainerType ElementsContainerType
Element container. A vector set of Elements with their Id's as key.
Definition: model_part.h:168
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
This utilitiy has as objective to interpolate the values inside elements (and conditions?...
Definition: nodal_values_interpolation_process.h:214
std::vector< PointTypePointer > PointVector
Definition: nodal_values_interpolation_process.h:231
Node NodeType
Definition: nodal_values_interpolation_process.h:223
FrameworkEulerLagrange
This enums allows to differentiate the working framework.
Definition: nodal_values_interpolation_process.h:250
PointVector::iterator PointIterator
Definition: nodal_values_interpolation_process.h:232
ModelPart::ElementsContainerType ElementsArrayType
Definition: nodal_values_interpolation_process.h:221
KRATOS_CLASS_POINTER_DEFINITION(NodalValuesInterpolationProcess)
Pointer definition of NodalValuesInterpolationProcess.
PointBoundary PointBoundaryType
Definition: nodal_values_interpolation_process.h:229
Tree< KDTreePartition< BucketType > > KDTreeType
Definition: nodal_values_interpolation_process.h:238
~NodalValuesInterpolationProcess() override=default
Destructor.
std::vector< double > DistanceVector
Definition: nodal_values_interpolation_process.h:233
PointBoundaryType::Pointer PointTypePointer
Definition: nodal_values_interpolation_process.h:230
ModelPart::NodesContainerType NodesArrayType
Definition: nodal_values_interpolation_process.h:220
PointType::CoordinatesArrayType CoordinatesArrayType
Definition: nodal_values_interpolation_process.h:226
std::string Info() const override
Turn back information as a string.
Definition: nodal_values_interpolation_process.h:309
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: nodal_values_interpolation_process.h:317
void operator()()
Definition: nodal_values_interpolation_process.h:275
Point PointType
Definition: nodal_values_interpolation_process.h:225
Bucket< 3ul, PointBoundaryType, PointVector, PointTypePointer, PointIterator, DistanceIterator > BucketType
Definition: nodal_values_interpolation_process.h:237
Geometry< NodeType > GeometryType
Definition: nodal_values_interpolation_process.h:224
DistanceVector::iterator DistanceIterator
Definition: nodal_values_interpolation_process.h:234
ModelPart::ConditionsContainerType ConditionsArrayType
Definition: nodal_values_interpolation_process.h:222
This class defines the node.
Definition: node.h:65
This class provides to Kratos a data structure for I/O based on the standard of JSON.
Definition: kratos_parameters.h:59
int GetInt() const
This method returns the integer contained in the current Parameter.
Definition: kratos_parameters.cpp:666
Custom Point container to be used to look in the boundary skin.
Definition: nodal_values_interpolation_process.h:83
PointBoundary(const array_1d< double, 3 > &Coords, Condition::Pointer pCond)
Definition: nodal_values_interpolation_process.h:114
void Check()
This method checks everything is right.
Definition: nodal_values_interpolation_process.h:177
PointBoundary(const array_1d< double, 3 > &Coords)
Definition: nodal_values_interpolation_process.h:103
BaseType GetPoint()
Returns the point.
Definition: nodal_values_interpolation_process.h:140
void SetCondition(Condition::Pointer pCond)
Sets the condition associated to the point.
Definition: nodal_values_interpolation_process.h:159
Condition::Pointer GetCondition()
Returns the condition associated to the point.
Definition: nodal_values_interpolation_process.h:168
void SetPoint(const BaseType Point)
Set the point.
Definition: nodal_values_interpolation_process.h:150
PointBoundary(Condition::Pointer pCond)
Definition: nodal_values_interpolation_process.h:108
~PointBoundary() override=default
Destructor.
KRATOS_CLASS_POINTER_DEFINITION(PointBoundary)
Counted pointer of PointBoundary.
PointBoundary()
Default constructors.
Definition: nodal_values_interpolation_process.h:98
PointBoundary(const PointBoundary &rhs)
Copy constructor (not really required)
Definition: nodal_values_interpolation_process.h:123
void UpdatePoint()
This function updates the database, using as base for the coordinates the condition center.
Definition: nodal_values_interpolation_process.h:191
Point BaseType
Definition: nodal_values_interpolation_process.h:88
Point class.
Definition: point.h:59
CoordinatesArrayType const & Coordinates() const
Definition: point.h:215
Point()
Default constructor.
Definition: point.h:86
The base class for all processes in Kratos.
Definition: process.h:49
A generic tree data structure for spatial partitioning.
Definition: tree.h:190
Short class definition.
Definition: array_1d.h:61
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_TRY
Definition: define.h:109
std::size_t IndexType
The definition of the index type.
Definition: key_hash.h:35
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
#define KRATOS_DEBUG_ERROR_IF(conditional)
Definition: exception.h:171
#define KRATOS_API(...)
Definition: kratos_export_api.h:40
bool Has(const std::string &ModelerName)
Checks if the modeler is registered.
Definition: modeler_factory.cpp:24
void GetListNonHistoricalVariables(const ModelPart &rModelPart, std::unordered_set< std::string > &rVariableList)
This methoid creates the list of non-historical variables fro nodal interpolation.
Definition: nodal_values_interpolation_process.cpp:30
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
KratosZeroVector< double > ZeroVector
Definition: amatrix_interface.h:561
Internals::Matrix< double, AMatrix::dynamic, 1 > Vector
Definition: amatrix_interface.h:472
KratosZeroMatrix< double > ZeroMatrix
Definition: amatrix_interface.h:559
Internals::Matrix< double, AMatrix::dynamic, AMatrix::dynamic > Matrix
Definition: amatrix_interface.h:470
FrameworkEulerLagrange
This enums allows to differentiate the working framework.
Definition: meshing_application.h:66
Geometry< Node > GeometryType
The definition of the geometry.
Definition: mortar_classes.h:37
std::size_t SizeType
The definition of the size type.
Definition: mortar_classes.h:43
T & noalias(T &TheMatrix)
Definition: amatrix_interface.h:484
rhs
Definition: generate_frictional_mortar_condition.py:297
int j
Definition: quadrature.py:648
integer i
Definition: TensorModule.f:17