17#ifndef MUELU_ADAPTIVESAMLPARAMETERLISTINTERPRETER_DEF_HPP_
18#define MUELU_ADAPTIVESAMLPARAMETERLISTINTERPRETER_DEF_HPP_
20#include <Teuchos_XMLParameterListHelpers.hpp>
23#if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA)
24#include <ml_ValidateParameters.h>
27#include <Xpetra_Matrix.hpp>
28#include <Xpetra_MultiVector.hpp>
29#include <Xpetra_MultiVectorFactory.hpp>
30#include <Xpetra_Operator.hpp>
31#include <Xpetra_IO.hpp>
36#include "MueLu_Hierarchy.hpp"
37#include "MueLu_FactoryManager.hpp"
39#include "MueLu_TentativePFactory.hpp"
40#include "MueLu_SaPFactory.hpp"
41#include "MueLu_PgPFactory.hpp"
42#include "MueLu_TransPFactory.hpp"
43#include "MueLu_GenericRFactory.hpp"
44#include "MueLu_SmootherPrototype.hpp"
45#include "MueLu_SmootherFactory.hpp"
46#include "MueLu_TrilinosSmoother.hpp"
47#include "MueLu_HierarchyUtils.hpp"
48#include "MueLu_RAPFactory.hpp"
49#include "MueLu_CoalesceDropFactory.hpp"
50#include "MueLu_UncoupledAggregationFactory.hpp"
51#include "MueLu_NullspaceFactory.hpp"
53#include "MueLu_ParameterListInterpreter.hpp"
65#define MUELU_READ_PARAM(paramList, paramStr, varType, defaultValue, varName) \
66 varType varName = defaultValue; \
67 if (paramList.isParameter(paramStr)) varName = paramList.get<varType>(paramStr);
70#define MUELU_COPY_PARAM(paramList, paramStr, varType, defaultValue, outParamList, outParamStr) \
71 if (paramList.isParameter(paramStr)) \
72 outParamList.set<varType>(outParamStr, paramList.get<varType>(paramStr)); \
74 outParamList.set<varType>(outParamStr, defaultValue);
79template <
class SC,
class LO,
class GO,
class NO>
80Teuchos::RCP<MueLu::SmootherFactory<SC, LO, GO, NO> >
getSmoother(Teuchos::ParameterList& list) {
83 return Teuchos::rcp_const_cast<SF>(Teuchos::rcp_dynamic_cast<const SF>(interpreter.
GetFactoryManager(0)->GetFactory(
"Smoother")));
87template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
94template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
99 Teuchos::RCP<Teuchos::ParameterList> paramList = Teuchos::getParametersFromXmlFile(xmlFileName);
103template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
105 Teuchos::ParameterList paramList = paramList_in;
107 RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
120 MUELU_READ_PARAM(paramList,
"aggregation: type", std::string,
"Uncoupled", agg_type);
122 MUELU_READ_PARAM(paramList,
"aggregation: damping factor",
double, (
double)4 / (
double)3, agg_damping);
124 MUELU_READ_PARAM(paramList,
"aggregation: nodes per aggregate",
int, 1, minPerAgg);
126 MUELU_READ_PARAM(paramList,
"null space: type", std::string,
"default vectors", nullspaceType);
127 MUELU_READ_PARAM(paramList,
"null space: dimension",
int, -1, nullspaceDim);
128 MUELU_READ_PARAM(paramList,
"null space: vectors",
double*, NULL, nullspaceVec);
130 MUELU_READ_PARAM(paramList,
"energy minimization: enable",
bool,
false, bEnergyMinimization);
138 ParameterList paramListWithSubList;
140 paramList = paramListWithSubList;
145 int maxNbrAlreadySelected = 0;
151 Teuchos::EVerbosityLevel eVerbLevel = Teuchos::VERB_NONE;
152 if (verbosityLevel == 0) eVerbLevel = Teuchos::VERB_NONE;
153 if (verbosityLevel > 0) eVerbLevel = Teuchos::VERB_LOW;
154 if (verbosityLevel > 4) eVerbLevel = Teuchos::VERB_MEDIUM;
155 if (verbosityLevel > 7) eVerbLevel = Teuchos::VERB_HIGH;
156 if (verbosityLevel > 9) eVerbLevel = Teuchos::VERB_EXTREME;
158 TEUCHOS_TEST_FOR_EXCEPTION(agg_type !=
"Uncoupled",
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter::Setup(): parameter \"aggregation: type\": only 'Uncoupled' aggregation is supported.");
167 AggFact->SetMinNodesPerAggregate(minPerAgg);
168 AggFact->SetMaxNeighAlreadySelected(maxNbrAlreadySelected);
169 AggFact->SetOrdering(
"natural");
171 if (verbosityLevel > 3) {
172 *out <<
"========================= Aggregate option summary =========================" << std::endl;
173 *out <<
"min Nodes per aggregate : " << minPerAgg << std::endl;
174 *out <<
"min # of root nbrs already aggregated : " << maxNbrAlreadySelected << std::endl;
175 *out <<
"aggregate ordering : natural" << std::endl;
176 *out <<
"=============================================================================" << std::endl;
182 if (agg_damping == 0.0 && bEnergyMinimization ==
false) {
186 }
else if (agg_damping != 0.0 && bEnergyMinimization ==
false) {
188 RCP<SaPFactory> SaPFact = rcp(
new SaPFactory());
189 SaPFact->SetParameter(
"sa: damping factor", ParameterEntry(agg_damping));
192 }
else if (bEnergyMinimization ==
true) {
198 RCP<RAPFactory> AcFact = rcp(
new RAPFactory());
210 if (nullspaceType !=
"default vectors") {
211 TEUCHOS_TEST_FOR_EXCEPTION(nullspaceType !=
"pre-computed",
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: no valid nullspace (no pre-computed null space). error.");
212 TEUCHOS_TEST_FOR_EXCEPTION(nullspaceDim == -1,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: no valid nullspace (nullspace dim == -1). error.");
213 TEUCHOS_TEST_FOR_EXCEPTION(nullspaceVec == NULL,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: no valid nullspace (nullspace == NULL). You have to provide a valid fine-level nullspace in \'null space: vectors\'");
219 Teuchos::RCP<NullspaceFactory> nspFact = Teuchos::rcp(
new NullspaceFactory());
220 nspFact->SetFactory(
"Nullspace", PtentFact);
232 RCP<SmootherFactory> initSmootherFact = Teuchos::null;
233 if (paramList.isSublist(
"init smoother")) {
234 ParameterList& initList = paramList.sublist(
"init smoother");
237 std::string ifpackType =
"RELAXATION";
238 Teuchos::ParameterList smootherParamList;
239 smootherParamList.set(
"relaxation: type",
"symmetric Gauss-Seidel");
240 smootherParamList.set(
"smoother: sweeps", 1);
241 smootherParamList.set(
"smoother: damping factor", 1.0);
242 RCP<SmootherPrototype> smooProto = rcp(
new TrilinosSmoother(ifpackType, smootherParamList, 0));
245 initSmootherFact->SetSmootherPrototypes(smooProto, smooProto);
251 ParameterList& coarseList = paramList.sublist(
"coarse: list");
266 for (
int levelID = 0; levelID < maxLevels; levelID++) {
282 ParameterList levelSmootherParam =
GetMLSubList(paramList,
"smoother", levelID);
289 manager->SetFactory(
"Smoother", smootherFact);
290 smootherFact->DisableMultipleCallCheck();
292 initmanager->SetFactory(
"Smoother", initSmootherFact);
293 initmanager->SetFactory(
"CoarseSolver", initSmootherFact);
294 initSmootherFact->DisableMultipleCallCheck();
301 Teuchos::rcp_dynamic_cast<PFactory>(PFact)->DisableMultipleCallCheck();
302 Teuchos::rcp_dynamic_cast<PFactory>(PtentFact)->DisableMultipleCallCheck();
303 Teuchos::rcp_dynamic_cast<TwoLevelFactoryBase>(RFact)->DisableMultipleCallCheck();
304 Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(coarseFact)->DisableMultipleCallCheck();
305 Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(dropFact)->DisableMultipleCallCheck();
306 Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(AggFact)->DisableMultipleCallCheck();
307 Teuchos::rcp_dynamic_cast<TwoLevelFactoryBase>(AcFact)->DisableMultipleCallCheck();
308 Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(nspFact)->DisableMultipleCallCheck();
310 manager->SetFactory(
"CoarseSolver", coarseFact);
311 manager->SetFactory(
"Graph", dropFact);
312 manager->SetFactory(
"Aggregates", AggFact);
313 manager->SetFactory(
"DofsPerNode", dropFact);
314 manager->SetFactory(
"A", AcFact);
315 manager->SetFactory(
"P", PFact);
316 manager->SetFactory(
"Ptent", PtentFact);
317 manager->SetFactory(
"R", RFact);
318 manager->SetFactory(
"Nullspace", nspFact);
321 initmanager->SetFactory(
"Graph", dropFact);
322 initmanager->SetFactory(
"Aggregates", AggFact);
323 initmanager->SetFactory(
"DofsPerNode", dropFact);
324 initmanager->SetFactory(
"A", AcFact);
325 initmanager->SetFactory(
"P", PtentFact);
326 initmanager->SetFactory(
"Ptent", PtentFact);
327 initmanager->SetFactory(
"R", RFact);
328 initmanager->SetFactory(
"Nullspace", nspFact);
335template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
340 RCP<Operator> Op = l->Get<RCP<Operator> >(
"A");
349 bool isLastLevel =
false;
351 while (!isLastLevel) {
352 bool r = H.
Setup(levelID,
357 isLastLevel = r || (levelID == lastLevelID);
362template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
368 RCP<Level> fineLevel = H.
GetLevel(0);
369 const RCP<const Map> rowMap = fineLevel->Get<RCP<Matrix> >(
"A")->getRowMap();
370 RCP<MultiVector> nullspace = MultiVectorFactory::Build(rowMap,
nullspaceDim_,
true);
372 for (
size_t i = 0; i < Teuchos::as<size_t>(
nullspaceDim_); i++) {
373 Teuchos::ArrayRCP<Scalar> nullspacei = nullspace->getDataNonConst(i);
374 const size_t myLength = nullspace->getLocalLength();
376 for (
size_t j = 0; j < myLength; j++) {
381 fineLevel->Set(
"Nullspace", nullspace);
394 Teuchos::RCP<MueLu::Level> Finest = H.
GetLevel(0);
395 Teuchos::RCP<MultiVector> nspVector2 = Finest->Get<Teuchos::RCP<MultiVector> >(
"Nullspace");
397 Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Write(
"orig_nsp.vec", *nspVector2);
399 RCP<Matrix> Op = Finest->Get<RCP<Matrix> >(
"A");
400 Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Write(
"A.mat", *Op);
402 Teuchos::RCP<MultiVector> homogRhsVec = MultiVectorFactory::Build(nspVector2->getMap(), nspVector2->getNumVectors(),
true);
403 homogRhsVec->putScalar(0.0);
408 H.
Iterate(*homogRhsVec, *nspVector2, 1,
false);
411 Finest->Set(
"Nullspace", nspVector2);
413 Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Write(
"new_nsp.vec", *nspVector2);
437template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
440 TEUCHOS_TEST_FOR_EXCEPTION(Teuchos::rcp_dynamic_cast<TwoLevelFactoryBase>(factory) == Teuchos::null,
Exceptions::BadCast,
"Transfer factory is not derived from TwoLevelFactoryBase. Since transfer factories will be handled by the RAPFactory they have to be derived from TwoLevelFactoryBase!");
444template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
449template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
452 Matrix& A =
dynamic_cast<Matrix&
>(Op);
453 if (A.IsFixedBlockSizeSet() && (A.GetFixedBlockSize() !=
blksize_))
455 <<
"instead of " << A.GetFixedBlockSize() <<
" (provided matrix)." << std::endl;
459 }
catch (std::bad_cast& e) {
460 this->
GetOStream(
Warnings0) <<
"Skipping setting block size as the operator is not a matrix" << std::endl;
#define MUELU_READ_PARAM(paramList, paramStr, varType, defaultValue, varName)
std::vector< RCP< FactoryBase > > TransferFacts_
size_t NumTransferFactories() const
Returns number of transfer factories.
void AddInitFactoryManager(int startLevel, int numDesiredLevel, RCP< FactoryManagerBase > manager)
internal routine to add a new factory manager used for the initialization phase
void SetParameterList(const Teuchos::ParameterList ¶mList)
virtual void SetupOperator(Operator &Op) const
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.
Teuchos::RCP< FactoryManagerBase > InitLvlMngr(int levelID, int lastLevelID) const
int nullspaceDim_
nullspace can be embedded in the ML parameter list
void SetupInitHierarchy(Hierarchy &H) const
int blksize_
Matrix configuration storage.
void AddTransferFactory(const RCP< FactoryBase > &factory)
Add transfer factory in the end of list of transfer factories for RAPFactory.
AdaptiveSaMLParameterListInterpreter()
Constructor.
Factory for creating a graph based on a given matrix.
Exception indicating invalid cast attempted.
Exception throws to report errors in the internal logical of the program.
This class specifies the default factory that should generate some data on a Level if the data does n...
Factory for building restriction operators using a prolongator factory.
virtual void SetupExtra(Hierarchy &) const
RCP< FactoryManagerBase > GetFactoryManager(int levelID) const
void AddFactoryManager(int startLevel, int numDesiredLevel, RCP< FactoryManagerBase > manager)
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.
Xpetra::global_size_t maxCoarseSize_
size_t getNumFactoryManagers() const
returns number of factory managers stored in levelManagers_ vector.
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
RCP< Level > & GetLevel(const int levelID=0)
Retrieve a certain level from hierarchy.
bool Setup(int coarseLevelID, const RCP< const FactoryManagerBase > fineLevelManager, const RCP< const FactoryManagerBase > coarseLevelManager, const RCP< const FactoryManagerBase > nextLevelManager=Teuchos::null)
Multi-level setup phase: build a new level of the hierarchy.
ConvergenceStatus Iterate(const MultiVector &B, MultiVector &X, ConvData conv=ConvData(), bool InitialGuessIsZero=false, LO startLevel=0)
Apply the multigrid preconditioner.
void SetMaxCoarseSize(Xpetra::global_size_t maxCoarseSize)
void Keep(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Call Level::Keep(ename, factory) for each level of the Hierarchy.
Factory for generating nullspace.
Factory for building Petrov-Galerkin Smoothed Aggregation prolongators.
Factory for building coarse matrices.
Factory for building Smoothed Aggregation prolongators.
Generic Smoother Factory for generating the smoothers of the MG hierarchy.
Factory for building tentative prolongator.
Factory for building restriction operators.
Class that encapsulates external library smoothers.
Factory for building uncoupled aggregates.
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
void SetVerbLevel(const VerbLevel verbLevel)
Set the verbosity level of this object.
Teuchos::RCP< MueLu::SmootherFactory< SC, LO, GO, NO > > getSmoother(Teuchos::ParameterList &list)
Namespace for MueLu classes and methods.
void CreateSublists(const Teuchos::ParameterList &List, Teuchos::ParameterList &newList)
Teuchos::RCP< Teuchos::ParameterList > ExtractSetOfParameters(const Teuchos::ParameterList ¶mList, const std::string &str)
@ Warnings0
Important warning messages (one line).
void MergeParameterList(const Teuchos::ParameterList &source, Teuchos::ParameterList &dest, bool overWrite)
: merge two parameter lists
const Teuchos::ParameterList & GetMLSubList(const Teuchos::ParameterList ¶mList, const std::string &type, int levelID)
VerbLevel toMueLuVerbLevel(const Teuchos::EVerbosityLevel verbLevel)
Translate Teuchos verbosity level to MueLu verbosity level.