53 #ifndef MUELU_UZAWASMOOTHER_DEF_HPP_ 54 #define MUELU_UZAWASMOOTHER_DEF_HPP_ 56 #include "Teuchos_ArrayViewDecl.hpp" 68 #include "MueLu_Utilities.hpp" 70 #include "MueLu_HierarchyUtils.hpp" 72 #include "MueLu_SubBlockAFactory.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_(
"Uzawa"), A_(
Teuchos::null)
88 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
91 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
96 validParamList->
set< Scalar > (
"Damping factor", 1.0,
"Damping/Scaling factor in SIMPLE");
97 validParamList->
set< LocalOrdinal > (
"Sweeps", 1,
"Number of SIMPLE sweeps (default = 1)");
99 return validParamList;
103 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
107 size_t myPos = Teuchos::as<size_t>(pos);
109 if (myPos < FactManager_.size()) {
111 FactManager_.at(myPos) = FactManager;
112 }
else if( myPos == FactManager_.size()) {
114 FactManager_.push_back(FactManager);
117 *out <<
"Warning: cannot add new FactoryManager at proper position " << pos <<
". The FactoryManager is just appended to the end. Check this!" << std::endl;
120 FactManager_.push_back(FactManager);
126 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
128 AddFactoryManager(FactManager, 0);
131 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
133 AddFactoryManager(FactManager, 1);
136 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
138 currentLevel.
DeclareInput(
"A",this->GetFactory(
"A").
get());
140 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!");
143 std::vector<Teuchos::RCP<const FactoryManagerBase> >::const_iterator it;
144 for(it = FactManager_.begin(); it!=FactManager_.end(); ++it) {
148 currentLevel.
DeclareInput(
"PreSmoother",(*it)->GetFactory(
"Smoother").get());
152 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
155 FactoryMonitor m(*
this,
"Setup blocked Uzawa Smoother", currentLevel);
158 this->GetOStream(
Warnings0) <<
"MueLu::UzawaSmoother::Setup(): Setup() has already been called";
161 A_ = Factory::Get<RCP<Matrix> > (currentLevel,
"A");
167 rangeMapExtractor_ = bA->getRangeMapExtractor();
168 domainMapExtractor_ = bA->getDomainMapExtractor();
171 F_ = bA->getMatrix(0, 0);
172 G_ = bA->getMatrix(0, 1);
173 D_ = bA->getMatrix(1, 0);
174 Z_ = bA->getMatrix(1, 1);
192 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
205 bool bFThyraSpecialTreatment =
false;
206 bool bZThyraSpecialTreatment =
false;
207 if (bA00 != Teuchos::null) {
208 if(bA00->Rows() == 1 && bA00->Cols() == 1 && rangeMapExtractor_->getThyraMode() ==
true) bFThyraSpecialTreatment =
true;
210 if (bA11 != Teuchos::null) {
211 if(bA11->Rows() == 1 && bA11->Cols() == 1 && rangeMapExtractor_->getThyraMode() ==
true) bZThyraSpecialTreatment =
true;
216 LocalOrdinal nSweeps = pL.
get<LocalOrdinal>(
"Sweeps");
217 Scalar omega = pL.
get<Scalar>(
"Damping factor");
224 RCP<MultiVector> residual = MultiVectorFactory::Build(B.getMap(), B.getNumVectors());
227 for (LocalOrdinal run = 0; run < nSweeps; ++run) {
229 residual->update(one,B,zero);
238 RCP<MultiVector> xtilde1 = MultiVectorFactory::Build(F_->getRowMap(),X.getNumVectors(),
true);
242 if(bFThyraSpecialTreatment ==
true) {
243 RCP<MultiVector> xtilde1_thyra = domainMapExtractor_->getVector(0, X.getNumVectors(),
true);
244 RCP<MultiVector> r1_thyra = rangeMapExtractor_->getVector(0, B.getNumVectors(),
true);
246 for(
size_t k=0; k < r1->getNumVectors(); k++) {
249 for(
size_t i=0; i < r1->getLocalLength(); i++) {
250 thyraVecData[i] = xpetraVecData[i];
254 velPredictSmoo_->Apply(*xtilde1_thyra,*r1_thyra);
256 for(
size_t k=0; k < xtilde1_thyra->getNumVectors(); k++) {
259 for(
size_t i=0; i < xtilde1_thyra->getLocalLength(); i++) {
260 xpetraVecData[i] = thyraVecData[i];
264 velPredictSmoo_->Apply(*xtilde1,*r1);
269 RCP<MultiVector> schurCompRHS = MultiVectorFactory::Build(Z_->getRowMap(),B.getNumVectors());
270 D_->apply(*xtilde1,*schurCompRHS);
271 schurCompRHS->update(one,*r2,-one);
275 RCP<MultiVector> xtilde2 = MultiVectorFactory::Build(Z_->getRowMap(),X.getNumVectors(),
true);
279 if(bZThyraSpecialTreatment ==
true) {
280 RCP<MultiVector> xtilde2_thyra = domainMapExtractor_->getVector(1, X.getNumVectors(),
true);
281 RCP<MultiVector> schurCompRHS_thyra = rangeMapExtractor_->getVector(1, B.getNumVectors(),
true);
283 for(
size_t k=0; k < schurCompRHS->getNumVectors(); k++) {
286 for(
size_t i=0; i < schurCompRHS->getLocalLength(); i++) {
287 thyraVecData[i] = xpetraVecData[i];
291 schurCompSmoo_->Apply(*xtilde2_thyra,*schurCompRHS_thyra);
293 for(
size_t k=0; k < xtilde2_thyra->getNumVectors(); k++) {
296 for(
size_t i=0; i < xtilde2_thyra->getLocalLength(); i++) {
297 xpetraVecData[i] = thyraVecData[i];
301 schurCompSmoo_->Apply(*xtilde2,*schurCompRHS);
310 x1->update(omega,*xtilde1,one);
311 x2->update(omega,*xtilde2,one);
314 domainMapExtractor_->InsertVector(x1, 0, rcpX);
315 domainMapExtractor_->InsertVector(x2, 1, rcpX);
319 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
325 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
327 std::ostringstream out;
329 out <<
"{type = " << type_ <<
"}";
333 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
338 out0 <<
"Prec. type: " << type_ << std::endl;
341 if (verbLevel &
Debug) {
Important warning messages (one line)
std::string description() const
Return a simple one-line description of this object.
Exception indicating invalid cast attempted.
void Setup(Level ¤tLevel)
Setup routine.
bool IsSetup() const
Get the state of a smoother prototype.
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
Timer to be used in factories. Similar to Monitor but with additional timers.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Print additional debugging information.
void DeclareInput(Level ¤tLevel) const
Input.
Namespace for MueLu classes and methods.
UzawaSmoother()
Constructor.
void SetVelocityPredictionFactoryManager(RCP< FactoryManager > FactManager)
RCP< const ParameterList > GetValidParameterList() const
Input.
virtual const RCP< const FactoryBase > GetFactory(const std::string &varName) const =0
Get.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Class that holds all level-specific information.
Block triangle Uzawa smoother for 2x2 block matrices.
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
virtual const Teuchos::ParameterList & GetParameterList() const
RCP< SmootherPrototype > Copy() const
void SetSchurCompFactoryManager(RCP< FactoryManager > FactManager)
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
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 Apply(MultiVector &X, MultiVector const &B, bool InitialGuessIsZero=false) const
Apply the Braess Sarazin smoother.
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.
std::string toString(const T &t)