48 #if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA)
49 #include <ml_ValidateParameters.h>
50 #include <ml_MultiLevelPreconditioner.h>
51 #include <ml_RefMaxwell.h>
61 TEUCHOS_TEST_FOR_EXCEPTION(pname !=
"coarse: type" && pname !=
"coarse: list" && pname !=
"smoother: type" && pname.find(
"smoother: list",0) != 0,
63 "MueLu::MLParameterListInterpreter::Setup(): Only \"coarse: type\", \"smoother: type\" or \"smoother: list\" (\"coarse: list\") are "
64 "supported as ML parameters for transformation of smoother/solver parameters to MueLu");
67 std::stringstream mueluss;
70 std::string mode =
"smoother:";
71 if (pname.find(
"coarse:", 0) == 0)
77 PreOrPost = paramList.
get<std::string>(mode +
" pre or post");
80 "MueLu::MLParameterListInterpreter::Setup(): The parameter \"coarse: pre or post\" is not supported by MueLu. "
81 "It does not make sense for direct solvers. For iterative solvers you obtain the same effect by increasing, "
82 "e.g., the number of sweeps for the coarse grid smoother. Please remove it from your parameters.");
85 std::string valuestr = value;
86 std::transform(valuestr.begin(), valuestr.end(), valuestr.begin(),
::tolower);
87 if ( valuestr ==
"jacobi" || valuestr ==
"gauss-seidel" || valuestr ==
"symmetric gauss-seidel" ) {
89 if ( PreOrPost ==
"both" ) my_name =
"\"" + pname +
"\"";
90 else my_name =
"\"smoother: " + PreOrPost +
" type\"";
91 mueluss <<
"<Parameter name=" << my_name <<
" type=\"string\" value=\"RELAXATION\"/>" << std::endl;
93 }
else if ( valuestr ==
"ifpack" ) {
94 std::string my_name =
"\"" + pname +
"\"";
95 if ( paramList.
isParameter(
"smoother: ifpack type") ) {
96 if ( paramList.
get<std::string>(
"smoother: ifpack type") ==
"ILU" ) {
97 mueluss <<
"<Parameter name=" << my_name <<
" type=\"string\" value=\"ILU\"/>" << std::endl;
98 adaptingParamList.
remove(
"smoother: ifpack type",
false);
100 if ( paramList.
get<std::string>(
"smoother: ifpack type") ==
"ILUT" ) {
101 mueluss <<
"<Parameter name=" << my_name <<
" type\" type=\"string\" value=\"ILUT\"/>" << std::endl;
102 adaptingParamList.
remove(
"smoother: ifpack type",
false);
106 }
else if ( valuestr ==
"chebyshev" ) {
107 std::string my_name =
"\"" + pname +
"\"";
108 mueluss <<
"<Parameter name=" << my_name <<
" type=\"string\" value=\"CHEBYSHEV\"/>" << std::endl;
110 }
else if (valuestr.length() > strlen(
"amesos") && valuestr.substr(0, strlen(
"amesos")) ==
"amesos") {
111 std::string solverType = valuestr.substr(strlen(
"amesos")+1);
114 const int validatorSize = 5;
115 std::string validator[validatorSize] = {
"superlu",
"superludist",
"klu",
"umfpack",
"mumps"};
116 for (
int i=0; i < validatorSize; i++)
117 if (validator[i] == solverType)
120 "MueLu::MLParameterListInterpreter: unknown smoother type. '" << solverType <<
"' not supported.");
122 mueluss <<
"<Parameter name=\"" << pname <<
"\" type=\"string\" value=\"" << solverType <<
"\"/>" << std::endl;
126 std::cout <<
"error in " << __FILE__ <<
":" << __LINE__ <<
" could not find valid smoother/solver" << std::endl;
131 if ( paramList.
isParameter(
"smoother: pre or post") && mode ==
"smoother:") {
135 mueluss <<
"<Parameter name=\"smoother: pre or post\" type=\"string\" value=\"" << PreOrPost <<
"\"/>" << std::endl;
136 adaptingParamList.
remove(
"smoother: pre or post",
false);
140 if (PreOrPost !=
"both") {
141 mueluss <<
"<ParameterList name=\"smoother: " << PreOrPost <<
" params\">" << std::endl;
143 mueluss <<
"<ParameterList name=\"" << mode <<
" params\">" << std::endl;
148 if ( valuestr ==
"jacobi" || valuestr ==
"gauss-seidel" || valuestr ==
"symmetric gauss-seidel" ) {
149 if ( valuestr ==
"jacobi" ) { mueluss <<
"<Parameter name=\"relaxation: type\" type=\"string\" value=\"Jacobi\"/>" << std::endl; adaptingParamList.
remove(
"relaxation: type",
false); }
150 if ( valuestr ==
"gauss-seidel" ) { mueluss <<
"<Parameter name=\"relaxation: type\" type=\"string\" value=\"Gauss-Seidel\"/>" << std::endl; adaptingParamList.
remove(
"relaxation: type",
false); }
151 if ( valuestr ==
"symmetric gauss-seidel" ) { mueluss <<
"<Parameter name=\"relaxation: type\" type=\"string\" value=\"Symmetric Gauss-Seidel\"/>" << std::endl; adaptingParamList.
remove(
"relaxation: type",
false); }
153 if ( paramList.
isParameter(
"smoother: sweeps") ) { mueluss <<
"<Parameter name=\"relaxation: sweeps\" type=\"int\" value=\"" << paramList.
get<
int>(
"smoother: sweeps") <<
"\"/>" << std::endl; adaptingParamList.
remove(
"smoother: sweeps",
false); }
154 if ( paramList.
isParameter(
"smoother: damping factor") ) { mueluss <<
"<Parameter name=\"relaxation: damping factor\" type=\"double\" value=\"" << paramList.
get<
double>(
"smoother: damping factor") <<
"\"/>" << std::endl; adaptingParamList.
remove(
"smoother: damping factor",
false); }
158 if ( valuestr ==
"chebyshev") {
159 if ( paramList.
isParameter(
"smoother: polynomial order") ) { mueluss <<
"<Parameter name=\"chebyshev: degree\" type=\"int\" value=\"" << paramList.
get<
int>(
"smoother: polynomial order") <<
"\"/>" << std::endl; adaptingParamList.
remove(
"smoother: polynomial order",
false); }
160 else { mueluss <<
"<Parameter name=\"chebyshev: degree\" type=\"int\" value=\"2\"/>" << std::endl; }
161 if ( paramList.
isParameter(
"smoother: Chebyshev alpha") ) { mueluss <<
"<Parameter name=\"chebyshev: ratio eigenvalue\" type=\"double\" value=\"" << paramList.
get<
double>(
"smoother: Chebyshev alpha") <<
"\"/>" << std::endl; adaptingParamList.
remove(
"smoother: Chebyshev alpha",
false); }
162 else { mueluss <<
"<Parameter name=\"chebyshev: ratio eigenvalue\" type=\"double\" value=\"20\"/>" << std::endl; adaptingParamList.
remove(
"smoother: Chebyshev alpha",
false); }
166 if ( valuestr ==
"ifpack") {
169 if ( paramList.
isParameter(
"smoother: ifpack overlap") ) { mueluss <<
"<Parameter name=\"partitioner: overlap\" type=\"int\" value=\"" << paramList.
get<
int>(
"smoother: ifpack overlap") <<
"\"/>" << std::endl; adaptingParamList.
remove(
"smoother: ifpack overlap",
false); }
170 if ( paramList.
isParameter(
"smoother: ifpack level-of-fill") ) { mueluss <<
"<Parameter name=\"fact: level-of-fill\" type=\"int\" value=\"" << paramList.
get<
int>(
"smoother: ifpack level-of-fill") <<
"\"/>" << std::endl; adaptingParamList.
remove(
"smoother: ifpack level-of-fill",
false); }
171 if ( paramList.
isParameter(
"smoother: ifpack absolute threshold") ) { mueluss <<
"<Parameter name=\"fact: absolute threshold\" type=\"int\" value=\"" << paramList.
get<
double>(
"smoother: ifpack absolute threshold") <<
"\"/>" << std::endl; adaptingParamList.
remove(
"smoother: ifpack absolute threshold",
false); }
172 if ( paramList.
isParameter(
"smoother: ifpack relative threshold") ) { mueluss <<
"<Parameter name=\"fact: relative threshold\" type=\"int\" value=\"" << paramList.
get<
double>(
"smoother: ifpack relative threshold") <<
"\"/>" << std::endl; adaptingParamList.
remove(
"smoother: ifpack relative threshold",
false); }
175 mueluss <<
"</ParameterList>" << std::endl;
178 if ( paramList.
isParameter(
"smoother: max size") ) {
179 mueluss <<
"<Parameter name=\"coarse: max size\" type=\"int\" value=\"" << paramList.
get<
int>(
"smoother: max size") <<
"\"/>" << std::endl; adaptingParamList.
remove(
"smoother: max size",
false);
182 return mueluss.str();
190 #if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA)
194 if (defaultVals !=
"") {
196 "MueLu::MLParameterListInterpreter: only \"SA\", \"NSSA\", and \"refmaxwell\" allowed as options for ML default parameters.");
198 if (defaultVals ==
"refmaxwell")
199 ML_Epetra::SetDefaultsRefMaxwell(ML_defaultlist);
201 ML_Epetra::SetDefaults(defaultVals,ML_defaultlist);
205 paramList = ML_defaultlist;
208 if (defaultVals !=
"") {
210 *out <<
"Warning: MueLu_ENABLE_ML=OFF and/or MueLu_ENABLE_Epetra=OFF. No ML default values available." << std::endl;
212 #endif // HAVE_MUELU_ML
222 paramList = paramListWithSubList;
229 bool validate = paramList.
get(
"ML validate parameter list",
true);
230 if (validate && defaultVals!=
"refmaxwell") {
232 #if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA)
234 int depth = paramList.
get(
"ML validate depth", 5);
236 "ERROR: ML's Teuchos::ParameterList contains incorrect parameter!");
239 *out <<
"Warning: MueLu_ENABLE_ML=OFF and/or MueLu_ENABLE_Epetra=OFF. The parameter list cannot be validated." << std::endl;
240 paramList.
set(
"ML validate parameter list",
false);
242 #endif // HAVE_MUELU_ML
247 std::stringstream mueluss;
250 mueluss <<
"<ParameterList name=\"MueLu\">" << std::endl;
256 const std::string & pname=paramListWithSubList.
name(param);
260 std::stringstream valuess;
261 valuess << paramList.
entry(param);
262 std::string valuestr = valuess.str();
265 valuestr =
trim(valuestr);
268 std::string valueInterpreterStr =
"\"" + valuestr +
"\"";
273 mueluss << ret << std::endl;
276 adaptingParamList.
remove(pname,
false);
282 if (pname ==
"energy minimization: enable") {
283 mueluss <<
"<Parameter name=\"problem: symmetric\" type=\"bool\" value=\"false\"/>" << std::endl;
284 mueluss <<
"<Parameter name=\"transpose: use implicit\" type=\"bool\" value=\"false\"/>" << std::endl;
288 if (pname ==
"smoother: type") {
295 if (pname.find(
"smoother: list (level",0) == 0) {
297 std::string type, option;
304 int matched = sscanf(pname.c_str(),
"%s %[^(](level %d)", ctype.
getRawPtr(), coption.
getRawPtr(), &levelID);
306 option = std::string(coption.
getRawPtr()); option.resize(option.size () - 1);
308 if (matched != 3 || (type !=
"smoother:")) {
310 <<
"Error in creating level-specific sublists" << std::endl
311 <<
"Offending parameter: " << pname << std::endl);
314 mueluss <<
"<ParameterList name=\"level " << levelID <<
"\">" << std::endl;
316 mueluss <<
"</ParameterList>" << std::endl;
322 if ( pname ==
"coarse: list" ) {
335 mueluss <<
"</ParameterList>" << std::endl;
337 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)