27 #ifndef OOMPH_QUAD_FROM_TRIANGLE_MESH_TEMPLATE_HEADER
28 #define OOMPH_QUAD_FROM_TRIANGLE_MESH_TEMPLATE_HEADER
43 #ifdef OOMPH_HAS_FPUCONTROLH
44 #include <fpu_control.h>
48 #include "../generic/problem.h"
49 #include "../generic/quad_mesh.h"
51 #include "../generic/triangle_scaffold_mesh.h"
52 #include "../generic/unstructured_two_d_mesh_geometry_base.h"
53 #include "../generic/refineable_quad_mesh.h"
54 #include "../generic/Qelements.h"
69 template<
class ELEMENT>
71 public virtual QuadMeshBase
77 #ifdef OOMPH_HAS_TRIANGLE_LIB
80 this->Allow_automatic_creation_of_vertices_on_boundaries =
true;
84 MeshChecker::assert_geometric_element<QElementGeometricBase, ELEMENT>(2);
89 const std::string& node_file_name,
90 const std::string& element_file_name,
91 const std::string& poly_file_name,
92 TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper,
93 const bool& use_attributes =
false,
94 const bool& allow_automatic_creation_of_vertices_on_boundaries =
true)
97 MeshChecker::assert_geometric_element<QElementGeometricBase, ELEMENT>(2);
100 this->Allow_automatic_creation_of_vertices_on_boundaries =
101 allow_automatic_creation_of_vertices_on_boundaries;
110 TriangleScaffoldMesh* tmp_mesh_pt =
new TriangleScaffoldMesh(
111 node_file_name, element_file_name, poly_file_name);
121 unsigned nbound = nboundary();
122 for (
unsigned ibound = 0; ibound < nbound; ibound++)
124 this->
template setup_boundary_coordinates<ELEMENT>(ibound);
128 #ifdef OOMPH_HAS_TRIANGLE_LIB
135 TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
138 MeshChecker::assert_geometric_element<QElementGeometricBase, ELEMENT>(2);
141 this->Allow_automatic_creation_of_vertices_on_boundaries =
142 triangle_mesh_parameters
156 unsigned max_boundary_id = 0;
163 Vector<TriangleMeshClosedCurve*> outer_boundary_pt =
169 if (outer_boundary_pt.size() == 0)
171 std::stringstream error_message;
173 <<
"There are no outer boundaries defined.\n"
174 <<
"Verify that you have specified the outer boundaries in the\n"
175 <<
"Triangle_mesh_parameter object\n\n";
176 throw OomphLibError(error_message.str(),
177 OOMPH_CURRENT_FUNCTION,
178 OOMPH_EXCEPTION_LOCATION);
184 unsigned n_outer_boundaries = outer_boundary_pt.size();
187 Vector<TriangleMeshPolygon*> outer_boundary_polygon_pt(
191 for (
unsigned i = 0; i < n_outer_boundaries; ++i)
197 outer_boundary_polygon_pt[i] = this->closed_curve_to_polygon_helper(
198 outer_boundary_pt[i], max_boundary_id);
206 Vector<TriangleMeshClosedCurve*> internal_closed_curve_pt =
210 unsigned n_internal_closed_curves = internal_closed_curve_pt.size();
215 Vector<TriangleMeshPolygon*> internal_polygon_pt(
216 n_internal_closed_curves);
219 for (
unsigned i = 0; i < n_internal_closed_curves; ++i)
223 internal_polygon_pt[i] = this->closed_curve_to_polygon_helper(
224 internal_closed_curve_pt[i], max_boundary_id);
232 Vector<TriangleMeshOpenCurve*> internal_open_curve_pt =
236 unsigned n_internal_open_curves = internal_open_curve_pt.size();
239 Vector<TriangleMeshOpenCurve*> internal_open_curve_poly_pt(
240 n_internal_open_curves);
243 for (
unsigned i = 0; i < n_internal_open_curves; i++)
248 internal_open_curve_poly_pt[i] =
249 this->create_open_curve_with_polyline_helper(
250 internal_open_curve_pt[i], max_boundary_id);
260 for (
unsigned i = 0; i < n_outer_boundaries; i++)
262 this->set_geom_objects_and_coordinate_limits_for_close_curve(
263 outer_boundary_pt[i]);
269 for (
unsigned i = 0; i < n_internal_closed_curves; i++)
271 this->set_geom_objects_and_coordinate_limits_for_close_curve(
272 internal_closed_curve_pt[i]);
278 for (
unsigned i = 0; i < n_internal_open_curves; i++)
280 this->set_geom_objects_and_coordinate_limits_for_open_curve(
281 internal_open_curve_pt[i]);
290 const double element_area = triangle_mesh_parameters.
element_area();
293 Vector<Vector<double>> extra_holes_coordinates =
297 std::map<unsigned, Vector<double>> regions =
303 const bool refine_boundary =
306 const bool refine_internal_boundary =
309 if (!refine_internal_boundary && refine_boundary)
311 std::ostringstream error_stream;
313 <<
"You have specified that Triangle may refine the outer boundary, "
315 <<
"not internal boundaries. Triangle does not support this "
317 <<
"If you do not want Triangle to refine internal boundaries, it "
319 <<
"refine outer boundaries either!\n"
320 <<
"Please either disable all boundary refinement\n"
321 <<
"(call TriangleMeshParameters::disable_boundary_refinement()\n"
322 <<
"or enable internal boundary refinement (the default)\n";
324 throw OomphLibError(error_stream.str().c_str(),
325 OOMPH_CURRENT_FUNCTION,
326 OOMPH_EXCEPTION_LOCATION);
330 outer_boundary_polygon_pt,
332 internal_open_curve_poly_pt,
334 extra_holes_coordinates,
340 refine_internal_boundary);
355 unsigned nb = nboundary();
356 for (
unsigned b = 0; b < nb; b++)
358 this->
template setup_boundary_coordinates<ELEMENT>(b);
362 this->snap_nodes_onto_geometric_objects();
369 Vector<TriangleMeshPolygon*>& outer_boundary_pt,
370 Vector<TriangleMeshPolygon*>& internal_polygon_pt,
371 Vector<TriangleMeshOpenCurve*>& open_polylines_pt,
372 const double& element_area,
373 Vector<Vector<double>>& extra_holes_coordinates,
374 std::map<
unsigned, Vector<double>>& regions_coordinates,
375 std::map<unsigned, double>& regions_areas,
376 TimeStepper* time_stepper_pt,
377 const bool& use_attributes,
378 const bool& refine_boundary,
379 const bool& refine_internal_boundary)
383 if (element_area < 10e-14)
385 std::ostringstream warning_message;
387 <<
"The current elements area was stated to (" << element_area
388 <<
").\nThe current precision to generate the input to triangle "
389 <<
"is fixed to 14 digits\n\n";
390 OomphLibWarning(warning_message.str(),
391 OOMPH_CURRENT_FUNCTION,
392 OOMPH_EXCEPTION_LOCATION);
404 this->Outer_boundary_pt = outer_boundary_pt;
407 this->Internal_polygon_pt = internal_polygon_pt;
410 this->Internal_open_curve_pt = open_polylines_pt;
413 this->Extra_holes_coordinates = extra_holes_coordinates;
416 this->Regions_coordinates = regions_coordinates;
419 TriangulateIO triangulate_io;
420 TriangulateIO triangulate_out;
423 TriangleHelper::initialise_triangulateio(triangulate_io);
427 UnstructuredTwoDMeshGeometryBase::build_triangulateio(
431 extra_holes_coordinates,
437 TriangleHelper::initialise_triangulateio(triangulate_out);
440 std::stringstream input_string_stream;
441 input_string_stream.precision(14);
442 input_string_stream.setf(std::ios_base::fixed, std::ios_base::floatfield);
448 input_string_stream <<
"-pA -a -a" << element_area <<
" -q30"
452 if (!this->is_automatic_creation_of_vertices_on_boundaries_allowed())
454 input_string_stream <<
" -YY";
458 if (refine_boundary ==
false)
460 input_string_stream <<
"-Y";
463 if (refine_internal_boundary ==
false)
465 input_string_stream <<
"Y";
470 char triswitches[100];
471 sprintf(triswitches,
"%s", input_string_stream.str().c_str());
474 triangulate(triswitches, &triangulate_io, &triangulate_out, 0);
476 #ifdef OOMPH_HAS_FPUCONTROLH
478 fpu_control_t cw = (_FPU_DEFAULT & ~_FPU_EXTENDED) | _FPU_DOUBLE;
483 TriangleScaffoldMesh* tmp_mesh_pt =
484 new TriangleScaffoldMesh(triangulate_out);
487 if (!regions_coordinates.empty())
507 bool clear_hole_data =
false;
508 TriangleHelper::clear_triangulateio(triangulate_io, clear_hole_data);
509 TriangleHelper::clear_triangulateio(triangulate_out, clear_hole_data);
523 #ifdef OOMPH_HAS_TRIANGLE_LIB
525 std::set<TriangleMeshCurveSection*>::iterator it_polyline;
526 for (it_polyline = Free_curve_section_pt.begin();
527 it_polyline != Free_curve_section_pt.end();
530 delete (*it_polyline);
533 std::set<TriangleMeshPolygon*>::iterator it_polygon;
534 for (it_polygon = Free_polygon_pt.begin();
535 it_polygon != Free_polygon_pt.end();
538 delete (*it_polygon);
541 std::set<TriangleMeshOpenCurve*>::iterator it_open_polyline;
542 for (it_open_polyline = Free_open_curve_pt.begin();
543 it_open_polyline != Free_open_curve_pt.end();
546 delete (*it_open_polyline);
554 TimeStepper* time_stepper_pt,
555 const bool& use_attributes);
574 template<
class ELEMENT>
577 public virtual RefineableQuadMesh<ELEMENT>
580 #ifdef OOMPH_HAS_TRIANGLE_LIB
586 TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
589 this->setup_quadtree_forest();
598 doc_info.directory() =
"";
599 doc_info.disable_doc();
600 refine_uniformly(doc_info);
607 unsigned nelem = this->nelement();
610 Vector<double> elem_error(nelem, DBL_MAX);
618 void adapt(
const Vector<double>& elem_error);
622 const std::string& node_file_name,
623 const std::string& element_file_name,
624 const std::string& poly_file_name,
625 TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
627 node_file_name, element_file_name, poly_file_name, time_stepper_pt)
629 this->setup_quadtree_forest();
645 template<
class ELEMENT>
648 public virtual SolidMesh
652 const std::string& node_file_name,
653 const std::string& element_file_name,
654 const std::string& poly_file_name,
655 TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper,
656 const bool& use_attributes =
false)
664 set_lagrangian_nodal_coordinates();
667 #ifdef OOMPH_HAS_TRIANGLE_LIB
674 TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
678 set_lagrangian_nodal_coordinates();
696 template<
class ELEMENT>
699 public virtual SolidMesh
705 const std::string& node_file_name,
706 const std::string& element_file_name,
707 const std::string& poly_file_name,
708 TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper,
709 const bool& use_attributes =
false)
717 set_lagrangian_nodal_coordinates();
720 #ifdef OOMPH_HAS_TRIANGLE_LIB
726 TimeStepper* time_stepper_pt = &Mesh::Default_TimeStepper)
733 set_lagrangian_nodal_coordinates();
Quad mesh built on top of triangle scaffold mesh coming from the triangle mesh generator Triangle....
void generic_constructor(Vector< TriangleMeshPolygon * > &outer_boundary_pt, Vector< TriangleMeshPolygon * > &internal_polygon_pt, Vector< TriangleMeshOpenCurve * > &open_polylines_pt, const double &element_area, Vector< Vector< double >> &extra_holes_coordinates, std::map< unsigned, Vector< double >> ®ions_coordinates, std::map< unsigned, double > ®ions_areas, TimeStepper *time_stepper_pt, const bool &use_attributes, const bool &refine_boundary, const bool &refine_internal_boundary)
A general-purpose construction function that builds the mesh once the different specific constructors...
TimeStepper * Time_stepper_pt
Timestepper used to build elements.
QuadFromTriangleMesh(TriangleMeshParameters &triangle_mesh_parameters, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Build mesh, based on the specifications on TriangleMeshParameters. All the actual work is done in Uns...
void operator=(const QuadFromTriangleMesh &)=delete
Broken assignment operator.
~QuadFromTriangleMesh()
Empty destructor.
QuadFromTriangleMesh(const std::string &node_file_name, const std::string &element_file_name, const std::string &poly_file_name, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper, const bool &use_attributes=false, const bool &allow_automatic_creation_of_vertices_on_boundaries=true)
Constructor with the input files.
bool Use_attributes
Boolean flag to indicate whether to use attributes or not (required for multidomain meshes)
void build_from_scaffold(TriangleScaffoldMesh *tmp_mesh_pt, TimeStepper *time_stepper_pt, const bool &use_attributes)
Build the quad mesh from the given scaffold mesh.
QuadFromTriangleMesh(const QuadFromTriangleMesh &dummy)=delete
Broken copy constructor.
QuadFromTriangleMesh()
Empty constructor.
///////////////////////////////////////////////////////////////// ///////////////////////////////////...
virtual void refine_uniformly()
Refine mesh uniformly.
RefineableQuadFromTriangleMesh(TriangleMeshParameters &triangle_mesh_parameters, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Build mesh, based on the specifications on TriangleMeshParameters.
RefineableQuadFromTriangleMesh(const std::string &node_file_name, const std::string &element_file_name, const std::string &poly_file_name, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Build mesh, based on the polyfiles.
virtual ~RefineableQuadFromTriangleMesh()
Empty Destructor.
void refine_uniformly(DocInfo &doc_info)
Refine mesh uniformly and doc process.
///////////////////////////////////////////////////////////////////// ///////////////////////////////...
virtual ~RefineableSolidQuadFromTriangleMesh()
Empty Destructor.
RefineableSolidQuadFromTriangleMesh(TriangleMeshParameters &triangle_mesh_parameters, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Build mesh, based on the specifications on TriangleMeshParameter.
RefineableSolidQuadFromTriangleMesh(const std::string &node_file_name, const std::string &element_file_name, const std::string &poly_file_name, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper, const bool &use_attributes=false)
Build mesh from specified triangulation and associated target areas for elements in it.
///////////////////////////////////////////////////////////////// ///////////////////////////////////...
SolidQuadFromTriangleMesh(TriangleMeshParameters &triangle_mesh_parameters, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Build mesh, based on closed curve that specifies the outer boundary of the domain and any number of i...
SolidQuadFromTriangleMesh(const std::string &node_file_name, const std::string &element_file_name, const std::string &poly_file_name, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper, const bool &use_attributes=false)
virtual ~SolidQuadFromTriangleMesh()
Empty Destructor.
///////////////////////////////////////////////////////////////////// ///////////////////////////////...
Vector< TriangleMeshClosedCurve * > internal_closed_curve_pt() const
Helper function for getting the internal closed boundaries.
bool is_automatic_creation_of_vertices_on_boundaries_allowed()
Returns the status of the variable Allow_automatic_creation_of_vertices_on_boundaries.
Vector< Vector< double > > extra_holes_coordinates() const
Helper function for getting the extra holes.
std::map< unsigned, double > & target_area_for_region()
Helper function for getting access to the region's target areas.
bool is_mesh_distributed() const
Boolean to indicate if Mesh has been distributed.
bool is_use_attributes() const
Helper function for getting the status of use_attributes variable.
Vector< TriangleMeshClosedCurve * > outer_boundary_pt() const
Helper function for getting the outer boundary.
OomphCommunicator * communicator_pt() const
Read-only access fct to communicator (Null if mesh is not distributed)
double element_area() const
Helper function for getting the element area.
Vector< TriangleMeshOpenCurve * > internal_open_curves_pt() const
Helper function for getting the internal open boundaries.
std::map< unsigned, Vector< double > > & regions_coordinates()
Helper function for getting access to the regions coordinates.
bool is_boundary_refinement_allowed() const
Helper function for getting the status of boundary refinement.
bool is_internal_boundary_refinement_allowed() const
Helper function for getting the status of boundary refinement.
////////////////////////////////////////////////////////////////////// //////////////////////////////...
void triangulate(char *triswitches, struct oomph::TriangulateIO *in, struct oomph::TriangulateIO *out, struct oomph::TriangulateIO *vorout)