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.
calculate_discontinuous_distance_to_skin_process.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: Pooyan Dadvand
11 // Ruben Zorrilla
12 //
13 // Collaborators: Franziska Wahl
14 //
15 
16 #if !defined(KRATOS_CALCULATE_DISCONTINUOUS_DISTANCE_TO_SKIN_PROCESS_H_INCLUDED )
17 #define KRATOS_CALCULATE_DISCONTINUOUS_DISTANCE_TO_SKIN_PROCESS_H_INCLUDED
18 
19 // System includes
20 #include <string>
21 #include <iostream>
22 
23 // External includes
24 
25 // Project includes
26 #include "geometries/plane_3d.h"
27 #include "includes/checks.h"
28 #include "processes/process.h"
32 
33 namespace Kratos
34 {
37 
40 
42 {
43 public:
44  KRATOS_DEFINE_LOCAL_FLAG(CALCULATE_ELEMENTAL_EDGE_DISTANCES);
45  KRATOS_DEFINE_LOCAL_FLAG(CALCULATE_ELEMENTAL_EDGE_DISTANCES_EXTRAPOLATED);
46  KRATOS_DEFINE_LOCAL_FLAG(USE_POSITIVE_EPSILON_FOR_ZERO_VALUES);
47 };
48 
50 
53 template<std::size_t TDim = 3>
54 class KRATOS_API(KRATOS_CORE) CalculateDiscontinuousDistanceToSkinProcess : public Process
55 {
56 
57 public:
60 
63 
67 
70  ModelPart& rVolumePart,
71  ModelPart& rSkinPart);
72 
75  ModelPart& rVolumePart,
76  ModelPart& rSkinPart,
77  const Flags rOptions);
78 
81  ModelPart& rVolumePart,
82  ModelPart& rSkinPart,
83  Parameters rParameters);
84 
87 
91 
94 
97 
100 
102 
106 
112  virtual void Initialize();
113 
118  virtual void FindIntersections();
119 
125  virtual std::vector<PointerVector<GeometricalObject>>& GetIntersections();
126 
132  virtual void CalculateDistances(std::vector<PointerVector<GeometricalObject>>& rIntersectedObjects);
133 
138  void Clear() override;
139 
144  void Execute() override;
145 
152  void CalculateEmbeddedVariableFromSkin(
153  const Variable<double> &rVariable,
154  const Variable<double> &rEmbeddedVariable);
155 
162  void CalculateEmbeddedVariableFromSkin(
163  const Variable<array_1d<double,3>> &rVariable,
164  const Variable<array_1d<double,3>> &rEmbeddedVariable);
165 
169  const Parameters GetDefaultParameters() const override;
170 
174 
175 
179 
181  std::string Info() const override;
182 
184  void PrintInfo(std::ostream& rOStream) const override;
185 
187  void PrintData(std::ostream& rOStream) const override;
188 
190 protected:
191 
192  const Variable<Vector>* mpElementalDistancesVariable = &ELEMENTAL_DISTANCES;
193 
194 
197 
206  Plane3D SetIntersectionPlane(const std::vector<array_1d<double,3>> &rIntPtsVector);
207 
214  double CalculateCharacteristicLength();
215 
217 private:
220 
221  ModelPart& mrSkinPart;
222  ModelPart& mrVolumePart;
223 
224  Flags mOptions;
225 
226  static const std::size_t mNumNodes = TDim + 1;
227  static const std::size_t mNumEdges = (TDim == 2) ? 3 : 6;
228 
229  const double mZeroToleranceMultiplier = 1e3;
230  bool mDetectedZeroDistanceValues = false;
231  bool mAreNeighboursComputed = false;
232  bool mCalculateElementalEdgeDistances = false;
233  bool mCalculateElementalEdgeDistancesExtrapolated = false;
234  bool mUsePositiveEpsilonForZeroValues = true;
235 
236 
237  const Variable<Vector>* mpElementalEdgeDistancesVariable = &ELEMENTAL_EDGE_DISTANCES;
238  const Variable<Vector>* mpElementalEdgeDistancesExtrapolatedVariable = &ELEMENTAL_EDGE_DISTANCES_EXTRAPOLATED;
239  const Variable<array_1d<double, 3>>* mpEmbeddedVelocityVariable = &EMBEDDED_VELOCITY;
240 
244 
251  void CalculateElementalDistances(
252  Element& rElement1,
253  PointerVector<GeometricalObject>& rIntersectedObjects);
254 
261  void CalculateElementalAndEdgeDistances(
262  Element& rElement1,
263  PointerVector<GeometricalObject>& rIntersectedObjects);
264 
277  unsigned int ComputeEdgesIntersections(
278  Element& rElement1,
279  const PointerVector<GeometricalObject>& rIntersectedObjects,
280  const Element::GeometryType::GeometriesArrayType& rEdgesContainer,
281  array_1d<double,mNumEdges> &rCutEdgesRatioVector,
282  array_1d<double,mNumEdges> &rCutExtraEdgesRatioVector,
283  std::vector<array_1d <double,3> > &rIntersectionPointsArray);
284 
296  int ComputeEdgeIntersection(
297  const Element::GeometryType& rIntObjGeometry,
298  const Element::NodeType& rEdgePoint1,
299  const Element::NodeType& rEdgePoint2,
300  Point& rIntersectionPoint);
301 
310  bool CheckIfPointIsRepeated(
311  const array_1d<double,3>& rIntersectionPoint,
312  const std::vector<array_1d<double,3>>& rIntersectionPointsVector,
313  const double& rEdgeTolerance);
314 
322  void ComputeIntersectionNormal(
323  const Element::GeometryType& rGeometry,
324  const Vector& rElementalDistances,
325  array_1d<double,3> &rNormal);
326 
336  void ComputeIntersectionPlaneElementalDistances(
337  Element& rElement,
338  const PointerVector<GeometricalObject>& rIntersectedObjects,
339  const std::vector<array_1d<double,3>>& rIntersectionPointsCoordinates);
340 
352  void ComputePlaneApproximation(
353  const Element& rElement1,
354  const std::vector< array_1d<double,3> >& rPointsCoord,
355  array_1d<double,3>& rPlaneBasePointCoords,
356  array_1d<double,3>& rPlaneNormal);
357 
358 
366  void ComputeElementalDistancesFromPlaneApproximation(
367  Element& rElement,
368  Vector& rElementalDistances,
369  const std::vector<array_1d<double,3>>& rPointVector);
370 
377  void ReplaceZeroDistances(Vector& rElementalDistances);
378 
389  void CorrectDistanceOrientation(
390  const Element::GeometryType& rGeometry,
391  const PointerVector<GeometricalObject>& rIntersectedObjects,
392  Vector& rElementalDistances);
393 
400  void inline ComputeIntersectionNormalFromGeometry(
401  const Element::GeometryType &rGeometry,
402  array_1d<double,3> &rIntObjNormal);
403 
416  void ComputeExtrapolatedEdgesIntersectionsIfIncised(
417  const Element& rElement,
418  const Element::GeometryType::GeometriesArrayType& rEdgesContainer,
419  unsigned int &rNumCutEdges,
420  array_1d<double,mNumEdges>& rCutEdgesRatioVector,
421  array_1d<double,3> &rExtraGeomNormal,
422  array_1d<double,mNumEdges>& rCutExtraEdgesRatioVector);
423 
436  void ComputeExtrapolatedGeometryIntersections(
437  const Element& rElement,
438  const Element::GeometryType::GeometriesArrayType& rEdgesContainer,
439  unsigned int& rNumCutEdges,
440  array_1d<double,mNumEdges>& rCutEdgesRatioVector,
441  array_1d<double,3>& rExtraGeomNormal,
442  array_1d<double,mNumEdges>& rCutExtraEdgesRatioVector);
443 
454  void ComputeElementalDistancesFromEdgeRatios(
455  Element& rElement,
456  const PointerVector<GeometricalObject>& rIntersectedObjects,
457  const Element::GeometryType::GeometriesArrayType& rEdgesContainer,
458  const array_1d<double,mNumEdges> &rCutEdgesRatioVector,
459  const array_1d<double,mNumEdges> &rCutExtraEdgesRatioVector);
460 
468  void ConvertRatiosToIntersectionPoints(
469  const Element::GeometryType& rGeometry,
470  const Element::GeometryType::GeometriesArrayType& rEdgesContainer,
471  const array_1d<double,mNumEdges> &rEdgeRatiosVector,
472  std::vector<array_1d <double,3> > &rIntersectionPointsVector);
473 
480  double ConvertIntersectionPointToEdgeRatio(
481  const Geometry<Node >& rEdge,
482  const array_1d<double,3>& rIntersectionPoint);
483 
490  array_1d<double,3> ConvertEdgeRatioToIntersectionPoint(
491  const Geometry<Node >& rEdge,
492  const double& rEdgeRatio);
493 
501  bool CheckIfCutEdgesShareNode(
502  const Element& rElement,
503  const Element::GeometryType::GeometriesArrayType& rEdgesContainer,
504  const array_1d<double,mNumEdges>& rCutEdgesRatioVector) const;
505 
516  template<class TVarType>
517  void CalculateEmbeddedVariableFromSkinSpecialization(
518  const Variable<TVarType> &rVariable,
519  const Variable<TVarType> &rEmbeddedVariable)
520  {
521  const auto &r_int_obj_vect= this->GetIntersections();
522  const int n_elems = mrVolumePart.NumberOfElements();
523 
524  KRATOS_ERROR_IF((mrSkinPart.NodesBegin())->SolutionStepsDataHas(rVariable) == false)
525  << "Skin model part solution step data missing variable: " << rVariable << std::endl;
526 
527  // Initialize embedded variable value
528  VariableUtils().SetNonHistoricalVariableToZero(rEmbeddedVariable, mrVolumePart.Elements());
529 
530  // Compute the embedded variable value for each element
531  #pragma omp parallel for schedule(dynamic)
532  for (int i_elem = 0; i_elem < n_elems; ++i_elem) {
533  // Check if the current element has intersecting entities
534  if (r_int_obj_vect[i_elem].size() != 0) {
535  // Initialize the element values
536  unsigned int n_int_edges = 0;
537  auto it_elem = mrVolumePart.ElementsBegin() + i_elem;
538  auto &r_geom = it_elem->GetGeometry();
539  const auto edges = r_geom.GenerateEdges();
540 
541  // Loop the element of interest edges
542  for (unsigned int i_edge = 0; i_edge < r_geom.EdgesNumber(); ++i_edge) {
543  // Initialize edge values
544  unsigned int n_int_obj = 0;
545  TVarType i_edge_val = rEmbeddedVariable.Zero();
546 
547  // Check the edge intersection against all the candidates
548  for (auto &r_int_obj : r_int_obj_vect[i_elem]) {
549  Point intersection_point;
550  const int is_intersected = this->ComputeEdgeIntersection(
551  r_int_obj.GetGeometry(),
552  edges[i_edge][0],
553  edges[i_edge][1],
554  intersection_point);
555 
556  // Compute the variable value in the intersection point
557  if (is_intersected == 1) {
558  n_int_obj++;
559  array_1d<double,3> local_coords;
560  r_int_obj.GetGeometry().PointLocalCoordinates(local_coords, intersection_point);
561  Vector int_obj_N;
562  r_int_obj.GetGeometry().ShapeFunctionsValues(int_obj_N, local_coords);
563  for (unsigned int i_node = 0; i_node < r_int_obj.GetGeometry().PointsNumber(); ++i_node) {
564  i_edge_val += r_int_obj.GetGeometry()[i_node].FastGetSolutionStepValue(rVariable) * int_obj_N[i_node];
565  }
566  }
567  }
568 
569  // Check if the edge is intersected
570  if (n_int_obj != 0) {
571  // Update the element intersected edges counter
572  n_int_edges++;
573  // Add the average edge value (there might exist cases in where
574  // more than one geometry intersects the edge of interest).
575  it_elem->GetValue(rEmbeddedVariable) += i_edge_val / n_int_obj;
576  }
577  }
578 
579  // Average between all the intersected edges
580  if (n_int_edges != 0) {
581  it_elem->GetValue(rEmbeddedVariable) /= n_int_edges;
582  }
583  }
584  }
585  };
586 
594  void SetToSplitFlag(
595  Element& rElement,
596  const double ZeroTolerance);
597 
603  void CheckAndCorrectEdgeDistances();
604 
609  GlobalPointerCommunicator<Element>::Pointer CreatePointerCommunicator();
611 
612 }; // Class CalculateDiscontinuousDistanceToSkinProcess
613 
617 
619 inline std::istream& operator >> (
620  std::istream& rIStream,
622 
624 inline std::ostream& operator << (
625  std::ostream& rOStream,
627 {
628  rThis.PrintInfo(rOStream);
629  rOStream << std::endl;
630  rThis.PrintData(rOStream);
631 
632  return rOStream;
633 }
634 
636 
638 
639 } // namespace Kratos.
640 
641 #endif // KRATOS_CALCULATE_DISCONTINUOUS_DISTANCE_TO_SKIN_PROCESS_H_INCLUDED defined
std::string Info() const override
Turn back information as a string.
Definition: periodic_interface_process.hpp:93
Definition: calculate_discontinuous_distance_to_skin_process.h:42
KRATOS_DEFINE_LOCAL_FLAG(CALCULATE_ELEMENTAL_EDGE_DISTANCES_EXTRAPOLATED)
Local flag to switch on/off the elemental edge distances storage.
KRATOS_DEFINE_LOCAL_FLAG(USE_POSITIVE_EPSILON_FOR_ZERO_VALUES)
Local flag to switch on/off the extrapolated elemental edge distances storage.
KRATOS_DEFINE_LOCAL_FLAG(CALCULATE_ELEMENTAL_EDGE_DISTANCES)
This only calculates the distance. Calculating the inside outside should be done by a derived class o...
Definition: calculate_discontinuous_distance_to_skin_process.h:55
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: calculate_discontinuous_distance_to_skin_process.cpp:211
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: calculate_discontinuous_distance_to_skin_process.cpp:218
Plane3D SetIntersectionPlane(const std::vector< array_1d< double, 3 >> &rIntPtsVector)
Set the Intersection Plane object This method returns the plane that defines the element intersection...
CalculateDiscontinuousDistanceToSkinProcess & operator=(CalculateDiscontinuousDistanceToSkinProcess const &rOther)=delete
Assignment operator.
CalculateDiscontinuousDistanceToSkinProcess(CalculateDiscontinuousDistanceToSkinProcess const &rOther)=delete
Copy constructor.
CalculateDiscontinuousDistanceToSkinProcess()=delete
Default constructor.
FindIntersectedGeometricalObjectsProcess mFindIntersectedObjectsProcess
Definition: calculate_discontinuous_distance_to_skin_process.h:101
KRATOS_CLASS_POINTER_DEFINITION(CalculateDiscontinuousDistanceToSkinProcess)
Pointer definition of CalculateDiscontinuousDistanceToSkinProcess.
Base class for all Elements.
Definition: element.h:60
This class takes two modelparts and marks the intersected ones with SELECTED flag.
Definition: find_intersected_geometrical_objects_process.h:321
Definition: flags.h:58
Geometry base class.
Definition: geometry.h:71
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
ElementIterator ElementsBegin(IndexType ThisIndex=0)
Definition: model_part.h:1169
NodeIterator NodesBegin(IndexType ThisIndex=0)
Definition: model_part.h:487
SizeType NumberOfElements(IndexType ThisIndex=0) const
Definition: model_part.h:1027
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
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
Definition: plane_3d.h:51
Point class.
Definition: point.h:59
PointerVector is a container like stl vector but using a vector to store pointers to its data.
Definition: pointer_vector.h:72
The base class for all processes in Kratos.
Definition: process.h:49
const TDataType & Zero() const
This method returns the zero value of the variable type.
Definition: variable.h:346
This class implements a set of auxiliar, already parallelized, methods to perform some common tasks r...
Definition: variable_utils.h:63
void SetNonHistoricalVariableToZero(const Variable< TType > &rVariable, TContainerType &rContainer)
Sets the nodal value of any variable to zero.
Definition: variable_utils.h:724
#define KRATOS_ERROR_IF(conditional)
Definition: exception.h:162
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432