#include <set>
#include <utility>
#include <complex>
+#include <algorithm>
#include <boost/scoped_ptr.hpp>
*/
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<types::global_dof_index> &indices) 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)
{
// 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)
{
// 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;
+void
+ConstraintMatrix::resolve_indices (std::vector<types::global_dof_index> &indices) const
+{
+ const unsigned int indices_size = indices.size();
+ const std::vector<std::pair<types::global_dof_index,double> > * line_ptr;
+ for (unsigned int i=0; i<indices_size; ++i)
+ {
+ line_ptr = get_constraint_entries(indices[i]);
+ // if the index is constraint, the constraints indices are added to the
+ // indices vector
+ if (line_ptr!=NULL)
+ {
+ const unsigned int line_size = line_ptr->size();
+ for (unsigned int j=0; j<line_size; ++j)
+ indices.push_back((*line_ptr)[j].first);
+ }
+ }
+
+ // keep only the unique elements
+ std::sort(indices.begin(),indices.end());
+ std::vector<types::global_dof_index>::iterator it;
+ it = std::unique(indices.begin(),indices.end());
+ indices.resize(it-indices.begin());
+}
+
// explicit instantiations
--- /dev/null
+// ---------------------------------------------------------------------
+// $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 <deal.II/lac/constraint_matrix.h>
+
+#include <fstream>
+#include <vector>
+
+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<types::global_dof_index> indices(4);
+ indices[0] = 1;
+ indices[1] = 2;
+ indices[2] = 3;
+ indices[3] = 5;
+
+ constraints.resolve_indices(indices);
+
+ for (unsigned int i=0; i<indices.size(); ++i)
+ deallog<<"Index: "<<indices[i]<<std::endl;
+}
+
+int main()
+{
+ std::ofstream logfile("output");
+ logfile.precision(2);
+
+ deallog.attach(logfile);
+ deallog.depth_console(0);
+ deallog.threshold_double(1.e-10);
+
+ test();
+
+ deallog<<"OK"<<std::endl;
+}
--- /dev/null
+
+DEAL::Index: 0
+DEAL::Index: 1
+DEAL::Index: 2
+DEAL::Index: 3
+DEAL::Index: 4
+DEAL::Index: 5
+DEAL::OK