Skip to content

Commit

Permalink
add functions to support dim-independent programming
Browse files Browse the repository at this point in the history
  • Loading branch information
nfehn committed Apr 4, 2020
1 parent 17d9e89 commit bb236de
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 2 deletions.
31 changes: 31 additions & 0 deletions include/deal.II/grid/grid_generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -1755,6 +1755,22 @@ namespace GridGenerator
const bool copy_manifold_ids = false,
const std::vector<types::manifold_id> &manifold_priorities = {});

/**
* Overload of extrude_triangulation() to allow dimension independent
* code to compile. This function throws an error when called, as
* extrude_triangulation() is only implemented to extrude a dim=2 to a dim=3
* Triangulation.
*/
void
extrude_triangulation(
const Triangulation<2, 2> & input,
const unsigned int n_slices,
const double height,
Triangulation<2, 2> & result,
const bool copy_manifold_ids = false,
const std::vector<types::manifold_id> &manifold_priorities = {});


/**
* Overload of the previous function. Take a 2d Triangulation that is being
* extruded. Differing from the previous function taking height and number of
Expand Down Expand Up @@ -1783,6 +1799,21 @@ namespace GridGenerator
const bool copy_manifold_ids = false,
const std::vector<types::manifold_id> &manifold_priorities = {});

/**
* Overload of extrude_triangulation() to allow dimension independent
* code to compile. This function throws an error when called, as
* extrude_triangulation() is only implemented to extrude a dim=2 to a dim=3
* Triangulation.
*/
void
extrude_triangulation(
const Triangulation<2, 2> & input,
const std::vector<double> & slice_coordinates,
Triangulation<2, 2> & result,
const bool copy_manifold_ids = false,
const std::vector<types::manifold_id> &manifold_priorities = {});



/**
* Given an input triangulation @p in_tria, this function makes a new flat
Expand Down
5 changes: 4 additions & 1 deletion include/deal.II/grid/grid_tools.h
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,12 @@ namespace GridTools
* given angle (given in radians, rather than degrees). This function uses
* the transform() function above, so the requirements on the triangulation
* stated there hold for this function as well.
*
* @note This function is only supported for dim=2.
*/
template <int dim>
void
rotate(const double angle, Triangulation<2> &triangulation);
rotate(const double angle, Triangulation<dim> &triangulation);

/**
* Rotate all vertices of the given @p triangulation in counter-clockwise
Expand Down
47 changes: 47 additions & 0 deletions source/grid/grid_generator.cc
Original file line number Diff line number Diff line change
Expand Up @@ -6196,6 +6196,30 @@ namespace GridGenerator



void
extrude_triangulation(
const Triangulation<2, 2> & input,
const unsigned int n_slices,
const double height,
Triangulation<2, 2> & result,
const bool copy_manifold_ids,
const std::vector<types::manifold_id> &manifold_priorities)
{
(void)input;
(void)n_slices;
(void)height;
(void)result;
(void)copy_manifold_ids;
(void)manifold_priorities;

AssertThrow(false,
ExcMessage(
"GridTools::extrude_triangulation() is only available "
"for Triangulation<3, 3> as output triangulation."));
}



void
extrude_triangulation(
const Triangulation<2, 2> & input,
Expand Down Expand Up @@ -6425,6 +6449,29 @@ namespace GridGenerator
}



void
extrude_triangulation(
const Triangulation<2, 2> & input,
const std::vector<double> & slice_coordinates,
Triangulation<2, 2> & result,
const bool copy_manifold_ids,
const std::vector<types::manifold_id> &manifold_priorities)
{
(void)input;
(void)slice_coordinates;
(void)result;
(void)copy_manifold_ids;
(void)manifold_priorities;

AssertThrow(false,
ExcMessage(
"GridTools::extrude_triangulation() is only available "
"for Triangulation<3, 3> as output triangulation."));
}



template <>
void hyper_cube_with_cylindrical_hole(Triangulation<1> &,
const double,
Expand Down
14 changes: 13 additions & 1 deletion source/grid/grid_tools.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1068,13 +1068,25 @@ namespace GridTools
}



template <>
void
rotate(const double angle, Triangulation<2> &triangulation)
{
transform(Rotate2d(angle), triangulation);
}

template <>
void
rotate(const double angle, Triangulation<3> &triangulation)
{
(void)angle;
(void)triangulation;

AssertThrow(
false, ExcMessage("GridTools::rotate() is not available for dim = 3."));
}


template <int dim>
void
rotate(const double angle,
Expand Down

0 comments on commit bb236de

Please sign in to comment.