MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_XpetraOperator_def.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // MueLu: A package for multigrid based preconditioning
4 //
5 // Copyright 2012 NTESS and the MueLu contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef MUELU_XPETRAOPERATOR_DEF_HPP
11 #define MUELU_XPETRAOPERATOR_DEF_HPP
12 
14 
15 namespace MueLu {
16 
17 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
20  : Hierarchy_(H) {}
21 
22 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
24  ~XpetraOperator() = default;
25 
26 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
29  getDomainMap() const {
31 
32  RCP<Matrix> A = Hierarchy_->GetLevel(0)->template Get<RCP<Matrix> >("A");
33  return A->getDomainMap();
34 }
35 
36 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
39  getRangeMap() const {
41 
42  RCP<Matrix> A = Hierarchy_->GetLevel(0)->template Get<RCP<Matrix> >("A");
43  return A->getRangeMap();
44 }
45 
46 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
50  Teuchos::ETransp mode,
51  Scalar /* alpha */,
52  Scalar /* beta */) const {
53  TEUCHOS_TEST_FOR_EXCEPTION(mode != Teuchos::NO_TRANS, std::logic_error, "MueLu::XpetraOperator does not support applying the adjoint operator");
54  try {
55 #ifdef HAVE_MUELU_DEBUG
57  RCP<Matrix> A = Hierarchy_->GetLevel(0)->template Get<RCP<Matrix> >("A");
58 
59  // X is supposed to live in the range map of the operator (const rhs = B)
64  TEUCHOS_TEST_FOR_EXCEPTION(A->getRangeMap()->isSameAs(*(Xop->getMap())) == false, std::logic_error,
65  "MueLu::XpetraOperator::apply: map of X is incompatible with range map of A");
66  TEUCHOS_TEST_FOR_EXCEPTION(A->getDomainMap()->isSameAs(*(Yop->getMap())) == false, std::logic_error,
67  "MueLu::XpetraOperator::apply: map of Y is incompatible with domain map of A");
68 #endif
69  Hierarchy_->Iterate(X, Y, 1, true);
70  } catch (std::exception& e) {
71  // FIXME add message and rethrow
72  std::cerr << "Caught an exception in MueLu::XpetraOperator::apply():" << std::endl
73  << e.what() << std::endl;
74  }
75 }
76 
77 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
80  return false;
81 }
82 
83 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
89  R.update(STS::one(), B, STS::zero());
90  this->apply(X, R, Teuchos::NO_TRANS, -STS::one(), STS::one());
91 }
92 
93 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
96  return Hierarchy_;
97 }
98 
99 } // namespace MueLu
100 
101 #endif // MUELU_XPETRAOPERATOR_DEF_HPP
static Teuchos::RCP< MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Build(const Teuchos::RCP< const Map< LocalOrdinal, GlobalOrdinal, Node >> &map, size_t NumVectors, bool zeroOut=true)
const Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
Returns the Tpetra::Map object associated with the domain of this operator.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
bool hasTransposeApply() const
Indicates whether this operator supports applying the adjoint operator.
RCP< MueLu::Hierarchy< Scalar, LocalOrdinal, GlobalOrdinal, Node > > GetHierarchy() const
Direct access to the underlying MueLu::Hierarchy.
virtual void update(const Scalar &alpha, const MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &A, const Scalar &beta)=0
virtual ~XpetraOperator()
Destructor.
MueLu::DefaultScalar Scalar
void apply(const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar=Teuchos::ScalarTraits< Scalar >::one(), Scalar=Teuchos::ScalarTraits< Scalar >::one()) const
Returns in Y the result of a Xpetra::Operator applied to a Xpetra::MultiVector X. ...
void residual(const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &B, Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &R) const
Compute a residual R = B - (*this) * X.
const Teuchos::RCP< const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
Returns the Tpetra::Map object associated with the range of this operator.
virtual size_t getNumVectors() const =0
Provides methods to build a multigrid hierarchy and apply multigrid cycles.