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>
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"
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);
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);
392 Xpetra::IO<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Write(
"orig_nsp.vec", *nspVector2);
395 Xpetra::IO<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Write(
"A.mat", *Op);
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);
409 Xpetra::IO<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Write(
"new_nsp.vec", *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;
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
void SetOrdering(const std::string &ordering)
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.
void SetOrdering(const std::string &ordering)
void SetParameterList(const Teuchos::ParameterList ¶mList)
Class that encapsulates external library smoothers.
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
void SetMaxCoarseSize(Xpetra::global_size_t maxCoarseSize)
VerbLevel toMueLuVerbLevel(const Teuchos::EVerbosityLevel verbLevel)
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.
const Teuchos::ParameterList & GetMLSubList(const Teuchos::ParameterList ¶mList, const std::string &type, int levelID)
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 SetPhase3AggCreation(double phase3AggCreation)
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
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)
void SetMaxNeighAlreadySelected(int maxNeighAlreadySelected)
RCP< FactoryManagerBase > GetFactoryManager(int levelID) const
void SetMinNodesPerAggregate(int minNodesPerAggregate)
void SetupInitHierarchy(Hierarchy &H) const
void Set(const std::string &ename, const T &entry, const FactoryBase *factory=NoFactory::get())
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 base on a given matrix.
virtual void SetFactory(const std::string &varName, const RCP< const FactoryBase > &factory)=0
Configuration.
An exception safe way to call the method TwoLevelFactoryBase::DisableMultipleCallCheck.
void SetMinNodesPerAggregate(int minNodesPerAggregate)
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...
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.
#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).
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
Factory for generating nullspace.
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.
void SetMaxNeighAlreadySelected(int maxNeighAlreadySelected)