10#ifndef MUELU_PROJECTORSMOOTHER_DEF_HPP
11#define MUELU_PROJECTORSMOOTHER_DEF_HPP
13#include <Xpetra_Matrix.hpp>
14#include <Xpetra_MultiVectorFactory.hpp>
20#include "MueLu_Utilities.hpp"
25template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
29template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
32template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
40template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
47 this->
GetOStream(
Warnings0) <<
"MueLu::ProjectorSmoother::Setup(): Setup() has already been called" << std::endl;
52 int m = B->getNumVectors();
55 Array<Scalar> br(m), bb(m);
56 RCP<MultiVector> R = MultiVectorFactory::Build(B->getMap(), m);
61 Array<size_t> selectedIndices;
62 for (
int i = 0; i < m; i++) {
63 Scalar rayleigh = br[i] / bb[i];
65 if (Teuchos::ScalarTraits<Scalar>::magnitude(rayleigh) < 1e-12)
66 selectedIndices.push_back(i);
68 this->
GetOStream(
Runtime0) <<
"Coarse level orth indices: " << selectedIndices << std::endl;
70#ifdef HAVE_MUELU_TPETRA_INST_INT_INT
72 RCP<const Tpetra::MultiVector<SC, LO, GO, NO> > B_ = toTpetra(B);
75 RCP<Tpetra::MultiVector<SC, LO, GO, NO> > Borth = B_->subCopy(selectedIndices);
76 for (
int i = 0; i < selectedIndices.size(); i++) {
77 RCP<Tpetra::Vector<SC, LO, GO, NO> > Bi = Borth->getVectorNonConst(i);
80 typename Teuchos::ScalarTraits<Scalar>::magnitudeType norm;
81 for (
int k = 0; k < i; k++) {
82 RCP<const Tpetra::Vector<SC, LO, GO, NO> > Bk = Borth->getVector(k);
85 Bi->update(-dot, *Bk, Teuchos::ScalarTraits<Scalar>::one());
89 Bi->scale(Teuchos::ScalarTraits<Scalar>::one() / norm);
92 Borth_ = rcp(
static_cast<MultiVector *
>(
new TpetraMultiVector(Borth)));
94 TEUCHOS_TEST_FOR_EXCEPTION(
true,
Exceptions::RuntimeError,
"Tpetra with GO=int not available. The code in ProjectorSmoother should be rewritten!");
100template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
104 int m =
Borth_->getNumVectors();
105 int n = X.getNumVectors();
107 RCP<Xpetra::MultiVector<SC, LO, GO, NO> > X_ = Teuchos::rcpFromRef(X);
108 for (
int i = 0; i < n; i++) {
109 RCP<Xpetra::Vector<SC, LO, GO, NO> > Xi = X_->getVectorNonConst(i);
111 Array<Scalar> dot(1);
112 for (
int k = 0; k < m; k++) {
113 RCP<const Xpetra::Vector<SC, LO, GO, NO> > Bk =
Borth_->getVector(k);
116 Xi->update(-dot[0], *Bk, Teuchos::ScalarTraits<Scalar>::one());
121template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
126template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
128 std::ostringstream out;
133template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
MueLu::DefaultScalar Scalar
virtual std::string description() const
Return a simple one-line description of this object.
Exception throws to report errors in the internal logical of the program.
void Input(Level &level, const std::string &varName) const
T Get(Level &level, const std::string &varName) const
Timer to be used in factories. Similar to Monitor but with additional timers.
Class that holds all level-specific information.
RCP< SmootherPrototype > coarseSolver_
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
Apply the direct solver. Solves the linear system AX=B using the constructed solver.
RCP< SmootherPrototype > Copy() const
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
virtual ~ProjectorSmoother()
Destructor.
void Setup(Level ¤tLevel)
Set up the direct solver.
std::string description() const
Return a simple one-line description of this object.
ProjectorSmoother(RCP< SmootherPrototype > coarseSolver)
Constructor.
RCP< MultiVector > Borth_
void DeclareInput(Level ¤tLevel) const
Input.
bool IsSetup() const
Get the state of a smoother prototype.
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
Namespace for MueLu classes and methods.
@ Warnings0
Important warning messages (one line).
@ Runtime0
One-liner description of what is happening.