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 //
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 
79  template <class ScalarType>
80  class Operator {
81  public:
83 
84 
86  Operator() {};
87 
89  virtual ~Operator() {};
91 
93 
94 
118  virtual void
119  Apply (const MultiVec<ScalarType>& x,
121  ETrans trans=NOTRANS) const = 0;
122 
141  virtual bool HasApplyTranspose () const {
142  return false;
143  }
145  };
146 
148  //
149  // Implementation of the Belos::OperatorTraits for Belos::Operator
150  // and Belos::MultiVec.
151  //
153 
161  template<class ScalarType>
162  class OperatorTraits<ScalarType, MultiVec<ScalarType>, Operator<ScalarType> >
163  {
164  public:
166  static void
168  const MultiVec<ScalarType>& x,
170  ETrans trans=NOTRANS)
171  {
172  Op.Apply (x, y, trans);
173  }
174 
176  static bool
178  {
179  return Op.HasApplyTranspose ();
180  }
181  };
182 
183 #ifdef HAVE_BELOS_EXPERIMENTAL
184 
198  template<class Scalar>
199  class OperatorInnerSolver : public Operator<Scalar> {
200  public:
201  typedef Scalar scalar_type;
202  typedef MultiVec<Scalar> multivector_type;
203  typedef Operator<Scalar> operator_type;
204  typedef InnerSolver<scalar_type, multivector_type, operator_type> inner_solver_type;
205 
209  OperatorInnerSolver (const Teuchos::RCP<inner_solver_type>& solver) :
210  solver_ (solver)
211  {}
213  virtual ~OperatorInnerSolver() {}
214 
236  Teuchos::RCP<inner_solver_type> getInnerSolver() const {
237  return solver_;
238  }
239 
249  virtual void
250  Apply (const multivector_type& X,
251  multivector_type& Y,
252  ETrans mode = NOTRANS) const
253  {
254  using Teuchos::rcpFromRef;
255 
256  TEUCHOS_TEST_FOR_EXCEPTION(mode != NOTRANS, std::invalid_argument,
257  "Belos::OperatorInnerSolver only supports applying the"
258  " operator itself, not its transpose or conjugate "
259  "transpose.");
260  solver_->solve (rcpFromRef (Y), rcpFromRef (X));
261  }
262 
267  virtual bool HasApplyTranspose() const {
268  return false;
269  }
270 
271  private:
273  OperatorInnerSolver ();
274 
277  };
278 
290  template <class Scalar>
291  class InnerSolverTraits<Scalar, MultiVec<Scalar>, Operator<Scalar> > {
292  public:
293  typedef Scalar scalar_type;
294  typedef MultiVec<scalar_type> multivector_type;
295  typedef Operator<scalar_type> operator_type;
296  typedef InnerSolver<scalar_type, multivector_type, operator_type> inner_solver_type;
297  typedef OperatorInnerSolver<scalar_type> wrapper_type;
298 
305  {
306  using Teuchos::rcp;
307  using Teuchos::rcp_implicit_cast;
308  return rcp_implicit_cast<operator_type> (rcp (new wrapper_type (solver)));
309  }
310 
322  {
323  using Teuchos::RCP;
324  using Teuchos::rcp_dynamic_cast;
325  RCP<wrapper_type> wrapper = rcp_dynamic_cast<wrapper_type> (op, true);
326  return wrapper->getInnerSolver();
327  }
328  };
329 #endif // HAVE_BELOS_EXPERIMENTAL
330 
331 } // end Belos namespace
332 
333 #endif
334 
335 // 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: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).
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 Fri Jun 5 2020 10:20:43 for Belos by doxygen 1.8.5