From: Jean-Paul Pelteret Date: Wed, 8 Feb 2017 08:04:22 +0000 (+0100) Subject: Enable deal.II solver use with Trilinos LinearOperator X-Git-Tag: v8.5.0-rc1~129^2~1 X-Git-Url: https://gitweb.dealii.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=51f9534f3c5b410151f71c9a29cf66ce45f4bd08;p=dealii.git Enable deal.II solver use with Trilinos LinearOperator By making a distinction between an `inverse_payload` created for Trilinos solvers/preconditioners and all other solver/preconditioner types, we allow a `TrilinosPayload` to be created when the solver/preconditioner is incompatible with `Epetra_Multivector`. In turn, it is now possible to use the deal.II solvers (e.g. `dealii::SolverCG`) with `Trilinos` `LinearOperator`s as such a call no longer results in a compiler error. --- diff --git a/include/deal.II/lac/trilinos_sparse_matrix.h b/include/deal.II/lac/trilinos_sparse_matrix.h index 7d328c3812..d7c55438cc 100644 --- a/include/deal.II/lac/trilinos_sparse_matrix.h +++ b/include/deal.II/lac/trilinos_sparse_matrix.h @@ -31,6 +31,7 @@ #ifdef DEAL_II_WITH_CXX11 #include +#include #endif // DEAL_II_WITH_CXX11 # include @@ -2049,6 +2050,7 @@ namespace TrilinosWrappers #ifdef DEAL_II_WITH_CXX11 // forwards declarations + class SolverBase; class PreconditionBase; namespace internal @@ -2216,17 +2218,50 @@ namespace TrilinosWrappers TrilinosPayload transpose_payload () const; /** - * Returns a payload configured for inverse operations - * - * Invoking this constructor will configure two additional functions, - * namely inv_vmult and inv_Tvmult, both of which wrap - * inverse operations. - * The vmult and Tvmult operations retain the standard - * definitions inherited from @p op. - */ + * Returns a payload configured for inverse operations + * + * Invoking this factory function will configure two additional functions, + * namely inv_vmult and inv_Tvmult, both of which wrap + * inverse operations. + * The vmult and Tvmult operations retain the standard + * definitions inherited from @p op. + * + * @note This function is enabled only if the solver and preconditioner + * derive from the respective TrilinosWrappers base classes. + * The C++ compiler will therefore only consider this function if the + * following criterion are satisfied: + * 1. the @p Solver derives from TrilinosWrappers::SolverBase, and + * 2. the @p Preconditioner derives from TrilinosWrappers::PreconditionBase. + */ template - TrilinosPayload inverse_payload (Solver &, const Preconditioner &) const; + typename std::enable_if< + std::is_base_of::value && + std::is_base_of::value, + TrilinosPayload>::type + inverse_payload (Solver &, const Preconditioner &) const; + /** + * Returns a payload configured for inverse operations + * + * Invoking this factory function will configure two additional functions, + * namely inv_vmult and inv_Tvmult, both of which + * are disabled because the @p Solver or @p Preconditioner are not + * compatible with Epetra_MultiVector. + * The vmult and Tvmult operations retain the standard + * definitions inherited from @p op. + * + * @note The C++ compiler will only consider this function if the + * following criterion are satisfied: + * 1. the @p Solver does not derive from TrilinosWrappers::SolverBase, and + * 2. the @p Preconditioner does not derive from + * TrilinosWrappers::PreconditionBase. + */ + template + typename std::enable_if< + !(std::is_base_of::value && + std::is_base_of::value), + TrilinosPayload>::type + inverse_payload (Solver &, const Preconditioner &) const; //@} @@ -3144,10 +3179,13 @@ namespace TrilinosWrappers namespace LinearOperator { template - TrilinosPayload - TrilinosPayload::inverse_payload ( - Solver &solver, - const Preconditioner &preconditioner) const + typename std::enable_if< + std::is_base_of::value && + std::is_base_of::value, + TrilinosPayload>::type + TrilinosPayload::inverse_payload ( + Solver &solver, + const Preconditioner &preconditioner) const { const auto &payload = *this; @@ -3192,6 +3230,36 @@ namespace TrilinosWrappers return return_op; } + + template + typename std::enable_if< + !(std::is_base_of::value && + std::is_base_of::value), + TrilinosPayload>::type + TrilinosPayload::inverse_payload ( + Solver &solver, + const Preconditioner &preconditioner) const + { + TrilinosPayload return_op(*this); + + return_op.inv_vmult = [](TrilinosPayload::Domain &, + const TrilinosPayload::Range &) + { + AssertThrow(false, + ExcMessage("Payload inv_vmult disabled because of " + "incompatible solver/preconditioner choice.")); + }; + + return_op.inv_Tvmult = [](TrilinosPayload::Range &, + const TrilinosPayload::Domain &) + { + AssertThrow(false, + ExcMessage("Payload inv_vmult disabled because of " + "incompatible solver/preconditioner choice.")); + }; + + return return_op; + } } // namespace LinearOperator } // namespace internal #endif // DEAL_II_WITH_CXX11 diff --git a/tests/lac/linear_operator_10a.cc b/tests/lac/linear_operator_10a.cc new file mode 100644 index 0000000000..035bcd8ad4 --- /dev/null +++ b/tests/lac/linear_operator_10a.cc @@ -0,0 +1,385 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 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. +// +// --------------------------------------------------------------------- + +// Test internal preconditioner and solver options + +#include "../tests.h" + +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include + + +using namespace dealii; + +template +void +print (const VECTOR &vec) +{ + for (types::global_dof_index i=0; i < vec.size(); ++i) + { + deallog << vec(i) << " "; + } + deallog << std::endl; +} + + +template +void +test_preconditioner (const MATRIX &A, + const VECTOR &b, + const ADDITIONAL_DATA &data = ADDITIONAL_DATA()) +{ + const auto lo_A = linear_operator(A); + // Note: The above should be equivalent to the following: + // + // typedef dealii::TrilinosWrappers::internal::LinearOperator::TrilinosPayload PAYLOAD; + // const auto lo_A = linear_operator(A); + + PRECONDITIONER preconditioner; + preconditioner.initialize(A, data); + + typedef SolverCG SOLVER; + SolverControl solver_control (100, 1.0e-10, false,false); + SOLVER solver (solver_control); + + // Exact inverse + const auto lo_A_inv = inverse_operator(lo_A, solver, preconditioner); + // Note: The above should be equivalent to the following: + // + // const auto lo_A_inv = inverse_operator(lo_A, + // solver, + // preconditioner); + + // Singular operation + { + deallog.push("S_Op"); + const VECTOR x = lo_A_inv*b; + print(x); + deallog.pop(); + } + + // Composite operation + { + deallog.push("C_Op"); + const VECTOR x = (lo_A_inv*lo_A*lo_A_inv)*b; + print(x); + deallog.pop(); + } + + // Approximate inverse + deallog.push("Approx"); + { + // Using exemplar matrix + deallog.push("Exemp"); + const auto lo_A_inv_approx = linear_operator(A, preconditioner); + // Note: The above should be equivalent to the following: + // + // typedef dealii::TrilinosWrappers::internal::LinearOperator::TrilinosPayload PAYLOAD; + // const auto lo_A_inv_approx = linear_operator(A, preconditioner); + + // Singular operation + { + deallog.push("S_Op"); + const VECTOR x_approx = lo_A_inv_approx*b; + print(x_approx); + deallog.pop(); + } + + // Composite operation + { + deallog.push("C_Op"); + const VECTOR x_approx = (lo_A_inv_approx*lo_A*lo_A_inv_approx)*b; + print(x_approx); + deallog.pop(); + } + + deallog.pop(); + } + { + // Stand-alone + deallog.push("S.A."); + typedef dealii::TrilinosWrappers::internal::LinearOperator::TrilinosPayload PAYLOAD; + const auto lo_A_inv_approx = linear_operator(preconditioner); + + // Singular operation + { + deallog.push("S_Op"); + const VECTOR x_approx = lo_A_inv_approx*b; + print(x_approx); + deallog.pop(); + } + + // Composite operation + { + deallog.push("C_Op"); + const VECTOR x_approx = (lo_A_inv_approx*lo_A*lo_A_inv_approx)*b; + print(x_approx); + deallog.pop(); + } + + deallog.pop(); + } + deallog.pop(); +} + +template +void +test_solver (const MATRIX &A, + const VECTOR &b) +{ + const auto lo_A = linear_operator(A); + // Note: The above should be equivalent to the following: + // + // typedef dealii::TrilinosWrappers::internal::LinearOperator::TrilinosPayload PAYLOAD; + // const auto lo_A = linear_operator(A); + + SolverControl solver_control (100, 1.0e-10, false,false); + SOLVER solver (solver_control); + + typedef TrilinosWrappers::PreconditionJacobi PRECONDITIONER; + PRECONDITIONER preconditioner; + preconditioner.initialize(A); + + { + const auto lo_A_inv = inverse_operator(lo_A, solver, preconditioner); + // Note: The above should be equivalent to the following: + // + // const auto lo_A_inv = inverse_operator(lo_A, + // solver, + // preconditioner); + + // Singular operation + { + deallog.push("S_Op"); + const VECTOR x_approx = lo_A_inv*b; + print(x_approx); + deallog.pop(); + } + + // Composite operation + { + deallog.push("C_Op"); + const VECTOR x_approx = (lo_A_inv*lo_A*lo_A_inv)*b; + print(x_approx); + deallog.pop(); + } + } + + // Composite operation 2 + { + deallog.push("C_Op2"); + SolverControl solver_control_1 (100, 1.0e-10, false,false); + SOLVER solver_1 (solver_control_1); + const auto lo_A_inv_1 = inverse_operator(lo_A, solver_1, preconditioner); + SolverControl solver_control_2 (100, 1.0e-10, false,false); + SOLVER solver_2 (solver_control_2); + const auto lo_A_inv_2 = inverse_operator(lo_A, solver_2, preconditioner); + const VECTOR x_approx = (lo_A_inv_2*lo_A*lo_A_inv_1)*b; + print(x_approx); + deallog.pop(); + } +} + +int main(int argc, char *argv[]) +{ + Utilities::MPI::MPI_InitFinalize mpi_initialization(argc, argv, 1); + MPILogInitAll all; + + deallog.depth_console(0); + deallog << std::setprecision(10); + + // TrilinosWrappers::SparseMatrix + { + const unsigned int rc=10; + TrilinosWrappers::SparsityPattern sparsity_pattern (rc, rc, /*n_entries_per_row =*/ 1); + for (unsigned int i=0; i < rc; ++i) + { + sparsity_pattern.add(i,i); + } + sparsity_pattern.compress(); + + TrilinosWrappers::SparseMatrix A (sparsity_pattern); + TrilinosWrappers::Vector b (A.domain_partitioner()); + TrilinosWrappers::MPI::Vector c (A.domain_partitioner()); + for (unsigned int i=0; i < rc; ++i) + { + A.set(i,i,2.0); + b(i) = i; + } + + // === PRECONDITIONERS === + deallog << "PRECONDITIONERS" << std::endl; + deallog.push("Preconditioners"); + + { + deallog.push("PreconditionAMG"); + typedef TrilinosWrappers::PreconditionAMG PREC; + test_preconditioner(A, b); + test_preconditioner(A, c); + deallog.pop(); + } + + { + deallog.push("PreconditionAMGMueLu"); + typedef TrilinosWrappers::PreconditionAMGMueLu PREC; + test_preconditioner(A, b); + test_preconditioner(A, c); + deallog.pop(); + } + + { + deallog.push("PreconditionChebyshev"); + typedef TrilinosWrappers::PreconditionChebyshev PREC; + test_preconditioner(A, b); + test_preconditioner(A, c); + deallog.pop(); + } + + { + deallog.push("PreconditionIC"); + typedef TrilinosWrappers::PreconditionIC PREC; + test_preconditioner(A, b); + test_preconditioner(A, c); + deallog.pop(); + } + + { + deallog.push("PreconditionIdentity"); + typedef TrilinosWrappers::PreconditionIdentity PREC; + test_preconditioner(A, b); + test_preconditioner(A, c); + deallog.pop(); + } + + { + deallog.push("PreconditionILU"); + typedef TrilinosWrappers::PreconditionILU PREC; + test_preconditioner(A, b); + test_preconditioner(A, c); + deallog.pop(); + } + + { + deallog.push("PreconditionILUT"); + typedef TrilinosWrappers::PreconditionILUT PREC; + test_preconditioner(A, b); + test_preconditioner(A, c); + deallog.pop(); + } + + { + deallog.push("PreconditionJacobi"); + typedef TrilinosWrappers::PreconditionJacobi PREC; + test_preconditioner(A, b); + test_preconditioner(A, c); + deallog.pop(); + } + + { + deallog.push("PreconditionSOR"); + typedef TrilinosWrappers::PreconditionSOR PREC; + test_preconditioner(A, b); + test_preconditioner(A, c); + deallog.pop(); + } + + { + deallog.push("PreconditionSSOR"); + typedef TrilinosWrappers::PreconditionSSOR PREC; + test_preconditioner(A, b); + test_preconditioner(A, c); + deallog.pop(); + } + + deallog.pop(); + + // === SOLVERS === + deallog << std::endl; + deallog << "SOLVERS" << std::endl; + deallog.push("Solvers"); + + { + deallog.push("SolverBicgstab"); + typedef SolverBicgstab SLVR; + test_solver (A, b); + deallog.pop(); + } + + { + deallog.push("SolverCG"); + typedef SolverCG SLVR; + test_solver (A, b); + deallog.pop(); + } + + { + deallog.push("SolverGMRES"); + typedef SolverGMRES SLVR; + test_solver (A, b); + deallog.pop(); + } + + { + deallog.push("SolverFGMRES"); + typedef SolverFGMRES SLVR; + test_solver (A, b); + deallog.pop(); + } + + { + deallog.push("SolverMinRes"); + typedef SolverMinRes SLVR; + test_solver (A, b); + deallog.pop(); + } + + { + deallog.push("SolverQMRS"); + typedef SolverQMRS SLVR; + test_solver (A, b); + deallog.pop(); + } + + { + deallog.push("SolverRichardson"); + typedef SolverRichardson SLVR; + test_solver (A, b); + deallog.pop(); + } + + deallog.pop(); + deallog << "TrilinosWrappers::SparseMatrix OK" << std::endl; + } // TrilinosWrappers::SparseMatrix + +} diff --git a/tests/lac/linear_operator_10a.with_cxx11=on.with_trilinos=on.output b/tests/lac/linear_operator_10a.with_cxx11=on.with_trilinos=on.output new file mode 100644 index 0000000000..0e3e7afc83 --- /dev/null +++ b/tests/lac/linear_operator_10a.with_cxx11=on.with_trilinos=on.output @@ -0,0 +1,146 @@ + +DEAL:0::PRECONDITIONERS +DEAL:0:Preconditioners:PreconditionAMG:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionAMG:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionAMG:Approx:Exemp:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionAMG:Approx:Exemp:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionAMG:Approx:S.A.:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionAMG:Approx:S.A.:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionAMG:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionAMG:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionAMG:Approx:Exemp:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionAMG:Approx:Exemp:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionAMG:Approx:S.A.:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionAMG:Approx:S.A.:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionAMGMueLu:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionAMGMueLu:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionAMGMueLu:Approx:Exemp:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionAMGMueLu:Approx:Exemp:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionAMGMueLu:Approx:S.A.:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionAMGMueLu:Approx:S.A.:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionAMGMueLu:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionAMGMueLu:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionAMGMueLu:Approx:Exemp:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionAMGMueLu:Approx:Exemp:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionAMGMueLu:Approx:S.A.:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionAMGMueLu:Approx:S.A.:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionChebyshev:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionChebyshev:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionChebyshev:Approx:Exemp:S_Op::0.000000000 0.08823529412 0.1764705882 0.2647058824 0.3529411765 0.4411764706 0.5294117647 0.6176470588 0.7058823529 0.7941176471 +DEAL:0:Preconditioners:PreconditionChebyshev:Approx:Exemp:C_Op::0.000000000 0.01557093426 0.03114186851 0.04671280277 0.06228373702 0.07785467128 0.09342560554 0.1089965398 0.1245674740 0.1401384083 +DEAL:0:Preconditioners:PreconditionChebyshev:Approx:S.A.:S_Op::0.000000000 0.08823529412 0.1764705882 0.2647058824 0.3529411765 0.4411764706 0.5294117647 0.6176470588 0.7058823529 0.7941176471 +DEAL:0:Preconditioners:PreconditionChebyshev:Approx:S.A.:C_Op::0.000000000 0.01557093426 0.03114186851 0.04671280277 0.06228373702 0.07785467128 0.09342560554 0.1089965398 0.1245674740 0.1401384083 +DEAL:0:Preconditioners:PreconditionChebyshev:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionChebyshev:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionChebyshev:Approx:Exemp:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionChebyshev:Approx:Exemp:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionChebyshev:Approx:S.A.:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionChebyshev:Approx:S.A.:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionIC:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionIC:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionIC:Approx:Exemp:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionIC:Approx:Exemp:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionIC:Approx:S.A.:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionIC:Approx:S.A.:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionIC:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionIC:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionIC:Approx:Exemp:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionIC:Approx:Exemp:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionIC:Approx:S.A.:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionIC:Approx:S.A.:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionIdentity:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionIdentity:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionIdentity:Approx:Exemp:S_Op::0.000000000 1.000000000 2.000000000 3.000000000 4.000000000 5.000000000 6.000000000 7.000000000 8.000000000 9.000000000 +DEAL:0:Preconditioners:PreconditionIdentity:Approx:Exemp:C_Op::0.000000000 2.000000000 4.000000000 6.000000000 8.000000000 10.00000000 12.00000000 14.00000000 16.00000000 18.00000000 +DEAL:0:Preconditioners:PreconditionIdentity:Approx:S.A.:S_Op::0.000000000 1.000000000 2.000000000 3.000000000 4.000000000 5.000000000 6.000000000 7.000000000 8.000000000 9.000000000 +DEAL:0:Preconditioners:PreconditionIdentity:Approx:S.A.:C_Op::0.000000000 2.000000000 4.000000000 6.000000000 8.000000000 10.00000000 12.00000000 14.00000000 16.00000000 18.00000000 +DEAL:0:Preconditioners:PreconditionIdentity:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionIdentity:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionIdentity:Approx:Exemp:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionIdentity:Approx:Exemp:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionIdentity:Approx:S.A.:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionIdentity:Approx:S.A.:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionILU:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionILU:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionILU:Approx:Exemp:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionILU:Approx:Exemp:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionILU:Approx:S.A.:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionILU:Approx:S.A.:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionILU:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionILU:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionILU:Approx:Exemp:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionILU:Approx:Exemp:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionILU:Approx:S.A.:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionILU:Approx:S.A.:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionILUT:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionILUT:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionILUT:Approx:Exemp:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionILUT:Approx:Exemp:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionILUT:Approx:S.A.:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionILUT:Approx:S.A.:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionILUT:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionILUT:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionILUT:Approx:Exemp:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionILUT:Approx:Exemp:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionILUT:Approx:S.A.:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionILUT:Approx:S.A.:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionJacobi:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionJacobi:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionJacobi:Approx:Exemp:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionJacobi:Approx:Exemp:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionJacobi:Approx:S.A.:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionJacobi:Approx:S.A.:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionJacobi:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionJacobi:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionJacobi:Approx:Exemp:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionJacobi:Approx:Exemp:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionJacobi:Approx:S.A.:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionJacobi:Approx:S.A.:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionSOR:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionSOR:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionSOR:Approx:Exemp:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionSOR:Approx:Exemp:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionSOR:Approx:S.A.:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionSOR:Approx:S.A.:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionSOR:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionSOR:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionSOR:Approx:Exemp:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionSOR:Approx:Exemp:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionSOR:Approx:S.A.:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionSOR:Approx:S.A.:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionSSOR:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionSSOR:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionSSOR:Approx:Exemp:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionSSOR:Approx:Exemp:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionSSOR:Approx:S.A.:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionSSOR:Approx:S.A.:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Preconditioners:PreconditionSSOR:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionSSOR:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionSSOR:Approx:Exemp:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionSSOR:Approx:Exemp:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionSSOR:Approx:S.A.:S_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:Preconditioners:PreconditionSSOR:Approx:S.A.:C_Op::0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 0.000000000 +DEAL:0:: +DEAL:0::SOLVERS +DEAL:0:Solvers:SolverBicgstab:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Solvers:SolverBicgstab:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Solvers:SolverBicgstab:C_Op2::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Solvers:SolverCG:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Solvers:SolverCG:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Solvers:SolverCG:C_Op2::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Solvers:SolverGMRES:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Solvers:SolverGMRES:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Solvers:SolverGMRES:C_Op2::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Solvers:SolverFGMRES:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Solvers:SolverFGMRES:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Solvers:SolverFGMRES:C_Op2::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Solvers:SolverMinRes:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Solvers:SolverMinRes:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Solvers:SolverMinRes:C_Op2::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Solvers:SolverQMRS:S_Op::0.000000000 1.000000000 2.000000000 3.000000000 4.000000000 5.000000000 6.000000000 7.000000000 8.000000000 9.000000000 +DEAL:0:Solvers:SolverQMRS:C_Op::0.000000000 2.000000000 4.000000000 6.000000000 8.000000000 10.00000000 12.00000000 14.00000000 16.00000000 18.00000000 +DEAL:0:Solvers:SolverQMRS:C_Op2::0.000000000 2.000000000 4.000000000 6.000000000 8.000000000 10.00000000 12.00000000 14.00000000 16.00000000 18.00000000 +DEAL:0:Solvers:SolverRichardson:S_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Solvers:SolverRichardson:C_Op::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0:Solvers:SolverRichardson:C_Op2::0.000000000 0.5000000000 1.000000000 1.500000000 2.000000000 2.500000000 3.000000000 3.500000000 4.000000000 4.500000000 +DEAL:0::TrilinosWrappers::SparseMatrix OK diff --git a/tests/lac/linear_operator_12a.cc b/tests/lac/linear_operator_12a.cc new file mode 100644 index 0000000000..756900ddea --- /dev/null +++ b/tests/lac/linear_operator_12a.cc @@ -0,0 +1,389 @@ +// --------------------------------------------------------------------- +// +// Copyright (C) 2017 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. +// +// --------------------------------------------------------------------- + +// tests Trilinos direct solvers on a 2D Poisson equation for linear elements +// Note: This test is a modified version of tests/trilinos/direct_solver_2.cc + +#include "../tests.h" + +#include +#include + +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#include + +#include +#include + +using namespace dealii; + +template +class Step4 +{ +public: + Step4 (); + void run (); + +private: + void make_grid (); + void setup_system(); + void assemble_system (); + void solve (); + + parallel::distributed::Triangulation triangulation; + FE_Q fe; + DoFHandler dof_handler; + + ConstraintMatrix constraints; + SparsityPattern sparsity_pattern; + + TrilinosWrappers::SparseMatrix system_matrix; + + TrilinosWrappers::MPI::Vector solution; + TrilinosWrappers::MPI::Vector system_rhs; +}; + + +template +class RightHandSide : public Function +{ +public: + RightHandSide () : Function() {} + + virtual double value (const Point &p, + const unsigned int component = 0) const; +}; + + +template +class RightHandSideTwo : public Function +{ +public: + RightHandSideTwo () : Function() {} + + virtual double value (const Point &p, + const unsigned int component = 0) const; +}; + + + + +template +class BoundaryValues : public Function +{ +public: + BoundaryValues () : Function() {} + + virtual double value (const Point &p, + const unsigned int component = 0) const; +}; + + + + +template +double RightHandSide::value (const Point &p, + const unsigned int /*component*/) const +{ + double return_value = 0; + for (unsigned int i=0; i +double RightHandSideTwo::value (const Point &p, + const unsigned int /*component*/) const +{ + double return_value = 0; + for (unsigned int i=0; i +double BoundaryValues::value (const Point &p, + const unsigned int /*component*/) const +{ + return p.square(); +} + + + +template +Step4::Step4 () + : + triangulation(MPI_COMM_WORLD, + typename Triangulation::MeshSmoothing + (Triangulation::smoothing_on_refinement | + Triangulation::smoothing_on_coarsening)), + fe (1), + dof_handler (triangulation) +{} + + +template +void Step4::make_grid () +{ + GridGenerator::hyper_cube (triangulation, -1, 1); + triangulation.refine_global (6); +} + + + +template +void Step4::setup_system () +{ + dof_handler.distribute_dofs (fe); + + constraints.clear(); + std::map boundary_values; + VectorTools::interpolate_boundary_values (dof_handler, + 0, + BoundaryValues(), + constraints); + constraints.close(); + + IndexSet locally_owned_dofs = dof_handler.locally_owned_dofs(); + IndexSet locally_relevant_dofs; + + DoFTools::extract_locally_relevant_dofs(dof_handler, + locally_relevant_dofs); + + + DynamicSparsityPattern dsp(dof_handler.n_dofs()); + DoFTools::make_sparsity_pattern (dof_handler, dsp, constraints, false); + SparsityTools::distribute_sparsity_pattern(dsp, + dof_handler.n_locally_owned_dofs_per_processor(), + MPI_COMM_WORLD, + locally_relevant_dofs); + + system_matrix.reinit (locally_owned_dofs, + locally_owned_dofs, + dsp, + MPI_COMM_WORLD); + + solution.reinit (locally_relevant_dofs, + MPI_COMM_WORLD); + + system_rhs.reinit (locally_owned_dofs, + locally_relevant_dofs, + MPI_COMM_WORLD, + true); + +} + + +template +void Step4::assemble_system () +{ + QGauss quadrature_formula(fe.degree+1); + + const RightHandSide right_hand_side; + + FEValues fe_values (fe, quadrature_formula, + update_values | update_gradients | + update_quadrature_points | update_JxW_values); + + const unsigned int dofs_per_cell = fe.dofs_per_cell; + const unsigned int n_q_points = quadrature_formula.size(); + + FullMatrix cell_matrix (dofs_per_cell, dofs_per_cell); + Vector cell_rhs (dofs_per_cell); + + std::vector local_dof_indices (dofs_per_cell); + + typename DoFHandler::active_cell_iterator + cell = dof_handler.begin_active(), + endc = dof_handler.end(); + + for (; cell!=endc; ++cell) + { + if (cell->is_locally_owned()) + { + fe_values.reinit (cell); + cell_matrix = 0; + cell_rhs = 0; + + for (unsigned int q_point=0; q_pointget_dof_indices (local_dof_indices); + constraints.distribute_local_to_global(cell_matrix, cell_rhs, + local_dof_indices, + system_matrix, system_rhs); + } + } + system_matrix.compress(VectorOperation::add); + system_rhs.compress(VectorOperation::add); +} + + + +template +void Step4::solve () +{ + typedef TrilinosWrappers::MPI::Vector VectorType; + + // Compute 'reference' solution with direct solver + VectorType temp_solution(system_rhs); + { + deallog.push("DirectKLU"); + temp_solution = 0; + TrilinosWrappers::SolverDirect::AdditionalData data; + data.solver_type = "Amesos_Klu"; + SolverControl solver_control (1000, 1e-10); + TrilinosWrappers::SolverDirect solver(solver_control, data); + solver.solve (system_matrix, temp_solution, system_rhs); + constraints.distribute(temp_solution); + solution = temp_solution; + deallog.pop(); + } + + VectorType output(system_rhs); + { + deallog.push("deal_II_CG_SSOR"); + output = 0; + SolverControl solver_control (1000, 1e-12); + SolverCG solver (solver_control); + TrilinosWrappers::PreconditionSSOR preconditioner; + preconditioner.initialize(system_matrix); + solver.solve (system_matrix, output, system_rhs, + preconditioner); + constraints.distribute(output); + output -= temp_solution; + const double local_error = output.l2_norm(); + const double global_error = std::sqrt(Utilities::MPI::sum( + local_error * local_error, + MPI_COMM_WORLD)); + deallog << "Norm of error in standard solve: " << global_error + << std::endl; + deallog.pop(); + } + + { + deallog.push("LinearOperator_deal_II_CG_SSOR"); + output = 0; + SolverControl solver_control (1000, 1e-12); + SolverCG solver (solver_control); + TrilinosWrappers::PreconditionSSOR preconditioner; + preconditioner.initialize(system_matrix); + const auto lo_A = linear_operator(system_matrix); + const auto lo_A_inv = inverse_operator(lo_A, solver, preconditioner); + output = lo_A_inv*system_rhs; + constraints.distribute(output); + output -= temp_solution; + const double local_error = output.l2_norm(); + const double global_error = std::sqrt(Utilities::MPI::sum( + local_error * local_error, + MPI_COMM_WORLD)); + deallog << "Norm of error in LinearOperator solve: " << global_error + << std::endl; + deallog.pop(); + } + +} + + + +template +void Step4::run() +{ + make_grid(); + setup_system(); + assemble_system(); + solve(); +} + + +int main (int argc, char **argv) +{ + std::ofstream logfile("output"); + deallog.attach(logfile); + deallog.threshold_double(1.e-10); + + Utilities::MPI::MPI_InitFinalize mpi_initialization (argc, argv, testing_max_num_threads()); + + try + { + Step4<2> test; + test.run(); + } + catch (std::exception &exc) + { + deallog << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + deallog << "Exception on processing: " << std::endl + << exc.what() << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + + return 1; + } + catch (...) + { + deallog << std::endl << std::endl + << "----------------------------------------------------" + << std::endl; + deallog << "Unknown exception!" << std::endl + << "Aborting!" << std::endl + << "----------------------------------------------------" + << std::endl; + return 1; + }; +} diff --git a/tests/lac/linear_operator_12a.with_cxx11=on.with_trilinos=on.with_mpi=true.mpirun=1.output b/tests/lac/linear_operator_12a.with_cxx11=on.with_trilinos=on.with_mpi=true.mpirun=1.output new file mode 100644 index 0000000000..a53349a74f --- /dev/null +++ b/tests/lac/linear_operator_12a.with_cxx11=on.with_trilinos=on.with_mpi=true.mpirun=1.output @@ -0,0 +1,9 @@ + +DEAL:DirectKLU::Starting value 0 +DEAL:DirectKLU::Convergence step 0 value 0 +DEAL:deal_II_CG_SSOR:cg::Starting value 21.8027 +DEAL:deal_II_CG_SSOR:cg::Convergence step 86 value 0 +DEAL:deal_II_CG_SSOR::Norm of error in standard solve: 0 +DEAL:LinearOperator_deal_II_CG_SSOR:cg::Starting value 21.8027 +DEAL:LinearOperator_deal_II_CG_SSOR:cg::Convergence step 86 value 0 +DEAL:LinearOperator_deal_II_CG_SSOR::Norm of error in LinearOperator solve: 0 diff --git a/tests/lac/linear_operator_12a.with_cxx11=on.with_trilinos=on.with_mpi=true.mpirun=2.output b/tests/lac/linear_operator_12a.with_cxx11=on.with_trilinos=on.with_mpi=true.mpirun=2.output new file mode 100644 index 0000000000..9ed8f08bb8 --- /dev/null +++ b/tests/lac/linear_operator_12a.with_cxx11=on.with_trilinos=on.with_mpi=true.mpirun=2.output @@ -0,0 +1,9 @@ + +DEAL:DirectKLU::Starting value 0 +DEAL:DirectKLU::Convergence step 0 value 0 +DEAL:deal_II_CG_SSOR:cg::Starting value 21.8027 +DEAL:deal_II_CG_SSOR:cg::Convergence step 105 value 0 +DEAL:deal_II_CG_SSOR::Norm of error in standard solve: 0 +DEAL:LinearOperator_deal_II_CG_SSOR:cg::Starting value 21.8027 +DEAL:LinearOperator_deal_II_CG_SSOR:cg::Convergence step 105 value 0 +DEAL:LinearOperator_deal_II_CG_SSOR::Norm of error in LinearOperator solve: 0