From: frohne Date: Tue, 1 Nov 2011 21:30:31 +0000 (+0000) Subject: Implementation of an alternative handling of inhomogeneous constraints in ConstraintM... X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=3d417a03d904d6473625ecbb47e3fe7fad710025;p=dealii-svn.git Implementation of an alternative handling of inhomogeneous constraints in ConstraintMatrix: use_inhomogeneities_for_rhs in distribute_local_to_global() git-svn-id: https://svn.dealii.org/trunk@24715 0785d39b-7218-0410-832d-ea1e28bc413d --- diff --git a/deal.II/doc/doxygen/headers/constraints.h b/deal.II/doc/doxygen/headers/constraints.h index 6fa5c9d8d8..1a96c8519d 100644 --- a/deal.II/doc/doxygen/headers/constraints.h +++ b/deal.II/doc/doxygen/headers/constraints.h @@ -283,7 +283,34 @@ * has already been condensed before). * * The use of ConstraintMatrix for implementing Dirichlet boundary conditions - * is discussed in the step-22 tutorial program. + * is discussed in the step-22 tutorial program. A further example that applies + * the ConstraintMatrix is step-41. The situation here is little more complicated, + * because there we have some constraints which are not at the boundary. + * There are two ways to apply inhomogeneous constraints after creating the + * ConstraintMatrix: + * + * First: + * - Set the solution to zero in the inhomogeneous constrained components + * using the ConstraintMatrix::set_zero() function (or start with a solution + * vector equal to zero) + * - Apply the ConstraintMatrix::distribute_local_to_global() function to the + * system matrix and the right-hand-side with the parameter + * use_inhomogeneities_for_rhs = false (default) + * - solve() the linear system + * - Apply ConstraintMatrix::distribute() to the solution + * + * Second: + * - Set the concerning components of the solution to the inhomogeneous + * constrained values + * - Use the ConstraintMatrix::distribute_local_to_global() function with the parameter + * use_inhomogeneities_for_rhs = true and apply it to + * the system matrix and the right-hand-side + * - solve() the linear system + * - Depending on the solver now you have to apply the ConstraintMatrix::distribute() + * function to the solution, because the solver could change the constrained + * values in the solution. For a krylov based solver this should not be the + * case, but it is still possible that there is a difference between the + * inhomogeneous value and the solution value in the order of machine precision. * * *

Dealing with conflicting constraints

diff --git a/deal.II/doc/news/changes.h b/deal.II/doc/news/changes.h index d66ce3821b..c0ee0ad1b0 100644 --- a/deal.II/doc/news/changes.h +++ b/deal.II/doc/news/changes.h @@ -47,6 +47,11 @@ enabled due to a missing include file in file

Specific improvements

