17 #ifndef MUELU_ADAPTIVESAMLPARAMETERLISTINTERPRETER_DEF_HPP_
18 #define MUELU_ADAPTIVESAMLPARAMETERLISTINTERPRETER_DEF_HPP_
23 #if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA)
24 #include <ml_ValidateParameters.h>
29 #include <Xpetra_MultiVectorFactory.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);
78 namespace AdaptiveDetails {
79 template <
class SC,
class LO,
class GO,
class NO>
83 return Teuchos::rcp_const_cast<SF>(Teuchos::rcp_dynamic_cast<
const SF>(interpreter.
GetFactoryManager(0)->GetFactory(
"Smoother")));
87 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
89 : TransferFacts_(factoryList)
94 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
97 , TransferFacts_(factoryList)
103 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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);
140 paramList = paramListWithSubList;
145 int maxNbrAlreadySelected = 0;
148 this->blksize_ = nDofsPerNode;
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) {
192 }
else if (bEnergyMinimization ==
true) {
199 for (
size_t i = 0; i < TransferFacts_.size(); i++) {
210 if (nullspaceType !=
"default vectors") {
215 nullspaceDim_ = nullspaceDim;
216 nullspace_ = nullspaceVec;
228 this->numDesiredLevel_ = maxLevels;
229 this->maxCoarseSize_ = maxCoarseSize;
233 if (paramList.
isSublist(
"init smoother")) {
235 initSmootherFact = AdaptiveDetails::getSmoother<SC, LO, GO, NO>(initList);
237 std::string ifpackType =
"RELAXATION";
239 smootherParamList.
set(
"relaxation: type",
"symmetric Gauss-Seidel");
240 smootherParamList.
set(
"smoother: sweeps", 1);
241 smootherParamList.
set(
"smoother: damping factor", 1.0);
266 for (
int levelID = 0; levelID < maxLevels; levelID++) {
288 RCP<SmootherFactory> smootherFact = AdaptiveDetails::getSmoother<SC, LO, GO, NO>(levelSmootherParam);
289 manager->
SetFactory(
"Smoother", smootherFact);
292 initmanager->
SetFactory(
"Smoother", initSmootherFact);
293 initmanager->
SetFactory(
"CoarseSolver", initSmootherFact);
310 manager->
SetFactory(
"CoarseSolver", coarseFact);
322 initmanager->
SetFactory(
"Aggregates", AggFact);
323 initmanager->
SetFactory(
"DofsPerNode", dropFact);
328 initmanager->
SetFactory(
"Nullspace", nspFact);
330 this->AddFactoryManager(levelID, 1, manager);
331 this->AddInitFactoryManager(levelID, 1, initmanager);
335 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
348 int lastLevelID = this->numDesiredLevel_ - 1;
349 bool isLastLevel =
false;
351 while (!isLastLevel) {
352 bool r = H.
Setup(levelID,
353 InitLvlMngr(levelID - 1, lastLevelID),
354 InitLvlMngr(levelID, lastLevelID),
355 InitLvlMngr(levelID + 1, lastLevelID));
357 isLastLevel = r || (levelID == lastLevelID);
362 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
367 if (this->nullspace_ != NULL) {
370 RCP<MultiVector> nullspace = MultiVectorFactory::Build(rowMap, nullspaceDim_,
true);
372 for (
size_t i = 0; i < Teuchos::as<size_t>(nullspaceDim_); i++) {
374 const size_t myLength = nullspace->getLocalLength();
376 for (
size_t j = 0; j < myLength; j++) {
377 nullspacei[j] = nullspace_[i * myLength + j];
381 fineLevel->
Set(
"Nullspace", nullspace);
390 SetupInitHierarchy(H);
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);
437 template <
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!");
441 TransferFacts_.push_back(factory);
444 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
446 return TransferFacts_.size();
449 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
452 Matrix& A =
dynamic_cast<Matrix&
>(Op);
453 if (A.IsFixedBlockSizeSet() && (A.GetFixedBlockSize() != blksize_))
454 this->GetOStream(
Warnings0) <<
"Setting matrix block size to " << blksize_ <<
" (value of the parameter in the list) "
455 <<
"instead of " << A.GetFixedBlockSize() <<
" (provided matrix)." << std::endl;
457 A.SetFixedBlockSize(blksize_);
459 }
catch (std::bad_cast& e) {
460 this->GetOStream(
Warnings0) <<
"Skipping setting block size as the operator is not a matrix" << std::endl;
Important warning messages (one line)
Generic Smoother Factory for generating the smoothers of the MG hierarchy.
void DisableMultipleCallCheck() const
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
T & Get(const std::string &ename, const FactoryBase *factory=NoFactory::get())
Get data without decrementing associated storage counter (i.e., read-only access). Usage: Level->Get< RCP<Matrix> >("A", factory) if factory == NULL => use default factory.
RCP< Level > & GetLevel(const int levelID=0)
Retrieve a certain level from hierarchy.
virtual void SetFactory(const std::string &varName, const RCP< const FactoryBase > &factory)
Configuration.
void SetOrdering(const std::string &ordering)
void SetParameterList(const Teuchos::ParameterList ¶mList)
Class that encapsulates external library smoothers.
RCP< FactoryManagerBase > GetFactoryManager(int levelID) const
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
static void Write(const std::string &fileName, const Xpetra::Map< LocalOrdinal, GlobalOrdinal, Node > &M)
void SetMaxCoarseSize(Xpetra::global_size_t maxCoarseSize)
VerbLevel toMueLuVerbLevel(const Teuchos::EVerbosityLevel verbLevel)
Translate Teuchos verbosity level to MueLu verbosity level.
AdaptiveSaMLParameterListInterpreter()
Constructor.
Base class for factories that use two levels (fineLevel and coarseLevel).
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.
void AddTransferFactory(const RCP< const FactoryBase > &factory)
Add transfer factory in the end of list of transfer factories in RepartitionAcFactory.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
const Teuchos::ParameterList & GetMLSubList(const Teuchos::ParameterList ¶mList, const std::string &type, int levelID)
Factory for building tentative prolongator.
ConvergenceStatus Iterate(const MultiVector &B, MultiVector &X, ConvData conv=ConvData(), bool InitialGuessIsZero=false, LO startLevel=0)
Apply the multigrid preconditioner.
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.
void SetSmootherPrototypes(RCP< SmootherPrototype > preAndPostSmootherPrototype)
Set smoother prototypes.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
size_t NumTransferFactories() const
Returns number of transfer factories.
bool isSublist(const std::string &name) const
Teuchos::RCP< Teuchos::ParameterList > ExtractSetOfParameters(const Teuchos::ParameterList ¶mList, const std::string &str)
void SetMaxNeighAlreadySelected(int maxNeighAlreadySelected)
void SetMinNodesPerAggregate(int minNodesPerAggregate)
void SetupInitHierarchy(Hierarchy &H) const
void Set(const std::string &ename, const T &entry, const FactoryBase *factory=NoFactory::get())
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.
void SetParameter(const std::string &name, const ParameterEntry &entry)
Set a parameter directly as a ParameterEntry.
void SetFactory(const std::string &varName, const RCP< const FactoryBase > &factory)
Set Factory.
Factory for creating a graph based on a given matrix.
An exception safe way to call the method TwoLevelFactoryBase::DisableMultipleCallCheck.
Factory for building restriction operators.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
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...
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
#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.
Base class for factories that use one level (currentLevel).
Teuchos::RCP< MueLu::SmootherFactory< SC, LO, GO, NO > > getSmoother(Teuchos::ParameterList &list)
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
Factory for generating nullspace.