]> https://gitweb.dealii.org/ - dealii-svn.git/commitdiff
Improve the ConstraintMatrix::merge function for the case that objects are already...
authorwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 9 Aug 2001 13:43:17 +0000 (13:43 +0000)
committerwolf <wolf@0785d39b-7218-0410-832d-ea1e28bc413d>
Thu, 9 Aug 2001 13:43:17 +0000 (13:43 +0000)
git-svn-id: https://svn.dealii.org/trunk@4873 0785d39b-7218-0410-832d-ea1e28bc413d

deal.II/deal.II/source/dofs/dof_constraints.cc
tests/deal.II/constraints.cc
tests/deal.II/constraints.checked

index 6271db259fe5b5fe567882f624bc7c660445d639..0c0b594545f4df05c4cbf1c98cd2b04fd24d871a 100644 (file)
@@ -335,13 +335,29 @@ void ConstraintMatrix::merge (const ConstraintMatrix &other_constraints)
        {
          if (other_constraints.sorted == true)
            {
+                                              // as the array is
+                                              // sorted, use a
+                                              // bindary find to
+                                              // check for the
+                                              // existence of the
+                                              // element. if it does
+                                              // not exist, then the
+                                              // pointer may still
+                                              // point into tha
+                                              // array, but to an
+                                              // element of which the
+                                              // indices do not
+                                              // match, so return the
+                                              // end iterator
              ConstraintLine index_comparison;
              index_comparison.line = line->entries[i].first;
-//TODO:[WB] we should use a binary search, since we are sure that the array is sorted
              tmp_other_lines[i] =
-               std::find (other_constraints.lines.begin (),
-                          other_constraints.lines.end (),
-                          index_comparison);
+               std::lower_bound (other_constraints.lines.begin (),
+                                 other_constraints.lines.end (),
+                                 index_comparison);
+             if ((tmp_other_lines[i] != other_constraints.lines.end ()) &&
+                 (tmp_other_lines[i]->line != index_comparison.line))
+               tmp_other_lines[i] = other_constraints.lines.end ();
            }
          else
            {
index e5f12e4d1d17395b6fb6c7ce799fe22430886992..c87036790aade555bd8d3ef805843814476049a3 100644 (file)
@@ -32,6 +32,9 @@
 #include <cstdlib>
 
 
+std::ofstream logfile("constraints.output");
+
+
 void make_tria (Triangulation<3> &tria, int step) 
 {
   switch (step)
@@ -230,9 +233,56 @@ void make_tria (Triangulation<3> &tria, int step)
 };
 
 
+
+void merge_check ()
+{
+  deallog << "Checking ConstraintMatrix::merge" << std::endl;
+
+                                  // check twice, once with closed
+                                  // objects, once with open ones
+  for (unsigned int run=0; run<2; ++run)
+    {
+      deallog << "Checking with " << (run == 0 ? "open" : "closed")
+             << " objects" << std::endl;
+      
+                                      // check that the `merge' function
+                                      // works correctly
+      ConstraintMatrix c1, c2;
+
+                                  // enter simple line
+      c1.add_line (0);
+      c1.add_entry (0, 11, 1.);
+                                      // add more complex line
+      c1.add_line (1);
+      c1.add_entry (1, 3, 0.5);
+      c1.add_entry (1, 4, 0.5);
+  
+                                  // fill second constraints object
+                                  // with one trivial line and one
+                                  // which further constrains one of
+                                  // the entries in the first object
+      c2.add_line (10);
+      c2.add_entry (10, 11, 1.);
+      c2.add_line (3);
+      c2.add_entry (3, 12, 0.25);
+      c2.add_entry (3, 13, 0.75);
+
+      if (run == 1)
+       {
+         c1.close ();
+         c2.close ();
+       };
+
+                                      // now merge the two and print the
+                                      // results
+      c1.merge (c2);
+      c1.print (logfile);
+    };
+};
+
+
 int main ()
 {
-  std::ofstream logfile("constraints.output");
   logfile.precision (2);
   deallog.attach(logfile);
   deallog.depth_console(0);
@@ -276,5 +326,7 @@ int main ()
 
       delete fe;
     };
+
+  merge_check ();
 };
 
index 0747390089c6dc7cf83588549ede05eae834db61..ab1b92b2e16b49d79e1ee43e2d9e773ca0f005bd 100644 (file)
@@ -6084,3 +6084,20 @@ DEAL::Element=1, Step=8
     284 42:  0.28
     284 47:  0.56
 DEAL::
+DEAL::Checking ConstraintMatrix::merge
+DEAL::Checking with open objects
+    0 11:  1.0
+    1 12:  0.12
+    1 13:  0.38
+    1 4:  0.50
+    10 11:  1.0
+    3 12:  0.25
+    3 13:  0.75
+DEAL::Checking with closed objects
+    0 11:  1.0
+    1 4:  0.50
+    1 12:  0.12
+    1 13:  0.38
+    3 12:  0.25
+    3 13:  0.75
+    10 11:  1.0

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.