]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Compute reverse and inverse permutations.
authorbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 31 Oct 2008 17:41:03 +0000 (17:41 +0000)
committerbangerth <bangerth@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 31 Oct 2008 17:41:03 +0000 (17:41 +0000)
git-svn-id: https://svn.dealii.org/trunk@17431 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/base/include/base/utilities.h
deal.II/base/source/utilities.cc
deal.II/doc/news/changes.h

index 1b5a7ca497be05c8e8607faee027e5371d91142d..330e5b91502bd33288fbba8a6d88f21a341f8c6b 100644 (file)
@@ -172,6 +172,27 @@ namespace Utilities
   template <int N, typename T>
   T
   fixed_power (const T t);
+
+                                  /**
+                                   * Given a permutation vector (i.e. a
+                                   * vector $p_0\ldots p_{N-1}$ where each
+                                   * $p_i\in [0,N)$ and $p_i\neq p_j$ for
+                                   * $i\neq j$), produce the reverse
+                                   * permutation $q_i=N-1-p_i$.
+                                   */
+  std::vector<unsigned int>
+  reverse_permutation (const std::vector<unsigned int> &permutation);
+
+                                  /**
+                                   * Given a permutation vector (i.e. a
+                                   * vector $p_0\ldots p_{N-1}$ where each
+                                   * $p_i\in [0,N)$ and $p_i\neq p_j$ for
+                                   * $i\neq j$), produce the inverse
+                                   * permutation $q_0\ldots q_{N-1}$ so that
+                                   * $q_{p_i}=p_{q_i}=i$.
+                                   */
+  std::vector<unsigned int>
+  invert_permutation (const std::vector<unsigned int> &permutation);
   
                                    /**
                                     * A namespace for utility functions that
index 44b74d70dc25934c2eb1fa43c03fb3428b9077d6..129f8ebcf91384bbe82e01b0ef3c2ca8bd8d402d 100644 (file)
@@ -345,6 +345,45 @@ namespace Utilities
 
 
 
+  std::vector<unsigned int>
+  reverse_permutation (const std::vector<unsigned int> &permutation)
+  {
+    const unsigned int n = permutation.size();
+    
+    std::vector<unsigned int> out (n);
+    for (unsigned int i=0; i<n; ++i)
+      out[i] = n - 1 - permutation[i];
+
+    return out;
+  }
+
+
+
+  std::vector<unsigned int>
+  invert_permutation (const std::vector<unsigned int> &permutation)
+  {
+    const unsigned int n = permutation.size();
+    
+    std::vector<unsigned int> out (n, numbers::invalid_unsigned_int);
+    
+    for (unsigned int i=0; i<n; ++i)
+      {
+       Assert (permutation[i] < n, ExcIndexRange (permutation[i], 0, n));
+       out[permutation[i]] = i;
+      }
+
+                                    // check that we have actually reached
+                                    // all indices
+    for (unsigned int i=0; i<n; ++i)
+      Assert (out[i] != numbers::invalid_unsigned_int,
+             ExcMessage ("The given input permutation had duplicate entries!"));
+    
+    return out;
+  }
+  
+
+
+
   namespace System
   {
 #if defined(__linux__)
index d4d4c45c0747bc4cd9d5dcdf6f4be1f5a31637cc..dd81efaa7ebc109beed741c449d47a52573e0f77 100644 (file)
@@ -196,6 +196,14 @@ inconvenience this causes.
 <h3>base</h3>
 
 <ol>
+  <li>
+  <p>
+  New: The Utilities::reverse_permutation and Utilities::invert_permutation
+  compute the reverse and inverse of a given permutation of indices.
+  <br> 
+  (WB 2008/10/31)
+  </p>
+
   <li>
   <p>
   Fixed: The PolynomialsRaviartThomas class had a bug that led to random
@@ -399,6 +407,15 @@ inconvenience this causes.
 <h3>deal.II</h3>
 
 <ol>
+  <li>
+  <p>
+  Fixed: The DoFRenumbering::Cuthill_McKee algorithm had a bug when applied
+  to MGDoFHandler objects and if the <code>reverse</code> flag was set. This
+  should now be fixed.
+  <br>
+  (WB 2008/10/31)
+  </p>
+
   <li>
   <p>
   New: MatrixTools::apply_boundary_values() also for PETScWrappers::MPI::BlockSparseMatrix.

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.