42#ifndef THYRA_LINEAR_OP_WITH_SOLVE_EXAMPLES_HPP
43#define THYRA_LINEAR_OP_WITH_SOLVE_EXAMPLES_HPP
46#include "Thyra_LinearOpWithSolveFactoryBase.hpp"
47#include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
48#include "Thyra_LinearOpWithSolveBase.hpp"
49#include "Thyra_PreconditionerFactoryHelpers.hpp"
50#include "Thyra_DefaultScaledAdjointLinearOp.hpp"
51#include "Thyra_DefaultPreconditioner.hpp"
52#include "Thyra_MultiVectorStdOps.hpp"
53#include "Thyra_VectorStdOps.hpp"
54#include "Thyra_VectorBase.hpp"
106template<
class Scalar>
107void singleLinearSolve(
116 using Teuchos::rcpFromRef;
118 out <<
"\nPerforming a single linear solve ...\n";
126 out <<
"\nSolve status:\n" << status;
135template<
class Scalar>
137createScaledAdjointLinearOpWithSolve(
139 const Scalar &scalar,
145 out <<
"\nCreating a scaled adjoint LinearOpWithSolveBase object ...\n";
149 out <<
"\nCreated LOWSB object:\n" << describe(*invertibleAdjointA,
151 return invertibleAdjointA;
160template<
class Scalar>
161void solveNumericalChangeSolve(
172 using Teuchos::as;
using Teuchos::ptr;
using Teuchos::rcpFromPtr;
174 out <<
"\nPerforming a solve, changing the operator, then performing another"
209template<
class Scalar>
210void solveSmallNumericalChangeSolve(
221 using Teuchos::ptr;
using Teuchos::as;
using Teuchos::rcpFromPtr;
223 out <<
"\nPerforming a solve, changing the operator in a very small way,"
224 <<
" then performing another solve ...\n";
257template<
class Scalar>
258void solveMajorChangeSolve(
271 out <<
"\nPerforming a solve, changing the operator in a major way, then performing"
272 <<
" another solve ...\n";
292 invertibleA = lowsFactory.
createOp();
311template<
class Scalar>
313createGeneralPreconditionedLinearOpWithSolve(
321 out <<
"\nCreating an externally preconditioned LinearOpWithSolveBase object ...\n";
336template<
class Scalar>
338createUnspecifiedPreconditionedLinearOpWithSolve(
346 out <<
"\nCreating an LinearOpWithSolveBase object given a preconditioner operator"
347 <<
" not targeted to the left or right ...\n";
365template<
class Scalar>
367createLeftPreconditionedLinearOpWithSolve(
375 out <<
"\nCreating an LinearOpWithSolveBase object given a left preconditioner"
376 <<
" operator ...\n";
392template<
class Scalar>
394createRightPreconditionedLinearOpWithSolve(
402 out <<
"\nCreating an LinearOpWithSolveBase object given a right"
403 <<
" preconditioner operator ...\n";
419template<
class Scalar>
421createLeftRightPreconditionedLinearOpWithSolve(
430 out <<
"\nCreating an LinearOpWithSolveBase object given a left and"
431 <<
"right preconditioner operator ...\n";
447template<
class Scalar>
449createMatrixPreconditionedLinearOpWithSolve(
457 out <<
"\nCreating a LinearOpWithSolveBase object given an approximate forward"
458 <<
" operator to define the preconditioner ...\n";
472template<
class Scalar>
473void externalPreconditionerReuseWithSolves(
485 using Teuchos::tab;
using Teuchos::rcpFromPtr;
488 out <<
"\nShowing resuse of the preconditioner ...\n";
502 out <<
"\nSolve status:\n" << status1;
520 out <<
"\nSolve status:\n" << status2;
534template<
class Scalar>
535void nonExternallyPreconditionedLinearSolveUseCases(
538 bool supportsAdjoints,
544 out <<
"\nRunning example use cases for a LinearOpWithSolveFactoryBase object ...\n";
559 singleLinearSolve(A, lowsFactory, *b1, x1.
ptr(), out);
561 if(supportsAdjoints) {
563 invertibleAdjointA = createScaledAdjointLinearOpWithSolve(
564 Teuchos::rcp(&A,
false),as<Scalar>(2.0),lowsFactory,out);
567 solveNumericalChangeSolve<Scalar>(
570 lowsFactory, *b1, x1.
ptr(), *b2, x1.
ptr(), out );
572 solveSmallNumericalChangeSolve<Scalar>(
575 lowsFactory, *b1, x1.
ptr(), *b2, x1.
ptr(), out );
577 solveMajorChangeSolve<Scalar>(
580 lowsFactory, *b1, x1.
ptr(), *b2, x1.
ptr(), out );
589template<
class Scalar>
590void externallyPreconditionedLinearSolveUseCases(
594 const bool supportsLeftPrec,
595 const bool supportsRightPrec,
601 out <<
"\nRunning example use cases with an externally defined"
602 <<
" preconditioner with a LinearOpWithSolveFactoryBase object ...\n";
628 invertibleA = createGeneralPreconditionedLinearOpWithSolve<Scalar>(
635 if (nonnull (P_op = P->getUnspecifiedPrecOp ()))
637 else if (nonnull (P_op = P->getLeftPrecOp ()))
639 else if (nonnull (P_op = P->getRightPrecOp ()))
642 invertibleA = createUnspecifiedPreconditionedLinearOpWithSolve(
643 rcpFromRef(A), P_op, lowsFactory, out);
645 if(supportsLeftPrec) {
646 invertibleA = createLeftPreconditionedLinearOpWithSolve(
647 rcpFromRef(A), P_op, lowsFactory,out);
650 if(supportsRightPrec) {
651 invertibleA = createRightPreconditionedLinearOpWithSolve(
652 rcpFromRef(A), P_op, lowsFactory, out);
656 if( supportsLeftPrec && supportsRightPrec ) {
657 invertibleA = createLeftRightPreconditionedLinearOpWithSolve(
658 rcpFromRef(A), P_op, P_op, lowsFactory, out);
662 invertibleA = createMatrixPreconditionedLinearOpWithSolve<Scalar>(
663 rcpFromRef(A), rcpFromRef(A), lowsFactory,out);
665 externalPreconditionerReuseWithSolves<Scalar>(
668 lowsFactory, precFactory,
669 *b1, x1.
ptr(), *b2, x2.ptr(), out );
RCP< const T > getConst() const
Teuchos::RCP< const DefaultPreconditioner< Scalar > > rightPrec(const Teuchos::RCP< const LinearOpBase< Scalar > > &rightPrecOp)
Create a precondioner from a single linear operator targeted to be used on the right.
Teuchos::RCP< const DefaultPreconditioner< Scalar > > leftPrec(const Teuchos::RCP< const LinearOpBase< Scalar > > &leftPrecOp)
Create a precondioner from a single linear operator targeted to be used on the left.
Teuchos::RCP< const DefaultPreconditioner< Scalar > > unspecifiedPrec(const Teuchos::RCP< const LinearOpBase< Scalar > > &unspecifiedPrecOp)
Create a precondioner from a single linear operator not targeted to be used on the left or the right.
Teuchos::RCP< const DefaultPreconditioner< Scalar > > splitPrec(const Teuchos::RCP< const LinearOpBase< Scalar > > &leftPrecOp, const Teuchos::RCP< const LinearOpBase< Scalar > > &rightPrecOp)
Create a split precondioner from two linear operators, one to be applied on the left and one to be ap...
RCP< const LinearOpBase< Scalar > > scale(const Scalar &scalar, const RCP< const LinearOpBase< Scalar > > &Op, const std::string &label="")
Build an implicit const scaled linear operator.
RCP< const LinearOpBase< Scalar > > adjoint(const RCP< const LinearOpBase< Scalar > > &Op, const std::string &label="")
Build an implicit const adjoined linear operator.
Base class for all linear operators.
virtual RCP< const VectorSpaceBase< Scalar > > range() const =0
Return a smart pointer for the range space for this operator.
virtual RCP< const VectorSpaceBase< Scalar > > domain() const =0
Return a smart pointer for the domain space for this operator.
Silly abstract strategy interface for changing Thyra::LinearOpBase objects.
virtual ~LinearOpChanger()
virtual void changeOp(const Teuchos::Ptr< LinearOpBase< Scalar > > &op) const =0
SolveStatus< Scalar > solve(const LinearOpWithSolveBase< Scalar > &A, const EOpTransp A_trans, const MultiVectorBase< Scalar > &B, const Ptr< MultiVectorBase< Scalar > > &X, const Ptr< const SolveCriteria< Scalar > > solveCriteria=Teuchos::null)
Call solve() as a non-member function.
Factory interface for creating LinearOpWithSolveBase objects from compatible LinearOpBase objects.
void initializeApproxPreconditionedOp(const LinearOpWithSolveFactoryBase< Scalar > &lowsFactory, const RCP< const LinearOpBase< Scalar > > &fwdOp, const RCP< const LinearOpBase< Scalar > > &approxFwdOp, const Ptr< LinearOpWithSolveBase< Scalar > > &Op, const ESupportSolveUse supportSolveUse=SUPPORT_SOLVE_UNSPECIFIED)
Initialize a preconditioned LOWSB object given an external operator to be used to generate the precon...
RCP< LinearOpWithSolveBase< Scalar > > linearOpWithSolve(const LinearOpWithSolveFactoryBase< Scalar > &lowsFactory, const RCP< const LinearOpBase< Scalar > > &fwdOp, const ESupportSolveUse supportSolveUse=SUPPORT_SOLVE_UNSPECIFIED)
Create and initialize a LinearOpWithSolveBase object from a LinearOpBase object using a LinearOpWithS...
void initializeOp(const LinearOpWithSolveFactoryBase< Scalar > &lowsFactory, const RCP< const LinearOpBase< Scalar > > &fwdOp, const Ptr< LinearOpWithSolveBase< Scalar > > &Op, const ESupportSolveUse supportSolveUse=SUPPORT_SOLVE_UNSPECIFIED)
Initialize a pre-created LOWSB object given a forward operator.
void uninitializeOp(const LinearOpWithSolveFactoryBase< Scalar > &lowsFactory, const Ptr< LinearOpWithSolveBase< Scalar > > &Op, const Ptr< RCP< const LinearOpBase< Scalar > > > &fwdOp=Teuchos::null, const Ptr< RCP< const PreconditionerBase< Scalar > > > &prec=Teuchos::null, const Ptr< RCP< const LinearOpBase< Scalar > > > &approxFwdOp=Teuchos::null, const Ptr< ESupportSolveUse > &supportSolveUse=Teuchos::null)
Uninitialized a pre-created LOWSB object, returning input objects used to initialize it.
void initializePreconditionedOp(const LinearOpWithSolveFactoryBase< Scalar > &lowsFactory, const RCP< const LinearOpBase< Scalar > > &fwdOp, const RCP< const PreconditionerBase< Scalar > > &prec, const Ptr< LinearOpWithSolveBase< Scalar > > &Op, const ESupportSolveUse supportSolveUse=SUPPORT_SOLVE_UNSPECIFIED)
Initialize a preconditioned LOWSB object given an external preconditioner.
void initializeAndReuseOp(const LinearOpWithSolveFactoryBase< Scalar > &lowsFactory, const RCP< const LinearOpBase< Scalar > > &fwdOp, const Ptr< LinearOpWithSolveBase< Scalar > > &Op)
Reinitialize a pre-created LOWSB object given a forward operator, reusing a much as possible from the...
virtual RCP< LinearOpWithSolveBase< Scalar > > createOp() const =0
Create an (uninitialized) LinearOpWithSolveBase object to be initialized later in this->initializeOp(...
void assign(const Ptr< MultiVectorBase< Scalar > > &V, Scalar alpha)
V = alpha.
void randomize(Scalar l, Scalar u, const Ptr< MultiVectorBase< Scalar > > &V)
Generate a random multi-vector with elements uniformly distributed elements.
void changeOp(const Teuchos::Ptr< LinearOpBase< Scalar > > &op) const
Simple interface class to access a precreated preconditioner as one or more linear operators objects ...
Factory interface for creating preconditioner objects from LinearOpBase objects.
void initializePrec(const PreconditionerFactoryBase< Scalar > &precFactory, const Teuchos::RCP< const LinearOpBase< Scalar > > &fwdOp, const Teuchos::Ptr< PreconditionerBase< Scalar > > &prec, const ESupportSolveUse supportSolveUse=SUPPORT_SOLVE_UNSPECIFIED)
Initialize a preconditioner from a forward linear operator.
virtual RCP< PreconditionerBase< Scalar > > createPrec() const =0
Create an (uninitialized) LinearOpBase object to be initialized as the preconditioner later in this->...
Abstract interface for finite-dimensional dense vectors.
RCP< VectorBase< Scalar > > createMember(const RCP< const VectorSpaceBase< Scalar > > &vs, const std::string &label="")
Create a vector member from the vector space.
@ NOTRANS
Use the non-transposed operator.
TypeTo as(const TypeFrom &t)
basic_FancyOStream< char > FancyOStream
basic_OSTab< char > OSTab
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Simple struct for the return status from a solve.