12 #if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_IFPACK)
14 #include <Ifpack_Chebyshev.h>
15 #include "Xpetra_MultiVectorFactory.hpp"
20 #include "MueLu_Utilities.hpp"
22 #include "MueLu_Aggregates.hpp"
41 prec_->SetParameters(const_cast<ParameterList&>(this->GetParameterList()));
52 prec_->SetParameters(*precList);
80 this->Input(currentLevel,
"A");
82 if (type_ ==
"LINESMOOTHING_BANDED_RELAXATION" ||
83 type_ ==
"LINESMOOTHING_BANDED RELAXATION" ||
84 type_ ==
"LINESMOOTHING_BANDEDRELAXATION" ||
85 type_ ==
"LINESMOOTHING_BLOCK_RELAXATION" ||
86 type_ ==
"LINESMOOTHING_BLOCK RELAXATION" ||
87 type_ ==
"LINESMOOTHING_BLOCKRELAXATION") {
88 this->Input(currentLevel,
"CoarseNumZLayers");
89 this->Input(currentLevel,
"LineDetection_VertLineIds");
91 else if (type_ ==
"AGGREGATE") {
93 this->Input(currentLevel,
"Aggregates");
101 this->GetOStream(
Warnings0) <<
"MueLu::IfpackSmoother::Setup(): Setup() has already been called" << std::endl;
103 A_ = Factory::Get<RCP<Matrix> >(currentLevel,
"A");
105 double lambdaMax = -1.0;
106 if (type_ ==
"Chebyshev") {
107 std::string maxEigString =
"chebyshev: max eigenvalue";
108 std::string eigRatioString =
"chebyshev: ratio eigenvalue";
111 lambdaMax = Teuchos::getValue<Scalar>(this->GetParameter(maxEigString));
112 this->GetOStream(
Statistics1) << maxEigString <<
" (cached with smoother parameter list) = " << lambdaMax << std::endl;
115 lambdaMax = A_->GetMaxEigenvalueEstimate();
117 if (lambdaMax != -1.0) {
118 this->GetOStream(
Statistics1) << maxEigString <<
" (cached with matrix) = " << lambdaMax << std::endl;
124 const Scalar defaultEigRatio = 20;
126 Scalar ratio = defaultEigRatio;
128 ratio = Teuchos::getValue<Scalar>(this->GetParameter(eigRatioString));
134 if (currentLevel.GetLevelID()) {
140 size_t nRowsFine = fineA->getGlobalNumRows();
141 size_t nRowsCoarse = A_->getGlobalNumRows();
143 ratio = std::max(ratio, as<Scalar>(nRowsFine) / nRowsCoarse);
145 this->GetOStream(
Statistics1) << eigRatioString <<
" (computed) = " << ratio << std::endl;
150 if (type_ ==
"LINESMOOTHING_BANDED_RELAXATION" ||
151 type_ ==
"LINESMOOTHING_BANDED RELAXATION" ||
152 type_ ==
"LINESMOOTHING_BANDEDRELAXATION" ||
153 type_ ==
"LINESMOOTHING_BLOCK_RELAXATION" ||
154 type_ ==
"LINESMOOTHING_BLOCK RELAXATION" ||
155 type_ ==
"LINESMOOTHING_BLOCKRELAXATION") {
159 if (CoarseNumZLayers > 0) {
164 for (
size_t k = 0; k < Teuchos::as<size_t>(TVertLineIdSmoo.
size()); k++) {
165 if (maxPart < TVertLineIdSmoo[k]) maxPart = TVertLineIdSmoo[k];
168 size_t numLocalRows = A_->getLocalNumRows();
171 if (numLocalRows == Teuchos::as<size_t>(TVertLineIdSmoo.
size())) {
172 myparamList.
set(
"partitioner: type",
"user");
173 myparamList.
set(
"partitioner: map", &(TVertLineIdSmoo[0]));
174 myparamList.
set(
"partitioner: local parts", maxPart + 1);
177 size_t numDofsPerNode = numLocalRows / TVertLineIdSmoo.
size();
181 for (
size_t blockRow = 0; blockRow < Teuchos::as<size_t>(TVertLineIdSmoo.
size()); ++blockRow)
182 for (
size_t dof = 0; dof < numDofsPerNode; dof++)
183 partitionerMap[blockRow * numDofsPerNode + dof] = TVertLineIdSmoo[blockRow];
184 myparamList.
set(
"partitioner: type",
"user");
185 myparamList.
set(
"partitioner: map", &(partitionerMap[0]));
186 myparamList.
set(
"partitioner: local parts", maxPart + 1);
189 if (type_ ==
"LINESMOOTHING_BANDED_RELAXATION" ||
190 type_ ==
"LINESMOOTHING_BANDED RELAXATION" ||
191 type_ ==
"LINESMOOTHING_BANDEDRELAXATION")
192 type_ =
"block relaxation";
194 type_ =
"block relaxation";
197 this->GetOStream(
Runtime0) <<
"Line detection failed: fall back to point-wise relaxation" << std::endl;
198 myparamList.
remove(
"partitioner: type",
false);
199 myparamList.
remove(
"partitioner: map",
false);
200 myparamList.
remove(
"partitioner: local parts",
false);
201 type_ =
"point relaxation stand-alone";
206 if (type_ ==
"AGGREGATE") {
207 SetupAggregate(currentLevel);
213 if (precList.
isParameter(
"partitioner: type") && precList.
get<std::string>(
"partitioner: type") ==
"linear" &&
214 !precList.
isParameter(
"partitioner: local parts")) {
215 precList.
set(
"partitioner: local parts", (
int)A_->getLocalNumRows() / A_->GetFixedBlockSize());
221 prec_ =
rcp(factory.
Create(type_, &(*epA), overlap_));
229 if (type_ ==
"Chebyshev" && lambdaMax == -1.0) {
231 if (chebyPrec != Teuchos::null) {
233 A_->SetMaxEigenvalueEstimate(lambdaMax);
234 this->GetOStream(
Statistics1) <<
"chebyshev: max eigenvalue (calculated by Ifpack)"
235 <<
" = " << lambdaMax << std::endl;
240 this->GetOStream(
Statistics1) << description() << std::endl;
243 template <
class Node>
247 if (this->IsSetup() ==
true) {
248 this->GetOStream(
Warnings0) <<
"MueLu::Ifpack2moother::SetupAggregate(): Setup() has already been called" << std::endl;
249 this->GetOStream(
Warnings0) <<
"MueLu::IfpackSmoother::SetupAggregate(): reuse of this type is not available, reverting to full construction" << std::endl;
252 this->GetOStream(
Statistics0) <<
"IfpackSmoother: Using Aggregate Smoothing" << std::endl;
254 RCP<Aggregates> aggregates = Factory::Get<RCP<Aggregates> >(currentLevel,
"Aggregates");
256 ArrayRCP<LO> aggregate_ids = rcp_const_cast<LOMultiVector>(vertex2AggId)->getDataNonConst(0);
260 if (A_->GetFixedBlockSize() > 1) {
265 LO blocksize = (
LO)A_->GetFixedBlockSize();
266 dof_ids.
resize(aggregate_ids.
size() * blocksize);
267 for (
LO i = 0; i < (
LO)aggregate_ids.
size(); i++) {
268 for (
LO j = 0; j < (
LO)blocksize; j++)
269 dof_ids[i * blocksize + j] = aggregate_ids[i];
272 dof_ids = aggregate_ids;
276 paramList.
set(
"partitioner: type",
"user");
277 paramList.
set(
"partitioner: overlap", 0);
280 paramList.
set(
"partitioner: keep singletons",
true);
283 type_ =
"block relaxation stand-alone";
286 prec_ =
rcp(factory.
Create(type_, &(*A), overlap_));
290 int rv = prec_->Compute();
294 template <
class Node>
300 bool supportInitialGuess =
false;
301 if (type_ ==
"Chebyshev") {
302 paramList.
set(
"chebyshev: zero starting solution", InitialGuessIsZero);
303 supportInitialGuess =
true;
305 }
else if (type_ ==
"point relaxation stand-alone") {
306 paramList.
set(
"relaxation: zero starting solution", InitialGuessIsZero);
307 supportInitialGuess =
true;
310 SetPrecParameters(paramList);
313 if (InitialGuessIsZero || supportInitialGuess) {
317 prec_->ApplyInverse(epB, epX);
321 RCP<MultiVector> Correction = MultiVectorFactory::Build(A_->getDomainMap(), X.getNumVectors());
326 prec_->ApplyInverse(epB, epX);
328 X.update(1.0, *Correction, 1.0);
332 template <
class Node>
335 smoother->SetParameterList(this->GetParameterList());
339 template <
class Node>
341 std::ostringstream out;
344 if (prec_ == Teuchos::null || this->GetVerbLevel() ==
InterfaceTest) {
346 out <<
"{type = " << type_ <<
"}";
348 out << prec_->Label();
353 template <
class Node>
358 out0 <<
"Prec. type: " << type_ << std::endl;
361 out0 <<
"Parameter list: " << std::endl;
363 out << this->GetParameterList();
364 out0 <<
"Overlap: " << overlap_ << std::endl;
368 if (prec_ != Teuchos::null) {
370 out << *prec_ << std::endl;
373 if (verbLevel &
Debug) {
376 <<
"RCP<A_>: " << A_ << std::endl
377 <<
"RCP<prec_>: " << prec_ << std::endl;
381 template <
class Node>
392 #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)
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.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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.
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.
const RCP< const FactoryBase > GetFactory(const std::string &varName) const
Default implementation of FactoryAcceptor::GetFactory()
Class that encapsulates Ifpack smoothers.
std::string toString(const T &t)