From: denis.davydov Date: Fri, 21 Mar 2014 15:27:18 +0000 (+0000) Subject: added locally_owned_dofs_with_subdomain into DoFTools and use it in the new policy... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=03424bc538b0cd21997f329925e12517214df974;p=dealii-svn.git added locally_owned_dofs_with_subdomain into DoFTools and use it in the new policy class; added a dynamic cast check to hp::DoFHandler to put populate locally_owned IndexSet later git-svn-id: https://svn.dealii.org/branches/branch_sharedtria@32681 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/dofs/dof_handler_policy.h b/deal.II/include/deal.II/dofs/dof_handler_policy.h index 16ef98281b..f588ba63f8 100644 --- a/deal.II/include/deal.II/dofs/dof_handler_policy.h +++ b/deal.II/include/deal.II/dofs/dof_handler_policy.h @@ -22,6 +22,7 @@ #include #include #include +#include #include #include diff --git a/deal.II/include/deal.II/dofs/dof_tools.h b/deal.II/include/deal.II/dofs/dof_tools.h index 22a6a74efa..ab0d3ed1f0 100644 --- a/deal.II/include/deal.II/dofs/dof_tools.h +++ b/deal.II/include/deal.II/dofs/dof_tools.h @@ -1372,6 +1372,11 @@ namespace DoFTools extract_locally_relevant_dofs (const DH &dof_handler, IndexSet &dof_set); + template + IndexSet + locally_owned_dofs_with_subdomain (const DH &dof_handler, + const types::subdomain_id subdomain ); + /** * For each DoF, return in the output array to which subdomain (as * given by the cell->subdomain_id() function) it diff --git a/deal.II/include/deal.II/hp/dof_handler.h b/deal.II/include/deal.II/hp/dof_handler.h index 8b0c2b1ace..ef0e929767 100644 --- a/deal.II/include/deal.II/hp/dof_handler.h +++ b/deal.II/include/deal.II/hp/dof_handler.h @@ -26,6 +26,7 @@ #include #include #include +//#include #include #include diff --git a/deal.II/source/dofs/dof_handler.cc b/deal.II/source/dofs/dof_handler.cc index 503e2357d5..a87e4fcb04 100644 --- a/deal.II/source/dofs/dof_handler.cc +++ b/deal.II/source/dofs/dof_handler.cc @@ -73,6 +73,8 @@ namespace internal policy_name = "Policy::Sequential<"; else if (dynamic_cast*>(&policy)) policy_name = "Policy::ParallelDistributed<"; + else if (dynamic_cast*>(&policy)) + policy_name = "Policy::ParallelShared<"; else AssertThrow(false, ExcNotImplemented()); policy_name += Utilities::int_to_string(dim)+ @@ -763,6 +765,11 @@ DoFHandler::DoFHandler (const Triangulation &tria) // decide whether we need a // sequential or a parallel // distributed policy + if (dynamic_cast*> + (&tria) + != 0) + policy.reset (new internal::DoFHandler::Policy::ParallelShared()); + else if (dynamic_cast*> (&tria) == 0) diff --git a/deal.II/source/dofs/dof_handler_policy.cc b/deal.II/source/dofs/dof_handler_policy.cc index 30926ebeba..da667b0400 100644 --- a/deal.II/source/dofs/dof_handler_policy.cc +++ b/deal.II/source/dofs/dof_handler_policy.cc @@ -971,8 +971,7 @@ namespace internal { NumberCache number_cache = Sequential::distribute_dofs (dof_handler); //correct number_cache: - - + number_cache.locally_owned_dofs = dealii::DoFTools::locally_owned_dofs_with_subdomain(dof_handler,dof_handler.get_tria().locally_owned_subdomain() ); return number_cache; } @@ -982,9 +981,8 @@ namespace internal distribute_mg_dofs (DoFHandler &dof_handler, std::vector &number_caches) const { - NumberCache number_cache = Sequential:: distribute_mg_dofs (dof_handler, number_caches); + Sequential:: distribute_mg_dofs (dof_handler, number_caches); Assert(false,ExcMessage("Not implemented")); - return number_cache; } template @@ -995,7 +993,7 @@ namespace internal { NumberCache number_cache = Sequential::renumber_dofs (new_numbers,dof_handler); //correct number_cache: - + number_cache.locally_owned_dofs = dealii::DoFTools::locally_owned_dofs_with_subdomain(dof_handler,dof_handler.get_tria().locally_owned_subdomain() ); return number_cache; } diff --git a/deal.II/source/dofs/dof_handler_policy.inst.in b/deal.II/source/dofs/dof_handler_policy.inst.in index 9b86beb03f..b1fbf341f6 100644 --- a/deal.II/source/dofs/dof_handler_policy.inst.in +++ b/deal.II/source/dofs/dof_handler_policy.inst.in @@ -25,17 +25,20 @@ namespace internal \{ template class PolicyBase; template class Sequential; + template class ParallelShared; template class ParallelDistributed; #if deal_II_dimension==1 || deal_II_dimension==2 template class PolicyBase; template class Sequential; + template class ParallelShared; template class ParallelDistributed; #endif #if deal_II_dimension==3 template class PolicyBase<1,3>; template class Sequential<1,3>; + template class ParallelShared<1,3>; template class ParallelDistributed<1,3>; #endif \} diff --git a/deal.II/source/dofs/dof_tools.cc b/deal.II/source/dofs/dof_tools.cc index 3ea5499334..a2ac1ad4b6 100644 --- a/deal.II/source/dofs/dof_tools.cc +++ b/deal.II/source/dofs/dof_tools.cc @@ -1058,7 +1058,44 @@ namespace DoFTools active_fe_indices[index] = cell->active_fe_index(); } - + template + IndexSet + locally_owned_dofs_with_subdomain (const DH &dof_handler, + const types::subdomain_id subdomain ) + { + IndexSet index_set (dof_handler.n_dofs()); + std::vector< types::subdomain_id > subdomain_association(dof_handler.n_dofs()); + DoFTools::get_subdomain_association(dof_handler,subdomain_association); + types::global_dof_index i_min=0, i_max_plus_1=0; + + //loop over subdomain_association + //and populate IndexSet when + //a given subdomain is found + bool found_start = false; + for (types::global_dof_index ind = 0; ind < subdomain_association.size(); ind++) + { + if (!found_start && (subdomain_association[ind]== subdomain) ) + { + found_start = true; + i_min = ind; + } + if (found_start && (subdomain_association[ind] != subdomain) ) + { + found_start = false; + i_max_plus_1 = ind; + index_set.add_range(i_min,i_max_plus_1); + } + } + + // we have found the starting element, but not the end. + // the last element must have the same subdomain id, + // thus use it to add the range + if (found_start) { + index_set.add_range(i_min,subdomain_association.size()); + } + index_set.compress(); + return index_set; + } template void diff --git a/deal.II/source/dofs/dof_tools.inst.in b/deal.II/source/dofs/dof_tools.inst.in index 9309ae6bc2..4e16d7b6d8 100644 --- a/deal.II/source/dofs/dof_tools.inst.in +++ b/deal.II/source/dofs/dof_tools.inst.in @@ -269,7 +269,17 @@ void DoFTools::get_subdomain_association > (const hp::DoFHandler &dof_handler, std::vector &subdomain_association); - + +template +IndexSet +DoFTools::locally_owned_dofs_with_subdomain > +(const DoFHandler &dof_handler, + const types::subdomain_id subdomain); +template +IndexSet +DoFTools::locally_owned_dofs_with_subdomain > +(const hp::DoFHandler &dof_handler, + const types::subdomain_id subdomain); template unsigned int @@ -352,6 +362,17 @@ void DoFTools::get_subdomain_association > (const hp::DoFHandler &dof_handler, std::vector &subdomain_association); + +template +IndexSet +DoFTools::locally_owned_dofs_with_subdomain > +(const DoFHandler &dof_handler, + const types::subdomain_id subdomain); +template +IndexSet +DoFTools::locally_owned_dofs_with_subdomain > +(const hp::DoFHandler &dof_handler, + const types::subdomain_id subdomain); template void @@ -380,6 +401,17 @@ void DoFTools::get_subdomain_association > (const hp::DoFHandler<1,3> &dof_handler, std::vector &subdomain_association); + +template +IndexSet +DoFTools::locally_owned_dofs_with_subdomain > +(const DoFHandler<1,3> &dof_handler, + const types::subdomain_id subdomain); +template +IndexSet +DoFTools::locally_owned_dofs_with_subdomain > +(const hp::DoFHandler<1,3> &dof_handler, + const types::subdomain_id subdomain); template unsigned int diff --git a/deal.II/source/hp/dof_handler.cc b/deal.II/source/hp/dof_handler.cc index 2f271224d7..d73508e06a 100644 --- a/deal.II/source/hp/dof_handler.cc +++ b/deal.II/source/hp/dof_handler.cc @@ -2690,10 +2690,17 @@ namespace hp number_cache.n_global_dofs = next_free_dof; number_cache.n_locally_owned_dofs = number_cache.n_global_dofs; - number_cache.locally_owned_dofs - = IndexSet (number_cache.n_global_dofs); - number_cache.locally_owned_dofs.add_range (0, - number_cache.n_global_dofs); + if (dynamic_cast*> + (&this->get_tria()) + == 0) { + number_cache.locally_owned_dofs + = IndexSet (number_cache.n_global_dofs); + number_cache.locally_owned_dofs.add_range (0, + number_cache.n_global_dofs); + } else { + Assert(false, ExcMessage("not implemented")); + //number_cache.locally_owned_dofs = dealii::DoFTools::locally_owned_dofs_with_subdomain(this,tria->locally_owned_subdomain() ); + } Assert (number_cache.n_global_dofs < std::numeric_limits::max (), ExcMessage ("Global number of degrees of freedom is too large.")); number_cache.n_locally_owned_dofs_per_processor