From: David Wells Date: Thu, 24 Jun 2021 20:26:02 +0000 (-0400) Subject: Improve some checks for distributed Triangulations. X-Git-Tag: v9.4.0-rc1~1197^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=127dd400084854cb583b1b12bae74662f83876df;p=dealii.git Improve some checks for distributed Triangulations. --- diff --git a/include/deal.II/numerics/error_estimator.templates.h b/include/deal.II/numerics/error_estimator.templates.h index f0bdf44323..10b0f65550 100644 --- a/include/deal.II/numerics/error_estimator.templates.h +++ b/include/deal.II/numerics/error_estimator.templates.h @@ -24,7 +24,7 @@ #include #include -#include +#include #include #include @@ -1160,30 +1160,23 @@ KellyErrorEstimator::estimate( const types::material_id material_id, const Strategy strategy) { -#ifdef DEAL_II_WITH_P4EST - if (dynamic_cast *>( - &dof_handler.get_triangulation()) != nullptr) - Assert((subdomain_id_ == numbers::invalid_subdomain_id) || - (subdomain_id_ == - dynamic_cast< - const parallel::distributed::Triangulation &>( - dof_handler.get_triangulation()) - .locally_owned_subdomain()), - ExcMessage( - "For parallel distributed triangulations, the only " - "valid subdomain_id that can be passed here is the " - "one that corresponds to the locally owned subdomain id.")); - - const types::subdomain_id subdomain_id = - ((dynamic_cast *>( - &dof_handler.get_triangulation()) != nullptr) ? - dynamic_cast - &>(dof_handler.get_triangulation()) - .locally_owned_subdomain() : - subdomain_id_); -#else - const types::subdomain_id subdomain_id = subdomain_id_; -#endif + types::subdomain_id subdomain_id = numbers::invalid_subdomain_id; + if (const auto *triangulation = dynamic_cast< + const parallel::DistributedTriangulationBase *>( + &dof_handler.get_triangulation())) + { + Assert((subdomain_id_ == numbers::invalid_subdomain_id) || + (subdomain_id_ == triangulation->locally_owned_subdomain()), + ExcMessage( + "For distributed Triangulation objects and associated " + "DoFHandler objects, asking for any subdomain other than the " + "locally owned one does not make sense.")); + subdomain_id = triangulation->locally_owned_subdomain(); + } + else + { + subdomain_id = subdomain_id_; + } const unsigned int n_components = dof_handler.get_fe(0).n_components(); (void)n_components; diff --git a/source/dofs/dof_tools_sparsity.cc b/source/dofs/dof_tools_sparsity.cc index 887f7d9adf..7f049f6e3b 100644 --- a/source/dofs/dof_tools_sparsity.cc +++ b/source/dofs/dof_tools_sparsity.cc @@ -75,18 +75,20 @@ namespace DoFTools Assert(sparsity.n_cols() == n_dofs, ExcDimensionMismatch(sparsity.n_cols(), n_dofs)); - // If we have a distributed::Triangulation only allow locally_owned + // If we have a distributed Triangulation only allow locally_owned // subdomain. Not setting a subdomain is also okay, because we skip // ghost cells in the loop below. - Assert((dof.get_triangulation().locally_owned_subdomain() == - numbers::invalid_subdomain_id) || - (subdomain_id == numbers::invalid_subdomain_id) || - (subdomain_id == - dof.get_triangulation().locally_owned_subdomain()), - ExcMessage( - "For parallel::distributed::Triangulation objects and " - "associated DoF handler objects, asking for any subdomain other " - "than the locally owned one does not make sense.")); + if (const auto *triangulation = dynamic_cast< + const parallel::DistributedTriangulationBase *>( + &dof.get_triangulation())) + { + Assert((subdomain_id == numbers::invalid_subdomain_id) || + (subdomain_id == triangulation->locally_owned_subdomain()), + ExcMessage( + "For distributed Triangulation objects and associated " + "DoFHandler objects, asking for any subdomain other than the " + "locally owned one does not make sense.")); + } std::vector dofs_on_this_cell; dofs_on_this_cell.reserve(dof.get_fe_collection().max_dofs_per_cell()); @@ -143,18 +145,20 @@ namespace DoFTools ExcDimensionMismatch(couplings.n_cols(), dof.get_fe(0).n_components())); - // If we have a distributed::Triangulation only allow locally_owned + // If we have a distributed Triangulation only allow locally_owned // subdomain. Not setting a subdomain is also okay, because we skip // ghost cells in the loop below. - Assert((dof.get_triangulation().locally_owned_subdomain() == - numbers::invalid_subdomain_id) || - (subdomain_id == numbers::invalid_subdomain_id) || - (subdomain_id == - dof.get_triangulation().locally_owned_subdomain()), - ExcMessage( - "For parallel::distributed::Triangulation objects and " - "associated DoF handler objects, asking for any subdomain other " - "than the locally owned one does not make sense.")); + if (const auto *triangulation = dynamic_cast< + const parallel::DistributedTriangulationBase *>( + &dof.get_triangulation())) + { + Assert((subdomain_id == numbers::invalid_subdomain_id) || + (subdomain_id == triangulation->locally_owned_subdomain()), + ExcMessage( + "For distributed Triangulation objects and associated " + "DoFHandler objects, asking for any subdomain other than the " + "locally owned one does not make sense.")); + } const hp::FECollection &fe_collection = dof.get_fe_collection(); @@ -541,18 +545,20 @@ namespace DoFTools AssertDimension(sparsity.n_rows(), n_dofs); AssertDimension(sparsity.n_cols(), n_dofs); - // If we have a distributed::Triangulation only allow locally_owned + // If we have a distributed Triangulation only allow locally_owned // subdomain. Not setting a subdomain is also okay, because we skip // ghost cells in the loop below. - Assert((dof.get_triangulation().locally_owned_subdomain() == - numbers::invalid_subdomain_id) || - (subdomain_id == numbers::invalid_subdomain_id) || - (subdomain_id == - dof.get_triangulation().locally_owned_subdomain()), - ExcMessage( - "For parallel::distributed::Triangulation objects and " - "associated DoF handler objects, asking for any subdomain other " - "than the locally owned one does not make sense.")); + if (const auto *triangulation = dynamic_cast< + const parallel::DistributedTriangulationBase *>( + &dof.get_triangulation())) + { + Assert((subdomain_id == numbers::invalid_subdomain_id) || + (subdomain_id == triangulation->locally_owned_subdomain()), + ExcMessage( + "For distributed Triangulation objects and associated " + "DoFHandler objects, asking for any subdomain other than the " + "locally owned one does not make sense.")); + } std::vector dofs_on_this_cell; std::vector dofs_on_other_cell; @@ -1428,18 +1434,20 @@ namespace DoFTools Assert(flux_mask.n_cols() == n_comp, ExcDimensionMismatch(flux_mask.n_cols(), n_comp)); - // If we have a distributed::Triangulation only allow locally_owned + // If we have a distributed Triangulation only allow locally_owned // subdomain. Not setting a subdomain is also okay, because we skip // ghost cells in the loop below. - Assert((dof.get_triangulation().locally_owned_subdomain() == - numbers::invalid_subdomain_id) || - (subdomain_id == numbers::invalid_subdomain_id) || - (subdomain_id == - dof.get_triangulation().locally_owned_subdomain()), - ExcMessage( - "For parallel::distributed::Triangulation objects and " - "associated DoF handler objects, asking for any subdomain other " - "than the locally owned one does not make sense.")); + if (const auto *triangulation = dynamic_cast< + const parallel::DistributedTriangulationBase *>( + &dof.get_triangulation())) + { + Assert((subdomain_id == numbers::invalid_subdomain_id) || + (subdomain_id == triangulation->locally_owned_subdomain()), + ExcMessage( + "For distributed Triangulation objects and associated " + "DoFHandler objects, asking for any subdomain other than the " + "locally owned one does not make sense.")); + } Assert( face_has_flux_coupling, diff --git a/source/numerics/error_estimator_1d.cc b/source/numerics/error_estimator_1d.cc index 5a098cc9f6..8e11d0f6d8 100644 --- a/source/numerics/error_estimator_1d.cc +++ b/source/numerics/error_estimator_1d.cc @@ -18,7 +18,7 @@ #include #include -#include +#include #include #include @@ -311,31 +311,24 @@ KellyErrorEstimator<1, spacedim>::estimate( const Strategy strategy) { AssertThrow(strategy == cell_diameter_over_24, ExcNotImplemented()); - using number = typename InputVector::value_type; -#ifdef DEAL_II_WITH_P4EST - if (dynamic_cast *>( - &dof_handler.get_triangulation()) != nullptr) - Assert((subdomain_id_ == numbers::invalid_subdomain_id) || - (subdomain_id_ == - dynamic_cast< - const parallel::distributed::Triangulation<1, spacedim> &>( - dof_handler.get_triangulation()) - .locally_owned_subdomain()), - ExcMessage( - "For parallel distributed triangulations, the only " - "valid subdomain_id that can be passed here is the " - "one that corresponds to the locally owned subdomain id.")); - - const types::subdomain_id subdomain_id = - ((dynamic_cast *>( - &dof_handler.get_triangulation()) != nullptr) ? - dynamic_cast &>( - dof_handler.get_triangulation()) - .locally_owned_subdomain() : - subdomain_id_); -#else - const types::subdomain_id subdomain_id = subdomain_id_; -#endif + using number = typename InputVector::value_type; + types::subdomain_id subdomain_id = numbers::invalid_subdomain_id; + if (const auto *triangulation = dynamic_cast< + const parallel::DistributedTriangulationBase<1, spacedim> *>( + &dof_handler.get_triangulation())) + { + Assert((subdomain_id_ == numbers::invalid_subdomain_id) || + (subdomain_id_ == triangulation->locally_owned_subdomain()), + ExcMessage( + "For distributed Triangulation objects and associated " + "DoFHandler objects, asking for any subdomain other than the " + "locally owned one does not make sense.")); + subdomain_id = triangulation->locally_owned_subdomain(); + } + else + { + subdomain_id = subdomain_id_; + } const unsigned int n_components = dof_handler.get_fe(0).n_components(); const unsigned int n_solution_vectors = solutions.size();