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> 64 #include "MueLu_Hierarchy.hpp" 65 #include "MueLu_FactoryManager.hpp" 67 #include "MueLu_TentativePFactory.hpp" 68 #include "MueLu_SaPFactory.hpp" 69 #include "MueLu_PgPFactory.hpp" 70 #include "MueLu_AmalgamationFactory.hpp" 71 #include "MueLu_TransPFactory.hpp" 72 #include "MueLu_GenericRFactory.hpp" 73 #include "MueLu_SmootherPrototype.hpp" 74 #include "MueLu_SmootherFactory.hpp" 75 #include "MueLu_TrilinosSmoother.hpp" 77 #include "MueLu_DirectSolver.hpp" 78 #include "MueLu_HierarchyUtils.hpp" 79 #include "MueLu_RAPFactory.hpp" 80 #include "MueLu_CoalesceDropFactory.hpp" 81 #include "MueLu_CoupledAggregationFactory.hpp" 82 #include "MueLu_UncoupledAggregationFactory.hpp" 83 #include "MueLu_NullspaceFactory.hpp" 86 #if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI) 87 #include "MueLu_IsorropiaInterface.hpp" 88 #include "MueLu_RepartitionHeuristicFactory.hpp" 89 #include "MueLu_RepartitionFactory.hpp" 90 #include "MueLu_RebalanceTransferFactory.hpp" 91 #include "MueLu_RepartitionInterface.hpp" 92 #include "MueLu_RebalanceAcFactory.hpp" 102 #define MUELU_READ_PARAM(paramList, paramStr, varType, defaultValue, varName) \ 103 varType varName = defaultValue; if (paramList.isParameter(paramStr)) varName = paramList.get<varType>(paramStr); 106 #define MUELU_COPY_PARAM(paramList, paramStr, varType, defaultValue, outParamList, outParamStr) \ 107 if (paramList.isParameter(paramStr)) \ 108 outParamList.set(outParamStr, paramList.get<varType>(paramStr)); \ 109 else outParamList.set(outParamStr, static_cast<varType>(defaultValue)); \ 113 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
114 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) {
117 std::string filename = paramList.
get(
"xml parameter file",
"");
118 if (filename.length() != 0) {
122 paramList2.remove(
"xml parameter file");
132 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
138 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
153 MUELU_READ_PARAM(paramList,
"aggregation: type", std::string,
"Uncoupled", agg_type);
155 MUELU_READ_PARAM(paramList,
"aggregation: damping factor",
double, (
double)4/(
double)3, agg_damping);
157 MUELU_READ_PARAM(paramList,
"aggregation: nodes per aggregate",
int, 1, minPerAgg);
158 MUELU_READ_PARAM(paramList,
"aggregation: keep Dirichlet bcs",
bool,
false, bKeepDirichletBcs);
159 MUELU_READ_PARAM(paramList,
"aggregation: max neighbours already aggregated",
int, 0, maxNbrAlreadySelected);
160 MUELU_READ_PARAM(paramList,
"aggregation: aux: enable",
bool,
false, agg_use_aux);
161 MUELU_READ_PARAM(paramList,
"aggregation: aux: threshold",
double,
false, agg_aux_thresh);
163 MUELU_READ_PARAM(paramList,
"null space: type", std::string,
"default vectors", nullspaceType);
164 MUELU_READ_PARAM(paramList,
"null space: dimension",
int, -1, nullspaceDim);
165 MUELU_READ_PARAM(paramList,
"null space: vectors",
double*, NULL, nullspaceVec);
167 MUELU_READ_PARAM(paramList,
"energy minimization: enable",
bool,
false, bEnergyMinimization);
169 MUELU_READ_PARAM(paramList,
"RAP: fix diagonal",
bool,
false, bFixDiagonal);
184 paramList = paramListWithSubList;
191 bool validate = paramList.
get(
"ML validate parameter list",
true);
194 #if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA) 196 int depth = paramList.
get(
"ML validate depth", 5);
198 "ERROR: ML's Teuchos::ParameterList contains incorrect parameter!");
201 this->GetOStream(
Warnings0) <<
"Warning: MueLu_ENABLE_ML=OFF. The parameter list cannot be validated." << std::endl;
202 paramList.
set(
"ML validate parameter list",
false);
204 #endif // HAVE_MUELU_ML 210 blksize_ = nDofsPerNode;
216 if (verbosityLevel == 0) eVerbLevel =
None;
217 if (verbosityLevel >= 1) eVerbLevel =
Low;
218 if (verbosityLevel >= 5) eVerbLevel =
Medium;
219 if (verbosityLevel >= 10) eVerbLevel =
High;
220 if (verbosityLevel >= 11) eVerbLevel =
Extreme;
221 if (verbosityLevel >= 42) eVerbLevel =
Test;
222 this->verbosity_ = eVerbLevel;
226 "MueLu::MLParameterListInterpreter::SetParameterList(): parameter \"aggregation: type\": only 'Uncoupled' or 'Coupled' aggregation is supported.");
236 if (agg_type ==
"Uncoupled") {
239 MyUncoupledAggFact->
SetFactory(
"Graph", dropFact);
240 MyUncoupledAggFact->
SetFactory(
"DofsPerNode", dropFact);
246 AggFact = MyUncoupledAggFact;
254 CoupledAggFact2->
SetFactory(
"Graph", dropFact);
255 CoupledAggFact2->
SetFactory(
"DofsPerNode", dropFact);
256 AggFact = CoupledAggFact2;
258 if (verbosityLevel > 3) {
259 std::ostringstream oss;
260 oss <<
"========================= Aggregate option summary  =========================" << std::endl;
261 oss <<
"min Nodes per aggregate : Â Â Â Â Â Â Â " << minPerAgg << std::endl;
262 oss <<
"min # of root nbrs already aggregated : " << maxNbrAlreadySelected << std::endl;
263 oss <<
"aggregate ordering : Â Â Â Â Â Â Â Â Â Â natural" << std::endl;
264 oss <<
"=============================================================================" << std::endl;
265 this->GetOStream(
Runtime1) << oss.str();
271 if (agg_damping == 0.0 && bEnergyMinimization ==
false) {
275 }
else if (agg_damping != 0.0 && bEnergyMinimization ==
false) {
281 }
else if (bEnergyMinimization ==
true) {
289 for (
size_t i = 0; i<TransferFacts_.size(); i++) {
296 #if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI) 303 if (bDoRepartition == 1) {
313 rebAmalgFact->SetFactory(
"A", AcFact);
315 MUELU_READ_PARAM(paramList,
"repartition: max min ratio",
double, 1.3, maxminratio);
316 MUELU_READ_PARAM(paramList,
"repartition: min per proc",
int, 512, minperproc);
322 paramListRepFact.
set(
"repartition: min rows per proc", minperproc);
323 paramListRepFact.
set(
"repartition: max imbalance", maxminratio);
326 RepartitionHeuristicFact->
SetFactory(
"A", AcFact);
330 isoInterface->SetFactory(
"A", AcFact);
331 isoInterface->SetFactory(
"number of partitions", RepartitionHeuristicFact);
332 isoInterface->SetFactory(
"UnAmalgamationInfo", rebAmalgFact);
336 repInterface->SetFactory(
"A", AcFact);
337 repInterface->SetFactory(
"number of partitions", RepartitionHeuristicFact);
338 repInterface->SetFactory(
"AmalgamatedPartition", isoInterface);
344 RepartitionFact->
SetFactory(
"number of partitions", RepartitionHeuristicFact);
345 RepartitionFact->
SetFactory(
"Partition", repInterface);
351 RebalancedPFact->
SetFactory(
"Nullspace", PtentFact);
352 RebalancedPFact->
SetFactory(
"Importer", RepartitionFact);
357 RebalancedRFact->
SetFactory(
"Importer", RepartitionFact);
363 #else // #ifdef HAVE_MUELU_ISORROPIA 377 if (nullspaceType !=
"default vectors") {
382 nullspaceDim_ = nullspaceDim;
383 nullspace_ = nullspaceVec;
402 this->numDesiredLevel_ = maxLevels;
403 this->maxCoarseSize_ = maxCoarseSize;
411 coarseList.
set(
"smoother: type",
"Amesos-KLU");
423 for (
int levelID=0; levelID < maxLevels; levelID++) {
446 manager->
SetFactory(
"Smoother", smootherFact);
453 manager->
SetFactory(
"CoarseSolver", coarseFact);
459 #if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI) 460 if (bDoRepartition == 1) {
464 manager->
SetFactory(
"Nullspace", RebalancedPFact);
465 manager->
SetFactory(
"Importer", RepartitionFact);
467 #endif // #ifdef HAVE_MUELU_ISORROPIA 472 #if defined(HAVE_MUELU_ISORROPIA) && defined(HAVE_MPI) 476 this->AddFactoryManager(levelID, 1, manager);
481 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
485 if (nullspace_ != NULL) {
491 RCP<MultiVector> nullspace = MultiVectorFactory::Build(rowMap, nullspaceDim_,
true);
493 for (
size_t i=0; i < Teuchos::as<size_t>(nullspaceDim_); i++) {
495 const size_t myLength = nullspace->getLocalLength();
497 for (
size_t j = 0; j < myLength; j++) {
498 nullspacei[j] = nullspace_[i*myLength + j];
502 fineLevel->
Set(
"Nullspace", nullspace);
507 size_t num_coords = 0;
508 double * coordPTR[3];
510 coordPTR[0] = xcoord_;
513 coordPTR[1] = ycoord_;
516 coordPTR[2] = zcoord_;
529 for (
size_t i=0; i < num_coords; i++) {
531 const size_t myLength = coordinates->getLocalLength();
532 for (
size_t j = 0; j < myLength; j++) {
533 coordsi[j] = coordPTR[0][j];
536 fineLevel->
Set(
"Coordinates",coordinates);
544 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
550 std::string type =
"symmetric Gauss-Seidel";
572 if (paramList.
isParameter(
"smoother: type")) type = paramList.
get<std::string>(
"smoother: type");
580 std::string ifpackType;
583 if (type ==
"Jacobi" || type ==
"Gauss-Seidel" || type ==
"symmetric Gauss-Seidel") {
584 if (type ==
"symmetric Gauss-Seidel") type =
"Symmetric Gauss-Seidel";
586 ifpackType =
"RELAXATION";
587 smootherParamList.
set(
"relaxation: type", type);
589 MUELU_COPY_PARAM(paramList,
"smoother: sweeps",
int, 2, smootherParamList,
"relaxation: sweeps");
590 MUELU_COPY_PARAM(paramList,
"smoother: damping factor",
double, 1.0, smootherParamList,
"relaxation: damping factor");
593 smooProto->SetFactory(
"A", AFact);
595 }
else if (type ==
"Chebyshev" || type ==
"MLS") {
597 ifpackType =
"CHEBYSHEV";
599 MUELU_COPY_PARAM(paramList,
"smoother: sweeps",
int, 2, smootherParamList,
"chebyshev: degree");
600 if (paramList.
isParameter(
"smoother: MLS alpha")) {
601 MUELU_COPY_PARAM(paramList,
"smoother: MLS alpha",
double, 20, smootherParamList,
"chebyshev: ratio eigenvalue");
603 MUELU_COPY_PARAM(paramList,
"smoother: Chebyshev alpha",
double, 20, smootherParamList,
"chebyshev: ratio eigenvalue");
608 smooProto->SetFactory(
"A", AFact);
610 }
else if (type ==
"IFPACK") {
612 #if defined(HAVE_MUELU_EPETRA) && defined(HAVE_MUELU_IFPACK) 613 ifpackType = paramList.
get<std::string>(
"smoother: ifpack type");
615 if (ifpackType ==
"ILU") {
618 if (paramList.
isParameter(
"smoother: ifpack level-of-fill"))
619 smootherParamList.
set(
"fact: level-of-fill", Teuchos::as<int>(paramList.
get<
double>(
"smoother: ifpack level-of-fill")));
620 else smootherParamList.
set(
"fact: level-of-fill", as<int>(0));
622 MUELU_COPY_PARAM(paramList,
"smoother: ifpack overlap",
int, 2, smootherParamList,
"partitioner: overlap");
626 MueLu::GetIfpackSmoother<Scalar, LocalOrdinal, GlobalOrdinal, Node> (ifpackType,
628 paramList.
get<
int> (
"smoother: ifpack overlap"));
629 smooProto->SetFactory(
"A", AFact);
637 }
else if (type.length() > strlen(
"Amesos") && type.substr(0, strlen(
"Amesos")) ==
"Amesos") {
638 std::string solverType = type.substr(strlen(
"Amesos")+1);
642 const int validatorSize = 5;
643 std::string validator[validatorSize] = {
"Superlu",
"Superludist",
"KLU",
"UMFPACK"};
644 for (
int i=0; i < validatorSize; i++) {
if (validator[i] == solverType) valid =
true; }
648 std::transform(solverType.begin()+1, solverType.end(), solverType.begin()+1, ::tolower);
651 smooProto->SetFactory(
"A", AFact);
667 MUELU_READ_PARAM(paramList,
"smoother: pre or post", std::string,
"both", preOrPost);
668 if (preOrPost ==
"both") {
670 }
else if (preOrPost ==
"pre") {
672 }
else if (preOrPost ==
"post") {
679 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
682 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!");
683 TransferFacts_.push_back(factory);
686 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
688 return TransferFacts_.size();
691 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
694 Matrix& A =
dynamic_cast<Matrix&
>(Op);
695 if (A.GetFixedBlockSize() != blksize_)
696 this->GetOStream(
Warnings0) <<
"Setting matrix block size to " << blksize_ <<
" (value of the parameter in the list) " 697 <<
"instead of " << A.GetFixedBlockSize() <<
" (provided matrix)." << std::endl;
699 A.SetFixedBlockSize(blksize_);
701 }
catch (std::bad_cast& e) {
702 this->GetOStream(
Warnings0) <<
"Skipping setting block size as the operator is not a matrix" << std::endl;
708 #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
virtual void SetupOperator(Operator &Op) const
Setup Operator object.
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)
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.
Factory for building permutation matrix that can be be used to shuffle data (matrices, vectors) among processes.
void AddTransferFactory(const RCP< const FactoryBase > &factory)
Add transfer factory in the end of list of transfer factories in RepartitionAcFactory.
Namespace for MueLu classes and methods.
#define MUELU_READ_PARAM(paramList, paramStr, varType, defaultValue, varName)
const Teuchos::ParameterList & GetMLSubList(const Teuchos::ParameterList ¶mList, const std::string &type, int levelID)
Print skeleton for the run, i.e. factory calls and used parameters.
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.
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.
Factory for building restriction operators using a prolongator factory.
void SetPhase3AggCreation(double phase3AggCreation)
void CreateSublists(const ParameterList &List, ParameterList &newList)
void SetSmootherPrototypes(RCP< SmootherPrototype > preAndPostSmootherPrototype)
Set smoother prototypes.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
virtual void SetParameterList(const ParameterList ¶mList)
Set parameters from a parameter list and return with default values.
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)
AmalgamationFactory for subblocks of strided map based amalgamation data.
size_t NumTransferFactories() const
Returns number of transfer factories.
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)
void SetMinNodesPerAggregate(int minNodesPerAggregate)
Factory for building restriction operators.
bool isParameter(const std::string &name) const
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
virtual void SetFactory(const std::string &varName, const RCP< const FactoryBase > &factory)
Configuration.
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.
void SetMaxNeighAlreadySelected(int maxNeighAlreadySelected)