From: Marc Fehling Date: Tue, 9 Feb 2021 00:20:31 +0000 (-0700) Subject: ::SolutionTransfer with p::s::Triangulation and artificial cells. X-Git-Tag: v9.3.0-rc1~440^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5ee3104b2e6a10bc4e4622f835a67a6c1c502cf9;p=dealii.git ::SolutionTransfer with p::s::Triangulation and artificial cells. --- diff --git a/source/numerics/solution_transfer.cc b/source/numerics/solution_transfer.cc index 80d4fc4857..dacfb341ba 100644 --- a/source/numerics/solution_transfer.cc +++ b/source/numerics/solution_transfer.cc @@ -15,6 +15,7 @@ #include +#include #include #include @@ -92,6 +93,32 @@ SolutionTransfer::prepare_for_pure_refinement() clear(); + // We need to access dof indices on the entire domain. For + // shared::Triangulations, ownership of cells might change. If they allow the + // use of artificial cells, we need to restore the true cell owners + // temporarily. We save the current set of subdomain ids, set subdomain ids to + // the "true" owner of each cell, and later restore these flags. + std::vector saved_subdomain_ids; + const parallel::shared::Triangulation + *shared_tria = + (dynamic_cast *>( + &dof_handler->get_triangulation())); + if (shared_tria != nullptr && shared_tria->with_artificial_cells()) + { + saved_subdomain_ids.resize(shared_tria->n_active_cells()); + + const std::vector &true_subdomain_ids = + shared_tria->get_true_subdomain_ids_of_cells(); + + for (const auto &cell : shared_tria->active_cell_iterators()) + { + const unsigned int index = cell->active_cell_index(); + saved_subdomain_ids[index] = cell->subdomain_id(); + cell->set_subdomain_id(true_subdomain_ids[index]); + } + } + const unsigned int n_active_cells = dof_handler->get_triangulation().n_active_cells(); n_dofs_old = dof_handler->n_dofs(); @@ -115,6 +142,11 @@ SolutionTransfer::prepare_for_pure_refinement() Pointerstruct(&indices_on_cell[i], cell->active_fe_index()); } prepared_for = pure_refinement; + + // Undo the subdomain modification. + if (shared_tria != nullptr && shared_tria->with_artificial_cells()) + for (const auto &cell : shared_tria->active_cell_iterators()) + cell->set_subdomain_id(saved_subdomain_ids[cell->active_cell_index()]); } @@ -133,6 +165,32 @@ SolutionTransfer::refine_interpolate( ExcMessage("Vectors cannot be used as input and output" " at the same time!")); + // We need to access dof indices on the entire domain. For + // shared::Triangulations, ownership of cells might change. If they allow the + // use of artificial cells, we need to restore the true cell owners + // temporarily. We save the current set of subdomain ids, set subdomain ids to + // the "true" owner of each cell, and later restore these flags. + std::vector saved_subdomain_ids; + const parallel::shared::Triangulation + *shared_tria = + (dynamic_cast *>( + &dof_handler->get_triangulation())); + if (shared_tria != nullptr && shared_tria->with_artificial_cells()) + { + saved_subdomain_ids.resize(shared_tria->n_active_cells()); + + const std::vector &true_subdomain_ids = + shared_tria->get_true_subdomain_ids_of_cells(); + + for (const auto &cell : shared_tria->active_cell_iterators()) + { + const unsigned int index = cell->active_cell_index(); + saved_subdomain_ids[index] = cell->subdomain_id(); + cell->set_subdomain_id(true_subdomain_ids[index]); + } + } + Vector local_values(0); typename std::map, @@ -171,6 +229,11 @@ SolutionTransfer::refine_interpolate( this_fe_index); } } + + // Undo the subdomain modification. + if (shared_tria != nullptr && shared_tria->with_artificial_cells()) + for (const auto &cell : shared_tria->active_cell_iterators()) + cell->set_subdomain_id(saved_subdomain_ids[cell->active_cell_index()]); } @@ -274,6 +337,32 @@ SolutionTransfer:: } #endif + // We need to access dof indices on the entire domain. For + // shared::Triangulations, ownership of cells might change. If they allow the + // use of artificial cells, we need to restore the true cell owners + // temporarily. We save the current set of subdomain ids, set subdomain ids to + // the "true" owner of each cell, and later restore these flags. + std::vector saved_subdomain_ids; + const parallel::shared::Triangulation + *shared_tria = + (dynamic_cast *>( + &dof_handler->get_triangulation())); + if (shared_tria != nullptr && shared_tria->with_artificial_cells()) + { + saved_subdomain_ids.resize(shared_tria->n_active_cells()); + + const std::vector &true_subdomain_ids = + shared_tria->get_true_subdomain_ids_of_cells(); + + for (const auto &cell : shared_tria->active_cell_iterators()) + { + const unsigned int index = cell->active_cell_index(); + saved_subdomain_ids[index] = cell->subdomain_id(); + cell->set_subdomain_id(true_subdomain_ids[index]); + } + } + // first count the number // of cells that will be coarsened // and that'll stay or be refined @@ -391,6 +480,11 @@ SolutionTransfer:: Assert(n_cf == n_coarsen_fathers, ExcInternalError()); prepared_for = coarsening_and_refinement; + + // Undo the subdomain modification. + if (shared_tria != nullptr && shared_tria->with_artificial_cells()) + for (const auto &cell : shared_tria->active_cell_iterators()) + cell->set_subdomain_id(saved_subdomain_ids[cell->active_cell_index()]); } @@ -429,6 +523,32 @@ SolutionTransfer::interpolate( " at the same time!")); #endif + // We need to access dof indices on the entire domain. For + // shared::Triangulations, ownership of cells might change. If they allow the + // use of artificial cells, we need to restore the true cell owners + // temporarily. We save the current set of subdomain ids, set subdomain ids to + // the "true" owner of each cell, and later restore these flags. + std::vector saved_subdomain_ids; + const parallel::shared::Triangulation + *shared_tria = + (dynamic_cast *>( + &dof_handler->get_triangulation())); + if (shared_tria != nullptr && shared_tria->with_artificial_cells()) + { + saved_subdomain_ids.resize(shared_tria->n_active_cells()); + + const std::vector &true_subdomain_ids = + shared_tria->get_true_subdomain_ids_of_cells(); + + for (const auto &cell : shared_tria->active_cell_iterators()) + { + const unsigned int index = cell->active_cell_index(); + saved_subdomain_ids[index] = cell->subdomain_id(); + cell->set_subdomain_id(true_subdomain_ids[index]); + } + } + Vector local_values; std::vector dofs; @@ -534,6 +654,11 @@ SolutionTransfer::interpolate( Assert(false, ExcInternalError()); } } + + // Undo the subdomain modification. + if (shared_tria != nullptr && shared_tria->with_artificial_cells()) + for (const auto &cell : shared_tria->active_cell_iterators()) + cell->set_subdomain_id(saved_subdomain_ids[cell->active_cell_index()]); }