10 #ifndef MUELU_MLPARAMETERLISTINTERPRETER_DEF_HPP
11 #define MUELU_MLPARAMETERLISTINTERPRETER_DEF_HPP
16 #if defined(HAVE_MUELU_ML)
17 #include <ml_ValidateParameters.h>
23 #include <Xpetra_MultiVectorFactory.hpp>
29 #include "MueLu_Hierarchy.hpp"
30 #include "MueLu_FactoryManager.hpp"
32 #include "MueLu_TentativePFactory.hpp"
33 #include "MueLu_SaPFactory.hpp"
34 #include "MueLu_PgPFactory.hpp"
35 #include "MueLu_AmalgamationFactory.hpp"
36 #include "MueLu_TransPFactory.hpp"
37 #include "MueLu_GenericRFactory.hpp"
38 #include "MueLu_SmootherPrototype.hpp"
39 #include "MueLu_SmootherFactory.hpp"
40 #include "MueLu_TrilinosSmoother.hpp"
42 #include "MueLu_DirectSolver.hpp"
43 #include "MueLu_HierarchyUtils.hpp"
44 #include "MueLu_RAPFactory.hpp"
45 #include "MueLu_CoalesceDropFactory.hpp"
46 #include "MueLu_UncoupledAggregationFactory.hpp"
47 #include "MueLu_NullspaceFactory.hpp"
50 #include "MueLu_CoalesceDropFactory_kokkos.hpp"
52 #include "MueLu_TentativePFactory_kokkos.hpp"
54 #if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
55 #include "MueLu_IsorropiaInterface.hpp"
56 #include "MueLu_RepartitionHeuristicFactory.hpp"
57 #include "MueLu_RepartitionFactory.hpp"
58 #include "MueLu_RebalanceTransferFactory.hpp"
59 #include "MueLu_RepartitionInterface.hpp"
60 #include "MueLu_RebalanceAcFactory.hpp"
70 #define MUELU_READ_PARAM(paramList, paramStr, varType, defaultValue, varName) \
71 varType varName = defaultValue; \
72 if (paramList.isParameter(paramStr)) varName = paramList.get<varType>(paramStr);
75 #define MUELU_COPY_PARAM(paramList, paramStr, varType, defaultValue, outParamList, outParamStr) \
76 if (paramList.isParameter(paramStr)) \
77 outParamList.set(outParamStr, paramList.get<varType>(paramStr)); \
79 outParamList.set(outParamStr, static_cast<varType>(defaultValue));
83 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
89 , TransferFacts_(factoryList)
92 std::string filename = paramList.
get(
"xml parameter file",
"");
93 if (filename.length() != 0) {
97 paramList2.remove(
"xml parameter file");
105 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
108 , TransferFacts_(factoryList)
114 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
129 MUELU_READ_PARAM(paramList,
"aggregation: type", std::string,
"Uncoupled", agg_type);
131 MUELU_READ_PARAM(paramList,
"aggregation: damping factor",
double, (
double)4 / (
double)3, agg_damping);
133 MUELU_READ_PARAM(paramList,
"aggregation: nodes per aggregate",
int, 1, minPerAgg);
134 MUELU_READ_PARAM(paramList,
"aggregation: keep Dirichlet bcs",
bool,
false, bKeepDirichletBcs);
135 MUELU_READ_PARAM(paramList,
"aggregation: max neighbours already aggregated",
int, 0, maxNbrAlreadySelected);
136 MUELU_READ_PARAM(paramList,
"aggregation: aux: enable",
bool,
false, agg_use_aux);
137 MUELU_READ_PARAM(paramList,
"aggregation: aux: threshold",
double,
false, agg_aux_thresh);
139 MUELU_READ_PARAM(paramList,
"null space: type", std::string,
"default vectors", nullspaceType);
140 MUELU_READ_PARAM(paramList,
"null space: dimension",
int, -1, nullspaceDim);
141 MUELU_READ_PARAM(paramList,
"null space: vectors",
double*, NULL, nullspaceVec);
143 MUELU_READ_PARAM(paramList,
"energy minimization: enable",
bool,
false, bEnergyMinimization);
145 MUELU_READ_PARAM(paramList,
"RAP: fix diagonal",
bool,
false, bFixDiagonal);
159 paramList = paramListWithSubList;
162 bool setKokkosRefactor =
false;
163 bool useKokkosRefactor = !Node::is_serial;
164 if (paramList.
isType<
bool>(
"use kokkos refactor")) {
165 useKokkosRefactor = paramList.
get<
bool>(
"use kokkos refactor");
166 setKokkosRefactor =
true;
167 paramList.
remove(
"use kokkos refactor");
175 bool validate = paramList.
get(
"ML validate parameter list",
true);
177 #if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA)
179 int depth = paramList.
get(
"ML validate depth", 5);
181 "ERROR: ML's Teuchos::ParameterList contains incorrect parameter!");
184 this->GetOStream(
Warnings0) <<
"Warning: MueLu_ENABLE_ML=OFF. The parameter list cannot be validated." << std::endl;
185 paramList.
set(
"ML validate parameter list",
false);
187 #endif // HAVE_MUELU_ML
192 blksize_ = nDofsPerNode;
198 if (verbosityLevel == 0) eVerbLevel =
None;
199 if (verbosityLevel >= 1) eVerbLevel =
Low;
200 if (verbosityLevel >= 5) eVerbLevel =
Medium;
201 if (verbosityLevel >= 10) eVerbLevel =
High;
202 if (verbosityLevel >= 11) eVerbLevel =
Extreme;
203 if (verbosityLevel >= 42) eVerbLevel =
Test;
205 this->verbosity_ = eVerbLevel;
208 "MueLu::MLParameterListInterpreter::SetParameterList(): parameter \"aggregation: type\": only 'Uncoupled' aggregation is supported.");
212 if (useKokkosRefactor)
233 if (verbosityLevel > 3) {
234 std::ostringstream oss;
235 oss <<
"========================= Aggregate option summary =========================" << std::endl;
236 oss <<
"min Nodes per aggregate : " << minPerAgg << std::endl;
237 oss <<
"min # of root nbrs already aggregated : " << maxNbrAlreadySelected << std::endl;
238 oss <<
"aggregate ordering : natural" << std::endl;
239 oss <<
"=============================================================================" << std::endl;
240 this->GetOStream(
Runtime1) << oss.str();
246 if (useKokkosRefactor)
250 if (agg_damping == 0.0 && bEnergyMinimization ==
false) {
254 }
else if (agg_damping != 0.0 && bEnergyMinimization ==
false) {
260 }
else if (bEnergyMinimization ==
true) {
268 for (
size_t i = 0; i < TransferFacts_.size(); i++) {
275 #if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
282 if (bDoRepartition == 1) {
292 rebAmalgFact->SetFactory(
"A", AcFact);
294 MUELU_READ_PARAM(paramList,
"repartition: max min ratio",
double, 1.3, maxminratio);
295 MUELU_READ_PARAM(paramList,
"repartition: min per proc",
int, 512, minperproc);
301 paramListRepFact.
set(
"repartition: min rows per proc", minperproc);
302 paramListRepFact.
set(
"repartition: max imbalance", maxminratio);
305 RepartitionHeuristicFact->
SetFactory(
"A", AcFact);
309 isoInterface->SetFactory(
"A", AcFact);
310 isoInterface->SetFactory(
"number of partitions", RepartitionHeuristicFact);
311 isoInterface->SetFactory(
"UnAmalgamationInfo", rebAmalgFact);
315 repInterface->SetFactory(
"A", AcFact);
316 repInterface->SetFactory(
"number of partitions", RepartitionHeuristicFact);
317 repInterface->SetFactory(
"AmalgamatedPartition", isoInterface);
323 RepartitionFact->
SetFactory(
"number of partitions", RepartitionHeuristicFact);
324 RepartitionFact->
SetFactory(
"Partition", repInterface);
330 RebalancedPFact->
SetFactory(
"Nullspace", PtentFact);
331 RebalancedPFact->
SetFactory(
"Importer", RepartitionFact);
336 RebalancedRFact->
SetFactory(
"Importer", RepartitionFact);
342 #else // #ifdef HAVE_MUELU_ISORROPIA
356 if (nullspaceType !=
"default vectors") {
361 nullspaceDim_ = nullspaceDim;
362 nullspace_ = nullspaceVec;
378 this->numDesiredLevel_ = maxLevels;
379 this->maxCoarseSize_ = maxCoarseSize;
387 coarseList.
set(
"smoother: type",
"Amesos-KLU");
399 for (
int levelID = 0; levelID < maxLevels; levelID++) {
405 if (setKokkosRefactor)
423 manager->
SetFactory(
"Smoother", smootherFact);
430 manager->
SetFactory(
"CoarseSolver", coarseFact);
436 #if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
437 if (bDoRepartition == 1) {
441 manager->
SetFactory(
"Nullspace", RebalancedPFact);
442 manager->
SetFactory(
"Importer", RepartitionFact);
444 #endif // #ifdef HAVE_MUELU_ISORROPIA
449 #if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
453 this->AddFactoryManager(levelID, 1, manager);
457 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
461 if (nullspace_ != NULL) {
467 RCP<MultiVector> nullspace = MultiVectorFactory::Build(rowMap, nullspaceDim_,
true);
469 for (
size_t i = 0; i < Teuchos::as<size_t>(nullspaceDim_); i++) {
471 const size_t myLength = nullspace->getLocalLength();
473 for (
size_t j = 0; j < myLength; j++) {
474 nullspacei[j] = nullspace_[i * myLength + j];
478 fineLevel->
Set(
"Nullspace", nullspace);
483 size_t num_coords = 0;
486 coordPTR[0] = xcoord_;
489 coordPTR[1] = ycoord_;
492 coordPTR[2] = zcoord_;
505 for (
size_t i = 0; i < num_coords; i++) {
507 const size_t myLength = coordinates->getLocalLength();
508 for (
size_t j = 0; j < myLength; j++) {
509 coordsi[j] = coordPTR[i][j];
512 fineLevel->
Set(
"Coordinates", coordinates);
520 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
528 std::string type =
"symmetric Gauss-Seidel";
549 if (paramList.
isParameter(
"smoother: type")) type = paramList.
get<std::string>(
"smoother: type");
558 std::string ifpackType;
561 if (type ==
"Jacobi" || type ==
"Gauss-Seidel" || type ==
"symmetric Gauss-Seidel") {
562 if (type ==
"symmetric Gauss-Seidel") type =
"Symmetric Gauss-Seidel";
564 ifpackType =
"RELAXATION";
565 smootherParamList.
set(
"relaxation: type", type);
567 MUELU_COPY_PARAM(paramList,
"smoother: sweeps",
int, 2, smootherParamList,
"relaxation: sweeps");
568 MUELU_COPY_PARAM(paramList,
"smoother: damping factor",
Scalar, one, smootherParamList,
"relaxation: damping factor");
571 smooProto->SetFactory(
"A", AFact);
573 }
else if (type ==
"Chebyshev" || type ==
"MLS") {
574 ifpackType =
"CHEBYSHEV";
576 MUELU_COPY_PARAM(paramList,
"smoother: sweeps",
int, 2, smootherParamList,
"chebyshev: degree");
577 if (paramList.
isParameter(
"smoother: MLS alpha")) {
578 MUELU_COPY_PARAM(paramList,
"smoother: MLS alpha",
double, 20, smootherParamList,
"chebyshev: ratio eigenvalue");
580 MUELU_COPY_PARAM(paramList,
"smoother: Chebyshev alpha",
double, 20, smootherParamList,
"chebyshev: ratio eigenvalue");
584 smooProto->SetFactory(
"A", AFact);
586 }
else if (type ==
"Hiptmair") {
587 ifpackType =
"HIPTMAIR";
588 std::string subSmootherType =
"Chebyshev";
590 subSmootherType = paramList.
get<std::string>(
"subsmoother: type");
591 std::string subSmootherIfpackType;
592 if (subSmootherType ==
"Chebyshev")
593 subSmootherIfpackType =
"CHEBYSHEV";
594 else if (subSmootherType ==
"Jacobi" || subSmootherType ==
"Gauss-Seidel" || subSmootherType ==
"symmetric Gauss-Seidel") {
595 if (subSmootherType ==
"symmetric Gauss-Seidel") subSmootherType =
"Symmetric Gauss-Seidel";
596 subSmootherIfpackType =
"RELAXATION";
600 smootherParamList.
set(
"hiptmair: smoother type 1", subSmootherIfpackType);
601 smootherParamList.
set(
"hiptmair: smoother type 2", subSmootherIfpackType);
603 auto smoother1ParamList = smootherParamList.
sublist(
"hiptmair: smoother list 1");
604 auto smoother2ParamList = smootherParamList.
sublist(
"hiptmair: smoother list 2");
606 if (subSmootherType ==
"Chebyshev") {
607 MUELU_COPY_PARAM(paramList,
"subsmoother: edge sweeps",
int, 2, smoother1ParamList,
"chebyshev: degree");
608 MUELU_COPY_PARAM(paramList,
"subsmoother: node sweeps",
int, 2, smoother2ParamList,
"chebyshev: degree");
610 MUELU_COPY_PARAM(paramList,
"subsmoother: Chebyshev",
double, 20, smoother1ParamList,
"chebyshev: ratio eigenvalue");
611 MUELU_COPY_PARAM(paramList,
"subsmoother: Chebyshev",
double, 20, smoother2ParamList,
"chebyshev: ratio eigenvalue");
613 MUELU_COPY_PARAM(paramList,
"subsmoother: edge sweeps",
int, 2, smoother1ParamList,
"relaxation: sweeps");
614 MUELU_COPY_PARAM(paramList,
"subsmoother: node sweeps",
int, 2, smoother2ParamList,
"relaxation: sweeps");
616 MUELU_COPY_PARAM(paramList,
"subsmoother: SGS damping factor",
double, 0.8, smoother2ParamList,
"relaxation: damping factor");
620 smooProto->SetFactory(
"A", AFact);
622 }
else if (type ==
"IFPACK") {
624 #if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_IFPACK)
625 ifpackType = paramList.
get<std::string>(
"smoother: ifpack type");
627 if (ifpackType ==
"ILU") {
630 if (paramList.
isParameter(
"smoother: ifpack level-of-fill"))
631 smootherParamList.
set(
"fact: level-of-fill", Teuchos::as<int>(paramList.
get<
double>(
"smoother: ifpack level-of-fill")));
633 smootherParamList.
set(
"fact: level-of-fill", as<int>(0));
635 MUELU_COPY_PARAM(paramList,
"smoother: ifpack overlap",
int, 2, smootherParamList,
"partitioner: overlap");
639 MueLu::GetIfpackSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node>(ifpackType,
641 paramList.
get<
int>(
"smoother: ifpack overlap"));
642 smooProto->SetFactory(
"A", AFact);
650 }
else if (type.length() > strlen(
"Amesos") && type.substr(0, strlen(
"Amesos")) ==
"Amesos") {
651 std::string solverType = type.substr(strlen(
"Amesos") + 1);
655 const int validatorSize = 5;
656 std::string validator[validatorSize] = {
"Superlu",
"Superludist",
"KLU",
"UMFPACK",
"MUMPS"};
657 for (
int i = 0; i < validatorSize; i++) {
658 if (validator[i] == solverType) valid =
true;
663 std::transform(solverType.begin() + 1, solverType.end(), solverType.begin() + 1,
::tolower);
666 smooProto->SetFactory(
"A", AFact);
680 MUELU_READ_PARAM(paramList,
"smoother: pre or post", std::string,
"both", preOrPost);
681 if (preOrPost ==
"both") {
683 }
else if (preOrPost ==
"pre") {
685 }
else if (preOrPost ==
"post") {
692 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
695 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!");
696 TransferFacts_.push_back(factory);
699 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
701 return TransferFacts_.size();
704 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
707 Matrix& A =
dynamic_cast<Matrix&
>(Op);
708 if (A.IsFixedBlockSizeSet() && (A.GetFixedBlockSize() != blksize_))
709 this->GetOStream(
Warnings0) <<
"Setting matrix block size to " << blksize_ <<
" (value of the parameter in the list) "
710 <<
"instead of " << A.GetFixedBlockSize() <<
" (provided matrix)." << std::endl;
712 A.SetFixedBlockSize(blksize_);
714 #ifdef HAVE_MUELU_DEBUG
715 MatrixUtils::checkLocalRowMapMatchesColMap(A);
716 #endif // HAVE_MUELU_DEBUG
718 }
catch (std::bad_cast&) {
719 this->GetOStream(
Warnings0) <<
"Skipping setting block size as the operator is not a matrix" << std::endl;
725 #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.
virtual void SetFactory(const std::string &varName, const RCP< const FactoryBase > &factory)
Configuration.
T & get(const std::string &name, T def_value)
Class that encapsulates external library smoothers.
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.
ParameterList & set(std::string const &name, T &&value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
#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())
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.
Helper class which transforms an "AmalgamatedPartition" array to an unamalgamated "Partition"...
void SetParameterList(const Teuchos::ParameterList ¶mList)
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.