From: turcksin Date: Fri, 22 Nov 2013 20:58:21 +0000 (+0000) Subject: Add a function to resolve constraint indices. X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=00d16cea6a0ffc4c9b304142c9f99c45042f53fe;p=dealii-svn.git Add a function to resolve constraint indices. git-svn-id: https://svn.dealii.org/trunk@31767 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/include/deal.II/lac/constraint_matrix.h b/deal.II/include/deal.II/lac/constraint_matrix.h index 4bb240c83c..dc48b0b345 100644 --- a/deal.II/include/deal.II/lac/constraint_matrix.h +++ b/deal.II/include/deal.II/lac/constraint_matrix.h @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -660,6 +661,12 @@ public: */ std::size_t memory_consumption () const; + /** + * Add the constraint indices associated to the indices in the given vector. + * The indices in the vector are not repeated. + */ + void resolve_indices(std::vector &indices) const; + /** * @} */ diff --git a/deal.II/source/lac/constraint_matrix.cc b/deal.II/source/lac/constraint_matrix.cc index 4c1a7e8fac..5ace029bd2 100644 --- a/deal.II/source/lac/constraint_matrix.cc +++ b/deal.II/source/lac/constraint_matrix.cc @@ -1549,7 +1549,7 @@ bool ConstraintMatrix::is_identity_constrained (const size_type index) const bool ConstraintMatrix::are_identity_constrained (const size_type index1, - const size_type index2) const + const size_type index2) const { if (is_constrained(index1) == true) { @@ -1559,8 +1559,8 @@ bool ConstraintMatrix::are_identity_constrained (const size_type index1, // return if an entry for this line was found and if it has only one // entry equal to 1.0 and that one is index2 return ((p.entries.size() == 1) && - (p.entries[0].first == index2) && - (p.entries[0].second == 1.0)); + (p.entries[0].first == index2) && + (p.entries[0].second == 1.0)); } else if (is_constrained(index2) == true) { @@ -1570,8 +1570,8 @@ bool ConstraintMatrix::are_identity_constrained (const size_type index1, // return if an entry for this line was found and if it has only one // entry equal to 1.0 and that one is index1 return ((p.entries.size() == 1) && - (p.entries[0].first == index1) && - (p.entries[0].second == 1.0)); + (p.entries[0].first == index1) && + (p.entries[0].second == 1.0)); } else return false; @@ -1675,6 +1675,31 @@ ConstraintMatrix::memory_consumption () const +void +ConstraintMatrix::resolve_indices (std::vector &indices) const +{ + const unsigned int indices_size = indices.size(); + const std::vector > * line_ptr; + for (unsigned int i=0; isize(); + for (unsigned int j=0; j::iterator it; + it = std::unique(indices.begin(),indices.end()); + indices.resize(it-indices.begin()); +} + // explicit instantiations diff --git a/tests/lac/constraints_02.cc b/tests/lac/constraints_02.cc new file mode 100644 index 0000000000..aefaafbb80 --- /dev/null +++ b/tests/lac/constraints_02.cc @@ -0,0 +1,65 @@ +// --------------------------------------------------------------------- +// $Id: constraints_01.cc 31349 2013-10-20 19:07:06Z maier $ +// +// Copyright (C) 2005 - 2013 by the deal.II authors +// +// This file is part of the deal.II library. +// +// The deal.II library is free software; you can use it, redistribute +// it, and/or modify it under the terms of the GNU Lesser General +// Public License as published by the Free Software Foundation; either +// version 2.1 of the License, or (at your option) any later version. +// The full text of the license can be found in the file LICENSE at +// the top level of the deal.II distribution. +// +// --------------------------------------------------------------------- + + +#include "../tests.h" +#include + +#include +#include + +void test() +{ + ConstraintMatrix constraints; + + constraints.add_line(1); + constraints.add_entry(1,2,1.); + constraints.add_entry(1,3,1.); + + constraints.add_line(3); + constraints.add_entry(3,4,1.); + constraints.add_entry(3,5,1.); + + constraints.add_line(5); + constraints.add_entry(5,0,1.); + + constraints.close(); + + std::vector indices(4); + indices[0] = 1; + indices[1] = 2; + indices[2] = 3; + indices[3] = 5; + + constraints.resolve_indices(indices); + + for (unsigned int i=0; i