]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Update copy_indices - use std::vector instead of std::map.
authorkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 9 Feb 2010 11:21:29 +0000 (11:21 +0000)
committerkronbichler <kronbichler@0785d39b-7218-0410-832d-ea1e28bc413d>
Tue, 9 Feb 2010 11:21:29 +0000 (11:21 +0000)
git-svn-id: https://svn.dealii.org/trunk@20526 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/multigrid/mg_transfer.h
deal.II/deal.II/include/multigrid/mg_transfer.templates.h
deal.II/deal.II/include/multigrid/mg_transfer_component.h
deal.II/deal.II/include/multigrid/mg_transfer_component.templates.h
deal.II/deal.II/source/multigrid/mg_transfer_component.cc
deal.II/deal.II/source/multigrid/mg_transfer_prebuilt.cc

index 61ad98b3d5a48f91b1138a75fff8c865a34e25c6..8c63dc237a8c3336f8719107f368b673bd9fd07e 100644 (file)
@@ -223,7 +223,7 @@ class MGTransferPrebuilt : public MGTransferBase<VECTOR>
                                      * The data is first the global
                                      * index, then the level index.
                                     */
-    std::vector<std::map<unsigned int, unsigned int> >
+    std::vector<std::vector<std::pair<unsigned int, unsigned int> > >
       copy_indices;
 
                                     /**
index ac3e9308d8a284629b6dc208a5312e6b2ae2f605..0aad386f8bf329405931975ccbad5769f620cb52 100644 (file)
@@ -49,7 +49,7 @@ MGTransferPrebuilt<VECTOR>::copy_from_mg(
   dst = 0;
   for (unsigned int level=0;level<mg_dof_handler.get_tria().n_levels();++level)
   {
-    typedef std::map<unsigned int, unsigned int>::const_iterator IT;
+    typedef std::vector<std::pair<unsigned int, unsigned int> >::const_iterator IT;
     for (IT i= copy_indices[level].begin();
         i != copy_indices[level].end();++i)
       dst(i->first) = src[level](i->second);
@@ -77,7 +77,7 @@ MGTransferPrebuilt<VECTOR>::copy_from_mg_add (
                                       // functions
   for (unsigned int level=0;level<mg_dof_handler.get_tria().n_levels();++level)
   {
-    typedef std::map<unsigned int, unsigned int>::const_iterator IT;
+    typedef std::vector<std::pair<unsigned int, unsigned int> >::const_iterator IT;
     for (IT i= copy_indices[level].begin();
         i != copy_indices[level].end();++i)
       dst(i->first) += src[level](i->second);
index ea98f0b9577b98ed4f4cab46cff0ff19b3e8ef60..2e32e710672c477a1cdb2b939fe573f0aa09004f 100644 (file)
@@ -170,7 +170,7 @@ class MGTransferComponentBase
                                      * The data is first the global
                                      * index, then the level index.
                                      */
