48 #if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_IFPACK)
50 #include <Ifpack_Chebyshev.h>
51 #include "Xpetra_MultiVectorFactory.hpp"
56 #include "MueLu_Utilities.hpp"
63 : type_(type), overlap_(overlap)
76 prec_->SetParameters(
const_cast<ParameterList&
>(this->GetParameterList()));
82 ParameterList& paramList =
const_cast<ParameterList&
>(this->GetParameterList());
83 paramList.setParameters(list);
85 RCP<ParameterList> precList = this->RemoveFactoriesFromList(this->GetParameterList());
87 prec_->SetParameters(*precList);
113 template <
class Node>
115 this->Input(currentLevel,
"A");
117 if (type_ ==
"LINESMOOTHING_BANDED_RELAXATION" ||
118 type_ ==
"LINESMOOTHING_BANDED RELAXATION" ||
119 type_ ==
"LINESMOOTHING_BANDEDRELAXATION" ||
120 type_ ==
"LINESMOOTHING_BLOCK_RELAXATION" ||
121 type_ ==
"LINESMOOTHING_BLOCK RELAXATION" ||
122 type_ ==
"LINESMOOTHING_BLOCKRELAXATION") {
123 this->Input(currentLevel,
"CoarseNumZLayers");
124 this->Input(currentLevel,
"LineDetection_VertLineIds");
128 template <
class Node>
132 this->GetOStream(
Warnings0) <<
"MueLu::IfpackSmoother::Setup(): Setup() has already been called" << std::endl;
134 A_ = Factory::Get< RCP<Matrix> >(currentLevel,
"A");
136 double lambdaMax = -1.0;
137 if (type_ ==
"Chebyshev") {
138 std::string maxEigString =
"chebyshev: max eigenvalue";
139 std::string eigRatioString =
"chebyshev: ratio eigenvalue";
142 lambdaMax = Teuchos::getValue<Scalar>(this->GetParameter(maxEigString));
143 this->GetOStream(
Statistics1) << maxEigString <<
" (cached with smoother parameter list) = " << lambdaMax << std::endl;
145 }
catch (Teuchos::Exceptions::InvalidParameterName&) {
146 lambdaMax = A_->GetMaxEigenvalueEstimate();
148 if (lambdaMax != -1.0) {
149 this->GetOStream(
Statistics1) << maxEigString <<
" (cached with matrix) = " << lambdaMax << std::endl;
150 this->SetParameter(maxEigString, ParameterEntry(lambdaMax));
155 const Scalar defaultEigRatio = 20;
157 Scalar ratio = defaultEigRatio;
159 ratio = Teuchos::getValue<Scalar>(this->GetParameter(eigRatioString));
161 }
catch (Teuchos::Exceptions::InvalidParameterName&) {
162 this->SetParameter(eigRatioString, ParameterEntry(ratio));
170 RCP<const Matrix> fineA = currentLevel.
GetPreviousLevel()->Get<RCP<Matrix> >(
"A");
171 size_t nRowsFine = fineA->getGlobalNumRows();
172 size_t nRowsCoarse = A_->getGlobalNumRows();
174 ratio = std::max(ratio, as<Scalar>(nRowsFine)/nRowsCoarse);
176 this->GetOStream(
Statistics1) << eigRatioString <<
" (computed) = " << ratio << std::endl;
177 this->SetParameter(eigRatioString, ParameterEntry(ratio));
181 if (type_ ==
"LINESMOOTHING_BANDED_RELAXATION" ||
182 type_ ==
"LINESMOOTHING_BANDED RELAXATION" ||
183 type_ ==
"LINESMOOTHING_BANDEDRELAXATION" ||
184 type_ ==
"LINESMOOTHING_BLOCK_RELAXATION" ||
185 type_ ==
"LINESMOOTHING_BLOCK RELAXATION" ||
186 type_ ==
"LINESMOOTHING_BLOCKRELAXATION" ) {
187 ParameterList& myparamList =
const_cast<ParameterList&
>(this->GetParameterList());
189 LO CoarseNumZLayers = currentLevel.
Get<LO>(
"CoarseNumZLayers",
Factory::GetFactory(
"CoarseNumZLayers").get());
190 if (CoarseNumZLayers > 0) {
191 Teuchos::ArrayRCP<LO> TVertLineIdSmoo = currentLevel.
Get< Teuchos::ArrayRCP<LO> >(
"LineDetection_VertLineIds",
Factory::GetFactory(
"LineDetection_VertLineIds").get());
195 for(
size_t k = 0; k < Teuchos::as<size_t>(TVertLineIdSmoo.size()); k++) {
196 if(maxPart < TVertLineIdSmoo[k]) maxPart = TVertLineIdSmoo[k];
199 size_t numLocalRows = A_->getNodeNumRows();
200 TEUCHOS_TEST_FOR_EXCEPTION(numLocalRows % TVertLineIdSmoo.size() != 0,
Exceptions::RuntimeError,
"MueLu::Ifpack2Smoother::Setup(): the number of local nodes is incompatible with the TVertLineIdsSmoo.");
202 if (numLocalRows == Teuchos::as<size_t>(TVertLineIdSmoo.size())) {
203 myparamList.set(
"partitioner: type",
"user");
204 myparamList.set(
"partitioner: map",&(TVertLineIdSmoo[0]));
205 myparamList.set(
"partitioner: local parts",maxPart+1);
208 size_t numDofsPerNode = numLocalRows / TVertLineIdSmoo.size();
211 Teuchos::ArrayRCP<LO> partitionerMap(numLocalRows, Teuchos::OrdinalTraits<LocalOrdinal>::invalid());
212 for (
size_t blockRow = 0; blockRow < Teuchos::as<size_t>(TVertLineIdSmoo.size()); ++blockRow)
213 for (
size_t dof = 0; dof < numDofsPerNode; dof++)
214 partitionerMap[blockRow * numDofsPerNode + dof] = TVertLineIdSmoo[blockRow];
215 myparamList.set(
"partitioner: type",
"user");
216 myparamList.set(
"partitioner: map",&(partitionerMap[0]));
217 myparamList.set(
"partitioner: local parts",maxPart + 1);
220 if (type_ ==
"LINESMOOTHING_BANDED_RELAXATION" ||
221 type_ ==
"LINESMOOTHING_BANDED RELAXATION" ||
222 type_ ==
"LINESMOOTHING_BANDEDRELAXATION")
223 type_ =
"block relaxation";
225 type_ =
"block relaxation";
228 this->GetOStream(
Runtime0) <<
"Line detection failed: fall back to point-wise relaxation" << std::endl;
229 myparamList.remove(
"partitioner: type",
false);
230 myparamList.remove(
"partitioner: map",
false);
231 myparamList.remove(
"partitioner: local parts",
false);
232 type_ =
"point relaxation stand-alone";
238 ParameterList precList = this->GetParameterList();
239 if(precList.isParameter(
"partitioner: type") && precList.get<std::string>(
"partitioner: type") ==
"linear" &&
240 !precList.isParameter(
"partitioner: local parts")) {
241 precList.set(
"partitioner: local parts", (
int)A_->getNodeNumRows() / A_->GetFixedBlockSize());
248 prec_ = rcp(factory.
Create(type_, &(*epA), overlap_));
249 TEUCHOS_TEST_FOR_EXCEPTION(prec_.is_null(),
Exceptions::RuntimeError,
"Could not create an Ifpack preconditioner with type = \"" << type_ <<
"\"");
255 if (type_ ==
"Chebyshev" && lambdaMax == -1.0) {
256 Teuchos::RCP<Ifpack_Chebyshev> chebyPrec = rcp_dynamic_cast<Ifpack_Chebyshev>(prec_);
257 if (chebyPrec != Teuchos::null) {
258 lambdaMax = chebyPrec->GetLambdaMax();
259 A_->SetMaxEigenvalueEstimate(lambdaMax);
260 this->GetOStream(
Statistics1) <<
"chebyshev: max eigenvalue (calculated by Ifpack)" <<
" = " << lambdaMax << std::endl;
262 TEUCHOS_TEST_FOR_EXCEPTION(lambdaMax == -1.0,
Exceptions::RuntimeError,
"MueLu::IfpackSmoother::Setup(): no maximum eigenvalue estimate");
265 this->GetOStream(
Statistics1) << description() << std::endl;
268 template <
class Node>
273 Teuchos::ParameterList paramList;
274 bool supportInitialGuess =
false;
275 if (type_ ==
"Chebyshev") {
276 paramList.set(
"chebyshev: zero starting solution", InitialGuessIsZero);
277 supportInitialGuess =
true;
279 }
else if (type_ ==
"point relaxation stand-alone") {
280 paramList.set(
"relaxation: zero starting solution", InitialGuessIsZero);
281 supportInitialGuess =
true;
284 SetPrecParameters(paramList);
287 if (InitialGuessIsZero || supportInitialGuess) {
291 prec_->ApplyInverse(epB, epX);
295 RCP<MultiVector> Correction = MultiVectorFactory::Build(A_->getDomainMap(), X.getNumVectors());
300 prec_->ApplyInverse(epB, epX);
302 X.update(1.0, *Correction, 1.0);
306 template <
class Node>
309 smoother->SetParameterList(this->GetParameterList());
310 return Teuchos::rcp_dynamic_cast<MueLu::SmootherPrototype<double, int, int, Node> >(smoother);
313 template <
class Node>
315 std::ostringstream out;
318 if (prec_ == Teuchos::null || this->GetVerbLevel() ==
Test) {
320 out <<
"{type = " << type_ <<
"}";
322 out << prec_->Label();
327 template <
class Node>
332 out0 <<
"Prec. type: " << type_ << std::endl;
335 out0 <<
"Parameter list: " << std::endl;
336 Teuchos::OSTab tab2(out);
337 out << this->GetParameterList();
338 out0 <<
"Overlap: " << overlap_ << std::endl;
342 if (prec_ != Teuchos::null) {
343 Teuchos::OSTab tab2(out);
344 out << *prec_ << std::endl;
347 if (verbLevel &
Debug) {
350 <<
"RCP<A_>: " << A_ << std::endl
351 <<
"RCP<prec_>: " << prec_ << std::endl;
355 template <
class Node>
358 return Teuchos::OrdinalTraits<size_t>::invalid();
367 #if defined(HAVE_MUELU_EPETRA)
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
Ifpack_Preconditioner * Create(const std::string PrecType, Epetra_RowMatrix *Matrix, const int overlap=0, bool overrideSerialDefault=false)
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.
const RCP< const FactoryBase > GetFactory(const std::string &varName) const
Default implementation of FactoryAcceptor::GetFactory()
Class that encapsulates Ifpack smoothers.
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
Apply the preconditioner.
void SetPrecParameters(const Teuchos::ParameterList &list=Teuchos::ParameterList()) const
IfpackSmoother(std::string const &type, Teuchos::ParameterList const ¶mList=Teuchos::ParameterList(), LO const &overlap=0)
Constructor.
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.
void Setup(Level ¤tLevel)
Set up the smoother.
RCP< SmootherPrototype > Copy() const
void DeclareInput(Level ¤tLevel) const
Input.
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
void SetParameterList(const Teuchos::ParameterList ¶mList)
Set parameters from a parameter list and return with default values.
Class that holds all level-specific information.
int GetLevelID() const
Return level number.
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access)....
RCP< Level > & GetPreviousLevel()
Previous level.
virtual void SetParameterList(const Teuchos::ParameterList ¶mList)
Set parameters from a parameter list and return with default values.
void declareConstructionOutcome(bool fail, std::string msg)
bool IsSetup() const
Get the state of a smoother prototype.
static RCP< Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Residual(const Xpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &X, const Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > &RHS)
static RCP< Epetra_MultiVector > MV2NonConstEpetraMV(RCP< Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > vec)
static RCP< Epetra_CrsMatrix > Op2NonConstEpetraCrs(RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node > > Op)
static RCP< const Epetra_MultiVector > MV2EpetraMV(RCP< Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node > > const vec)
Helper utility to pull out the underlying Epetra objects from an Xpetra object.
Namespace for MueLu classes and methods.
@ Warnings0
Important warning messages (one line)
@ Debug
Print additional debugging information.
@ Statistics1
Print more statistics.
@ External
Print external lib objects.
@ Runtime0
One-liner description of what is happening.
@ Parameters0
Print class parameters.
@ Parameters1
Print class parameters (more parameters, more verbose)
std::string toString(const T &what)
Little helper function to convert non-string types to strings.