| 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_XPETRA_ADAPTER_OPERATOR_HPP |
| 11 |
#define BELOS_XPETRA_ADAPTER_OPERATOR_HPP |
| 12 |
|
| 13 |
//Note: using MACRO HAVE_XPETRA_ instead of HAVE_MUELU_ because this file will eventually be moved to Xpetra |
| 14 |
|
| 15 |
#include "Xpetra_ConfigDefs.hpp" |
| 16 |
|
| 17 |
#ifdef HAVE_XPETRA_EPETRA |
| 18 |
#include <Epetra_config.h> |
| 19 |
#include <BelosOperator.hpp> |
| 20 |
#endif |
| 21 |
|
| 22 |
#include <BelosOperatorT.hpp> |
| 23 |
|
| 24 |
namespace Belos { |
| 25 |
using Teuchos::RCP; |
| 26 |
using Teuchos::rcpFromRef; |
| 27 |
|
| 28 |
// |
| 29 |
//! @name MueLu Adapter Exceptions |
| 30 |
//@{ |
| 31 |
|
| 32 |
/** \brief XpetraOpFailure is thrown when a return value from an MueLu |
| 33 |
* call on an Xpetra::Operator or MueLu::Hierarchy is non-zero. |
| 34 |
*/ |
| 35 |
class XpetraOpFailure : public BelosError {public: |
| 36 |
XpetraOpFailure(const std::string& what_arg) : BelosError(what_arg) |
| 37 |
{}}; |
| 38 |
|
| 39 |
//@} |
| 40 |
|
| 41 |
//! @name Belos operator for Xpetra |
| 42 |
//@{ |
| 43 |
|
| 44 |
/*! @class XpetraOp |
| 45 |
* |
| 46 |
* @brief Implementation of the Belos::XpetraOp. It derives from the Belos::OperatorT templated on |
| 47 |
* the Xpetra::MultiVector and the Tpetra::MultiVector (if Teptra is enabled) |
| 48 |
* Note, in contrast to Belos::MueLuOp this operator administrates an Xpetra::Matrix<> object |
| 49 |
* and implements the effect of a vector applied to the stored matrix. |
| 50 |
* |
| 51 |
* The Belos::OperatorT class is a generalization of the Belos::Operator<> class, which |
| 52 |
* deals with any kind of vector (not only Belos::MultiVec as the Belos::Operator<> interface does). |
| 53 |
* |
| 54 |
* This is the general implementation for Tpetra only. |
| 55 |
*/ |
| 56 |
template <class Scalar, |
| 57 |
class LocalOrdinal, |
| 58 |
class GlobalOrdinal, |
| 59 |
class Node> |
| 60 |
class XpetraOp : |
| 61 |
public OperatorT<Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > |
| 62 |
#ifdef HAVE_XPETRA_TPETRA |
| 63 |
, public OperatorT<Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> > |
| 64 |
#endif |
| 65 |
{ |
| 66 |
|
| 67 |
public: |
| 68 |
|
| 69 |
//! @name Constructor/Destructor |
| 70 |
//@{ |
| 71 |
|
| 72 |
//! Default constructor |
| 73 |
XpetraOp (const RCP<Xpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > & Op) : Op_(Op) {} |
| 74 |
|
| 75 |
//! Destructor. |
| 76 |
virtual ~XpetraOp() {}; |
| 77 |
//@} |
| 78 |
|
| 79 |
//! @name Operator application method |
| 80 |
//@{ |
| 81 |
|
| 82 |
/*! \brief This routine takes the Xpetra::MultiVector \c x and applies the operator |
| 83 |
to it resulting in the Xpetra::MultiVector \c y, which is returned. |
| 84 |
\note It is expected that any problem with applying this operator to \c x will be |
| 85 |
indicated by an std::exception being thrown. |
| 86 |
*/ |
| 87 |
void Apply ( const Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& x, Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& y, ETrans trans=NOTRANS ) const { |
| 88 |
TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure, |
| 89 |
"Belos::XpetraOp::Apply, transpose mode != NOTRANS not supported."); |
| 90 |
|
| 91 |
//FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate(). |
| 92 |
y.putScalar(0.0); |
| 93 |
|
| 94 |
Op_->apply(x,y); |
| 95 |
} |
| 96 |
|
| 97 |
#ifdef HAVE_XPETRA_TPETRA |
| 98 |
// TO SKIP THE TRAIT IMPLEMENTATION OF XPETRA::MULTIVECTOR |
| 99 |
/*! \brief This routine takes the Tpetra::MultiVector \c x and applies the operator |
| 100 |
to it resulting in the Tpetra::MultiVector \c y, which is returned. |
| 101 |
\note It is expected that any problem with applying this operator to \c x will be |
| 102 |
indicated by an std::exception being thrown. |
| 103 |
*/ |
| 104 |
void Apply ( const Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& x, Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& y, ETrans trans=NOTRANS ) const { |
| 105 |
TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure, |
| 106 |
"Belos::MueLuTpetraOp::Apply, transpose mode != NOTRANS not supported."); |
| 107 |
|
| 108 |
|
| 109 |
Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & temp_x = const_cast<Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &>(x); |
| 110 |
|
| 111 |
const Xpetra::TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> tX(rcpFromRef(temp_x)); |
| 112 |
Xpetra::TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> tY(rcpFromRef(y)); |
| 113 |
|
| 114 |
//FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate(). |
| 115 |
tY.putScalar(0.0); |
| 116 |
|
| 117 |
Op_->apply(tX,tY); |
| 118 |
} |
| 119 |
#endif |
| 120 |
|
| 121 |
RCP<const Xpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > getOperator() const { return Op_; } |
| 122 |
|
| 123 |
private: |
| 124 |
|
| 125 |
RCP<Xpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Op_; |
| 126 |
}; |
| 127 |
|
| 128 |
#ifdef HAVE_XPETRA_EPETRA |
| 129 |
#ifndef EPETRA_NO_32BIT_GLOBAL_INDICES |
| 130 |
/*! @class XpetraOp |
| 131 |
* |
| 132 |
* @brief Implementation of the Belos::XpetraOp. It derives from the Belos::OperatorT templated on |
| 133 |
* the Xpetra::MultiVector and/or the Tpetra::MultiVector (if Teptra is enabled) and/or the |
| 134 |
* EpetraMultiVector (if Epetra is enabled) |
| 135 |
* |
| 136 |
* This is the specialization for <double,int,int,Xpetra::EpetraNode> |
| 137 |
*/ |
| 138 |
template <> |
| 139 |
class XpetraOp<double, int, int, Xpetra::EpetraNode> |
| 140 |
: |
| 141 |
public OperatorT<Xpetra::MultiVector<double, int, int, Xpetra::EpetraNode> > |
| 142 |
#ifdef HAVE_XPETRA_TPETRA |
| 143 |
#if !((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \ |
| 144 |
(!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT)))) |
| 145 |
, public OperatorT<Tpetra::MultiVector<double, int, int, Xpetra::EpetraNode> > |
| 146 |
#endif |
| 147 |
#endif |
| 148 |
#ifdef HAVE_XPETRA_EPETRA |
| 149 |
, public OperatorT<Epetra_MultiVector> |
| 150 |
#endif |
| 151 |
{ |
| 152 |
typedef double Scalar; |
| 153 |
typedef int LocalOrdinal; |
| 154 |
typedef int GlobalOrdinal; |
| 155 |
typedef Xpetra::EpetraNode Node; |
| 156 |
|
| 157 |
public: |
| 158 |
|
| 159 |
XpetraOp(const RCP<Xpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > & Op) : Op_(Op) {} |
| 160 |
|
| 161 |
virtual ~XpetraOp() {}; |
| 162 |
|
| 163 |
void Apply ( const Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& x, Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& y, ETrans trans=NOTRANS ) const { |
| 164 |
TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure, |
| 165 |
"Belos::XpetraOp::Apply, transpose mode != NOTRANS not supported."); |
| 166 |
|
| 167 |
//FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate(). |
| 168 |
y.putScalar(0.0); |
| 169 |
|
| 170 |
Op_->apply(x,y); |
| 171 |
} |
| 172 |
|
| 173 |
#ifdef HAVE_XPETRA_TPETRA |
| 174 |
#if !((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_INT))) || \ |
| 175 |
(!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_INT)))) |
| 176 |
void Apply ( const Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& x, Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& y, ETrans trans=NOTRANS ) const { |
| 177 |
TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure, |
| 178 |
"Belos::MueLuTpetraOp::Apply, transpose mode != NOTRANS not supported."); |
| 179 |
|
| 180 |
Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & temp_x = const_cast<Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &>(x); |
| 181 |
|
| 182 |
const Xpetra::TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> tX(rcpFromRef(temp_x)); |
| 183 |
Xpetra::TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> tY(rcpFromRef(y)); |
| 184 |
|
| 185 |
//FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate(). |
| 186 |
tY.putScalar(0.0); |
| 187 |
|
| 188 |
Op_->apply(tX,tY); |
| 189 |
} |
| 190 |
#endif |
| 191 |
#endif |
| 192 |
|
| 193 |
#ifdef HAVE_XPETRA_EPETRA |
| 194 |
// TO SKIP THE TRAIT IMPLEMENTATION OF XPETRA::MULTIVECTOR |
| 195 |
/*! \brief This routine takes the Epetra_MultiVector \c x and applies the operator |
| 196 |
to it resulting in the Epetra_MultiVector \c y, which is returned. |
| 197 |
\note It is expected that any problem with applying this operator to \c x will be |
| 198 |
indicated by an std::exception being thrown. |
| 199 |
*/ |
| 200 |
void Apply ( const Epetra_MultiVector& x, Epetra_MultiVector& y, ETrans trans=NOTRANS ) const { |
| 201 |
TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure, |
| 202 |
"Belos::MueLuTpetraOp::Apply, transpose mode != NOTRANS not supported."); |
| 203 |
|
| 204 |
Epetra_MultiVector & temp_x = const_cast<Epetra_MultiVector &>(x); |
| 205 |
|
| 206 |
const Xpetra::EpetraMultiVectorT<GlobalOrdinal,Node> tX(rcpFromRef(temp_x)); |
| 207 |
Xpetra::EpetraMultiVectorT<GlobalOrdinal,Node> tY(rcpFromRef(y)); |
| 208 |
|
| 209 |
//FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate(). |
| 210 |
tY.putScalar(0.0); |
| 211 |
|
| 212 |
Op_->apply(tX,tY); |
| 213 |
} |
| 214 |
#endif |
| 215 |
|
| 216 |
RCP<const Xpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > getOperator() const { return Op_; } |
| 217 |
|
| 218 |
private: |
| 219 |
|
| 220 |
RCP<Xpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Op_; |
| 221 |
}; |
| 222 |
#endif // !EPETRA_NO_32BIT_GLOBAL_INDICES |
| 223 |
#endif // HAVE_XPETRA_EPETRA |
| 224 |
|
| 225 |
#ifdef HAVE_XPETRA_EPETRA |
| 226 |
#ifndef EPETRA_NO_64BIT_GLOBAL_INDICES |
| 227 |
/*! @class XpetraOp |
| 228 |
* |
| 229 |
* @brief Implementation of the Belos::XpetraOp. It derives from the Belos::OperatorT templated on |
| 230 |
* the Xpetra::MultiVector and/or the Tpetra::MultiVector (if Teptra is enabled) and/or the |
| 231 |
* EpetraMultiVector (if Epetra64 is enabled). Please be aware that Epetra64 is not supported |
| 232 |
* by MueLu. Don't expect it to work or produce reasonable results. |
| 233 |
* |
| 234 |
* This is the specialization for <double,int,long long,Xpetra::EpetraNode> |
| 235 |
*/ |
| 236 |
template <> |
| 237 |
class XpetraOp<double, int, long long, Xpetra::EpetraNode> |
| 238 |
: |
| 239 |
public OperatorT<Xpetra::MultiVector<double, int, long long, Xpetra::EpetraNode> > |
| 240 |
#ifdef HAVE_XPETRA_TPETRA |
| 241 |
#if !((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \ |
| 242 |
(!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_LONG_LONG)))) |
| 243 |
, public OperatorT<Tpetra::MultiVector<double, int, long long, Xpetra::EpetraNode> > |
| 244 |
#endif |
| 245 |
#endif |
| 246 |
#ifdef HAVE_XPETRA_EPETRA |
| 247 |
, public OperatorT<Epetra_MultiVector> |
| 248 |
#endif |
| 249 |
{ |
| 250 |
typedef double Scalar; |
| 251 |
typedef int LocalOrdinal; |
| 252 |
typedef long long GlobalOrdinal; |
| 253 |
typedef Xpetra::EpetraNode Node; |
| 254 |
|
| 255 |
public: |
| 256 |
|
| 257 |
XpetraOp(const RCP<Xpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > & Op) : Op_(Op) {} |
| 258 |
|
| 259 |
virtual ~XpetraOp() {}; |
| 260 |
|
| 261 |
void Apply ( const Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& x, Xpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& y, ETrans trans=NOTRANS ) const { |
| 262 |
TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure, |
| 263 |
"Belos::XpetraOp::Apply, transpose mode != NOTRANS not supported."); |
| 264 |
|
| 265 |
//FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate(). |
| 266 |
y.putScalar(0.0); |
| 267 |
|
| 268 |
Op_->apply(x,y); |
| 269 |
} |
| 270 |
|
| 271 |
#ifdef HAVE_XPETRA_TPETRA |
| 272 |
#if !((defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_OPENMP) || !defined(HAVE_TPETRA_INST_INT_LONG_LONG))) || \ |
| 273 |
(!defined(EPETRA_HAVE_OMP) && (!defined(HAVE_TPETRA_INST_SERIAL) || !defined(HAVE_TPETRA_INST_INT_LONG_LONG)))) |
| 274 |
void Apply ( const Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& x, Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node>& y, ETrans trans=NOTRANS ) const { |
| 275 |
TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure, |
| 276 |
"Belos::MueLuTpetraOp::Apply, transpose mode != NOTRANS not supported."); |
| 277 |
|
| 278 |
Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> & temp_x = const_cast<Tpetra::MultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> &>(x); |
| 279 |
|
| 280 |
const Xpetra::TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> tX(rcpFromRef(temp_x)); |
| 281 |
Xpetra::TpetraMultiVector<Scalar, LocalOrdinal, GlobalOrdinal, Node> tY(rcpFromRef(y)); |
| 282 |
|
| 283 |
//FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate(). |
| 284 |
tY.putScalar(0.0); |
| 285 |
|
| 286 |
Op_->apply(tX,tY); |
| 287 |
} |
| 288 |
#endif |
| 289 |
#endif |
| 290 |
|
| 291 |
#ifdef HAVE_XPETRA_EPETRA |
| 292 |
// TO SKIP THE TRAIT IMPLEMENTATION OF XPETRA::MULTIVECTOR |
| 293 |
/*! \brief This routine takes the Epetra_MultiVector \c x and applies the operator |
| 294 |
to it resulting in the Epetra_MultiVector \c y, which is returned. |
| 295 |
\note It is expected that any problem with applying this operator to \c x will be |
| 296 |
indicated by an std::exception being thrown. |
| 297 |
*/ |
| 298 |
void Apply ( const Epetra_MultiVector& x, Epetra_MultiVector& y, ETrans trans=NOTRANS ) const { |
| 299 |
TEUCHOS_TEST_FOR_EXCEPTION(trans!=NOTRANS, XpetraOpFailure, |
| 300 |
"Belos::MueLuTpetraOp::Apply, transpose mode != NOTRANS not supported."); |
| 301 |
|
| 302 |
Epetra_MultiVector & temp_x = const_cast<Epetra_MultiVector &>(x); |
| 303 |
|
| 304 |
const Xpetra::EpetraMultiVectorT<GlobalOrdinal,Node> tX(rcpFromRef(temp_x)); |
| 305 |
Xpetra::EpetraMultiVectorT<GlobalOrdinal,Node> tY(rcpFromRef(y)); |
| 306 |
|
| 307 |
//FIXME InitialGuessIsZero currently does nothing in MueLu::Hierarchy.Iterate(). |
| 308 |
tY.putScalar(0.0); |
| 309 |
|
| 310 |
Op_->apply(tX,tY); |
| 311 |
} |
| 312 |
#endif |
| 313 |
|
| 314 |
RCP<const Xpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > getOperator() const { return Op_; } |
| 315 |
|
| 316 |
private: |
| 317 |
|
| 318 |
RCP<Xpetra::Operator<Scalar, LocalOrdinal, GlobalOrdinal, Node> > Op_; |
| 319 |
}; |
| 320 |
#endif // !EPETRA_NO_64BIT_GLOBAL_INDICES |
| 321 |
#endif // HAVE_XPETRA_EPETRA |
| 322 |
|
| 323 |
//@} |
| 324 |
|
| 325 |
} // namespace Belos |
| 326 |
|
| 327 |
#endif // BELOS_XPETRA_ADAPTER_OPERATOR_HPP |