29#include "libmesh/elem.h"
30#include "libmesh/face_tri3.h"
31#include "libmesh/mesh.h"
32#include "libmesh/mesh_generation.h"
33#include "libmesh/mesh_tetgen_interface.h"
34#include "libmesh/mesh_triangle_holes.h"
35#include "libmesh/mesh_triangle_interface.h"
36#include "libmesh/node.h"
37#include "libmesh/replicated_mesh.h"
38#include "libmesh/utility.h"
55int main (
int argc,
char ** argv)
60 libmesh_example_requires(2 <= LIBMESH_DIM,
"2D support");
62 libMesh::out <<
"Triangulating an L-shaped domain with holes" << std::endl;
67 libmesh_example_requires(3 <= LIBMESH_DIM,
"3D support");
69 libMesh::out <<
"Tetrahedralizing a prismatic domain with a hole" << std::endl;
82#ifdef LIBMESH_HAVE_TRIANGLE
122 PolygonHole hole_1(
Point(-0.5, 0.5),
127 PolygonHole hole_2(
Point(0.5, 0.5),
132 Point ellipse_center(-0.5, -0.5);
133 const unsigned int n_ellipse_points=100;
134 std::vector<Point> ellipse_points(n_ellipse_points);
140 for (
unsigned int i=0; i<n_ellipse_points; ++i)
141 ellipse_points[i]=
Point(ellipse_center(0)+a*cos(i*dtheta),
142 ellipse_center(1)+
b*sin(i*dtheta));
144 ArbitraryHole hole_3(ellipse_center, ellipse_points);
147 std::vector<Hole *> holes;
148 holes.push_back(&hole_1);
149 holes.push_back(&hole_2);
150 holes.push_back(&hole_3);
158#ifdef LIBMESH_HAVE_EXODUS_API
173#ifdef LIBMESH_HAVE_TETGEN
185 Point hole_lower_limit(0.2, 0.2, 0.4);
186 Point hole_upper_limit(0.8, 0.8, 0.6);
200 std::vector<Point> hole(1);
201 hole[0] =
Point(0.5*(hole_lower_limit + hole_upper_limit));
206 double quality_constraint = 2.0;
211 double volume_constraint = 0.001;
233#ifdef LIBMESH_HAVE_EXODUS_API
259#ifdef LIBMESH_HAVE_TETGEN
265 n_elem, n_elem, n_elem,
266 lower_limit(0), upper_limit(0),
267 lower_limit(1), upper_limit(1),
268 lower_limit(2), upper_limit(2),
281 std::map<unsigned, unsigned> node_id_map;
282 typedef std::map<unsigned, unsigned>::iterator iterator;
284 for (
auto & elem : cube_mesh.element_ptr_range())
285 for (
auto s : elem->side_index_range())
286 if (elem->neighbor_ptr(s) ==
nullptr)
289 std::unique_ptr<Elem> side = elem->side_ptr(s);
291 for (
auto n : side->node_index_range())
292 node_id_map.emplace(side->node_id(n), 0);
297 for (iterator it=node_id_map.begin(); it != node_id_map.end(); ++it)
300 unsigned id = (*it).first;
309 (*it).second = new_node->
id();
315 for (
auto & old_elem : cube_mesh.element_ptr_range())
316 if (old_elem->type() ==
TRI3)
322 for (
auto i : old_elem->node_index_range())
325 unsigned int new_node_id = libmesh_map_find(node_id_map, old_elem->node_id(i));
This is the base class from which all geometric element types are derived.
virtual Node *& set_node(const unsigned int i)
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
This is the MeshBase class.
virtual const Node & node_ref(const dof_id_type i) const
virtual const Node * node_ptr(const dof_id_type i) const =0
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
Prepare a newly created (or read) mesh for use.
virtual void write(const std::string &name) const =0
virtual Node * add_point(const Point &p, const dof_id_type id=DofObject::invalid_id, const processor_id_type proc_id=DofObject::invalid_processor_id)=0
Add a new Node at Point p to the end of the vertex array, with processor_id procid.
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
virtual void find_neighbors(const bool reset_remote_elements=false, const bool reset_current_list=true, const bool assert_valid=true)=0
Locate element face (edge in 2D) neighbors.
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
A Node is like a Point, but with more information.
const Parallel::Communicator & comm() const
A Point defines a location in LIBMESH_DIM dimensional Real space.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
Class TetGenMeshInterface provides an interface for tetrahedralization of meshes using the TetGen lib...
void triangulate_conformingDelaunayMesh_carvehole(const std::vector< Point > &holes, double quality_constraint=0., double volume_constraint=0.)
Method invokes TetGen library to compute a Delaunay tetrahedralization from the nodes point set.
void pointset_convexhull()
Method invokes TetGen library to compute a Delaunay tetrahedralization from the nodes point set.
void set_switches(std::string new_switches)
Method to set switches to tetgen, allowing for different behaviours.
A C++ interface between LibMesh and the Triangle library written by J.R.
virtual void triangulate() override
Internally, this calls Triangle's triangulate routine.
Another concrete instantiation of the hole, this one should be sufficiently general for most non-poly...
An abstract class for defining a 2-dimensional hole.
A concrete instantiation of the Hole class that describes polygonal (triangular, square,...
TriangulationType & triangulation_type()
Sets and/or gets the desired triangulation type.
bool & smooth_after_generating()
Sets/gets flag which tells whether to do two steps of Laplace mesh smoothing after generating the gri...
void attach_hole_list(const std::vector< Hole * > *holes)
Attaches a vector of Hole* pointers which will be meshed around.
Real & desired_area()
Sets and/or gets the desired triangle area.
void add_cube_convex_hull_to_mesh(MeshBase &mesh, Point lower_limit, Point upper_limit)
void triangulate_domain(const Parallel::Communicator &comm)
void tetrahedralize_domain(const Parallel::Communicator &comm)
The libMesh namespace provides an interface to certain functionality in the library.
void libmesh_ignore(const Args &...)
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real