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" 62 : type_(type), overlap_(overlap)
78 ParameterList& paramList =
const_cast<ParameterList&
>(this->
GetParameterList());
79 paramList.setParameters(list);
83 prec_->SetParameters(*precList);
110 this->
Input(currentLevel,
"A");
112 if (
type_ ==
"LINESMOOTHING_BANDED_RELAXATION" ||
113 type_ ==
"LINESMOOTHING_BANDED RELAXATION" ||
114 type_ ==
"LINESMOOTHING_BANDEDRELAXATION" ||
115 type_ ==
"LINESMOOTHING_BLOCK_RELAXATION" ||
116 type_ ==
"LINESMOOTHING_BLOCK RELAXATION" ||
117 type_ ==
"LINESMOOTHING_BLOCKRELAXATION") {
118 this->
Input(currentLevel,
"CoarseNumZLayers");
119 this->
Input(currentLevel,
"LineDetection_VertLineIds");
126 GetOStream(
Warnings0) <<
"MueLu::IfpackSmoother::Setup(): Setup() has already been called";
128 A_ = Factory::Get< RCP<Matrix> >(currentLevel,
"A");
130 double lambdaMax = -1.0;
131 if (
type_ ==
"Chebyshev") {
132 std::string maxEigString =
"chebyshev: max eigenvalue";
133 std::string eigRatioString =
"chebyshev: ratio eigenvalue";
136 lambdaMax = Teuchos::getValue<Scalar>(this->
GetParameter(maxEigString));
137 this->
GetOStream(
Statistics1) << maxEigString <<
" (cached with smoother parameter list) = " << lambdaMax << std::endl;
139 }
catch (Teuchos::Exceptions::InvalidParameterName) {
140 lambdaMax =
A_->GetMaxEigenvalueEstimate();
142 if (lambdaMax != -1.0) {
143 this->
GetOStream(
Statistics1) << maxEigString <<
" (cached with matrix) = " << lambdaMax << std::endl;
144 this->
SetParameter(maxEigString, ParameterEntry(lambdaMax));
149 const Scalar defaultEigRatio = 20;
151 Scalar ratio = defaultEigRatio;
153 ratio = Teuchos::getValue<Scalar>(this->
GetParameter(eigRatioString));
155 }
catch (Teuchos::Exceptions::InvalidParameterName) {
156 this->
SetParameter(eigRatioString, ParameterEntry(ratio));
159 if (currentLevel.GetLevelID()) {
164 RCP<const Matrix> fineA = currentLevel.GetPreviousLevel()->Get<RCP<Matrix> >(
"A");
165 size_t nRowsFine = fineA->getGlobalNumRows();
166 size_t nRowsCoarse =
A_->getGlobalNumRows();
168 ratio = std::max(ratio, as<Scalar>(nRowsFine)/nRowsCoarse);
171 this->
SetParameter(eigRatioString, ParameterEntry(ratio));
175 if (
type_ ==
"LINESMOOTHING_BANDED_RELAXATION" ||
176 type_ ==
"LINESMOOTHING_BANDED RELAXATION" ||
177 type_ ==
"LINESMOOTHING_BANDEDRELAXATION" ||
178 type_ ==
"LINESMOOTHING_BLOCK_RELAXATION" ||
179 type_ ==
"LINESMOOTHING_BLOCK RELAXATION" ||
180 type_ ==
"LINESMOOTHING_BLOCKRELAXATION" ) {
181 ParameterList& myparamList =
const_cast<ParameterList&
>(this->
GetParameterList());
183 LO CoarseNumZLayers = Factory::Get<LO>(currentLevel,
"CoarseNumZLayers");
184 if (CoarseNumZLayers > 0) {
185 Teuchos::ArrayRCP<LO> TVertLineIdSmoo = Factory::Get< Teuchos::ArrayRCP<LO> >(currentLevel,
"LineDetection_VertLineIds");
189 for(
size_t k = 0; k < Teuchos::as<size_t>(TVertLineIdSmoo.size()); k++) {
190 if(maxPart < TVertLineIdSmoo[k]) maxPart = TVertLineIdSmoo[k];
193 size_t numLocalRows =
A_->getNodeNumRows();
194 TEUCHOS_TEST_FOR_EXCEPTION(numLocalRows % TVertLineIdSmoo.size() != 0,
Exceptions::RuntimeError,
"MueLu::Ifpack2Smoother::Setup(): the number of local nodes is incompatible with the TVertLineIdsSmoo.");
196 if (numLocalRows == Teuchos::as<size_t>(TVertLineIdSmoo.size())) {
197 myparamList.set(
"partitioner: type",
"user");
198 myparamList.set(
"partitioner: map",&(TVertLineIdSmoo[0]));
199 myparamList.set(
"partitioner: local parts",maxPart+1);
202 size_t numDofsPerNode = numLocalRows / TVertLineIdSmoo.size();
205 Teuchos::ArrayRCP<LO> partitionerMap(numLocalRows, Teuchos::OrdinalTraits<LocalOrdinal>::invalid());
206 for (
size_t blockRow = 0; blockRow < Teuchos::as<size_t>(TVertLineIdSmoo.size()); ++blockRow)
207 for (
size_t dof = 0; dof < numDofsPerNode; dof++)
208 partitionerMap[blockRow * numDofsPerNode + dof] = TVertLineIdSmoo[blockRow];
209 myparamList.set(
"partitioner: type",
"user");
210 myparamList.set(
"partitioner: map",&(partitionerMap[0]));
211 myparamList.set(
"partitioner: local parts",maxPart + 1);
214 if (
type_ ==
"LINESMOOTHING_BANDED_RELAXATION" ||
215 type_ ==
"LINESMOOTHING_BANDED RELAXATION" ||
216 type_ ==
"LINESMOOTHING_BANDEDRELAXATION")
217 type_ =
"block relaxation";
219 type_ =
"block relaxation";
222 this->
GetOStream(
Runtime0) <<
"Line detection failed: fall back to point-wise relaxation" << std::endl;
223 myparamList.remove(
"partitioner: type",
false);
224 myparamList.remove(
"partitioner: map",
false);
225 myparamList.remove(
"partitioner: local parts",
false);
226 type_ =
"point relaxation stand-alone";
241 if (
type_ ==
"Chebyshev" && lambdaMax == -1.0) {
243 if (chebyPrec != Teuchos::null) {
245 A_->SetMaxEigenvalueEstimate(lambdaMax);
246 this->
GetOStream(
Statistics1) <<
"chebyshev: max eigenvalue (calculated by Ifpack)" <<
" = " << lambdaMax << std::endl;
248 TEUCHOS_TEST_FOR_EXCEPTION(lambdaMax == -1.0,
Exceptions::RuntimeError,
"MueLu::IfpackSmoother::Setup(): no maximum eigenvalue estimate");
258 Teuchos::ParameterList paramList;
259 bool supportInitialGuess =
false;
260 if (
type_ ==
"Chebyshev") {
261 paramList.set(
"chebyshev: zero starting solution", InitialGuessIsZero);
262 supportInitialGuess =
true;
264 }
else if (
type_ ==
"point relaxation stand-alone") {
265 paramList.set(
"relaxation: zero starting solution", InitialGuessIsZero);
266 supportInitialGuess =
true;
272 if (InitialGuessIsZero || supportInitialGuess) {
276 prec_->ApplyInverse(epB, epX);
280 RCP<MultiVector> Correction = MultiVectorFactory::Build(
A_->getDomainMap(), X.getNumVectors());
285 prec_->ApplyInverse(epB, epX);
287 X.update(1.0, *Correction, 1.0);
298 std::ostringstream out;
303 out <<
"{type = " <<
type_ <<
"}";
305 out <<
prec_->Label();
314 out0 <<
"Prec. type: " <<
type_ << std::endl;
317 out0 <<
"Parameter list: " << std::endl;
318 Teuchos::OSTab tab2(out);
320 out0 <<
"Overlap: " <<
overlap_ << std::endl;
324 if (
prec_ != Teuchos::null) {
325 Teuchos::OSTab tab2(out);
326 out << *
prec_ << std::endl;
329 if (verbLevel &
Debug) {
332 <<
"RCP<A_>: " <<
A_ << std::endl
333 <<
"RCP<prec_>: " <<
prec_ << std::endl;
Important warning messages (one line)
void SetParameterList(const Teuchos::ParameterList ¶mList)
std::string description() const
Return a simple one-line description of this object.
static RCP< Epetra_MultiVector > MV2NonConstEpetraMV(RCP< MultiVector > Vec)
std::string toString(const T &what)
Little helper function to convert non-string types to strings.
RCP< SmootherPrototype > Copy() const
RCP< Matrix > A_
Matrix. Not used directly, but held inside of prec_. So we have to keep an RCP pointer to it! ...
Print external lib objects.
LO overlap_
overlap when using the smoother in additive Schwarz mode
void SetPrecParameters(const Teuchos::ParameterList &list=Teuchos::ParameterList()) const
Timer to be used in factories. Similar to Monitor but with additional timers.
Print additional debugging information.
One-liner description of what is happening.
Namespace for MueLu classes and methods.
virtual const Teuchos::ParameterList & GetParameterList() const
Ifpack_Preconditioner * Create(const std::string PrecType, Epetra_RowMatrix *Matrix, const int overlap=0, bool overrideSerialDefault=false)
Print skeleton for the run, i.e. factory calls and used parameters.
static RCP< const Epetra_MultiVector > MV2EpetraMV(RCP< MultiVector > const Vec)
Helper utility to pull out the underlying Epetra objects from an Xpetra object.
RCP< Ifpack_Preconditioner > prec_
pointer to Ifpack solver object
VerbLevel GetVerbLevel() const
Get the verbosity level.
Print statistics that do not involve significant additional computation.
RCP< ParameterList > RemoveFactoriesFromList(const ParameterList &list) const
virtual void SetParameterList(const ParameterList ¶mList)
Set parameters from a parameter list and return with default values.
Class that holds all level-specific information.
void print(Teuchos::FancyOStream &out, const VerbLevel verbLevel=Default) const
Print the object with some verbosity level to an FancyOStream object.
IfpackSmoother(std::string const &type, Teuchos::ParameterList const ¶mList=Teuchos::ParameterList(), LO const &overlap=0)
Constructor.
bool IsSetup() const
Get the state of a smoother prototype.
void Apply(MultiVector &X, const MultiVector &B, bool InitialGuessIsZero=false) const
Apply the preconditioner.
virtual double GetLambdaMax()
#define MUELU_DESCRIBE
Helper macro for implementing Describable::describe() for BaseClass objects.
void SetParameter(const std::string &name, const ParameterEntry &entry)
Set a parameter directly as a ParameterEntry.
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
void Setup(Level ¤tLevel)
Set up the smoother.
std::string type_
ifpack-specific key phrase that denote smoother type
Print class parameters (more parameters, more verbose)
Exception throws to report errors in the internal logical of the program.
static RCP< Epetra_CrsMatrix > Op2NonConstEpetraCrs(RCP< Matrix > Op)
const ParameterEntry & GetParameter(const std::string &name) const
Retrieves a const entry with the name name.
void Input(Level &level, const std::string &varName) const
virtual std::string description() const
Return a simple one-line description of this object.
static RCP< MultiVector > Residual(const Operator &Op, const MultiVector &X, const MultiVector &RHS)
void DeclareInput(Level ¤tLevel) const
Input.