From 6c2e94f9a72b9b653638c01e6be51aecabd7ea22 Mon Sep 17 00:00:00 2001 From: Peter Munch Date: Tue, 10 Mar 2020 10:39:49 +0100 Subject: [PATCH] Replace some hard written constants by using GeometryInfo --- include/deal.II/dofs/dof_accessor.templates.h | 93 +++++++++++++------ .../deal.II/grid/tria_accessor.templates.h | 62 +++++++------ 2 files changed, 95 insertions(+), 60 deletions(-) diff --git a/include/deal.II/dofs/dof_accessor.templates.h b/include/deal.II/dofs/dof_accessor.templates.h index aa30251af7..02649b8da5 100644 --- a/include/deal.II/dofs/dof_accessor.templates.h +++ b/include/deal.II/dofs/dof_accessor.templates.h @@ -1814,7 +1814,8 @@ namespace internal dofs_per_line = accessor.get_fe(fe_index).dofs_per_line; std::vector::iterator next = dof_indices.begin(); - for (unsigned int vertex = 0; vertex < 2; ++vertex) + for (unsigned int vertex = 0; vertex < GeometryInfo<1>::vertices_per_cell; + ++vertex) for (unsigned int d = 0; d < dofs_per_vertex; ++d) *next++ = accessor.vertex_dof_index(vertex, d, fe_index); for (unsigned int d = 0; d < dofs_per_line; ++d) @@ -1837,7 +1838,8 @@ namespace internal dofs_per_quad = accessor.get_fe(fe_index).dofs_per_quad; std::vector::iterator next = dof_indices.begin(); - for (unsigned int vertex = 0; vertex < 4; ++vertex) + for (unsigned int vertex = 0; vertex < GeometryInfo<2>::vertices_per_cell; + ++vertex) for (unsigned int d = 0; d < dofs_per_vertex; ++d) *next++ = accessor.vertex_dof_index(vertex, d, fe_index); // now copy dof numbers from the line. for @@ -1851,7 +1853,8 @@ namespace internal // to adjust the shape function indices that // we see to correspond to the correct // (face-local) ordering. - for (unsigned int line = 0; line < 4; ++line) + for (unsigned int line = 0; line < GeometryInfo<2>::vertices_per_cell; + ++line) for (unsigned int d = 0; d < dofs_per_line; ++d) *next++ = accessor.line(line)->dof_index( accessor.get_fe(fe_index) @@ -1879,7 +1882,8 @@ namespace internal accessor.get_fe(fe_index).dofs_per_quad, dofs_per_hex = accessor.get_fe(fe_index).dofs_per_hex; std::vector::iterator next = dof_indices.begin(); - for (unsigned int vertex = 0; vertex < 8; ++vertex) + for (unsigned int vertex = 0; vertex < GeometryInfo<3>::vertices_per_cell; + ++vertex) for (unsigned int d = 0; d < dofs_per_vertex; ++d) *next++ = accessor.vertex_dof_index(vertex, d, fe_index); // now copy dof numbers from the line. for @@ -1893,7 +1897,8 @@ namespace internal // adjust the shape function indices that we // see to correspond to the correct // (cell-local) ordering. - for (unsigned int line = 0; line < 12; ++line) + for (unsigned int line = 0; line < GeometryInfo<3>::lines_per_cell; + ++line) for (unsigned int d = 0; d < dofs_per_line; ++d) *next++ = accessor.line(line)->dof_index( accessor.get_fe(fe_index) @@ -1913,7 +1918,8 @@ namespace internal // correct (cell-local) ordering. The same // applies, if the face_rotation or // face_orientation is non-standard - for (unsigned int quad = 0; quad < 6; ++quad) + for (unsigned int quad = 0; quad < GeometryInfo<3>::faces_per_cell; + ++quad) for (unsigned int d = 0; d < dofs_per_quad; ++d) *next++ = accessor.quad(quad)->dof_index( accessor.get_fe(fe_index) @@ -2057,22 +2063,28 @@ DoFAccessor::get_dof_indices( { case 1: Assert(dof_indices.size() == - (2 * this->dof_handler->get_fe(fe_index).dofs_per_vertex + + (GeometryInfo<1>::vertices_per_cell * + this->dof_handler->get_fe(fe_index).dofs_per_vertex + this->dof_handler->get_fe(fe_index).dofs_per_line), ExcVectorDoesNotMatch()); break; case 2: Assert(dof_indices.size() == - (4 * this->dof_handler->get_fe(fe_index).dofs_per_vertex + - 4 * this->dof_handler->get_fe(fe_index).dofs_per_line + + (GeometryInfo<2>::vertices_per_cell * + this->dof_handler->get_fe(fe_index).dofs_per_vertex + + GeometryInfo<2>::lines_per_cell * + this->dof_handler->get_fe(fe_index).dofs_per_line + this->dof_handler->get_fe(fe_index).dofs_per_quad), ExcVectorDoesNotMatch()); break; case 3: Assert(dof_indices.size() == - (8 * this->dof_handler->get_fe(fe_index).dofs_per_vertex + - 12 * this->dof_handler->get_fe(fe_index).dofs_per_line + - 6 * this->dof_handler->get_fe(fe_index).dofs_per_quad + + (GeometryInfo<3>::vertices_per_cell * + this->dof_handler->get_fe(fe_index).dofs_per_vertex + + GeometryInfo<3>::lines_per_cell * + this->dof_handler->get_fe(fe_index).dofs_per_line + + GeometryInfo<3>::faces_per_cell * + this->dof_handler->get_fe(fe_index).dofs_per_quad + this->dof_handler->get_fe(fe_index).dofs_per_hex), ExcVectorDoesNotMatch()); break; @@ -2120,7 +2132,8 @@ DoFAccessor::get_mg_dof_indices( case 1: { Assert(dof_indices.size() == - 2 * this->dof_handler->get_fe(fe_index).dofs_per_vertex + + GeometryInfo<1>::vertices_per_cell * + this->dof_handler->get_fe(fe_index).dofs_per_vertex + this->dof_handler->get_fe(fe_index).dofs_per_line, ExcVectorDoesNotMatch()); break; @@ -2129,8 +2142,10 @@ DoFAccessor::get_mg_dof_indices( case 2: { Assert(dof_indices.size() == - 4 * (this->dof_handler->get_fe(fe_index).dofs_per_vertex + - this->dof_handler->get_fe(fe_index).dofs_per_line) + + GeometryInfo<2>::vertices_per_cell * + this->dof_handler->get_fe(fe_index).dofs_per_vertex + + GeometryInfo<2>::lines_per_cell * + this->dof_handler->get_fe(fe_index).dofs_per_line + this->dof_handler->get_fe(fe_index).dofs_per_quad, ExcVectorDoesNotMatch()); break; @@ -2139,9 +2154,12 @@ DoFAccessor::get_mg_dof_indices( case 3: { Assert(dof_indices.size() == - 8 * this->dof_handler->get_fe(fe_index).dofs_per_vertex + - 12 * this->dof_handler->get_fe(fe_index).dofs_per_line + - 6 * this->dof_handler->get_fe(fe_index).dofs_per_quad + + GeometryInfo<3>::vertices_per_cell * + this->dof_handler->get_fe(fe_index).dofs_per_vertex + + GeometryInfo<3>::lines_per_cell * + this->dof_handler->get_fe(fe_index).dofs_per_line + + GeometryInfo<3>::faces_per_cell * + this->dof_handler->get_fe(fe_index).dofs_per_quad + this->dof_handler->get_fe(fe_index).dofs_per_hex, ExcVectorDoesNotMatch()); break; @@ -2172,7 +2190,8 @@ DoFAccessor::set_mg_dof_indices( case 1: { Assert(dof_indices.size() == - 2 * this->dof_handler->get_fe(fe_index).dofs_per_vertex + + GeometryInfo<1>::vertices_per_cell * + this->dof_handler->get_fe(fe_index).dofs_per_vertex + this->dof_handler->get_fe(fe_index).dofs_per_line, ExcVectorDoesNotMatch()); break; @@ -2181,8 +2200,10 @@ DoFAccessor::set_mg_dof_indices( case 2: { Assert(dof_indices.size() == - 4 * (this->dof_handler->get_fe(fe_index).dofs_per_vertex + - this->dof_handler->get_fe(fe_index).dofs_per_line) + + GeometryInfo<2>::vertices_per_cell * + this->dof_handler->get_fe(fe_index).dofs_per_vertex + + GeometryInfo<2>::lines_per_cell * + this->dof_handler->get_fe(fe_index).dofs_per_line + this->dof_handler->get_fe(fe_index).dofs_per_quad, ExcVectorDoesNotMatch()); break; @@ -2191,9 +2212,12 @@ DoFAccessor::set_mg_dof_indices( case 3: { Assert(dof_indices.size() == - 8 * this->dof_handler->get_fe(fe_index).dofs_per_vertex + - 12 * this->dof_handler->get_fe(fe_index).dofs_per_line + - 6 * this->dof_handler->get_fe(fe_index).dofs_per_quad + + GeometryInfo<3>::vertices_per_cell * + this->dof_handler->get_fe(fe_index).dofs_per_vertex + + GeometryInfo<3>::lines_per_cell * + this->dof_handler->get_fe(fe_index).dofs_per_line + + GeometryInfo<3>::faces_per_cell * + this->dof_handler->get_fe(fe_index).dofs_per_quad + this->dof_handler->get_fe(fe_index).dofs_per_hex, ExcVectorDoesNotMatch()); break; @@ -2764,7 +2788,9 @@ namespace internal ->cell_dof_indices_cache.begin() + accessor.present_index * dofs_per_cell); - for (unsigned int vertex = 0; vertex < 2; ++vertex) + for (unsigned int vertex = 0; + vertex < GeometryInfo<1>::vertices_per_cell; + ++vertex) for (unsigned int d = 0; d < dofs_per_vertex; ++d) *next++ = accessor.vertex_dof_index(vertex, d); for (unsigned int d = 0; d < dofs_per_line; ++d) @@ -2810,10 +2836,13 @@ namespace internal ->cell_dof_indices_cache.begin() + accessor.present_index * dofs_per_cell); - for (unsigned int vertex = 0; vertex < 4; ++vertex) + for (unsigned int vertex = 0; + vertex < GeometryInfo<2>::vertices_per_cell; + ++vertex) for (unsigned int d = 0; d < dofs_per_vertex; ++d) *next++ = accessor.vertex_dof_index(vertex, d); - for (unsigned int line = 0; line < 4; ++line) + for (unsigned int line = 0; line < GeometryInfo<2>::lines_per_cell; + ++line) for (unsigned int d = 0; d < dofs_per_line; ++d) *next++ = accessor.line(line)->dof_index(d); for (unsigned int d = 0; d < dofs_per_quad; ++d) @@ -2859,7 +2888,9 @@ namespace internal ->cell_dof_indices_cache.begin() + accessor.present_index * dofs_per_cell); - for (unsigned int vertex = 0; vertex < 8; ++vertex) + for (unsigned int vertex = 0; + vertex < GeometryInfo<3>::vertices_per_cell; + ++vertex) for (unsigned int d = 0; d < dofs_per_vertex; ++d) *next++ = accessor.vertex_dof_index(vertex, d); // now copy dof numbers from the line. for @@ -2873,7 +2904,8 @@ namespace internal // adjust the shape function indices that we // see to correspond to the correct // (cell-local) ordering. - for (unsigned int line = 0; line < 12; ++line) + for (unsigned int line = 0; line < GeometryInfo<3>::lines_per_cell; + ++line) for (unsigned int d = 0; d < dofs_per_line; ++d) *next++ = accessor.line(line)->dof_index( accessor.dof_handler->get_fe() @@ -2892,7 +2924,8 @@ namespace internal // correct (cell-local) ordering. The same // applies, if the face_rotation or // face_orientation is non-standard - for (unsigned int quad = 0; quad < 6; ++quad) + for (unsigned int quad = 0; quad < GeometryInfo<3>::faces_per_cell; + ++quad) for (unsigned int d = 0; d < dofs_per_quad; ++d) *next++ = accessor.quad(quad)->dof_index( accessor.dof_handler->get_fe() diff --git a/include/deal.II/grid/tria_accessor.templates.h b/include/deal.II/grid/tria_accessor.templates.h index a4b5d33003..b0832b3ca3 100644 --- a/include/deal.II/grid/tria_accessor.templates.h +++ b/include/deal.II/grid/tria_accessor.templates.h @@ -640,21 +640,22 @@ namespace internal // quad to take it, b) which line // therein it is if the face is // oriented correctly - static const unsigned int lookup_table[12][2] = { - {4, 0}, // take first four lines from bottom face - {4, 1}, - {4, 2}, - {4, 3}, - - {5, 0}, // second four lines from top face - {5, 1}, - {5, 2}, - {5, 3}, - - {0, 0}, // the rest randomly - {1, 0}, - {0, 1}, - {1, 1}}; + static const unsigned int + lookup_table[GeometryInfo<3>::lines_per_cell][2] = { + {4, 0}, // take first four lines from bottom face + {4, 1}, + {4, 2}, + {4, 3}, + + {5, 0}, // second four lines from top face + {5, 1}, + {5, 2}, + {5, 3}, + + {0, 0}, // the rest randomly + {1, 0}, + {0, 1}, + {1, 1}}; // respect non-standard faces by calling the // reordering function from GeometryInfo @@ -858,21 +859,22 @@ namespace internal // quad to take it, b) which line // therein it is if the face is // oriented correctly - static const unsigned int lookup_table[12][2] = { - {4, 0}, // take first four lines from bottom face - {4, 1}, - {4, 2}, - {4, 3}, - - {5, 0}, // second four lines from top face - {5, 1}, - {5, 2}, - {5, 3}, - - {0, 0}, // the rest randomly - {1, 0}, - {0, 1}, - {1, 1}}; + static const unsigned int + lookup_table[GeometryInfo<3>::lines_per_cell][2] = { + {4, 0}, // take first four lines from bottom face + {4, 1}, + {4, 2}, + {4, 3}, + + {5, 0}, // second four lines from top face + {5, 1}, + {5, 2}, + {5, 3}, + + {0, 0}, // the rest randomly + {1, 0}, + {0, 1}, + {1, 1}}; const unsigned int quad_index = lookup_table[line][0]; const unsigned int std_line_index = lookup_table[line][1]; -- 2.39.5