From: denis.davydov Date: Fri, 2 May 2014 11:24:23 +0000 (+0000) Subject: reworked DoFTools::locally_owned_dofs_with_subdomain again; Sum of locally owned... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8be96e535de631d8ae1543279edefe70cabf1794;p=dealii-svn.git reworked DoFTools::locally_owned_dofs_with_subdomain again; Sum of locally owned now equals n_dofs() git-svn-id: https://svn.dealii.org/branches/branch_sharedtria@32873 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/source/dofs/dof_handler_policy.cc b/deal.II/source/dofs/dof_handler_policy.cc index 0e03d7342b..4f8fe256fb 100644 --- a/deal.II/source/dofs/dof_handler_policy.cc +++ b/deal.II/source/dofs/dof_handler_policy.cc @@ -976,12 +976,14 @@ namespace internal NumberCache number_cache = Sequential::distribute_dofs (dof_handler,number_cache_current); //update current number cache in DoFHandler number_cache_current = number_cache; + //number_cache.n_global_dofs; DoFRenumbering::subdomain_wise (dof_handler); number_cache.locally_owned_dofs_per_processor = DoFTools::locally_owned_dofs_with_subdomain (dof_handler); number_cache.locally_owned_dofs = number_cache.locally_owned_dofs_per_processor[dof_handler.get_tria().locally_owned_subdomain()]; number_cache.n_locally_owned_dofs_per_processor.resize (number_cache.locally_owned_dofs_per_processor.size()); for (unsigned int i = 0; i < number_cache.n_locally_owned_dofs_per_processor.size(); i++) number_cache.n_locally_owned_dofs_per_processor[i] = number_cache.locally_owned_dofs_per_processor[i].n_elements(); + number_cache.n_locally_owned_dofs = number_cache.n_locally_owned_dofs_per_processor[dof_handler.get_tria().locally_owned_subdomain()]; return number_cache; } diff --git a/deal.II/source/dofs/dof_tools.cc b/deal.II/source/dofs/dof_tools.cc index 5f01c410d2..0b43671c13 100644 --- a/deal.II/source/dofs/dof_tools.cc +++ b/deal.II/source/dofs/dof_tools.cc @@ -1086,54 +1086,33 @@ namespace DoFTools 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 - std::vector found_start(num_subdomains,false); - for (types::global_dof_index ind = 0; ind < subdomain_association.size(); ind++) + //a change in subdomain ID is found + types::global_dof_index i_min = 0; + types::global_dof_index cur_subdomain = subdomain_association[0]; + for (types::global_dof_index ind = 1; ind < subdomain_association.size(); ind++) { - for (unsigned int i = 0; i < num_subdomains; i++) + //found index different from the current one + if (subdomain_association[ind] != cur_subdomain) { - 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; - } + index_sets[cur_subdomain].add_range(i_min,ind); + i_min = ind; + cur_subdomain = subdomain_association[ind]; } } - //check that only 1 found_start[i] is true: + //the very last element is of different index + if (i_min == subdomain_association.size()-1) { - bool found = false; - for (unsigned int i = 0; i < num_subdomains; i++) - { - if (found_start[i]) - { - Assert(!found, ExcInternalError()) - found = true; - } - } + index_sets[cur_subdomain].add_index(i_min); } - // 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 - for (unsigned int i = 0;i< num_subdomains; i++) + else //there are at least two different indices { - if (found_start[i]) { - index_sets[i].add_range(i_min[i],subdomain_association.size()); - } - index_sets[i].compress(); + index_sets[cur_subdomain].add_range(i_min,subdomain_association.size()); } + for (unsigned int i = 0;i< num_subdomains; i++) + index_sets[i].compress(); return index_sets; }