46 #ifndef MUELU_MLPARAMETERLISTINTERPRETER_DEF_HPP
47 #define MUELU_MLPARAMETERLISTINTERPRETER_DEF_HPP
52 #if defined(HAVE_MUELU_ML)
53 #include <ml_ValidateParameters.h>
59 #include <Xpetra_MultiVectorFactory.hpp>
65 #include "MueLu_Hierarchy.hpp"
66 #include "MueLu_FactoryManager.hpp"
68 #include "MueLu_TentativePFactory.hpp"
69 #include "MueLu_SaPFactory.hpp"
70 #include "MueLu_PgPFactory.hpp"
71 #include "MueLu_AmalgamationFactory.hpp"
72 #include "MueLu_TransPFactory.hpp"
73 #include "MueLu_GenericRFactory.hpp"
74 #include "MueLu_SmootherPrototype.hpp"
75 #include "MueLu_SmootherFactory.hpp"
76 #include "MueLu_TrilinosSmoother.hpp"
78 #include "MueLu_DirectSolver.hpp"
79 #include "MueLu_HierarchyUtils.hpp"
80 #include "MueLu_RAPFactory.hpp"
81 #include "MueLu_CoalesceDropFactory.hpp"
82 #include "MueLu_UncoupledAggregationFactory.hpp"
83 #include "MueLu_NullspaceFactory.hpp"
86 #include "MueLu_CoalesceDropFactory_kokkos.hpp"
88 #include "MueLu_TentativePFactory_kokkos.hpp"
90 #if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
91 #include "MueLu_IsorropiaInterface.hpp"
92 #include "MueLu_RepartitionHeuristicFactory.hpp"
93 #include "MueLu_RepartitionFactory.hpp"
94 #include "MueLu_RebalanceTransferFactory.hpp"
95 #include "MueLu_RepartitionInterface.hpp"
96 #include "MueLu_RebalanceAcFactory.hpp"
106 #define MUELU_READ_PARAM(paramList, paramStr, varType, defaultValue, varName) \
107 varType varName = defaultValue; \
108 if (paramList.isParameter(paramStr)) varName = paramList.get<varType>(paramStr);
111 #define MUELU_COPY_PARAM(paramList, paramStr, varType, defaultValue, outParamList, outParamStr) \
112 if (paramList.isParameter(paramStr)) \
113 outParamList.set(outParamStr, paramList.get<varType>(paramStr)); \
115 outParamList.set(outParamStr, static_cast<varType>(defaultValue));
119 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
125 , TransferFacts_(factoryList)
128 std::string filename = paramList.
get(
"xml parameter file",
"");
129 if (filename.length() != 0) {
133 paramList2.remove(
"xml parameter file");
141 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
144 , TransferFacts_(factoryList)
150 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
165 MUELU_READ_PARAM(paramList,
"aggregation: type", std::string,
"Uncoupled", agg_type);
167 MUELU_READ_PARAM(paramList,
"aggregation: damping factor",
double, (
double)4 / (
double)3, agg_damping);
169 MUELU_READ_PARAM(paramList,
"aggregation: nodes per aggregate",
int, 1, minPerAgg);
170 MUELU_READ_PARAM(paramList,
"aggregation: keep Dirichlet bcs",
bool,
false, bKeepDirichletBcs);
171 MUELU_READ_PARAM(paramList,
"aggregation: max neighbours already aggregated",
int, 0, maxNbrAlreadySelected);
172 MUELU_READ_PARAM(paramList,
"aggregation: aux: enable",
bool,
false, agg_use_aux);
173 MUELU_READ_PARAM(paramList,
"aggregation: aux: threshold",
double,
false, agg_aux_thresh);
175 MUELU_READ_PARAM(paramList,
"null space: type", std::string,
"default vectors", nullspaceType);
176 MUELU_READ_PARAM(paramList,
"null space: dimension",
int, -1, nullspaceDim);
177 MUELU_READ_PARAM(paramList,
"null space: vectors",
double*, NULL, nullspaceVec);
179 MUELU_READ_PARAM(paramList,
"energy minimization: enable",
bool,
false, bEnergyMinimization);
181 MUELU_READ_PARAM(paramList,
"RAP: fix diagonal",
bool,
false, bFixDiagonal);
195 paramList = paramListWithSubList;
198 bool setKokkosRefactor =
false;
199 bool useKokkosRefactor = !Node::is_serial;
200 if (paramList.
isType<
bool>(
"use kokkos refactor")) {
201 useKokkosRefactor = paramList.
get<
bool>(
"use kokkos refactor");
202 setKokkosRefactor =
true;
203 paramList.
remove(
"use kokkos refactor");
211 bool validate = paramList.
get(
"ML validate parameter list",
true);
213 #if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA)
215 int depth = paramList.
get(
"ML validate depth", 5);
217 "ERROR: ML's Teuchos::ParameterList contains incorrect parameter!");
220 this->GetOStream(
Warnings0) <<
"Warning: MueLu_ENABLE_ML=OFF. The parameter list cannot be validated." << std::endl;
221 paramList.
set(
"ML validate parameter list",
false);
223 #endif // HAVE_MUELU_ML
228 blksize_ = nDofsPerNode;
234 if (verbosityLevel == 0) eVerbLevel =
None;
235 if (verbosityLevel >= 1) eVerbLevel =
Low;
236 if (verbosityLevel >= 5) eVerbLevel =
Medium;
237 if (verbosityLevel >= 10) eVerbLevel =
High;
238 if (verbosityLevel >= 11) eVerbLevel =
Extreme;
239 if (verbosityLevel >= 42) eVerbLevel =
Test;
241 this->verbosity_ = eVerbLevel;
244 "MueLu::MLParameterListInterpreter::SetParameterList(): parameter \"aggregation: type\": only 'Uncoupled' aggregation is supported.");
248 if (useKokkosRefactor)
269 if (verbosityLevel > 3) {
270 std::ostringstream oss;
271 oss <<
"========================= Aggregate option summary  =========================" << std::endl;
272 oss <<
"min Nodes per aggregate : Â Â Â Â Â Â Â " << minPerAgg << std::endl;
273 oss <<
"min # of root nbrs already aggregated : " << maxNbrAlreadySelected << std::endl;
274 oss <<
"aggregate ordering : Â Â Â Â Â Â Â Â Â Â natural" << std::endl;
275 oss <<
"=============================================================================" << std::endl;
276 this->GetOStream(
Runtime1) << oss.str();
282 if (useKokkosRefactor)
286 if (agg_damping == 0.0 && bEnergyMinimization ==
false) {
290 }
else if (agg_damping != 0.0 && bEnergyMinimization ==
false) {
296 }
else if (bEnergyMinimization ==
true) {
304 for (
size_t i = 0; i < TransferFacts_.size(); i++) {
311 #if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
318 if (bDoRepartition == 1) {
328 rebAmalgFact->SetFactory(
"A", AcFact);
330 MUELU_READ_PARAM(paramList,
"repartition: max min ratio",
double, 1.3, maxminratio);
331 MUELU_READ_PARAM(paramList,
"repartition: min per proc",
int, 512, minperproc);
337 paramListRepFact.
set(
"repartition: min rows per proc", minperproc);
338 paramListRepFact.
set(
"repartition: max imbalance", maxminratio);
341 RepartitionHeuristicFact->
SetFactory(
"A", AcFact);
345 isoInterface->SetFactory(
"A", AcFact);
346 isoInterface->SetFactory(
"number of partitions", RepartitionHeuristicFact);
347 isoInterface->SetFactory(
"UnAmalgamationInfo", rebAmalgFact);
351 repInterface->SetFactory(
"A", AcFact);
352 repInterface->SetFactory(
"number of partitions", RepartitionHeuristicFact);
353 repInterface->SetFactory(
"AmalgamatedPartition", isoInterface);
359 RepartitionFact->
SetFactory(
"number of partitions", RepartitionHeuristicFact);
360 RepartitionFact->
SetFactory(
"Partition", repInterface);
366 RebalancedPFact->
SetFactory(
"Nullspace", PtentFact);
367 RebalancedPFact->
SetFactory(
"Importer", RepartitionFact);
372 RebalancedRFact->
SetFactory(
"Importer", RepartitionFact);
378 #else // #ifdef HAVE_MUELU_ISORROPIA
392 if (nullspaceType !=
"default vectors") {
397 nullspaceDim_ = nullspaceDim;
398 nullspace_ = nullspaceVec;
414 this->numDesiredLevel_ = maxLevels;
415 this->maxCoarseSize_ = maxCoarseSize;
423 coarseList.
set(
"smoother: type",
"Amesos-KLU");
435 for (
int levelID = 0; levelID < maxLevels; levelID++) {
441 if (setKokkosRefactor)
459 manager->
SetFactory(
"Smoother", smootherFact);
466 manager->
SetFactory(
"CoarseSolver", coarseFact);
472 #if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
473 if (bDoRepartition == 1) {
477 manager->
SetFactory(
"Nullspace", RebalancedPFact);
478 manager->
SetFactory(
"Importer", RepartitionFact);
480 #endif // #ifdef HAVE_MUELU_ISORROPIA
485 #if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
489 this->AddFactoryManager(levelID, 1, manager);
493 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
497 if (nullspace_ != NULL) {
503 RCP<MultiVector> nullspace = MultiVectorFactory::Build(rowMap, nullspaceDim_,
true);
505 for (
size_t i = 0; i < Teuchos::as<size_t>(nullspaceDim_); i++) {
507 const size_t myLength = nullspace->getLocalLength();
509 for (
size_t j = 0; j < myLength; j++) {
510 nullspacei[j] = nullspace_[i * myLength + j];
514 fineLevel->
Set(
"Nullspace", nullspace);
519 size_t num_coords = 0;
522 coordPTR[0] = xcoord_;
525 coordPTR[1] = ycoord_;
528 coordPTR[2] = zcoord_;
541 for (
size_t i = 0; i < num_coords; i++) {
543 const size_t myLength = coordinates->getLocalLength();
544 for (
size_t j = 0; j < myLength; j++) {
545 coordsi[j] = coordPTR[i][j];
548 fineLevel->
Set(
"Coordinates", coordinates);
556 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
564 std::string type =
"symmetric Gauss-Seidel";
585 if (paramList.
isParameter(
"smoother: type")) type = paramList.
get<std::string>(
"smoother: type");
594 std::string ifpackType;
597 if (type ==
"Jacobi" || type ==
"Gauss-Seidel" || type ==
"symmetric Gauss-Seidel") {
598 if (type ==
"symmetric Gauss-Seidel") type =
"Symmetric Gauss-Seidel";
600 ifpackType =
"RELAXATION";
601 smootherParamList.
set(
"relaxation: type", type);
603 MUELU_COPY_PARAM(paramList,
"smoother: sweeps",
int, 2, smootherParamList,
"relaxation: sweeps");
604 MUELU_COPY_PARAM(paramList,
"smoother: damping factor",
Scalar, one, smootherParamList,
"relaxation: damping factor");
607 smooProto->SetFactory(
"A", AFact);
609 }
else if (type ==
"Chebyshev" || type ==
"MLS") {
610 ifpackType =
"CHEBYSHEV";
612 MUELU_COPY_PARAM(paramList,
"smoother: sweeps",
int, 2, smootherParamList,
"chebyshev: degree");
613 if (paramList.
isParameter(
"smoother: MLS alpha")) {
614 MUELU_COPY_PARAM(paramList,
"smoother: MLS alpha",
double, 20, smootherParamList,
"chebyshev: ratio eigenvalue");
616 MUELU_COPY_PARAM(paramList,
"smoother: Chebyshev alpha",
double, 20, smootherParamList,
"chebyshev: ratio eigenvalue");
620 smooProto->SetFactory(
"A", AFact);
622 }
else if (type ==
"Hiptmair") {
623 ifpackType =
"HIPTMAIR";
624 std::string subSmootherType =
"Chebyshev";
626 subSmootherType = paramList.
get<std::string>(
"subsmoother: type");
627 std::string subSmootherIfpackType;
628 if (subSmootherType ==
"Chebyshev")
629 subSmootherIfpackType =
"CHEBYSHEV";
630 else if (subSmootherType ==
"Jacobi" || subSmootherType ==
"Gauss-Seidel" || subSmootherType ==
"symmetric Gauss-Seidel") {
631 if (subSmootherType ==
"symmetric Gauss-Seidel") subSmootherType =
"Symmetric Gauss-Seidel";
632 subSmootherIfpackType =
"RELAXATION";
636 smootherParamList.
set(
"hiptmair: smoother type 1", subSmootherIfpackType);
637 smootherParamList.
set(
"hiptmair: smoother type 2", subSmootherIfpackType);
639 auto smoother1ParamList = smootherParamList.
sublist(
"hiptmair: smoother list 1");
640 auto smoother2ParamList = smootherParamList.
sublist(
"hiptmair: smoother list 2");
642 if (subSmootherType ==
"Chebyshev") {
643 MUELU_COPY_PARAM(paramList,
"subsmoother: edge sweeps",
int, 2, smoother1ParamList,
"chebyshev: degree");
644 MUELU_COPY_PARAM(paramList,
"subsmoother: node sweeps",
int, 2, smoother2ParamList,
"chebyshev: degree");
646 MUELU_COPY_PARAM(paramList,
"subsmoother: Chebyshev",
double, 20, smoother1ParamList,
"chebyshev: ratio eigenvalue");
647 MUELU_COPY_PARAM(paramList,
"subsmoother: Chebyshev",
double, 20, smoother2ParamList,
"chebyshev: ratio eigenvalue");
649 MUELU_COPY_PARAM(paramList,
"subsmoother: edge sweeps",
int, 2, smoother1ParamList,
"relaxation: sweeps");
650 MUELU_COPY_PARAM(paramList,
"subsmoother: node sweeps",
int, 2, smoother2ParamList,
"relaxation: sweeps");
652 MUELU_COPY_PARAM(paramList,
"subsmoother: SGS damping factor",
double, 0.8, smoother2ParamList,
"relaxation: damping factor");
656 smooProto->SetFactory(
"A", AFact);
658 }
else if (type ==
"IFPACK") {
660 #if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_IFPACK)
661 ifpackType = paramList.
get<std::string>(
"smoother: ifpack type");
663 if (ifpackType ==
"ILU") {
666 if (paramList.
isParameter(
"smoother: ifpack level-of-fill"))
667 smootherParamList.
set(
"fact: level-of-fill", Teuchos::as<int>(paramList.
get<
double>(
"smoother: ifpack level-of-fill")));
669 smootherParamList.
set(
"fact: level-of-fill", as<int>(0));
671 MUELU_COPY_PARAM(paramList,
"smoother: ifpack overlap",
int, 2, smootherParamList,
"partitioner: overlap");
675 MueLu::GetIfpackSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>(ifpackType,
677 paramList.
get<
int>(
"smoother: ifpack overlap"));
678 smooProto->SetFactory(
"A", AFact);
686 }
else if (type.length() > strlen(
"Amesos") && type.substr(0, strlen(
"Amesos")) ==
"Amesos") {
687 std::string solverType = type.substr(strlen(
"Amesos") + 1);
691 const int validatorSize = 5;
692 std::string validator[validatorSize] = {
"Superlu",
"Superludist",
"KLU",
"UMFPACK",
"MUMPS"};
693 for (
int i = 0; i < validatorSize; i++) {
694 if (validator[i] == solverType) valid =
true;
699 std::transform(solverType.begin() + 1, solverType.end(), solverType.begin() + 1,
::tolower);
702 smooProto->SetFactory(
"A", AFact);
716 MUELU_READ_PARAM(paramList,
"smoother: pre or post", std::string,
"both", preOrPost);
717 if (preOrPost ==
"both") {
719 }
else if (preOrPost ==
"pre") {
721 }
else if (preOrPost ==
"post") {
728 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
731 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!");
732 TransferFacts_.push_back(factory);
735 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
737 return TransferFacts_.size();
740 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
743 Matrix& A =
dynamic_cast<Matrix&
>(Op);
744 if (A.IsFixedBlockSizeSet() && (A.GetFixedBlockSize() != blksize_))
745 this->GetOStream(
Warnings0) <<
"Setting matrix block size to " << blksize_ <<
" (value of the parameter in the list) "
746 <<
"instead of " << A.GetFixedBlockSize() <<
" (provided matrix)." << std::endl;
748 A.SetFixedBlockSize(blksize_);
750 #ifdef HAVE_MUELU_DEBUG
751 MatrixUtils::checkLocalRowMapMatchesColMap(A);
752 #endif // HAVE_MUELU_DEBUG
754 }
catch (std::bad_cast&) {
755 this->GetOStream(
Warnings0) <<
"Skipping setting block size as the operator is not a matrix" << std::endl;
761 #define MUELU_MLPARAMETERLISTINTERPRETER_SHORT
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
MLParameterListInterpreter()
Constructor.
Factory for determing the number of partitions for rebalancing.
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.
T & get(const std::string &name, T def_value)
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)
Interface to IsorropiaInterface to Isorropia allowing to access other rebalancing/repartitioning algo...
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Factory for building permutation matrix that can be be used to shuffle data (matrices, vectors) among processes.
void SetKokkosRefactor(const bool useKokkos)
std::string tolower(const std::string &str)
void AddTransferFactory(const RCP< const FactoryBase > &factory)
Add transfer factory in the end of list of transfer factories in RepartitionAcFactory.
#define MUELU_READ_PARAM(paramList, paramStr, varType, defaultValue, varName)
const Teuchos::ParameterList & GetMLSubList(const Teuchos::ParameterList ¶mList, const std::string &type, int levelID)
void AddTransferFactory(const RCP< FactoryBase > &factory)
Add transfer factory in the end of list of transfer factories for RAPFactory.
Factory for building tentative prolongator.
Class that encapsulates direct solvers. Autoselection of AmesosSmoother or Amesos2Smoother according ...
Factory for building restriction operators using a prolongator factory.
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.
bool isParameter(const std::string &name) const
void CreateSublists(const ParameterList &List, ParameterList &newList)
bool remove(std::string const &name, bool throwIfNotExists=true)
virtual void SetParameterList(const Teuchos::ParameterList ¶mList)
Set parameters from a parameter list and return with default values.
void SetSmootherPrototypes(RCP< SmootherPrototype > preAndPostSmootherPrototype)
Set smoother prototypes.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
MueLu::DefaultScalar Scalar
static RCP< SmootherFactory > GetSmootherFactory(const Teuchos::ParameterList ¶mList, const RCP< FactoryBase > &AFact=Teuchos::null)
Read smoother options and build the corresponding smoother factory.
virtual void SetupOperator(Operator &Op) const
Setup Operator object.
Teuchos::RCP< Teuchos::ParameterList > ExtractSetOfParameters(const Teuchos::ParameterList ¶mList, const std::string &str)
size_t NumTransferFactories() const
Returns number of transfer factories.
AmalgamationFactory for subblocks of strided map based amalgamation data.
Applies permutation to grid transfer operators.
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 based on a given matrix.
Helper class which transforms an "AmalgamatedPartition" array to an unamalgamated "Partition"...
void SetParameterList(const Teuchos::ParameterList ¶mList)
virtual void SetFactory(const std::string &varName, const RCP< const FactoryBase > &factory)=0
Configuration.
bool isType(const std::string &name) const
Factory for building restriction operators.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
Factory for creating a graph based on a given matrix.
Factory for building coarse matrices.
Exception throws to report errors in the internal logical of the program.
Description of what is happening (more verbose)
Factory for building coarse matrices.
#define MUELU_COPY_PARAM(paramList, paramStr, varType, defaultValue, outParamList, outParamStr)
Factory for building Petrov-Galerkin Smoothed Aggregation prolongators.
Factory for building Smoothed Aggregation prolongators.Input/output of SaPFactory
Factory for building uncoupled aggregates.
Provides methods to build a multigrid hierarchy and apply multigrid cycles.
Factory for generating nullspace.
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.