Thyra Version of the Day
Loading...
Searching...
No Matches
Thyra_LinearOpWithSolveFactoryHelpers.hpp
1// @HEADER
2// *****************************************************************************
3// Thyra: Interfaces and Support for Abstract Numerical Algorithms
4//
5// Copyright 2004 NTESS and the Thyra contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef THYRA_LINEAR_OP_WITH_SOLVE_FACTORY_HELPERS_HPP
11#define THYRA_LINEAR_OP_WITH_SOLVE_FACTORY_HELPERS_HPP
12
13#include "Thyra_LinearOpWithSolveFactoryBase.hpp"
14#include "Thyra_DefaultLinearOpSource.hpp"
15#include "Thyra_DefaultPreconditioner.hpp"
16#include "Thyra_DefaultInverseLinearOp.hpp"
17
18
19namespace Thyra {
20
21
27template<class Scalar>
29 const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
30 const LinearOpBase<Scalar> &fwdOp
31 )
32{
33 return lowsFactory.isCompatible(*defaultLinearOpSource(fwdOp));
34}
35
36
41template<class Scalar>
43 const LinearOpBase<Scalar> &fwdOp,
45 )
46{
47 const std::string OpLabel = Op->getObjectLabel();
48 const std::string fwdOpLabel = fwdOp.getObjectLabel();
49 if ( !OpLabel.length() && fwdOpLabel.length() )
50 Op->setObjectLabel(fwdOpLabel);
51}
52
53
58template<class Scalar>
60 const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
61 const RCP<const LinearOpBase<Scalar> > &fwdOp,
63 const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
64 )
65{
66 lowsFactory.initializeOp(defaultLinearOpSource(fwdOp), &*Op, supportSolveUse);
67 setDefaultObjectLabel(*fwdOp, Op);
68}
69
70
76template<class Scalar>
78 const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
79 const RCP<const LinearOpBase<Scalar> > &fwdOp,
81 )
82{
83 lowsFactory.initializeAndReuseOp(defaultLinearOpSource(fwdOp), &*Op);
84 setDefaultObjectLabel(*fwdOp, Op);
85}
86
87
93template<class Scalar>
95 const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
96 const RCP<const LinearOpBase<Scalar> > &fwdOp,
97 const RCP<const PreconditionerBase<Scalar> > &prec,
99 const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
100 )
101{
102 lowsFactory.initializePreconditionedOp(defaultLinearOpSource(fwdOp),
103 prec, &*Op, supportSolveUse);
104 setDefaultObjectLabel(*fwdOp ,Op);
105}
106
107
113template<class Scalar>
115 const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
116 const RCP<const LinearOpBase<Scalar> > &fwdOp,
117 const RCP<const LinearOpBase<Scalar> > &approxFwdOp,
119 const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
120 )
121{
122 lowsFactory.initializeApproxPreconditionedOp(defaultLinearOpSource(fwdOp),
123 defaultLinearOpSource(approxFwdOp), &*Op, supportSolveUse);
124 setDefaultObjectLabel(*fwdOp,Op);
125}
126
127
132template<class Scalar>
135 const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
136 const RCP<const LinearOpBase<Scalar> > &fwdOp,
137 const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
138 )
139{
140 RCP<LinearOpWithSolveBase<Scalar> > Op = lowsFactory.createOp();
141 Thyra::initializeOp<Scalar>( lowsFactory, fwdOp, Op.ptr(), supportSolveUse);
142 return Op;
143}
144
145
151template<class Scalar>
155 const RCP<const LinearOpBase<Scalar> > &fwdOp,
156 const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED,
157 const Ptr<const SolveCriteria<Scalar> > &fwdSolveCriteria = Teuchos::null,
158 const EThrowOnSolveFailure throwOnFwdSolveFailure = THROW_ON_SOLVE_FAILURE,
159 const Ptr<const SolveCriteria<Scalar> > &adjSolveCriteria = Teuchos::null,
160 const EThrowOnSolveFailure throwOnAdjSolveFailure = THROW_ON_SOLVE_FAILURE
161 )
162{
163 return inverse<Scalar>(linearOpWithSolve<Scalar>(LOWSF, fwdOp, supportSolveUse),
164 fwdSolveCriteria, throwOnFwdSolveFailure, adjSolveCriteria, throwOnAdjSolveFailure);
165}
166
167
173template<class Scalar>
175 const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
177 const Ptr<RCP<const LinearOpBase<Scalar> > > &fwdOp = Teuchos::null,
178 const Ptr<RCP<const PreconditionerBase<Scalar> > > &prec = Teuchos::null,
179 const Ptr<RCP<const LinearOpBase<Scalar> > > &approxFwdOp = Teuchos::null,
180 const Ptr<ESupportSolveUse> &supportSolveUse = Teuchos::null
181 )
182{
185 lowsFactory.uninitializeOp(Op.get(), &fwdOpSrc, prec.get(), &approxFwdOpSrc,
186 supportSolveUse.get());
187 if (nonnull(fwdOp)) {
188 *fwdOp = ( nonnull(fwdOpSrc) ? fwdOpSrc->getOp() : Teuchos::null );
189 }
190 if (nonnull(approxFwdOp)) {
191 *approxFwdOp = ( nonnull(approxFwdOpSrc) ? approxFwdOpSrc->getOp() : Teuchos::null );
192 }
193}
194
195
196} // namespace Thyra
197
198
199#endif // THYRA_LINEAR_OP_WITH_SOLVE_FACTORY_HELPERS_HPP
virtual std::string getObjectLabel() const
Ptr< T > ptr() const
T * get() const
Base class for all linear operators.
Base class for all linear operators that can support a high-level solve operation.
Factory interface for creating LinearOpWithSolveBase objects from compatible LinearOpBase objects.
bool isCompatible(const LinearOpWithSolveFactoryBase< Scalar > &lowsFactory, const LinearOpBase< Scalar > &fwdOp)
Return if the forward operator is a compatible source for a LOWSFB object.
virtual bool isCompatible(const LinearOpSourceBase< Scalar > &fwdOpSrc) const =0
Check that a LinearOpBase object is compatible with *this factory object.
RCP< LinearOpBase< Scalar > > inverse(const LinearOpWithSolveFactoryBase< Scalar > &LOWSF, const RCP< const LinearOpBase< Scalar > > &fwdOp, const ESupportSolveUse supportSolveUse=SUPPORT_SOLVE_UNSPECIFIED, const Ptr< const SolveCriteria< Scalar > > &fwdSolveCriteria=Teuchos::null, const EThrowOnSolveFailure throwOnFwdSolveFailure=THROW_ON_SOLVE_FAILURE, const Ptr< const SolveCriteria< Scalar > > &adjSolveCriteria=Teuchos::null, const EThrowOnSolveFailure throwOnAdjSolveFailure=THROW_ON_SOLVE_FAILURE)
Form a const implicit inverse operator M = inv(A) given a factory.
virtual void initializeApproxPreconditionedOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const RCP< const LinearOpSourceBase< Scalar > > &approxFwdOpSrc, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse=SUPPORT_SOLVE_UNSPECIFIED) const
Initialize a pre-created LinearOpWithSolveBase object given a "compatible" forward LinearOpBase objec...
virtual void initializeOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse=SUPPORT_SOLVE_UNSPECIFIED) const =0
Initialize a pre-created LinearOpWithSolveBase object given a "compatible" LinearOpBase object.
void setDefaultObjectLabel(const LinearOpBase< Scalar > &fwdOp, const Ptr< LinearOpWithSolveBase< Scalar > > &Op)
Set default label on a LOWSB object.
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...
virtual void initializePreconditionedOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const RCP< const PreconditionerBase< Scalar > > &prec, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse=SUPPORT_SOLVE_UNSPECIFIED) const
Initialize a pre-created LinearOpWithSolveBase object given a "compatible" LinearOpBase object and an...
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.
virtual void initializeAndReuseOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, LinearOpWithSolveBase< Scalar > *Op) const
Initialize a pre-created LinearOpWithSolveBase object given a "compatible" LinearOpBase object but al...
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(...
virtual void uninitializeOp(LinearOpWithSolveBase< Scalar > *Op, RCP< const LinearOpSourceBase< Scalar > > *fwdOpSrc=NULL, RCP< const PreconditionerBase< Scalar > > *prec=NULL, RCP< const LinearOpSourceBase< Scalar > > *approxFwdOpSrc=NULL, ESupportSolveUse *supportSolveUse=NULL) const =0
Uninitialize a LinearOpWithSolveBase object and return its remembered forward linear operator and pot...
Simple interface class to access a precreated preconditioner as one or more linear operators objects ...
ESupportSolveUse
Enum that specifies how a LinearOpWithSolveBase object will be used for solves after it is constructe...
@ SUPPORT_SOLVE_UNSPECIFIED
How the output LOWSB object will be useded for solves in unspecified.
EThrowOnSolveFailure
Determines what to do if inverse solve fails.
@ THROW_ON_SOLVE_FAILURE
Throw an exception if a solve fails to converge.
T_To & dyn_cast(T_From &from)
Simple struct that defines the requested solution criteria for a solve.