46 #ifndef MUELU_PROJECTORSMOOTHER_DEF_HPP 47 #define MUELU_PROJECTORSMOOTHER_DEF_HPP 49 #include <Xpetra_Matrix.hpp> 50 #include <Xpetra_MultiVectorFactory.hpp> 56 #include "MueLu_Utilities.hpp" 61 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
63 : coarseSolver_(coarseSolver)
66 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
69 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
77 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
84 this->
GetOStream(
Warnings0) <<
"MueLu::ProjectorSmoother::Setup(): Setup() has already been called" << std::endl;
86 RCP<Matrix> A = Factory::Get< RCP<Matrix> > (currentLevel,
"A");
87 RCP<MultiVector> B = Factory::Get< RCP<MultiVector> >(currentLevel,
"Nullspace");
89 int m = B->getNumVectors();
92 Array<Scalar> br(m), bb(m);
93 RCP<MultiVector> R = MultiVectorFactory::Build(B->getMap(), m);
98 Array<size_t> selectedIndices;
99 for (
int i = 0; i < m; i++) {
100 Scalar rayleigh = br[i] / bb[i];
102 if (Teuchos::ScalarTraits<Scalar>::magnitude(rayleigh) < 1e-12)
103 selectedIndices.push_back(i);
105 this->
GetOStream(
Runtime0) <<
"Coarse level orth indices: " << selectedIndices << std::endl;
107 #if defined(HAVE_MUELU_TPETRA) && defined(HAVE_XPETRA_TPETRA) 110 RCP<Tpetra::MultiVector<SC,LO,GO,NO> > Borth = B_->subCopy(selectedIndices);
111 for (
int i = 0; i < selectedIndices.size(); i++) {
112 RCP<Tpetra::Vector<SC,LO,GO,NO> > Bi = Borth->getVectorNonConst(i);
115 typename Teuchos::ScalarTraits<Scalar>::magnitudeType norm;
116 for (
int k = 0; k < i; k++) {
117 RCP<const Tpetra::Vector<SC,LO,GO,NO> > Bk = Borth->getVector(k);
120 Bi->update(-dot, *Bk, Teuchos::ScalarTraits<Scalar>::one());
124 Bi->scale(Teuchos::ScalarTraits<Scalar>::one()/norm);
127 Borth_ = rcp(static_cast<MultiVector*>(
new TpetraMultiVector(Borth)));
133 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
137 #if defined(HAVE_MUELU_TPETRA) && defined(HAVE_XPETRA_TPETRA) 138 int m =
Borth_->getNumVectors();
139 int n = X.getNumVectors();
143 for (
int i = 0; i < n; i++) {
144 RCP<Tpetra::Vector<SC,LO,GO,NO> > Xi = X_->getVectorNonConst(i);
146 Array<Scalar> dot(1);
147 for (
int k = 0; k < m; k++) {
148 RCP<const Tpetra::Vector<SC,LO,GO,NO> > Bk = Borth__->getVector(k);
151 Xi->update(-dot[0], *Bk, Teuchos::ScalarTraits<Scalar>::one());
155 this->
GetOStream(
Warnings0) <<
"MueLu::ProjectorSmoother::Setup(): disabling as it works only with Tpetra" << std::endl;
159 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
164 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
166 std::ostringstream out;
171 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
179 #endif // MUELU_PROJECTORSMOOTHER_DEF_HPP Important warning messages (one line)
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
std::string description() const
Return a simple one-line description of this object.
RCP< MultiVector > Borth_
static RCP< const Tpetra::MultiVector< SC, LO, GO, NO > > MV2TpetraMV(RCP< MultiVector > const Vec)
Helper utility to pull out the underlying Tpetra objects from an Xpetra object.
Timer to be used in factories. Similar to Monitor but with additional timers.
One-liner description of what is happening.
RCP< SmootherPrototype > coarseSolver_
Namespace for MueLu classes and methods.
static RCP< Tpetra::MultiVector< SC, LO, GO, NO > > MV2NonConstTpetraMV(RCP< MultiVector > Vec)
virtual ~ProjectorSmoother()
Destructor.
Class that holds all level-specific information.
RCP< SmootherPrototype > Copy() const
bool IsSetup() const
Get the state of a smoother prototype.
void Setup(Level ¤tLevel)
Set up the direct solver.
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
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.
ProjectorSmoother(RCP< SmootherPrototype > coarseSolver)
Constructor.
void Input(Level &level, const std::string &varName) const
void DeclareInput(Level ¤tLevel) const
Input.
virtual std::string description() const
Return a simple one-line description of this object.