Belos  Version of the Day
BelosOperator.hpp
Go to the documentation of this file.
1 //@HEADER
2 // ************************************************************************
3 //
4 // Belos: Block Linear Solvers Package
5 // Copyright 2004 Sandia Corporation
6 //
7 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8 // the U.S. Government retains certain rights in this software.
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 Michael A. Heroux (maherou@sandia.gov)
38 //
39 // ************************************************************************
40 //@HEADER
41 
42 #ifndef BELOS_OPERATOR_HPP
43 #define BELOS_OPERATOR_HPP
44 
48 
49 #include "BelosConfigDefs.hpp"
50 #include "BelosOperatorTraits.hpp"
51 #include "BelosMultiVec.hpp"
52 #ifdef HAVE_BELOS_EXPERIMENTAL
53 # include "BelosInnerSolver.hpp"
54 #endif // HAVE_BELOS_EXPERIMENTAL
55 
56 
57 namespace Belos {
58 
80  template <class ScalarType>
81  class Operator {
82  public:
84 
85 
87  Operator() {};
88 
90  virtual ~Operator() {};
92 
94 
95 
119  virtual void
120  Apply (const MultiVec<ScalarType>& x,
122  ETrans trans=NOTRANS) const = 0;
123 
142  virtual bool HasApplyTranspose () const {
143  return false;
144  }
146  };
147 
149  //
150  // Implementation of the Belos::OperatorTraits for Belos::Operator
151  // and Belos::MultiVec.
152  //
154 
162  template<class ScalarType>
163  class OperatorTraits<ScalarType, MultiVec<ScalarType>, Operator<ScalarType> >
164  {
165  public:
167  static void
169  const MultiVec<ScalarType>& x,
171  ETrans trans=NOTRANS)
172  {
173  Op.Apply (x, y, trans);
174  }
175 
177  static bool
179  {
180  return Op.HasApplyTranspose ();
181  }
182  };
183 
184 #ifdef HAVE_BELOS_EXPERIMENTAL
185 
199  template<class Scalar>
200  class OperatorInnerSolver : public Operator<Scalar> {
201  public:
202  typedef Scalar scalar_type;
203  typedef MultiVec<Scalar> multivector_type;
204  typedef Operator<Scalar> operator_type;
205  typedef InnerSolver<scalar_type, multivector_type, operator_type> inner_solver_type;
206 
210  OperatorInnerSolver (const Teuchos::RCP<inner_solver_type>& solver) :
211  solver_ (solver)
212  {}
214  virtual ~OperatorInnerSolver() {}
215 
237  Teuchos::RCP<inner_solver_type> getInnerSolver() const {
238  return solver_;
239  }
240 
250  virtual void
251  Apply (const multivector_type& X,
252  multivector_type& Y,
253  ETrans mode = NOTRANS) const
254  {
255  using Teuchos::rcpFromRef;
256 
257  TEUCHOS_TEST_FOR_EXCEPTION(mode != NOTRANS, std::invalid_argument,
258  "Belos::OperatorInnerSolver only supports applying the"
259  " operator itself, not its transpose or conjugate "
260  "transpose.");
261  solver_->solve (rcpFromRef (Y), rcpFromRef (X));
262  }
263 
268  virtual bool HasApplyTranspose() const {
269  return false;
270  }
271 
272  private:
274  OperatorInnerSolver ();
275 
278  };
279 
291  template <class Scalar>
292  class InnerSolverTraits<Scalar, MultiVec<Scalar>, Operator<Scalar> > {
293  public:
294  typedef Scalar scalar_type;
295  typedef MultiVec<scalar_type> multivector_type;
296  typedef Operator<scalar_type> operator_type;
297  typedef InnerSolver<scalar_type, multivector_type, operator_type> inner_solver_type;
298  typedef OperatorInnerSolver<scalar_type> wrapper_type;
299 
306  {
307  using Teuchos::rcp;
308  using Teuchos::rcp_implicit_cast;
309  return rcp_implicit_cast<operator_type> (rcp (new wrapper_type (solver)));
310  }
311 
323  {
324  using Teuchos::RCP;
325  using Teuchos::rcp_dynamic_cast;
326  RCP<wrapper_type> wrapper = rcp_dynamic_cast<wrapper_type> (op, true);
327  return wrapper->getInnerSolver();
328  }
329  };
330 #endif // HAVE_BELOS_EXPERIMENTAL
331 
332 } // end Belos namespace
333 
334 #endif
335 
336 // end of file BelosOperator.hpp
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:81
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).
virtual bool HasApplyTranspose() const
Whether this operator implements applying the transpose.
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 for Belos by doxygen 1.8.14