Go to the documentation of this file.
8 #ifndef MUELU_ADAPTIVESAMLPARAMETERLISTINTERPRETER_DEF_HPP_
9 #define MUELU_ADAPTIVESAMLPARAMETERLISTINTERPRETER_DEF_HPP_
14 #if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA)
15 #include <ml_ValidateParameters.h>
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"
39 #include "MueLu_DirectSolver.hpp"
40 #include "MueLu_HierarchyUtils.hpp"
41 #include "MueLu_RAPFactory.hpp"
42 #include "MueLu_CoalesceDropFactory.hpp"
43 #include "MueLu_CoupledAggregationFactory.hpp"
44 #include "MueLu_UncoupledAggregationFactory.hpp"
45 #include "MueLu_HybridAggregationFactory.hpp"
46 #include "MueLu_NullspaceFactory.hpp"
48 #include "MueLu_MLParameterListInterpreter.hpp"
60 #define MUELU_READ_PARAM(paramList, paramStr, varType, defaultValue, varName) \
61 varType varName = defaultValue; if (paramList.isParameter(paramStr)) varName = paramList.get<varType>(paramStr);
64 #define MUELU_COPY_PARAM(paramList, paramStr, varType, defaultValue, outParamList, outParamStr) \
65 if (paramList.isParameter(paramStr)) \
66 outParamList.set<varType>(outParamStr, paramList.get<varType>(paramStr)); \
67 else outParamList.set<varType>(outParamStr, defaultValue); \
71 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
76 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
82 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
99 MUELU_READ_PARAM(paramList,
"aggregation: type", std::string,
"Uncoupled", agg_type);
101 MUELU_READ_PARAM(paramList,
"aggregation: damping factor",
double, (
double)4/(
double)3, agg_damping);
103 MUELU_READ_PARAM(paramList,
"aggregation: nodes per aggregate",
int, 1, minPerAgg);
105 MUELU_READ_PARAM(paramList,
"null space: type", std::string,
"default vectors", nullspaceType);
106 MUELU_READ_PARAM(paramList,
"null space: dimension",
int, -1, nullspaceDim);
107 MUELU_READ_PARAM(paramList,
"null space: vectors",
double*, NULL, nullspaceVec);
109 MUELU_READ_PARAM(paramList,
"energy minimization: enable",
bool,
false, bEnergyMinimization);
120 paramList = paramListWithSubList;
125 int maxNbrAlreadySelected = 0;
128 this->blksize_ = nDofsPerNode;
146 if(agg_type ==
"Uncoupled") {
152 CoupledAggFact = CoupledAggFact2;
160 CoupledAggFact = CoupledAggFact2;
162 if (verbosityLevel > 3) {
163 *out <<
"========================= Aggregate option summary =========================" << std::endl;
164 *out <<
"min Nodes per aggregate : " << minPerAgg << std::endl;
165 *out <<
"min # of root nbrs already aggregated : " << maxNbrAlreadySelected << std::endl;
166 *out <<
"aggregate ordering : natural" << std::endl;
167 *out <<
"=============================================================================" << std::endl;
173 if (agg_damping == 0.0 && bEnergyMinimization ==
false) {
177 }
else if (agg_damping != 0.0 && bEnergyMinimization ==
false) {
183 }
else if (bEnergyMinimization ==
true) {
190 for (
size_t i = 0; i<TransferFacts_.size(); i++) {
201 if (nullspaceType !=
"default vectors") {
206 nullspaceDim_ = nullspaceDim;
207 nullspace_ = nullspaceVec;
219 this->numDesiredLevel_ = maxLevels;
220 this->maxCoarseSize_ = maxCoarseSize;
224 if(paramList.
isSublist(
"init smoother")) {
228 std::string ifpackType =
"RELAXATION";
230 smootherParamList.
set(
"relaxation: type",
"symmetric Gauss-Seidel");
231 smootherParamList.
set(
"smoother: sweeps", 1);
232 smootherParamList.
set(
"smoother: damping factor", 1.0);
258 for (
int levelID=0; levelID < maxLevels; levelID++) {
282 manager->
SetFactory(
"Smoother", smootherFact);
285 initmanager->
SetFactory(
"Smoother", initSmootherFact);
286 initmanager->
SetFactory(
"CoarseSolver", initSmootherFact);
295 Teuchos::rcp_dynamic_cast<PFactory>(PFact)->DisableMultipleCallCheck();
296 Teuchos::rcp_dynamic_cast<PFactory>(PtentFact)->DisableMultipleCallCheck();
297 Teuchos::rcp_dynamic_cast<TwoLevelFactoryBase>(RFact)->DisableMultipleCallCheck();
298 Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(coarseFact)->DisableMultipleCallCheck();
299 Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(dropFact)->DisableMultipleCallCheck();
300 Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(CoupledAggFact)->DisableMultipleCallCheck();
301 Teuchos::rcp_dynamic_cast<TwoLevelFactoryBase>(AcFact)->DisableMultipleCallCheck();
302 Teuchos::rcp_dynamic_cast<SingleLevelFactoryBase>(nspFact)->DisableMultipleCallCheck();
304 manager->
SetFactory(
"CoarseSolver", coarseFact);
306 manager->
SetFactory(
"Aggregates", CoupledAggFact);
316 initmanager->
SetFactory(
"Aggregates", CoupledAggFact);
317 initmanager->
SetFactory(
"DofsPerNode", dropFact);
322 initmanager->
SetFactory(
"Nullspace", nspFact);
324 this->AddFactoryManager(levelID, 1, manager);
325 this->AddInitFactoryManager(levelID, 1, initmanager);
329 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
342 int lastLevelID = this->numDesiredLevel_ - 1;
343 bool isLastLevel =
false;
345 while(!isLastLevel) {
346 bool r = H.
Setup(levelID,
347 InitLvlMngr(levelID-1, lastLevelID),
348 InitLvlMngr(levelID, lastLevelID),
349 InitLvlMngr(levelID+1, lastLevelID));
351 isLastLevel = r || (levelID == lastLevelID);
356 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
362 if (this->nullspace_ != NULL) {
365 RCP<MultiVector> nullspace = MultiVectorFactory::Build(rowMap, nullspaceDim_,
true);
367 for (
size_t i=0; i < Teuchos::as<size_t>(nullspaceDim_); i++) {
369 const size_t myLength = nullspace->getLocalLength();
371 for (
size_t j = 0; j < myLength; j++) {
372 nullspacei[j] = nullspace_[i*myLength + j];
376 fineLevel->
Set(
"Nullspace", nullspace);
385 SetupInitHierarchy(H);
398 Teuchos::RCP<MultiVector> homogRhsVec = MultiVectorFactory::Build(nspVector2->getMap(),nspVector2->getNumVectors(),
true);
399 homogRhsVec->putScalar(0.0);
404 H.
Iterate(*homogRhsVec, *nspVector2, 1,
false);
407 Finest->
Set(
"Nullspace",nspVector2);
434 template <
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!");
438 TransferFacts_.push_back(factory);
441 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
443 return TransferFacts_.size();
446 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
449 Matrix& A = dynamic_cast<Matrix&>(Op);
450 if (A.GetFixedBlockSize() != blksize_)
451 this->GetOStream(
Warnings0) <<
"Setting matrix block size to " << blksize_ <<
" (value of the parameter in the list) "
452 <<
"instead of " << A.GetFixedBlockSize() <<
" (provided matrix)." << std::endl;
454 A.SetFixedBlockSize(blksize_);
456 }
catch (std::bad_cast& e) {
457 this->GetOStream(
Warnings0) <<
"Skipping setting block size as the operator is not a matrix" << std::endl;
void SetMinNodesPerAggregate(int minNodesPerAggregate)
Factory for building restriction operators using a prolongator factory.
void SetMaxNeighAlreadySelected(int maxNeighAlreadySelected)
void SetParameter(const std::string &name, const ParameterEntry &entry)
Set a parameter directly as a ParameterEntry.
Factory for generating nullspace.
void SetOrdering(const std::string &ordering)
static void Write(const std::string &fileName, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &M)
Class that encapsulates external library smoothers.
#define MUELU_READ_PARAM(paramList, paramStr, varType, defaultValue, varName)
void CreateSublists(const ParameterList &List, ParameterList &newList)
void SetOrdering(const std::string &ordering)
const Teuchos::ParameterList & GetMLSubList(const Teuchos::ParameterList ¶mList, const std::string &type, int levelID)
Important warning messages (one line)
void SetParameterList(const Teuchos::ParameterList ¶mList)
Factory for building uncoupled aggregates.
RCP< FactoryManagerBase > GetFactoryManager(int levelID) const
RCP< Level > & GetLevel(const int levelID=0)
Retrieve a certain level from hierarchy.
void DisableMultipleCallCheck() const
VerbLevel toMueLuVerbLevel(const Teuchos::EVerbosityLevel verbLevel)
void Keep(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Call Level::Keep(ename, factory) for each level of the Hierarchy.
Exception indicating invalid cast attempted.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
Namespace for MueLu classes and methods.
Teuchos::RCP< Teuchos::ParameterList > ExtractSetOfParameters(const Teuchos::ParameterList ¶mList, const std::string &str)
void SetFactory(const std::string &varName, const RCP< const FactoryBase > &factory)
Set Factory.
Factory for coarsening a graph with uncoupled aggregation.
ReturnType Iterate(const MultiVector &B, MultiVector &X, ConvData conv=ConvData(), bool InitialGuessIsZero=false, LO startLevel=0)
Apply the multigrid preconditioner.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
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.
bool isSublist(const std::string &name) const
virtual void SetFactory(const std::string &varName, const RCP< const FactoryBase > &factory)
Configuration.
size_t NumTransferFactories() const
Returns number of transfer factories.
void SetPhase3AggCreation(double phase3AggCreation)
void SetSmootherPrototypes(RCP< SmootherPrototype > preAndPostSmootherPrototype)
Set smoother prototypes.
Exception throws to report errors in the internal logical of the program.
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access)....
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.
void AddTransferFactory(const RCP< FactoryBase > &factory)
Add transfer factory in the end of list of transfer factories for RAPFactory.
Factory for building restriction operators.
void MergeParameterList(const Teuchos::ParameterList &source, Teuchos::ParameterList &dest, bool overWrite)
: merge two parameter lists
void SetMaxNeighAlreadySelected(int maxNeighAlreadySelected)
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.
Generic Smoother Factory for generating the smoothers of the MG hierarchy.
void Set(const std::string &ename, const T &entry, const FactoryBase *factory=NoFactory::get())
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
void SetMaxCoarseSize(Xpetra::global_size_t maxCoarseSize)
size_t getNumFactoryManagers() const
returns number of factory managers stored in levelManagers_ vector.
static RCP< SmootherFactory > GetSmootherFactory(const Teuchos::ParameterList ¶mList, const RCP< FactoryBase > &AFact=Teuchos::null)
Read smoother options and build the corresponding smoother factory.
AdaptiveSaMLParameterListInterpreter()
Constructor.
Classes::Operator< Scalar, LocalOrdinal, GlobalOrdinal, Node > Operator
void AddTransferFactory(const RCP< const FactoryBase > &factory)
Add transfer factory in the end of list of transfer factories in RepartitionAcFactory.
Factory for building coarse matrices.
Factory for building tentative prolongator.
Factory for building Petrov-Galerkin Smoothed Aggregation prolongators.
void SetupInitHierarchy(Hierarchy &H) const
Factory for building Smoothed Aggregation prolongators.
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
This class specifies the default factory that should generate some data on a Level if the data does n...
void SetMinNodesPerAggregate(int minNodesPerAggregate)
Factory for creating a graph base on a given matrix.
virtual void SetupOperator(Operator &Op) const