From 5d6d4679993d1d6d0185fcb23bbf71c290404af5 Mon Sep 17 00:00:00 2001 From: Matthias Maier Date: Fri, 14 Jul 2017 16:56:51 -0500 Subject: [PATCH] Bugfix: Add overload for linear_operator that takes a LinearOperator exemplar This allows to copy the reinit functions from a LinearOperator directly. --- include/deal.II/lac/linear_operator.h | 39 +++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/include/deal.II/lac/linear_operator.h b/include/deal.II/lac/linear_operator.h index 22d37c2fbc..7f00ad0020 100644 --- a/include/deal.II/lac/linear_operator.h +++ b/include/deal.II/lac/linear_operator.h @@ -1291,6 +1291,45 @@ linear_operator(const OperatorExemplar &operator_exemplar, const Matrix &matrix) } + +/** + * @relates LinearOperator + * + * Variant of above function that takes a LinearOperator @p + * operator_exemplar as an additional reference. + * The reinit_domain_vector and reinit_range_vector function are copied + * from the @p operator_exemplar object. + * + * The reference @p matrix is used to construct vmult, Tvmult, etc. + * + * This variant can, for example, be used to encapsulate preconditioners (that + * typically do not expose any information about the underlying matrix). + * + * @author Matthias Maier, 2017 + * + * @ingroup LAOperators + */ +template +LinearOperator +linear_operator(const LinearOperator &operator_exemplar, + const Matrix &matrix) +{ + // Initialise the payload based on the LinearOperator exemplar + auto return_op = operator_exemplar; + + typename std::conditional< + has_vmult_add_and_Tvmult_add::type::value, + MatrixInterfaceWithVmultAdd, + MatrixInterfaceWithoutVmultAdd>::type(). + operator()(return_op, matrix); + + return return_op; +} + + //@} -- 2.39.5