From: denis.davydov Date: Fri, 2 May 2014 09:40:49 +0000 (+0000) Subject: reworked DoFTools::locally_owned_dofs_with_subdomain; use updated version in policy X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=7606bcb5c5d6b57bd896132c711207da2a711071;p=dealii-svn.git reworked DoFTools::locally_owned_dofs_with_subdomain; use updated version in policy git-svn-id: https://svn.dealii.org/branches/branch_sharedtria@32872 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 9456dc491a..03a56e22ff 100644 --- a/deal.II/include/deal.II/dofs/dof_handler_policy.h +++ b/deal.II/include/deal.II/dofs/dof_handler_policy.h @@ -177,6 +177,8 @@ namespace internal renumber_dofs (const std::vector &new_numbers, dealii::DoFHandler &dof_handler, NumberCache & number_cache_current) const; + private: + }; diff --git a/deal.II/include/deal.II/dofs/dof_tools.h b/deal.II/include/deal.II/dofs/dof_tools.h index 12f13864c7..b08b1f12f6 100644 --- a/deal.II/include/deal.II/dofs/dof_tools.h +++ b/deal.II/include/deal.II/dofs/dof_tools.h @@ -1373,15 +1373,13 @@ namespace DoFTools IndexSet &dof_set); /** - * Extract the set of global DoF indices distributed on - * cells with the given subdomain id. This function should be used for + * Extract the set of global DoF indices distributed on cells. This function should be used for * DoFHandler objects built on dealii::Triangulation or parallel::shared::Triangulation * classes. Internally the funciton is based on DoFTools::get_subdomain_association. */ template - IndexSet - locally_owned_dofs_with_subdomain (const DH &dof_handler, - const types::subdomain_id subdomain ); + std::vector + locally_owned_dofs_with_subdomain (const DH &dof_handler); /** * For each DoF, return in the output array to which subdomain (as diff --git a/deal.II/source/dofs/dof_handler_policy.cc b/deal.II/source/dofs/dof_handler_policy.cc index c5d0aef91d..0e03d7342b 100644 --- a/deal.II/source/dofs/dof_handler_policy.cc +++ b/deal.II/source/dofs/dof_handler_policy.cc @@ -966,6 +966,7 @@ namespace internal } /* --------------------- class ParallelSequential ---------------- */ + template NumberCache ParallelShared:: @@ -976,12 +977,11 @@ namespace internal //update current number cache in DoFHandler number_cache_current = number_cache; DoFRenumbering::subdomain_wise (dof_handler); - const parallel::shared::Triangulation *shared_tr = dynamic_cast*>(&dof_handler.get_tria()); - const unsigned int n_mpi_processes = Utilities::MPI::n_mpi_processes( shared_tr->get_communicator () ); - number_cache.n_locally_owned_dofs_per_processor.resize (n_mpi_processes); - for (unsigned int i=0; i - IndexSet - locally_owned_dofs_with_subdomain (const DH &dof_handler, - const types::subdomain_id subdomain ) + std::vector + locally_owned_dofs_with_subdomain (const DH &dof_handler) { - IndexSet index_set (dof_handler.n_dofs()); + //the following is a random process (flip of a coin), thus should be called once only. 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; + + const unsigned int num_subdomains = 1 + (*max_element(subdomain_association.begin(), subdomain_association.end())); + + std::vector index_sets (num_subdomains,IndexSet(dof_handler.n_dofs())); + std::vector i_min(num_subdomains,0), + i_max_plus_1(num_subdomains,0); //loop over subdomain_association //and populate IndexSet when //a given subdomain is found - bool found_start = false; + std::vector found_start(num_subdomains,false); for (types::global_dof_index ind = 0; ind < subdomain_association.size(); ind++) { - if (!found_start && (subdomain_association[ind]== subdomain) ) + for (unsigned int i = 0; i < num_subdomains; i++) { - found_start = true; - i_min = ind; + if (!found_start[i] && (subdomain_association[ind]== i) ) + { + found_start[i] = true; + i_min[i] = ind; + break; + } + if (found_start[i] && (subdomain_association[ind] != i) ) + { + found_start[i] = false; + i_max_plus_1[i] = ind; + index_sets[i].add_range(i_min[i],i_max_plus_1[i]); + break; + } } - if (found_start && (subdomain_association[ind] != subdomain) ) + } + //check that only 1 found_start[i] is true: + { + bool found = false; + for (unsigned int i = 0; i < num_subdomains; i++) { - found_start = false; - i_max_plus_1 = ind; - index_set.add_range(i_min,i_max_plus_1); + if (found_start[i]) + { + Assert(!found, ExcInternalError()) + found = true; + } } } - // 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()); + for (unsigned int i = 0;i< num_subdomains; i++) + { + if (found_start[i]) { + index_sets[i].add_range(i_min[i],subdomain_association.size()); + } + index_sets[i].compress(); } - index_set.compress(); - return index_set; + return index_sets; } template diff --git a/deal.II/source/dofs/dof_tools.inst.in b/deal.II/source/dofs/dof_tools.inst.in index 4e16d7b6d8..b0e66feaf8 100644 --- a/deal.II/source/dofs/dof_tools.inst.in +++ b/deal.II/source/dofs/dof_tools.inst.in @@ -271,15 +271,13 @@ DoFTools::get_subdomain_association > std::vector &subdomain_association); template -IndexSet +std::vector DoFTools::locally_owned_dofs_with_subdomain > -(const DoFHandler &dof_handler, - const types::subdomain_id subdomain); +(const DoFHandler &dof_handler); template -IndexSet +std::vector DoFTools::locally_owned_dofs_with_subdomain > -(const hp::DoFHandler &dof_handler, - const types::subdomain_id subdomain); +(const hp::DoFHandler &dof_handler); template unsigned int @@ -364,15 +362,13 @@ DoFTools::get_subdomain_association &subdomain_association); template -IndexSet +std::vector DoFTools::locally_owned_dofs_with_subdomain > -(const DoFHandler &dof_handler, - const types::subdomain_id subdomain); +(const DoFHandler &dof_handler); template -IndexSet +std::vector DoFTools::locally_owned_dofs_with_subdomain > -(const hp::DoFHandler &dof_handler, - const types::subdomain_id subdomain); +(const hp::DoFHandler &dof_handler); template void @@ -403,15 +399,13 @@ DoFTools::get_subdomain_association > std::vector &subdomain_association); template -IndexSet +std::vector DoFTools::locally_owned_dofs_with_subdomain > -(const DoFHandler<1,3> &dof_handler, - const types::subdomain_id subdomain); +(const DoFHandler<1,3> &dof_handler); template -IndexSet +std::vector DoFTools::locally_owned_dofs_with_subdomain > -(const hp::DoFHandler<1,3> &dof_handler, - const types::subdomain_id subdomain); +(const hp::DoFHandler<1,3> &dof_handler); template unsigned int