From: wolf Date: Thu, 9 Aug 2001 13:43:17 +0000 (+0000) Subject: Improve the ConstraintMatrix::merge function for the case that objects are already... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1b90ecaeaa359c28627b439c4a37dfebdffd1bd2;p=dealii-svn.git Improve the ConstraintMatrix::merge function for the case that objects are already sorted. Write a test for this function. git-svn-id: https://svn.dealii.org/trunk@4873 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/source/dofs/dof_constraints.cc b/deal.II/deal.II/source/dofs/dof_constraints.cc index 6271db259f..0c0b594545 100644 --- a/deal.II/deal.II/source/dofs/dof_constraints.cc +++ b/deal.II/deal.II/source/dofs/dof_constraints.cc @@ -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 { diff --git a/tests/deal.II/constraints.cc b/tests/deal.II/constraints.cc index e5f12e4d1d..c87036790a 100644 --- a/tests/deal.II/constraints.cc +++ b/tests/deal.II/constraints.cc @@ -32,6 +32,9 @@ #include +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 (); }; diff --git a/tests/deal.II/constraints.checked b/tests/deal.II/constraints.checked index 0747390089..ab1b92b2e1 100644 --- a/tests/deal.II/constraints.checked +++ b/tests/deal.II/constraints.checked @@ -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