From d44e81c73496786648131274811d03a8f52ca080 Mon Sep 17 00:00:00 2001 From: David Wells Date: Sat, 31 Mar 2018 16:33:54 -0400 Subject: [PATCH] Explicitly check the result of a dynamic_cast. --- source/fe/fe_system.cc | 134 +++++++++++++++++++++-------------------- 1 file changed, 70 insertions(+), 64 deletions(-) diff --git a/source/fe/fe_system.cc b/source/fe/fe_system.cc index 81c9671f1d..75ff4b2008 100644 --- a/source/fe/fe_system.cc +++ b/source/fe/fe_system.cc @@ -1883,80 +1883,86 @@ get_subface_interpolation_matrix (const FiniteElement &x_source_fe // FESystem(FESystem(FE_Q(r),2),1,FE_Q(s),1) const FESystem *fe_other_system = dynamic_cast*>(&x_source_fe); + if (fe_other_system != nullptr) + { + // clear matrix, since we will not get to set all elements + interpolation_matrix = 0; - // clear matrix, since we will not get to set all elements - interpolation_matrix = 0; - - // 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; + // 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; - FullMatrix base_to_base_interpolation; + FullMatrix base_to_base_interpolation; - while (true) - { - const FiniteElement - &base = base_element(base_index), - &base_other = fe_other_system->base_element(base_index_other); + 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()); + Assert (base.n_components() == base_other.n_components(), + ExcNotImplemented()); - // get the interpolation from the bases - base_to_base_interpolation.reinit (base_other.dofs_per_face, - base.dofs_per_face); - base.get_subface_interpolation_matrix (base_other, - subface, - base_to_base_interpolation); + // get the interpolation from the bases + base_to_base_interpolation.reinit (base_other.dofs_per_face, + base.dofs_per_face); + base.get_subface_interpolation_matrix (base_other, + subface, + base_to_base_interpolation); - // now translate entries. we'd like to have something like - // face_base_to_system_index, but that doesn't exist. rather, all we - // have is the reverse. well, use that then - for (unsigned int i=0; idofs_per_face; ++i) - if (this->face_system_to_base_index(i).first - == - std::make_pair (base_index, multiplicity)) - for (unsigned int j=0; jdofs_per_face; ++j) - if (fe_other_system->face_system_to_base_index(j).first + // now translate entries. we'd like to have something like + // face_base_to_system_index, but that doesn't exist. rather, all we + // have is the reverse. well, use that then + for (unsigned int i=0; idofs_per_face; ++i) + if (this->face_system_to_base_index(i).first == - std::make_pair (base_index_other, multiplicity_other)) - interpolation_matrix(j, i) - = base_to_base_interpolation(fe_other_system->face_system_to_base_index(j).second, - this->face_system_to_base_index(i).second); - - // advance to the next base element for this and the other fe_system; - // see if we can simply advance the multiplicity by one, or if have to - // move on to the next base element - ++multiplicity; - if (multiplicity == this->element_multiplicity(base_index)) - { - multiplicity = 0; - ++base_index; - } - ++multiplicity_other; - if (multiplicity_other == - fe_other_system->element_multiplicity(base_index_other)) - { - multiplicity_other = 0; - ++base_index_other; - } + std::make_pair (base_index, multiplicity)) + for (unsigned int j=0; jdofs_per_face; ++j) + if (fe_other_system->face_system_to_base_index(j).first + == + std::make_pair (base_index_other, multiplicity_other)) + interpolation_matrix(j, i) + = base_to_base_interpolation(fe_other_system->face_system_to_base_index(j).second, + this->face_system_to_base_index(i).second); - // 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 == this->n_base_elements()) - { - Assert (base_index_other == fe_other_system->n_base_elements(), + // advance to the next base element for this and the other fe_system; + // see if we can simply advance the multiplicity by one, or if have to + // move on to the next base element + ++multiplicity; + if (multiplicity == this->element_multiplicity(base_index)) + { + multiplicity = 0; + ++base_index; + } + ++multiplicity_other; + if (multiplicity_other == + fe_other_system->element_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 == this->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()); - 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()); + } + else + { + Assert(fe_other_system != nullptr, ExcInternalError()); } } -- 2.39.5