From: Peter Munch Date: Thu, 4 Mar 2021 20:34:35 +0000 (+0100) Subject: Use get_communicator() X-Git-Tag: v9.3.0-rc1~373^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c0d58e074018039d7d4e1b86642d97fdc086cae0;p=dealii.git Use get_communicator() --- diff --git a/include/deal.II/dofs/dof_handler.h b/include/deal.II/dofs/dof_handler.h index df5a1ec44b..21687df85e 100644 --- a/include/deal.II/dofs/dof_handler.h +++ b/include/deal.II/dofs/dof_handler.h @@ -1945,20 +1945,10 @@ DoFHandler::n_locally_owned_dofs_per_processor() const if (number_cache.n_locally_owned_dofs_per_processor.empty() && number_cache.n_global_dofs > 0) { - MPI_Comm comm; - - const parallel::TriangulationBase *tr = - (dynamic_cast *>( - &this->get_triangulation())); - if (tr != nullptr) - comm = tr->get_communicator(); - else - comm = MPI_COMM_SELF; - const_cast( number_cache) .n_locally_owned_dofs_per_processor = - number_cache.get_n_locally_owned_dofs_per_processor(comm); + number_cache.get_n_locally_owned_dofs_per_processor(get_communicator()); } return number_cache.n_locally_owned_dofs_per_processor; } @@ -1972,20 +1962,10 @@ DoFHandler::locally_owned_dofs_per_processor() const if (number_cache.locally_owned_dofs_per_processor.empty() && number_cache.n_global_dofs > 0) { - MPI_Comm comm; - - const parallel::TriangulationBase *tr = - (dynamic_cast *>( - &this->get_triangulation())); - if (tr != nullptr) - comm = tr->get_communicator(); - else - comm = MPI_COMM_SELF; - const_cast( number_cache) .locally_owned_dofs_per_processor = - number_cache.get_locally_owned_dofs_per_processor(comm); + number_cache.get_locally_owned_dofs_per_processor(get_communicator()); } return number_cache.locally_owned_dofs_per_processor; } @@ -2007,20 +1987,11 @@ DoFHandler::locally_owned_mg_dofs_per_processor( if (mg_number_cache[level].locally_owned_dofs_per_processor.empty() && mg_number_cache[level].n_global_dofs > 0) { - MPI_Comm comm; - - const parallel::TriangulationBase *tr = - (dynamic_cast *>( - &this->get_triangulation())); - if (tr != nullptr) - comm = tr->get_communicator(); - else - comm = MPI_COMM_SELF; - const_cast( mg_number_cache[level]) .locally_owned_dofs_per_processor = - mg_number_cache[level].get_locally_owned_dofs_per_processor(comm); + mg_number_cache[level].get_locally_owned_dofs_per_processor( + get_communicator()); } return mg_number_cache[level].locally_owned_dofs_per_processor; } diff --git a/include/deal.II/multigrid/mg_transfer.h b/include/deal.II/multigrid/mg_transfer.h index 370a3c156e..ab97964760 100644 --- a/include/deal.II/multigrid/mg_transfer.h +++ b/include/deal.II/multigrid/mg_transfer.h @@ -84,12 +84,7 @@ namespace internal const SparsityPatternType & sp, const DoFHandler &dh) { - const dealii::parallel::TriangulationBase *dist_tria = - dynamic_cast< - const dealii::parallel::TriangulationBase *>( - &(dh.get_triangulation())); - MPI_Comm communicator = - dist_tria != nullptr ? dist_tria->get_communicator() : MPI_COMM_SELF; + const MPI_Comm communicator = dh.get_communicator(); matrix.reinit(dh.locally_owned_mg_dofs(level + 1), dh.locally_owned_mg_dofs(level), @@ -115,12 +110,8 @@ namespace internal const SparsityPatternType & sp, const DoFHandler &dh) { - const dealii::parallel::TriangulationBase *dist_tria = - dynamic_cast< - const dealii::parallel::TriangulationBase *>( - &(dh.get_triangulation())); - MPI_Comm communicator = - dist_tria != nullptr ? dist_tria->get_communicator() : MPI_COMM_SELF; + const MPI_Comm communicator = dh.get_communicator(); + matrix.reinit(dh.locally_owned_mg_dofs(level + 1), dh.locally_owned_mg_dofs(level), sp, @@ -147,12 +138,8 @@ namespace internal const SparsityPatternType & sp, const DoFHandler &dh) { - const dealii::parallel::TriangulationBase *dist_tria = - dynamic_cast< - const dealii::parallel::TriangulationBase *>( - &(dh.get_triangulation())); - MPI_Comm communicator = - dist_tria != nullptr ? dist_tria->get_communicator() : MPI_COMM_SELF; + const MPI_Comm communicator = dh.get_communicator(); + matrix.reinit(dh.locally_owned_mg_dofs(level + 1), dh.locally_owned_mg_dofs(level), sp, @@ -178,12 +165,8 @@ namespace internal const SparsityPatternType & sp, const DoFHandler &dh) { - const dealii::parallel::TriangulationBase *dist_tria = - dynamic_cast< - const dealii::parallel::TriangulationBase *>( - &(dh.get_triangulation())); - MPI_Comm communicator = - dist_tria != nullptr ? dist_tria->get_communicator() : MPI_COMM_SELF; + const MPI_Comm communicator = dh.get_communicator(); + matrix.reinit(dh.locally_owned_mg_dofs(level + 1), dh.locally_owned_mg_dofs(level), sp, @@ -238,12 +221,8 @@ namespace internal const SparsityPatternType & sp, const DoFHandler &dh) { - const dealii::parallel::TriangulationBase *dist_tria = - dynamic_cast< - const dealii::parallel::TriangulationBase *>( - &(dh.get_triangulation())); - MPI_Comm communicator = - dist_tria != nullptr ? dist_tria->get_communicator() : MPI_COMM_SELF; + const MPI_Comm communicator = dh.get_communicator(); + // Reinit PETSc matrix matrix.reinit(dh.locally_owned_mg_dofs(level + 1), dh.locally_owned_mg_dofs(level), diff --git a/include/deal.II/multigrid/mg_transfer.templates.h b/include/deal.II/multigrid/mg_transfer.templates.h index 3554957ffe..9153d0c915 100644 --- a/include/deal.II/multigrid/mg_transfer.templates.h +++ b/include/deal.II/multigrid/mg_transfer.templates.h @@ -443,13 +443,8 @@ MGLevelGlobalTransfer>::copy_to_mg( dst[level].reinit(ghosted_level_vector[level], false); else { - const dealii::parallel::TriangulationBase *tria = - (dynamic_cast< - const dealii::parallel::TriangulationBase *>( - &dof_handler.get_triangulation())); dst[level].reinit(dof_handler.locally_owned_mg_dofs(level), - tria != nullptr ? tria->get_communicator() : - MPI_COMM_SELF); + dof_handler.get_communicator()); } } else if ((perform_plain_copy == false && diff --git a/include/deal.II/multigrid/mg_transfer_matrix_free.h b/include/deal.II/multigrid/mg_transfer_matrix_free.h index 210aa36a1b..be7d526ea5 100644 --- a/include/deal.II/multigrid/mg_transfer_matrix_free.h +++ b/include/deal.II/multigrid/mg_transfer_matrix_free.h @@ -674,8 +674,7 @@ MGTransferBlockMatrixFree::copy_to_mg( LinearAlgebra::distributed::Vector &v = dst[level].block(b); v.reinit(dof_handler[b]->locally_owned_mg_dofs(level), - tria != nullptr ? tria->get_communicator() : - MPI_COMM_SELF); + dof_handler[b]->get_communicator()); } dst[level].collect_sizes(); } diff --git a/include/deal.II/numerics/vector_tools_integrate_difference.templates.h b/include/deal.II/numerics/vector_tools_integrate_difference.templates.h index 4e77bd2fce..29c7a84b9d 100644 --- a/include/deal.II/numerics/vector_tools_integrate_difference.templates.h +++ b/include/deal.II/numerics/vector_tools_integrate_difference.templates.h @@ -1260,13 +1260,7 @@ namespace VectorTools } #endif - MPI_Comm comm = MPI_COMM_SELF; -#ifdef DEAL_II_WITH_MPI - if (const parallel::TriangulationBase *ptria = - dynamic_cast *>( - &tria)) - comm = ptria->get_communicator(); -#endif + const MPI_Comm comm = tria.get_communicator(); switch (norm) { diff --git a/source/multigrid/mg_level_global_transfer.cc b/source/multigrid/mg_level_global_transfer.cc index 51ffc58d02..abcc0d3d58 100644 --- a/source/multigrid/mg_level_global_transfer.cc +++ b/source/multigrid/mg_level_global_transfer.cc @@ -284,11 +284,7 @@ void MGLevelGlobalTransfer>:: fill_and_communicate_copy_indices(const DoFHandler &mg_dof) { - const parallel::TriangulationBase *ptria = - dynamic_cast *>( - &mg_dof.get_triangulation()); - const MPI_Comm mpi_communicator = - ptria != nullptr ? ptria->get_communicator() : MPI_COMM_SELF; + const MPI_Comm mpi_communicator = mg_dof.get_communicator(); fill_internal(mg_dof, mg_constrained_dofs, diff --git a/source/multigrid/mg_transfer_internal.cc b/source/multigrid/mg_transfer_internal.cc index 99106b8e3c..d6405b17fc 100644 --- a/source/multigrid/mg_transfer_internal.cc +++ b/source/multigrid/mg_transfer_internal.cc @@ -946,18 +946,12 @@ namespace internal // the base class for keeping ghosted transfer indices. To avoid // keeping two very similar vectors, we keep one single ghosted // vector that is augmented/filled here. - const dealii::parallel::TriangulationBase *ptria = - (dynamic_cast< - const dealii::parallel::TriangulationBase *>(&tria)); - const MPI_Comm communicator = - ptria != nullptr ? ptria->get_communicator() : MPI_COMM_SELF; - reinit_level_partitioner(dof_handler.locally_owned_mg_dofs(level), ghosted_level_dofs, external_partitioners.empty() ? nullptr : external_partitioners[level], - communicator, + tria.get_communicator(), target_partitioners[level], copy_indices_global_mine[level]); @@ -976,7 +970,7 @@ namespace internal external_partitioners.empty() ? nullptr : external_partitioners[0], - communicator, + tria.get_communicator(), target_partitioners[0], copy_indices_global_mine[0]); diff --git a/source/multigrid/mg_transfer_prebuilt.cc b/source/multigrid/mg_transfer_prebuilt.cc index 472942fa46..5c576eca65 100644 --- a/source/multigrid/mg_transfer_prebuilt.cc +++ b/source/multigrid/mg_transfer_prebuilt.cc @@ -266,20 +266,11 @@ MGTransferPrebuilt::build( // complete sparsity patterns on their own, the sparsity pattern must // be manually distributed. - // Retrieve communicator from triangulation if it is parallel - const parallel::TriangulationBase *dist_tria = - dynamic_cast *>( - &(dof_handler.get_triangulation())); - - MPI_Comm communicator = dist_tria != nullptr ? - dist_tria->get_communicator() : - MPI_COMM_SELF; - // Distribute sparsity pattern ::dealii::SparsityTools::distribute_sparsity_pattern( dsp, dof_handler.locally_owned_mg_dofs(level + 1), - communicator, + dof_handler.get_communicator(), dsp.row_index_set()); } #endif diff --git a/source/particles/particle_handler.cc b/source/particles/particle_handler.cc index c69838d84a..514ba68a18 100644 --- a/source/particles/particle_handler.cc +++ b/source/particles/particle_handler.cc @@ -491,11 +491,7 @@ namespace Particles if (!ids.empty()) AssertDimension(ids.size(), positions.size()); - const auto tria = - dynamic_cast *>( - &(*triangulation)); - const auto comm = - (tria != nullptr ? tria->get_communicator() : MPI_COMM_WORLD); + const auto comm = triangulation->get_communicator(); const auto n_mpi_processes = Utilities::MPI::n_mpi_processes(comm);