From: bangerth Date: Mon, 14 Jan 2013 14:10:11 +0000 (+0000) Subject: Patch by Daniel Arndt: add is_local_range() to all vector classes. Use it in the... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=b28ea796484dd426f6a2b7bced7cb68e98327a59;p=dealii-svn.git Patch by Daniel Arndt: add is_local_range() to all vector classes. Use it in the ConstraintMatrix. git-svn-id: https://svn.dealii.org/trunk@28047 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index 635f13388b..e3c0fcd829 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -177,6 +177,11 @@ DoFHandler, in particular removal of specializations.

Specific improvements

    +
  1. New: All vector classes should now have a in_local_range() +function indicating whether a given index is locally stored or not. +
    +(Daniel Arndt, 2013/01/14) +
  2. Fixed: The one-argument version of ConstraintMatrix::condense was not prepared to deal with parallel vectors. This is now fixed.
    diff --git a/deal.II/include/deal.II/lac/block_vector_base.h b/deal.II/include/deal.II/lac/block_vector_base.h index a36f8daf8c..2de0135288 100644 --- a/deal.II/include/deal.II/lac/block_vector_base.h +++ b/deal.II/include/deal.II/lac/block_vector_base.h @@ -957,6 +957,13 @@ public: */ real_type linfty_norm () const; + /** + * Returns true if the given global index is + * in the local range of this processor. + * Asks the corresponding block. + */ + bool in_local_range (const types::global_dof_index global_index) const; + /** * Return whether the vector contains only * elements with value zero. This function @@ -1866,6 +1873,18 @@ BlockVectorBase::end() const } +template +inline +bool +BlockVectorBase::in_local_range +(const types::global_dof_index global_index) const +{ + const std::pair local_index + = block_indices.global_to_local (global_index); + + return components[local_index.first].in_local_range (global_index); +} + template bool diff --git a/deal.II/include/deal.II/lac/constraint_matrix.templates.h b/deal.II/include/deal.II/lac/constraint_matrix.templates.h index 587e4fc30b..aea9d0c6c0 100644 --- a/deal.II/include/deal.II/lac/constraint_matrix.templates.h +++ b/deal.II/include/deal.II/lac/constraint_matrix.templates.h @@ -160,10 +160,11 @@ ConstraintMatrix::condense (VectorType &vec) const const typename VectorType::value_type old_value = vec(constraint_line->line); for (unsigned int q=0; q!=constraint_line->entries.size(); ++q) - vec(constraint_line->entries[q].first) - += (static_cast - (old_value) * - constraint_line->entries[q].second); + if (vec.in_local_range(constraint_line->entries[q].first) == true) + vec(constraint_line->entries[q].first) + += (static_cast + (old_value) * + constraint_line->entries[q].second); } vec.compress(); @@ -171,7 +172,8 @@ ConstraintMatrix::condense (VectorType &vec) const for (std::vector::const_iterator constraint_line = lines.begin(); constraint_line!=lines.end(); ++constraint_line) - vec(constraint_line->line) = 0.; + if (vec.in_local_range(constraint_line->line) == true) + vec(constraint_line->line) = 0.; } @@ -2875,3 +2877,4 @@ add_entries_local_to_global (const std::vector &local_dof_indices, DEAL_II_NAMESPACE_CLOSE #endif + diff --git a/deal.II/include/deal.II/lac/vector.h b/deal.II/include/deal.II/lac/vector.h index ca8980b124..97058d7788 100644 --- a/deal.II/include/deal.II/lac/vector.h +++ b/deal.II/include/deal.II/lac/vector.h @@ -579,6 +579,14 @@ public: */ real_type linfty_norm () const; + /** + * Returns true if the given global index is + * in the local range of this processor. + * Since this is not a distributed + * vector the method always returns true. + */ + bool in_local_range (const types::global_dof_index global_index) const; + /** * Return dimension of the vector. */ @@ -1189,6 +1197,15 @@ unsigned int Vector::size () const } +template +inline +bool Vector::in_local_range +(const types::global_dof_index global_index) const +{ + return true; +} + + template inline