+
    +
  1. New: Implementation of an alternative handling of inhomogeneous constraints in ConstraintMatrix. This is controlled with a new parameter use_inhomogeneities_for_rhs in distribute_local_to_global() and determines whether the correct or zero values (this was the case before and still is the default) are kept in the linear system during the solution process. +
    +(Jörg Frohne, 2011/11/01) +
    1. Fixed: SparseMatrix::mmult and SpareMatrix::Tmmult had a number of issues that are now fixed: (i) rebuilding the sparsity pattern was allowed diff --git a/deal.II/include/deal.II/lac/constraint_matrix.h b/deal.II/include/deal.II/lac/constraint_matrix.h index 3de3362880..1e8aeedb3b 100644 --- a/deal.II/include/deal.II/lac/constraint_matrix.h +++ b/deal.II/include/deal.II/lac/constraint_matrix.h @@ -654,7 +654,7 @@ class ConstraintMatrix : public Subscriptor * This function does much the same as * the above one, except that it * condenses the matrix struct - * 'in-place'. It does not remove + * 'in-place'. It does not removes * nonzero entries from the matrix but * adds those needed for the process of * distribution of the constrained @@ -1175,13 +1175,17 @@ class ConstraintMatrix : public Subscriptor MatrixType &global_matrix) const; /** - * This function simultaneously writes - * elements into matrix and vector, - * according to the constraints - * specified by the calling - * ConstraintMatrix. This function can - * correctly handle inhomogeneous - * constraints as well. + * This function simultaneously + * writes elements into matrix + * and vector, according to the + * constraints specified by the + * calling ConstraintMatrix. This + * function can correctly handle + * inhomogeneous constraints as + * well. For the parameter + * use_inhomogeneities_for_rhs + * see the documentation in @ref + * constraints module. * * Note: This function is not * thread-safe, so you will need to @@ -1194,7 +1198,8 @@ class ConstraintMatrix : public Subscriptor const Vector &local_vector, const std::vector &local_dof_indices, MatrixType &global_matrix, - VectorType &global_vector) const; + VectorType &global_vector, + bool use_inhomogeneities_for_rhs = false) const; /** * Do a similar operation as the @@ -1668,6 +1673,7 @@ class ConstraintMatrix : public Subscriptor const std::vector &local_dof_indices, MatrixType &global_matrix, VectorType &global_vector, + bool use_inhomogeneities_for_rhs, internal::bool2type) const; /** @@ -1682,6 +1688,7 @@ class ConstraintMatrix : public Subscriptor const std::vector &local_dof_indices, MatrixType &global_matrix, VectorType &global_vector, + bool use_inhomogeneities_for_rhs, internal::bool2type) const; /** @@ -2059,14 +2066,15 @@ distribute_local_to_global (const FullMatrix &local_matrix, const Vector &local_vector, const std::vector &local_dof_indices, MatrixType &global_matrix, - VectorType &global_vector) const + VectorType &global_vector, + bool use_inhomogeneities_for_rhs) const { // enter the internal function with the // respective block information set, the // actual implementation follows in the // cm.templates.h file. distribute_local_to_global (local_matrix, local_vector, local_dof_indices, - global_matrix, global_vector, + global_matrix, global_vector, use_inhomogeneities_for_rhs, internal::bool2type::value>()); } 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 f4dd01fbe3..263356543e 100644 --- a/deal.II/include/deal.II/lac/constraint_matrix.templates.h +++ b/deal.II/include/deal.II/lac/constraint_matrix.templates.h @@ -1913,12 +1913,15 @@ namespace internals // hanging nodes in 3d). however, in // the line below, we do actually do // something with this dof - template + template inline void set_matrix_diagonals (const internals::GlobalRowsFromLocal &global_rows, const std::vector &local_dof_indices, const FullMatrix &local_matrix, - MatrixType &global_matrix) + const ConstraintMatrix &constraints, + MatrixType &global_matrix, + VectorType &global_vector, + bool use_inhomogeneities_for_rhs) { if (global_rows.n_constraints() > 0) { @@ -1935,6 +1938,15 @@ namespace internals = (std::fabs(local_matrix(local_row,local_row)) != 0 ? std::fabs(local_matrix(local_row,local_row)) : average_diagonal); global_matrix.add(global_row, global_row, new_diagonal); + + // if the use_inhomogeneities_for_rhs flag is + // set to true, the inhomogeneities are used + // to create the global vector. instead of + // fill in a zero in the ith components with an + // inhomogeneity, we set those to: + // inhomogeneity(i)*global_matrix (i,i). + if (use_inhomogeneities_for_rhs == true) + global_vector(global_row) += constraints.get_inhomogeneity(global_row) * new_diagonal; } } } @@ -2190,6 +2202,7 @@ ConstraintMatrix::distribute_local_to_global ( const std::vector &local_dof_indices, MatrixType &global_matrix, VectorType &global_vector, + bool use_inhomogeneities_for_rhs, internal::bool2type) const { // check whether we work on real vectors @@ -2281,7 +2294,8 @@ ConstraintMatrix::distribute_local_to_global ( } internals::set_matrix_diagonals (global_rows, local_dof_indices, - local_matrix, global_matrix); + local_matrix, *this, + global_matrix, global_vector, use_inhomogeneities_for_rhs); } @@ -2350,6 +2364,7 @@ distribute_local_to_global (const FullMatrix &local_matrix, const std::vector &local_dof_indices, MatrixType &global_matrix, VectorType &global_vector, + bool use_inhomogeneities_for_rhs, internal::bool2type) const { const bool use_vectors = (local_vector.size() == 0 && @@ -2454,7 +2469,8 @@ distribute_local_to_global (const FullMatrix &local_matrix, } internals::set_matrix_diagonals (global_rows, local_dof_indices, - local_matrix, global_matrix); + local_matrix, *this, + global_matrix, global_vector, use_inhomogeneities_for_rhs); } diff --git a/deal.II/source/lac/constraint_matrix.cc b/deal.II/source/lac/constraint_matrix.cc index cd6872efe3..e0db3731b7 100644 --- a/deal.II/source/lac/constraint_matrix.cc +++ b/deal.II/source/lac/constraint_matrix.cc @@ -2352,6 +2352,7 @@ distribute_local_to_global (const FullMatrix const std::vector &, \ MatrixType &, \ VectorType &, \ + bool , \ internal::bool2type) const #define MATRIX_FUNCTIONS(MatrixType) \ template void ConstraintMatrix:: \ @@ -2360,6 +2361,7 @@ distribute_local_to_global > (const FullMatrix const std::vector &, \ MatrixType &, \ Vector &, \ + bool , \ internal::bool2type) const #define BLOCK_MATRIX_VECTOR_FUNCTIONS(MatrixType, VectorType) \ template void ConstraintMatrix:: \ @@ -2368,6 +2370,7 @@ distribute_local_to_global (const FullMatrix const std::vector &, \ MatrixType &, \ VectorType &, \ + bool , \ internal::bool2type) const #define BLOCK_MATRIX_FUNCTIONS(MatrixType) \ template void ConstraintMatrix:: \ @@ -2376,6 +2379,7 @@ distribute_local_to_global > (const FullMatrix const std::vector &, \ MatrixType &, \ Vector &, \ + bool , \ internal::bool2type) const MATRIX_FUNCTIONS(SparseMatrix);