Thyra Version of the Day
Loading...
Searching...
No Matches
Thyra_DefaultBlockedTriangularLinearOpWithSolveFactory_def.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_DEFAULT_BLOCKED_TRIANGULAR_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
11#define THYRA_DEFAULT_BLOCKED_TRIANGULAR_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
12
13
14#include "Thyra_DefaultBlockedTriangularLinearOpWithSolveFactory_decl.hpp"
15#include "Thyra_LinearOpWithSolveBase.hpp"
16#include "Thyra_LinearOpWithSolveFactoryHelpers.hpp"
17#include "Thyra_PhysicallyBlockedLinearOpBase.hpp"
18#include "Thyra_PhysicallyBlockedLinearOpWithSolveBase.hpp" // Interface
19#include "Thyra_DefaultBlockedTriangularLinearOpWithSolve.hpp" // Implementation
20#include "Thyra_DefaultLinearOpSource.hpp"
21
22
23namespace Thyra {
24
25
26// Overridden from Constructors/Initializers/Accessors
27
28
29template<class Scalar>
32 )
33{
34#ifdef TEUCHOS_DEBUG
35 TEUCHOS_TEST_FOR_EXCEPT(is_null(lowsf));
36#endif
37 lowsf_.initialize(lowsf);
38}
39
40
41template<class Scalar>
43 const RCP<const LinearOpWithSolveFactoryBase<Scalar> > &lowsf
44 )
45{
46#ifdef TEUCHOS_DEBUG
47 TEUCHOS_TEST_FOR_EXCEPT(is_null(lowsf));
48#endif
49 lowsf_.initialize(lowsf);
50}
51
52
53template<class Scalar>
59
60
61template<class Scalar>
67
68
69// Overridden from Teuchos::Describable
70
71
72template<class Scalar>
73std::string
75{
76 std::ostringstream oss;
78 << "{"
79 << "lowsf=";
80 if (!is_null(lowsf_.getConstObj()))
81 oss << lowsf_.getConstObj()->description();
82 else
83 oss << "NULL";
84 oss << "}";
85 return oss.str();
86}
87
88
89// Overridden from ParameterListAcceptor
90
91
92template<class Scalar>
93void
95 RCP<ParameterList> const& paramList
96 )
97{
98 lowsf_.getNonconstObj()->setParameterList(paramList);
99}
100
101
102template<class Scalar>
105{
106 return lowsf_.getNonconstObj()->getNonconstParameterList();
107}
108
109
110template<class Scalar>
113{
114 return lowsf_.getNonconstObj()->unsetParameterList();
115}
116
117
118template<class Scalar>
121{
122 return lowsf_.getConstObj()->getParameterList();
123}
124
125
126template<class Scalar>
129{
130 return lowsf_.getConstObj()->getValidParameters();
131}
132
133
134// Overridden from LinearOpWithSolveFactoyBase
135
136
137template<class Scalar>
138bool
143
144
145template<class Scalar>
146void
148 const RCP<PreconditionerFactoryBase<Scalar> > &/* precFactory */,
149 const std::string &/* precFactoryName */
150 )
151{
152 TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
153 "Error, we don't support a preconditioner factory!");
154}
155
156
157template<class Scalar>
163
164
165template<class Scalar>
167 RCP<PreconditionerFactoryBase<Scalar> > * /* precFactory */,
168 std::string * /* precFactoryName */
169 )
170{
171 TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
172 "Error, we don't support a preconditioner factory!");
173}
174
175
176template<class Scalar>
177bool
185
186
187template<class Scalar>
190{
191 return defaultBlockedTriangularLinearOpWithSolve<Scalar>();
192}
193
194
195template<class Scalar>
196void
198 const RCP<const LinearOpSourceBase<Scalar> > &fwdOpSrc,
200 const ESupportSolveUse /* supportSolveUse */
201 ) const
202{
203
204 using Teuchos::dyn_cast;
205 using Teuchos::rcp_dynamic_cast;
206
207#ifdef TEUCHOS_DEBUG
209#endif
210
211 // Set the verbosity settings for the wrapped LOWSF object!
212 lowsf_.getConstObj()->setOStream(this->getOStream());
213 lowsf_.getConstObj()->setVerbLevel(this->getVerbLevel());
214
215 // Get the block interface to get at the blocks
217 const RCP<const PBLOB> blo =
218 rcp_dynamic_cast<const PBLOB>(fwdOpSrc->getOp().assert_not_null());
219
220 // Dynamic cast to get the DefaultBlockedTriangularLinearOpWithSolveBase
221 // interface that we will fill.
222
224 DBTLOWS &btlows = dyn_cast<DBTLOWS>(*Op);
225
226 // Determine if this is the first time through or if we have already
227 // initialized before. This will be needed to allow efficient reuse of the
228 // LOWSB objects for the diagonal blocks.
229 const bool firstTime = is_null(btlows.range());
230
231 // If this is the first time through, we need to fill and create the block
232 // structure
233 if (firstTime)
234 btlows.beginBlockFill(blo->productRange(),blo->productDomain());
235
236 const int N = blo->productRange()->numBlocks();
237 for ( int k = 0; k < N; ++k ) {
238 const RCP<const LinearOpBase<Scalar> > fwdOp_k =
239 blo->getBlock(k,k).assert_not_null();
240 if (firstTime) {
241 // This is the first time through so reate and initialize a new LOWSB
242 // object for each block
243 btlows.setNonconstLOWSBlock( k, k,
244 linearOpWithSolve<Scalar>(*lowsf_.getConstObj(),fwdOp_k)
245 );
246 }
247 else {
248 // This is not the first time through so we need to just reinitiallize
249 // the object that is already created. This allows us to efficiently
250 // reuse precreated structure and storage.
252 invOp_k = btlows.getNonconstLOWSBlock(k,k).assert_not_null();
253 Thyra::initializeOp<Scalar>(*lowsf_.getConstObj(), fwdOp_k, invOp_k.ptr());
254 }
255 }
256
257 // If this is the first time through, then we need to finalize the block
258 // structure.
259 if (firstTime)
260 btlows.endBlockFill();
261
262 // After the block structure has been setup, set the off-diagonal blocks.
263 // Note that this also sets the diagonal blocks but these are ignored since
264 // the LOWSB blocks created above override these.
265 btlows.setBlocks(blo);
266
267 // Set the verbosity settings
268 btlows.setOStream(this->getOStream());
269 btlows.setVerbLevel(this->getVerbLevel());
270
271}
272
273
274template<class Scalar>
275void
283
284
285template<class Scalar>
286void
289 RCP<const LinearOpSourceBase<Scalar> > *fwdOpSrc,
290 RCP<const PreconditionerBase<Scalar> > *prec,
291 RCP<const LinearOpSourceBase<Scalar> > *approxFwdOpSrc,
292 ESupportSolveUse * /* supportSolveUse */
293 ) const
294{
295 using Teuchos::dyn_cast;
296 using Teuchos::rcp_implicit_cast;
297 using Teuchos::rcp_dynamic_cast;
300 DBTLOWS &btlowsOp = dyn_cast<DBTLOWS>(*Op);
301 if (fwdOpSrc) {
302 const RCP<const LinearOpBase<Scalar> > fwdOp = btlowsOp.getBlocks();
303 if (!is_null(fwdOp))
304 *fwdOpSrc = defaultLinearOpSource<Scalar>(fwdOp);
305 else
306 *fwdOpSrc = Teuchos::null;
307 }
308 if (prec) *prec = Teuchos::null;
309 if (approxFwdOpSrc) *approxFwdOpSrc = Teuchos::null;
310}
311
312
313template<class Scalar>
314bool
316 const EPreconditionerInputType /* precOpType */
317 ) const
318{
319 // We don't support any external preconditioners!
320 return false;
321 // 20071006: rabartl: Note: We could support external preconditioners but it
322 // will take some work. We would have to extract out the individual
323 // preconditioners from each block. This would be pretty easy to do but I
324 // am not going to do this until we have to.
325}
326
327
328template<class Scalar>
329void
331 const RCP<const LinearOpSourceBase<Scalar> > &/* fwdOpSrc */,
332 const RCP<const PreconditionerBase<Scalar> > &/* prec */,
334 const ESupportSolveUse /* supportSolveUse */
335 ) const
336{
337 TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
338 "Error, we don't support an external preconditioner!");
339}
340
341
342template<class Scalar>
343void
345 const RCP<const LinearOpSourceBase<Scalar> > &/* fwdOpSrc */,
346 const RCP<const LinearOpSourceBase<Scalar> > &/* approxFwdOpSrc */,
348 const ESupportSolveUse /* supportSolveUse */
349 ) const
350{
351 TEUCHOS_TEST_FOR_EXCEPTION(true,std::logic_error,
352 "Error, we don't support an external preconditioner!");
353}
354
355
356// protected
357
358
359template<class Scalar>
360void
362{
363 lowsf_.getConstObj()->setVerbLevel(this->getVerbLevel());
364 lowsf_.getConstObj()->setOStream(this->getOStream());
365}
366
367
368} // namespace Thyra
369
370
371#endif // THYRA_DEFAULT_BLOCKED_TRIANGULAR_LINEAR_OP_WITH_SOLVE_FACTORY_HPP
virtual std::string description() const
Ptr< T > ptr() const
const RCP< T > & assert_not_null() const
Implicit subclass that takes a blocked triangular LOWB object and turns it into a LOWSB object.
virtual void setPreconditionerFactory(const RCP< PreconditionerFactoryBase< Scalar > > &precFactory, const std::string &precFactoryName)
Throws exception.
virtual void initializeAndReuseOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, LinearOpWithSolveBase< Scalar > *Op) const
virtual void initializePreconditionedOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const RCP< const PreconditionerBase< Scalar > > &prec, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
virtual RCP< PreconditionerFactoryBase< Scalar > > getPreconditionerFactory() const
Returns null .
virtual bool supportsPreconditionerInputType(const EPreconditionerInputType precOpType) const
virtual void unsetPreconditionerFactory(RCP< PreconditionerFactoryBase< Scalar > > *precFactory, std::string *precFactoryName)
Throws exception.
virtual void uninitializeOp(LinearOpWithSolveBase< Scalar > *Op, RCP< const LinearOpSourceBase< Scalar > > *fwdOpSrc, RCP< const PreconditionerBase< Scalar > > *prec, RCP< const LinearOpSourceBase< Scalar > > *approxFwdOpSrc, ESupportSolveUse *supportSolveUse) const
virtual void initializeApproxPreconditionedOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, const RCP< const LinearOpSourceBase< Scalar > > &approxFwdOpSrc, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
virtual void initializeOp(const RCP< const LinearOpSourceBase< Scalar > > &fwdOpSrc, LinearOpWithSolveBase< Scalar > *Op, const ESupportSolveUse supportSolveUse) const
Concrete composite LinearOpWithSolveBase subclass that creates single upper or lower block triangular...
Base interface for objects that can return a linear operator.
Base class for all linear operators that can support a high-level solve operation.
Factory interface for creating LinearOpWithSolveBase objects from compatible LinearOpBase objects.
Base interface for physically blocked linear operators.
Simple interface class to access a precreated preconditioner as one or more linear operators objects ...
Factory interface for creating preconditioner objects from LinearOpBase objects.
#define TEUCHOS_TEST_FOR_EXCEPT(throw_exception_test)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
EPreconditionerInputType
Enum defining the status of a preconditioner object.
ESupportSolveUse
Enum that specifies how a LinearOpWithSolveBase object will be used for solves after it is constructe...
#define TEUCHOS_UNREACHABLE_RETURN(dummyReturnVal)
T_To & dyn_cast(T_From &from)