From: Jean-Paul Pelteret Date: Mon, 26 Oct 2015 21:11:29 +0000 (+0100) Subject: Fixes in relation to #1673. X-Git-Tag: v8.4.0-rc2~278^2 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f89ba58237c516b023b34f9b3c07e3763cdaff98;p=dealii.git Fixes in relation to #1673. Changed size_type in PreconditionChebyshev. Added static_asserts that compare matrix and vector types in precondtioners. Updated linear_operator_08 test to account for inability to wrap IterativeInverse in a linear_operator. --- diff --git a/include/deal.II/lac/precondition.h b/include/deal.II/lac/precondition.h index 536d4d097f..6c0285b23a 100644 --- a/include/deal.II/lac/precondition.h +++ b/include/deal.II/lac/precondition.h @@ -810,7 +810,7 @@ public: /** * Declare type for container size. */ - typedef typename MATRIX::size_type size_type; + typedef types::global_dof_index size_type; /** * Standardized data struct to pipe additional parameters to the @@ -1092,6 +1092,12 @@ template inline void PreconditionRichardson::vmult (VECTOR &dst, const VECTOR &src) const { +#ifdef DEAL_II_WITH_CXX11 + static_assert( + std::is_same::value, + "PreconditionRichardson and VECTOR must have the same size_type."); +#endif // DEAL_II_WITH_CXX11 + dst.equ(relaxation,src); } @@ -1101,6 +1107,12 @@ template inline void PreconditionRichardson::Tvmult (VECTOR &dst, const VECTOR &src) const { +#ifdef DEAL_II_WITH_CXX11 + static_assert( + std::is_same::value, + "PreconditionRichardson and VECTOR must have the same size_type."); +#endif // DEAL_II_WITH_CXX11 + dst.equ(relaxation,src); } @@ -1108,6 +1120,12 @@ template inline void PreconditionRichardson::vmult_add (VECTOR &dst, const VECTOR &src) const { +#ifdef DEAL_II_WITH_CXX11 + static_assert( + std::is_same::value, + "PreconditionRichardson and VECTOR must have the same size_type."); +#endif // DEAL_II_WITH_CXX11 + dst.add(relaxation,src); } @@ -1117,6 +1135,12 @@ template inline void PreconditionRichardson::Tvmult_add (VECTOR &dst, const VECTOR &src) const { +#ifdef DEAL_II_WITH_CXX11 + static_assert( + std::is_same::value, + "PreconditionRichardson and VECTOR must have the same size_type."); +#endif // DEAL_II_WITH_CXX11 + dst.add(relaxation,src); } @@ -1176,6 +1200,12 @@ template inline void PreconditionJacobi::vmult (VECTOR &dst, const VECTOR &src) const { +#ifdef DEAL_II_WITH_CXX11 + static_assert( + std::is_same::size_type, typename VECTOR::size_type>::value, + "PreconditionJacobi and VECTOR must have the same size_type."); +#endif // DEAL_II_WITH_CXX11 + Assert (this->A!=0, ExcNotInitialized()); this->A->precondition_Jacobi (dst, src, this->relaxation); } @@ -1187,6 +1217,12 @@ template inline void PreconditionJacobi::Tvmult (VECTOR &dst, const VECTOR &src) const { +#ifdef DEAL_II_WITH_CXX11 + static_assert( + std::is_same::size_type, typename VECTOR::size_type>::value, + "PreconditionJacobi and VECTOR must have the same size_type."); +#endif // DEAL_II_WITH_CXX11 + Assert (this->A!=0, ExcNotInitialized()); this->A->precondition_Jacobi (dst, src, this->relaxation); } @@ -1198,6 +1234,12 @@ template inline void PreconditionJacobi::step (VECTOR &dst, const VECTOR &src) const { +#ifdef DEAL_II_WITH_CXX11 + static_assert( + std::is_same::size_type, typename VECTOR::size_type>::value, + "PreconditionJacobi and VECTOR must have the same size_type."); +#endif // DEAL_II_WITH_CXX11 + Assert (this->A!=0, ExcNotInitialized()); this->A->Jacobi_step (dst, src, this->relaxation); } @@ -1209,6 +1251,12 @@ template inline void PreconditionJacobi::Tstep (VECTOR &dst, const VECTOR &src) const { +#ifdef DEAL_II_WITH_CXX11 + static_assert( + std::is_same::size_type, typename VECTOR::size_type>::value, + "PreconditionJacobi and VECTOR must have the same size_type."); +#endif // DEAL_II_WITH_CXX11 + step (dst, src); } @@ -1221,6 +1269,12 @@ template inline void PreconditionSOR::vmult (VECTOR &dst, const VECTOR &src) const { +#ifdef DEAL_II_WITH_CXX11 + static_assert( + std::is_same::size_type, typename VECTOR::size_type>::value, + "PreconditionSOR and VECTOR must have the same size_type."); +#endif // DEAL_II_WITH_CXX11 + Assert (this->A!=0, ExcNotInitialized()); this->A->precondition_SOR (dst, src, this->relaxation); } @@ -1232,6 +1286,12 @@ template inline void PreconditionSOR::Tvmult (VECTOR &dst, const VECTOR &src) const { +#ifdef DEAL_II_WITH_CXX11 + static_assert( + std::is_same::size_type, typename VECTOR::size_type>::value, + "PreconditionSOR and VECTOR must have the same size_type."); +#endif // DEAL_II_WITH_CXX11 + Assert (this->A!=0, ExcNotInitialized()); this->A->precondition_TSOR (dst, src, this->relaxation); } @@ -1243,6 +1303,12 @@ template inline void PreconditionSOR::step (VECTOR &dst, const VECTOR &src) const { +#ifdef DEAL_II_WITH_CXX11 + static_assert( + std::is_same::size_type, typename VECTOR::size_type>::value, + "PreconditionSOR and VECTOR must have the same size_type."); +#endif // DEAL_II_WITH_CXX11 + Assert (this->A!=0, ExcNotInitialized()); this->A->SOR_step (dst, src, this->relaxation); } @@ -1254,6 +1320,12 @@ template inline void PreconditionSOR::Tstep (VECTOR &dst, const VECTOR &src) const { +#ifdef DEAL_II_WITH_CXX11 + static_assert( + std::is_same::size_type, typename VECTOR::size_type>::value, + "PreconditionSOR and VECTOR must have the same size_type."); +#endif // DEAL_II_WITH_CXX11 + Assert (this->A!=0, ExcNotInitialized()); this->A->TSOR_step (dst, src, this->relaxation); } @@ -1301,6 +1373,12 @@ template inline void PreconditionSSOR::vmult (VECTOR &dst, const VECTOR &src) const { +#ifdef DEAL_II_WITH_CXX11 + static_assert( + std::is_same::size_type, typename VECTOR::size_type>::value, + "PreconditionSSOR and VECTOR must have the same size_type."); +#endif // DEAL_II_WITH_CXX11 + Assert (this->A!=0, ExcNotInitialized()); this->A->precondition_SSOR (dst, src, this->relaxation, pos_right_of_diagonal); } @@ -1312,6 +1390,12 @@ template inline void PreconditionSSOR::Tvmult (VECTOR &dst, const VECTOR &src) const { +#ifdef DEAL_II_WITH_CXX11 + static_assert( + std::is_same::size_type, typename VECTOR::size_type>::value, + "PreconditionSSOR and VECTOR must have the same size_type."); +#endif // DEAL_II_WITH_CXX11 + Assert (this->A!=0, ExcNotInitialized()); this->A->precondition_SSOR (dst, src, this->relaxation, pos_right_of_diagonal); } @@ -1323,6 +1407,12 @@ template inline void PreconditionSSOR::step (VECTOR &dst, const VECTOR &src) const { +#ifdef DEAL_II_WITH_CXX11 + static_assert( + std::is_same::size_type, typename VECTOR::size_type>::value, + "PreconditionSSOR and VECTOR must have the same size_type."); +#endif // DEAL_II_WITH_CXX11 + Assert (this->A!=0, ExcNotInitialized()); this->A->SSOR_step (dst, src, this->relaxation); } @@ -1334,6 +1424,12 @@ template inline void PreconditionSSOR::Tstep (VECTOR &dst, const VECTOR &src) const { +#ifdef DEAL_II_WITH_CXX11 + static_assert( + std::is_same::size_type, typename VECTOR::size_type>::value, + "PreconditionSSOR and VECTOR must have the same size_type."); +#endif // DEAL_II_WITH_CXX11 + step (dst, src); } @@ -1373,6 +1469,12 @@ template inline void PreconditionPSOR::vmult (VECTOR &dst, const VECTOR &src) const { +#ifdef DEAL_II_WITH_CXX11 + static_assert( + std::is_same::size_type, typename VECTOR::size_type>::value, + "PreconditionPSOR and VECTOR must have the same size_type."); +#endif // DEAL_II_WITH_CXX11 + Assert (this->A!=0, ExcNotInitialized()); dst = src; this->A->PSOR (dst, *permutation, *inverse_permutation, this->relaxation); @@ -1385,6 +1487,12 @@ template inline void PreconditionPSOR::Tvmult (VECTOR &dst, const VECTOR &src) const { +#ifdef DEAL_II_WITH_CXX11 + static_assert( + std::is_same::size_type, typename VECTOR::size_type>::value, + "PreconditionPSOR and VECTOR must have the same size_type."); +#endif // DEAL_II_WITH_CXX11 + Assert (this->A!=0, ExcNotInitialized()); dst = src; this->A->TPSOR (dst, *permutation, *inverse_permutation, this->relaxation); @@ -1678,7 +1786,13 @@ inline PreconditionChebyshev::PreconditionChebyshev () : is_initialized (false) -{} +{ +#ifdef DEAL_II_WITH_CXX11 + static_assert( + std::is_same::value, + "PreconditionChebyshev and VECTOR must have the same size_type."); +#endif // DEAL_II_WITH_CXX11 +} diff --git a/tests/lac/linear_operator_08.cc b/tests/lac/linear_operator_08.cc index 965fda2f21..6ba3f68e7d 100644 --- a/tests/lac/linear_operator_08.cc +++ b/tests/lac/linear_operator_08.cc @@ -396,21 +396,21 @@ int main() const auto lo_A_inv = linear_operator(solver); const Vector x = lo_A_inv*b; } - { - deallog << "IterativeInverse" << std::endl; - - PreconditionJacobi< SparseMatrix > preconditioner; - preconditioner.initialize(A); - - ReductionControl solver_control (10, 1.e-30, 1.e-2); - IterativeInverse< Vector > A_inv; - A_inv.initialize(A,preconditioner); - A_inv.solver.select("cg"); - A_inv.solver.set_control(solver_control); - - const auto lo_A_inv = linear_operator(A_inv); - const Vector x = lo_A_inv*b; - } +// { // See #1673 and #1784 +// deallog << "IterativeInverse" << std::endl; +// +// PreconditionJacobi< SparseMatrix > preconditioner; +// preconditioner.initialize(A); +// +// ReductionControl solver_control (10, 1.e-30, 1.e-2); +// IterativeInverse< Vector > A_inv; +// A_inv.initialize(A,preconditioner); +// A_inv.solver.select("cg"); +// A_inv.solver.set_control(solver_control); +// +// const auto lo_A_inv = linear_operator(A_inv); +// const Vector x = lo_A_inv*b; +// } deallog.pop(); diff --git a/tests/lac/linear_operator_08.with_cxx11=on.output b/tests/lac/linear_operator_08.with_cxx11=on.output index 0aeb146b82..459bc5bca8 100644 --- a/tests/lac/linear_operator_08.with_cxx11=on.output +++ b/tests/lac/linear_operator_08.with_cxx11=on.output @@ -80,9 +80,6 @@ DEAL:Solvers:Linear operator:Richardson::Convergence step 1 value 0.000000000 DEAL:Solvers::SolverSelector DEAL:Solvers:cg::Convergence step 0 value 0.000000000 DEAL:Solvers::SparseDirectUMFPACK -DEAL:Solvers::IterativeInverse -DEAL:Solvers:cg::Starting value 16.88194302 -DEAL:Solvers:cg::Convergence step 1 value 0.000000000 DEAL::SparseMatrix OK DEAL::PreconditionBlockIdentity DEAL:cg::Starting value 49.69909456