-    std::vector<std::map<unsigned int, unsigned int> >
+    std::vector<std::vector<std::pair<unsigned int, unsigned int> > >
     copy_to_and_from_indices;
 
                                     /**
index 301c987de5b8cb58472583ef4d49b4e1484eb6eb..a8abc206256eceb3bf03cab77b9537def5d83d9c 100644 (file)
@@ -86,15 +86,15 @@ MGTransferSelect<number>::copy_from_mg (
   do_copy_from_mg (mg_dof_handler, dst, src);
   if (constraints != 0)
   {
-    //If we were given constraints 
-    //apply them to the dst that goes 
+    //If we were given constraints
+    //apply them to the dst that goes
     //back now to the linear solver.
     //Since constraints are globally
     //defined create a global vector here
-    //and copy dst to the right component, 
-    //apply the constraints then and copy 
+    //and copy dst to the right component,
+    //apply the constraints then and copy
     //the block back to dst.
-    const unsigned int n_blocks = 
+    const unsigned int n_blocks =
       *std::max_element(target_component.begin(), target_component.end()) + 1;
     std::vector<unsigned int> dofs_per_block (n_blocks);
     DoFTools::count_dofs_per_block (mg_dof_handler, dofs_per_block, target_component);
@@ -166,7 +166,7 @@ MGTransferSelect<number>::do_copy_from_mg (
   for (; level_cell != endc; ++level_cell)
   {
     const unsigned int level = level_cell->level();
-    typedef std::map<unsigned int, unsigned int>::const_iterator IT;
+    typedef std::vector<std::pair<unsigned int, unsigned int> >::const_iterator IT;
     for (IT i=copy_to_and_from_indices[level].begin();
         i != copy_to_and_from_indices[level].end(); ++i)
       dst(i->first) = src[level](i->second);
@@ -203,7 +203,7 @@ MGTransferSelect<number>::do_copy_from_mg_add (
   for (; level_cell != endc; ++level_cell)
     {
       const unsigned int level = level_cell->level();
-      typedef std::map<unsigned int, unsigned int>::const_iterator IT;
+      typedef std::vector<std::pair<unsigned int, unsigned int> >::const_iterator IT;
       for (IT i=copy_to_and_from_indices[level].begin();
         i != copy_to_and_from_indices[level].end(); ++i)
              dst(i->first) += src[level](i->second);
index c30c638a8ab9e4426d0a6de87c6e6bf49bf2a602..b358e07d96d38dfa1ae3d789fe3448836aefc20d 100644 (file)
@@ -247,19 +247,20 @@ MGTransferSelect<number>::do_copy_to_mg (
   for (unsigned int level=mg_dof_handler.get_tria().n_levels(); level!=0;)
     {
       --level;
+      Vector<number> &dst_level = dst[level];
 
-      typedef std::map<unsigned int, unsigned int>::const_iterator IT;
-         for (IT i=copy_to_and_from_indices[level].begin();
-              i != copy_to_and_from_indices[level].end(); ++i)
-              dst[level](i->second) = src(i->first);
+      typedef std::vector<std::pair<unsigned int, unsigned int> >::const_iterator IT;
+      for (IT i=copy_to_and_from_indices[level].begin();
+          i != copy_to_and_from_indices[level].end(); ++i)
+       dst_level(i->second) = src(i->first);
                                       // for that part of the level
                                       // which is further refined:
                                       // get the defect by
                                       // restriction of the defect on
                                       // one level higher
-          if(!first)
-            restrict_and_add (level+1, dst[level], dst[level+1]);
-          first = false;
+      if(!first)
+       restrict_and_add (level+1, dst[level], dst[level+1]);
+      first = false;
     }
 }
 
@@ -610,6 +611,9 @@ void MGTransferSelect<number>::build_matrices (
     interface_dofs[l].resize(mg_dof.n_dofs(l));
   MGTools::extract_inner_interface_dofs(mg_dof, interface_dofs);
 
+                               // use a temporary vector to create the
+                               // relation between global and level dofs
+  std::vector<unsigned int> temp_copy_indices;
   std::vector<unsigned int> global_dof_indices (fe.dofs_per_cell);
   std::vector<unsigned int> level_dof_indices  (fe.dofs_per_cell);
   for (int level=dof.get_tria().n_levels()-1; level>=0; --level)
@@ -620,6 +624,9 @@ void MGTransferSelect<number>::build_matrices (
       const typename MGDoFHandler<dim,spacedim>::active_cell_iterator
        level_end  = mg_dof.end_active(level);
 
+      temp_copy_indices.resize (0);
+      temp_copy_indices.resize (mg_dof.n_dofs(level), numbers::invalid_unsigned_int);
+
                                       // Compute coarse level right hand side
                                       // by restricting from fine level.
       for (; level_cell!=level_end; ++level_cell)
@@ -644,10 +651,8 @@ void MGTransferSelect<number>::build_matrices (
                    = mg_component_start[level][mg_target_component[component]];
                  const unsigned int global_start
                    = component_start[target_component[component]];
-                 copy_to_and_from_indices[level].insert(
-                   std::make_pair(global_dof_indices[i] - global_start
-                                  /*- component_start[target_component[selected_component]]*/,
-                                  level_dof_indices[i]-level_start));
+                 temp_copy_indices[level_dof_indices[i]-level_start] = 
+                   global_dof_indices[i]-global_start;
                   deallog << "global " << global_dof_indices[i]
                     - component_start[target_component[selected_component]] <<
                     " lokal " << level_dof_indices[i]-level_start << std::endl;
@@ -659,6 +664,20 @@ void MGTransferSelect<number>::build_matrices (
                }
            }
        }
+
+                               // write indices from vector into the map from
+                               // global to level dofs
+      const unsigned int n_active_dofs =
+       std::count_if (temp_copy_indices.begin(), temp_copy_indices.end(),
+                      std::bind2nd(std::not_equal_to<unsigned int>(),
+                                   numbers::invalid_unsigned_int));
+      copy_to_and_from_indices[level].resize (n_active_dofs);
+      unsigned int counter = 0;
+      for (unsigned int i=0; i<temp_copy_indices.size(); ++i)
+       if (temp_copy_indices[i] != numbers::invalid_unsigned_int)
+         copy_to_and_from_indices[level][counter++] =
+           std::make_pair<unsigned int,unsigned int> (temp_copy_indices[i], i);
+      Assert (counter == n_active_dofs, ExcInternalError());
     }
 }
 
