From 14594e0cd5cb8e7186cc9979400ca1095bf26c17 Mon Sep 17 00:00:00 2001 From: wolf Date: Fri, 8 Apr 2005 20:47:44 +0000 Subject: [PATCH] The distribute_local_to_global function needs to know which dofs are constrained to do its work properly. git-svn-id: https://svn.dealii.org/trunk@10443 0785d39b-7218-0410-832d-ea1e28bc413d --- .../deal.II/include/dofs/dof_constraints.h | 57 ++++++++++++++++++- .../include/dofs/dof_constraints.templates.h | 51 ++++++++++------- .../deal.II/source/dofs/dof_constraints.cc | 2 + tests/bits/dof_constraints_01.cc | 3 +- tests/bits/dof_constraints_02.cc | 3 +- 5 files changed, 93 insertions(+), 23 deletions(-) diff --git a/deal.II/deal.II/include/dofs/dof_constraints.h b/deal.II/deal.II/include/dofs/dof_constraints.h index 68d824245c..95adfa5b46 100644 --- a/deal.II/deal.II/include/dofs/dof_constraints.h +++ b/deal.II/deal.II/include/dofs/dof_constraints.h @@ -16,6 +16,7 @@ #include #include +#include #include #include #include @@ -656,7 +657,7 @@ class ConstraintMatrix : public Subscriptor * In contrast to the similar function in * the DoFAccessor class, this function * also takes care of constraints, - * i.e. of one of the elements of @p + * i.e. if one of the elements of @p * local_dof_indices belongs to a * constrained node, then rather than * writing the corresponding element of @@ -672,11 +673,37 @@ class ConstraintMatrix : public Subscriptor * the condense function after the * vectors and matrices are fully * assembled. + * + * In order to do its work + * properly, this function has to + * know which degrees of freedom + * are fixed, for example + * boundary values. For this, the + * third argument is a map + * between the numbers of the + * DoFs that are fixed and the + * values they are fixed to. One + * can pass an empty map in for + * this argument, but note that + * you will then have to fix + * these nodes later on again, + * for example by using + * MatrixTools::apply_boundary_values + * to the resulting + * matrix. However, since the + * present function was written + * for the express purpose of not + * having to use tools that later + * modify the matrix, it is + * advisable to have the list of + * fixed nodes available when + * calling the present function. */ template void distribute_local_to_global (const Vector &local_vector, const std::vector &local_dof_indices, + const std::map &fixed_dofs, VectorType &global_vector) const; /** @@ -697,7 +724,7 @@ class ConstraintMatrix : public Subscriptor * In contrast to the similar function in * the DoFAccessor class, this function * also takes care of constraints, - * i.e. of one of the elements of @p + * i.e. if one of the elements of @p * local_dof_indices belongs to a * constrained node, then rather than * writing the corresponding element of @@ -736,11 +763,37 @@ class ConstraintMatrix : public Subscriptor * the condense function after the * vectors and matrices are fully * assembled. + * + * In order to do its work + * properly, this function has to + * know which degrees of freedom + * are fixed, for example + * boundary values. For this, the + * third argument is a map + * between the numbers of the + * DoFs that are fixed and the + * values they are fixed to. One + * can pass an empty map in for + * this argument, but note that + * you will then have to fix + * these nodes later on again, + * for example by using + * MatrixTools::apply_boundary_values + * to the resulting + * matrix. However, since the + * present function was written + * for the express purpose of not + * having to use tools that later + * modify the matrix, it is + * advisable to have the list of + * fixed nodes available when + * calling the present function. */ template void distribute_local_to_global (const FullMatrix &local_matrix, const std::vector &local_dof_indices, + const std::map &fixed_dofs, MatrixType &global_matrix) const; /** diff --git a/deal.II/deal.II/include/dofs/dof_constraints.templates.h b/deal.II/deal.II/include/dofs/dof_constraints.templates.h index 522b54656c..ea249687d0 100644 --- a/deal.II/deal.II/include/dofs/dof_constraints.templates.h +++ b/deal.II/deal.II/include/dofs/dof_constraints.templates.h @@ -554,11 +554,15 @@ ConstraintMatrix::set_zero (VectorType &vec) const +#define is_fixed(i) (fixed_dofs.find(i) != fixed_dofs.end()) +//#define is_fixed(i) false + template void ConstraintMatrix:: distribute_local_to_global (const Vector &local_vector, const std::vector &local_dof_indices, + const std::map &fixed_dofs, VectorType &global_vector) const { Assert (local_vector.size() == local_dof_indices.size(), @@ -589,15 +593,19 @@ distribute_local_to_global (const Vector &local_vector, lines.end(), index_comparison); - // if the line is not constrained, - // then simply copy the - // data. otherwise distribute it + // if the line is not + // constrained, then simply + // copy the data. otherwise + // distribute it, but make + // sure we don't touch the + // entries of fixed dofs if (position->line != local_dof_indices[i]) global_vector(local_dof_indices[i]) += local_vector(i); else for (unsigned int j=0; jentries.size(); ++j) - global_vector(position->entries[j].first) - += local_vector(i) * position->entries[j].second; + if (!is_fixed(position->entries[j].first)) + global_vector(position->entries[j].first) + += local_vector(i) * position->entries[j].second; } } } @@ -609,6 +617,7 @@ void ConstraintMatrix:: distribute_local_to_global (const FullMatrix &local_matrix, const std::vector &local_dof_indices, + const std::map &fixed_dofs, MatrixType &global_matrix) const { Assert (local_matrix.n() == local_dof_indices.size(), @@ -693,10 +702,11 @@ distribute_local_to_global (const FullMatrix &local_matrix, // ok, row is constrained, // but column is not for (unsigned int q=0; qentries.size(); ++q) - global_matrix.add (position_i->entries[q].first, - local_dof_indices[j], - local_matrix(i,j) * - position_i->entries[q].second); + if (!is_fixed(position_i->entries[q].first)) + global_matrix.add (position_i->entries[q].first, + local_dof_indices[j], + local_matrix(i,j) * + position_i->entries[q].second); } else if ((is_constrained_i == false) && (is_constrained_j == true)) @@ -705,10 +715,11 @@ distribute_local_to_global (const FullMatrix &local_matrix, // round: row ok, column is // constrained for (unsigned int q=0; qentries.size(); ++q) - global_matrix.add (local_dof_indices[i], - position_j->entries[q].first, - local_matrix(i,j) * - position_j->entries[q].second); + if (!is_fixed(position_j->entries[q].first)) + global_matrix.add (local_dof_indices[i], + position_j->entries[q].first, + local_matrix(i,j) * + position_j->entries[q].second); } else if ((is_constrained_i == true) && (is_constrained_j == true)) @@ -716,12 +727,14 @@ distribute_local_to_global (const FullMatrix &local_matrix, // last case: both row and // column are constrained for (unsigned int p=0; pentries.size(); ++p) - for (unsigned int q=0; qentries.size(); ++q) - global_matrix.add (position_i->entries[p].first, - position_j->entries[q].first, - local_matrix(i,j) * - position_i->entries[p].second * - position_j->entries[q].second); + if (!is_fixed(position_i->entries[p].first)) + for (unsigned int q=0; qentries.size(); ++q) + if (!is_fixed(position_j->entries[q].first)) + global_matrix.add (position_i->entries[p].first, + position_j->entries[q].first, + local_matrix(i,j) * + position_i->entries[p].second * + position_j->entries[q].second); // to make sure that the // global matrix remains diff --git a/deal.II/deal.II/source/dofs/dof_constraints.cc b/deal.II/deal.II/source/dofs/dof_constraints.cc index 8a270988ac..acaa000c9c 100644 --- a/deal.II/deal.II/source/dofs/dof_constraints.cc +++ b/deal.II/deal.II/source/dofs/dof_constraints.cc @@ -1195,6 +1195,7 @@ ConstraintMatrix::memory_consumption () const template void ConstraintMatrix:: \ distribute_local_to_global (const Vector &, \ const std::vector &, \ + const std::map &, \ VectorType &) const; \ template void ConstraintMatrix::distribute(const VectorType &condensed,\ VectorType &uncondensed) const;\ @@ -1247,6 +1248,7 @@ ConstraintMatrix::condense(BlockSparseMatrix &uncondensed) const; template void ConstraintMatrix:: \ distribute_local_to_global (const FullMatrix &, \ const std::vector &, \ + const std::map &, \ MatrixType &) const MATRIX_FUNCTIONS(SparseMatrix); diff --git a/tests/bits/dof_constraints_01.cc b/tests/bits/dof_constraints_01.cc index 0d4a3616d1..e16d38035c 100644 --- a/tests/bits/dof_constraints_01.cc +++ b/tests/bits/dof_constraints_01.cc @@ -99,7 +99,8 @@ void test () A.add (local_dofs[i], local_dofs[j], local_matrix(i,j)); // or let other functions do that - constraints.distribute_local_to_global (local_matrix, local_dofs, B); + constraints.distribute_local_to_global (local_matrix, local_dofs, + std::map(), B); } // now condense away constraints from A diff --git a/tests/bits/dof_constraints_02.cc b/tests/bits/dof_constraints_02.cc index b70f9168ff..aac44a4f3c 100644 --- a/tests/bits/dof_constraints_02.cc +++ b/tests/bits/dof_constraints_02.cc @@ -90,7 +90,8 @@ void test () A(local_dofs[i]) += local_vector(i); // or let other functions do that - constraints.distribute_local_to_global (local_vector, local_dofs, B); + constraints.distribute_local_to_global (local_vector, local_dofs, + std::map(), B); } // now condense away constraints from A -- 2.39.5