]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Add a function to resolve constraint indices.
authorturcksin <turcksin@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 22 Nov 2013 20:58:21 +0000 (20:58 +0000)
committerturcksin <turcksin@0785d39b-7218-0410-832d-ea1e28bc413d>
Fri, 22 Nov 2013 20:58:21 +0000 (20:58 +0000)
git-svn-id: https://svn.dealii.org/trunk@31767 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/include/deal.II/lac/constraint_matrix.h
deal.II/source/lac/constraint_matrix.cc
tests/lac/constraints_02.cc [new file with mode: 0644]
tests/lac/constraints_02.output [new file with mode: 0644]

index 4bb240c83c686b872d604c844a263cc7bdae62cd..dc48b0b3454a9cc576c22c0ae2bcad6637aa4ecd 100644 (file)
@@ -31,6 +31,7 @@
 #include <set>
 #include <utility>
 #include <complex>
+#include <algorithm>
 
 #include <boost/scoped_ptr.hpp>
 
@@ -660,6 +661,12 @@ public:
    */
   std::size_t memory_consumption () const;
 
+  /**
+   * Add the constraint indices associated to the indices in the given vector. 
+   * The indices in the vector are not repeated.
+   */
+  void resolve_indices(std::vector<types::global_dof_index> &indices) const;
+
   /**
    * @}
    */
index 4c1a7e8facb1f97ca923f106fe3aac5a8c1c8ff1..5ace029bd2d314f14f0e2755bff2cf554df9fc80 100644 (file)
@@ -1549,7 +1549,7 @@ bool ConstraintMatrix::is_identity_constrained (const size_type index) const
 
 
 bool ConstraintMatrix::are_identity_constrained (const size_type index1,
-                                                       const size_type index2) const
+                                                 const size_type index2) const
 {
   if (is_constrained(index1) == true)
     {
@@ -1559,8 +1559,8 @@ bool ConstraintMatrix::are_identity_constrained (const size_type index1,
       // return if an entry for this line was found and if it has only one
       // entry equal to 1.0 and that one is index2
       return ((p.entries.size() == 1) &&
-          (p.entries[0].first == index2) &&
-          (p.entries[0].second == 1.0));
+              (p.entries[0].first == index2) &&
+              (p.entries[0].second == 1.0));
     }
   else if (is_constrained(index2) == true)
     {
@@ -1570,8 +1570,8 @@ bool ConstraintMatrix::are_identity_constrained (const size_type index1,
       // return if an entry for this line was found and if it has only one
       // entry equal to 1.0 and that one is index1
       return ((p.entries.size() == 1) &&
-          (p.entries[0].first == index1) &&
-          (p.entries[0].second == 1.0));
+              (p.entries[0].first == index1) &&
+              (p.entries[0].second == 1.0));
     }
   else
     return false;
@@ -1675,6 +1675,31 @@ ConstraintMatrix::memory_consumption () const
 
 
 
+void
+ConstraintMatrix::resolve_indices (std::vector<types::global_dof_index> &indices) const
+{
+  const unsigned int indices_size = indices.size();
+  const std::vector<std::pair<types::global_dof_index,double> > * line_ptr;
+  for (unsigned int i=0; i<indices_size; ++i)
+    {
+      line_ptr = get_constraint_entries(indices[i]);
+      // if the index is constraint, the constraints indices are added to the
+      // indices vector
+      if (line_ptr!=NULL)
+        {
+          const unsigned int line_size = line_ptr->size();
+          for (unsigned int j=0; j<line_size; ++j)
+            indices.push_back((*line_ptr)[j].first);
+        }
+    }
+
+  // keep only the unique elements
+  std::sort(indices.begin(),indices.end());
+  std::vector<types::global_dof_index>::iterator it;
+  it = std::unique(indices.begin(),indices.end());
+  indices.resize(it-indices.begin());
+}
+
 
 
 // explicit instantiations
diff --git a/tests/lac/constraints_02.cc b/tests/lac/constraints_02.cc
new file mode 100644 (file)
index 0000000..aefaafb
--- /dev/null
@@ -0,0 +1,65 @@
+// ---------------------------------------------------------------------
+// $Id: constraints_01.cc 31349 2013-10-20 19:07:06Z maier $
+//
+// Copyright (C) 2005 - 2013 by the deal.II authors
+//
+// This file is part of the deal.II library.
+//
+// The deal.II library is free software; you can use it, redistribute
+// it, and/or modify it under the terms of the GNU Lesser General
+// Public License as published by the Free Software Foundation; either
+// version 2.1 of the License, or (at your option) any later version.
+// The full text of the license can be found in the file LICENSE at
+// the top level of the deal.II distribution.
+//
+// ---------------------------------------------------------------------
+
+
+#include "../tests.h"
+#include  <deal.II/lac/constraint_matrix.h>
+
+#include <fstream>
+#include <vector>
+
+void test()
+{
+  ConstraintMatrix constraints;
+
+  constraints.add_line(1);
+  constraints.add_entry(1,2,1.);
+  constraints.add_entry(1,3,1.);
+  
+  constraints.add_line(3);
+  constraints.add_entry(3,4,1.);
+  constraints.add_entry(3,5,1.);
+
+  constraints.add_line(5);
+  constraints.add_entry(5,0,1.);
+
+  constraints.close();
+
+  std::vector<types::global_dof_index> indices(4);
+  indices[0] = 1;
+  indices[1] = 2;
+  indices[2] = 3;
+  indices[3] = 5;
+  
+  constraints.resolve_indices(indices);
+
+  for (unsigned int i=0; i<indices.size(); ++i)
+    deallog<<"Index: "<<indices[i]<<std::endl;
+}
+
+int main()
+{
+  std::ofstream logfile("output");
+  logfile.precision(2);
+
+  deallog.attach(logfile);
+  deallog.depth_console(0);
+  deallog.threshold_double(1.e-10);
+
+  test();
+
+  deallog<<"OK"<<std::endl;
+}
diff --git a/tests/lac/constraints_02.output b/tests/lac/constraints_02.output
new file mode 100644 (file)
index 0000000..32dc666
--- /dev/null
@@ -0,0 +1,8 @@
+
+DEAL::Index: 0
+DEAL::Index: 1
+DEAL::Index: 2
+DEAL::Index: 3
+DEAL::Index: 4
+DEAL::Index: 5
+DEAL::OK

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.