8#ifndef MUELU_ADAPTIVESAMLPARAMETERLISTINTERPRETER_DEF_HPP_
9#define MUELU_ADAPTIVESAMLPARAMETERLISTINTERPRETER_DEF_HPP_
11#include <Teuchos_XMLParameterListHelpers.hpp>
14#if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA)
15#include <ml_ValidateParameters.h>
18#include <Xpetra_Matrix.hpp>
19#include <Xpetra_MultiVector.hpp>
20#include <Xpetra_MultiVectorFactory.hpp>
21#include <Xpetra_Operator.hpp>
22#include <Xpetra_IO.hpp>
27#include "MueLu_Hierarchy.hpp"
28#include "MueLu_FactoryManager.hpp"
30#include "MueLu_TentativePFactory.hpp"
31#include "MueLu_SaPFactory.hpp"
32#include "MueLu_PgPFactory.hpp"
33#include "MueLu_TransPFactory.hpp"
34#include "MueLu_GenericRFactory.hpp"
35#include "MueLu_SmootherPrototype.hpp"
36#include "MueLu_SmootherFactory.hpp"
37#include "MueLu_TrilinosSmoother.hpp"
38#include "MueLu_HierarchyUtils.hpp"
39#include "MueLu_RAPFactory.hpp"
40#include "MueLu_CoalesceDropFactory.hpp"
41#include "MueLu_UncoupledAggregationFactory.hpp"
42#include "MueLu_NullspaceFactory.hpp"
44#include "MueLu_MLParameterListInterpreter.hpp"
56#define MUELU_READ_PARAM(paramList, paramStr, varType, defaultValue, varName) \
57 varType varName = defaultValue; if (paramList.isParameter(paramStr)) varName = paramList.get<varType>(paramStr);
60#define MUELU_COPY_PARAM(paramList, paramStr, varType, defaultValue, outParamList, outParamStr) \
61 if (paramList.isParameter(paramStr)) \
62 outParamList.set<varType>(outParamStr, paramList.get<varType>(paramStr)); \
63 else outParamList.set<varType>(outParamStr, defaultValue); \
67 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
72 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
74 Teuchos::RCP<Teuchos::ParameterList> paramList = Teuchos::getParametersFromXmlFile(xmlFileName);
78 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
80 Teuchos::ParameterList paramList = paramList_in;
82 RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
95 MUELU_READ_PARAM(paramList,
"aggregation: type", std::string,
"Uncoupled", agg_type);
97 MUELU_READ_PARAM(paramList,
"aggregation: damping factor",
double, (
double)4/(
double)3, agg_damping);
99 MUELU_READ_PARAM(paramList,
"aggregation: nodes per aggregate",
int, 1, minPerAgg);
101 MUELU_READ_PARAM(paramList,
"null space: type", std::string,
"default vectors", nullspaceType);
102 MUELU_READ_PARAM(paramList,
"null space: dimension",
int, -1, nullspaceDim);
103 MUELU_READ_PARAM(paramList,
"null space: vectors",
double*, NULL, nullspaceVec);
105 MUELU_READ_PARAM(paramList,
"energy minimization: enable",
bool,
false, bEnergyMinimization);
114 ParameterList paramListWithSubList;
116 paramList = paramListWithSubList;
121 int maxNbrAlreadySelected = 0;
127 Teuchos::EVerbosityLevel eVerbLevel = Teuchos::VERB_NONE;
128 if (verbosityLevel == 0) eVerbLevel = Teuchos::VERB_NONE;
129 if (verbosityLevel > 0) eVerbLevel = Teuchos::VERB_LOW;
130 if (verbosityLevel > 4) eVerbLevel = Teuchos::VERB_MEDIUM;
131 if (verbosityLevel > 7) eVerbLevel = Teuchos::VERB_HIGH;
132 if (verbosityLevel > 9) eVerbLevel = Teuchos::VERB_EXTREME;
134 TEUCHOS_TEST_FOR_EXCEPTION(agg_type !=
"Uncoupled",
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter::Setup(): parameter \"aggregation: type\": only 'Uncoupled' aggregation is supported.");
143 AggFact->SetMinNodesPerAggregate(minPerAgg);
144 AggFact->SetMaxNeighAlreadySelected(maxNbrAlreadySelected);
145 AggFact->SetOrdering(
"natural");
147 if (verbosityLevel > 3) {
148 *out <<
"========================= Aggregate option summary =========================" << std::endl;
149 *out <<
"min Nodes per aggregate : " << minPerAgg << std::endl;
150 *out <<
"min # of root nbrs already aggregated : " << maxNbrAlreadySelected << std::endl;
151 *out <<
"aggregate ordering : natural" << std::endl;
152 *out <<
"=============================================================================" << std::endl;
158 if (agg_damping == 0.0 && bEnergyMinimization ==
false) {
162 }
else if (agg_damping != 0.0 && bEnergyMinimization ==
false) {
164 RCP<SaPFactory> SaPFact = rcp(
new SaPFactory() );
165 SaPFact->SetParameter(
"sa: damping factor", ParameterEntry(agg_damping));
168 }
else if (bEnergyMinimization ==
true) {
174 RCP<RAPFactory> AcFact = rcp(
new RAPFactory() );
186 if (nullspaceType !=
"default vectors") {
187 TEUCHOS_TEST_FOR_EXCEPTION(nullspaceType !=
"pre-computed",
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: no valid nullspace (no pre-computed null space). error.");
188 TEUCHOS_TEST_FOR_EXCEPTION(nullspaceDim == -1,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: no valid nullspace (nullspace dim == -1). error.");
189 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\'");
195 Teuchos::RCP<NullspaceFactory> nspFact = Teuchos::rcp(
new NullspaceFactory());
196 nspFact->SetFactory(
"Nullspace", PtentFact);
208 RCP<SmootherFactory> initSmootherFact = Teuchos::null;
209 if(paramList.isSublist(
"init smoother")) {
210 ParameterList& initList = paramList.sublist(
"init smoother");
213 std::string ifpackType =
"RELAXATION";
214 Teuchos::ParameterList smootherParamList;
215 smootherParamList.set(
"relaxation: type",
"symmetric Gauss-Seidel");
216 smootherParamList.set(
"smoother: sweeps", 1);
217 smootherParamList.set(
"smoother: damping factor", 1.0);
218 RCP<SmootherPrototype> smooProto = rcp(
new TrilinosSmoother(ifpackType, smootherParamList, 0) );
221 initSmootherFact->SetSmootherPrototypes(smooProto, smooProto);
227 ParameterList& coarseList = paramList.sublist(
"coarse: list");
243 for (
int levelID=0; levelID < maxLevels; levelID++) {
260 ParameterList levelSmootherParam =
GetMLSubList(paramList,
"smoother", levelID);
267 manager->SetFactory(
"Smoother", smootherFact);
268 smootherFact->DisableMultipleCallCheck();
270 initmanager->SetFactory(
"Smoother", initSmootherFact);
271 initmanager->SetFactory(
"CoarseSolver", initSmootherFact);
272 initSmootherFact->DisableMultipleCallCheck();
280 Teuchos::rcp_dynamic_cast<PFactory>(PFact)->DisableMultipleCallCheck();
281 Teuchos::rcp_dynamic_cast<PFactory>(PtentFact)->DisableMultipleCallCheck();
282 Teuchos::rcp_dynamic_cast<TwoLevelFactoryBase>(RFact)->DisableMultipleCallCheck();
283 Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(coarseFact)->DisableMultipleCallCheck();
284 Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(dropFact)->DisableMultipleCallCheck();
285 Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(AggFact)->DisableMultipleCallCheck();
286 Teuchos::rcp_dynamic_cast<TwoLevelFactoryBase>(AcFact)->DisableMultipleCallCheck();
287 Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(nspFact)->DisableMultipleCallCheck();
289 manager->SetFactory(
"CoarseSolver", coarseFact);
290 manager->SetFactory(
"Graph", dropFact);
291 manager->SetFactory(
"Aggregates", AggFact);
292 manager->SetFactory(
"DofsPerNode", dropFact);
293 manager->SetFactory(
"A", AcFact);
294 manager->SetFactory(
"P", PFact);
295 manager->SetFactory(
"Ptent", PtentFact);
296 manager->SetFactory(
"R", RFact);
297 manager->SetFactory(
"Nullspace", nspFact);
300 initmanager->SetFactory(
"Graph", dropFact);
301 initmanager->SetFactory(
"Aggregates", AggFact);
302 initmanager->SetFactory(
"DofsPerNode", dropFact);
303 initmanager->SetFactory(
"A", AcFact);
304 initmanager->SetFactory(
"P", PtentFact);
305 initmanager->SetFactory(
"Ptent", PtentFact);
306 initmanager->SetFactory(
"R", RFact);
307 initmanager->SetFactory(
"Nullspace", nspFact);
314 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
319 RCP<Operator> Op = l->Get<RCP<Operator> >(
"A");
328 bool isLastLevel =
false;
330 while(!isLastLevel) {
331 bool r = H.
Setup(levelID,
336 isLastLevel = r || (levelID == lastLevelID);
341 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
348 RCP<Level> fineLevel = H.
GetLevel(0);
349 const RCP<const Map> rowMap = fineLevel->Get< RCP<Matrix> >(
"A")->getRowMap();
350 RCP<MultiVector> nullspace = MultiVectorFactory::Build(rowMap,
nullspaceDim_,
true);
352 for (
size_t i=0; i < Teuchos::as<size_t>(
nullspaceDim_); i++) {
353 Teuchos::ArrayRCP<Scalar> nullspacei = nullspace->getDataNonConst(i);
354 const size_t myLength = nullspace->getLocalLength();
356 for (
size_t j = 0; j < myLength; j++) {
361 fineLevel->Set(
"Nullspace", nullspace);
374 Teuchos::RCP<MueLu::Level> Finest = H.
GetLevel(0);
375 Teuchos::RCP<MultiVector> nspVector2 = Finest->Get<Teuchos::RCP<MultiVector> >(
"Nullspace");
377 Xpetra::IO<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Write(
"orig_nsp.vec", *nspVector2);
379 RCP<Matrix> Op = Finest->Get<RCP<Matrix> >(
"A");
380 Xpetra::IO<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Write(
"A.mat", *Op);
383 Teuchos::RCP<MultiVector> homogRhsVec = MultiVectorFactory::Build(nspVector2->getMap(),nspVector2->getNumVectors(),
true);
384 homogRhsVec->putScalar(0.0);
389 H.
Iterate(*homogRhsVec, *nspVector2, 1,
false);
392 Finest->Set(
"Nullspace",nspVector2);
394 Xpetra::IO<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Write(
"new_nsp.vec", *nspVector2);
419 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
422 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!");
426 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
431 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
434 Matrix& A =
dynamic_cast<Matrix&
>(Op);
435 if (A.IsFixedBlockSizeSet() && (A.GetFixedBlockSize() !=
blksize_))
437 <<
"instead of " << A.GetFixedBlockSize() <<
" (provided matrix)." << std::endl;
441 }
catch (std::bad_cast& e) {
442 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.
MueLu::GenericRFactory< Scalar, LocalOrdinal, GlobalOrdinal, Node > GenericRFactory
void AddInitFactoryManager(int startLevel, int numDesiredLevel, RCP< FactoryManagerBase > manager)
internal routine to add a new factory manager used for the initialization phase
MueLu::SaPFactory< Scalar, LocalOrdinal, GlobalOrdinal, Node > SaPFactory
void SetParameterList(const Teuchos::ParameterList ¶mList)
virtual void SetupOperator(Operator &Op) const
MueLu::SmootherFactory< Scalar, LocalOrdinal, GlobalOrdinal, Node > SmootherFactory
MueLu::TentativePFactory< Scalar, LocalOrdinal, GlobalOrdinal, Node > TentativePFactory
MueLu::TrilinosSmoother< Scalar, LocalOrdinal, GlobalOrdinal, Node > TrilinosSmoother
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
MueLu::RAPFactory< Scalar, LocalOrdinal, GlobalOrdinal, Node > RAPFactory
MueLu::Hierarchy< Scalar, LocalOrdinal, GlobalOrdinal, Node > Hierarchy
int blksize_
Matrix configuration storage.
MueLu::NullspaceFactory< Scalar, LocalOrdinal, GlobalOrdinal, Node > NullspaceFactory
MueLu::TransPFactory< Scalar, LocalOrdinal, GlobalOrdinal, Node > TransPFactory
MueLu::PgPFactory< Scalar, LocalOrdinal, GlobalOrdinal, Node > PgPFactory
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...
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.
virtual void SetupExtra(Hierarchy &) const
RCP< FactoryManagerBase > GetFactoryManager(int levelID) const
void AddFactoryManager(int startLevel, int numDesiredLevel, RCP< FactoryManagerBase > manager)
Xpetra::global_size_t maxCoarseSize_
size_t getNumFactoryManagers() const
returns number of factory managers stored in levelManagers_ vector.
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.
static RCP< SmootherFactory > GetSmootherFactory(const Teuchos::ParameterList ¶mList, const RCP< FactoryBase > &AFact=Teuchos::null)
Read smoother options and build the corresponding smoother factory.
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.
Namespace for MueLu classes and methods.
Teuchos::RCP< Teuchos::ParameterList > ExtractSetOfParameters(const Teuchos::ParameterList ¶mList, const std::string &str)
@ Warnings0
Important warning messages (one line).
void CreateSublists(const ParameterList &List, ParameterList &newList)
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.