From b9b205024c693e64e8f16e293bd76eadb4c9ab4e Mon Sep 17 00:00:00 2001 From: wolf Date: Tue, 1 Feb 2000 17:57:28 +0000 Subject: [PATCH] Add a function which we can ask whether a certain DoF is constrained or not. git-svn-id: https://svn.dealii.org/trunk@2308 0785d39b-7218-0410-832d-ea1e28bc413d --- .../deal.II/include/dofs/dof_constraints.h | 18 +++++++++++ .../deal.II/source/dofs/dof_constraints.cc | 32 +++++++++++++++++-- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/deal.II/deal.II/include/dofs/dof_constraints.h b/deal.II/deal.II/include/dofs/dof_constraints.h index 4b4500ed1b..740cb20431 100644 --- a/deal.II/deal.II/include/dofs/dof_constraints.h +++ b/deal.II/deal.II/include/dofs/dof_constraints.h @@ -154,6 +154,24 @@ class ConstraintMatrix : public Subscriptor */ unsigned int n_constraints () const; + /** + * Return whether the degree of + * freedom with number #index# is + * a constrained one. + * + * Note that if #close# was + * called before, then this + * function is significantly + * faster, since then the + * constrained degrees of freedom + * are sorted and we can do a + * binary search, while before + * #close# was called, we have to + * perform a linear search + * through all entries. + */ + bool is_constrained (const unsigned int index) const; + /** * Condense a given sparsity pattern. This * function assumes the uncondensed diff --git a/deal.II/deal.II/source/dofs/dof_constraints.cc b/deal.II/deal.II/source/dofs/dof_constraints.cc index b07515369a..9e1cf51df2 100644 --- a/deal.II/deal.II/source/dofs/dof_constraints.cc +++ b/deal.II/deal.II/source/dofs/dof_constraints.cc @@ -12,7 +12,9 @@ -bool ConstraintMatrix::ConstraintLine::operator < (const ConstraintMatrix::ConstraintLine &a) const +inline +bool +ConstraintMatrix::ConstraintLine::operator < (const ConstraintLine &a) const { return line < a.line; }; @@ -308,12 +310,38 @@ void ConstraintMatrix::condense (SparsityPattern &sparsity) const { -unsigned int ConstraintMatrix::n_constraints () const { +unsigned int ConstraintMatrix::n_constraints () const +{ return lines.size(); }; +bool ConstraintMatrix::is_constrained (const unsigned int index) const +{ + if (sorted == true) + { + + ConstraintLine index_comparison; + index_comparison.line = index; + + return binary_search (lines.begin (), + lines.end (), + index_comparison); + } + else + { + for (vector::const_iterator i=lines.begin(); + i!=lines.end(); ++i) + if (i->line == index) + return true; + + return false; + }; +}; + + + void ConstraintMatrix::print (ostream &out) const { for (unsigned int i=0; i!=lines.size(); ++i) for (unsigned int j=0; j!=lines[i].entries.size(); ++j) -- 2.39.5