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.
trigen_cdt.h
Go to the documentation of this file.
1 //
2 // Project Name: Kratos
3 // Last Modified by: $Author: rrossi $
4 // Date: $Date: 2008-02-25 19:05:54 $
5 // Revision: $Revision: 1.1 $
6 //
7 //
8 
9 
10 #if !defined(KRATOS_TRIGEN_CDT_H_INCLUDED )
11 #define KRATOS_TRIGEN_CDT_H_INCLUDED
12 
13 
14 
15 // System includes
16 #include <string>
17 #include <iostream>
18 #include <cstdlib>
19 
20 // External includes
21 #include "triangle.h"
22 
23 // Project includes
24 #include "includes/define.h"
25 #include "includes/model_part.h"
28 
29 
30 
31 
32 namespace Kratos
33 {
34 extern "C" {
35  void triangulate(char *, struct triangulateio *, struct triangulateio *,struct triangulateio *);
36  //void trifree();
37 }
38 
39 
42 
46 
50 
54 
58 
60 
62 class TriGenCDT
63 {
64 public:
67 
70 
74 
76  TriGenCDT() = default; //
77 
79  virtual ~TriGenCDT() = default;
80 
81 
85 
86 
90 
91 
92  //*******************************************************************************************
93  //*******************************************************************************************
95  ModelPart& ThisModelPart ,
96  Element const& rReferenceElement
97  )
98  {
99 
100  KRATOS_TRY
101 
102 
103  struct triangulateio in;
104  struct triangulateio mid;
105  struct triangulateio out;
106  struct triangulateio vorout;
107 
108  clean_triangulateio(in);
109  clean_triangulateio(mid);
110  clean_triangulateio(out);
111  clean_triangulateio(vorout);
112 
113  //*********************************************************************
114  //input mesh
115  in.numberofpoints = ThisModelPart.Nodes().size();
116  in.pointlist = (REAL *) malloc(in.numberofpoints * 2 * sizeof(REAL));
117  //writing the points coordinates in a vector
118  ModelPart::NodesContainerType::iterator nodes_begin = ThisModelPart.NodesBegin();
119  for(unsigned int i = 0; i<ThisModelPart.Nodes().size(); i++)
120  {
121  int base = i*2;
122  //int base = ((nodes_begin + i)->Id() - 1 ) * 2;
123 
124  //from now on it is consecutive
125  (nodes_begin + i)->SetId(i+1);
126 // (nodes_begin + i)->Id() = i+1;
127 
128  in.pointlist[base] = (nodes_begin + i)->X();
129  in.pointlist[base+1] = (nodes_begin + i)->Y();
130  }
131 
132  in.numberoftriangles = ThisModelPart.Elements().size();
133  in.trianglelist = (int*) malloc(in.numberoftriangles * 3 * sizeof(int));
134  //copying the elements in the input file
135  ModelPart::ElementsContainerType::iterator elem_begin = ThisModelPart.ElementsBegin();
136  for(unsigned int el = 0; el<ThisModelPart.Elements().size(); el++)
137  {
138  int base = el * 3;
139 
140  Geometry<Node >& geom = (elem_begin+el)->GetGeometry();
141 
142 
143  in.trianglelist[base] = geom[0].Id();
144  in.trianglelist[base+1] = geom[1].Id();
145  in.trianglelist[base+2] = geom[2].Id();
146  }
147 
148  //clearing elements
149  ThisModelPart.Elements().clear();
150 
151  KRATOS_WATCH(in.numberofsegments);
152  KRATOS_WATCH(in.numberofpoints);
153  KRATOS_WATCH(in.numberoftriangles);
154  KRATOS_WATCH(in.numberofholes);
155 
156  //read and regenerate the existing mesh ... to generate the boundaries
157  char options[] = "rcEBQ";
158  triangulate(options, &in, &mid, &vorout);
159 
160  //free the memory used in the first step
161  free( in.pointlist );
162  free( in.trianglelist );
163 
164  //uses the boundary list generated at the previous step to generate the "skin"
165  mid.numberoftriangles = 0;
166  free(mid.trianglelist);
167  char regeneration_option[] = "pBQY";
168  triangulate(regeneration_option, &mid, &out, &vorout);
169 
170  KRATOS_WATCH(out.numberofsegments);
171  KRATOS_WATCH(out.numberofpoints);
172  KRATOS_WATCH(out.numberoftriangles);
173  KRATOS_WATCH(out.numberofholes);
174 
175  //free the memory used in the intermediate step
176  free( mid.pointlist );
177  free( mid.segmentlist );
178 
179  //*******************************************************************
180  //properties to be used in the generation
181  Properties::Pointer properties = ThisModelPart.GetMesh().pGetProperties(1);
182 
183  //generate Kratos triangle
184  int el_number = out.numberoftriangles;
185 
186  //note that the node list can not be changed starting from here
187  ModelPart::NodesContainerType& ModelNodes = ThisModelPart.Nodes();
188 
189  //generate kratos elements (conditions are not touched)
190  for(int el = 0; el< el_number; el++)
191  {
192  int id = el + 1;
193  int base = el * 3;
194 
196  temp.push_back( *((ModelNodes).find( out.trianglelist[base]).base() ) );
197  temp.push_back( *((ModelNodes).find( out.trianglelist[base+1]).base() ) );
198  temp.push_back( *((ModelNodes).find( out.trianglelist[base+2]).base() ) );
199 
200  Element::Pointer p_element = rReferenceElement.Create(id, temp, properties);
201  ThisModelPart.Elements().push_back(p_element);
202  }
203 
204 
205  /* free( in.pointmarkerlist);
206  free( in.pointmarkerlist );
207  free( in.regionlist );*/
208 
209 
210 
211  free( out.pointattributelist );
212  free( out.trianglelist );
213 // free( out.triangleattributelist );
214 // free( out.neighborlist );
215 
216 
217  KRATOS_CATCH("")
218  }
219 
220 
221 
225 
226 
230 
231 
235 
237  virtual std::string Info() const
238  {
239  return "";
240  }
241 
243  virtual void PrintInfo(std::ostream& rOStream) const {}
244 
246  virtual void PrintData(std::ostream& rOStream) const {}
247 
248 
252 
253 
255 
256 protected:
259 
260 
264 
265 
269 
270 
274 
275 
279 
280 
284 
285 
289 
290 
292 
293 private:
296 
297 
301  void clean_triangulateio( triangulateio& tr )
302  {
303 
304  tr.pointlist = (REAL*) nullptr;
305  tr.pointattributelist = (REAL*) nullptr;
306  tr.pointmarkerlist = (int*) nullptr;
307  tr.numberofpoints = 0;
308  tr.numberofpointattributes = 0;
309  tr.trianglelist = (int*) nullptr;
310  tr.triangleattributelist = (REAL*) nullptr;
311  tr.trianglearealist = (REAL*) nullptr;
312  tr.neighborlist = (int*) nullptr;
313  tr.numberoftriangles = 0;
314  tr.numberofcorners = 3;
315  tr.numberoftriangleattributes = 0;
316  tr.segmentlist = (int*) nullptr;
317  tr.segmentmarkerlist = (int*) nullptr;
318  tr.numberofsegments = 0;
319  tr.holelist = (REAL*) nullptr;
320  tr.numberofholes = 0;
321  tr.regionlist = (REAL*) nullptr;
322  tr.numberofregions = 0;
323  tr.edgelist = (int*) nullptr;
324  tr.edgemarkerlist = (int*) nullptr;
325  tr.normlist = (REAL*) nullptr;
326  tr.numberofedges = 0;
327 
328  };
329 
330 
334 
338 
339 
343 
344 
348 
349 
353 
355  TriGenCDT& operator=(TriGenCDT const& rOther);
356 
357 
359 
360 }; // Class TriGenCDT
361 
363 
366 
367 
371 
372 
374 inline std::istream& operator >> (std::istream& rIStream,
375  TriGenCDT& rThis);
376 
378 inline std::ostream& operator << (std::ostream& rOStream,
379  const TriGenCDT& rThis)
380 {
381  rThis.PrintInfo(rOStream);
382  rOStream << std::endl;
383  rThis.PrintData(rOStream);
384 
385  return rOStream;
386 }
388 
389 
390 } // namespace Kratos.
391 
392 #endif // KRATOS_TRIGEN_CDT_H_INCLUDED defined
393 
394 
PeriodicInterfaceProcess & operator=(const PeriodicInterfaceProcess &)=delete
Base class for all Elements.
Definition: element.h:60
virtual Pointer Create(IndexType NewId, NodesArrayType const &ThisNodes, PropertiesType::Pointer pProperties) const
It creates a new element pointer.
Definition: element.h:202
Geometry base class.
Definition: geometry.h:71
IndexType const & Id() const
Id of this Geometry.
Definition: geometry.h:964
PropertiesType::Pointer pGetProperties(IndexType PropertiesId)
Definition: mesh.h:394
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
ElementsContainerType & Elements(IndexType ThisIndex=0)
Definition: model_part.h:1189
MeshType::NodesContainerType NodesContainerType
Nodes container. Which is a vector set of nodes with their Id's as key.
Definition: model_part.h:128
MeshType & GetMesh(IndexType ThisIndex=0)
Definition: model_part.h:1791
NodesContainerType & Nodes(IndexType ThisIndex=0)
Definition: model_part.h:507
Short class definition.
Definition: trigen_cdt.h:63
virtual std::string Info() const
Turn back information as a string.
Definition: trigen_cdt.h:237
KRATOS_CLASS_POINTER_DEFINITION(TriGenCDT)
Pointer definition of TriGenCDT.
virtual void PrintInfo(std::ostream &rOStream) const
Print information about this object.
Definition: trigen_cdt.h:243
TriGenCDT()=default
Default constructor.
virtual ~TriGenCDT()=default
Destructor.
virtual void PrintData(std::ostream &rOStream) const
Print object's data.
Definition: trigen_cdt.h:246
void GenerateCDT(ModelPart &ThisModelPart, Element const &rReferenceElement)
Definition: trigen_cdt.h:94
#define KRATOS_CATCH(MoreInfo)
Definition: define.h:110
#define KRATOS_WATCH(variable)
Definition: define.h:806
#define KRATOS_TRY
Definition: define.h:109
#define REAL
Definition: delaunator_utilities.cpp:16
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
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
el
Definition: read_stl.py:25
float temp
Definition: rotating_cone.py:85
integer i
Definition: TensorModule.f:17