MueLu  Version of the Day
BelosXpetraAdapterOperator.hpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // MueLu: A package for multigrid based preconditioning
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 #ifndef BELOS_XPETRA_ADAPTER_OPERATOR_HPP
47 #define BELOS_XPETRA_ADAPTER_OPERATOR_HPP
48 
49 //Note: using MACRO HAVE_XPETRA_ instead of HAVE_MUELU_ because this file will eventually be moved to Xpetra
50 
51 #include "Xpetra_ConfigDefs.hpp"
52 
53 #ifdef HAVE_XPETRA_EPETRA
54 #include <Epetra_config.h>
55 #include <BelosOperator.hpp>
56 #endif
57 
58 #include <BelosOperatorT.hpp>
59 
60 namespace Belos {
61  using Teuchos::RCP;
62  using Teuchos::rcpFromRef;
63 
64  //
66 
67 
71  class XpetraOpFailure : public BelosError {public:
72  XpetraOpFailure(const std::string& what_arg) : BelosError(what_arg)
73  {}};
74 
76 
78 
79 
92  template <class Scalar,
93  class LocalOrdinal,
94  class GlobalOrdinal,
95  class Node>
96  class XpetraOp :
97  public OperatorT<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
98 #ifdef HAVE_XPETRA_TPETRA
99  , public OperatorT<Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
100 #endif
101  {
102 
103  public:
104 
106 
107 
110 
112  virtual ~XpetraOp() {};
114 
116 
117 
124  TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure,
125  "Belos::XpetraOp::Apply, transpose mode != NOTRANS not supported.");
126 
127  //FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate().
128  y.putScalar(0.0);
129 
130  Op_->apply(x,y);
131  }
132 
133 #ifdef HAVE_XPETRA_TPETRA
134  // TO SKIP THE TRAIT IMPLEMENTATION OF XPETRA::MULTIVECTOR
141  TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure,
142  "Belos::MueLuTpetraOp::Apply, transpose mode != NOTRANS not supported.");
143 
144 
146 
149 
150  //FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate().
151  tY.putScalar(0.0);
152 
153  Op_->apply(tX,tY);
154  }
155 #endif
156 
157  RCP<const Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > getOperator() const { return Op_; }
158 
159  private:
160 
161  RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Op_;
162  };
163 
164 #ifdef HAVE_MUELU_EPETRA
165 #ifndef EPETRA_NO_32BIT_GLOBAL_INDICES
166 
174  template <>
175  class XpetraOp<double, int, int, Xpetra::EpetraNode>
176  :
177  public OperatorT<Xpetra::MultiVector<double, int, int, Xpetra::EpetraNode> >
178 #ifdef HAVE_XPETRA_TPETRA
179 #if !((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
180  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
181  , public OperatorT<Tpetra::MultiVector<double, int, int, Xpetra::EpetraNode> >
182 #endif
183 #endif
184 #ifdef HAVE_XPETRA_EPETRA
185  , public OperatorT<Epetra_MultiVector>
186 #endif
187  {
188  typedef double Scalar;
189  typedef int LocalOrdinal;
190  typedef int GlobalOrdinal;
192 
193  public:
194 
196 
197  virtual ~XpetraOp() {};
198 
200  TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure,
201  "Belos::XpetraOp::Apply, transpose mode != NOTRANS not supported.");
202 
203  //FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate().
204  y.putScalar(0.0);
205 
206  Op_->apply(x,y);
207  }
208 
209 #ifdef HAVE_XPETRA_TPETRA
210 #if !((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \
211  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT))))
213  TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure,
214  "Belos::MueLuTpetraOp::Apply, transpose mode != NOTRANS not supported.");
215 
217 
220 
221  //FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate().
222  tY.putScalar(0.0);
223 
224  Op_->apply(tX,tY);
225  }
226 #endif
227 #endif
228 
229 #ifdef HAVE_XPETRA_EPETRA
230  // TO SKIP THE TRAIT IMPLEMENTATION OF XPETRA::MULTIVECTOR
236  void Apply ( const Epetra_MultiVector& x, Epetra_MultiVector& y, ETrans trans=NOTRANS ) const {
237  TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure,
238  "Belos::MueLuTpetraOp::Apply, transpose mode != NOTRANS not supported.");
239 
240  Epetra_MultiVector & temp_x = const_cast<Epetra_MultiVector &>(x);
241 
242  const Xpetra::EpetraMultiVectorT<GlobalOrdinal,Node> tX(rcpFromRef(temp_x));
244 
245  //FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate().
246  tY.putScalar(0.0);
247 
248  Op_->apply(tX,tY);
249  }
250 #endif
251 
252  RCP<const Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > getOperator() const { return Op_; }
253 
254  private:
255 
256  RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Op_;
257  };
258 #endif // !EPETRA_NO_32BIT_GLOBAL_INDICES
259 #endif // HAVE_MUELU_EPETRA
260 
261 #ifdef HAVE_MUELU_EPETRA
262 #ifndef EPETRA_NO_64BIT_GLOBAL_INDICES
263 
272  template <>
273  class XpetraOp<double, int, long long, Xpetra::EpetraNode>
274  :
275  public OperatorT<Xpetra::MultiVector<double, int, long long, Xpetra::EpetraNode> >
276 #ifdef HAVE_XPETRA_TPETRA
277 #if !((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \
278  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_LONG_LONG))))
279  , public OperatorT<Tpetra::MultiVector<double, int, long long, Xpetra::EpetraNode> >
280 #endif
281 #endif
282 #ifdef HAVE_XPETRA_EPETRA
283  , public OperatorT<Epetra_MultiVector>
284 #endif
285  {
286  typedef double Scalar;
287  typedef int LocalOrdinal;
288  typedef long long GlobalOrdinal;
290 
291  public:
292 
294 
295  virtual ~XpetraOp() {};
296 
298  TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure,
299  "Belos::XpetraOp::Apply, transpose mode != NOTRANS not supported.");
300 
301  //FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate().
302  y.putScalar(0.0);
303 
304  Op_->apply(x,y);
305  }
306 
307 #ifdef HAVE_XPETRA_TPETRA
308 #if !((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \
309  (!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_LONG_LONG))))
311  TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure,
312  "Belos::MueLuTpetraOp::Apply, transpose mode != NOTRANS not supported.");
313 
315 
318 
319  //FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate().
320  tY.putScalar(0.0);
321 
322  Op_->apply(tX,tY);
323  }
324 #endif
325 #endif
326 
327 #ifdef HAVE_XPETRA_EPETRA
328  // TO SKIP THE TRAIT IMPLEMENTATION OF XPETRA::MULTIVECTOR
334  void Apply ( const Epetra_MultiVector& x, Epetra_MultiVector& y, ETrans trans=NOTRANS ) const {
335  TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure,
336  "Belos::MueLuTpetraOp::Apply, transpose mode != NOTRANS not supported.");
337 
338  Epetra_MultiVector & temp_x = const_cast<Epetra_MultiVector &>(x);
339 
340  const Xpetra::EpetraMultiVectorT<GlobalOrdinal,Node> tX(rcpFromRef(temp_x));
342 
343  //FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate().
344  tY.putScalar(0.0);
345 
346  Op_->apply(tX,tY);
347  }
348 #endif
349 
350  RCP<const Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > getOperator() const { return Op_; }
351 
352  private:
353 
354  RCP<Xpetra::Matrix<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Op_;
355  };
356 #endif // !EPETRA_NO_64BIT_GLOBAL_INDICES
357 #endif // HAVE_MUELU_EPETRA
358 
360 
361 } // namespace Belos
362 
363 #endif // BELOS_XPETRA_ADAPTER_OPERATOR_HPP
RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getOperator() const
RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getOperator() const
RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op_
virtual void putScalar(const Scalar &value)=0
virtual ~XpetraOp()
Destructor.
XpetraOp(const RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &Op)
Default constructor.
void Apply(const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x, Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &y, ETrans trans=NOTRANS) const
This routine takes the Xpetra::MultiVector x and applies the operator to it resulting in the Xpetra::...
XpetraOpFailure(const std::string &what_arg)
RCP< const Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > getOperator() const
void Apply(const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x, Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &y, ETrans trans=NOTRANS) const
This routine takes the Belos::MultiVec x and applies the operator to it resulting in the Belos::Multi...
XpetraOp(const RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &Op)
Implementation of the Belos::XpetraOp. It derives from the Belos::OperatorT templated on the Xpetra::...
XpetraOpFailure is thrown when a return value from an MueLu call on an Xpetra::Operator or MueLu::Hie...
XpetraOp(const RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > &Op)
RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op_
RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op_
void Apply(const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &x, Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &y, ETrans trans=NOTRANS) const
This routine takes the Belos::MultiVec x and applies the operator to it resulting in the Belos::Multi...