From: bangerth Date: Fri, 11 Aug 2006 12:21:26 +0000 (+0000) Subject: Unify a bunch of code into a single function that just uses a bit of template tricker... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=248f090b210c20284a9954743d7daad5faec37f8;p=dealii-svn.git Unify a bunch of code into a single function that just uses a bit of template trickery to achieve what it wants. git-svn-id: https://svn.dealii.org/trunk@13655 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/fe/fe_system.h b/deal.II/deal.II/include/fe/fe_system.h index 93c6edef0b..f09bd41d9f 100644 --- a/deal.II/deal.II/include/fe/fe_system.h +++ b/deal.II/deal.II/include/fe/fe_system.h @@ -814,6 +814,17 @@ class FESystem : public FiniteElement */ void build_interface_constraints (); + /** + * A function that computes the + * hp_vertex_dof_identities(), + * hp_line_dof_identities(), or + * hp_quad_dof_identities(), depending on + * the value of the template parameter. + */ + template + std::vector > + hp_object_dof_identities (const FiniteElement &fe_other) const; + /** * Usually: Fields of * cell-independent data. diff --git a/deal.II/deal.II/source/fe/fe_system.cc b/deal.II/deal.II/source/fe/fe_system.cc index 46b039ca19..afe286a289 100644 --- a/deal.II/deal.II/source/fe/fe_system.cc +++ b/deal.II/deal.II/source/fe/fe_system.cc @@ -1861,8 +1861,9 @@ hp_constraints_are_implemented () const template +template std::vector > -FESystem::hp_vertex_dof_identities (const FiniteElement &fe_other) const +FESystem::hp_object_dof_identities (const FiniteElement &fe_other) const { // since dofs on each subobject (vertex, // line, ...) are ordered such that first @@ -1915,8 +1916,21 @@ FESystem::hp_vertex_dof_identities (const FiniteElement &fe_other) con // returned by the base elements to // the indices of this system // element - const std::vector > - base_identities = base.hp_vertex_dof_identities (base_other); + std::vector > base_identities; + switch (structdim) + { + case 0: + base_identities = base.hp_vertex_dof_identities (base_other); + break; + case 1: + base_identities = base.hp_line_dof_identities (base_other); + break; + case 2: + base_identities = base.hp_quad_dof_identities (base_other); + break; + default: + Assert (false, ExcNotImplemented()); + } for (unsigned int i=0; i::hp_vertex_dof_identities (const FiniteElement &fe_other) con // record the dofs treated above as // already taken care of - dof_offset += base.dofs_per_vertex; - dof_offset_other += base_other.dofs_per_vertex; + dof_offset += base.template n_dofs_per_object(); + dof_offset_other += base_other.template n_dofs_per_object(); // advance to the next base element // for this and the other @@ -1980,118 +1994,16 @@ FESystem::hp_vertex_dof_identities (const FiniteElement &fe_other) con template std::vector > -FESystem::hp_line_dof_identities (const FiniteElement &fe_other) const +FESystem::hp_vertex_dof_identities (const FiniteElement &fe_other) const { - // since dofs on each subobject (vertex, - // line, ...) are ordered such that first - // come all from the first base element all - // multiplicities, then second base element - // all multiplicities, etc., we simply have - // to stack all the identities after each - // other - // - // the problem is that we have to work with - // two FEs (this and fe_other). only deal - // with the case that both are FESystems - // and that they both have the same number - // of bases (counting multiplicity) each of - // which match in their number of - // components. this covers - // FESystem(FE_Q(p),1,FE_Q(q),2) vs - // FESystem(FE_Q(r),2,FE_Q(s),1), but not - // FESystem(FE_Q(p),1,FE_Q(q),2) vs - // FESystem(FESystem(FE_Q(r),2),1,FE_Q(s),1) - if (const FESystem *fe_other_system - = dynamic_cast*>(&fe_other)) - { - // loop over all the base elements of - // this and the other element, counting - // their multiplicities - unsigned int base_index = 0, - base_index_other = 0; - unsigned int multiplicity = 0, - multiplicity_other = 0; - - // we also need to keep track of the - // number of dofs already treated for - // each of the elements - unsigned int dof_offset = 0, - dof_offset_other = 0; - - std::vector > identities; - - while (true) - { - const FiniteElement - &base = base_element(base_index), - &base_other = fe_other_system->base_element(base_index_other); - - Assert (base.n_components() == base_other.n_components(), - ExcNotImplemented()); - - // now translate the identities - // returned by the base elements to - // the indices of this system - // element - const std::vector > - base_identities = base.hp_line_dof_identities (base_other); - - for (unsigned int i=0; ielement_multiplicity(base_index_other)) - { - multiplicity_other = 0; - ++base_index_other; - } - - // see if we have reached the end - // of the present element. if so, - // we should have reached the end - // of the other one as well - if (base_index == n_base_elements()) - { - Assert (base_index_other == fe_other_system->n_base_elements(), - ExcInternalError()); - break; - } - - // if we haven't reached the end of - // this element, we shouldn't have - // reached the end of the other one - // either - Assert (base_index_other != fe_other_system->n_base_elements(), - ExcInternalError()); - } + return hp_object_dof_identities<0> (fe_other); +} - return identities; - } - else - { - Assert (false, ExcNotImplemented()); - return std::vector >(); - } +template +std::vector > +FESystem::hp_line_dof_identities (const FiniteElement &fe_other) const +{ + return hp_object_dof_identities<1> (fe_other); } @@ -2100,116 +2012,7 @@ template std::vector > FESystem::hp_quad_dof_identities (const FiniteElement &fe_other) const { - // since dofs on each subobject (vertex, - // line, ...) are ordered such that first - // come all from the first base element all - // multiplicities, then second base element - // all multiplicities, etc., we simply have - // to stack all the identities after each - // other - // - // the problem is that we have to work with - // two FEs (this and fe_other). only deal - // with the case that both are FESystems - // and that they both have the same number - // of bases (counting multiplicity) each of - // which match in their number of - // components. this covers - // FESystem(FE_Q(p),1,FE_Q(q),2) vs - // FESystem(FE_Q(r),2,FE_Q(s),1), but not - // FESystem(FE_Q(p),1,FE_Q(q),2) vs - // FESystem(FESystem(FE_Q(r),2),1,FE_Q(s),1) - if (const FESystem *fe_other_system - = dynamic_cast*>(&fe_other)) - { - // loop over all the base elements of - // this and the other element, counting - // their multiplicities - unsigned int base_index = 0, - base_index_other = 0; - unsigned int multiplicity = 0, - multiplicity_other = 0; - - // we also need to keep track of the - // number of dofs already treated for - // each of the elements - unsigned int dof_offset = 0, - dof_offset_other = 0; - - std::vector > identities; - - while (true) - { - const FiniteElement - &base = base_element(base_index), - &base_other = fe_other_system->base_element(base_index_other); - - Assert (base.n_components() == base_other.n_components(), - ExcNotImplemented()); - - // now translate the identities - // returned by the base elements to - // the indices of this system - // element - const std::vector > - base_identities = base.hp_quad_dof_identities (base_other); - - for (unsigned int i=0; ielement_multiplicity(base_index_other)) - { - multiplicity_other = 0; - ++base_index_other; - } - - // see if we have reached the end - // of the present element. if so, - // we should have reached the end - // of the other one as well - if (base_index == n_base_elements()) - { - Assert (base_index_other == fe_other_system->n_base_elements(), - ExcInternalError()); - break; - } - - // if we haven't reached the end of - // this element, we shouldn't have - // reached the end of the other one - // either - Assert (base_index_other != fe_other_system->n_base_elements(), - ExcInternalError()); - } - - return identities; - } - else - { - Assert (false, ExcNotImplemented()); - return std::vector >(); - } + return hp_object_dof_identities<2> (fe_other); }