From: Wolfgang Bangerth Date: Thu, 26 Oct 2023 19:58:31 +0000 (-0600) Subject: Use RefinementCase::all_refinement_cases() and assorted cleanups. X-Git-Tag: relicensing~344^2~2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=42fb1612c6eecba1d563f693c355f001867707ec;p=dealii.git Use RefinementCase::all_refinement_cases() and assorted cleanups. --- diff --git a/include/deal.II/fe/fe_tools.templates.h b/include/deal.II/fe/fe_tools.templates.h index f093b1bb6d..dc6b6570ec 100644 --- a/include/deal.II/fe/fe_tools.templates.h +++ b/include/deal.II/fe/fe_tools.templates.h @@ -1865,11 +1865,11 @@ namespace FETools Threads::TaskGroup task_group; // loop over all possible refinement cases - unsigned int ref_case = (isotropic_only) ? - RefinementCase::isotropic_refinement : - RefinementCase::cut_x; - - for (; ref_case <= RefinementCase::isotropic_refinement; ++ref_case) + for (unsigned int ref_case = + (isotropic_only ? RefinementCase::isotropic_refinement : + RefinementCase::cut_x); + ref_case <= RefinementCase::isotropic_refinement; + ++ref_case) task_group += Threads::new_task( &internal::FEToolsComputeEmbeddingMatricesHelper:: compute_embedding_matrices_for_refinement_case, @@ -2270,10 +2270,11 @@ namespace FETools // finally loop over all possible refinement cases Threads::TaskGroup<> tasks; - unsigned int ref_case = (isotropic_only) ? - RefinementCase::isotropic_refinement : - RefinementCase::cut_x; - for (; ref_case <= RefinementCase::isotropic_refinement; ++ref_case) + for (unsigned int ref_case = + (isotropic_only ? RefinementCase::isotropic_refinement : + RefinementCase::cut_x); + ref_case <= RefinementCase::isotropic_refinement; + ++ref_case) tasks += Threads::new_task([&, ref_case]() { compute_one_case(ref_case, mass, matrices[ref_case - 1]); }); diff --git a/source/fe/fe.cc b/source/fe/fe.cc index 9dd634495c..a1ca2bac05 100644 --- a/source/fe/fe.cc +++ b/source/fe/fe.cc @@ -135,17 +135,17 @@ FiniteElement::FiniteElement( // constructor of FullMatrix initializes them with size zero prolongation.resize(RefinementCase::isotropic_refinement); restriction.resize(RefinementCase::isotropic_refinement); - for (unsigned int ref = RefinementCase::cut_x; - ref < RefinementCase::isotropic_refinement + 1; - ++ref) - { - prolongation[ref - 1].resize(GeometryInfo::n_children( - RefinementCase(ref)), - FullMatrix()); - restriction[ref - 1].resize(GeometryInfo::n_children( - RefinementCase(ref)), - FullMatrix()); - } + for (const unsigned int ref_case : + RefinementCase::all_refinement_cases()) + if (ref_case != RefinementCase::no_refinement) + { + prolongation[ref - 1].resize(GeometryInfo::n_children( + RefinementCase(ref)), + FullMatrix()); + restriction[ref - 1].resize(GeometryInfo::n_children( + RefinementCase(ref)), + FullMatrix()); + } if (dim == 3) @@ -300,29 +300,29 @@ FiniteElement::reinit_restriction_and_prolongation_matrices( const bool isotropic_restriction_only, const bool isotropic_prolongation_only) { - for (unsigned int ref_case = RefinementCase::cut_x; - ref_case <= RefinementCase::isotropic_refinement; - ++ref_case) - { - const unsigned int nc = - GeometryInfo::n_children(RefinementCase(ref_case)); - - for (unsigned int i = 0; i < nc; ++i) - { - if (this->restriction[ref_case - 1][i].m() != - this->n_dofs_per_cell() && - (!isotropic_restriction_only || - ref_case == RefinementCase::isotropic_refinement)) - this->restriction[ref_case - 1][i].reinit(this->n_dofs_per_cell(), - this->n_dofs_per_cell()); - if (this->prolongation[ref_case - 1][i].m() != - this->n_dofs_per_cell() && - (!isotropic_prolongation_only || - ref_case == RefinementCase::isotropic_refinement)) - this->prolongation[ref_case - 1][i].reinit(this->n_dofs_per_cell(), - this->n_dofs_per_cell()); - } - } + for (const unsigned int ref_case : + RefinementCase::all_refinement_cases()) + if (ref_case != RefinementCase::no_refinement) + { + const unsigned int nc = + GeometryInfo::n_children(RefinementCase(ref_case)); + + for (unsigned int i = 0; i < nc; ++i) + { + if (this->restriction[ref_case - 1][i].m() != + this->n_dofs_per_cell() && + (!isotropic_restriction_only || + ref_case == RefinementCase::isotropic_refinement)) + this->restriction[ref_case - 1][i].reinit( + this->n_dofs_per_cell(), this->n_dofs_per_cell()); + if (this->prolongation[ref_case - 1][i].m() != + this->n_dofs_per_cell() && + (!isotropic_prolongation_only || + ref_case == RefinementCase::isotropic_refinement)) + this->prolongation[ref_case - 1][i].reinit( + this->n_dofs_per_cell(), this->n_dofs_per_cell()); + } + } } @@ -722,25 +722,27 @@ template bool FiniteElement::prolongation_is_implemented() const { - for (unsigned int ref_case = RefinementCase::cut_x; - ref_case < RefinementCase::isotropic_refinement + 1; - ++ref_case) - for (unsigned int c = 0; - c < GeometryInfo::n_children(RefinementCase(ref_case)); - ++c) - { - // make sure also the lazily initialized matrices are created - get_prolongation_matrix(c, RefinementCase(ref_case)); - Assert((prolongation[ref_case - 1][c].m() == this->n_dofs_per_cell()) || - (prolongation[ref_case - 1][c].m() == 0), - ExcInternalError()); - Assert((prolongation[ref_case - 1][c].n() == this->n_dofs_per_cell()) || - (prolongation[ref_case - 1][c].n() == 0), - ExcInternalError()); - if ((prolongation[ref_case - 1][c].m() == 0) || - (prolongation[ref_case - 1][c].n() == 0)) - return false; - } + for (const unsigned int ref_case : + RefinementCase::all_refinement_cases()) + if (ref_case != RefinementCase::no_refinement) + for (unsigned int c = 0; + c < GeometryInfo::n_children(RefinementCase(ref_case)); + ++c) + { + // make sure also the lazily initialized matrices are created + get_prolongation_matrix(c, RefinementCase(ref_case)); + Assert((prolongation[ref_case - 1][c].m() == + this->n_dofs_per_cell()) || + (prolongation[ref_case - 1][c].m() == 0), + ExcInternalError()); + Assert((prolongation[ref_case - 1][c].n() == + this->n_dofs_per_cell()) || + (prolongation[ref_case - 1][c].n() == 0), + ExcInternalError()); + if ((prolongation[ref_case - 1][c].m() == 0) || + (prolongation[ref_case - 1][c].n() == 0)) + return false; + } return true; } @@ -750,25 +752,27 @@ template bool FiniteElement::restriction_is_implemented() const { - for (unsigned int ref_case = RefinementCase::cut_x; - ref_case < RefinementCase::isotropic_refinement + 1; - ++ref_case) - for (unsigned int c = 0; - c < GeometryInfo::n_children(RefinementCase(ref_case)); - ++c) - { - // make sure also the lazily initialized matrices are created - get_restriction_matrix(c, RefinementCase(ref_case)); - Assert((restriction[ref_case - 1][c].m() == this->n_dofs_per_cell()) || - (restriction[ref_case - 1][c].m() == 0), - ExcInternalError()); - Assert((restriction[ref_case - 1][c].n() == this->n_dofs_per_cell()) || - (restriction[ref_case - 1][c].n() == 0), - ExcInternalError()); - if ((restriction[ref_case - 1][c].m() == 0) || - (restriction[ref_case - 1][c].n() == 0)) - return false; - } + for (const unsigned int ref_case : + RefinementCase::all_refinement_cases()) + if (ref_case != RefinementCase::no_refinement) + for (unsigned int c = 0; + c < GeometryInfo::n_children(RefinementCase(ref_case)); + ++c) + { + // make sure also the lazily initialized matrices are created + get_restriction_matrix(c, RefinementCase(ref_case)); + Assert((restriction[ref_case - 1][c].m() == + this->n_dofs_per_cell()) || + (restriction[ref_case - 1][c].m() == 0), + ExcInternalError()); + Assert((restriction[ref_case - 1][c].n() == + this->n_dofs_per_cell()) || + (restriction[ref_case - 1][c].n() == 0), + ExcInternalError()); + if ((restriction[ref_case - 1][c].m() == 0) || + (restriction[ref_case - 1][c].n() == 0)) + return false; + } return true; } diff --git a/source/fe/fe_dgp_nonparametric.cc b/source/fe/fe_dgp_nonparametric.cc index 21e3f9e434..2e391ff178 100644 --- a/source/fe/fe_dgp_nonparametric.cc +++ b/source/fe/fe_dgp_nonparametric.cc @@ -52,27 +52,27 @@ FE_DGPNonparametric::FE_DGPNonparametric( , polynomial_space(Polynomials::Legendre::generate_complete_basis(degree)) { const unsigned int n_dofs = this->n_dofs_per_cell(); - for (unsigned int ref_case = RefinementCase::cut_x; - ref_case < RefinementCase::isotropic_refinement + 1; - ++ref_case) - { - if (dim != 2 && ref_case != RefinementCase::isotropic_refinement) - // do nothing, as anisotropic - // refinement is not - // implemented so far - continue; - - const unsigned int nc = - GeometryInfo::n_children(RefinementCase(ref_case)); - for (unsigned int i = 0; i < nc; ++i) - { - this->prolongation[ref_case - 1][i].reinit(n_dofs, n_dofs); - // Fill prolongation matrices with - // embedding operators - for (unsigned int j = 0; j < n_dofs; ++j) - this->prolongation[ref_case - 1][i](j, j) = 1.; - } - } + for (const unsigned int ref_case : + RefinementCase::all_refinement_cases()) + if (ref_case != RefinementCase::no_refinement) + { + if (dim != 2 && ref_case != RefinementCase::isotropic_refinement) + // do nothing, as anisotropic + // refinement is not + // implemented so far + continue; + + const unsigned int nc = + GeometryInfo::n_children(RefinementCase(ref_case)); + for (unsigned int i = 0; i < nc; ++i) + { + this->prolongation[ref_case - 1][i].reinit(n_dofs, n_dofs); + // Fill prolongation matrices with + // embedding operators + for (unsigned int j = 0; j < n_dofs; ++j) + this->prolongation[ref_case - 1][i](j, j) = 1.; + } + } // restriction can be defined // through projection for diff --git a/source/fe/fe_q_bubbles.cc b/source/fe/fe_q_bubbles.cc index 274ace01a7..ef72b4cd71 100644 --- a/source/fe/fe_q_bubbles.cc +++ b/source/fe/fe_q_bubbles.cc @@ -92,10 +92,10 @@ namespace internal const unsigned int nq = q_fine->size(); // loop over all possible refinement cases - unsigned int ref_case = (isotropic_only) ? - RefinementCase::isotropic_refinement : - RefinementCase::cut_x; - for (; ref_case <= RefinementCase::isotropic_refinement; + for (unsigned int ref_case = + (isotropic_only ? RefinementCase::isotropic_refinement : + RefinementCase::cut_x); + ref_case <= RefinementCase::isotropic_refinement; ++ref_case) { const unsigned int nc = diff --git a/source/fe/fe_rt_bubbles.cc b/source/fe/fe_rt_bubbles.cc index 25ff68000c..5613c5ea28 100644 --- a/source/fe/fe_rt_bubbles.cc +++ b/source/fe/fe_rt_bubbles.cc @@ -68,16 +68,16 @@ FE_RT_Bubbles::FE_RT_Bubbles(const unsigned int deg) // Reinit the vectors of prolongation matrices to the // right sizes. There are no restriction matrices implemented - for (unsigned int ref_case = RefinementCase::cut_x; - ref_case < RefinementCase::isotropic_refinement + 1; - ++ref_case) - { - const unsigned int nc = - GeometryInfo::n_children(RefinementCase(ref_case)); + for (const unsigned int ref_case : + RefinementCase::all_refinement_cases()) + if (ref_case != RefinementCase::no_refinement) + { + const unsigned int nc = + GeometryInfo::n_children(RefinementCase(ref_case)); - for (unsigned int i = 0; i < nc; ++i) - this->prolongation[ref_case - 1][i].reinit(n_dofs, n_dofs); - } + for (unsigned int i = 0; i < nc; ++i) + this->prolongation[ref_case - 1][i].reinit(n_dofs, n_dofs); + } // TODO: the implementation makes the assumption that all faces have the // same number of dofs