29 #ifndef OOMPH_QUAD_FROM_TRIANGLE_MESH_TEMPLATE_HEADER 30 #define OOMPH_QUAD_FROM_TRIANGLE_MESH_TEMPLATE_HEADER 46 #include "../generic/problem.h" 47 #include "../generic/quad_mesh.h" 49 #include "../generic/triangle_scaffold_mesh.h" 50 #include "../generic/unstructured_two_d_mesh_geometry_base.h" 51 #include "../generic/refineable_quad_mesh.h" 52 #include "../generic/Qelements.h" 55 using namespace oomph;
71 template <
class ELEMENT>
73 public virtual QuadMeshBase
81 #ifdef OOMPH_HAS_TRIANGLE_LIB 84 this->Allow_automatic_creation_of_vertices_on_boundaries=
true;
88 MeshChecker::assert_geometric_element<QElementGeometricBase,ELEMENT>(2);
93 const std::string& element_file_name,
94 const std::string& poly_file_name,
95 TimeStepper* time_stepper_pt=&Mesh::Default_TimeStepper,
96 const bool &use_attributes=
false,
98 allow_automatic_creation_of_vertices_on_boundaries=
true)
101 MeshChecker::assert_geometric_element<QElementGeometricBase,ELEMENT>(2);
104 this->Allow_automatic_creation_of_vertices_on_boundaries=
105 allow_automatic_creation_of_vertices_on_boundaries;
108 this->Time_stepper_pt=time_stepper_pt;
111 this->Use_attributes=use_attributes;
114 TriangleScaffoldMesh* tmp_mesh_pt=
new TriangleScaffoldMesh(node_file_name,
119 this->build_from_scaffold(tmp_mesh_pt,time_stepper_pt,use_attributes);
126 unsigned nbound=nboundary();
127 for (
unsigned ibound=0;ibound<nbound;ibound++)
129 this->
template setup_boundary_coordinates<ELEMENT>(ibound);
133 #ifdef OOMPH_HAS_TRIANGLE_LIB 139 TimeStepper* time_stepper_pt=&Mesh::Default_TimeStepper)
142 MeshChecker::assert_geometric_element<QElementGeometricBase,ELEMENT>(2);
145 this->Allow_automatic_creation_of_vertices_on_boundaries=
149 this->Time_stepper_pt=time_stepper_pt;
159 unsigned max_boundary_id = 0;
166 Vector<TriangleMeshClosedCurve* > outer_boundary_pt=
172 if (outer_boundary_pt.size()==0)
174 std::stringstream error_message;
176 <<
"There are no outer boundaries defined.\n" 177 <<
"Verify that you have specified the outer boundaries in the\n" 178 <<
"Triangle_mesh_parameter object\n\n";
179 throw OomphLibError(error_message.str(),
180 OOMPH_CURRENT_FUNCTION,
181 OOMPH_EXCEPTION_LOCATION);
187 unsigned n_outer_boundaries=outer_boundary_pt.size();
190 Vector<TriangleMeshPolygon*> outer_boundary_polygon_pt(n_outer_boundaries);
193 for(
unsigned i=0;i<n_outer_boundaries;++i)
199 outer_boundary_polygon_pt[i]=
200 this->closed_curve_to_polygon_helper(outer_boundary_pt[i],max_boundary_id);
208 Vector<TriangleMeshClosedCurve* > internal_closed_curve_pt=
212 unsigned n_internal_closed_curves=internal_closed_curve_pt.size();
217 Vector<TriangleMeshPolygon*> internal_polygon_pt(n_internal_closed_curves);
220 for(
unsigned i=0;i<n_internal_closed_curves;++i)
224 internal_polygon_pt[i]=this->closed_curve_to_polygon_helper(
225 internal_closed_curve_pt[i],max_boundary_id);
233 Vector<TriangleMeshOpenCurve*> internal_open_curve_pt=
237 unsigned n_internal_open_curves=internal_open_curve_pt.size();
240 Vector<TriangleMeshOpenCurve*> internal_open_curve_poly_pt(
241 n_internal_open_curves);
244 for (
unsigned i=0;i<n_internal_open_curves;i++)
249 internal_open_curve_poly_pt[i]=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, but\n" 314 <<
"not internal boundaries. Triangle does not support this combination.\n" 315 <<
"If you do not want Triangle to refine internal boundaries, it can't\n" 316 <<
"refine outer boundaries either!\n" 317 <<
"Please either disable all boundary refinement\n" 318 <<
"(call TriangleMeshParameters::disable_boundary_refinement()\n" 319 <<
"or enable internal boundary refinement (the default)\n";
321 throw OomphLibError(error_stream.str().c_str(),
322 OOMPH_CURRENT_FUNCTION,
323 OOMPH_EXCEPTION_LOCATION);
326 this->generic_constructor(outer_boundary_polygon_pt,
328 internal_open_curve_poly_pt,
330 extra_holes_coordinates,
336 refine_internal_boundary);
351 unsigned nb=nboundary();
352 for (
unsigned b=0;b<nb;b++)
354 this->
template setup_boundary_coordinates<ELEMENT>(b);
358 this->snap_nodes_onto_geometric_objects();
365 Vector<TriangleMeshPolygon*>& internal_polygon_pt,
366 Vector<TriangleMeshOpenCurve*>& open_polylines_pt,
367 const double &element_area,
368 Vector<Vector<double> >& extra_holes_coordinates,
369 std::map<
unsigned,Vector<double> >& regions_coordinates,
370 std::map<unsigned,double >& regions_areas,
371 TimeStepper* time_stepper_pt,
372 const bool &use_attributes,
373 const bool &refine_boundary,
374 const bool &refine_internal_boundary)
378 if (element_area<10e-14)
380 std::ostringstream warning_message;
382 <<
"The current elements area was stated to (" << element_area
383 <<
").\nThe current precision to generate the input to triangle " 384 <<
"is fixed to 14 digits\n\n";
385 OomphLibWarning(warning_message.str(),
386 OOMPH_CURRENT_FUNCTION,
387 OOMPH_EXCEPTION_LOCATION);
393 this->Use_attributes=use_attributes;
396 this->Time_stepper_pt=time_stepper_pt;
399 this->Outer_boundary_pt=outer_boundary_pt;
402 this->Internal_polygon_pt=internal_polygon_pt;
405 this->Internal_open_curve_pt=open_polylines_pt;
408 this->Extra_holes_coordinates=extra_holes_coordinates;
411 this->Regions_coordinates=regions_coordinates;
414 TriangulateIO triangulate_io;
415 TriangulateIO triangulate_out;
418 TriangleHelper::initialise_triangulateio(triangulate_io);
422 UnstructuredTwoDMeshGeometryBase::build_triangulateio(outer_boundary_pt,
425 extra_holes_coordinates,
431 TriangleHelper::initialise_triangulateio(triangulate_out);
434 std::stringstream input_string_stream;
435 input_string_stream.precision(14);
436 input_string_stream.setf(std::ios_base::fixed,
437 std::ios_base::floatfield);
443 input_string_stream <<
"-pA -a -a" << element_area <<
" -q30" << std::fixed;
446 if (!this->is_automatic_creation_of_vertices_on_boundaries_allowed())
448 input_string_stream <<
" -YY";
452 if(refine_boundary==
false)
454 input_string_stream <<
"-Y";
457 if(refine_internal_boundary==
false)
459 input_string_stream <<
"Y";
464 char triswitches[100];
465 sprintf(triswitches,
"%s",input_string_stream.str().c_str());
468 triangulate(triswitches,&triangulate_io,&triangulate_out,0);
471 TriangleScaffoldMesh* tmp_mesh_pt=
new TriangleScaffoldMesh(triangulate_out);
474 if(!regions_coordinates.empty())
477 build_from_scaffold(tmp_mesh_pt,time_stepper_pt,
true);
480 this->Use_attributes=
true;
486 build_from_scaffold(tmp_mesh_pt,time_stepper_pt,use_attributes);
494 bool clear_hole_data=
false;
495 TriangleHelper::clear_triangulateio(triangulate_io,clear_hole_data);
496 TriangleHelper::clear_triangulateio(triangulate_out,clear_hole_data);
499 #endif // OOMPH_HAS_TRIANGLE_LIB 504 BrokenCopy::broken_copy(
"QuadFromTriangleMesh");
510 BrokenCopy::broken_assign(
"QuadFromTriangleMesh");
517 #ifdef OOMPH_HAS_TRIANGLE_LIB 519 std::set<TriangleMeshCurveSection*>::iterator it_polyline;
520 for (it_polyline = Free_curve_section_pt.begin();
521 it_polyline != Free_curve_section_pt.end();
524 delete (*it_polyline);
527 std::set<TriangleMeshPolygon*>::iterator it_polygon;
528 for (it_polygon = Free_polygon_pt.begin();
529 it_polygon != Free_polygon_pt.end();
532 delete (*it_polygon);
535 std::set<TriangleMeshOpenCurve*>::iterator it_open_polyline;
536 for (it_open_polyline = Free_open_curve_pt.begin();
537 it_open_polyline != Free_open_curve_pt.end();
540 delete (*it_open_polyline);
547 void build_from_scaffold(TriangleScaffoldMesh* tmp_mesh_pt,
548 TimeStepper* time_stepper_pt,
549 const bool &use_attributes);
570 template<
class ELEMENT>
573 public virtual RefineableQuadMesh<ELEMENT>
578 #ifdef OOMPH_HAS_TRIANGLE_LIB 583 triangle_mesh_parameters,
584 TimeStepper* time_stepper_pt=
585 &Mesh::Default_TimeStepper)
588 this->setup_quadtree_forest();
597 doc_info.directory()=
"";
598 doc_info.disable_doc();
599 refine_uniformly(doc_info);
606 unsigned nelem=this->nelement();
609 Vector<double> elem_error(nelem,DBL_MAX);
616 void adapt(
const Vector<double>& elem_error);
620 const std::string& element_file_name,
621 const std::string& poly_file_name,
622 TimeStepper* time_stepper_pt=
623 &Mesh::Default_TimeStepper)
629 this->setup_quadtree_forest();
647 template<
class ELEMENT>
649 public virtual SolidMesh
655 const std::string& element_file_name,
656 const std::string& poly_file_name,
657 TimeStepper* time_stepper_pt=
658 &Mesh::Default_TimeStepper,
659 const bool &use_attributes=
false) :
667 set_lagrangian_nodal_coordinates();
670 #ifdef OOMPH_HAS_TRIANGLE_LIB 677 TimeStepper* time_stepper_pt=&Mesh::Default_TimeStepper)
681 set_lagrangian_nodal_coordinates();
700 template<
class ELEMENT>
703 public virtual SolidMesh
711 const std::string& element_file_name,
712 const std::string& poly_file_name,
713 TimeStepper* time_stepper_pt=
714 &Mesh::Default_TimeStepper,
715 const bool &use_attributes=
false) :
723 set_lagrangian_nodal_coordinates();
726 #ifdef OOMPH_HAS_TRIANGLE_LIB 732 TimeStepper* time_stepper_pt=&Mesh::Default_TimeStepper)
738 set_lagrangian_nodal_coordinates();
752 #endif // OOMPH_QUAD_FROM_TRIANGLE_MESH_HEADER
virtual ~RefineableSolidQuadFromTriangleMesh()
Empty Destructor.
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...
std::map< unsigned, Vector< double > > & regions_coordinates()
Helper function for getting access to the regions coordinates.
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...
bool is_internal_boundary_refinement_allowed() const
Helper function for getting the status of boundary refinement.
RefineableQuadFromTriangleMesh(TriangleMeshParameters &triangle_mesh_parameters, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Build mesh, based on the specifications on TriangleMeshParameters.
Vector< TriangleMeshOpenCurve * > internal_open_curves_pt() const
Helper function for getting the internal open boundaries.
TimeStepper * Time_stepper_pt
Timestepper used to build elements.
Helper object for dealing with the parameters used for the TriangleMesh objects.
~QuadFromTriangleMesh()
Empty destructor.
Vector< TriangleMeshClosedCurve * > outer_boundary_pt() const
Helper function for getting the outer boundary.
bool is_boundary_refinement_allowed() const
Helper function for getting the status of boundary refinement.
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...
bool is_mesh_distributed() const
Boolean to indicate if Mesh has been distributed.
void refine_uniformly(DocInfo &doc_info)
Refine mesh uniformly and doc process.
void operator=(const QuadFromTriangleMesh &)
Broken assignment operator.
RefineableSolidQuadFromTriangleMesh(TriangleMeshParameters &triangle_mesh_parameters, TimeStepper *time_stepper_pt=&Mesh::Default_TimeStepper)
Build mesh, based on the specifications on TriangleMeshParameter.
QuadFromTriangleMesh()
Empty constructor.
virtual ~RefineableQuadFromTriangleMesh()
Empty Destructor.
Unstructured refineable QuadFromTriangleMesh upgraded to solid mesh.
Unstructured refineable QuadFromTriangleMesh.
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)
QuadFromTriangleMesh(const QuadFromTriangleMesh &dummy)
Broken copy constructor.
Vector< Vector< double > > extra_holes_coordinates() const
Helper function for getting the extra holes.
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.
void triangulate(char *triswitches, struct oomph::TriangulateIO *in, struct oomph::TriangulateIO *out, struct oomph::TriangulateIO *vorout)
Vector< TriangleMeshClosedCurve * > internal_closed_curve_pt() const
Helper function for getting the internal closed boundaries.
Unstructured QuadFromTriangleMesh upgraded to solid mesh.
std::map< unsigned, double > & target_area_for_region()
Helper function for getting access to the region's target areas.
virtual ~SolidQuadFromTriangleMesh()
Empty Destructor.
double element_area() const
Helper function for getting the element area.
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...
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.
bool is_automatic_creation_of_vertices_on_boundaries_allowed()
virtual void refine_uniformly()
Refine mesh uniformly.
bool is_use_attributes() const
Helper function for getting the status of use_attributes variable.
OomphCommunicator * communicator_pt() const
Read-only access fct to communicator (Null if mesh is not distributed)