53 #ifndef MUELU_UZAWASMOOTHER_DEF_HPP_ 54 #define MUELU_UZAWASMOOTHER_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" 73 #include "MueLu_SubBlockAFactory.hpp" 76 #include "MueLu_SchurComplementFactory.hpp" 77 #include "MueLu_DirectSolver.hpp" 78 #include "MueLu_SmootherFactory.hpp" 79 #include "MueLu_FactoryManager.hpp" 83 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
85 : type_(
"Uzawa"), A_(
Teuchos::null)
89 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
92 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
94 RCP<ParameterList> validParamList = rcp(
new ParameterList());
96 validParamList->set< RCP<const FactoryBase> >(
"A", Teuchos::null,
"Generating factory of the matrix A");
97 validParamList->set< Scalar > (
"Damping factor", 1.0,
"Damping/Scaling factor in SIMPLE");
98 validParamList->set< LocalOrdinal > (
"Sweeps", 1,
"Number of SIMPLE sweeps (default = 1)");
100 return validParamList;
104 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
106 TEUCHOS_TEST_FOR_EXCEPTION(pos < 0,
Exceptions::RuntimeError,
"MueLu::UzawaSmoother::AddFactoryManager: parameter \'pos\' must not be negative! error.");
108 size_t myPos = Teuchos::as<size_t>(pos);
117 RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
118 *out <<
"Warning: cannot add new FactoryManager at proper position " << pos <<
". The FactoryManager is just appended to the end. Check this!" << std::endl;
127 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
132 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
137 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
141 TEUCHOS_TEST_FOR_EXCEPTION(
FactManager_.size() != 2,
Exceptions::RuntimeError,
"MueLu::UzawaSmoother::DeclareInput: You have to declare two FactoryManagers with a \"Smoother\" object: One for predicting the primary variable and one for the SchurComplement system. The smoother for the SchurComplement system needs a SchurComplementFactory as input for variable \"A\". make sure that you use the same proper damping factors for omega both in the SchurComplementFactory and in the SIMPLE smoother!");
144 std::vector<Teuchos::RCP<const FactoryManagerBase> >::const_iterator it;
149 currentLevel.
DeclareInput(
"PreSmoother",(*it)->GetFactory(
"Smoother").get());
153 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
156 FactoryMonitor m(*
this,
"Setup blocked Uzawa Smoother", currentLevel);
159 this->
GetOStream(
Warnings0) <<
"MueLu::UzawaSmoother::Setup(): Setup() has already been called";
162 A_ = Factory::Get<RCP<Matrix> > (currentLevel,
"A");
164 RCP<BlockedCrsMatrix> bA = Teuchos::rcp_dynamic_cast<BlockedCrsMatrix>(
A_);
165 TEUCHOS_TEST_FOR_EXCEPTION(bA == Teuchos::null,
Exceptions::BadCast,
"MueLu::UzawaSmoother::Setup: input matrix A is not of type BlockedCrsMatrix! error.");
172 Teuchos::RCP<CrsMatrix> A00 = bA->getMatrix(0, 0);
173 Teuchos::RCP<CrsMatrix> A01 = bA->getMatrix(0, 1);
174 Teuchos::RCP<CrsMatrix> A10 = bA->getMatrix(1, 0);
175 Teuchos::RCP<CrsMatrix> A11 = bA->getMatrix(1, 1);
177 Teuchos::RCP<CrsMatrixWrap> Op00 = Teuchos::rcp(
new CrsMatrixWrap(A00));
178 Teuchos::RCP<CrsMatrixWrap> Op01 = Teuchos::rcp(
new CrsMatrixWrap(A01));
179 Teuchos::RCP<CrsMatrixWrap> Op10 = Teuchos::rcp(
new CrsMatrixWrap(A10));
180 Teuchos::RCP<CrsMatrixWrap> Op11 = Teuchos::rcp(
new CrsMatrixWrap(A11));
182 F_ = Teuchos::rcp_dynamic_cast<Matrix>(Op00);
183 G_ = Teuchos::rcp_dynamic_cast<Matrix>(Op01);
184 D_ = Teuchos::rcp_dynamic_cast<Matrix>(Op10);
185 Z_ = Teuchos::rcp_dynamic_cast<Matrix>(Op11);
188 F_->CreateView(
"stridedMaps", bA->getRangeMap(0), bA->getDomainMap(0));
189 G_->CreateView(
"stridedMaps", bA->getRangeMap(0), bA->getDomainMap(1));
190 D_->CreateView(
"stridedMaps", bA->getRangeMap(1), bA->getDomainMap(0));
191 Z_->CreateView(
"stridedMaps", bA->getRangeMap(1), bA->getDomainMap(1));
196 RCP<const FactoryManagerBase> velpredictFactManager =
FactManager_.at(0);
198 velPredictSmoo_ = currentLevel.Get< RCP<SmootherBase> >(
"PreSmoother",velpredictFactManager->GetFactory(
"Smoother").get());
201 RCP<const FactoryManagerBase> schurFactManager =
FactManager_.at(1);
203 schurCompSmoo_ = currentLevel.Get< RCP<SmootherBase> >(
"PreSmoother", schurFactManager->GetFactory(
"Smoother").get());
209 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
214 Teuchos::RCP<Teuchos::FancyOStream> fos = Teuchos::getFancyOStream(Teuchos::rcpFromRef(std::cout));
216 SC zero = Teuchos::ScalarTraits<SC>::zero(), one = Teuchos::ScalarTraits<SC>::one();
220 LocalOrdinal nSweeps = pL.get<LocalOrdinal>(
"Sweeps");
221 Scalar omega = pL.get<Scalar>(
"Damping factor");
224 RCP<MultiVector> rcpX = Teuchos::rcpFromRef(X);
228 RCP<MultiVector> residual = MultiVectorFactory::Build(B.getMap(), B.getNumVectors());
231 for (LocalOrdinal run = 0; run < nSweeps; ++run) {
233 residual->update(one,B,zero);
234 A_->apply(*rcpX, *residual, Teuchos::NO_TRANS, -one, one);
242 RCP<MultiVector> xtilde1 = MultiVectorFactory::Build(
F_->getRowMap(),1);
243 xtilde1->putScalar(zero);
248 RCP<MultiVector> schurCompRHS = MultiVectorFactory::Build(
Z_->getRowMap(),1);
249 D_->apply(*xtilde1,*schurCompRHS);
250 schurCompRHS->update(one,*r2,-one);
254 RCP<MultiVector> xtilde2 = MultiVectorFactory::Build(
Z_->getRowMap(),1);
255 xtilde2->putScalar(zero);
264 x1->update(omega,*xtilde1,one);
265 x2->update(omega,*xtilde2,one);
274 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
275 RCP<MueLu::SmootherPrototype<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
280 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
282 std::ostringstream out;
284 out <<
"{type = " <<
type_ <<
"}";
288 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
293 out0 <<
"Prec. type: " <<
type_ << std::endl;
296 if (verbLevel &
Debug) {
Important warning messages (one line)
Exception indicating invalid cast attempted.
void Setup(Level ¤tLevel)
Setup routine.
std::string toString(const T &what)
Little helper function to convert non-string types to strings.
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
Timer to be used in factories. Similar to Monitor but with additional timers.
Print additional debugging information.
Teuchos::RCP< Matrix > D_
divergence operator
RCP< const MapExtractorClass > domainMapExtractor_
domain map extractor (from A_ generated by AFact)
Namespace for MueLu classes and methods.
virtual const Teuchos::ParameterList & GetParameterList() const
void DeclareInput(Level ¤tLevel) const
Input.
void Apply(MultiVector &X, MultiVector const &B, bool InitialGuessIsZero=false) const
Apply the Braess Sarazin smoother.
RCP< const ParameterList > GetValidParameterList() const
Input.
RCP< const MapExtractorClass > rangeMapExtractor_
range map extractor (from A_ generated by AFact)
UzawaSmoother()
Constructor.
void SetVelocityPredictionFactoryManager(RCP< FactoryManager > FactManager)
Teuchos::RCP< Matrix > F_
fluid operator
Class that holds all level-specific information.
RCP< Matrix > A_
block operator
std::string description() const
Return a simple one-line description of this object.
RCP< SmootherPrototype > Copy() const
bool IsSetup() const
Get the state of a smoother prototype.
Teuchos::RCP< Matrix > Z_
pressure stabilization term or null block
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
std::vector< Teuchos::RCP< const FactoryManagerBase > > FactManager_
vector of factory managers
Teuchos::RCP< SmootherBase > schurCompSmoo_
smoother for SchurComplement equation
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
void SetSchurCompFactoryManager(RCP< FactoryManager > FactManager)
Teuchos::RCP< Matrix > G_
pressure gradient operator
Teuchos::RCP< SmootherBase > velPredictSmoo_
smoother for velocity prediction
std::string type_
smoother type
void AddFactoryManager(RCP< const FactoryManagerBase > FactManager, int pos)
Add a factory manager at a specific position.
Exception throws to report errors in the internal logical of the program.
An exception safe way to call the method 'Level::SetFactoryManager()'.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput()
virtual ~UzawaSmoother()
Destructor.
virtual std::string description() const
Return a simple one-line description of this object.
const RCP< const FactoryBase > GetFactory(const std::string &varName) const
Default implementation of FactoryAcceptor::GetFactory()