22 #ifdef DEAL_II_WITH_CGAL
31 # include <CGAL/Boolean_set_operations_2.h>
32 # include <CGAL/Cartesian.h>
33 # include <CGAL/Circular_kernel_intersections.h>
34 # include <CGAL/Constrained_Delaunay_triangulation_2.h>
35 # include <CGAL/Delaunay_mesh_face_base_2.h>
36 # include <CGAL/Delaunay_mesh_size_criteria_2.h>
37 # include <CGAL/Delaunay_mesher_2.h>
38 # include <CGAL/Delaunay_triangulation_2.h>
39 # include <CGAL/Exact_predicates_exact_constructions_kernel_with_sqrt.h>
40 # include <CGAL/Kernel_traits.h>
41 # include <CGAL/Polygon_2.h>
42 # include <CGAL/Polygon_with_holes_2.h>
43 # include <CGAL/Projection_traits_xy_3.h>
44 # include <CGAL/Segment_3.h>
45 # include <CGAL/Simple_cartesian.h>
46 # include <CGAL/Tetrahedron_3.h>
47 # include <CGAL/Triangle_2.h>
48 # include <CGAL/Triangle_3.h>
49 # include <CGAL/Triangulation_2.h>
50 # include <CGAL/Triangulation_3.h>
51 # include <CGAL/Triangulation_face_base_with_id_2.h>
52 # include <CGAL/Triangulation_face_base_with_info_2.h>
62 using K = CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt;
63 using K_exact = CGAL::Exact_predicates_exact_constructions_kernel;
93 using Vb = CGAL::Triangulation_vertex_base_2<K>;
94 using Fbb = CGAL::Triangulation_face_base_with_info_2<FaceInfo2, K>;
95 using CFb = CGAL::Constrained_triangulation_face_base_2<K, Fbb>;
96 using Fb = CGAL::Delaunay_mesh_face_base_2<K, CFb>;
97 using Tds = CGAL::Triangulation_data_structure_2<Vb, Fb>;
98 using Itag = CGAL::Exact_predicates_tag;
99 using CDT = CGAL::Constrained_Delaunay_triangulation_2<K, Tds, Itag>;
100 using Criteria = CGAL::Delaunay_mesh_size_criteria_2<CDT>;
112 template <
typename TargetVariant>
113 struct Repackage : boost::static_visitor<TargetVariant>
115 template <
typename T>
117 operator()(
const T &t)
const
119 return TargetVariant(t);
129 template <
typename... Types>
130 std::optional<std::variant<Types...>>
131 convert_boost_to_std(
const boost::optional<boost::variant<Types...>> &x)
140 using std_variant = std::variant<Types...>;
141 return boost::apply_visitor(Repackage<std_variant>(), *x);
158 std::list<CDT::Edge> &border)
160 if (start->info().nesting_level != -1)
164 std::list<Face_handle> queue;
165 queue.push_back(start);
166 while (!queue.empty())
170 if (fh->info().nesting_level == -1)
172 fh->info().nesting_level = index;
173 for (
int i = 0; i < 3; i++)
177 if (n->info().nesting_level == -1)
179 if (ct.is_constrained(
e))
196 f->info().nesting_level = -1;
198 std::list<CDT::Edge> border;
200 while (!border.empty())
202 CDT::Edge
e = border.front();
205 if (n->info().nesting_level == -1)
207 mark_domains(cdt, n,
e.first->info().nesting_level + 1, border);
224 std::vector<CGALPoint2>>>
232 std::array<CGALPoint2, 3> pts0, pts1;
237 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint2, 2>);
242 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint2, 2>);
246 return convert_boost_to_std(
247 CGAL::intersection(cgal_triangle0, cgal_triangle1));
251 std::optional<std::variant<CGALPoint2, CGALSegment2>>
259 std::array<CGALPoint2, 3> pts0;
260 std::array<CGALPoint2, 2> pts1;
265 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint2, 2>);
270 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint2, 2>);
274 return convert_boost_to_std(
275 CGAL::intersection(cgal_segment, cgal_triangle));
281 std::vector<Polygon_with_holes_2>
288 std::array<CGALPoint2, 4> pts0, pts1;
293 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint2, 2>);
298 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint2, 2>);
300 const CGALPolygon first_poly{pts0.begin(), pts0.end()};
301 const CGALPolygon second_poly{pts1.begin(), pts1.end()};
303 std::vector<Polygon_with_holes_2> poly_list;
304 CGAL::intersection(first_poly,
306 std::back_inserter(poly_list));
312 std::optional<std::variant<CGALPoint3, CGALSegment3>>
317 # if DEAL_II_CGAL_VERSION_GTE(5, 5, 0)
322 std::array<CGALPoint3, 4> pts0;
323 std::array<CGALPoint3, 2> pts1;
328 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint3, 3>);
333 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint3, 3>);
335 CGALTetra cgal_tetrahedron{pts0[0], pts0[1], pts0[2], pts0[3]};
337 return convert_boost_to_std(
338 CGAL::intersection(cgal_segment, cgal_tetrahedron));
343 "This function requires a version of CGAL greater or equal than 5.5."));
355 std::vector<CGALPoint3>>>
360 # if DEAL_II_CGAL_VERSION_GTE(5, 5, 0)
365 std::array<CGALPoint3, 4> pts0;
366 std::array<CGALPoint3, 3> pts1;
371 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint3, 3>);
376 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint3, 3>);
378 CGALTetra cgal_tetrahedron{pts0[0], pts0[1], pts0[2], pts0[3]};
380 return convert_boost_to_std(
381 CGAL::intersection(cgal_triangle, cgal_tetrahedron));
387 "This function requires a version of CGAL greater or equal than 5.5."));
395 std::vector<std::array<Point<2>, 3>>
403 const auto intersection_test =
406 if (!intersection_test.empty())
408 const auto &poly = intersection_test[0].outer_boundary();
409 const unsigned int size_poly = poly.size();
415 {{CGALWrappers::cgal_point_to_dealii_point<2>(poly.vertex(0)),
416 CGALWrappers::cgal_point_to_dealii_point<2>(poly.vertex(1)),
417 CGALWrappers::cgal_point_to_dealii_point<2>(
420 else if (size_poly >= 4)
423 std::vector<std::array<Point<2>, 3>> collection;
426 cdt.insert_constraint(poly.vertices_begin(),
434 if (f->info().in_domain() &&
435 CGAL::to_double(cdt.triangle(f).area()) > tol)
437 collection.push_back(
438 {{CGALWrappers::cgal_point_to_dealii_point<2>(
439 cdt.triangle(f).vertex(0)),
440 CGALWrappers::cgal_point_to_dealii_point<2>(
441 cdt.triangle(f).vertex(1)),
442 CGALWrappers::cgal_point_to_dealii_point<2>(
443 cdt.triangle(f).vertex(2))}});
461 std::vector<std::array<Point<2>, 2>>
469 std::array<CGALPoint2, 4> pts;
474 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint2, 2>);
479 CGALWrappers::dealii_point_to_cgal_point<CGALPoint2>(line[0]),
480 CGALWrappers::dealii_point_to_cgal_point<CGALPoint2>(line[1]));
482 cdt.insert_constraint(poly.vertices_begin(), poly.vertices_end(),
true);
483 std::vector<std::array<Point<2>, 2>>
vertices;
487 if (f->info().in_domain() &&
488 CGAL::to_double(cdt.triangle(f).area()) > tol &&
489 CGAL::do_intersect(segm, cdt.triangle(f)))
491 const auto intersection =
492 CGAL::intersection(segm, cdt.triangle(f));
494 boost::get<CGALSegment2>(&*intersection))
497 {{CGALWrappers::cgal_point_to_dealii_point<2>((*s)[0]),
498 CGALWrappers::cgal_point_to_dealii_point<2>((*s)[1])}});
507 std::vector<std::array<Point<3>, 2>>
512 # if DEAL_II_CGAL_VERSION_GTE(5, 5, 0)
517 std::array<CGALPoint3_exact, 8> pts;
523 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint3_exact, 3>);
526 CGALWrappers::dealii_point_to_cgal_point<CGALPoint3_exact>(line[0]),
527 CGALWrappers::dealii_point_to_cgal_point<CGALPoint3_exact>(line[1]));
531 std::vector<std::array<Point<3>, 2>>
vertices;
533 cgal_triangulation.insert(pts.begin(), pts.end());
534 for (
const auto &c : cgal_triangulation.finite_cell_handles())
536 const auto &cgal_tetrahedron = cgal_triangulation.tetrahedron(c);
537 if (CGAL::do_intersect(cgal_segment, cgal_tetrahedron))
539 const auto intersection =
540 CGAL::intersection(cgal_segment, cgal_tetrahedron);
542 boost::get<CGALSegment3_exact>(&*intersection))
544 if (s->squared_length() > tol * tol)
547 {{CGALWrappers::cgal_point_to_dealii_point<3>(
549 CGALWrappers::cgal_point_to_dealii_point<3>(
560 "This function requires a version of CGAL greater or equal than 5.5."));
568 std::vector<std::array<Point<3>, 3>>
573 # if DEAL_II_CGAL_VERSION_GTE(5, 5, 0)
578 std::array<CGALPoint3_exact, 8> pts_hex;
579 std::array<CGALPoint3_exact, 4> pts_quad;
585 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint3_exact, 3>);
591 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint3_exact, 3>);
594 std::vector<std::array<Point<3>, 3>>
vertices;
596 triangulation_hexa.insert(pts_hex.begin(), pts_hex.end());
600 triangulation_quad.insert(pts_quad.begin(), pts_quad.end());
602 for (
const auto &c : triangulation_hexa.finite_cell_handles())
604 const auto &tet = triangulation_hexa.tetrahedron(c);
606 for (
const auto &f : triangulation_quad.finite_facets())
608 if (CGAL::do_intersect(tet, triangulation_quad.triangle(f)))
610 const auto intersection =
611 CGAL::intersection(triangulation_quad.triangle(f), tet);
614 boost::get<CGALTriangle3_exact>(&*intersection))
616 if (CGAL::to_double(t->squared_area()) > tol * tol)
619 {{cgal_point_to_dealii_point<3>((*t)[0]),
620 cgal_point_to_dealii_point<3>((*t)[1]),
621 cgal_point_to_dealii_point<3>((*t)[2])}});
625 if (
const std::vector<CGALPoint3_exact> *vps =
626 boost::get<std::vector<CGALPoint3_exact>>(
630 tria_inter.insert(vps->begin(), vps->end());
632 for (
auto it = tria_inter.finite_facets_begin();
633 it != tria_inter.finite_facets_end();
636 const auto triangle = tria_inter.triangle(*it);
637 if (CGAL::to_double(triangle.squared_area()) >
640 std::array<Point<3>, 3> verts = {
641 {CGALWrappers::cgal_point_to_dealii_point<3>(
643 CGALWrappers::cgal_point_to_dealii_point<3>(
645 CGALWrappers::cgal_point_to_dealii_point<3>(
661 "This function requires a version of CGAL greater or equal than 5.5."));
669 std::vector<std::array<Point<3>, 4>>
677 std::array<CGALPoint3_exact, 8> pts_hex0;
678 std::array<CGALPoint3_exact, 8> pts_hex1;
684 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint3_exact, 3>);
690 &CGALWrappers::dealii_point_to_cgal_point<CGALPoint3_exact, 3>);
694 std::vector<std::array<Point<3>, 4>>
vertices;
697 tria0.insert(pts_hex0.begin(), pts_hex0.end());
698 tria1.insert(pts_hex1.begin(), pts_hex1.end());
700 for (
const auto &c0 : tria0.finite_cell_handles())
702 const auto &tet0 = tria1.tetrahedron(c0);
703 const auto &tetg0 = CGAL::make_tetrahedron(tet0.vertex(0),
709 for (
const auto &c1 : tria1.finite_cell_handles())
711 const auto &tet1 = tria1.tetrahedron(c1);
712 const auto &tetg1 = CGAL::make_tetrahedron(tet1.vertex(0),
718 namespace PMP = CGAL::Polygon_mesh_processing;
719 const bool test_intersection =
720 PMP::corefine_and_compute_intersection(surf0, surf1, sm);
725 triangulation_hexa.insert(sm.points().begin(),
727 for (
const auto &c : triangulation_hexa.finite_cell_handles())
729 const auto &tet = triangulation_hexa.tetrahedron(c);
731 {{CGALWrappers::cgal_point_to_dealii_point<3>(
733 CGALWrappers::cgal_point_to_dealii_point<3>(
735 CGALWrappers::cgal_point_to_dealii_point<3>(
737 CGALWrappers::cgal_point_to_dealii_point<3>(
752 template <
int dim0,
int dim1,
int spacedim>
753 std::vector<std::array<Point<spacedim>, dim1 + 1>>
759 const unsigned int n_vertices0 = vertices0.size();
760 const unsigned int n_vertices1 = vertices1.size();
763 n_vertices0 > 0 || n_vertices1 > 0,
765 "The intersection cannot be computed as at least one of the two cells has no vertices."));
767 if constexpr (dim0 == 2 && dim1 == 2 && spacedim == 2)
769 if (n_vertices0 == 4 && n_vertices1 == 4)
776 else if constexpr (dim0 == 2 && dim1 == 1 && spacedim == 2)
778 if (n_vertices0 == 4 && n_vertices1 == 2)
785 else if constexpr (dim0 == 3 && dim1 == 1 && spacedim == 3)
787 if (n_vertices0 == 8 && n_vertices1 == 2)
794 else if constexpr (dim0 == 3 && dim1 == 2 && spacedim == 3)
796 if (n_vertices0 == 8 && n_vertices1 == 4)
803 else if constexpr (dim0 == 3 && dim1 == 3 && spacedim == 3)
805 if (n_vertices0 == 8 && n_vertices1 == 8)
822 template <
int dim0,
int dim1,
int spacedim>
823 std::vector<std::array<Point<spacedim>, dim1 + 1>>
832 ReferenceCells::get_hypercube<dim0>().n_vertices(),
835 ReferenceCells::get_hypercube<dim1>().n_vertices(),
838 const auto &vertices0 =
839 CGALWrappers::get_vertices_in_cgal_order(cell0, mapping0);
840 const auto &vertices1 =
841 CGALWrappers::get_vertices_in_cgal_order(cell1, mapping1);
843 return compute_intersection_of_cells<dim0, dim1, spacedim>(vertices0,
848 # include "intersections.inst"
863 std::vector<std::array<Point<spacedim>, dim1 + 1>>
875 template <
int dim0,
int dim1,
int spacedim>
876 std::vector<std::array<Point<spacedim>, dim1 + 1>>
Abstract base class for mapping classes.
virtual boost::container::small_vector< Point< spacedim >, GeometryInfo< dim >::vertices_per_cell > get_vertices(const typename Triangulation< dim, spacedim >::cell_iterator &cell) const
#define DEAL_II_NAMESPACE_OPEN
#define DEAL_II_NAMESPACE_CLOSE
#define Assert(cond, exc)
static ::ExceptionBase & ExcNotImplemented()
#define AssertDimension(dim1, dim2)
static ::ExceptionBase & ExcNeedsCGAL()
static ::ExceptionBase & ExcMessage(std::string arg1)
#define AssertThrow(cond, exc)
std::optional< std::variant< CGALPoint3, CGALSegment3 > > compute_intersection_tetra_segment(const ArrayView< const Point< 3 >> &tetrahedron, const ArrayView< const Point< 3 >> &segment)
std::optional< std::variant< CGALPoint3, CGALSegment3, CGALTriangle3, std::vector< CGALPoint3 > > > compute_intersection_tetra_triangle(const ArrayView< const Point< 3 >> &tetrahedron, const ArrayView< const Point< 3 >> &triangle)
void mark_domains(CDT &ct, Face_handle start, int index, std::list< CDT::Edge > &border)
std::vector< std::array< Point< 3 >, 4 > > compute_intersection_hexa_hexa(const ArrayView< const Point< 3 >> &hexa0, const ArrayView< const Point< 3 >> &hexa1, const double tol)
std::vector< std::array< Point< 2 >, 3 > > compute_intersection_quad_quad(const ArrayView< const Point< 2 >> &quad0, const ArrayView< const Point< 2 >> &quad1, const double tol)
std::vector< Polygon_with_holes_2 > compute_intersection_rect_rect(const ArrayView< const Point< 2 >> &rectangle0, const ArrayView< const Point< 2 >> &rectangle1)
std::vector< std::array< Point< 3 >, 2 > > compute_intersection_hexa_line(const ArrayView< const Point< 3 >> &hexa, const ArrayView< const Point< 3 >> &line, const double tol)
std::optional< std::variant< CGALPoint2, CGALSegment2, CGALTriangle2, std::vector< CGALPoint2 > > > compute_intersection_triangle_triangle(const ArrayView< const Point< 2 >> &triangle0, const ArrayView< const Point< 2 >> &triangle1)
std::vector< std::array< Point< 3 >, 3 > > compute_intersection_hexa_quad(const ArrayView< const Point< 3 >> &hexa, const ArrayView< const Point< 3 >> &quad, const double tol)
std::optional< std::variant< CGALPoint2, CGALSegment2 > > compute_intersection_triangle_segment(const ArrayView< const Point< 2 >> &triangle, const ArrayView< const Point< 2 >> &segment)
std::vector< std::array< Point< 2 >, 2 > > compute_intersection_quad_line(const ArrayView< const Point< 2 >> &quad, const ArrayView< const Point< 2 >> &line, const double tol)
K::Tetrahedron_3 CGALTetra
CGAL::Surface_mesh< K_exact::Point_3 > Surface_mesh
K::Segment_2 CGALSegment2
CGAL::Exact_predicates_tag Itag
K_exact::Tetrahedron_3 CGALTetra_exact
K_exact::Triangle_3 CGALTriangle3_exact
CDT::Vertex_handle Vertex_handle
K::Triangle_3 CGALTriangle3
K::Segment_3 CGALSegment3
CDT::Face_handle Face_handle
CGAL::Triangulation_3< K_exact > Triangulation3_exact
CGAL::Constrained_Delaunay_triangulation_2< K, Tds, Itag > CDT
CGAL::Delaunay_mesh_size_criteria_2< CDT > Criteria
CGAL::Triangulation_vertex_base_2< K > Vb
CGAL::Polygon_with_holes_2< K > Polygon_with_holes_2
CGAL::Triangulation_data_structure_2< Vb, Fb > Tds
std::vector< std::array< Point< spacedim >, dim1+1 > > compute_intersection_of_cells(const typename Triangulation< dim0, spacedim >::cell_iterator &cell0, const typename Triangulation< dim1, spacedim >::cell_iterator &cell1, const Mapping< dim0, spacedim > &mapping0, const Mapping< dim1, spacedim > &mapping1, const double tol=1e-9)
CGAL::Polygon_2< K > CGALPolygon
CGAL::Triangulation_2< K > Triangulation2
CGAL::Exact_predicates_exact_constructions_kernel K_exact
CGAL::Triangulation_3< K > Triangulation3
CGAL::Constrained_triangulation_face_base_2< K, Fbb > CFb
CGAL::Exact_predicates_exact_constructions_kernel_with_sqrt K
K::Triangle_2 CGALTriangle2
CGAL::Delaunay_mesh_face_base_2< K, CFb > Fb
K_exact::Segment_3 CGALSegment3_exact
K_exact::Point_3 CGALPoint3_exact
CGAL::Triangulation_face_base_with_info_2< FaceInfo2, K > Fbb
SymmetricTensor< 2, dim, Number > e(const Tensor< 2, dim, Number > &F)
void transform(const InputIterator &begin_in, const InputIterator &end_in, OutputIterator out, const Function &function, const unsigned int grainsize)