Belos  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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"
18 #include "BelosOperatorTraits.hpp"
19 #include "BelosMultiVec.hpp"
20 #ifdef HAVE_BELOS_EXPERIMENTAL
21 # include "BelosInnerSolver.hpp"
22 #endif // HAVE_BELOS_EXPERIMENTAL
23 
24 
25 namespace Belos {
26 
47  template <class ScalarType>
48  class Operator {
49  public:
51 
52 
54  Operator() {};
55 
57  virtual ~Operator() {};
59 
61 
62 
86  virtual void
87  Apply (const MultiVec<ScalarType>& x,
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>
130  class OperatorTraits<ScalarType, MultiVec<ScalarType>, Operator<ScalarType> >
131  {
132  public:
134  static void
136  const MultiVec<ScalarType>& x,
138  ETrans trans=NOTRANS)
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;
172  typedef InnerSolver<scalar_type, multivector_type, operator_type> inner_solver_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:
241  OperatorInnerSolver ();
242 
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 
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 
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
virtual bool HasApplyTranspose() const
Whether this operator implements applying the transpose.
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 Teuchos::RCP< inner_solver_type > getInnerSolver(const Teuchos::RCP< operator_type > &op)
Return the given wrapper&#39;s inner solver object.
static bool HasApplyTranspose(const Operator< ScalarType > &Op)
Specialization of HasApplyTranspose() for Operator objects.
static Teuchos::RCP< OP > makeInnerSolverOperator(const Teuchos::RCP< InnerSolver< Scalar, MV, OP > > &solver)
Wrap the given inner solver in a wrapper_type.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
virtual ~Operator()
Virtual destructor, for memory safety of derived classes.
Class which defines basic traits for the operator type.
ETrans
Whether to apply the (conjugate) transpose of an operator.
Definition: BelosTypes.hpp:49
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.
Alternative run-time polymorphic interface for operators.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
UndefinedWrapperType< Scalar, MV, OP > wrapper_type
InnerSolver< scalar_type, multivector_type, operator_type > inner_solver_type
Operator()
Default constructor (does nothing).
Interface for multivectors used by Belos&#39; linear solvers.
Class which defines basic traits for the operator type.
Belos header file which uses auto-configuration information to include necessary C++ headers...
Interface for multivectors used by Belos&#39; linear solvers.

Generated on Mon Jul 15 2024 09:24:24 for Belos by doxygen 1.8.5