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 // KratosShapeOptimizationApplication
3 //
4 // License: BSD License
5 // license: ShapeOptimizationApplication/license.txt
6 //
7 // Main authors: Baumgaertner Daniel, https://github.com/dbaumgaertner
8 //
9 // ==============================================================================
10 
11 #ifndef GEOMETRY_UTILITIES_H
12 #define GEOMETRY_UTILITIES_H
13 
14 // ------------------------------------------------------------------------------
15 // System includes
16 // ------------------------------------------------------------------------------
17 #include <iostream>
18 #include <string>
19 
20 // ------------------------------------------------------------------------------
21 // Project includes
22 // ------------------------------------------------------------------------------
23 #include "includes/define.h"
24 #include "includes/model_part.h"
27 
28 // ==============================================================================
29 
30 namespace Kratos
31 {
32 
35 
39 
40 
44 
48 
52 
54 
58 class KRATOS_API(SHAPE_OPTIMIZATION_APPLICATION) GeometryUtilities
59 {
60 public:
63 
64  // For better reading
68  typedef std::size_t SizeType;
69  using NodeType = Node;
70 
73 
77 
80  : mrModelPart( modelPart )
81  {
82  }
83 
86  {
87  }
88 
89 
93 
94 
98 
99  void CalculateNodalAreasFromConditions();
100 
101  void ComputeUnitSurfaceNormals();
102 
103  void ProjectNodalVariableOnUnitSurfaceNormals( const Variable<array_3d> &rNodalVariable );
104 
105  void ProjectNodalVariableOnDirection( const Variable<array_3d> &rNodalVariable, const Variable<array_3d> &rDirectionVariable);
106 
107  void ProjectNodalVariableOnTangentPlane( const Variable<array_3d> &rNodalVariable, const Variable<array_3d> &rPlaneNormalVariable);
108 
109  void ExtractBoundaryNodes( std::string const& rBoundarySubModelPartName );
110 
111  void ExtractEdgeNodes( std::string const& rEdgeSubModelPartName );
112 
113  std::tuple<std::vector<double>, std::vector<double>> ComputeDistancesToBoundingModelPart(ModelPart& rBoundingModelPart);
114 
115  template <class TContainerType>
116  double CalculateLength(TContainerType& rContainer)
117  {
118  double length = block_for_each<SumReduction<double>>(rContainer, [&](typename TContainerType::value_type& rEntity){
119  return rEntity.GetGeometry().Length();
120  });
121 
122  return length;
123  }
124 
125  double ComputeVolume();
126 
127  void ComputeVolumeShapeDerivatives(const Variable<array_3d>& rDerivativeVariable);
128 
129  // Computes the gaussian curvature at all surface nodes depending on the surrounding elements
130  // (I) Quadratic Elements: Curvature tensor by shape functions
131  // (II) Linear Quadrangle: Taubin http://graphics.stanford.edu/courses/cs348a-17-winter/ReaderNotes/taubin-iccv95b.pdf
132  // Camprubi Estebo https://mediatum.ub.tum.de/doc/601055/00000039.pdf
133  // (III) Linear Triangle: Meyer https://authors.library.caltech.edu/99186/2/diffGeoOps.pdf
134  void CalculateGaussianCurvature();
135 
136  // Computes the gaussian curvature at a surface node from the curvature tensor.
137  // For quadratic elements (e.g. 6NTriangle).
138  double GaussianCurvatureForNodeFromTensor(const NodeType &rNode);
139 
140  // Computes the gaussian curvature at a surface node according to Taubin.
141  // For 4NQuads, variable naming according to Camprubi Estebo.
142  double GaussianCurvatureForNodeTaubin(const NodeType &rNode);
143 
144  // Computes the gaussian curvature at a surface node according to Meyer.
145  // For 3NTriangles.
146  double GaussianCurvatureForNodeMeyer(const NodeType &rNode);
147 
148  // Selects the curvature technique according to the surrounding elements
149  // Precedence: (I) > (II) > (III)
150  std::string GetCurvatureTechnique(const NodeType &rNode);
151 
152  bool CheckIfElementIsQuadratic(const Kratos::GlobalPointer<Kratos::Condition> pElement);
153 
154  bool CheckIfNodesHasQuadraticNeigbourElement(const NodeType &rNode);
155 
156  void LocalPointInElement(const NodeType& rNode, const Kratos::GlobalPointer<Kratos::Condition> pElement, Kratos::Point::CoordinatesArrayType& rLocalPoint);
157 
158  Matrix CurvatureTensor(const NodeType& rNode, const Kratos::GlobalPointer<Kratos::Condition> pElement);
159 
160  void BaseVectors(const NodeType& rNode, const Kratos::GlobalPointer<Kratos::Condition> pElement, Vector& rG1, Vector& rG2);
161 
162  void CartesianBaseVectors(const NodeType& rNode, const Kratos::GlobalPointer<Kratos::Condition> pElement, Vector& rE1, Vector& rE2);
163 
164  void TransformTensorCoefficients(Matrix& rTensor, Matrix& rResultTensor, Vector&rG1, Vector&rG2, Vector&rE1, Vector&rE2);
165 
166  void InnerAngleAndMixedAreaOf3D3NTriangletAtNode(const NodeType& rNode, const Kratos::GlobalPointer<Kratos::Condition> pElement, double& rInnerAngle, double& rMixedArea);
167 
168  // --------------------------------------------------------------------------
169 
173 
174 
178 
179 
183 
185  virtual std::string Info() const
186  {
187  return "GeometryUtilities";
188  }
189 
191  virtual void PrintInfo(std::ostream& rOStream) const
192  {
193  rOStream << "GeometryUtilities";
194  }
195 
197  virtual void PrintData(std::ostream& rOStream) const
198  {
199  }
200 
201 
205 
206 
208 
209 protected:
212 
213 
217 
218 
222 
223 
227 
228 
232 
233 
237 
238 
242 
243 
245 
246 private:
249 
250 
254 
255  ModelPart& mrModelPart;
256 
260 
261 
265 
266  // --------------------------------------------------------------------------
267  void CalculateAreaNormalsFromConditions();
268 
269  // --------------------------------------------------------------------------
270  void CalculateUnitNormals();
271 
272  // --------------------------------------------------------------------------
273 
274 
278 
279 
283 
284 
288 
290 // GeometryUtilities& operator=(GeometryUtilities const& rOther);
291 
293 // GeometryUtilities(GeometryUtilities const& rOther);
294 
295 
297 
298 }; // Class GeometryUtilities
299 
301 
304 
305 
309 
311 
312 
313 } // namespace Kratos.
314 
315 #endif // GEOMETRY_UTILITIES_H
Geometry base class.
Definition: geometry.h:71
Short class definition.
Definition: geometry_utilities.h:59
std::size_t SizeType
Definition: geometry_utilities.h:68
ModelPart::ElementType::GeometryType GeometryType
Definition: geometry_utilities.h:67
ModelPart::ConditionsContainerType ConditionsArrayType
Definition: geometry_utilities.h:66
KRATOS_CLASS_POINTER_DEFINITION(GeometryUtilities)
Pointer definition of GeometryUtilities.
GeometryUtilities(ModelPart &modelPart)
Default constructor.
Definition: geometry_utilities.h:79
virtual std::string Info() const
Turn back information as a string.
Definition: geometry_utilities.h:185
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: geometry_utilities.h:191
array_1d< double, 3 > array_3d
Definition: geometry_utilities.h:65
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: geometry_utilities.h:197
virtual ~GeometryUtilities()
Destructor.
Definition: geometry_utilities.h:85
double CalculateLength(TContainerType &rContainer)
Definition: geometry_utilities.h:116
This class is a wrapper for a pointer to a data that is located in a different rank.
Definition: global_pointer.h:44
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
This class defines the node.
Definition: node.h:65
A sorted associative container similar to an STL set, but uses a vector to store pointers to its data...
Definition: pointer_vector_set.h:72
Variable class contains all information needed to store and retrive data from a data container.
Definition: variable.h:63
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21