From: Wolfgang Bangerth Date: Thu, 26 Oct 2000 15:49:17 +0000 (+0000) Subject: Add add_entries function. X-Git-Tag: v8.0.0~19970 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8f7b05e267740721f08e429957349eeaf9164727;p=dealii.git Add add_entries function. git-svn-id: https://svn.dealii.org/trunk@3462 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/deal.II/include/dofs/dof_constraints.h b/deal.II/deal.II/include/dofs/dof_constraints.h index a44c9bcd14..25edb18ca9 100644 --- a/deal.II/deal.II/include/dofs/dof_constraints.h +++ b/deal.II/deal.II/include/dofs/dof_constraints.h @@ -130,6 +130,18 @@ class ConstraintMatrix : public Subscriptor const unsigned int column, const double value); + /** + * Add a whole series of entries, + * denoted by pairs of column + * indices and values, to a line + * of constraints. This function + * is equivalent to calling the + * preceeding function more + * several times, but is faster. + */ + void add_entries (const unsigned int line, + const vector > &col_val_pairs); + /** * Close the filling of entries. Since the * lines of a matrix of this type are diff --git a/deal.II/deal.II/source/dofs/dof_constraints.cc b/deal.II/deal.II/source/dofs/dof_constraints.cc index 28d7b2a075..54593af886 100644 --- a/deal.II/deal.II/source/dofs/dof_constraints.cc +++ b/deal.II/deal.II/source/dofs/dof_constraints.cc @@ -101,6 +101,55 @@ void ConstraintMatrix::add_entry (const unsigned int line, +void ConstraintMatrix::add_entries (const unsigned int line, + const vector > &col_val_pairs) +{ + Assert (sorted==false, ExcMatrixIsClosed()); + + vector::iterator line_ptr; + const vector::const_iterator start=lines.begin(); + // the usual case is that the line where + // a value is entered is the one we + // added last, so we search backward + for (line_ptr=&lines.back(); line_ptr!=start; --line_ptr) + if (line_ptr->line == line) + break; + + // if the loop didn't break, then + // line_ptr must be begin(). + // we have an error if that doesn't + // point to 'line' then + Assert (line_ptr->line==line, ExcLineInexistant(line)); + + // if in debug mode, check whether an + // entry for this column already + // exists and if its the same as + // the one entered at present + // + // in any case: skip this entry if + // an entry for this column already + // exists, since we don't want to + // enter it twice + for (vector >::const_iterator col_val_pair = col_val_pairs.begin(); + col_val_pair!=col_val_pairs.end(); ++col_val_pair) + { + for (vector >::const_iterator p=line_ptr->entries.begin(); + p != line_ptr->entries.end(); ++p) + if (p->first == col_val_pair->first) + { + // entry exists, break + // innermost loop + Assert (p->second == col_val_pair->second, + ExcEntryAlreadyExists(line, column, p->second, value)); + break; + }; + + line_ptr->entries.push_back (*col_val_pair); + }; +}; + + + void ConstraintMatrix::close () { Assert (sorted==false, ExcMatrixIsClosed());