48 #if defined(HAVE_MUELU_ML)
49 #include <ml_config.h>
50 #if defined(HAVE_ML_EPETRA) && defined(HAVE_ML_TEUCHOS)
51 #include <ml_ValidateParameters.h>
52 #include <ml_MultiLevelPreconditioner.h>
53 #include <ml_RefMaxwell.h>
62 TEUCHOS_TEST_FOR_EXCEPTION(pname !=
"coarse: type" && pname !=
"coarse: list" && pname !=
"smoother: type" && pname.find(
"smoother: list", 0) != 0,
64 "MueLu::MLParameterListInterpreter::Setup(): Only \"coarse: type\", \"smoother: type\" or \"smoother: list\" (\"coarse: list\") are "
65 "supported as ML parameters for transformation of smoother/solver parameters to MueLu");
68 std::stringstream mueluss;
71 std::string mode =
"smoother:";
72 bool is_coarse =
false;
73 if (pname.find(
"coarse:", 0) == 0) {
81 PreOrPost = paramList.
get<std::string>(mode +
" pre or post");
84 "MueLu::MLParameterListInterpreter::Setup(): The parameter \"coarse: pre or post\" is not supported by MueLu. "
85 "It does not make sense for direct solvers. For iterative solvers you obtain the same effect by increasing, "
86 "e.g., the number of sweeps for the coarse grid smoother. Please remove it from your parameters.");
89 std::string valuestr = value;
90 std::transform(valuestr.begin(), valuestr.end(), valuestr.begin(),
::tolower);
91 if (valuestr ==
"jacobi" || valuestr ==
"gauss-seidel" || valuestr ==
"symmetric gauss-seidel") {
93 if (PreOrPost ==
"both")
94 my_name =
"\"" + pname +
"\"";
96 my_name =
"\"smoother: " + PreOrPost +
" type\"";
97 mueluss <<
"<Parameter name=" << my_name <<
" type=\"string\" value=\"RELAXATION\"/>" << std::endl;
99 }
else if (valuestr ==
"hiptmair") {
101 if (PreOrPost ==
"both")
102 my_name =
"\"" + pname +
"\"";
104 my_name =
"\"smoother: " + PreOrPost +
" type\"";
105 mueluss <<
"<Parameter name=" << my_name <<
" type=\"string\" value=\"HIPTMAIR\"/>" << std::endl;
107 }
else if (valuestr ==
"ifpack") {
108 std::string my_name =
"\"" + pname +
"\"";
109 if (paramList.
isParameter(
"smoother: ifpack type")) {
110 if (paramList.
get<std::string>(
"smoother: ifpack type") ==
"ILU") {
111 mueluss <<
"<Parameter name=" << my_name <<
" type=\"string\" value=\"ILU\"/>" << std::endl;
112 adaptingParamList.
remove(
"smoother: ifpack type",
false);
114 if (paramList.
get<std::string>(
"smoother: ifpack type") ==
"ILUT") {
115 mueluss <<
"<Parameter name=" << my_name <<
" type\" type=\"string\" value=\"ILUT\"/>" << std::endl;
116 adaptingParamList.
remove(
"smoother: ifpack type",
false);
120 }
else if ((valuestr ==
"chebyshev") || (valuestr ==
"mls")) {
121 std::string my_name =
"\"" + pname +
"\"";
122 mueluss <<
"<Parameter name=" << my_name <<
" type=\"string\" value=\"CHEBYSHEV\"/>" << std::endl;
124 }
else if (valuestr.length() > strlen(
"amesos") && valuestr.substr(0, strlen(
"amesos")) ==
"amesos") {
125 std::string solverType = valuestr.substr(strlen(
"amesos") + 1);
128 const int validatorSize = 5;
129 std::string validator[validatorSize] = {
"superlu",
"superludist",
"klu",
"umfpack",
"mumps"};
130 for (
int i = 0; i < validatorSize; i++)
131 if (validator[i] == solverType)
134 "MueLu::MLParameterListInterpreter: unknown smoother type. '" << solverType <<
"' not supported.");
136 mueluss <<
"<Parameter name=\"" << pname <<
"\" type=\"string\" value=\"" << solverType <<
"\"/>" << std::endl;
140 std::cout <<
"error in " << __FILE__ <<
":" << __LINE__ <<
" could not find valid smoother/solver" << std::endl;
145 if (paramList.
isParameter(
"smoother: pre or post") && mode ==
"smoother:") {
149 mueluss <<
"<Parameter name=\"smoother: pre or post\" type=\"string\" value=\"" << PreOrPost <<
"\"/>" << std::endl;
150 adaptingParamList.
remove(
"smoother: pre or post",
false);
154 if (PreOrPost !=
"both") {
155 mueluss <<
"<ParameterList name=\"smoother: " << PreOrPost <<
" params\">" << std::endl;
157 mueluss <<
"<ParameterList name=\"" << mode <<
" params\">" << std::endl;
162 if (valuestr ==
"jacobi" || valuestr ==
"gauss-seidel" || valuestr ==
"symmetric gauss-seidel") {
163 if (valuestr ==
"jacobi") {
164 mueluss <<
"<Parameter name=\"relaxation: type\" type=\"string\" value=\"Jacobi\"/>" << std::endl;
165 adaptingParamList.
remove(
"relaxation: type",
false);
167 if (valuestr ==
"gauss-seidel") {
168 mueluss <<
"<Parameter name=\"relaxation: type\" type=\"string\" value=\"Gauss-Seidel\"/>" << std::endl;
169 adaptingParamList.
remove(
"relaxation: type",
false);
171 if (valuestr ==
"symmetric gauss-seidel") {
172 mueluss <<
"<Parameter name=\"relaxation: type\" type=\"string\" value=\"Symmetric Gauss-Seidel\"/>" << std::endl;
173 adaptingParamList.
remove(
"relaxation: type",
false);
177 mueluss <<
"<Parameter name=\"relaxation: sweeps\" type=\"int\" value=\"" << paramList.
get<
int>(
"smoother: sweeps") <<
"\"/>" << std::endl;
178 adaptingParamList.
remove(
"smoother: sweeps",
false);
180 if (paramList.
isParameter(
"smoother: damping factor")) {
181 mueluss <<
"<Parameter name=\"relaxation: damping factor\" type=\"double\" value=\"" << paramList.
get<
double>(
"smoother: damping factor") <<
"\"/>" << std::endl;
182 adaptingParamList.
remove(
"smoother: damping factor",
false);
184 if (paramList.
isParameter(
"smoother: use l1 Gauss-Seidel")) {
185 mueluss <<
"<Parameter name=\"relaxation: use l1\" type=\"bool\" value=\"" << paramList.
get<
bool>(
"smoother: use l1 Gauss-Seidel") <<
"\"/>" << std::endl;
186 adaptingParamList.
remove(
"smoother: use l1 Gauss-Seidel",
false);
191 if (valuestr ==
"chebyshev") {
192 if (paramList.
isParameter(
"smoother: polynomial order")) {
193 mueluss <<
"<Parameter name=\"chebyshev: degree\" type=\"int\" value=\"" << paramList.
get<
int>(
"smoother: polynomial order") <<
"\"/>" << std::endl;
194 adaptingParamList.
remove(
"smoother: polynomial order",
false);
196 mueluss <<
"<Parameter name=\"chebyshev: degree\" type=\"int\" value=\"2\"/>" << std::endl;
198 if (paramList.
isParameter(
"smoother: Chebyshev alpha")) {
199 mueluss <<
"<Parameter name=\"chebyshev: ratio eigenvalue\" type=\"double\" value=\"" << paramList.
get<
double>(
"smoother: Chebyshev alpha") <<
"\"/>" << std::endl;
200 adaptingParamList.
remove(
"smoother: Chebyshev alpha",
false);
202 mueluss <<
"<Parameter name=\"chebyshev: ratio eigenvalue\" type=\"double\" value=\"20\"/>" << std::endl;
203 adaptingParamList.
remove(
"smoother: Chebyshev alpha",
false);
205 if (paramList.
isParameter(
"eigen-analysis: type")) {
206 mueluss <<
"<Parameter name=\"eigen-analysis: type\" type=\"string\" value=\"" << paramList.
get<std::string>(
"eigen-analysis: type") <<
"\"/>" << std::endl;
207 adaptingParamList.
remove(
"eigen-analysis: type",
false);
209 mueluss <<
"<Parameter name=\"eigen-analysis: type\" type=\"string\" value=\"cg\"/>" << std::endl;
214 if (valuestr ==
"mls") {
215 if (paramList.
isParameter(
"smoother: MLS polynomial order")) {
216 mueluss <<
"<Parameter name=\"chebyshev: degree\" type=\"int\" value=\"" << paramList.
get<
int>(
"smoother: MLS polynomial order") <<
"\"/>" << std::endl;
217 adaptingParamList.
remove(
"smoother: MLS polynomial order",
false);
218 }
else if (paramList.
isParameter(
"smoother: polynomial order")) {
219 mueluss <<
"<Parameter name=\"chebyshev: degree\" type=\"int\" value=\"" << paramList.
get<
int>(
"smoother: polynomial order") <<
"\"/>" << std::endl;
220 adaptingParamList.
remove(
"smoother: polynomial order",
false);
222 mueluss <<
"<Parameter name=\"chebyshev: degree\" type=\"int\" value=\"2\"/>" << std::endl;
224 if (paramList.
isParameter(
"smoother: MLS alpha")) {
225 mueluss <<
"<Parameter name=\"chebyshev: ratio eigenvalue\" type=\"double\" value=\"" << paramList.
get<
double>(
"smoother: MLS alpha") <<
"\"/>" << std::endl;
226 adaptingParamList.
remove(
"smoother: MLS alpha",
false);
227 }
else if (paramList.
isParameter(
"smoother: Chebyshev alpha")) {
228 mueluss <<
"<Parameter name=\"chebyshev: ratio eigenvalue\" type=\"double\" value=\"" << paramList.
get<
double>(
"smoother: Chebyshev alpha") <<
"\"/>" << std::endl;
229 adaptingParamList.
remove(
"smoother: Chebyshev alpha",
false);
231 mueluss <<
"<Parameter name=\"chebyshev: ratio eigenvalue\" type=\"double\" value=\"20\"/>" << std::endl;
233 if (paramList.
isParameter(
"eigen-analysis: type")) {
234 mueluss <<
"<Parameter name=\"eigen-analysis: type\" type=\"string\" value=\"" << paramList.
get<std::string>(
"eigen-analysis: type") <<
"\"/>" << std::endl;
235 adaptingParamList.
remove(
"eigen-analysis: type",
false);
237 mueluss <<
"<Parameter name=\"eigen-analysis: type\" type=\"string\" value=\"cg\"/>" << std::endl;
241 if (valuestr ==
"hiptmair") {
242 std::string subSmootherType =
"Chebyshev";
243 if (!is_coarse && paramList.
isParameter(
"subsmoother: type"))
244 subSmootherType = paramList.
get<std::string>(
"subsmoother: type");
245 if (is_coarse && paramList.
isParameter(
"smoother: subsmoother type"))
246 subSmootherType = paramList.
get<std::string>(
"smoother: subsmoother type");
248 std::string subSmootherIfpackType;
249 if (subSmootherType ==
"Chebyshev")
250 subSmootherIfpackType =
"CHEBYSHEV";
251 else if (subSmootherType ==
"Jacobi" || subSmootherType ==
"Gauss-Seidel" || subSmootherType ==
"symmetric Gauss-Seidel") {
252 if (subSmootherType ==
"symmetric Gauss-Seidel") subSmootherType =
"Symmetric Gauss-Seidel";
253 subSmootherIfpackType =
"RELAXATION";
257 mueluss <<
"<Parameter name=\"hiptmair: smoother type 1\" type=\"string\" value=\"" << subSmootherIfpackType <<
"\"/>" << std::endl;
258 mueluss <<
"<Parameter name=\"hiptmair: smoother type 2\" type=\"string\" value=\"" << subSmootherIfpackType <<
"\"/>" << std::endl;
260 mueluss <<
"<ParameterList name=\"hiptmair: smoother list 1\">" << std::endl;
261 if (subSmootherType ==
"Chebyshev") {
262 std::string edge_sweeps = is_coarse ?
"smoother: edge sweeps" :
"subsmoother: edge sweeps";
263 std::string cheby_alpha = is_coarse ?
"smoother: Chebyshev alpha" :
"subsmoother: Chebyshev_alpha";
266 mueluss <<
"<Parameter name=\"chebyshev: degree\" type=\"int\" value=\"" << paramList.
get<
int>(edge_sweeps) <<
"\"/>" << std::endl;
267 adaptingParamList.
remove(
"subsmoother: edge sweeps",
false);
270 mueluss <<
"<Parameter name=\"chebyshev: ratio eigenvalue\" type=\"double\" value=\"" << paramList.
get<
double>(cheby_alpha) <<
"\"/>" << std::endl;
273 std::string edge_sweeps = is_coarse ?
"smoother: edge sweeps" :
"subsmoother: edge sweeps";
274 std::string SGS_damping = is_coarse ?
"smoother: SGS damping factor" :
"subsmoother: SGS damping factor";
277 mueluss <<
"<Parameter name=\"relaxation: type\" type=\"string\" value=\"" << subSmootherType <<
"\"/>" << std::endl;
278 mueluss <<
"<Parameter name=\"relaxation: sweeps\" type=\"int\" value=\"" << paramList.
get<
int>(edge_sweeps) <<
"\"/>" << std::endl;
279 adaptingParamList.
remove(edge_sweeps,
false);
282 mueluss <<
"<Parameter name=\"relaxation: damping factor\" type=\"double\" value=\"" << paramList.
get<
double>(SGS_damping) <<
"\"/>" << std::endl;
285 mueluss <<
"</ParameterList>" << std::endl;
287 mueluss <<
"<ParameterList name=\"hiptmair: smoother list 2\">" << std::endl;
288 if (subSmootherType ==
"Chebyshev") {
289 std::string node_sweeps = is_coarse ?
"smoother: node sweeps" :
"subsmoother: node sweeps";
290 std::string cheby_alpha = is_coarse ?
"smoother: Chebyshev alpha" :
"subsmoother: Chebyshev_alpha";
292 mueluss <<
"<Parameter name=\"chebyshev: degree\" type=\"int\" value=\"" << paramList.
get<
int>(node_sweeps) <<
"\"/>" << std::endl;
293 adaptingParamList.
remove(
"subsmoother: node sweeps",
false);
296 mueluss <<
"<Parameter name=\"chebyshev: ratio eigenvalue\" type=\"double\" value=\"" << paramList.
get<
double>(cheby_alpha) <<
"\"/>" << std::endl;
297 adaptingParamList.
remove(
"subsmoother: Chebyshev alpha",
false);
300 std::string node_sweeps = is_coarse ?
"smoother: node sweeps" :
"subsmoother: node sweeps";
301 std::string SGS_damping = is_coarse ?
"smoother: SGS damping factor" :
"subsmoother: SGS damping factor";
304 mueluss <<
"<Parameter name=\"relaxation: type\" type=\"string\" value=\"" << subSmootherType <<
"\"/>" << std::endl;
305 mueluss <<
"<Parameter name=\"relaxation: sweeps\" type=\"int\" value=\"" << paramList.
get<
int>(node_sweeps) <<
"\"/>" << std::endl;
306 adaptingParamList.
remove(
"subsmoother: node sweeps",
false);
309 mueluss <<
"<Parameter name=\"relaxation: damping factor\" type=\"double\" value=\"" << paramList.
get<
double>(SGS_damping) <<
"\"/>" << std::endl;
310 adaptingParamList.
remove(
"subsmoother: SGS damping factor",
false);
313 mueluss <<
"</ParameterList>" << std::endl;
317 if (valuestr ==
"ifpack") {
319 if (paramList.
isParameter(
"smoother: ifpack overlap")) {
320 mueluss <<
"<Parameter name=\"partitioner: overlap\" type=\"int\" value=\"" << paramList.
get<
int>(
"smoother: ifpack overlap") <<
"\"/>" << std::endl;
321 adaptingParamList.
remove(
"smoother: ifpack overlap",
false);
323 if (paramList.
isParameter(
"smoother: ifpack level-of-fill")) {
324 mueluss <<
"<Parameter name=\"fact: level-of-fill\" type=\"int\" value=\"" << paramList.
get<
int>(
"smoother: ifpack level-of-fill") <<
"\"/>" << std::endl;
325 adaptingParamList.
remove(
"smoother: ifpack level-of-fill",
false);
327 if (paramList.
isParameter(
"smoother: ifpack absolute threshold")) {
328 mueluss <<
"<Parameter name=\"fact: absolute threshold\" type=\"int\" value=\"" << paramList.
get<
double>(
"smoother: ifpack absolute threshold") <<
"\"/>" << std::endl;
329 adaptingParamList.
remove(
"smoother: ifpack absolute threshold",
false);
331 if (paramList.
isParameter(
"smoother: ifpack relative threshold")) {
332 mueluss <<
"<Parameter name=\"fact: relative threshold\" type=\"int\" value=\"" << paramList.
get<
double>(
"smoother: ifpack relative threshold") <<
"\"/>" << std::endl;
333 adaptingParamList.
remove(
"smoother: ifpack relative threshold",
false);
337 mueluss <<
"</ParameterList>" << std::endl;
341 mueluss <<
"<Parameter name=\"coarse: max size\" type=\"int\" value=\"" << paramList.
get<
int>(
"smoother: max size") <<
"\"/>" << std::endl;
342 adaptingParamList.
remove(
"smoother: max size",
false);
345 return mueluss.str();
353 #if defined(HAVE_MUELU_ML) && defined(HAVE_ML_EPETRA) && defined(HAVE_ML_TEUCHOS)
357 if (defaultVals !=
"") {
359 "MueLu::MLParameterListInterpreter: only \"SA\", \"NSSA\", \"refmaxwell\" and \"Maxwell\" allowed as options for ML default parameters.");
361 if (defaultVals ==
"refmaxwell")
362 ML_Epetra::SetDefaultsRefMaxwell(ML_defaultlist);
364 ML_Epetra::SetDefaults(defaultVals, ML_defaultlist);
368 paramList = ML_defaultlist;
371 if (defaultVals !=
"") {
373 *out <<
"Warning: MueLu_ENABLE_ML=OFF, ML_ENABLE_Epetra=OFF or ML_ENABLE_TEUCHOS=OFF. No ML default values available." << std::endl;
375 #endif // HAVE_MUELU_ML && HAVE_ML_EPETRA && HAVE_ML_TEUCHOS
386 paramList = paramListWithSubList;
393 bool validate = paramList.
get(
"ML validate parameter list",
true);
394 if (validate && defaultVals !=
"refmaxwell") {
395 #if defined(HAVE_MUELU_ML) && defined(HAVE_ML_EPETRA) && defined(HAVE_ML_TEUCHOS)
397 int depth = paramList.
get(
"ML validate depth", 5);
399 "ERROR: ML's Teuchos::ParameterList contains incorrect parameter!");
402 *out <<
"Warning: MueLu_ENABLE_ML=OFF, ML_ENABLE_Epetra=OFF or ML_ENABLE_TEUCHOS=OFF. The parameter list cannot be validated." << std::endl;
403 paramList.
set(
"ML validate parameter list",
false);
405 #endif // HAVE_MUELU_ML && HAVE_ML_EPETRA && HAVE_ML_TEUCHOS
418 if (paramListWithSubList.
isParameter(
"aggregation: aux: enable") && paramListWithSubList.
get<
bool>(
"aggregation: aux: enable")) {
419 if (paramListWithSubList.
isParameter(
"aggregation: aux: threshold")) {
420 paramListWithSubList.
set(
"aggregation: threshold", paramListWithSubList.
get<
double>(
"aggregation: aux: threshold"));
421 paramListWithSubList.
remove(
"aggregation: aux: threshold");
427 std::stringstream mueluss;
430 mueluss <<
"<ParameterList name=\"MueLu\">" << std::endl;
433 mueluss <<
"<Parameter name=\"aggregation: match ML phase1\" type=\"bool\" value=\"true\"/>" << std::endl;
436 mueluss <<
"<Parameter name=\"aggregation: match ML phase2a\" type=\"bool\" value=\"true\"/>" << std::endl;
439 mueluss <<
"<Parameter name=\"aggregation: match ML phase2b\" type=\"bool\" value=\"true\"/>" << std::endl;
442 mueluss <<
"<Parameter name=\"aggregation: use ml scaling of drop tol\" type=\"bool\" value=\"true\"/>" << std::endl;
447 const std::string& pname = paramListWithSubList.
name(param);
451 std::stringstream valuess;
452 valuess << paramList.
entry(param);
453 std::string valuestr = valuess.str();
456 valuestr =
trim(valuestr);
459 std::string valueInterpreterStr =
"\"" + valuestr +
"\"";
462 if ((pname ==
"aggregation: aux: enable") && (paramListWithSubList.
get<
bool>(
"aggregation: aux: enable"))) {
463 mueluss <<
"<Parameter name=\"aggregation: drop scheme\" type=\"string\" value=\""
464 <<
"distance laplacian"
465 <<
"\"/>" << std::endl;
469 if (pname ==
"ML output") {
471 int verbosityLevel = std::stoi(valuestr);
472 std::string eVerbLevel =
"none";
473 if (verbosityLevel == 0) eVerbLevel =
"none";
474 if (verbosityLevel >= 1) eVerbLevel =
"low";
475 if (verbosityLevel >= 5) eVerbLevel =
"medium";
476 if (verbosityLevel >= 10) eVerbLevel =
"high";
477 if (verbosityLevel >= 11) eVerbLevel =
"extreme";
478 if (verbosityLevel >= 42) eVerbLevel =
"test";
479 if (verbosityLevel >= 666) eVerbLevel =
"interfacetest";
480 mueluss <<
"<Parameter name=\"verbosity\" type=\"string\" value=\"" << eVerbLevel <<
"\"/>" << std::endl;
486 mueluss << ret << std::endl;
489 adaptingParamList.
remove(pname,
false);
495 if (pname ==
"energy minimization: enable") {
496 mueluss <<
"<Parameter name=\"problem: symmetric\" type=\"bool\" value=\"false\"/>" << std::endl;
497 mueluss <<
"<Parameter name=\"transpose: use implicit\" type=\"bool\" value=\"false\"/>" << std::endl;
501 if (pname ==
"smoother: type") {
506 if (pname.find(
"smoother: list (level", 0) == 0) {
508 std::string type, option;
515 int matched = sscanf(pname.c_str(),
"%s %[^(](level %d)", ctype.
getRawPtr(), coption.
getRawPtr(), &levelID);
517 option = std::string(coption.
getRawPtr());
518 option.resize(option.size() - 1);
520 if (matched != 3 || (type !=
"smoother:")) {
522 <<
"Error in creating level-specific sublists" << std::endl
523 <<
"Offending parameter: " << pname << std::endl);
526 mueluss <<
"<ParameterList name=\"level " << levelID <<
"\">" << std::endl;
528 mueluss <<
"</ParameterList>" << std::endl;
534 if (pname ==
"coarse: list") {
543 mueluss <<
"</ParameterList>" << std::endl;
545 return mueluss.str();
static std::string SetParameterList(const Teuchos::ParameterList ¶mList_in, const std::string &defaultVals)
: Interpret parameter list
const std::string & name() const
void MergeParameterList(const Teuchos::ParameterList &source, Teuchos::ParameterList &dest, bool overWrite)
: merge two parameter lists
ConstIterator end() const
T & get(const std::string &name, T def_value)
ParameterList & set(std::string const &name, T const &value, std::string const &docString="", RCP< const ParameterEntryValidator > const &validator=null)
static std::string interpretParameterName(const std::string &name, const std::string &value)
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
std::string tolower(const std::string &str)
bool isParameter(const std::string &name) const
static std::string GetSmootherFactory(const Teuchos::ParameterList ¶mList, Teuchos::ParameterList &adaptingParamList, const std::string &pname, const std::string &value)
: Helper function which translates ML smoother/solver paramters to MueLu XML string ...
void CreateSublists(const ParameterList &List, ParameterList &newList)
bool remove(std::string const &name, bool throwIfNotExists=true)
params_t::ConstIterator ConstIterator
ConstIterator begin() const
const ParameterEntry & entry(ConstIterator i) const
static std::string ML2MueLu(const std::string &name)
Translate ML parameter to corresponding MueLu parameter.
ParameterList & sublist(const std::string &name, bool mustAlreadyExist=false, const std::string &docString="")
Exception throws to report errors in the internal logical of the program.
static std::string & trim(std::string &s)
void replaceAll(std::string &str, const std::string &from, const std::string &to)