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.
triangular_mesh_2D_mesher.hpp
Go to the documentation of this file.
1 //
2 // Project Name: KratosDelaunayMeshingApplication $
3 // Created by: $Author: JMCarbonell $
4 // Last modified by: $Co-Author: $
5 // Date: $Date: April 2018 $
6 // Revision: $Revision: 0.0 $
7 //
8 //
9 
10 #if !defined(KRATOS_TRIANGULAR_MESH_2D_MESHER_H_INCLUDED )
11 #define KRATOS_TRIANGULAR_MESH_2D_MESHER_H_INCLUDED
12 
13 // If SINGLE is defined when triangle.o is compiled, it should also be defined here
14 // If SINGLE is NOT defined in compilation, it should not be defined here.
15 // #define SINGLE
16 
17 #ifdef SINGLE
18 #define REAL float
19 #else // not SINGLE
20 #define REAL double
21 #endif // not SINGLE
22 
23 // External includes
24 #ifndef TRILIBRARY
25 #define TRILIBRARY
26 #endif
27 
28 #include "triangle.h"
29 
30 // System includes
31 
32 // Project includes
35 
37 //Data:
38 //StepData:
39 //Flags: (checked)
40 // (set)
41 // (modified)
42 // (reset)
43 
44 
45 namespace Kratos
46 {
47 
48  extern "C" {
49  void triangulate(char *, struct triangulateio *, struct triangulateio *,struct triangulateio *);
50  void trifree(void *);
51  }
52 
53 
56 
60 
64 
68 
72 
74 
76 class KRATOS_API(DELAUNAY_MESHING_APPLICATION) TriangularMesh2DMesher
77  : public Mesher
78 {
79 protected:
80 
81  enum TriangleErrors {INPUT_MEMORY_ERROR=1, INTERNAL_ERROR=2, INVALID_GEOMETRY_ERROR=3};
82 
83 public:
84 
87 
90 
94 
98 
101 
104 
107 
111 
112 
116 
117 
118 
122 
123 
127 
128 
132 
134  std::string Info() const override
135  {
136  return "";
137  }
138 
140  void PrintInfo(std::ostream& rOStream) const override{}
141 
143  void PrintData(std::ostream& rOStream) const override{}
144 
145 
149 
150 
152 
153 protected:
156 
157 
161 
162 
166 
167 
171 
172 
173  //generate :: meshing step call to delaunay tessellation
174  void Generate(ModelPart& rModelPart, MeshingParametersType& rMeshingVariables) override;
175 
176  //generate the Delaunay Tesselation
177  int GenerateTessellation(MeshingParametersType& rMeshingVariables, struct triangulateio& in, struct triangulateio& out);
178 
179 
183 
184 
188 
189 
193 
194 
196 
197 private:
200 
201 
205 
206 
210 
213 
217 
218  //build the input for the mesher
219  void BuildInput ( ModelPart &rModelPart, MeshingParametersType & rMeshingVariables, struct triangulateio &in);
220 
221  //set and get from mesh container in meshing variables
222  void GetFromContainer(MesherUtilities::MeshContainer& rMesh, struct triangulateio& tr);
223 
224  void SetToContainer(MesherUtilities::MeshContainer& rMesh, struct triangulateio& tr);
225 
226 
227  //delete in/out structures
228  void DeleteInContainer(MesherUtilities::MeshContainer& rMesh, struct triangulateio& tr);
229 
230  void DeleteOutContainer(MesherUtilities::MeshContainer& rMesh, struct triangulateio& tr);
231 
232 
233  //set faces in the triangulateio before the Delaunay Tesselation
234  virtual void SetFaces ( ModelPart &rModelPart, MeshingParametersType & rMeshingVariables, struct triangulateio &in );
235 
236 
237  //print methods
238  void WriteTriangles ( struct triangulateio& tr );
239 
240  void WritePoints ( struct triangulateio& tr );
241 
242 
243  //free memory of the mesher
244  void ClearTrianglesList ( struct triangulateio& tr );
245 
246  void DeleteTrianglesList ( struct triangulateio& tr );
247 
248  void DeletePointsList ( struct triangulateio& tr );
249 
253 
254 
258 
259 
263 
265 
266 }; // Class TriangularMesh2DMesher
267 
269 
272 
273 
277 
278 
280  inline std::istream& operator >> (std::istream& rIStream,
281  TriangularMesh2DMesher& rThis);
282 
284  inline std::ostream& operator << (std::ostream& rOStream,
285  const TriangularMesh2DMesher& rThis)
286  {
287  rThis.PrintInfo(rOStream);
288  rOStream << std::endl;
289  rThis.PrintData(rOStream);
290 
291  return rOStream;
292  }
294 
295 
296 } // namespace Kratos.
297 
298 #endif // KRATOS_TRIANGULAR_MESH_2D_MESHER_H_INCLUDED defined
299 
300 
301 
302 
303 //************************************************************************************
304 // Command line switches for TRIANGLE:
305 
306 // To run Triangle, the command line syntax is
307 
308 // For some of the command line switches described below, you may click on the switch for detailed information.
309 // -p Triangulates a Planar Straight Line Graph (.poly file).
310 // -r Refines a previously generated mesh.
311 // -q Quality mesh generation with no angles smaller than 20 degrees. An alternate minimum angle may be specified after the `q'.
312 // -a Imposes a maximum triangle area constraint. A fixed area constraint (that applies to every triangle) may be specified after the `a', or varying area constraints may be read from a .poly file or .area file.
313 // -u Imposes a user-defined constraint on triangle size.
314 // -A Assigns a regional attribute to each triangle that identifies what segment-bounded region it belongs to.
315 // -c Encloses the convex hull with segments.
316 // -D Conforming Delaunay: use this switch if you want all triangles in the mesh to be Delaunay, and not just constrained Delaunay; or if you want to ensure that all Voronoi vertices lie within the triangulation.
317 // -j Jettisons vertices that are not part of the final triangulation from the output .node file (including duplicate input vertices and vertices ``eaten'' by holes).
318 // -e Outputs (to an .edge file) a list of edges of the triangulation.
319 // -v Outputs the Voronoi diagram associated with the triangulation. Does not attempt to detect degeneracies, so some Voronoi vertices may be duplicated.
320 // -n Outputs (to a .neigh file) a list of triangles neighboring each triangle.
321 // -g Outputs the mesh to an Object File Format (.off) file, suitable for viewing with the Geometry Center's Geomview package.
322 // -B Suppresses boundary markers in the output .node, .poly, and .edge output files.
323 // -P Suppresses the output .poly file. Saves disk space, but you lose the ability to maintain constraining segments on later refinements of the mesh.
324 // -N Suppresses the output .node file.
325 // -E Suppresses the output .ele file.
326 // -I Suppresses mesh iteration numbers.
327 // -O Suppresses holes: ignores the holes in the .poly file.
328 // -X Suppresses exact arithmetic.
329 // -z Numbers all items starting from zero (rather than one). Note that this switch is normally overrided by the value used to number the first vertex of the input .node or .poly file. However, this switch is useful when calling Triangle from another program.
330 // -o2 Generates second-order subparametric elements with six nodes each.
331 // -Y Prohibits the insertion of Steiner points on the mesh boundary. If specified twice (-YY), it prohibits the insertion of Steiner points on any segment, including internal segments.
332 // -S Specifies the maximum number of added Steiner points.
333 // -i Uses the incremental algorithm for Delaunay triangulation, rather than the divide-and-conquer algorithm.
334 // -F Uses Steven Fortune's sweepline algorithm for Delaunay triangulation, rather than the divide-and-conquer algorithm.
335 // -l Uses only vertical cuts in the divide-and-conquer algorithm. By default, Triangle uses alternating vertical and horizontal cuts, which usually improve the speed except with vertex sets that are small or short and wide. This switch is primarily of theoretical interest.
336 // -s Specifies that segments should be forced into the triangulation by recursively splitting them at their midpoints, rather than by generating a constrained Delaunay triangulation. Segment splitting is true to Ruppert's original algorithm, but can create needlessly small triangles. This switch is primarily of theoretical interest.
337 // -C Check the consistency of the final mesh. Uses exact arithmetic for checking, even if the -X switch is used. Useful if you suspect Triangle is buggy.
338 // -Q Quiet: Suppresses all explanation of what Triangle is doing, unless an error occurs.
339 // -V Verbose: Gives detailed information about what Triangle is doing. Add more `V's for increasing amount of detail. `-V' gives information on algorithmic progress and detailed statistics.
340 // -h Help: Displays complete instructions.
PeriodicInterfaceProcess & operator=(const PeriodicInterfaceProcess &)=delete
Short class definition.
Definition: mesher.hpp:60
This class aims to manage meshes for multi-physics simulations.
Definition: model_part.h:77
Short class definition.
Definition: triangular_mesh_2D_mesher.hpp:78
KRATOS_CLASS_POINTER_DEFINITION(TriangularMesh2DMesher)
Pointer definition of TriGenCDT.
TriangularMesh2DMesher(TriangularMesh2DMesher const &rOther)
Copy constructor.
Definition: triangular_mesh_2D_mesher.hpp:103
MesherUtilities::MeshingParameters MeshingParametersType
Definition: triangular_mesh_2D_mesher.hpp:92
void PrintInfo(std::ostream &rOStream) const override
Print information about this object.
Definition: triangular_mesh_2D_mesher.hpp:140
TriangleErrors
Definition: triangular_mesh_2D_mesher.hpp:81
void PrintData(std::ostream &rOStream) const override
Print object's data.
Definition: triangular_mesh_2D_mesher.hpp:143
TriangularMesh2DMesher()
Default constructor.
Definition: triangular_mesh_2D_mesher.hpp:100
virtual ~TriangularMesh2DMesher()
Destructor.
Definition: triangular_mesh_2D_mesher.hpp:106
std::string Info() const override
Turn back information as a string.
Definition: triangular_mesh_2D_mesher.hpp:134
MesherUtilities::RefiningParameters RefineParametersType
Definition: triangular_mesh_2D_mesher.hpp:93
MesherUtilities::MeshingInfoParameters InfoParametersType
Definition: triangular_mesh_2D_mesher.hpp:91
REF: G. R. Cowper, GAUSSIAN QUADRATURE FORMULAS FOR TRIANGLES.
Definition: mesh_condition.cpp:21
void trifree(void *)
std::istream & operator>>(std::istream &rIStream, LinearMasterSlaveConstraint &rThis)
input stream function
void triangulate(char *, struct triangulateio *, struct triangulateio *, struct triangulateio *)
std::ostream & operator<<(std::ostream &rOStream, const LinearMasterSlaveConstraint &rThis)
output stream function
Definition: linear_master_slave_constraint.h:432
out
Definition: isotropic_damage_automatic_differentiation.py:200
Definition: mesher_utilities.hpp:149
Definition: mesher_utilities.hpp:269
Definition: mesher_utilities.hpp:631
Definition: mesher_utilities.hpp:479