17#ifndef MUELU_ADAPTIVESAMLPARAMETERLISTINTERPRETER_DEF_HPP_
18#define MUELU_ADAPTIVESAMLPARAMETERLISTINTERPRETER_DEF_HPP_
20#include <Teuchos_XMLParameterListHelpers.hpp>
24#include <Xpetra_Matrix.hpp>
25#include <Xpetra_MultiVector.hpp>
26#include <Xpetra_MultiVectorFactory.hpp>
27#include <Xpetra_Operator.hpp>
28#include <Xpetra_IO.hpp>
33#include "MueLu_Hierarchy.hpp"
34#include "MueLu_FactoryManager.hpp"
36#include "MueLu_TentativePFactory.hpp"
37#include "MueLu_SaPFactory.hpp"
38#include "MueLu_PgPFactory.hpp"
39#include "MueLu_TransPFactory.hpp"
40#include "MueLu_GenericRFactory.hpp"
41#include "MueLu_SmootherPrototype.hpp"
42#include "MueLu_SmootherFactory.hpp"
43#include "MueLu_TrilinosSmoother.hpp"
44#include "MueLu_HierarchyUtils.hpp"
45#include "MueLu_RAPFactory.hpp"
46#include "MueLu_CoalesceDropFactory.hpp"
47#include "MueLu_UncoupledAggregationFactory.hpp"
48#include "MueLu_NullspaceFactory.hpp"
50#include "MueLu_ParameterListInterpreter.hpp"
62#define MUELU_READ_PARAM(paramList, paramStr, varType, defaultValue, varName) \
63 varType varName = defaultValue; \
64 if (paramList.isParameter(paramStr)) varName = paramList.get<varType>(paramStr);
67#define MUELU_COPY_PARAM(paramList, paramStr, varType, defaultValue, outParamList, outParamStr) \
68 if (paramList.isParameter(paramStr)) \
69 outParamList.set<varType>(outParamStr, paramList.get<varType>(paramStr)); \
71 outParamList.set<varType>(outParamStr, defaultValue);
76template <
class SC,
class LO,
class GO,
class NO>
77Teuchos::RCP<MueLu::SmootherFactory<SC, LO, GO, NO> >
getSmoother(Teuchos::ParameterList& list) {
80 return Teuchos::rcp_const_cast<SF>(Teuchos::rcp_dynamic_cast<const SF>(interpreter.
GetFactoryManager(0)->GetFactory(
"Smoother")));
84template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
91template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
96 Teuchos::RCP<Teuchos::ParameterList> paramList = Teuchos::getParametersFromXmlFile(xmlFileName);
100template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
102 Teuchos::ParameterList paramList = paramList_in;
104 RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
117 MUELU_READ_PARAM(paramList,
"aggregation: type", std::string,
"Uncoupled", agg_type);
119 MUELU_READ_PARAM(paramList,
"aggregation: damping factor",
double, (
double)4 / (
double)3, agg_damping);
121 MUELU_READ_PARAM(paramList,
"aggregation: nodes per aggregate",
int, 1, minPerAgg);
123 MUELU_READ_PARAM(paramList,
"null space: type", std::string,
"default vectors", nullspaceType);
124 MUELU_READ_PARAM(paramList,
"null space: dimension",
int, -1, nullspaceDim);
125 MUELU_READ_PARAM(paramList,
"null space: vectors",
double*, NULL, nullspaceVec);
127 MUELU_READ_PARAM(paramList,
"energy minimization: enable",
bool,
false, bEnergyMinimization);
135 ParameterList paramListWithSubList;
137 paramList = paramListWithSubList;
142 int maxNbrAlreadySelected = 0;
148 Teuchos::EVerbosityLevel eVerbLevel = Teuchos::VERB_NONE;
149 if (verbosityLevel == 0) eVerbLevel = Teuchos::VERB_NONE;
150 if (verbosityLevel > 0) eVerbLevel = Teuchos::VERB_LOW;
151 if (verbosityLevel > 4) eVerbLevel = Teuchos::VERB_MEDIUM;
152 if (verbosityLevel > 7) eVerbLevel = Teuchos::VERB_HIGH;
153 if (verbosityLevel > 9) eVerbLevel = Teuchos::VERB_EXTREME;
155 TEUCHOS_TEST_FOR_EXCEPTION(agg_type !=
"Uncoupled",
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter::Setup(): parameter \"aggregation: type\": only 'Uncoupled' aggregation is supported.");
164 AggFact->SetMinNodesPerAggregate(minPerAgg);
165 AggFact->SetMaxNeighAlreadySelected(maxNbrAlreadySelected);
166 AggFact->SetOrdering(
"natural");
168 if (verbosityLevel > 3) {
169 *out <<
"========================= Aggregate option summary =========================" << std::endl;
170 *out <<
"min Nodes per aggregate : " << minPerAgg << std::endl;
171 *out <<
"min # of root nbrs already aggregated : " << maxNbrAlreadySelected << std::endl;
172 *out <<
"aggregate ordering : natural" << std::endl;
173 *out <<
"=============================================================================" << std::endl;
179 if (agg_damping == 0.0 && bEnergyMinimization ==
false) {
183 }
else if (agg_damping != 0.0 && bEnergyMinimization ==
false) {
185 RCP<SaPFactory> SaPFact = rcp(
new SaPFactory());
186 SaPFact->SetParameter(
"sa: damping factor", ParameterEntry(agg_damping));
189 }
else if (bEnergyMinimization ==
true) {
195 RCP<RAPFactory> AcFact = rcp(
new RAPFactory());
207 if (nullspaceType !=
"default vectors") {
208 TEUCHOS_TEST_FOR_EXCEPTION(nullspaceType !=
"pre-computed",
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: no valid nullspace (no pre-computed null space). error.");
209 TEUCHOS_TEST_FOR_EXCEPTION(nullspaceDim == -1,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: no valid nullspace (nullspace dim == -1). error.");
210 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\'");
216 Teuchos::RCP<NullspaceFactory> nspFact = Teuchos::rcp(
new NullspaceFactory());
217 nspFact->SetFactory(
"Nullspace", PtentFact);
229 RCP<SmootherFactory> initSmootherFact = Teuchos::null;
230 if (paramList.isSublist(
"init smoother")) {
231 ParameterList& initList = paramList.sublist(
"init smoother");
234 std::string ifpackType =
"RELAXATION";
235 Teuchos::ParameterList smootherParamList;
236 smootherParamList.set(
"relaxation: type",
"symmetric Gauss-Seidel");
237 smootherParamList.set(
"smoother: sweeps", 1);
238 smootherParamList.set(
"smoother: damping factor", 1.0);
239 RCP<SmootherPrototype> smooProto = rcp(
new TrilinosSmoother(ifpackType, smootherParamList, 0));
242 initSmootherFact->SetSmootherPrototypes(smooProto, smooProto);
248 ParameterList& coarseList = paramList.sublist(
"coarse: list");
263 for (
int levelID = 0; levelID < maxLevels; levelID++) {
279 ParameterList levelSmootherParam =
GetMLSubList(paramList,
"smoother", levelID);
286 manager->SetFactory(
"Smoother", smootherFact);
287 smootherFact->DisableMultipleCallCheck();
289 initmanager->SetFactory(
"Smoother", initSmootherFact);
290 initmanager->SetFactory(
"CoarseSolver", initSmootherFact);
291 initSmootherFact->DisableMultipleCallCheck();
298 Teuchos::rcp_dynamic_cast<PFactory>(PFact)->DisableMultipleCallCheck();
299 Teuchos::rcp_dynamic_cast<PFactory>(PtentFact)->DisableMultipleCallCheck();
300 Teuchos::rcp_dynamic_cast<TwoLevelFactoryBase>(RFact)->DisableMultipleCallCheck();
301 Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(coarseFact)->DisableMultipleCallCheck();
302 Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(dropFact)->DisableMultipleCallCheck();
303 Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(AggFact)->DisableMultipleCallCheck();
304 Teuchos::rcp_dynamic_cast<TwoLevelFactoryBase>(AcFact)->DisableMultipleCallCheck();
305 Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(nspFact)->DisableMultipleCallCheck();
307 manager->SetFactory(
"CoarseSolver", coarseFact);
308 manager->SetFactory(
"Graph", dropFact);
309 manager->SetFactory(
"Aggregates", AggFact);
310 manager->SetFactory(
"DofsPerNode", dropFact);
311 manager->SetFactory(
"A", AcFact);
312 manager->SetFactory(
"P", PFact);
313 manager->SetFactory(
"Ptent", PtentFact);
314 manager->SetFactory(
"R", RFact);
315 manager->SetFactory(
"Nullspace", nspFact);
318 initmanager->SetFactory(
"Graph", dropFact);
319 initmanager->SetFactory(
"Aggregates", AggFact);
320 initmanager->SetFactory(
"DofsPerNode", dropFact);
321 initmanager->SetFactory(
"A", AcFact);
322 initmanager->SetFactory(
"P", PtentFact);
323 initmanager->SetFactory(
"Ptent", PtentFact);
324 initmanager->SetFactory(
"R", RFact);
325 initmanager->SetFactory(
"Nullspace", nspFact);
332template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
337 RCP<Operator> Op = l->Get<RCP<Operator> >(
"A");
346 bool isLastLevel =
false;
348 while (!isLastLevel) {
349 bool r = H.
Setup(levelID,
354 isLastLevel = r || (levelID == lastLevelID);
359template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
365 RCP<Level> fineLevel = H.
GetLevel(0);
366 const RCP<const Map> rowMap = fineLevel->Get<RCP<Matrix> >(
"A")->getRowMap();
367 RCP<MultiVector> nullspace = MultiVectorFactory::Build(rowMap,
nullspaceDim_,
true);
369 for (
size_t i = 0; i < Teuchos::as<size_t>(
nullspaceDim_); i++) {
370 Teuchos::ArrayRCP<Scalar> nullspacei = nullspace->getDataNonConst(i);
371 const size_t myLength = nullspace->getLocalLength();
373 for (
size_t j = 0; j < myLength; j++) {
378 fineLevel->Set(
"Nullspace", nullspace);
391 Teuchos::RCP<MueLu::Level> Finest = H.
GetLevel(0);
392 Teuchos::RCP<MultiVector> nspVector2 = Finest->Get<Teuchos::RCP<MultiVector> >(
"Nullspace");
394 Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Write(
"orig_nsp.vec", *nspVector2);
396 RCP<Matrix> Op = Finest->Get<RCP<Matrix> >(
"A");
397 Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Write(
"A.mat", *Op);
399 Teuchos::RCP<MultiVector> homogRhsVec = MultiVectorFactory::Build(nspVector2->getMap(), nspVector2->getNumVectors(),
true);
400 homogRhsVec->putScalar(0.0);
405 H.
Iterate(*homogRhsVec, *nspVector2, 1,
false);
408 Finest->Set(
"Nullspace", nspVector2);
410 Xpetra::IO<Scalar, LocalOrdinal, GlobalOrdinal, Node>::Write(
"new_nsp.vec", *nspVector2);
434template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
437 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!");
441template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
446template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
449 Matrix& A =
dynamic_cast<Matrix&
>(Op);
450 if (A.IsFixedBlockSizeSet() && (A.GetFixedBlockSize() !=
blksize_))
452 <<
"instead of " << A.GetFixedBlockSize() <<
" (provided matrix)." << std::endl;
456 }
catch (std::bad_cast& e) {
457 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.
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.
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.
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.