46 #ifndef MUELU_MLPARAMETERLISTINTERPRETER_DEF_HPP
47 #define MUELU_MLPARAMETERLISTINTERPRETER_DEF_HPP
52 #if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA)
53 #include <ml_ValidateParameters.h>
56 #include <Xpetra_Matrix.hpp>
57 #include <Xpetra_MatrixUtils.hpp>
58 #include <Xpetra_MultiVector.hpp>
59 #include <Xpetra_MultiVectorFactory.hpp>
60 #include <Xpetra_Operator.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_CoupledAggregationFactory.hpp"
83 #include "MueLu_UncoupledAggregationFactory.hpp"
84 #include "MueLu_HybridAggregationFactory.hpp"
85 #include "MueLu_NullspaceFactory.hpp"
88 #ifdef HAVE_MUELU_KOKKOS_REFACTOR
89 #include "MueLu_CoalesceDropFactory_kokkos.hpp"
93 #include "MueLu_SaPFactory_kokkos.hpp"
94 #include "MueLu_TentativePFactory_kokkos.hpp"
95 #include "MueLu_UncoupledAggregationFactory_kokkos.hpp"
98 #if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
99 #include "MueLu_IsorropiaInterface.hpp"
100 #include "MueLu_RepartitionHeuristicFactory.hpp"
101 #include "MueLu_RepartitionFactory.hpp"
102 #include "MueLu_RebalanceTransferFactory.hpp"
103 #include "MueLu_RepartitionInterface.hpp"
104 #include "MueLu_RebalanceAcFactory.hpp"
114 #define MUELU_READ_PARAM(paramList, paramStr, varType, defaultValue, varName) \
115 varType varName = defaultValue; if (paramList.isParameter(paramStr)) varName = paramList.get<varType>(paramStr);
118 #define MUELU_COPY_PARAM(paramList, paramStr, varType, defaultValue, outParamList, outParamStr) \
119 if (paramList.isParameter(paramStr)) \
120 outParamList.set(outParamStr, paramList.get<varType>(paramStr)); \
121 else outParamList.set(outParamStr, static_cast<varType>(defaultValue)); \
125 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
126 MLParameterListInterpreter<Scalar, LocalOrdinal, GlobalOrdinal, Node>::MLParameterListInterpreter(
Teuchos::ParameterList & paramList,
Teuchos::RCP<
const Teuchos::Comm<int> > comm, std::vector<
RCP<FactoryBase> > factoryList) : nullspace_(NULL), xcoord_(NULL), ycoord_(NULL), zcoord_(NULL),TransferFacts_(factoryList), blksize_(1) {
129 std::string filename = paramList.
get(
"xml parameter file",
"");
130 if (filename.length() != 0) {
134 paramList2.remove(
"xml parameter file");
144 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
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);
196 paramList = paramListWithSubList;
199 bool setKokkosRefactor =
false;
200 bool useKokkosRefactor;
201 #if !defined(HAVE_MUELU_KOKKOS_REFACTOR)
202 useKokkosRefactor =
false;
204 # ifdef HAVE_MUELU_SERIAL
205 if (
typeid(
Node).name() ==
typeid(Kokkos::Compat::KokkosSerialWrapperNode).name())
206 useKokkosRefactor =
false;
208 # ifdef HAVE_MUELU_OPENMP
209 if (
typeid(
Node).name() ==
typeid(Kokkos::Compat::KokkosOpenMPWrapperNode).name())
210 useKokkosRefactor =
true;
212 # ifdef HAVE_MUELU_CUDA
213 if (
typeid(
Node).name() ==
typeid(Kokkos::Compat::KokkosCudaWrapperNode).name())
214 useKokkosRefactor =
true;
217 if (paramList.
isType<
bool>(
"use kokkos refactor")) {
218 useKokkosRefactor = paramList.
get<
bool>(
"use kokkos refactor");
219 setKokkosRefactor =
true;
220 paramList.
remove(
"use kokkos refactor");
228 bool validate = paramList.
get(
"ML validate parameter list",
true);
231 #if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA)
233 int depth = paramList.
get(
"ML validate depth", 5);
235 "ERROR: ML's Teuchos::ParameterList contains incorrect parameter!");
238 this->GetOStream(
Warnings0) <<
"Warning: MueLu_ENABLE_ML=OFF. The parameter list cannot be validated." << std::endl;
239 paramList.
set(
"ML validate parameter list",
false);
241 #endif // HAVE_MUELU_ML
247 blksize_ = nDofsPerNode;
253 if (verbosityLevel == 0) eVerbLevel =
None;
254 if (verbosityLevel >= 1) eVerbLevel =
Low;
255 if (verbosityLevel >= 5) eVerbLevel =
Medium;
256 if (verbosityLevel >= 10) eVerbLevel =
High;
257 if (verbosityLevel >= 11) eVerbLevel =
Extreme;
258 if (verbosityLevel >= 42) eVerbLevel =
Test;
259 this->verbosity_ = eVerbLevel;
263 "MueLu::MLParameterListInterpreter::SetParameterList(): parameter \"aggregation: type\": only 'Uncoupled' or 'Coupled' aggregation is supported.");
267 #ifdef HAVE_MUELU_KOKKOS_REFACTOR
268 if(useKokkosRefactor)
269 dropFact =
rcp(
new CoalesceDropFactory_kokkos() );
280 if (agg_type ==
"Uncoupled") {
283 #ifdef HAVE_MUELU_KOKKOS_REFACTOR
284 if(useKokkosRefactor) {
285 MyUncoupledAggFact =
rcp(
new UncoupledAggregationFactory_kokkos() );
291 MyUncoupledAggFact->
SetFactory(
"Graph", dropFact);
292 MyUncoupledAggFact->
SetFactory(
"DofsPerNode", dropFact);
298 AggFact = MyUncoupledAggFact;
301 #ifdef HAVE_MUELU_KOKKOS_REFACTOR
302 if(useKokkosRefactor) {
303 AggFact =
rcp(
new UncoupledAggregationFactory_kokkos() );
310 CoupledAggFact2->
SetFactory(
"Graph", dropFact);
311 CoupledAggFact2->
SetFactory(
"DofsPerNode", dropFact);
312 AggFact = CoupledAggFact2;
321 CoupledAggFact2->
SetFactory(
"Graph", dropFact);
322 CoupledAggFact2->
SetFactory(
"DofsPerNode", dropFact);
323 AggFact = CoupledAggFact2;
326 if (verbosityLevel > 3) {
327 std::ostringstream oss;
328 oss <<
"========================= Aggregate option summary  =========================" << std::endl;
329 oss <<
"min Nodes per aggregate : Â Â Â Â Â Â Â " << minPerAgg << std::endl;
330 oss <<
"min # of root nbrs already aggregated : " << maxNbrAlreadySelected << std::endl;
331 oss <<
"aggregate ordering : Â Â Â Â Â Â Â Â Â Â natural" << std::endl;
332 oss <<
"=============================================================================" << std::endl;
333 this->GetOStream(
Runtime1) << oss.str();
339 #ifdef HAVE_MUELU_KOKKOS_REFACTOR
340 if(useKokkosRefactor)
341 PtentFact =
rcp(
new TentativePFactory_kokkos() );
345 if (agg_damping == 0.0 && bEnergyMinimization ==
false) {
349 }
else if (agg_damping != 0.0 && bEnergyMinimization ==
false) {
352 #ifdef HAVE_MUELU_KOKKOS_REFACTOR
353 if(useKokkosRefactor)
354 SaPFact =
rcp(
new SaPFactory_kokkos() );
361 }
else if (bEnergyMinimization ==
true) {
369 for (
size_t i = 0; i<TransferFacts_.size(); i++) {
376 #if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
383 if (bDoRepartition == 1) {
393 rebAmalgFact->SetFactory(
"A", AcFact);
395 MUELU_READ_PARAM(paramList,
"repartition: max min ratio",
double, 1.3, maxminratio);
396 MUELU_READ_PARAM(paramList,
"repartition: min per proc",
int, 512, minperproc);
402 paramListRepFact.
set(
"repartition: min rows per proc", minperproc);
403 paramListRepFact.
set(
"repartition: max imbalance", maxminratio);
406 RepartitionHeuristicFact->
SetFactory(
"A", AcFact);
410 isoInterface->SetFactory(
"A", AcFact);
411 isoInterface->SetFactory(
"number of partitions", RepartitionHeuristicFact);
412 isoInterface->SetFactory(
"UnAmalgamationInfo", rebAmalgFact);
416 repInterface->SetFactory(
"A", AcFact);
417 repInterface->SetFactory(
"number of partitions", RepartitionHeuristicFact);
418 repInterface->SetFactory(
"AmalgamatedPartition", isoInterface);
424 RepartitionFact->
SetFactory(
"number of partitions", RepartitionHeuristicFact);
425 RepartitionFact->
SetFactory(
"Partition", repInterface);
431 RebalancedPFact->
SetFactory(
"Nullspace", PtentFact);
432 RebalancedPFact->
SetFactory(
"Importer", RepartitionFact);
437 RebalancedRFact->
SetFactory(
"Importer", RepartitionFact);
443 #else // #ifdef HAVE_MUELU_ISORROPIA
457 if (nullspaceType !=
"default vectors") {
462 nullspaceDim_ = nullspaceDim;
463 nullspace_ = nullspaceVec;
482 this->numDesiredLevel_ = maxLevels;
483 this->maxCoarseSize_ = maxCoarseSize;
491 coarseList.
set(
"smoother: type",
"Amesos-KLU");
503 for (
int levelID=0; levelID < maxLevels; levelID++) {
510 if (setKokkosRefactor)
528 manager->
SetFactory(
"Smoother", smootherFact);
535 manager->
SetFactory(
"CoarseSolver", coarseFact);
541 #if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
542 if (bDoRepartition == 1) {
546 manager->
SetFactory(
"Nullspace", RebalancedPFact);
547 manager->
SetFactory(
"Importer", RepartitionFact);
549 #endif // #ifdef HAVE_MUELU_ISORROPIA
554 #if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI)
558 this->AddFactoryManager(levelID, 1, manager);
563 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
567 if (nullspace_ != NULL) {
573 RCP<MultiVector> nullspace = MultiVectorFactory::Build(rowMap, nullspaceDim_,
true);
575 for (
size_t i=0; i < Teuchos::as<size_t>(nullspaceDim_); i++) {
577 const size_t myLength = nullspace->getLocalLength();
579 for (
size_t j = 0; j < myLength; j++) {
580 nullspacei[j] = nullspace_[i*myLength + j];
584 fineLevel->
Set(
"Nullspace", nullspace);
589 size_t num_coords = 0;
590 double * coordPTR[3];
592 coordPTR[0] = xcoord_;
595 coordPTR[1] = ycoord_;
598 coordPTR[2] = zcoord_;
611 for (
size_t i=0; i < num_coords; i++) {
613 const size_t myLength = coordinates->getLocalLength();
614 for (
size_t j = 0; j < myLength; j++) {
615 coordsi[j] = coordPTR[0][j];
618 fineLevel->
Set(
"Coordinates",coordinates);
626 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
635 std::string type =
"symmetric Gauss-Seidel";
657 if (paramList.
isParameter(
"smoother: type")) type = paramList.
get<std::string>(
"smoother: type");
665 std::string ifpackType;
668 if (type ==
"Jacobi" || type ==
"Gauss-Seidel" || type ==
"symmetric Gauss-Seidel") {
669 if (type ==
"symmetric Gauss-Seidel") type =
"Symmetric Gauss-Seidel";
671 ifpackType =
"RELAXATION";
672 smootherParamList.
set(
"relaxation: type", type);
674 MUELU_COPY_PARAM(paramList,
"smoother: sweeps",
int, 2, smootherParamList,
"relaxation: sweeps");
675 MUELU_COPY_PARAM(paramList,
"smoother: damping factor",
Scalar, one, smootherParamList,
"relaxation: damping factor");
678 smooProto->SetFactory(
"A", AFact);
680 }
else if (type ==
"Chebyshev" || type ==
"MLS") {
682 ifpackType =
"CHEBYSHEV";
684 MUELU_COPY_PARAM(paramList,
"smoother: sweeps",
int, 2, smootherParamList,
"chebyshev: degree");
685 if (paramList.
isParameter(
"smoother: MLS alpha")) {
686 MUELU_COPY_PARAM(paramList,
"smoother: MLS alpha",
double, 20, smootherParamList,
"chebyshev: ratio eigenvalue");
688 MUELU_COPY_PARAM(paramList,
"smoother: Chebyshev alpha",
double, 20, smootherParamList,
"chebyshev: ratio eigenvalue");
693 smooProto->SetFactory(
"A", AFact);
695 }
else if (type ==
"IFPACK") {
697 #if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_IFPACK)
698 ifpackType = paramList.
get<std::string>(
"smoother: ifpack type");
700 if (ifpackType ==
"ILU") {
703 if (paramList.
isParameter(
"smoother: ifpack level-of-fill"))
704 smootherParamList.
set(
"fact: level-of-fill", Teuchos::as<int>(paramList.
get<
double>(
"smoother: ifpack level-of-fill")));
705 else smootherParamList.
set(
"fact: level-of-fill", as<int>(0));
707 MUELU_COPY_PARAM(paramList,
"smoother: ifpack overlap",
int, 2, smootherParamList,
"partitioner: overlap");
711 MueLu::GetIfpackSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node> (ifpackType,
713 paramList.
get<
int> (
"smoother: ifpack overlap"));
714 smooProto->SetFactory(
"A", AFact);
722 }
else if (type.length() > strlen(
"Amesos") && type.substr(0, strlen(
"Amesos")) ==
"Amesos") {
723 std::string solverType = type.substr(strlen(
"Amesos")+1);
727 const int validatorSize = 5;
728 std::string validator[validatorSize] = {
"Superlu",
"Superludist",
"KLU",
"UMFPACK",
"MUMPS"};
729 for (
int i=0; i < validatorSize; i++) {
if (validator[i] == solverType) valid =
true; }
733 std::transform(solverType.begin()+1, solverType.end(), solverType.begin()+1,
::tolower);
736 smooProto->SetFactory(
"A", AFact);
752 MUELU_READ_PARAM(paramList,
"smoother: pre or post", std::string,
"both", preOrPost);
753 if (preOrPost ==
"both") {
755 }
else if (preOrPost ==
"pre") {
757 }
else if (preOrPost ==
"post") {
764 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
767 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!");
768 TransferFacts_.push_back(factory);
771 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
773 return TransferFacts_.size();
776 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
779 Matrix& A =
dynamic_cast<Matrix&
>(Op);
780 if (A.GetFixedBlockSize() != blksize_)
781 this->GetOStream(
Warnings0) <<
"Setting matrix block size to " << blksize_ <<
" (value of the parameter in the list) "
782 <<
"instead of " << A.GetFixedBlockSize() <<
" (provided matrix)." << std::endl;
784 A.SetFixedBlockSize(blksize_);
786 #ifdef HAVE_MUELU_DEBUG
787 MatrixUtils::checkLocalRowMapMatchesColMap(A);
788 #endif // HAVE_MUELU_DEBUG
790 }
catch (std::bad_cast& e) {
791 this->GetOStream(
Warnings0) <<
"Skipping setting block size as the operator is not a matrix" << std::endl;
797 #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
void SetOrdering(const std::string &ordering)
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 coarsening a graph with uncoupled aggregation.
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 SetPhase3AggCreation(double phase3AggCreation)
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 base 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.
void SetMinNodesPerAggregate(int minNodesPerAggregate)
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 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.
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.
void SetMaxNeighAlreadySelected(int maxNeighAlreadySelected)