Belos Version of the Day
Loading...
Searching...
No Matches
BelosOperator.hpp
Go to the documentation of this file.
1// @HEADER
2// *****************************************************************************
3// Belos: Block Linear Solvers Package
4//
5// Copyright 2004-2016 NTESS and the Belos contributors.
6// SPDX-License-Identifier: BSD-3-Clause
7// *****************************************************************************
8// @HEADER
9
10#ifndef BELOS_OPERATOR_HPP
11#define BELOS_OPERATOR_HPP
12
16
17#include "BelosConfigDefs.hpp"
19#include "BelosMultiVec.hpp"
20#ifdef HAVE_BELOS_EXPERIMENTAL
21# include "BelosInnerSolver.hpp"
22#endif // HAVE_BELOS_EXPERIMENTAL
23
24
25namespace Belos {
26
47 template <class ScalarType>
48 class Operator {
49 public:
51
52
55
57 virtual ~Operator() {};
59
61
62
86 virtual void
89 ETrans trans=NOTRANS) const = 0;
90
109 virtual bool HasApplyTranspose () const {
110 return false;
111 }
113 };
114
116 //
117 // Implementation of the Belos::OperatorTraits for Belos::Operator
118 // and Belos::MultiVec.
119 //
121
129 template<class ScalarType>
131 {
132 public:
134 static void
136 const MultiVec<ScalarType>& x,
139 {
140 Op.Apply (x, y, trans);
141 }
142
144 static bool
146 {
147 return Op.HasApplyTranspose ();
148 }
149 };
150
151#ifdef HAVE_BELOS_EXPERIMENTAL
152
166 template<class Scalar>
167 class OperatorInnerSolver : public Operator<Scalar> {
168 public:
169 typedef Scalar scalar_type;
170 typedef MultiVec<Scalar> multivector_type;
171 typedef Operator<Scalar> operator_type;
173
177 OperatorInnerSolver (const Teuchos::RCP<inner_solver_type>& solver) :
178 solver_ (solver)
179 {}
181 virtual ~OperatorInnerSolver() {}
182
204 Teuchos::RCP<inner_solver_type> getInnerSolver() const {
205 return solver_;
206 }
207
217 virtual void
218 Apply (const multivector_type& X,
219 multivector_type& Y,
220 ETrans mode = NOTRANS) const
221 {
222 using Teuchos::rcpFromRef;
223
224 TEUCHOS_TEST_FOR_EXCEPTION(mode != NOTRANS, std::invalid_argument,
225 "Belos::OperatorInnerSolver only supports applying the"
226 " operator itself, not its transpose or conjugate "
227 "transpose.");
228 solver_->solve (rcpFromRef (Y), rcpFromRef (X));
229 }
230
235 virtual bool HasApplyTranspose() const {
236 return false;
237 }
238
239 private:
242
244 Teuchos::RCP<inner_solver_type> solver_;
245 };
246
258 template <class Scalar>
259 class InnerSolverTraits<Scalar, MultiVec<Scalar>, Operator<Scalar> > {
260 public:
261 typedef Scalar scalar_type;
262 typedef MultiVec<scalar_type> multivector_type;
263 typedef Operator<scalar_type> operator_type;
264 typedef InnerSolver<scalar_type, multivector_type, operator_type> inner_solver_type;
265 typedef OperatorInnerSolver<scalar_type> wrapper_type;
266
271 static Teuchos::RCP<operator_type>
272 makeInnerSolverOperator (const Teuchos::RCP<inner_solver_type>& solver)
273 {
274 using Teuchos::rcp;
275 using Teuchos::rcp_implicit_cast;
276 return rcp_implicit_cast<operator_type> (rcp (new wrapper_type (solver)));
277 }
278
288 static Teuchos::RCP<inner_solver_type>
289 getInnerSolver (const Teuchos::RCP<operator_type>& op)
290 {
291 using Teuchos::RCP;
292 using Teuchos::rcp_dynamic_cast;
293 RCP<wrapper_type> wrapper = rcp_dynamic_cast<wrapper_type> (op, true);
294 return wrapper->getInnerSolver();
295 }
296 };
297#endif // HAVE_BELOS_EXPERIMENTAL
298
299} // end Belos namespace
300
301#endif
302
303// end of file BelosOperator.hpp
Belos header file which uses auto-configuration information to include necessary C++ headers.
Interface for multivectors used by Belos' linear solvers.
Class which defines basic traits for the operator type.
InnerSolver< scalar_type, multivector_type, operator_type > inner_solver_type
static Teuchos::RCP< inner_solver_type > getInnerSolver(const Teuchos::RCP< operator_type > &op)
Return the given wrapper's inner solver object.
UndefinedWrapperType< Scalar, MV, OP > wrapper_type
static Teuchos::RCP< OP > makeInnerSolverOperator(const Teuchos::RCP< InnerSolver< Scalar, MV, OP > > &solver)
Wrap the given inner solver in a wrapper_type.
Interface for multivectors used by Belos' linear solvers.
Alternative run-time polymorphic interface for operators.
Operator()
Default constructor (does nothing).
virtual bool HasApplyTranspose() const
Whether this operator implements applying the transpose.
virtual ~Operator()
Virtual destructor, for memory safety of derived classes.
virtual void Apply(const MultiVec< ScalarType > &x, MultiVec< ScalarType > &y, ETrans trans=NOTRANS) const =0
Apply the operator to x, putting the result in y.
static bool HasApplyTranspose(const Operator< ScalarType > &Op)
Specialization of HasApplyTranspose() for Operator objects.
static void Apply(const Operator< ScalarType > &Op, const MultiVec< ScalarType > &x, MultiVec< ScalarType > &y, ETrans trans=NOTRANS)
Specialization of Apply() for Operator and MultiVec objects.
Class which defines basic traits for the operator type.
ETrans
Whether to apply the (conjugate) transpose of an operator.

Generated for Belos by doxygen 1.9.8