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_NullspaceFactory.hpp" 47 #include "MueLu_MLParameterListInterpreter.hpp" 59 #define MUELU_READ_PARAM(paramList, paramStr, varType, defaultValue, varName) \ 60 varType varName = defaultValue; if (paramList.isParameter(paramStr)) varName = paramList.get<varType>(paramStr); 63 #define MUELU_COPY_PARAM(paramList, paramStr, varType, defaultValue, outParamList, outParamStr) \ 64 if (paramList.isParameter(paramStr)) \ 65 outParamList.set<varType>(outParamStr, paramList.get<varType>(paramStr)); \ 66 else outParamList.set<varType>(outParamStr, defaultValue); \ 70 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
75 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
81 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
98 MUELU_READ_PARAM(paramList,
"aggregation: type", std::string,
"Uncoupled", agg_type);
100 MUELU_READ_PARAM(paramList,
"aggregation: damping factor",
double, (
double)4/(
double)3, agg_damping);
102 MUELU_READ_PARAM(paramList,
"aggregation: nodes per aggregate",
int, 1, minPerAgg);
104 MUELU_READ_PARAM(paramList,
"null space: type", std::string,
"default vectors", nullspaceType);
105 MUELU_READ_PARAM(paramList,
"null space: dimension",
int, -1, nullspaceDim);
106 MUELU_READ_PARAM(paramList,
"null space: vectors",
double*, NULL, nullspaceVec);
108 MUELU_READ_PARAM(paramList,
"energy minimization: enable",
bool,
false, bEnergyMinimization);
119 paramList = paramListWithSubList;
124 int maxNbrAlreadySelected = 0;
127 this->blksize_ = nDofsPerNode;
145 if(agg_type ==
"Uncoupled") {
151 CoupledAggFact = CoupledAggFact2;
159 CoupledAggFact = CoupledAggFact2;
161 if (verbosityLevel > 3) {
162 *out <<
"========================= Aggregate option summary =========================" << std::endl;
163 *out <<
"min Nodes per aggregate : " << minPerAgg << std::endl;
164 *out <<
"min # of root nbrs already aggregated : " << maxNbrAlreadySelected << std::endl;
165 *out <<
"aggregate ordering : natural" << std::endl;
166 *out <<
"=============================================================================" << std::endl;
172 if (agg_damping == 0.0 && bEnergyMinimization ==
false) {
176 }
else if (agg_damping != 0.0 && bEnergyMinimization ==
false) {
182 }
else if (bEnergyMinimization ==
true) {
189 for (
size_t i = 0; i<TransferFacts_.size(); i++) {
200 if (nullspaceType !=
"default vectors") {
205 nullspaceDim_ = nullspaceDim;
206 nullspace_ = nullspaceVec;
218 this->numDesiredLevel_ = maxLevels;
219 this->maxCoarseSize_ = maxCoarseSize;
223 if(paramList.
isSublist(
"init smoother")) {
227 std::string ifpackType =
"RELAXATION";
229 smootherParamList.
set(
"relaxation: type",
"symmetric Gauss-Seidel");
230 smootherParamList.
set(
"smoother: sweeps", 1);
231 smootherParamList.
set(
"smoother: damping factor", 1.0);
257 for (
int levelID=0; levelID < maxLevels; levelID++) {
281 manager->
SetFactory(
"Smoother", smootherFact);
284 initmanager->
SetFactory(
"Smoother", initSmootherFact);
285 initmanager->
SetFactory(
"CoarseSolver", initSmootherFact);
303 manager->
SetFactory(
"CoarseSolver", coarseFact);
305 manager->
SetFactory(
"Aggregates", CoupledAggFact);
315 initmanager->
SetFactory(
"Aggregates", CoupledAggFact);
316 initmanager->
SetFactory(
"DofsPerNode", dropFact);
321 initmanager->
SetFactory(
"Nullspace", nspFact);
323 this->AddFactoryManager(levelID, 1, manager);
324 this->AddInitFactoryManager(levelID, 1, initmanager);
328 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
341 int lastLevelID = this->numDesiredLevel_ - 1;
342 bool isLastLevel =
false;
344 while(!isLastLevel) {
345 bool r = H.
Setup(levelID,
346 InitLvlMngr(levelID-1, lastLevelID),
347 InitLvlMngr(levelID, lastLevelID),
348 InitLvlMngr(levelID+1, lastLevelID));
350 isLastLevel = r || (levelID == lastLevelID);
355 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
361 if (this->nullspace_ != NULL) {
364 RCP<MultiVector> nullspace = MultiVectorFactory::Build(rowMap, nullspaceDim_,
true);
366 for (
size_t i=0; i < Teuchos::as<size_t>(nullspaceDim_); i++) {
368 const size_t myLength = nullspace->getLocalLength();
370 for (
size_t j = 0; j < myLength; j++) {
371 nullspacei[j] = nullspace_[i*myLength + j];
375 fineLevel->
Set(
"Nullspace", nullspace);
384 SetupInitHierarchy(H);
391 Xpetra::IO<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Write(
"orig_nsp.vec", *nspVector2);
394 Xpetra::IO<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Write(
"A.mat", *Op);
397 Teuchos::RCP<MultiVector> homogRhsVec = MultiVectorFactory::Build(nspVector2->getMap(),nspVector2->getNumVectors(),
true);
398 homogRhsVec->putScalar(0.0);
403 H.
Iterate(*homogRhsVec, *nspVector2, 1,
false);
406 Finest->
Set(
"Nullspace",nspVector2);
408 Xpetra::IO<Scalar,LocalOrdinal,GlobalOrdinal,Node>::Write(
"new_nsp.vec", *nspVector2);
433 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
436 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!");
437 TransferFacts_.push_back(factory);
440 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
442 return TransferFacts_.size();
445 template <
class Scalar,
class LocalOrdinal,
class GlobalOrdinal,
class Node>
448 Matrix& A =
dynamic_cast<Matrix&
>(Op);
449 if (A.GetFixedBlockSize() != blksize_)
450 this->GetOStream(
Warnings0) <<
"Setting matrix block size to " << blksize_ <<
" (value of the parameter in the list) " 451 <<
"instead of " << A.GetFixedBlockSize() <<
" (provided matrix)." << std::endl;
453 A.SetFixedBlockSize(blksize_);
455 }
catch (std::bad_cast& e) {
456 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.
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
size_t NumTransferFactories() const
Returns number of transfer factories.
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 SetupInitHierarchy(Hierarchy &H) const
void SetMaxCoarseSize(Xpetra::global_size_t maxCoarseSize)
bool isSublist(const std::string &name) const
VerbLevel toMueLuVerbLevel(const Teuchos::EVerbosityLevel verbLevel)
AdaptiveSaMLParameterListInterpreter()
Constructor.
Base class for factories that use two levels (fineLevel and coarseLevel).
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.
RCP< FactoryManagerBase > GetFactoryManager(int levelID) const
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 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 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)
virtual void SetupOperator(Operator &Op) 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)
void DisableMultipleCallCheck() const
void SetMinNodesPerAggregate(int minNodesPerAggregate)
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.
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="")
virtual void SetFactory(const std::string &varName, const RCP< const FactoryBase > &factory)
Configuration.
Exception throws to report errors in the internal logical of the program.
size_t getNumFactoryManagers() const
returns number of factory managers stored in levelManagers_ vector.
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.
virtual void SetupHierarchy(Hierarchy &H) const
Setup Hierarchy object.
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.Input/output of SaPFactory
#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.
void SetMaxNeighAlreadySelected(int maxNeighAlreadySelected)