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" 55 int 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 84 typedef TriangleInterface::Hole Hole;
85 typedef TriangleInterface::PolygonHole PolygonHole;
86 typedef TriangleInterface::ArbitraryHole ArbitraryHole;
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 166 #endif // LIBMESH_HAVE_TRIANGLE 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 240 #endif // LIBMESH_HAVE_TETGEN 259 #ifdef LIBMESH_HAVE_TETGEN 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;
303 Node & old_node = cube_mesh.node_ref(
id);
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));
334 #endif // LIBMESH_HAVE_TETGEN Class TetGenMeshInterface provides an interface for tetrahedralization of meshes using the TetGen lib...
virtual void triangulate() override
Internally, this calls Triangle's triangulate routine.
The ReplicatedMesh class is derived from the MeshBase class, and is used to store identical copies of...
virtual Node *& set_node(const unsigned int i)
A Node is like a Point, but with more information.
void set_switches(std::string new_switches)
Method to set switches to tetgen, allowing for different behaviours.
void add_cube_convex_hull_to_mesh(MeshBase &mesh, Point lower_limit, Point upper_limit)
void prepare_for_use(const bool skip_renumber_nodes_and_elements, const bool skip_find_neighbors)
Prepare a newly ecreated (or read) mesh for use.
This is the base class from which all geometric element types are derived.
const Parallel::Communicator & comm() const
The LibMeshInit class, when constructed, initializes the dependent libraries (e.g.
The libMesh namespace provides an interface to certain functionality in the library.
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.
This is the MeshBase class.
TriangulationType & triangulation_type()
Sets and/or gets the desired triangulation type.
void libmesh_ignore(const Args &...)
virtual void find_neighbors(const bool reset_remote_elements=false, const bool reset_current_list=true)=0
Locate element face (edge in 2D) neighbors.
void attach_hole_list(const std::vector< Hole *> *holes)
Attaches a vector of Hole* pointers which will be meshed around.
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...
int main(int argc, char **argv)
virtual Elem * add_elem(Elem *e)=0
Add elem e to the end of the element array.
static std::unique_ptr< Elem > build(const ElemType type, Elem *p=nullptr)
void init(triangulateio &t)
Initializes the fields of t to nullptr/0 as necessary.
virtual void write(const std::string &name) const =0
Real & desired_area()
Sets and/or gets the desired triangle area.
Triangulate the interior of a Planar Straight Line Graph, which is defined implicitly by the order of...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
void tetrahedralize_domain(const Parallel::Communicator &comm)
void pointset_convexhull()
Method invokes TetGen library to compute a Delaunay tetrahedralization from the nodes point set...
virtual const Node * node_ptr(const dof_id_type i) const =0
The Mesh class is a thin wrapper, around the ReplicatedMesh class by default.
A C++ interface between LibMesh and the Triangle library written by J.R.
A Point defines a location in LIBMESH_DIM dimensional Real space.
void triangulate_domain(const Parallel::Communicator &comm)
bool & smooth_after_generating()
Sets/gets flag which tells whether to do two steps of Laplace mesh smoothing after generating the gri...