Skip to content

Commit

Permalink
Surface deal.II Tria to volumetric deal.II Tria
Browse files Browse the repository at this point in the history
  • Loading branch information
fdrmrc committed May 20, 2022
1 parent 821ac20 commit 0ed2dc1
Show file tree
Hide file tree
Showing 4 changed files with 145 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/deal.II/cgal/triangulation.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
# include <CGAL/Surface_mesh.h>
# include <CGAL/Triangulation_2.h>
# include <CGAL/Triangulation_3.h>
# include <deal.II/cgal/surface_mesh.h>
# include <deal.II/cgal/utilities.h>

DEAL_II_NAMESPACE_OPEN
Expand Down
87 changes: 87 additions & 0 deletions include/deal.II/grid/grid_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@ DEAL_II_DISABLE_EXTRA_DIAGNOSTICS
# include <boost/iostreams/filtering_stream.hpp>
# include <boost/iostreams/stream.hpp>
#endif

#ifdef DEAL_II_WITH_CGAL
# include <deal.II/cgal/surface_mesh.h>
# include <deal.II/cgal/triangulation.h>
#endif
DEAL_II_ENABLE_EXTRA_DIAGNOSTICS

#include <bitset>
Expand Down Expand Up @@ -576,6 +581,28 @@ namespace GridTools
transform(const Transformation & transformation,
Triangulation<dim, spacedim> &triangulation);

#ifdef DEAL_II_WITH_CGAL
/**
* Create a deal.II Triangulation<3> out of a deal.II Triangulation<2,3>
* by filling it with tetrahedrons. Optional variable arguments `cgal_args`
* can be used to control size, quality, and distribution of the cells of
* the final triangulation.
*
* See https://doc.cgal.org/latest/Mesh_3/index.html for more information.
*
*
* @param [in] surface_tria The input deal.II Triangulation<2,3>.
* @param [out] vol_tria The output deal.II Triangulation<3>.
* @param [in] cgal_args Additional parameters to pass to the CGAL::make_mesh_3
* function.
*/
template <typename... Args>
void
surface_mesh_to_volumetric_mesh(const Triangulation<2, 3> &surface_tria,
Triangulation<3> & vol_tria,
Args... cgal_args);
#endif

/**
* Shift each vertex of the triangulation by the given shift vector. This
* function uses the transform() function above, so the requirements on the
Expand Down Expand Up @@ -911,6 +938,13 @@ namespace GridTools
regularize_corner_cells(Triangulation<dim, spacedim> &tria,
const double limit_angle_fraction = .75);

#ifdef DEAL_II_WITH_CGAL
template <typename... Args>
void
surface_mesh_to_volumetric_mesh(const Triangulation<2, 3> &surface_tria,
Triangulation<3> & vol_tria,
Args... cgal_args);
#endif
/*@}*/
/**
* @name Finding cells and vertices of a triangulation
Expand Down Expand Up @@ -3655,6 +3689,59 @@ namespace GridTools



# ifdef DEAL_II_WITH_CGAL
template <typename... Args>
void
surface_mesh_to_volumetric_mesh(const Triangulation<2, 3> &surface_tria,
Triangulation<3> & vol_tria,
Args... cgal_args)
{
Assert(
vol_tria.n_cells() > 0,
ExcMessage(
"The input triangulation cannot be empty when calling this function."));
Assert(
vol_tria.n_cells() == 0,
ExcMessage(
"The output triangulation must be empty when calling this function."));
using K = CGAL::Exact_predicates_inexact_constructions_kernel;
using Point_3 = K::Point_3;

using Mesh_domain =
CGAL::Polyhedral_mesh_domain_with_features_3<K,
CGAL::Surface_mesh<Point_3>>;
using Tr = CGAL::Mesh_triangulation_3<Mesh_domain,
CGAL::Default,
CGALWrappers::ConcurrencyTag>::type;
using Mesh_criteria = CGAL::Mesh_criteria_3<Tr>;
using C3t3 =
CGAL::Mesh_complex_3_in_triangulation_3<Tr,
Mesh_domain::Corner_index,
Mesh_domain::Curve_index>;

CGAL::Surface_mesh<Point_3> mesh;
// This function "fills" the missing arrow of the following diagram.
// Tria<2,3> Tria<3>
// | ^
// | |
// | |
// | |
// V |
// CGAL::Surface_mesh -----------> CGAL::C3t3
CGALWrappers::dealii_tria_to_cgal_surface_mesh(surface_tria, mesh);
CGAL::Polygon_mesh_processing::triangulate_faces(mesh);
CGAL::Polygon_mesh_processing::stitch_borders(mesh);
Mesh_domain domain(mesh);
domain.detect_features();
Mesh_criteria criteria(cgal_args...);
const auto cgal_triangulation = CGAL::make_mesh_3<C3t3>(domain, criteria);
CGALWrappers::cgal_triangulation_to_dealii_triangulation(cgal_triangulation,
vol_tria);
}
# endif



template <class MeshType>
std::vector<typename MeshType::active_cell_iterator>
get_active_child_cells(const typename MeshType::cell_iterator &cell)
Expand Down
55 changes: 55 additions & 0 deletions tests/cgal/cgal_triangulation_07.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
// ---------------------------------------------------------------------
//
// Copyright (C) 2022 by the deal.II authors
//
// This file is part of the deal.II library.
//
// The deal.II library is free software; you can use it, redistribute
// it, and/or modify it under the terms of the GNU Lesser General
// Public License as published by the Free Software Foundation; either
// version 2.1 of the License, or (at your option) any later version.
// The full text of the license can be found in the file LICENSE.md at
// the top level directory of deal.II.
//
// ---------------------------------------------------------------------

// Create a Tria<3> out of a Tria<2,3>.

#include <deal.II/base/config.h>

#include <deal.II/grid/grid_generator.h>
#include <deal.II/grid/grid_out.h>
#include <deal.II/grid/grid_tools.h>
#include <deal.II/grid/tria.h>

#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/IO/io.h>

#include "../tests.h"

using namespace CGALWrappers;
int
main()
{
initlog();
Triangulation<2, 3> surface_tria;
GridGenerator::hyper_sphere(surface_tria, {0., 1., 0.}, 1.);
surface_tria.refine_global(3);


Triangulation<3> out_tria;
GridTools::surface_mesh_to_volumetric_mesh(
surface_tria,
out_tria,
CGAL::parameters::facet_size = 0.1,
CGAL::parameters::facet_distance = 0,
CGAL::parameters::cell_radius_edge_ratio = 2,
CGAL::parameters::cell_size = 0.1);

GridOut go;
std::ofstream out_tria_name("tria_surface_to_volumetric.vtk");
go.write_vtk(out_tria, out_tria_name);

// cat_file("tria_surface_to_volumetric.vtk");
deallog << "OK" << std::endl;
}
2 changes: 2 additions & 0 deletions tests/cgal/cgal_triangulation_07.output
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@

DEAL::OK

0 comments on commit 0ed2dc1

Please sign in to comment.