index 5f2b214a01e696cd110d3da8fd63385739458a05..fd3d1b05b204ca2f7584722b787065020e1c5d03 100644 (file)
@@ -121,12 +121,12 @@ MGTransferPrebuilt<VECTOR>::copy_to_mg (
   for (unsigned int level=mg_dof_handler.get_tria().n_levels();level != 0;)
     {
       --level;
-//      VECTOR& dst_level = dst[level];
+      VECTOR& dst_level = dst[level];
 
-      typedef std::map<unsigned int, unsigned int>::const_iterator IT;
+      typedef std::vector<std::pair<unsigned int, unsigned int> >::const_iterator IT;
       for (IT i= copy_indices[level].begin();
           i != copy_indices[level].end();++i)
-       dst[level](i->second) = src(i->first);
+       dst_level(i->second) = src(i->first);
 
                                       // For non-DG: degrees of
                                       // freedom in the refinement
@@ -329,7 +329,7 @@ void MGTransferPrebuilt<VECTOR>::build_matrices (
   MGTools::extract_inner_interface_dofs (mg_dof, interface_dofs);
 
   copy_indices.resize(n_levels);
-//  std::vector<unsigned int> temp_copy_indices;
+  std::vector<unsigned int> temp_copy_indices;
   std::vector<unsigned int> global_dof_indices (dofs_per_cell);
   std::vector<unsigned int> level_dof_indices  (dofs_per_cell);
   for (int level=mg_dof.get_tria().n_levels()-1; level>=0; --level)
@@ -340,8 +340,8 @@ void MGTransferPrebuilt<VECTOR>::build_matrices (
       const typename MGDoFHandler<dim,spacedim>::active_cell_iterator
        level_end  = mg_dof.end_active(level);
 
-//      temp_copy_indices.resize (0);
-//      temp_copy_indices.resize (mg_dof.n_dofs(level), numbers::invalid_unsigned_int);
+      temp_copy_indices.resize (0);
+      temp_copy_indices.resize (mg_dof.n_dofs(level), numbers::invalid_unsigned_int);
 
                                       // Compute coarse level right hand side
                                       // by restricting from fine level.
@@ -357,12 +357,8 @@ void MGTransferPrebuilt<VECTOR>::build_matrices (
 
          for (unsigned int i=0; i<dofs_per_cell; ++i)
           {
-              if(!interface_dofs[level][level_dof_indices[i]])
-             copy_indices[level].insert(
-               std::make_pair(global_dof_indices[i], level_dof_indices[i]));
-//         temp_copy_indices[level_dof_indices[i]] = global_dof_indices[i];
-//         if(!interface_dofs[level][level_dof_indices[i]])
-//           temp_copy_indices[level_dof_indices[i]] = global_dof_indices[i];
+           if(!interface_dofs[level][level_dof_indices[i]])
+             temp_copy_indices[level_dof_indices[i]] = global_dof_indices[i];
           }
        }
 
@@ -372,17 +368,17 @@ void MGTransferPrebuilt<VECTOR>::build_matrices (
                                // copy_indices object. Then, insert the pairs
                                // of global index and level index into
                                // copy_indices.
-//      const unsigned int n_active_dofs =
-//     std::count_if (temp_copy_indices.begin(), temp_copy_indices.end(),
-//                    std::bind2nd(std::not_equal_to<unsigned int>(),
-//                                 numbers::invalid_unsigned_int));
-//      copy_indices[level].resize (n_active_dofs);
-//      unsigned int counter = 0;
-//      for (unsigned int i=0; i<temp_copy_indices.size(); ++i)
-//     if (temp_copy_indices[i] != numbers::invalid_unsigned_int)
-//       copy_indices[level][counter++] =
-//         std::make_pair<unsigned int,unsigned int> (temp_copy_indices[i], i);
-//      Assert (counter == n_active_dofs, ExcInternalError());
+      const unsigned int n_active_dofs =
+       std::count_if (temp_copy_indices.begin(), temp_copy_indices.end(),
+                      std::bind2nd(std::not_equal_to<unsigned int>(),
+                                   numbers::invalid_unsigned_int));
+      copy_indices[level].resize (n_active_dofs);
+      unsigned int counter = 0;
+      for (unsigned int i=0; i<temp_copy_indices.size(); ++i)
+       if (temp_copy_indices[i] != numbers::invalid_unsigned_int)
+         copy_indices[level][counter++] =
+           std::make_pair<unsigned int,unsigned int> (temp_copy_indices[i], i);
+      Assert (counter == n_active_dofs, ExcInternalError());
     }
 }
 

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.