From a9f42137dacc47cb7df5882d4e32e0a223ca3913 Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Thu, 28 Jan 2021 11:49:16 -0700 Subject: [PATCH] Move the function that generates a reference cell to GridGenerator. --- include/deal.II/fe/fe_tools.templates.h | 4 +- include/deal.II/grid/grid_generator.h | 11 ++++ include/deal.II/grid/reference_cell.h | 9 --- source/grid/grid_generator.cc | 79 +++++++++++++++++++++++++ source/grid/grid_generator.inst.in | 5 ++ source/grid/reference_cell.cc | 79 +------------------------ source/grid/reference_cell.inst.in | 4 -- tests/simplex/fe_p_bubbles_02.cc | 2 +- tests/simplex/orientation_02.cc | 2 +- 9 files changed, 100 insertions(+), 95 deletions(-) diff --git a/include/deal.II/fe/fe_tools.templates.h b/include/deal.II/fe/fe_tools.templates.h index 4e3edf8a92..b2142de629 100644 --- a/include/deal.II/fe/fe_tools.templates.h +++ b/include/deal.II/fe/fe_tools.templates.h @@ -1605,7 +1605,7 @@ namespace FETools // First, create a local mass matrix for the unit cell Triangulation tr; - ReferenceCell::make_triangulation(reference_cell_type, tr); + GridGenerator::reference_cell(reference_cell_type, tr); const auto &mapping = reference_cell_type.template get_default_linear_mapping(); @@ -1814,7 +1814,7 @@ namespace FETools // Set up meshes, one with a single // reference cell and refine it once Triangulation tria; - ReferenceCell::make_triangulation(reference_cell_type, tria); + GridGenerator::reference_cell(reference_cell_type, tria); tria.begin_active()->set_refine_flag(RefinementCase(ref_case)); tria.execute_coarsening_and_refinement(); diff --git a/include/deal.II/grid/grid_generator.h b/include/deal.II/grid/grid_generator.h index 6dfaee23c6..75a94c6e88 100644 --- a/include/deal.II/grid/grid_generator.h +++ b/include/deal.II/grid/grid_generator.h @@ -128,6 +128,17 @@ namespace GridGenerator simplex(Triangulation & tria, const std::vector> &vertices); + /* + * Create a (coarse) grid with a single cell of the shape of the provided + * reference cell. This is a generalization of the hyper_cube() and simplex() + * functions above. + */ + template + void + reference_cell(const ReferenceCell::Type & reference_cell, + Triangulation &tria); + + /** * Same as hyper_cube(), but with the difference that not only one cell is * created but each coordinate direction is subdivided into @p repetitions diff --git a/include/deal.II/grid/reference_cell.h b/include/deal.II/grid/reference_cell.h index d54ed6352d..37c360d56b 100644 --- a/include/deal.II/grid/reference_cell.h +++ b/include/deal.II/grid/reference_cell.h @@ -712,15 +712,6 @@ namespace ReferenceCell return {}; } - /* - * Create a (coarse) grid with a single cell of the shape of the provided - * reference cell. - */ - template - void - make_triangulation(const Type & reference_cell, - Triangulation &tria); - /** * Return a default linear mapping that works for the given triangulation. * Internally, this function calls the function above for the reference diff --git a/source/grid/grid_generator.cc b/source/grid/grid_generator.cc index b1d2070aaf..aca11b6270 100644 --- a/source/grid/grid_generator.cc +++ b/source/grid/grid_generator.cc @@ -1580,6 +1580,7 @@ namespace GridGenerator } + template void hyper_cube(Triangulation &tria, @@ -1599,6 +1600,8 @@ namespace GridGenerator hyper_rectangle(tria, p1, p2, colorize); } + + template void simplex(Triangulation &tria, const std::vector> &vertices) @@ -1711,6 +1714,82 @@ namespace GridGenerator } + + template + void + reference_cell(const ReferenceCell::Type & reference_cell, + Triangulation &tria) + { + AssertDimension(dim, reference_cell.get_dimension()); + + if (reference_cell == ReferenceCell::Type::get_hypercube()) + { + GridGenerator::hyper_cube(tria, 0, 1); + } + else if ((dim == 2) && (reference_cell == ReferenceCell::Type::Tri)) + { + const std::vector> vertices = { + Point(), // the origin + Point::unit_vector(0), // unit point along x-axis + Point::unit_vector(1) // unit point along y-axis + }; + + std::vector> cells(1); + cells[0].vertices = {0, 1, 2}; + + tria.create_triangulation(vertices, cells, {}); + } + else if ((dim == 3) && (reference_cell == ReferenceCell::Type::Tet)) + { + AssertDimension(spacedim, 3); + + static const std::vector> vertices = { + {{0.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}}; + + std::vector> cells(1); + cells[0].vertices = {0, 1, 2, 3}; + + tria.create_triangulation(vertices, cells, {}); + } + else if ((dim == 3) && (reference_cell == ReferenceCell::Type::Pyramid)) + { + AssertDimension(spacedim, 3); + + static const std::vector> vertices = { + {{-1.0, -1.0, 0.0}, + {+1.0, -1.0, 0.0}, + {-1.0, +1.0, 0.0}, + {+1.0, +1.0, 0.0}, + {+0.0, +0.0, 1.0}}}; + + std::vector> cells(1); + cells[0].vertices = {0, 1, 2, 3, 4}; + + tria.create_triangulation(vertices, cells, {}); + } + else if ((dim == 3) && (reference_cell == ReferenceCell::Type::Wedge)) + { + AssertDimension(spacedim, 3); + + static const std::vector> vertices = { + {{1.0, 0.0, 0.0}, + {0.0, 1.0, 0.0}, + {0.0, 0.0, 0.0}, + {1.0, 0.0, 1.0}, + {0.0, 1.0, 1.0}, + {0.0, 0.0, 1.0}}}; + + std::vector> cells(1); + cells[0].vertices = {0, 1, 2, 3, 4, 5}; + + tria.create_triangulation(vertices, cells, {}); + } + else + { + Assert(false, ExcNotImplemented()); + } + } + void moebius(Triangulation<3> & tria, const unsigned int n_cells, const unsigned int n_rotations, diff --git a/source/grid/grid_generator.inst.in b/source/grid/grid_generator.inst.in index c6c2bd6d68..d7e1b25dd4 100644 --- a/source/grid/grid_generator.inst.in +++ b/source/grid/grid_generator.inst.in @@ -269,6 +269,11 @@ for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS) namespace GridGenerator \{ #if deal_II_dimension <= deal_II_space_dimension + template void + reference_cell( + const ReferenceCell::Type &, + Triangulation &); + template void convert_hypercube_to_simplex_mesh( const Triangulation &, diff --git a/source/grid/reference_cell.cc b/source/grid/reference_cell.cc index 85c33d5b3f..c187cdd4ea 100644 --- a/source/grid/reference_cell.cc +++ b/source/grid/reference_cell.cc @@ -92,83 +92,6 @@ namespace ReferenceCell - template - void - make_triangulation(const Type & reference_cell, - Triangulation &tria) - { - AssertDimension(dim, reference_cell.get_dimension()); - - if (reference_cell == Type::get_hypercube()) - { - GridGenerator::hyper_cube(tria, 0, 1); - } - else if ((dim == 2) && (reference_cell == Type::Tri)) - { - const std::vector> vertices = { - Point(), // the origin - Point::unit_vector(0), // unit point along x-axis - Point::unit_vector(1) // unit point along y-axis - }; - - std::vector> cells(1); - cells[0].vertices = {0, 1, 2}; - - tria.create_triangulation(vertices, cells, {}); - } - else if ((dim == 3) && (reference_cell == Type::Tet)) - { - AssertDimension(spacedim, 3); - - static const std::vector> vertices = { - {{0.0, 0.0, 0.0}, {1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0}}}; - - std::vector> cells(1); - cells[0].vertices = {0, 1, 2, 3}; - - tria.create_triangulation(vertices, cells, {}); - } - else if ((dim == 3) && (reference_cell == Type::Pyramid)) - { - AssertDimension(spacedim, 3); - - static const std::vector> vertices = { - {{-1.0, -1.0, 0.0}, - {+1.0, -1.0, 0.0}, - {-1.0, +1.0, 0.0}, - {+1.0, +1.0, 0.0}, - {+0.0, +0.0, 1.0}}}; - - std::vector> cells(1); - cells[0].vertices = {0, 1, 2, 3, 4}; - - tria.create_triangulation(vertices, cells, {}); - } - else if ((dim == 3) && (reference_cell == Type::Wedge)) - { - AssertDimension(spacedim, 3); - - static const std::vector> vertices = { - {{1.0, 0.0, 0.0}, - {0.0, 1.0, 0.0}, - {0.0, 0.0, 0.0}, - {1.0, 0.0, 1.0}, - {0.0, 1.0, 1.0}, - {0.0, 0.0, 1.0}}}; - - std::vector> cells(1); - cells[0].vertices = {0, 1, 2, 3, 4, 5}; - - tria.create_triangulation(vertices, cells, {}); - } - else - { - Assert(false, ExcNotImplemented()); - } - } - - - template std::unique_ptr> Type::get_default_mapping(const unsigned int degree) const @@ -285,7 +208,7 @@ namespace ReferenceCell const auto create_quadrature = [](const Type &reference_cell) { Triangulation tria; - make_triangulation(reference_cell, tria); + GridGenerator::reference_cell(reference_cell, tria); return Quadrature(tria.get_vertices()); }; diff --git a/source/grid/reference_cell.inst.in b/source/grid/reference_cell.inst.in index b232ba517a..418844ce49 100644 --- a/source/grid/reference_cell.inst.in +++ b/source/grid/reference_cell.inst.in @@ -16,10 +16,6 @@ for (deal_II_dimension : DIMENSIONS; deal_II_space_dimension : SPACE_DIMENSIONS) { #if deal_II_dimension <= deal_II_space_dimension - template void make_triangulation( - const Type & reference_cell, - Triangulation &tria); - template std::unique_ptr< Mapping> Type::get_default_mapping(const unsigned int degree) const; diff --git a/tests/simplex/fe_p_bubbles_02.cc b/tests/simplex/fe_p_bubbles_02.cc index 331a65e520..9a45e95ed8 100644 --- a/tests/simplex/fe_p_bubbles_02.cc +++ b/tests/simplex/fe_p_bubbles_02.cc @@ -49,7 +49,7 @@ compute_nodal_quadrature(const FiniteElement &fe) const Quadrature q_gauss = ReferenceCell::get_gauss_type_quadrature(type, fe.tensor_degree() + 1); Triangulation tria; - ReferenceCell::make_triangulation(type, tria); + GridGenerator::reference_cell(type, tria); const Mapping &mapping = ReferenceCell::get_default_linear_mapping(type); diff --git a/tests/simplex/orientation_02.cc b/tests/simplex/orientation_02.cc index c81eb0903f..8931b1da8f 100644 --- a/tests/simplex/orientation_02.cc +++ b/tests/simplex/orientation_02.cc @@ -29,7 +29,7 @@ test(const unsigned int orientation) Triangulation<3> dummy, tria; - ReferenceCell::make_triangulation(ReferenceCell::Type::Tet, dummy); + GridGenerator::reference_cell(ReferenceCell::Type::Tet, dummy); auto vertices = dummy.get_vertices(); -- 2.39.5