libMesh
elem_cutter.h
Go to the documentation of this file.
1 // The libMesh Finite Element Library.
2 // Copyright (C) 2002-2019 Benjamin S. Kirk, John W. Peterson, Roy H. Stogner
3 
4 // This library is free software; you can redistribute it and/or
5 // modify it under the terms of the GNU Lesser General Public
6 // License as published by the Free Software Foundation; either
7 // version 2.1 of the License, or (at your option) any later version.
8 
9 // This library is distributed in the hope that it will be useful,
10 // but WITHOUT ANY WARRANTY; without even the implied warranty of
11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 // Lesser General Public License for more details.
13 
14 // You should have received a copy of the GNU Lesser General Public
15 // License along with this library; if not, write to the Free Software
16 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 
18 
19 
20 #ifndef LIBMESH_ELEM_CUTTER_H
21 #define LIBMESH_ELEM_CUTTER_H
22 
23 #include "libmesh/libmesh_config.h"
24 
25 #if defined(LIBMESH_HAVE_TRIANGLE) && defined(LIBMESH_HAVE_TETGEN)
26 
27 // libMesh includes
28 #include "libmesh/libmesh_common.h"
29 #include "libmesh/point.h"
30 
31 // TIMPI includes
32 #include "timpi/communicator.h"
33 
34 // C++ includes
35 #include <vector>
36 #include <memory>
37 
38 namespace libMesh
39 {
40 
41 // Forward declarations
42 class Elem;
43 class ReplicatedMesh;
44 class TriangleInterface;
45 class TetGenMeshInterface;
46 
47 // This is for backwards compatibility, but if your code relies on
48 // forward declarations in our headers then fix it.
49 class SerialMesh;
50 
62 {
63 public:
64 
69  ElemCutter();
70 
74  ~ElemCutter();
75 
81  bool is_inside (const Elem & elem,
82  const std::vector<Real> & vertex_distance_func) const;
83 
89  bool is_outside (const Elem & elem,
90  const std::vector<Real> & vertex_distance_func) const;
91 
97  bool is_cut (const Elem & elem,
98  const std::vector<Real> & vertex_distance_func) const;
99 
109  void operator()(const Elem & elem_in,
110  const std::vector<Real> & vertex_distance_func);
111 
117  const std::vector<Elem const *> & inside_elements () const
118  { return _inside_elem; }
119 
125  const std::vector<Elem const *> & outside_elements() const
126  { return _outside_elem; }
127 
128 protected:
129 
134  void find_intersection_points(const Elem & elem,
135  const std::vector<Real> & vertex_distance_func);
136 
140  void cut_1D(const Elem & elem,
141  const std::vector<Real> & vertex_distance_func);
142 
146  void cut_2D(const Elem & elem,
147  const std::vector<Real> & vertex_distance_func);
148 
152  void cut_3D(const Elem & elem,
153  const std::vector<Real> & vertex_distance_func);
154 
155  std::vector<Elem const *> _inside_elem;
156  std::vector<Elem const *> _outside_elem;
157 
158  Parallel::Communicator _comm_self; // defaults to MPI_COMM_SELF
159 
160  std::unique_ptr<ReplicatedMesh> _inside_mesh_2D;
161  std::unique_ptr<TriangleInterface> _triangle_inside;
162 
163  std::unique_ptr<ReplicatedMesh> _outside_mesh_2D;
164  std::unique_ptr<TriangleInterface> _triangle_outside;
165 
166  std::unique_ptr<ReplicatedMesh> _inside_mesh_3D;
167  std::unique_ptr<TetGenMeshInterface> _tetgen_inside;
168 
169  std::unique_ptr<ReplicatedMesh> _outside_mesh_3D;
170  std::unique_ptr<TetGenMeshInterface> _tetgen_outside;
171 
172  std::vector<Point> _intersection_pts;
173 };
174 
175 
176 } // namespace libMesh
177 
178 #endif // LIBMESH_HAVE_TRIANGLE && LIBMESH_HAVE_TETGEN
179 #endif // LIBMESH_ELEM_CUTTER_H
libMesh::ElemCutter::_tetgen_inside
std::unique_ptr< TetGenMeshInterface > _tetgen_inside
Definition: elem_cutter.h:167
libMesh::ElemCutter::_tetgen_outside
std::unique_ptr< TetGenMeshInterface > _tetgen_outside
Definition: elem_cutter.h:170
libMesh::ElemCutter::operator()
void operator()(const Elem &elem_in, const std::vector< Real > &vertex_distance_func)
This function implements cutting an element by a signed distance function.
Definition: elem_cutter.C:109
libMesh::ElemCutter::_inside_elem
std::vector< Elem const * > _inside_elem
Definition: elem_cutter.h:155
libMesh::ElemCutter::_outside_mesh_2D
std::unique_ptr< ReplicatedMesh > _outside_mesh_2D
Definition: elem_cutter.h:163
libMesh::ElemCutter::_triangle_outside
std::unique_ptr< TriangleInterface > _triangle_outside
Definition: elem_cutter.h:164
libMesh
The libMesh namespace provides an interface to certain functionality in the library.
Definition: factoryfunction.C:55
libMesh::ElemCutter::ElemCutter
ElemCutter()
Constructor.
Definition: elem_cutter.C:38
libMesh::ElemCutter::cut_3D
void cut_3D(const Elem &elem, const std::vector< Real > &vertex_distance_func)
cutting algorithm in 3D.
Definition: elem_cutter.C:297
libMesh::ElemCutter::_inside_mesh_3D
std::unique_ptr< ReplicatedMesh > _inside_mesh_3D
Definition: elem_cutter.h:166
libMesh::ElemCutter::~ElemCutter
~ElemCutter()
Destructor.
Definition: elem_cutter.C:53
libMesh::ElemCutter::cut_1D
void cut_1D(const Elem &elem, const std::vector< Real > &vertex_distance_func)
cutting algorithm in 1D.
Definition: elem_cutter.C:209
libMesh::ElemCutter::_outside_elem
std::vector< Elem const * > _outside_elem
Definition: elem_cutter.h:156
libMesh::ElemCutter::_outside_mesh_3D
std::unique_ptr< ReplicatedMesh > _outside_mesh_3D
Definition: elem_cutter.h:169
libMesh::ElemCutter::_comm_self
Parallel::Communicator _comm_self
Definition: elem_cutter.h:158
libMesh::ElemCutter::inside_elements
const std::vector< Elem const * > & inside_elements() const
Definition: elem_cutter.h:117
libMesh::ElemCutter::_triangle_inside
std::unique_ptr< TriangleInterface > _triangle_inside
Definition: elem_cutter.h:161
libMesh::ElemCutter::_inside_mesh_2D
std::unique_ptr< ReplicatedMesh > _inside_mesh_2D
Definition: elem_cutter.h:160
libMesh::ElemCutter
This class implements cutting a single element into a collection of subelements.
Definition: elem_cutter.h:61
libMesh::ElemCutter::outside_elements
const std::vector< Elem const * > & outside_elements() const
Definition: elem_cutter.h:125
libMesh::ElemCutter::_intersection_pts
std::vector< Point > _intersection_pts
Definition: elem_cutter.h:172
libMesh::Elem
This is the base class from which all geometric element types are derived.
Definition: elem.h:100
libMesh::ElemCutter::find_intersection_points
void find_intersection_points(const Elem &elem, const std::vector< Real > &vertex_distance_func)
Finds the points where the cutting surface intersects the element edges.
Definition: elem_cutter.C:154
libMesh::ElemCutter::is_cut
bool is_cut(const Elem &elem, const std::vector< Real > &vertex_distance_func) const
Definition: elem_cutter.C:88
libMesh::ElemCutter::cut_2D
void cut_2D(const Elem &elem, const std::vector< Real > &vertex_distance_func)
cutting algorithm in 2D.
Definition: elem_cutter.C:217
communicator.h
libMesh::ElemCutter::is_outside
bool is_outside(const Elem &elem, const std::vector< Real > &vertex_distance_func) const
Definition: elem_cutter.C:73
libMesh::ElemCutter::is_inside
bool is_inside(const Elem &elem, const std::vector< Real > &vertex_distance_func) const
Definition: elem_cutter.C:58