48 #if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA) 49 #include <ml_ValidateParameters.h> 50 #include <ml_MultiLevelPreconditioner.h> 60 TEUCHOS_TEST_FOR_EXCEPTION(pname !=
"coarse: type" && pname !=
"coarse: list" && pname !=
"smoother: type" && pname.find(
"smoother: list",0) != 0,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter::Setup(): Only \"coarse: type\", \"smoother: type\" or \"smoother: list\" (\"coarse: list\") are supported as ML parameters for transformation of smoother/solver parameters to MueLu");
63 std::stringstream mueluss;
66 std::string mode =
"smoother:";
67 if (pname.find(
"coarse:",0) == 0)
72 if (paramList.isParameter(mode +
" pre or post") )
74 PreOrPost = paramList.get<std::string>(mode +
" pre or post");
79 TEUCHOS_TEST_FOR_EXCEPTION(mode==
"coarse:" && PreOrPost !=
"both",
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter::Setup(): The parameter \"coarse: pre or post\" is not supported by MueLu. It does not make sense for direct solvers. For iterative solvers you obtain the same effect by increasing, e.g., the number of sweeps for the coarse grid smoother. Please remove it from your parameters.");
82 std::string valuestr = value;
83 std::transform(valuestr.begin(), valuestr.end(), valuestr.begin(), ::tolower);
84 if ( valuestr ==
"jacobi" || valuestr ==
"gauss-seidel" || valuestr ==
"symmetric gauss-seidel" ) {
86 if ( PreOrPost ==
"both" ) my_name =
"\"" + pname +
"\"";
87 else my_name =
"\"smoother: " + PreOrPost +
" type\"";
88 mueluss <<
"<Parameter name=" << my_name <<
" type=\"string\" value=\"RELAXATION\"/>" << std::endl;
89 }
else if ( valuestr ==
"ifpack" ) {
90 std::string my_name =
"\"" + pname +
"\"";
91 if ( paramList.isParameter(
"smoother: ifpack type") ) {
92 if ( paramList.get<std::string>(
"smoother: ifpack type") ==
"ILU" ) { mueluss <<
"<Parameter name=" << my_name <<
" type=\"string\" value=\"ILU\"/>" << std::endl; adaptingParamList.remove(
"smoother: ifpack type",
false); }
93 if ( paramList.get<std::string>(
"smoother: ifpack type") ==
"ILUT" ) { mueluss <<
"<Parameter name=" << my_name <<
" type\" type=\"string\" value=\"ILUT\"/>" << std::endl; adaptingParamList.remove(
"smoother: ifpack type",
false); }
95 }
else if ( valuestr ==
"chebyshev" ) {
96 std::string my_name =
"\"" + pname +
"\"";
97 mueluss <<
"<Parameter name=" << my_name <<
" type=\"string\" value=\"CHEBYSHEV\"/>" << std::endl;
98 }
else if (valuestr.length() > strlen(
"amesos") && valuestr.substr(0, strlen(
"amesos")) ==
"amesos") {
99 std::string solverType = valuestr.substr(strlen(
"amesos")+1);
102 const int validatorSize = 5;
103 std::string validator[validatorSize] = {
"superlu",
"superludist",
"klu",
"umfpack"};
104 for (
int i=0; i < validatorSize; i++) {
if (validator[i] == solverType) valid =
true; }
105 TEUCHOS_TEST_FOR_EXCEPTION(!valid,
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter: unknown smoother type. '" << solverType <<
"' not supported.");
107 mueluss <<
"<Parameter name=\"" << pname <<
"\" type=\"string\" value=\"" << solverType <<
"\"/>" << std::endl;
110 std::cout <<
"error in " << __FILE__ <<
":" << __LINE__ <<
" could not find valid smoother/solver" << std::endl;
115 if ( paramList.isParameter(
"smoother: pre or post") && mode ==
"smoother:") {
119 mueluss <<
"<Parameter name=\"smoother: pre or post\" type=\"string\" value=\"" << PreOrPost <<
"\"/>" << std::endl;
120 adaptingParamList.remove(
"smoother: pre or post",
false);
124 if (PreOrPost !=
"both") {
125 mueluss <<
"<ParameterList name=\"smoother: " << PreOrPost <<
" params\">" << std::endl;
127 mueluss <<
"<ParameterList name=\"" << mode <<
" params\">" << std::endl;
132 if ( valuestr ==
"jacobi" || valuestr ==
"gauss-seidel" || valuestr ==
"symmetric gauss-seidel" ) {
133 if ( valuestr ==
"jacobi" ) { mueluss <<
"<Parameter name=\"relaxation: type\" type=\"string\" value=\"Jacobi\"/>" << std::endl; adaptingParamList.remove(
"relaxation: type",
false); }
134 if ( valuestr ==
"gauss-seidel" ) { mueluss <<
"<Parameter name=\"relaxation: type\" type=\"string\" value=\"Gauss-Seidel\"/>" << std::endl; adaptingParamList.remove(
"relaxation: type",
false); }
135 if ( valuestr ==
"symmetric gauss-seidel" ) { mueluss <<
"<Parameter name=\"relaxation: type\" type=\"string\" value=\"Symmetric Gauss-Seidel\"/>" << std::endl; adaptingParamList.remove(
"relaxation: type",
false); }
137 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); }
138 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); }
142 if ( valuestr ==
"chebyshev") {
143 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); }
144 else { mueluss <<
"<Parameter name=\"chebyshev: degree\" type=\"int\" value=\"2\"/>" << std::endl; }
145 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); }
146 else { mueluss <<
"<Parameter name=\"chebyshev: ratio eigenvalue\" type=\"double\" value=\"20\"/>" << std::endl; adaptingParamList.remove(
"smoother: Chebyshev alpha",
false); }
150 if ( valuestr ==
"ifpack") {
153 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); }
154 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); }
155 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); }
156 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); }
159 mueluss <<
"</ParameterList>" << std::endl;
162 if ( paramList.isParameter(
"smoother: max size") ) {
163 mueluss <<
"<Parameter name=\"coarse: max size\" type=\"int\" value=\"" << paramList.get<
int>(
"smoother: max size") <<
"\"/>" << std::endl; adaptingParamList.remove(
"smoother: max size",
false);
166 return mueluss.str();
171 Teuchos::ParameterList paramList = paramList_in;
173 RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout));
175 #if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA) 179 if (defaultVals !=
"") {
181 "MueLu::MLParameterListInterpreter: only \"SA\" and \"NSSA\" allowed as options for ML default parameters.");
182 Teuchos::ParameterList ML_defaultlist;
183 ML_Epetra::SetDefaults(defaultVals,ML_defaultlist);
187 paramList = ML_defaultlist;
190 if (defaultVals !=
"") {
192 *out <<
"Warning: MueLu_ENABLE_ML=OFF. No ML default values available." << std::endl;
194 #endif // HAVE_MUELU_ML 202 ParameterList paramListWithSubList;
204 paramList = paramListWithSubList;
205 Teuchos::ParameterList adaptingParamList = paramList;
211 bool validate = paramList.get(
"ML validate parameter list",
true);
214 #if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA) 216 int depth = paramList.get(
"ML validate depth", 5);
218 "ERROR: ML's Teuchos::ParameterList contains incorrect parameter!");
221 *out <<
"Warning: MueLu_ENABLE_ML=OFF. The parameter list cannot be validated." << std::endl;
222 paramList.set(
"ML validate parameter list",
false);
224 #endif // HAVE_MUELU_ML 229 std::stringstream mueluss;
232 mueluss <<
"<ParameterList name=\"MueLu\">" << std::endl;
235 for (ParameterList::ConstIterator param=paramListWithSubList.begin(); param!=paramListWithSubList.end(); ++param) {
238 const std::string & pname=paramListWithSubList.name(param);
242 std::stringstream valuess;
243 valuess << paramList.entry(param);
244 std::string valuestr = valuess.str();
247 valuestr =
trim(valuestr);
250 std::string valueInterpreterStr =
"\"" + valuestr +
"\"";
255 mueluss << ret << std::endl;
258 adaptingParamList.remove(pname,
false);
264 if (pname ==
"energy minimization: enable") {
265 mueluss <<
"<Parameter name=\"problem: symmetric\" type=\"bool\" value=\"false\"/>" << std::endl;
266 mueluss <<
"<Parameter name=\"transpose: use implicit\" type=\"bool\" value=\"false\"/>" << std::endl;
270 if (pname ==
"smoother: type") {
277 if (pname.find(
"smoother: list (level",0) == 0) {
279 std::string type, option;
282 typedef Teuchos::ArrayRCP<char>::size_type size_type;
283 Teuchos::Array<char> ctype (size_type(pname.size()+1));
284 Teuchos::Array<char> coption(size_type(pname.size()+1));
286 int matched = sscanf(pname.c_str(),
"%s %[^(](level %d)", ctype.getRawPtr(), coption.getRawPtr(), &levelID);
287 type = std::string(ctype.getRawPtr());
288 option = std::string(coption.getRawPtr()); option.resize(option.size () - 1);
290 if (matched != 3 || (type !=
"smoother:")) {
292 <<
"Error in creating level-specific sublists" << std::endl
293 <<
"Offending parameter: " << pname << std::endl);
296 mueluss <<
"<ParameterList name=\"level " << levelID <<
"\">" << std::endl;
297 mueluss <<
GetSmootherFactory(paramList.sublist(pname),adaptingParamList.sublist(pname),
"smoother: type", paramList.sublist(pname).get<std::string>(
"smoother: type"));
298 mueluss <<
"</ParameterList>" << std::endl;
303 TEUCHOS_TEST_FOR_EXCEPTION(paramList.isParameter(
"coarse: type"),
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter::Setup(): The parameter \"coarse: type\" should not exist but being stored in \"coarse: list\" instead.");
304 if ( pname ==
"coarse: list" ) {
310 TEUCHOS_TEST_FOR_EXCEPTION(!paramList.sublist(
"coarse: list").isParameter(
"smoother: type"),
Exceptions::RuntimeError,
"MueLu::MLParameterListInterpreter::Setup(): no coarse grid solver defined.");
311 mueluss <<
GetSmootherFactory(paramList.sublist(
"coarse: list"), adaptingParamList.sublist(
"coarse: list"),
"coarse: type", paramList.sublist(
"coarse: list").get<std::string>(
"smoother: type"));
320 mueluss <<
"</ParameterList>" << std::endl;
322 return mueluss.str();
static std::string SetParameterList(const Teuchos::ParameterList ¶mList_in, const std::string &defaultVals)
: Interpret parameter list
void MergeParameterList(const Teuchos::ParameterList &source, Teuchos::ParameterList &dest, bool overWrite)
: merge two parameter lists
static std::string interpretParameterName(const std::string &name, const std::string &value)
Namespace for MueLu classes and methods.
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)
static std::string ML2MueLu(const std::string &name)
Translate ML parameter to corresponding MueLu parameter.
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)