MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_PermutingSmoother_def.hpp
Go to the documentation of this file.
1// @HEADER
2//
3// ***********************************************************************
4//
5// MueLu: A package for multigrid based preconditioning
6// Copyright 2012 Sandia Corporation
7//
8// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9// the U.S. Government retains certain rights in this software.
10//
11// Redistribution and use in source and binary forms, with or without
12// modification, are permitted provided that the following conditions are
13// met:
14//
15// 1. Redistributions of source code must retain the above copyright
16// notice, this list of conditions and the following disclaimer.
17//
18// 2. Redistributions in binary form must reproduce the above copyright
19// notice, this list of conditions and the following disclaimer in the
20// documentation and/or other materials provided with the distribution.
21//
22// 3. Neither the name of the Corporation nor the names of the
23// contributors may be used to endorse or promote products derived from
24// this software without specific prior written permission.
25//
26// THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27// EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28// IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29// PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30// CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31// EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32// PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33// PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34// LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35// NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36// SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37//
38// Questions? Contact
39// Jonathan Hu (jhu@sandia.gov)
40// Andrey Prokopenko (aprokop@sandia.gov)
41// Ray Tuminaro (rstumin@sandia.gov)
42//
43// ***********************************************************************
44//
45// @HEADER
46/*
47 * MueLu_PermutingSmoother_def.hpp
48 *
49 * Created on: Nov 28, 2012
50 * Author: wiesner
51 */
52
53#ifndef MUELU_PERMUTINGSMOOTHER_DEF_HPP
54#define MUELU_PERMUTINGSMOOTHER_DEF_HPP
55
56#include <Xpetra_Matrix.hpp>
57#include <Xpetra_MultiVector.hpp>
58#include <Xpetra_MultiVectorFactory.hpp>
59#include <Xpetra_Vector.hpp>
60#include <Xpetra_VectorFactory.hpp>
61
62#include "MueLu_ConfigDefs.hpp"
63
65#include "MueLu_Level.hpp"
66#include "MueLu_TrilinosSmoother.hpp"
68#include "MueLu_PermutationFactory.hpp"
69#include "MueLu_Monitor.hpp"
70
71namespace MueLu {
72
73 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
74 PermutingSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::PermutingSmoother(const std::string& mapName, const RCP<const FactoryBase>& mapFact, const std::string& type, const Teuchos::ParameterList& paramList, const LO& overlap, RCP<FactoryBase> permFact)
75 : type_(type), overlap_(overlap), permQT_(Teuchos::null), permP_(Teuchos::null), diagScalingOp_(Teuchos::null)
76 {
77 this->SetParameterList(paramList);
78
79 permFact_ = permFact;
80 if (permFact_ == Teuchos::null) {
81 RCP<PermutationFactory> newPermFact = Teuchos::rcp(new PermutationFactory());
82 newPermFact->SetParameter("PermutationRowMapName", Teuchos::ParameterEntry(mapName));
83 newPermFact->SetFactory ("PermutationRowMapFactory", mapFact);
84 permFact_ = newPermFact;
85 }
86
87 // create internal smoother
88 if (type_ == "ILU") {
89#if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_IFPACK)
91#else
92 TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::PermutingSmoother requires Epetra and Ifpack.");
93#endif
94 } else {
95 s_ = Teuchos::rcp(new TrilinosSmoother(type_, this->GetParameterList(), overlap_));
96 }
97 TEUCHOS_TEST_FOR_EXCEPTION(s_ == Teuchos::null, Exceptions::RuntimeError, "");
98
99 // Use permuted matrix A
100 s_->SetFactory("A", permFact_);
101 }
102
103 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
105
106 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
108 currentLevel.DeclareInput("permP", permFact_.get());
109 currentLevel.DeclareInput("permQT", permFact_.get());
110 currentLevel.DeclareInput("permScaling", permFact_.get());
111
112 s_->DeclareInput(currentLevel);
113 }
114
115 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
117 FactoryMonitor monitor(*this, "Permuting Smoother", currentLevel);
118
119 if (SmootherPrototype::IsSetup() == true)
120 this->GetOStream(Warnings0) << "MueLu::PermutingSmoother::Setup(): Setup() has already been called" << std::endl;
121
122 // extract information from level class
123 permP_ = currentLevel.Get< RCP<Matrix> > ("permP", permFact_.get());
124 permQT_ = currentLevel.Get< RCP<Matrix> > ("permQT", permFact_.get());
125 diagScalingOp_ = currentLevel.Get< RCP<Matrix> > ("permScaling", permFact_.get());
126
127 s_->Setup(currentLevel);
128
130 }
131
132 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
133 void PermutingSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Apply(MultiVector& X, const MultiVector& B, bool InitialGuessIsZero) const {
134 TEUCHOS_TEST_FOR_EXCEPTION(SmootherPrototype::IsSetup() == false, Exceptions::RuntimeError, "MueLu::PermutingSmoother::Apply(): Setup() has not been called");
135
136 typedef Teuchos::ScalarTraits<Scalar> STS;
137
138 Teuchos::RCP<MultiVector> Xtemp = MultiVectorFactory::Build(X.getMap(), 1, true);
139 Xtemp->update(STS::one(), X, STS::zero());
140
141 // TODO: unify scaling and left permutation operator
142 Teuchos::RCP<MultiVector> Btemp = MultiVectorFactory::Build(B.getMap(), 1, true);
143 Teuchos::RCP<MultiVector> Btemp2 = MultiVectorFactory::Build(B.getMap(), 1, true);
144 permP_->apply(B, *Btemp, Teuchos::NO_TRANS); // apply permutation operator to rhs
145 diagScalingOp_->apply(*Btemp, *Btemp2, Teuchos::NO_TRANS); // apply scaling operator to rhs
146
147 // apply smoother to permuted linear system
148 s_->Apply(*Xtemp, *Btemp2, InitialGuessIsZero);
149
150 // retransform smooth solution
151 permQT_->apply(*Xtemp, X, Teuchos::NO_TRANS);
152 }
153
154 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
155 RCP<MueLu::SmootherPrototype<Scalar, LocalOrdinal, GlobalOrdinal, Node> >
159
160 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
162 std::ostringstream out;
164 return out.str();
165 }
166
167 template <class Scalar,class LocalOrdinal, class GlobalOrdinal, class Node>
168 void PermutingSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>::print(Teuchos::FancyOStream &out, const VerbLevel verbLevel) const {
170 out0 << ""; // avoid warning
171 }
172
173} // namespace MueLu
174
175
176#endif /* MUELU_PERMUTINGSMOOTHER_DEF_HPP */
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
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.
Timer to be used in factories. Similar to Monitor but with additional timers.
Class that holds all level-specific information.
void DeclareInput(const std::string &ename, const FactoryBase *factory, const FactoryBase *requestedBy=NoFactory::get())
Callback from FactoryBase::CallDeclareInput() and FactoryBase::DeclareInput().
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access)....
virtual void SetParameterList(const Teuchos::ParameterList &paramList)
Set parameters from a parameter list and return with default values.
virtual const Teuchos::ParameterList & GetParameterList() const
std::string description() const
Return a simple one-line description of this object.
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
RCP< FactoryBase > permFact_
Permutation Factory.
RCP< Matrix > permQT_
permQT matrix object
Teuchos::RCP< Matrix > diagScalingOp_
scaling matrix object
RCP< SmootherPrototype > Copy() const
void DeclareInput(Level &currentLevel) const
Input.
void Setup(Level &currentLevel)
Set up the direct solver.
LO overlap_
overlap when using the smoother in additive Schwarz mode
std::string type_
ifpack1/2-specific key phrase that denote smoother type
PermutingSmoother(std::string const &mapName, const RCP< const FactoryBase > &mapFact, std::string const &type="", const Teuchos::ParameterList &paramList=Teuchos::ParameterList(), LO const &overlap=0, RCP< FactoryBase > permFact=Teuchos::null)
Constructor.
RCP< SmootherPrototype > s_
Smoother.
MueLu::PermutationFactory< Scalar, LocalOrdinal, GlobalOrdinal, Node > PermutationFactory
RCP< Matrix > permP_
permP matrix object
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.
bool IsSetup() const
Get the state of a smoother prototype.
Class that encapsulates external library smoothers.
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).
RCP< MueLu::SmootherPrototype< Scalar, LocalOrdinal, GlobalOrdinal, Node > > GetIfpackSmoother(const std::string &="", const Teuchos::ParameterList &=Teuchos::ParameterList(), const LocalOrdinal &=0)