From f013913a417ef789fd093f0917f7a2530408365c Mon Sep 17 00:00:00 2001 From: Wolfgang Bangerth Date: Wed, 31 Jan 2001 13:55:08 +0000 Subject: [PATCH] Implement ConstraintMatrix::merge git-svn-id: https://svn.dealii.org/trunk@3852 0785d39b-7218-0410-832d-ea1e28bc413d --- .../deal.II/include/dofs/dof_constraints.h | 33 +++++++++++ .../deal.II/source/dofs/dof_constraints.cc | 55 ++++++++++++++++++- deal.II/doc/news/2001/c-3-1.html | 8 +++ 3 files changed, 95 insertions(+), 1 deletion(-) diff --git a/deal.II/deal.II/include/dofs/dof_constraints.h b/deal.II/deal.II/include/dofs/dof_constraints.h index 740c164ed5..e0e106ae93 100644 --- a/deal.II/deal.II/include/dofs/dof_constraints.h +++ b/deal.II/deal.II/include/dofs/dof_constraints.h @@ -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: diff --git a/deal.II/deal.II/source/dofs/dof_constraints.cc b/deal.II/deal.II/source/dofs/dof_constraints.cc index 36996b2fd1..3a85a1bd17 100644 --- a/deal.II/deal.II/source/dofs/dof_constraints.cc +++ b/deal.II/deal.II/source/dofs/dof_constraints.cc @@ -24,6 +24,8 @@ #include #include #include +#include + 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 this_dofs; + for (std::vector::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::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(); + std::vector tmp; + lines.swap (tmp); sorted = false; }; diff --git a/deal.II/doc/news/2001/c-3-1.html b/deal.II/doc/news/2001/c-3-1.html index 4efeb7ce3f..2b9b1253a6 100644 --- a/deal.II/doc/news/2001/c-3-1.html +++ b/deal.II/doc/news/2001/c-3-1.html @@ -93,6 +93,14 @@ documentation, etc.

deal.II

    +
  1. + New: There is now a function + ConstraintMatrix::merge that merges + the constraints represented by two constraint matrices into one + object. +
    + (WB 2001/01/31) +


-- 2.39.5