]> https://gitweb.dealii.org/ - dealii.git/commitdiff
Implement ConstraintMatrix::merge
authorWolfgang Bangerth <bangerth@math.tamu.edu>
Wed, 31 Jan 2001 13:55:08 +0000 (13:55 +0000)
committerWolfgang Bangerth <bangerth@math.tamu.edu>
Wed, 31 Jan 2001 13:55:08 +0000 (13:55 +0000)
git-svn-id: https://svn.dealii.org/trunk@3852 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/include/dofs/dof_constraints.h
deal.II/deal.II/source/dofs/dof_constraints.cc
deal.II/doc/news/2001/c-3-1.html

index 740c164ed5f095ea46d3b4d84dad4679b4db5f03..e0e106ae9381698499534ac93afe19df0aaa9b65 100644 (file)
@@ -160,6 +160,32 @@ class ConstraintMatrix : public Subscriptor
                                      */
     void close ();
 
+                                    /**
+                                     * Merge the constraints
+                                     * represented by the object
+                                     * given as argument into the
+                                     * constraints represented by
+                                     * this object. Both objects may
+                                     * or may not be closed (by
+                                     * having their function
+                                     * @p{close} called before), if
+                                     * this object was closed before,
+                                     * then it will be closed
+                                     * afterwards as well.
+                                     *
+                                     * Note that the constraints in
+                                     * each of the two objects (the
+                                     * old one represented by this
+                                     * object and the argument) may
+                                     * not refer to the same degree
+                                     * of freedom, since this may
+                                     * result in incompatible
+                                     * constraints. If this is
+                                     * nevertheless the case, an
+                                     * exception is thrown.
+                                     */
+    void merge (const ConstraintMatrix &other_constraints);
+    
                                     /**
                                      * Clear all entries of this matrix. Reset
                                      * the flag determining whether new entries
@@ -433,6 +459,13 @@ class ConstraintMatrix : public Subscriptor
                    << "You tried to constrain DoF " << arg1
                    << " to DoF " << arg2
                    << ", but that one is also constrained. This is not allowed!");
+                                    /**
+                                     * Exception.
+                                     */
+    DeclException1 (ExcDoFIsConstrainedFromBothObjects,
+                   int,
+                   << "Degree of freedom " << arg1
+                   << " is constrained from both object in a merge operation.");
     
   private:
 
index 36996b2fd1bf7caa6de8b457b110ca380e414517..3a85a1bd1765bf9244a5f99587bd168ae5499c9b 100644 (file)
@@ -24,6 +24,8 @@
 #include <iostream>
 #include <algorithm>
 #include <numeric>
+#include <set>
+
 
 
 inline
@@ -222,9 +224,60 @@ void ConstraintMatrix::close ()
 
 
 
+void ConstraintMatrix::merge (const ConstraintMatrix &other_constraints)
+{
+                                  // first check whether the
+                                  // constraints in the two objects
+                                  // are for different degrees of
+                                  // freedom
+  if (true)
+    {
+                                      // first insert all dofs in
+                                      // this object into a list...
+      std::set<unsigned int> this_dofs;
+      for (std::vector<ConstraintLine>::const_iterator line=lines.begin();
+          line!=lines.end(); ++line)
+       this_dofs.insert (line->line);
+
+                                      // ...then check whether it
+                                      // appears in the other object
+                                      // as well. note that we have
+                                      // to do this in a somewhat
+                                      // complicated style since the
+                                      // two objects may not be
+                                      // sorted
+      for (std::vector<ConstraintLine>::const_iterator
+            line=other_constraints.lines.begin();
+          line!=other_constraints.lines.end(); ++line)
+       AssertThrow (this_dofs.find (line->line) == this_dofs.end(),
+                    ExcDoFIsConstrainedFromBothObjects (line->line));
+    };
+
+                                  // store the previous state with
+                                  // respect to sorting
+  const bool object_was_sorted = sorted;
+  sorted = false;
+
+                                  // append new lines at the end
+  lines.insert (lines.end(),
+               other_constraints.lines.begin(),
+               other_constraints.lines.end());
+
+                                  // if the object was sorted before,
+                                  // then make sure it is so
+                                  // afterwards as well. otherwise
+                                  // leave everything in the unsorted
+                                  // state
+  if (object_was_sorted == true)
+    close ();
+};
+
+
+
 void ConstraintMatrix::clear ()
 {
-  lines = std::vector<ConstraintLine>();
+  std::vector<ConstraintLine> tmp;
+  lines.swap (tmp);
   sorted = false;
 };
 
index 4efeb7ce3f0fe6723ffce1b403464d1f0c0e5cc9..2b9b1253a6c95b96cb2b512cd3a5c4e9d37b4539 100644 (file)
@@ -93,6 +93,14 @@ documentation, etc</a>.
 <h3>deal.II</h3>
 
 <ol>
+  <li> <p>
+       New: There is now a function
+       <code class="member">ConstraintMatrix::merge</code> that merges
+       the constraints represented by two constraint matrices into one
+       object.
+       <br>
+       (WB 2001/01/31)
+       </p>
 </ol>
 
 <hr>

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.