MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_ShiftedLaplacianOperator_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_SHIFTEDLAPLACIANOPERATOR_DEF_HPP
11 #define MUELU_SHIFTEDLAPLACIANOPERATOR_DEF_HPP
12 
13 #include "MueLu_ConfigDefs.hpp"
14 
15 #include <Xpetra_Matrix.hpp>
16 #include <Xpetra_CrsMatrixWrap.hpp>
18 #include <Xpetra_TpetraMultiVector.hpp>
19 #include <Xpetra_MultiVectorFactory.hpp>
20 
22 #include "MueLu_Hierarchy.hpp"
23 #include "MueLu_Utilities.hpp"
24 
25 namespace MueLu {
26 
27 // ------------- getDomainMap -----------------------
28 
29 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
32  getDomainMap() const {
34 
35  RCP<MueLu::Level> L0 = Hierarchy_->GetLevel(0);
36  RCP<XMatrix> A = L0->Get<RCP<XMatrix> >("A");
37 
40  if (tpbA != Teuchos::null) {
41  return Xpetra::toTpetraNonZero(tpbA->getDomainMap());
42  }
43 
46  return tpA->getDomainMap();
47 }
48 
49 // ------------- getRangeMap -----------------------
50 
51 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
54  getRangeMap() const {
56 
57  RCP<MueLu::Level> L0 = Hierarchy_->GetLevel(0);
58  RCP<XMatrix> A = L0->Get<RCP<XMatrix> >("A");
59 
62  if (tpbA != Teuchos::null)
63  return Xpetra::toTpetraNonZero(tpbA->getRangeMap());
64 
67  return tpA->getRangeMap();
68 }
69 
70 // ------------- apply -----------------------
71 
72 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
75  Teuchos::ETransp /* mode */, Scalar /* alpha */, Scalar /* beta */) const {
78  // typedef Xpetra::MultiVector<Scalar,LocalOrdinal,GlobalOrdinal,Node> XMV; // unused
79 
80  TMV& temp_x = const_cast<TMV&>(X);
81  const XTMV tX(rcpFromRef(temp_x));
82  XTMV tY(rcpFromRef(Y));
83 
84  try {
85  tY.putScalar(0.0);
86  Hierarchy_->Iterate(tX, tY, cycles_, true);
87  }
88 
89  catch (std::exception& e) {
90  // FIXME add message and rethrow
91  std::cerr << "Caught an exception in MueLu::ShiftedLaplacianOperator::ApplyInverse():" << std::endl
92  << e.what() << std::endl;
93  }
94 
95  // update solution with 2-grid error correction
96  /*if(option_==1) {
97  for(int j=0; j<cycles_; j++) {
98  RCP<XMV> residual = MueLu::Utilities<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Residual(*A_, tY, tX);
99  RCP<XMV> coarseResidual = Xpetra::MultiVectorFactory<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Build(R_->getRangeMap(), tX.getNumVectors());
100  RCP<XMV> coarseError = Xpetra::MultiVectorFactory<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Build(R_->getRangeMap(), tX.getNumVectors());
101  R_ -> apply(*residual, *coarseResidual, Teuchos::NO_TRANS, (Scalar) 1.0, (Scalar) 0.0);
102  RCP<TMV> tcoarseR = MueLu::Utilities<Scalar,LocalOrdinal,GlobalOrdinal,Node>::MV2NonConstTpetraMV(coarseResidual);
103  RCP<TMV> tcoarseE = MueLu::Utilities<Scalar,LocalOrdinal,GlobalOrdinal,Node>::MV2NonConstTpetraMV(coarseError);
104  BelosLP_ -> setProblem(tcoarseE,tcoarseR);
105  BelosSM_ -> solve();
106  RCP<XMV> fineError = Xpetra::MultiVectorFactory<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Build(P_->getRangeMap(), tX.getNumVectors());
107  XTMV tmpcoarseE(rcpFromRef(*tcoarseE));
108  P_ -> apply(tmpcoarseE, *fineError, Teuchos::NO_TRANS, (Scalar) 1.0, (Scalar) 0.0);
109  tY.update((Scalar) 1.0, *fineError, (Scalar) 1.0);
110  }
111  }
112 
113  try {
114  Hierarchy_->Iterate(tX, tY, 1, false);
115  }
116 
117  catch(std::exception& e) {
118  //FIXME add message and rethrow
119  std::cerr << "Caught an exception in MueLu::ShiftedLaplacianOperator::ApplyInverse():" << std::endl
120  << e.what() << std::endl;
121  }*/
122 }
123 
124 // ------------- apply -----------------------
125 template <class Scalar, class LocalOrdinal, class GlobalOrdinal, class Node>
127  return false;
128 }
129 
130 } // namespace MueLu
131 
132 #endif // ifdef MUELU_SHIFTEDLAPLACIANOPERATOR_DEF_HPP
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access). Usage: Level-&gt;Get&lt; RCP&lt;Matrix&gt; &gt;(&quot;A&quot;, factory) if factory == NULL =&gt; use default factory.
const RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > toTpetraNonZero(const RCP< const Map< LocalOrdinal, GlobalOrdinal, Node > > &map)
Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getDomainMap() const
Returns the Tpetra::Map object associated with the domain of this operator.
void apply(const Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, Tpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Y, Teuchos::ETransp mode=Teuchos::NO_TRANS, Scalar alpha=Teuchos::ScalarTraits< Scalar >::one(), Scalar beta=Teuchos::ScalarTraits< Scalar >::one()) const
Returns in Y the result of a Tpetra::Operator applied to a Tpetra::MultiVector X. ...
bool hasTransposeApply() const
Indicates whether this operator supports applying the adjoint operator.
MueLu::DefaultScalar Scalar
Teuchos::RCP< const Tpetra::Map< LocalOrdinal, GlobalOrdinal, Node > > getRangeMap() const
Returns the Tpetra::Map object associated with the range of this operator.
static RCP< Tpetra::CrsMatrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op2NonConstTpetraCrs(RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> Op)