]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Speed up dof_indices_with_subdomain_association.
authorkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 26 Aug 2011 11:25:04 +0000 (11:25 +0000)
committerkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 26 Aug 2011 11:25:04 +0000 (11:25 +0000)
git-svn-id: https://svn.dealii.org/trunk@24206 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/source/dofs/dof_tools.cc

index 9c2b88977a706628617b1b68e3fef965e7375214..591a4303d33fe63ad5f0e155210122a723f0beed 100644 (file)
@@ -4399,6 +4399,16 @@ namespace DoFTools
     std::vector<unsigned int> local_dof_indices;
     local_dof_indices.reserve (max_dofs_per_cell(dof_handler));
 
+                               // first generate an unsorted list of all
+                               // indices which we fill from the back. could
+                               // also insert them directly into the
+                               // IndexSet, but that inserts indices in the
+                               // middle, which is an O(n^2) algorithm and
+                               // hence too expensive. Could also use
+                               // std::set, but that is in general more
+                               // expensive than a vector
+    std::vector<unsigned int> subdomain_indices;
+
     typename DH::active_cell_iterator
       cell = dof_handler.begin_active(),
       endc = dof_handler.end();
@@ -4410,9 +4420,18 @@ namespace DoFTools
          const unsigned int dofs_per_cell = cell->get_fe().dofs_per_cell;
          local_dof_indices.resize (dofs_per_cell);
          cell->get_dof_indices (local_dof_indices);
-         index_set.add_indices (local_dof_indices.begin(),
-                                local_dof_indices.end());
+         subdomain_indices.insert(subdomain_indices.end(),
+                                  local_dof_indices.begin(),
+                                  local_dof_indices.end());
        }
+                               // sort indices and remove duplicates
+    std::sort (subdomain_indices.begin(), subdomain_indices.end());
+    subdomain_indices.erase (std::unique(subdomain_indices.begin(),
+                                        subdomain_indices.end()),
+                            subdomain_indices.end());
+
+                               // insert into IndexSet
+    index_set.add_indices (subdomain_indices.begin(), subdomain_indices.end());
     index_set.compress ();
 
     return index_set;

In the beginning the Universe was created. This has made a lot of people very angry and has been widely regarded as a bad move.

Douglas Adams


Typeset in Trocchi and Trocchi Bold Sans Serif.