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,
62 "MueLu::MLParameterListInterpreter::Setup(): Only \"coarse: type\", \"smoother: type\" or \"smoother: list\" (\"coarse: list\") are "
63 "supported as ML parameters for transformation of smoother/solver parameters to MueLu");
66 std::stringstream mueluss;
69 std::string mode =
"smoother:";
70 if (pname.find(
"coarse:", 0) == 0)
76 PreOrPost = paramList.
get<std::string>(mode +
" pre or post");
79 "MueLu::MLParameterListInterpreter::Setup(): The parameter \"coarse: pre or post\" is not supported by MueLu. "
80 "It does not make sense for direct solvers. For iterative solvers you obtain the same effect by increasing, "
81 "e.g., the number of sweeps for the coarse grid smoother. Please remove it from your parameters.");
84 std::string valuestr = value;
85 std::transform(valuestr.begin(), valuestr.end(), valuestr.begin(),
::tolower);
86 if ( valuestr ==
"jacobi" || valuestr ==
"gauss-seidel" || valuestr ==
"symmetric gauss-seidel" ) {
88 if ( PreOrPost ==
"both" ) my_name =
"\"" + pname +
"\"";
89 else my_name =
"\"smoother: " + PreOrPost +
" type\"";
90 mueluss <<
"<Parameter name=" << my_name <<
" type=\"string\" value=\"RELAXATION\"/>" << std::endl;
92 }
else if ( valuestr ==
"ifpack" ) {
93 std::string my_name =
"\"" + pname +
"\"";
94 if ( paramList.
isParameter(
"smoother: ifpack type") ) {
95 if ( paramList.
get<std::string>(
"smoother: ifpack type") ==
"ILU" ) {
96 mueluss <<
"<Parameter name=" << my_name <<
" type=\"string\" value=\"ILU\"/>" << std::endl;
97 adaptingParamList.
remove(
"smoother: ifpack type",
false);
99 if ( paramList.
get<std::string>(
"smoother: ifpack type") ==
"ILUT" ) {
100 mueluss <<
"<Parameter name=" << my_name <<
" type\" type=\"string\" value=\"ILUT\"/>" << std::endl;
101 adaptingParamList.
remove(
"smoother: ifpack type",
false);
105 }
else if ( valuestr ==
"chebyshev" ) {
106 std::string my_name =
"\"" + pname +
"\"";
107 mueluss <<
"<Parameter name=" << my_name <<
" type=\"string\" value=\"CHEBYSHEV\"/>" << std::endl;
109 }
else if (valuestr.length() > strlen(
"amesos") && valuestr.substr(0, strlen(
"amesos")) ==
"amesos") {
110 std::string solverType = valuestr.substr(strlen(
"amesos")+1);
113 const int validatorSize = 5;
114 std::string validator[validatorSize] = {
"superlu",
"superludist",
"klu",
"umfpack"};
115 for (
int i=0; i < validatorSize; i++)
116 if (validator[i] == solverType)
119 "MueLu::MLParameterListInterpreter: unknown smoother type. '" << solverType <<
"' not supported.");
121 mueluss <<
"<Parameter name=\"" << pname <<
"\" type=\"string\" value=\"" << solverType <<
"\"/>" << std::endl;
125 std::cout <<
"error in " << __FILE__ <<
":" << __LINE__ <<
" could not find valid smoother/solver" << std::endl;
130 if ( paramList.
isParameter(
"smoother: pre or post") && mode ==
"smoother:") {
134 mueluss <<
"<Parameter name=\"smoother: pre or post\" type=\"string\" value=\"" << PreOrPost <<
"\"/>" << std::endl;
135 adaptingParamList.
remove(
"smoother: pre or post",
false);
139 if (PreOrPost !=
"both") {
140 mueluss <<
"<ParameterList name=\"smoother: " << PreOrPost <<
" params\">" << std::endl;
142 mueluss <<
"<ParameterList name=\"" << mode <<
" params\">" << std::endl;
147 if ( valuestr ==
"jacobi" || valuestr ==
"gauss-seidel" || valuestr ==
"symmetric gauss-seidel" ) {
148 if ( valuestr ==
"jacobi" ) { mueluss <<
"<Parameter name=\"relaxation: type\" type=\"string\" value=\"Jacobi\"/>" << std::endl; adaptingParamList.
remove(
"relaxation: type",
false); }
149 if ( valuestr ==
"gauss-seidel" ) { mueluss <<
"<Parameter name=\"relaxation: type\" type=\"string\" value=\"Gauss-Seidel\"/>" << std::endl; adaptingParamList.
remove(
"relaxation: type",
false); }
150 if ( valuestr ==
"symmetric gauss-seidel" ) { mueluss <<
"<Parameter name=\"relaxation: type\" type=\"string\" value=\"Symmetric Gauss-Seidel\"/>" << std::endl; adaptingParamList.
remove(
"relaxation: type",
false); }
152 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); }
153 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); }
157 if ( valuestr ==
"chebyshev") {
158 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); }
159 else { mueluss <<
"<Parameter name=\"chebyshev: degree\" type=\"int\" value=\"2\"/>" << std::endl; }
160 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); }
161 else { mueluss <<
"<Parameter name=\"chebyshev: ratio eigenvalue\" type=\"double\" value=\"20\"/>" << std::endl; adaptingParamList.
remove(
"smoother: Chebyshev alpha",
false); }
165 if ( valuestr ==
"ifpack") {
168 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); }
169 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); }
170 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); }
171 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); }
174 mueluss <<
"</ParameterList>" << std::endl;
177 if ( paramList.
isParameter(
"smoother: max size") ) {
178 mueluss <<
"<Parameter name=\"coarse: max size\" type=\"int\" value=\"" << paramList.
get<
int>(
"smoother: max size") <<
"\"/>" << std::endl; adaptingParamList.
remove(
"smoother: max size",
false);
181 return mueluss.str();
189 #if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA)
193 if (defaultVals !=
"") {
195 "MueLu::MLParameterListInterpreter: only \"SA\" and \"NSSA\" allowed as options for ML default parameters.");
197 ML_Epetra::SetDefaults(defaultVals,ML_defaultlist);
201 paramList = ML_defaultlist;
204 if (defaultVals !=
"") {
206 *out <<
"Warning: MueLu_ENABLE_ML=OFF. No ML default values available." << std::endl;
208 #endif // HAVE_MUELU_ML
218 paramList = paramListWithSubList;
225 bool validate = paramList.
get(
"ML validate parameter list",
true);
228 #if defined(HAVE_MUELU_ML) && defined(HAVE_MUELU_EPETRA)
230 int depth = paramList.
get(
"ML validate depth", 5);
232 "ERROR: ML's Teuchos::ParameterList contains incorrect parameter!");
235 *out <<
"Warning: MueLu_ENABLE_ML=OFF. The parameter list cannot be validated." << std::endl;
236 paramList.
set(
"ML validate parameter list",
false);
238 #endif // HAVE_MUELU_ML
243 std::stringstream mueluss;
246 mueluss <<
"<ParameterList name=\"MueLu\">" << std::endl;
252 const std::string & pname=paramListWithSubList.
name(param);
256 std::stringstream valuess;
257 valuess << paramList.
entry(param);
258 std::string valuestr = valuess.str();
261 valuestr =
trim(valuestr);
264 std::string valueInterpreterStr =
"\"" + valuestr +
"\"";
269 mueluss << ret << std::endl;
272 adaptingParamList.
remove(pname,
false);
278 if (pname ==
"energy minimization: enable") {
279 mueluss <<
"<Parameter name=\"problem: symmetric\" type=\"bool\" value=\"false\"/>" << std::endl;
280 mueluss <<
"<Parameter name=\"transpose: use implicit\" type=\"bool\" value=\"false\"/>" << std::endl;
284 if (pname ==
"smoother: type") {
291 if (pname.find(
"smoother: list (level",0) == 0) {
293 std::string type, option;
300 int matched = sscanf(pname.c_str(),
"%s %[^(](level %d)", ctype.
getRawPtr(), coption.
getRawPtr(), &levelID);
302 option = std::string(coption.
getRawPtr()); option.resize(option.size () - 1);
304 if (matched != 3 || (type !=
"smoother:")) {
306 <<
"Error in creating level-specific sublists" << std::endl
307 <<
"Offending parameter: " << pname << std::endl);
310 mueluss <<
"<ParameterList name=\"level " << levelID <<
"\">" << std::endl;
312 mueluss <<
"</ParameterList>" << std::endl;
318 if ( pname ==
"coarse: list" ) {
331 mueluss <<
"</ParameterList>" << std::endl;
333 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)