53 #ifndef MUELU_BRAESSSARAZINSMOOTHER_DEF_HPP_ 54 #define MUELU_BRAESSSARAZINSMOOTHER_DEF_HPP_ 56 #include "Teuchos_ArrayViewDecl.hpp" 57 #include "Teuchos_ScalarTraits.hpp" 61 #include <Xpetra_Matrix.hpp> 62 #include <Xpetra_CrsMatrixWrap.hpp> 63 #include <Xpetra_BlockedCrsMatrix.hpp> 64 #include <Xpetra_MultiVectorFactory.hpp> 65 #include <Xpetra_VectorFactory.hpp> 69 #include "MueLu_Utilities.hpp" 71 #include "MueLu_HierarchyHelpers.hpp" 75 #include "MueLu_SchurComplementFactory.hpp" 76 #include "MueLu_DirectSolver.hpp" 77 #include "MueLu_SmootherFactory.hpp" 78 #include "MueLu_FactoryManager.hpp" 82 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
84 : type_(
"Braess Sarazin"), A_(null)
94 SchurFact->SetParameter(
"omega",ParameterEntry(omega));
95 SchurFact->SetFactory(
"A", this->
GetFactory(
"A"));
98 ParameterList SCparams;
100 RCP<SmootherPrototype> smoProtoSC = rcp(
new DirectSolver(SCtype,SCparams) );
101 smoProtoSC->SetFactory(
"A", SchurFact);
103 RCP<SmootherFactory> SmooSCFact = rcp(
new SmootherFactory(smoProtoSC) );
106 FactManager->SetFactory(
"A", SchurFact);
107 FactManager->SetFactory(
"Smoother", SmooSCFact);
108 FactManager->SetIgnoreUserData(
true);
114 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
118 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
120 TEUCHOS_TEST_FOR_EXCEPTION(pos != 0,
Exceptions::RuntimeError,
"MueLu::BraessSarazinSmoother::AddFactoryManager: parameter \'pos\' must be zero! error.");
124 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
126 RCP<ParameterList> validParamList = rcp(
new ParameterList());
128 SC one = Teuchos::ScalarTraits<SC>::one();
130 validParamList->set<RCP<const FactoryBase> >(
"A", null,
"Generating factory of the matrix A");
131 validParamList->set<SC> (
"Damping factor", one,
"Damping/Scaling factor in BraessSarazin (usually has to be chosen > 1, default = 1.0)");
132 validParamList->set<LO> (
"Sweeps", 1,
"Number of BraessSarazin sweeps (default = 1)");
133 validParamList->set<ParameterList> (
"block1", ParameterList(),
"Sublist for parameters for SchurComplement block. At least has to contain some information about a smoother \"Smoother\" for variable \"A\" which is generated by a SchurComplementFactory.");
135 return validParamList;
138 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
140 this->
Input(currentLevel,
"A");
143 "MueLu::BraessSarazinSmoother::DeclareInput: FactManager_ must not be null! " 144 "Introduce a FactoryManager for the SchurComplement equation.");
160 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
165 this->
GetOStream(
Warnings0) <<
"MueLu::BreaessSarazinSmoother::Setup(): Setup() has already been called";
168 A_ = Factory::Get<RCP<Matrix> > (currentLevel,
"A");
169 RCP<BlockedCrsMatrix> bA = rcp_dynamic_cast<BlockedCrsMatrix>(
A_);
171 "MueLu::BraessSarazinSmoother::Setup: input matrix A is not of type BlockedCrsMatrix! error.");
184 A00_->CreateView(
"stridedMaps", bA->getRangeMap(0), bA->getDomainMap(0));
185 A01_->CreateView(
"stridedMaps", bA->getRangeMap(0), bA->getDomainMap(1));
186 A10_->CreateView(
"stridedMaps", bA->getRangeMap(1), bA->getDomainMap(0));
188 A11_->CreateView(
"stridedMaps", bA->getRangeMap(1), bA->getDomainMap(1));
191 SC omega = pL.get<SC>(
"Damping factor");
194 D_ = VectorFactory::Build(
A00_->getRowMap());
195 A00_->getLocalDiagCopy(*D_);
197 SC one = Teuchos::ScalarTraits<SC>::one();
199 ArrayRCP<SC> Ddata = D_->getDataNonConst(0);
200 for (GO i = 0; i < Ddata.size(); i++)
201 Ddata[i] = one / (Ddata[i]*omega);
207 smoo_ = currentLevel.Get< RCP<SmootherBase> >(
"PreSmoother",
FactManager_->GetFactory(
"Smoother").get());
213 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
216 "MueLu::BraessSarazinSmoother::Apply(): Setup() has not been called");
218 RCP<MultiVector> rcpX = rcpFromRef(X);
219 RCP<MultiVector> deltaX0 = MultiVectorFactory::Build(
A00_->getRowMap(), 1);
220 RCP<MultiVector> deltaX1 = MultiVectorFactory::Build(
A10_->getRowMap(), 1);
221 RCP<MultiVector> Rtmp = MultiVectorFactory::Build(
A10_->getRowMap(), 1);
223 typedef Teuchos::ScalarTraits<SC> STS;
224 SC one = STS::one(), zero = STS::zero();
228 LO nSweeps = pL.get<LO>(
"Sweeps");
231 if (InitialGuessIsZero) {
232 R = MultiVectorFactory::Build(B.getMap(), B.getNumVectors());
233 R->update(one, B, zero);
238 for (LO run = 0; run < nSweeps; ++run) {
247 deltaX0->putScalar(zero);
248 deltaX0->elementWiseMultiply(one, *
D_, *R0, zero);
249 A10_->apply(*deltaX0, *Rtmp);
250 Rtmp->update(one, *R1, -one);
254 deltaX1->putScalar(zero);
255 smoo_->Apply(*deltaX1, *Rtmp);
258 deltaX0->putScalar(zero);
259 A01_->apply(*deltaX1, *deltaX0);
260 deltaX0->update(one, *R0, -one);
262 deltaX0->elementWiseMultiply(one, *
D_, *R0, zero);
265 X0->update(one, *deltaX0, one);
266 X1->update(one, *deltaX1, one);
276 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
277 RCP<MueLu::SmootherPrototype<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
282 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
285 std::ostringstream out;
287 out <<
"{type = " <<
type_ <<
"}";
291 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
296 out0 <<
"Prec. type: " <<
type_ << std::endl;
299 if (verbLevel &
Debug) {
Important warning messages (one line)
Generic Smoother Factory for generating the smoothers of the MG hierarchy.
Exception indicating invalid cast attempted.
This class specifies the default factory that should generate some data on a Level if the data does n...
RCP< Matrix > A00_
matrices
BraessSarazin smoother for 2x2 block matrices.
RCP< Vector > D_
Inverse to approximation to block (0,0). Here, D_ = omega*inv(diag(A(0,0)))
std::string toString(const T &what)
Little helper function to convert non-string types to strings.
RCP< const MapExtractorClass > domainMapExtractor_
domain map extractor (from A_ generated by AFact)
std::string type_
smoother type
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
RCP< Matrix > A_
block operator
Timer to be used in factories. Similar to Monitor but with additional timers.
Print additional debugging information.
RCP< SmootherPrototype > Copy() const
Namespace for MueLu classes and methods.
virtual const Teuchos::ParameterList & GetParameterList() const
RCP< const MapExtractorClass > rangeMapExtractor_
range map extractor (from A_ generated by AFact)
static RCP< Xpetra::Matrix< SC, LO, GO, NO > > Crs2Op(RCP< CrsMatrix > Op)
Class that encapsulates direct solvers. Autoselection of AmesosSmoother or Amesos2Smoother according ...
RCP< Matrix > A01_
Block (0,1) [typically, pressure gradient operator].
void DeclareInput(Level ¤tLevel) const
Input.
Class that holds all level-specific information.
virtual ~BraessSarazinSmoother()
Destructor.
bool IsSetup() const
Get the state of a smoother prototype.
RCP< Matrix > A11_
Block (1,1) [typically, pressure stabilization term or null block].
RCP< const ParameterList > GetValidParameterList() const
Input.
#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.
BraessSarazinSmoother()
Constructor.
Factory for building the Schur Complement for a 2x2 block matrix.
void AddFactoryManager(RCP< const FactoryManagerBase > FactManager, int pos=0)
Add a factory manager for BraessSarazin internal SchurComplement handling.
void Setup(Level ¤tLevel)
Setup routine.
RCP< Matrix > A10_
Block (1,0) [typically, divergence operator].
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
Apply the Braess Sarazin smoother.
Exception throws to report errors in the internal logical of the program.
An exception safe way to call the method 'Level::SetFactoryManager()'.
std::string description() const
Return a simple one-line description of this object.
Teuchos::RCP< SmootherBase > smoo_
Smoother for SchurComplement equation.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
void Input(Level &level, const std::string &varName) const
virtual std::string description() const
Return a simple one-line description of this object.
static RCP< MultiVector > Residual(const Operator &Op, const MultiVector &X, const MultiVector &RHS)
RCP< const FactoryManagerBase > FactManager_
Factory manager for creating the Schur Complement.
const RCP< const FactoryBase > GetFactory(const std::string &varName) const
Default implementation of FactoryAcceptor::GetFactory()