Thyra  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Thyra_LinearOpWithSolveFactoryHelpers.hpp
1 // @HEADER
2 // ***********************************************************************
3 //
4 // Thyra: Interfaces and Support for Abstract Numerical Algorithms
5 // Copyright (2004) Sandia Corporation
6 //
7 // Under terms of Contract DE-AC04-94AL85000, there is a non-exclusive
8 // license for use of this work by or on behalf of the U.S. Government.
9 //
10 // Redistribution and use in source and binary forms, with or without
11 // modification, are permitted provided that the following conditions are
12 // met:
13 //
14 // 1. Redistributions of source code must retain the above copyright
15 // notice, this list of conditions and the following disclaimer.
16 //
17 // 2. Redistributions in binary form must reproduce the above copyright
18 // notice, this list of conditions and the following disclaimer in the
19 // documentation and/or other materials provided with the distribution.
20 //
21 // 3. Neither the name of the Corporation nor the names of the
22 // contributors may be used to endorse or promote products derived from
23 // this software without specific prior written permission.
24 //
25 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
26 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
27 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
29 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
31 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
32 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
33 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
34 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
35 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
36 //
37 // Questions? Contact Roscoe A. Bartlett (bartlettra@ornl.gov)
38 //
39 // ***********************************************************************
40 // @HEADER
41 
42 #ifndef THYRA_LINEAR_OP_WITH_SOLVE_FACTORY_HELPERS_HPP
43 #define THYRA_LINEAR_OP_WITH_SOLVE_FACTORY_HELPERS_HPP
44 
45 #include "Thyra_LinearOpWithSolveFactoryBase.hpp"
46 #include "Thyra_DefaultLinearOpSource.hpp"
47 #include "Thyra_DefaultPreconditioner.hpp"
48 #include "Thyra_DefaultInverseLinearOp.hpp"
49 
50 
51 namespace Thyra {
52 
53 
59 template<class Scalar>
61  const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
62  const LinearOpBase<Scalar> &fwdOp
63  )
64 {
65  return lowsFactory.isCompatible(*defaultLinearOpSource(fwdOp));
66 }
67 
68 
73 template<class Scalar>
75  const LinearOpBase<Scalar> &fwdOp,
77  )
78 {
79  const std::string OpLabel = Op->getObjectLabel();
80  const std::string fwdOpLabel = fwdOp.getObjectLabel();
81  if ( !OpLabel.length() && fwdOpLabel.length() )
82  Op->setObjectLabel(fwdOpLabel);
83 }
84 
85 
90 template<class Scalar>
92  const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
93  const RCP<const LinearOpBase<Scalar> > &fwdOp,
95  const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
96  )
97 {
98  lowsFactory.initializeOp(defaultLinearOpSource(fwdOp), &*Op, supportSolveUse);
99  setDefaultObjectLabel(*fwdOp, Op);
100 }
101 
102 
108 template<class Scalar>
110  const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
111  const RCP<const LinearOpBase<Scalar> > &fwdOp,
113  )
114 {
115  lowsFactory.initializeAndReuseOp(defaultLinearOpSource(fwdOp), &*Op);
116  setDefaultObjectLabel(*fwdOp, Op);
117 }
118 
119 
125 template<class Scalar>
127  const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
128  const RCP<const LinearOpBase<Scalar> > &fwdOp,
129  const RCP<const PreconditionerBase<Scalar> > &prec,
131  const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
132  )
133 {
134  lowsFactory.initializePreconditionedOp(defaultLinearOpSource(fwdOp),
135  prec, &*Op, supportSolveUse);
136  setDefaultObjectLabel(*fwdOp ,Op);
137 }
138 
139 
145 template<class Scalar>
147  const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
148  const RCP<const LinearOpBase<Scalar> > &fwdOp,
149  const RCP<const LinearOpBase<Scalar> > &approxFwdOp,
151  const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
152  )
153 {
154  lowsFactory.initializeApproxPreconditionedOp(defaultLinearOpSource(fwdOp),
155  defaultLinearOpSource(approxFwdOp), &*Op, supportSolveUse);
156  setDefaultObjectLabel(*fwdOp,Op);
157 }
158 
159 
164 template<class Scalar>
167  const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
168  const RCP<const LinearOpBase<Scalar> > &fwdOp,
169  const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED
170  )
171 {
172  RCP<LinearOpWithSolveBase<Scalar> > Op = lowsFactory.createOp();
173  Thyra::initializeOp<Scalar>( lowsFactory, fwdOp, Op.ptr(), supportSolveUse);
174  return Op;
175 }
176 
177 
183 template<class Scalar>
187  const RCP<const LinearOpBase<Scalar> > &fwdOp,
188  const ESupportSolveUse supportSolveUse = SUPPORT_SOLVE_UNSPECIFIED,
189  const Ptr<const SolveCriteria<Scalar> > &fwdSolveCriteria = Teuchos::null,
190  const EThrowOnSolveFailure throwOnFwdSolveFailure = THROW_ON_SOLVE_FAILURE,
191  const Ptr<const SolveCriteria<Scalar> > &adjSolveCriteria = Teuchos::null,
192  const EThrowOnSolveFailure throwOnAdjSolveFailure = THROW_ON_SOLVE_FAILURE
193  )
194 {
195  return inverse<Scalar>(linearOpWithSolve<Scalar>(LOWSF, fwdOp, supportSolveUse),
196  fwdSolveCriteria, throwOnFwdSolveFailure, adjSolveCriteria, throwOnAdjSolveFailure);
197 }
198 
199 
205 template<class Scalar>
207  const LinearOpWithSolveFactoryBase<Scalar> &lowsFactory,
209  const Ptr<RCP<const LinearOpBase<Scalar> > > &fwdOp = Teuchos::null,
210  const Ptr<RCP<const PreconditionerBase<Scalar> > > &prec = Teuchos::null,
211  const Ptr<RCP<const LinearOpBase<Scalar> > > &approxFwdOp = Teuchos::null,
212  const Ptr<ESupportSolveUse> &supportSolveUse = Teuchos::null
213  )
214 {
216  RCP<const LinearOpSourceBase<Scalar> > approxFwdOpSrc;
217  lowsFactory.uninitializeOp(Op.get(), &fwdOpSrc, prec.get(), &approxFwdOpSrc,
218  supportSolveUse.get());
219  if (nonnull(fwdOp)) {
220  *fwdOp = ( nonnull(fwdOpSrc) ? fwdOpSrc->getOp() : Teuchos::null );
221  }
222  if (nonnull(approxFwdOp)) {
223  *approxFwdOp = ( nonnull(approxFwdOpSrc) ? approxFwdOpSrc->getOp() : Teuchos::null );
224  }
225 }
226 
227 
228 } // namespace Thyra
229 
230 
231 #endif // THYRA_LINEAR_OP_WITH_SOLVE_FACTORY_HELPERS_HPP
How the output LOWSB object will be useded for solves in unspecified.
virtual std::string getObjectLabel() const
Base class for all linear operators that can support a high-level solve operation.
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 &quot;compatible&quot; LinearOpBase object and an...
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 &quot;compatible&quot; LinearOpBase object...
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...
T * get() const
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...
Simple interface class to access a precreated preconditioner as one or more linear operators objects ...
virtual void initializeAndReuseOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, LinearOpWithSolveBase< Scalar > *Op) const
Initialize a pre-created LinearOpWithSolveBase object given a &quot;compatible&quot; LinearOpBase object but al...
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 &quot;compatible&quot; forward LinearOpBase objec...
virtual RCP< LinearOpWithSolveBase< Scalar > > createOp() const =0
Create an (uninitialized) LinearOpWithSolveBase object to be initialized later in this-&gt;initializeOp(...
void setDefaultObjectLabel(const LinearOpBase< Scalar > &fwdOp, const Ptr< LinearOpWithSolveBase< Scalar > > &Op)
Set default label on a LOWSB object.
Throw an exception if a solve fails to converge.
Factory interface for creating LinearOpWithSolveBase objects from compatible LinearOpBase objects...
Ptr< T > ptr() const
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...
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.
Base class for all linear operators.
ESupportSolveUse
Enum that specifies how a LinearOpWithSolveBase object will be used for solves after it is constructe...
virtual bool isCompatible(const LinearOpSourceBase< Scalar > &fwdOpSrc) const =0
Check that a LinearOpBase object is compatible with *this factory object.
bool nonnull(const boost::shared_ptr< T > &p)
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 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...
EThrowOnSolveFailure
Determines what to do if inverse solve fails.
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...
Simple struct that defines the requested solution criteria for a solve.
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.
bool isCompatible(const LinearOpWithSolveFactoryBase< Scalar > &lowsFactory, const LinearOpBase< Scalar > &fwdOp)
Return if the forward operator is a compatible source for a LOWSFB object.