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"
58 #include "MueLu_Aggregates.hpp"
77 prec_->SetParameters(const_cast<ParameterList&>(this->GetParameterList()));
88 prec_->SetParameters(*precList);
114 template <
class Node>
116 this->Input(currentLevel,
"A");
118 if (type_ ==
"LINESMOOTHING_BANDED_RELAXATION" ||
119 type_ ==
"LINESMOOTHING_BANDED RELAXATION" ||
120 type_ ==
"LINESMOOTHING_BANDEDRELAXATION" ||
121 type_ ==
"LINESMOOTHING_BLOCK_RELAXATION" ||
122 type_ ==
"LINESMOOTHING_BLOCK RELAXATION" ||
123 type_ ==
"LINESMOOTHING_BLOCKRELAXATION") {
124 this->Input(currentLevel,
"CoarseNumZLayers");
125 this->Input(currentLevel,
"LineDetection_VertLineIds");
127 else if (type_ ==
"AGGREGATE") {
129 this->Input(currentLevel,
"Aggregates");
133 template <
class Node>
137 this->GetOStream(
Warnings0) <<
"MueLu::IfpackSmoother::Setup(): Setup() has already been called" << std::endl;
139 A_ = Factory::Get<RCP<Matrix> >(currentLevel,
"A");
141 double lambdaMax = -1.0;
142 if (type_ ==
"Chebyshev") {
143 std::string maxEigString =
"chebyshev: max eigenvalue";
144 std::string eigRatioString =
"chebyshev: ratio eigenvalue";
147 lambdaMax = Teuchos::getValue<Scalar>(this->GetParameter(maxEigString));
148 this->GetOStream(
Statistics1) << maxEigString <<
" (cached with smoother parameter list) = " << lambdaMax << std::endl;
151 lambdaMax = A_->GetMaxEigenvalueEstimate();
153 if (lambdaMax != -1.0) {
154 this->GetOStream(
Statistics1) << maxEigString <<
" (cached with matrix) = " << lambdaMax << std::endl;
160 const Scalar defaultEigRatio = 20;
162 Scalar ratio = defaultEigRatio;
164 ratio = Teuchos::getValue<Scalar>(this->GetParameter(eigRatioString));
170 if (currentLevel.GetLevelID()) {
176 size_t nRowsFine = fineA->getGlobalNumRows();
177 size_t nRowsCoarse = A_->getGlobalNumRows();
179 ratio = std::max(ratio, as<Scalar>(nRowsFine) / nRowsCoarse);
181 this->GetOStream(
Statistics1) << eigRatioString <<
" (computed) = " << ratio << std::endl;
186 if (type_ ==
"LINESMOOTHING_BANDED_RELAXATION" ||
187 type_ ==
"LINESMOOTHING_BANDED RELAXATION" ||
188 type_ ==
"LINESMOOTHING_BANDEDRELAXATION" ||
189 type_ ==
"LINESMOOTHING_BLOCK_RELAXATION" ||
190 type_ ==
"LINESMOOTHING_BLOCK RELAXATION" ||
191 type_ ==
"LINESMOOTHING_BLOCKRELAXATION") {
195 if (CoarseNumZLayers > 0) {
200 for (
size_t k = 0; k < Teuchos::as<size_t>(TVertLineIdSmoo.
size()); k++) {
201 if (maxPart < TVertLineIdSmoo[k]) maxPart = TVertLineIdSmoo[k];
204 size_t numLocalRows = A_->getLocalNumRows();
207 if (numLocalRows == Teuchos::as<size_t>(TVertLineIdSmoo.
size())) {
208 myparamList.
set(
"partitioner: type",
"user");
209 myparamList.
set(
"partitioner: map", &(TVertLineIdSmoo[0]));
210 myparamList.
set(
"partitioner: local parts", maxPart + 1);
213 size_t numDofsPerNode = numLocalRows / TVertLineIdSmoo.
size();
217 for (
size_t blockRow = 0; blockRow < Teuchos::as<size_t>(TVertLineIdSmoo.
size()); ++blockRow)
218 for (
size_t dof = 0; dof < numDofsPerNode; dof++)
219 partitionerMap[blockRow * numDofsPerNode + dof] = TVertLineIdSmoo[blockRow];
220 myparamList.
set(
"partitioner: type",
"user");
221 myparamList.
set(
"partitioner: map", &(partitionerMap[0]));
222 myparamList.
set(
"partitioner: local parts", maxPart + 1);
225 if (type_ ==
"LINESMOOTHING_BANDED_RELAXATION" ||
226 type_ ==
"LINESMOOTHING_BANDED RELAXATION" ||
227 type_ ==
"LINESMOOTHING_BANDEDRELAXATION")
228 type_ =
"block relaxation";
230 type_ =
"block relaxation";
233 this->GetOStream(
Runtime0) <<
"Line detection failed: fall back to point-wise relaxation" << std::endl;
234 myparamList.
remove(
"partitioner: type",
false);
235 myparamList.
remove(
"partitioner: map",
false);
236 myparamList.
remove(
"partitioner: local parts",
false);
237 type_ =
"point relaxation stand-alone";
242 if (type_ ==
"AGGREGATE") {
243 SetupAggregate(currentLevel);
249 if (precList.
isParameter(
"partitioner: type") && precList.
get<std::string>(
"partitioner: type") ==
"linear" &&
250 !precList.
isParameter(
"partitioner: local parts")) {
251 precList.
set(
"partitioner: local parts", (
int)A_->getLocalNumRows() / A_->GetFixedBlockSize());
257 prec_ =
rcp(factory.
Create(type_, &(*epA), overlap_));
265 if (type_ ==
"Chebyshev" && lambdaMax == -1.0) {
267 if (chebyPrec != Teuchos::null) {
269 A_->SetMaxEigenvalueEstimate(lambdaMax);
270 this->GetOStream(
Statistics1) <<
"chebyshev: max eigenvalue (calculated by Ifpack)"
271 <<
" = " << lambdaMax << std::endl;
276 this->GetOStream(
Statistics1) << description() << std::endl;
279 template <
class Node>
283 if (this->IsSetup() ==
true) {
284 this->GetOStream(
Warnings0) <<
"MueLu::Ifpack2moother::SetupAggregate(): Setup() has already been called" << std::endl;
285 this->GetOStream(
Warnings0) <<
"MueLu::IfpackSmoother::SetupAggregate(): reuse of this type is not available, reverting to full construction" << std::endl;
288 this->GetOStream(
Statistics0) <<
"IfpackSmoother: Using Aggregate Smoothing" << std::endl;
290 RCP<Aggregates> aggregates = Factory::Get<RCP<Aggregates> >(currentLevel,
"Aggregates");
292 ArrayRCP<LO> aggregate_ids = rcp_const_cast<LOMultiVector>(vertex2AggId)->getDataNonConst(0);
296 if (A_->GetFixedBlockSize() > 1) {
301 LO blocksize = (
LO)A_->GetFixedBlockSize();
302 dof_ids.
resize(aggregate_ids.
size() * blocksize);
303 for (
LO i = 0; i < (
LO)aggregate_ids.
size(); i++) {
304 for (
LO j = 0; j < (
LO)blocksize; j++)
305 dof_ids[i * blocksize + j] = aggregate_ids[i];
308 dof_ids = aggregate_ids;
312 paramList.
set(
"partitioner: type",
"user");
313 paramList.
set(
"partitioner: overlap", 0);
316 paramList.
set(
"partitioner: keep singletons",
true);
319 type_ =
"block relaxation stand-alone";
322 prec_ =
rcp(factory.
Create(type_, &(*A), overlap_));
326 int rv = prec_->Compute();
330 template <
class Node>
336 bool supportInitialGuess =
false;
337 if (type_ ==
"Chebyshev") {
338 paramList.
set(
"chebyshev: zero starting solution", InitialGuessIsZero);
339 supportInitialGuess =
true;
341 }
else if (type_ ==
"point relaxation stand-alone") {
342 paramList.
set(
"relaxation: zero starting solution", InitialGuessIsZero);
343 supportInitialGuess =
true;
346 SetPrecParameters(paramList);
349 if (InitialGuessIsZero || supportInitialGuess) {
353 prec_->ApplyInverse(epB, epX);
357 RCP<MultiVector> Correction = MultiVectorFactory::Build(A_->getDomainMap(), X.getNumVectors());
362 prec_->ApplyInverse(epB, epX);
364 X.update(1.0, *Correction, 1.0);
368 template <
class Node>
371 smoother->SetParameterList(this->GetParameterList());
375 template <
class Node>
377 std::ostringstream out;
380 if (prec_ == Teuchos::null || this->GetVerbLevel() ==
InterfaceTest) {
382 out <<
"{type = " << type_ <<
"}";
384 out << prec_->Label();
389 template <
class Node>
394 out0 <<
"Prec. type: " << type_ << std::endl;
397 out0 <<
"Parameter list: " << std::endl;
399 out << this->GetParameterList();
400 out0 <<
"Overlap: " << overlap_ << std::endl;
404 if (prec_ != Teuchos::null) {
406 out << *prec_ << std::endl;
409 if (verbLevel &
Debug) {
412 <<
"RCP<A_>: " << A_ << std::endl
413 <<
"RCP<prec_>: " << prec_ << std::endl;
417 template <
class Node>
428 #if defined(HAVE_MUELU_EPETRA)
void Setup(Level ¤tLevel)
Set up the smoother.
Important warning messages (one line)
RCP< SmootherPrototype > Copy() const
void SetPrecParameters(const Teuchos::ParameterList &list=Teuchos::ParameterList()) const
KOKKOS_INLINE_FUNCTION LO GetNumAggregates() const
Print external lib objects.
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)
static RCP< Epetra_CrsMatrix > Op2NonConstEpetraCrs(RCP< Xpetra::Matrix< Scalar, LocalOrdinal, GlobalOrdinal, Node >> Op)
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.
One-liner description of what is happening.
Ifpack_Preconditioner * Create(const std::string PrecType, Epetra_RowMatrix *Matrix, const int overlap=0, bool overrideSerialDefault=false)
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.
void resize(const size_type n, const T &val=T())
bool isParameter(const std::string &name) const
Print statistics that do not involve significant additional computation.
bool remove(std::string const &name, bool throwIfNotExists=true)
static RCP< MultiVector > Residual(const Xpetra::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > &Op, const MultiVector &X, const MultiVector &RHS)
virtual void SetParameterList(const Teuchos::ParameterList ¶mList)
Set parameters from a parameter list and return with default values.
void DeclareInput(Level ¤tLevel) const
Input.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
static RCP< Epetra_MultiVector > MV2NonConstEpetraMV(RCP< Xpetra::MultiVector< Scalar, LocalOrdinal, GlobalOrdinal, Node >> vec)
void declareConstructionOutcome(bool fail, std::string msg)
Class that holds all level-specific information.
bool IsSetup() const
Get the state of a smoother prototype.
size_t getNodeSmootherComplexity() const
Get a rough estimate of cost per iteration.
const RCP< LOMultiVector > & GetVertex2AggId() const
Returns constant vector that maps local node IDs to local aggregates IDs.
virtual double GetLambdaMax()
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
ParameterList & setParameters(const ParameterList &source)
void SetParameterList(const Teuchos::ParameterList ¶mList)
Set parameters from a parameter list and return with default values.
std::string description() const
Return a simple one-line description of this object.
void SetupAggregate(Level ¤tLevel)
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.
virtual const RCP< const FactoryBase > GetFactory(const std::string &varName) const =0
Print class parameters (more parameters, more verbose)
Exception throws to report errors in the internal logical of the program.
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
Apply the preconditioner.
virtual std::string description() const
Return a simple one-line description of this object.
Class that encapsulates Ifpack smoothers.
std::string toString(const T &t)