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> 26 #include "MueLu_Hierarchy.hpp" 27 #include "MueLu_FactoryManager.hpp" 29 #include "MueLu_TentativePFactory.hpp" 30 #include "MueLu_SaPFactory.hpp" 31 #include "MueLu_PgPFactory.hpp" 32 #include "MueLu_TransPFactory.hpp" 33 #include "MueLu_GenericRFactory.hpp" 34 #include "MueLu_SmootherPrototype.hpp" 35 #include "MueLu_SmootherFactory.hpp" 36 #include "MueLu_TrilinosSmoother.hpp" 38 #include "MueLu_DirectSolver.hpp" 39 #include "MueLu_HierarchyHelpers.hpp" 40 #include "MueLu_RAPFactory.hpp" 41 #include "MueLu_CoalesceDropFactory.hpp" 42 #include "MueLu_CoupledAggregationFactory.hpp" 43 #include "MueLu_UncoupledAggregationFactory.hpp" 44 #include "MueLu_NullspaceFactory.hpp" 46 #include "MueLu_MLParameterListInterpreter.hpp" 48 #include "MueLu_Utilities.hpp" 58 #define MUELU_READ_PARAM(paramList, paramStr, varType, defaultValue, varName) \ 59 varType varName = defaultValue; if (paramList.isParameter(paramStr)) varName = paramList.get<varType>(paramStr); 62 #define MUELU_COPY_PARAM(paramList, paramStr, varType, defaultValue, outParamList, outParamStr) \ 63 if (paramList.isParameter(paramStr)) \ 64 outParamList.set<varType>(outParamStr, paramList.get<varType>(paramStr)); \ 65 else outParamList.set<varType>(outParamStr, defaultValue); \ 69 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
74 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
76 Teuchos::RCP<Teuchos::ParameterList> paramList = Teuchos::getParametersFromXmlFile(xmlFileName);
80 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
82 Teuchos::ParameterList paramList = paramList_in;
84 RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
97 MUELU_READ_PARAM(paramList,
"aggregation: type", std::string,
"Uncoupled", agg_type);
99 MUELU_READ_PARAM(paramList,
"aggregation: damping factor",
double, (
double)4/(
double)3, agg_damping);
101 MUELU_READ_PARAM(paramList,
"aggregation: nodes per aggregate",
int, 1, minPerAgg);
103 MUELU_READ_PARAM(paramList,
"null space: type", std::string,
"default vectors", nullspaceType);
104 MUELU_READ_PARAM(paramList,
"null space: dimension",
int, -1, nullspaceDim);
105 MUELU_READ_PARAM(paramList,
"null space: vectors",
double*, NULL, nullspaceVec);
107 MUELU_READ_PARAM(paramList,
"energy minimization: enable",
bool,
false, bEnergyMinimization);
116 ParameterList paramListWithSubList;
118 paramList = paramListWithSubList;
123 int maxNbrAlreadySelected = 0;
129 Teuchos::EVerbosityLevel eVerbLevel = Teuchos::VERB_NONE;
130 if (verbosityLevel == 0) eVerbLevel = Teuchos::VERB_NONE;
131 if (verbosityLevel > 0) eVerbLevel = Teuchos::VERB_LOW;
132 if (verbosityLevel > 4) eVerbLevel = Teuchos::VERB_MEDIUM;
133 if (verbosityLevel > 7) eVerbLevel = Teuchos::VERB_HIGH;
134 if (verbosityLevel > 9) eVerbLevel = Teuchos::VERB_EXTREME;
136 TEUCHOS_TEST_FOR_EXCEPTION(agg_type !=
"Uncoupled" && agg_type !=
"Coupled",
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter::Setup(): parameter \"aggregation: type\": only 'Uncoupled' or 'Coupled' aggregation is supported.");
143 RCP<FactoryBase> CoupledAggFact = Teuchos::null;
144 if(agg_type ==
"Uncoupled") {
147 CoupledAggFact2->SetMinNodesPerAggregate(minPerAgg);
148 CoupledAggFact2->SetMaxNeighAlreadySelected(maxNbrAlreadySelected);
149 CoupledAggFact2->SetOrdering(
"natural");
150 CoupledAggFact = CoupledAggFact2;
154 CoupledAggFact2->SetMinNodesPerAggregate(minPerAgg);
155 CoupledAggFact2->SetMaxNeighAlreadySelected(maxNbrAlreadySelected);
156 CoupledAggFact2->SetOrdering(
"natural");
157 CoupledAggFact2->SetPhase3AggCreation(0.5);
158 CoupledAggFact = CoupledAggFact2;
160 if (verbosityLevel > 3) {
161 *out <<
"========================= Aggregate option summary =========================" << std::endl;
162 *out <<
"min Nodes per aggregate : " << minPerAgg << std::endl;
163 *out <<
"min # of root nbrs already aggregated : " << maxNbrAlreadySelected << std::endl;
164 *out <<
"aggregate ordering : natural" << std::endl;
165 *out <<
"=============================================================================" << std::endl;
171 if (agg_damping == 0.0 && bEnergyMinimization ==
false) {
175 }
else if (agg_damping != 0.0 && bEnergyMinimization ==
false) {
177 RCP<SaPFactory> SaPFact = rcp(
new SaPFactory() );
178 SaPFact->SetParameter(
"sa: damping factor", ParameterEntry(agg_damping));
181 }
else if (bEnergyMinimization ==
true) {
187 RCP<RAPFactory> AcFact = rcp(
new RAPFactory() );
199 if (nullspaceType !=
"default vectors") {
200 TEUCHOS_TEST_FOR_EXCEPTION(nullspaceType !=
"pre-computed",
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: no valid nullspace (no pre-computed null space). error.");
201 TEUCHOS_TEST_FOR_EXCEPTION(nullspaceDim == -1,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: no valid nullspace (nullspace dim == -1). error.");
202 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\'");
208 Teuchos::RCP<NullspaceFactory> nspFact = Teuchos::rcp(
new NullspaceFactory());
209 nspFact->SetFactory(
"Nullspace", PtentFact);
221 RCP<SmootherFactory> initSmootherFact = Teuchos::null;
222 if(paramList.isSublist(
"init smoother")) {
223 ParameterList& initList = paramList.sublist(
"init smoother");
226 std::string ifpackType =
"RELAXATION";
227 Teuchos::ParameterList smootherParamList;
228 smootherParamList.set(
"relaxation: type",
"symmetric Gauss-Seidel");
229 smootherParamList.set(
"smoother: sweeps", 1);
230 smootherParamList.set(
"smoother: damping factor", 1.0);
231 RCP<SmootherPrototype> smooProto = rcp(
new TrilinosSmoother(ifpackType, smootherParamList, 0) );
234 initSmootherFact->SetSmootherPrototypes(smooProto, smooProto);
240 ParameterList& coarseList = paramList.sublist(
"coarse: list");
256 for (
int levelID=0; levelID < maxLevels; levelID++) {
273 ParameterList levelSmootherParam =
GetMLSubList(paramList,
"smoother", levelID);
280 manager->SetFactory(
"Smoother", smootherFact);
281 smootherFact->DisableMultipleCallCheck();
283 initmanager->SetFactory(
"Smoother", initSmootherFact);
284 initmanager->SetFactory(
"CoarseSolver", initSmootherFact);
285 initSmootherFact->DisableMultipleCallCheck();
302 manager->SetFactory(
"CoarseSolver", coarseFact);
303 manager->SetFactory(
"Graph", dropFact);
304 manager->SetFactory(
"Aggregates", CoupledAggFact);
305 manager->SetFactory(
"DofsPerNode", dropFact);
306 manager->SetFactory(
"A", AcFact);
307 manager->SetFactory(
"P", PFact);
308 manager->SetFactory(
"Ptent", PtentFact);
309 manager->SetFactory(
"R", RFact);
310 manager->SetFactory(
"Nullspace", nspFact);
313 initmanager->SetFactory(
"Graph", dropFact);
314 initmanager->SetFactory(
"Aggregates", CoupledAggFact);
315 initmanager->SetFactory(
"DofsPerNode", dropFact);
316 initmanager->SetFactory(
"A", AcFact);
317 initmanager->SetFactory(
"P", PtentFact);
318 initmanager->SetFactory(
"Ptent", PtentFact);
319 initmanager->SetFactory(
"R", RFact);
320 initmanager->SetFactory(
"Nullspace", nspFact);
327 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
332 RCP<Operator> Op = l->Get<RCP<Operator> >(
"A");
341 bool isLastLevel =
false;
343 while(!isLastLevel) {
344 bool r = H.
Setup(levelID,
349 isLastLevel = r || (levelID == lastLevelID);
354 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
361 RCP<Level> fineLevel = H.
GetLevel(0);
362 const RCP<const Map> rowMap = fineLevel->Get< RCP<Matrix> >(
"A")->getRowMap();
363 RCP<MultiVector> nullspace = MultiVectorFactory::Build(rowMap,
nullspaceDim_,
true);
365 for (
size_t i=0; i < Teuchos::as<size_t>(
nullspaceDim_); i++) {
366 Teuchos::ArrayRCP<Scalar> nullspacei = nullspace->getDataNonConst(i);
367 const size_t myLength = nullspace->getLocalLength();
369 for (
size_t j = 0; j < myLength; j++) {
374 fineLevel->Set(
"Nullspace", nullspace);
387 Teuchos::RCP<MueLu::Level> Finest = H.
GetLevel(0);
388 Teuchos::RCP<MultiVector> nspVector2 = Finest->Get<Teuchos::RCP<MultiVector> >(
"Nullspace");
392 RCP<Matrix> Op = Finest->Get<RCP<Matrix> >(
"A");
396 Teuchos::RCP<MultiVector> homogRhsVec = MultiVectorFactory::Build(nspVector2->getMap(),nspVector2->getNumVectors(),
true);
397 homogRhsVec->putScalar(0.0);
402 H.
Iterate(*homogRhsVec, *nspVector2, 1,
false);
405 Finest->Set(
"Nullspace",nspVector2);
432 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
435 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!");
439 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
444 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
447 Matrix& A =
dynamic_cast<Matrix&
>(Op);
448 if (A.GetFixedBlockSize() !=
blksize_)
450 <<
"instead of " << A.GetFixedBlockSize() <<
" (provided matrix)." << std::endl;
454 }
catch (std::bad_cast& e) {
455 this->
GetOStream(
Warnings0) <<
"Skipping setting block size as the operator is not a matrix" << std::endl;
virtual void SetupExtra(Hierarchy &H) const
Setup extra data.
Important warning messages (one line)
Generic Smoother Factory for generating the smoothers of the MG hierarchy.
Exception indicating invalid cast attempted.
This class specifies the default factory that should generate some data on a Level if the data does n...
void MergeParameterList(const Teuchos::ParameterList &source, Teuchos::ParameterList &dest, bool overWrite)
: merge two parameter lists
int blksize_
Matrix configuration storage.
static void Write(const std::string &fileName, const Map &M)
Read/Write methods.
RCP< Level > & GetLevel(const int levelID=0)
Retrieve a certain level from hierarchy.
void SetVerbLevel(const VerbLevel verbLevel)
Set the verbosity level of this object.
void SetParameterList(const Teuchos::ParameterList ¶mList)
Class that encapsulates external library smoothers.
void SetMaxCoarseSize(Xpetra::global_size_t maxCoarseSize)
int nullspaceDim_
nullspace can be embedded in the ML parameter list
VerbLevel toMueLuVerbLevel(const Teuchos::EVerbosityLevel verbLevel)
AdaptiveSaMLParameterListInterpreter()
Constructor.
void AddFactoryManager(int startLevel, int numDesiredLevel, RCP< FactoryManagerBase > manager)
Base class for factories that use two levels (fineLevel and coarseLevel).
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.
Namespace for MueLu classes and methods.
const Teuchos::ParameterList & GetMLSubList(const Teuchos::ParameterList ¶mList, const std::string &type, int levelID)
Teuchos::RCP< FactoryManagerBase > InitLvlMngr(int levelID, int lastLevelID) const
Factory for building tentative prolongator.
Factory for coarsening a graph with uncoupled aggregation.
virtual void SetupOperator(Operator &Op) const
Factory for building restriction operators using a prolongator factory.
void CreateSublists(const ParameterList &List, ParameterList &newList)
size_t getNumFactoryManagers() const
returns number of factory managers stored in levelManagers_ vector.
void AddTransferFactory(const RCP< FactoryBase > &factory)
Add transfer factory in the end of list of transfer factories for RAPFactory.
size_t NumTransferFactories() const
Returns number of transfer factories.
static RCP< SmootherFactory > GetSmootherFactory(const Teuchos::ParameterList ¶mList, const RCP< FactoryBase > &AFact=Teuchos::null)
Read smoother options and build the corresponding smoother factory.
Teuchos::RCP< Teuchos::ParameterList > ExtractSetOfParameters(const Teuchos::ParameterList ¶mList, const std::string &str)
RCP< FactoryManagerBase > GetFactoryManager(int levelID) const
void SetupInitHierarchy(Hierarchy &H) const
Teuchos::FancyOStream & GetOStream(MsgType type, int thisProcRankOnly=0) const
Get an output stream for outputting the input message type.
Factory for creating a graph base on a given matrix.
std::vector< RCP< FactoryBase > > TransferFacts_
An exception safe way to call the method TwoLevelFactoryBase::DisableMultipleCallCheck.
Factory for building restriction operators.
Exception throws to report errors in the internal logical of the program.
Factory that provides an interface for a concrete implementation of a prolongation operator...
ReturnType Iterate(const MultiVector &B, MultiVector &X, ConvData conv=ConvData(), bool InitialGuessIsZero=false, LO startLevel=0)
Apply the multigrid preconditioner.
void Keep(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Call Level::Keep(ename, factory) for each level of the Hierarchy.
Factory for building coarse matrices.
Factory for building Petrov-Galerkin Smoothed Aggregation prolongators.
Factory for building Smoothed Aggregation prolongators.Input/output of SaPFactory
Xpetra::global_size_t maxCoarseSize_
#define MUELU_READ_PARAM(paramList, paramStr, varType, defaultValue, varName)
Factory for building uncoupled aggregates.
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.
void AddInitFactoryManager(int startLevel, int numDesiredLevel, RCP< FactoryManagerBase > manager)
internal routine to add a new factory manager used for the initialization phase
Base class for factories that use one level (currentLevel).
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
Factory for generating nullspace.
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.