MueLu  Version of the Day
MueLu_ML2MueLuParameterTranslator.cpp
Go to the documentation of this file.
1 // @HEADER
2 //
3 // ***********************************************************************
4 //
5 // MueLu: A package for multigrid based preconditioning
6 // Copyright 2012 Sandia Corporation
7 //
8 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
9 // the U.S. Government retains certain rights in this software.
10 //
11 // Redistribution and use in source and binary forms, with or without
12 // modification, are permitted provided that the following conditions are
13 // met:
14 //
15 // 1. Redistributions of source code must retain the above copyright
16 // notice, this list of conditions and the following disclaimer.
17 //
18 // 2. Redistributions in binary form must reproduce the above copyright
19 // notice, this list of conditions and the following disclaimer in the
20 // documentation and/or other materials provided with the distribution.
21 //
22 // 3. Neither the name of the Corporation nor the names of the
23 // contributors may be used to endorse or promote products derived from
24 // this software without specific prior written permission.
25 //
26 // THIS SOFTWARE IS PROVIDED BY SANDIA CORPORATION "AS IS" AND ANY
27 // EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 // IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
29 // PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SANDIA CORPORATION OR THE
30 // CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
31 // EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
32 // PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
33 // PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
34 // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
35 // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 // SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 //
38 // Questions? Contact
39 // Jonathan Hu (jhu@sandia.gov)
40 // Andrey Prokopenko (aprokop@sandia.gov)
41 // Ray Tuminaro (rstumin@sandia.gov)
42 //
43 // ***********************************************************************
44 //
45 // @HEADER
46 
47 #include "MueLu_ConfigDefs.hpp"
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> // for default values
53 # include <ml_RefMaxwell.h>
54 # endif
55 #endif
56 
58 
59 namespace MueLu {
60 
61 
62  std::string ML2MueLuParameterTranslator::GetSmootherFactory(const Teuchos::ParameterList& paramList, Teuchos::ParameterList& adaptingParamList, const std::string& pname, const std::string& value) {
63 
64  TEUCHOS_TEST_FOR_EXCEPTION(pname != "coarse: type" && pname != "coarse: list" && pname != "smoother: type" && pname.find("smoother: list",0) != 0,
66  "MueLu::MLParameterListInterpreter::Setup(): Only \"coarse: type\", \"smoother: type\" or \"smoother: list\" (\"coarse: list\") are "
67  "supported as ML parameters for transformation of smoother/solver parameters to MueLu");
68 
69  // string stream containing the smoother/solver xml parameters
70  std::stringstream mueluss;
71 
72  // Check whether we are dealing with coarse level (solver) parameters or level smoother parameters
73  std::string mode = "smoother:";
74  if (pname.find("coarse:", 0) == 0)
75  mode = "coarse:";
76 
77  // check whether pre and/or post smoothing
78  std::string PreOrPost = "both";
79  if (paramList.isParameter(mode + " pre or post"))
80  PreOrPost = paramList.get<std::string>(mode + " pre or post");
81 
82  TEUCHOS_TEST_FOR_EXCEPTION(mode == "coarse:" && PreOrPost != "both", Exceptions::RuntimeError,
83  "MueLu::MLParameterListInterpreter::Setup(): The parameter \"coarse: pre or post\" is not supported by MueLu. "
84  "It does not make sense for direct solvers. For iterative solvers you obtain the same effect by increasing, "
85  "e.g., the number of sweeps for the coarse grid smoother. Please remove it from your parameters.");
86 
87  // select smoother type
88  std::string valuestr = value; // temporary variable
89  std::transform(valuestr.begin(), valuestr.end(), valuestr.begin(), ::tolower);
90  if ( valuestr == "jacobi" || valuestr == "gauss-seidel" || valuestr == "symmetric gauss-seidel" ) {
91  std::string my_name;
92  if ( PreOrPost == "both" ) my_name = "\"" + pname + "\"";
93  else my_name = "\"smoother: " + PreOrPost + " type\"";
94  mueluss << "<Parameter name=" << my_name << " type=\"string\" value=\"RELAXATION\"/>" << std::endl;
95 
96  } else if ( valuestr == "hiptmair" ) {
97  std::string my_name;
98  if ( PreOrPost == "both" ) my_name = "\"" + pname + "\"";
99  else my_name = "\"smoother: " + PreOrPost + " type\"";
100  mueluss << "<Parameter name=" << my_name << " type=\"string\" value=\"HIPTMAIR\"/>" << std::endl;
101 
102  } else if ( valuestr == "ifpack" ) {
103  std::string my_name = "\"" + pname + "\"";
104  if ( paramList.isParameter("smoother: ifpack type") ) {
105  if ( paramList.get<std::string>("smoother: ifpack type") == "ILU" ) {
106  mueluss << "<Parameter name=" << my_name << " type=\"string\" value=\"ILU\"/>" << std::endl;
107  adaptingParamList.remove("smoother: ifpack type",false);
108  }
109  if ( paramList.get<std::string>("smoother: ifpack type") == "ILUT" ) {
110  mueluss << "<Parameter name=" << my_name << " type\" type=\"string\" value=\"ILUT\"/>" << std::endl;
111  adaptingParamList.remove("smoother: ifpack type",false);
112  }
113  }
114 
115  } else if (( valuestr == "chebyshev" ) || ( valuestr == "mls" )) {
116  std::string my_name = "\"" + pname + "\"";
117  mueluss << "<Parameter name=" << my_name << " type=\"string\" value=\"CHEBYSHEV\"/>" << std::endl;
118 
119  } else if (valuestr.length() > strlen("amesos") && valuestr.substr(0, strlen("amesos")) == "amesos") { /* catch Amesos-* */
120  std::string solverType = valuestr.substr(strlen("amesos")+1); /* ("amesos-klu" -> "klu") */
121 
122  bool valid = false;
123  const int validatorSize = 5;
124  std::string validator[validatorSize] = {"superlu", "superludist", "klu", "umfpack", "mumps"};
125  for (int i=0; i < validatorSize; i++)
126  if (validator[i] == solverType)
127  valid = true;
128  TEUCHOS_TEST_FOR_EXCEPTION(!valid, Exceptions::RuntimeError,
129  "MueLu::MLParameterListInterpreter: unknown smoother type. '" << solverType << "' not supported.");
130 
131  mueluss << "<Parameter name=\"" << pname << "\" type=\"string\" value=\"" << solverType << "\"/>" << std::endl;
132 
133  } else {
134  // TODO error message
135  std::cout << "error in " << __FILE__ << ":" << __LINE__ << " could not find valid smoother/solver" << std::endl;
136  }
137 
138  // set smoother: pre or post parameter
139  // Note that there is no "coarse: pre or post" in MueLu!
140  if ( paramList.isParameter("smoother: pre or post") && mode == "smoother:") {
141  //std::cout << "paramList" << paramList << std::endl;
142  //std::string smootherPreOrPost = paramList.get<std::string>("smoother: pre or post");
143  //std::cout << "Create pre or post parameter with " << smootherPreOrPost << std::endl;
144  mueluss << "<Parameter name=\"smoother: pre or post\" type=\"string\" value=\"" << PreOrPost << "\"/>" << std::endl;
145  adaptingParamList.remove("smoother: pre or post",false);
146  }
147 
148  // create smoother parameter list
149  if (PreOrPost != "both") {
150  mueluss << "<ParameterList name=\"smoother: " << PreOrPost << " params\">" << std::endl;
151  } else {
152  mueluss << "<ParameterList name=\"" << mode << " params\">" << std::endl;
153  }
154 
155  // relaxation based smoothers:
156 
157  if ( valuestr == "jacobi" || valuestr == "gauss-seidel" || valuestr == "symmetric gauss-seidel" ) {
158  if ( valuestr == "jacobi" ) { mueluss << "<Parameter name=\"relaxation: type\" type=\"string\" value=\"Jacobi\"/>" << std::endl; adaptingParamList.remove("relaxation: type",false); }
159  if ( valuestr == "gauss-seidel" ) { mueluss << "<Parameter name=\"relaxation: type\" type=\"string\" value=\"Gauss-Seidel\"/>" << std::endl; adaptingParamList.remove("relaxation: type",false); }
160  if ( valuestr == "symmetric gauss-seidel" ) { mueluss << "<Parameter name=\"relaxation: type\" type=\"string\" value=\"Symmetric Gauss-Seidel\"/>" << std::endl; adaptingParamList.remove("relaxation: type",false); }
161 
162  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); }
163  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); }
164  if ( paramList.isParameter("smoother: use l1 Gauss-Seidel") ) { mueluss << "<Parameter name=\"relaxation: use l1\" type=\"bool\" value=\"" << paramList.get<bool>("smoother: use l1 Gauss-Seidel") << "\"/>" << std::endl; adaptingParamList.remove("smoother: use l1 Gauss-Seidel",false); }
165  }
166 
167  // Chebyshev
168  if ( valuestr == "chebyshev") {
169  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); }
170  else { mueluss << "<Parameter name=\"chebyshev: degree\" type=\"int\" value=\"2\"/>" << std::endl; }
171  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); }
172  else { mueluss << "<Parameter name=\"chebyshev: ratio eigenvalue\" type=\"double\" value=\"20\"/>" << std::endl; adaptingParamList.remove("smoother: Chebyshev alpha",false); }
173  if ( paramList.isParameter("eigen-analysis: type") ) { mueluss << "<Parameter name=\"eigen-analysis: type\" type=\"string\" value=\"" << paramList.get<std::string>("eigen-analysis: type") << "\"/>" << std::endl; adaptingParamList.remove("eigen-analysis: type",false); }
174  else { mueluss << "<Parameter name=\"eigen-analysis: type\" type=\"string\" value=\"cg\"/>" << std::endl; }
175  }
176 
177  // MLS
178  if ( valuestr == "mls") {
179  if ( paramList.isParameter("smoother: MLS polynomial order") ) { mueluss << "<Parameter name=\"chebyshev: degree\" type=\"int\" value=\"" << paramList.get<int>("smoother: MLS polynomial order") << "\"/>" << std::endl; adaptingParamList.remove("smoother: MLS polynomial order",false); }
180  else 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); }
181  else { mueluss << "<Parameter name=\"chebyshev: degree\" type=\"int\" value=\"2\"/>" << std::endl; }
182  if ( paramList.isParameter("smoother: MLS alpha") ) { mueluss << "<Parameter name=\"chebyshev: ratio eigenvalue\" type=\"double\" value=\"" << paramList.get<double>("smoother: MLS alpha") << "\"/>" << std::endl; adaptingParamList.remove("smoother: MLS alpha",false); }
183  else 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); }
184  else { mueluss << "<Parameter name=\"chebyshev: ratio eigenvalue\" type=\"double\" value=\"20\"/>" << std::endl; }
185  if ( paramList.isParameter("eigen-analysis: type") ) { mueluss << "<Parameter name=\"eigen-analysis: type\" type=\"string\" value=\"" << paramList.get<std::string>("eigen-analysis: type") << "\"/>" << std::endl; adaptingParamList.remove("eigen-analysis: type",false); }
186  else { mueluss << "<Parameter name=\"eigen-analysis: type\" type=\"string\" value=\"cg\"/>" << std::endl; }
187  }
188 
189  if ( valuestr == "hiptmair" ) {
190  std::string subSmootherType = "Chebyshev";
191  if (paramList.isParameter("subsmoother: type"))
192  subSmootherType = paramList.get<std::string>("subsmoother: type");
193  std::string subSmootherIfpackType;
194  if (subSmootherType == "Chebyshev")
195  subSmootherIfpackType = "CHEBYSHEV";
196  else if (subSmootherType == "Jacobi" || subSmootherType == "Gauss-Seidel" || subSmootherType == "symmetric Gauss-Seidel") {
197  if (subSmootherType == "symmetric Gauss-Seidel") subSmootherType = "Symmetric Gauss-Seidel"; // FIXME
198  subSmootherIfpackType = "RELAXATION";
199  } else
200  TEUCHOS_TEST_FOR_EXCEPTION(true, Exceptions::RuntimeError, "MueLu::MLParameterListTranslator: unknown smoother type. '" << subSmootherType << "' not supported by MueLu.");
201 
202  mueluss << "<Parameter name=\"hiptmair: smoother type 1\" type=\"string\" value=\"" << subSmootherIfpackType << "\"/>" << std::endl;
203  mueluss << "<Parameter name=\"hiptmair: smoother type 2\" type=\"string\" value=\"" << subSmootherIfpackType << "\"/>" << std::endl;
204 
205  mueluss << "<ParameterList name=\"hiptmair: smoother list 1\">" << std::endl;
206  if (subSmootherType == "Chebyshev") {
207  if (paramList.isParameter("subsmoother: edge sweeps")) {
208  mueluss << "<Parameter name=\"chebyshev: degree\" type=\"int\" value=\"" << paramList.get<int>("subsmoother: edge sweeps") << "\"/>" << std::endl;
209  adaptingParamList.remove("subsmoother: edge sweeps", false);
210  }
211  if (paramList.isParameter("subsmoother: Chebyshev alpha")) {
212  mueluss << "<Parameter name=\"chebyshev: ratio eigenvalue\" type=\"double\" value=\"" << paramList.get<double>("subsmoother: Chebyshev alpha") << "\"/>" << std::endl;
213  }
214  } else {
215  if (paramList.isParameter("subsmoother: edge sweeps")) {
216  mueluss << "<Parameter name=\"relaxation: type\" type=\"string\" value=\"" << subSmootherType << "\"/>" << std::endl;
217  mueluss << "<Parameter name=\"relaxation: sweeps\" type=\"int\" value=\"" << paramList.get<int>("subsmoother: edge sweeps") << "\"/>" << std::endl;
218  adaptingParamList.remove("subsmoother: edge sweeps", false);
219  }
220  if (paramList.isParameter("subsmoother: SGS damping factor")) {
221  mueluss << "<Parameter name=\"relaxation: damping factor\" type=\"double\" value=\"" << paramList.get<double>("subsmoother: SGS damping factor") << "\"/>" << std::endl;
222  }
223  }
224  mueluss << "</ParameterList>" << std::endl;
225 
226  mueluss << "<ParameterList name=\"hiptmair: smoother list 2\">" << std::endl;
227  if (subSmootherType == "Chebyshev") {
228  if (paramList.isParameter("subsmoother: node sweeps")) {
229  mueluss << "<Parameter name=\"chebyshev: degree\" type=\"int\" value=\"" << paramList.get<int>("subsmoother: node sweeps") << "\"/>" << std::endl;
230  adaptingParamList.remove("subsmoother: node sweeps", false);
231  }
232  if (paramList.isParameter("subsmoother: Chebyshev alpha")) {
233  mueluss << "<Parameter name=\"chebyshev: ratio eigenvalue\" type=\"double\" value=\"" << paramList.get<double>("subsmoother: Chebyshev alpha") << "\"/>" << std::endl;
234  adaptingParamList.remove("subsmoother: Chebyshev alpha", false);
235  }
236  } else {
237  if (paramList.isParameter("subsmoother: node sweeps")) {
238  mueluss << "<Parameter name=\"relaxation: type\" type=\"string\" value=\"" << subSmootherType << "\"/>" << std::endl;
239  mueluss << "<Parameter name=\"relaxation: sweeps\" type=\"int\" value=\"" << paramList.get<int>("subsmoother: node sweeps") << "\"/>" << std::endl;
240  adaptingParamList.remove("subsmoother: node sweeps", false);
241  }
242  if (paramList.isParameter("subsmoother: SGS damping factor")) {
243  mueluss << "<Parameter name=\"relaxation: damping factor\" type=\"double\" value=\"" << paramList.get<double>("subsmoother: SGS damping factor") << "\"/>" << std::endl;
244  adaptingParamList.remove("subsmoother: SGS damping factor", false);
245  }
246  }
247  mueluss << "</ParameterList>" << std::endl;
248 
249  }
250 
251  // parameters for ILU based preconditioners
252  if ( valuestr == "ifpack") {
253 
254  // add Ifpack parameters
255  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); }
256  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); }
257  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); }
258  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); }
259  }
260 
261  mueluss << "</ParameterList>" << std::endl;
262 
263  // max coarse level size parameter (outside of smoother parameter lists)
264  if ( paramList.isParameter("smoother: max size") ) {
265  mueluss << "<Parameter name=\"coarse: max size\" type=\"int\" value=\"" << paramList.get<int>("smoother: max size") << "\"/>" << std::endl; adaptingParamList.remove("smoother: max size",false);
266  }
267 
268  return mueluss.str();
269  }
270 
271  std::string ML2MueLuParameterTranslator::SetParameterList(const Teuchos::ParameterList & paramList_in, const std::string& defaultVals) {
272  Teuchos::ParameterList paramList = paramList_in;
273 
274  RCP<Teuchos::FancyOStream> out = Teuchos::fancyOStream(Teuchos::rcpFromRef(std::cout)); // TODO: use internal out (GetOStream())
275 
276 #if defined(HAVE_MUELU_ML) && defined(HAVE_ML_EPETRA) && defined(HAVE_ML_TEUCHOS)
277 
278  // TODO alternative with standard parameterlist from ML user guide?
279 
280  if (defaultVals != "") {
281  TEUCHOS_TEST_FOR_EXCEPTION(defaultVals!="SA" && defaultVals!="NSSA" && defaultVals!="refmaxwell" && defaultVals!="Maxwell", Exceptions::RuntimeError,
282  "MueLu::MLParameterListInterpreter: only \"SA\", \"NSSA\", \"refmaxwell\" and \"Maxwell\" allowed as options for ML default parameters.");
283  Teuchos::ParameterList ML_defaultlist;
284  if (defaultVals == "refmaxwell")
285  ML_Epetra::SetDefaultsRefMaxwell(ML_defaultlist);
286  else
287  ML_Epetra::SetDefaults(defaultVals,ML_defaultlist);
288 
289  // merge user parameters with default parameters
290  MueLu::MergeParameterList(paramList_in, ML_defaultlist, true);
291  paramList = ML_defaultlist;
292  }
293 #else
294  if (defaultVals != "") {
295  // If no validator available: issue a warning and set parameter value to false in the output list
296  *out << "Warning: MueLu_ENABLE_ML=OFF, ML_ENABLE_Epetra=OFF or ML_ENABLE_TEUCHOS=OFF. No ML default values available." << std::endl;
297  }
298 #endif // HAVE_MUELU_ML && HAVE_ML_EPETRA && HAVE_ML_TEUCHOS
299 
300  //
301  // Move smoothers/aggregation/coarse parameters to sublists
302  //
303 
304  // ML allows to have level-specific smoothers/aggregation/coarse parameters at the top level of the list or/and defined in sublists:
305  // See also: ML Guide section 6.4.1, MueLu::CreateSublists, ML_CreateSublists
306  ParameterList paramListWithSubList;
307  MueLu::CreateSublists(paramList, paramListWithSubList);
308  paramList = paramListWithSubList; // swap
309  Teuchos::ParameterList adaptingParamList = paramList; // copy of paramList which is used to removed already interpreted parameters
310 
311  //
312  // Validate parameter list
313  //
314  {
315  bool validate = paramList.get("ML validate parameter list", true); /* true = default in ML */
316  if (validate && defaultVals!="refmaxwell") {
317 
318 #if defined(HAVE_MUELU_ML) && defined(HAVE_ML_EPETRA) && defined(HAVE_ML_TEUCHOS)
319  // Validate parameter list using ML validator
320  int depth = paramList.get("ML validate depth", 5); /* 5 = default in ML */
321  TEUCHOS_TEST_FOR_EXCEPTION(! ML_Epetra::ValidateMLPParameters(paramList, depth), Exceptions::RuntimeError,
322  "ERROR: ML's Teuchos::ParameterList contains incorrect parameter!");
323 #else
324  // If no validator available: issue a warning and set parameter value to false in the output list
325  *out << "Warning: MueLu_ENABLE_ML=OFF, ML_ENABLE_Epetra=OFF or ML_ENABLE_TEUCHOS=OFF. The parameter list cannot be validated." << std::endl;
326  paramList.set("ML validate parameter list", false);
327 
328 #endif // HAVE_MUELU_ML && HAVE_ML_EPETRA && HAVE_ML_TEUCHOS
329  } // if(validate)
330  } // scope
331 
332 
333  {
334  // Special handling of ML's aux aggregation
335  //
336  // In ML, when "aggregation: aux: enable" == true, the threshold
337  // is set via "aggregation: aux: threshold" instead of
338  // "aggregation: threshold". In MueLu, we use "aggregation: drop
339  // tol" regardless of "sa: use filtering". So depending on
340  // "aggregation: aux: enable" we use either one or the other
341  // threshold to set "aggregation: drop tol".
342  if (paramListWithSubList.isParameter("aggregation: aux: enable") && paramListWithSubList.get<bool>("aggregation: aux: enable")) {
343  if (paramListWithSubList.isParameter("aggregation: aux: threshold")) {
344  paramListWithSubList.set("aggregation: threshold", paramListWithSubList.get<double>("aggregation: aux: threshold"));
345  paramListWithSubList.remove("aggregation: aux: threshold");
346  }
347  }
348  }
349 
350  // stringstream for concatenating xml parameter strings.
351  std::stringstream mueluss;
352 
353  // create surrounding MueLu parameter list
354  mueluss << "<ParameterList name=\"MueLu\">" << std::endl;
355 
356  // loop over all ML parameters in provided parameter list
357  for (ParameterList::ConstIterator param = paramListWithSubList.begin(); param != paramListWithSubList.end(); ++param) {
358 
359  // extract ML parameter name
360  const std::string & pname=paramListWithSubList.name(param);
361 
362  // extract corresponding (ML) value
363  // remove ParameterList specific information from result string
364  std::stringstream valuess;
365  valuess << paramList.entry(param);
366  std::string valuestr = valuess.str();
367  replaceAll(valuestr, "[unused]", "");
368  replaceAll(valuestr, "[default]", "");
369  valuestr = trim(valuestr);
370 
371  // transform ML parameter to corresponding MueLu parameter and generate XML string
372  std::string valueInterpreterStr = "\"" + valuestr + "\"";
373  std::string ret = MasterList::interpretParameterName(MasterList::ML2MueLu(pname),valueInterpreterStr);
374 
375  // special handling for verbosity level
376  if (pname == "ML output") {
377  // Translate verbosity parameter
378  int verbosityLevel = std::stoi(valuestr);
379  std::string eVerbLevel = "none";
380  if (verbosityLevel == 0) eVerbLevel = "none";
381  if (verbosityLevel >= 1) eVerbLevel = "low";
382  if (verbosityLevel >= 5) eVerbLevel = "medium";
383  if (verbosityLevel >= 10) eVerbLevel = "high";
384  if (verbosityLevel >= 11) eVerbLevel = "extreme";
385  if (verbosityLevel >= 42) eVerbLevel = "test";
386  if (verbosityLevel >= 666) eVerbLevel = "interfacetest";
387  mueluss << "<Parameter name=\"verbosity\" type=\"string\" value=\"" << eVerbLevel << "\"/>" << std::endl;
388  continue;
389  }
390 
391  // add XML string
392  if (ret != "") {
393  mueluss << ret << std::endl;
394 
395  // remove parameter from ML parameter list
396  adaptingParamList.remove(pname,false);
397  }
398 
399  // special handling for energy minimization
400  // TAW: this is not optimal for symmetric problems but at least works.
401  // for symmetric problems the "energy minimization" parameter should not exist anyway...
402  if (pname == "energy minimization: enable") {
403  mueluss << "<Parameter name=\"problem: symmetric\" type=\"bool\" value=\"false\"/>" << std::endl;
404  mueluss << "<Parameter name=\"transpose: use implicit\" type=\"bool\" value=\"false\"/>" << std::endl;
405  }
406 
407  // special handling for smoothers
408  if (pname == "smoother: type") {
409 
410  mueluss << GetSmootherFactory(paramList, adaptingParamList, pname, valuestr);
411 
412  }
413 
414  // special handling for level-specific smoothers
415  if (pname.find("smoother: list (level",0) == 0) {
416  // Scan pname (ex: pname="smoother: type (level 2)")
417  std::string type, option;
418  int levelID=-1;
419  {
420  typedef Teuchos::ArrayRCP<char>::size_type size_type;
421  Teuchos::Array<char> ctype (size_type(pname.size()+1));
422  Teuchos::Array<char> coption(size_type(pname.size()+1));
423 
424  int matched = sscanf(pname.c_str(),"%s %[^(](level %d)", ctype.getRawPtr(), coption.getRawPtr(), &levelID); // use [^(] instead of %s to allow for strings with white-spaces (ex: "ifpack list")
425  type = std::string(ctype.getRawPtr());
426  option = std::string(coption.getRawPtr()); option.resize(option.size () - 1); // remove final white-space
427 
428  if (matched != 3 || (type != "smoother:")) {
429  TEUCHOS_TEST_FOR_EXCEPTION(true, MueLu::Exceptions::RuntimeError, "MueLu::CreateSublist(), Line " << __LINE__ << ". "
430  << "Error in creating level-specific sublists" << std::endl
431  << "Offending parameter: " << pname << std::endl);
432  }
433 
434  mueluss << "<ParameterList name=\"level " << levelID << "\">" << std::endl;
435  mueluss << GetSmootherFactory(paramList.sublist(pname),adaptingParamList.sublist(pname), "smoother: type", paramList.sublist(pname).get<std::string>("smoother: type"));
436  mueluss << "</ParameterList>" << std::endl;
437  }
438  }
439 
440  // special handling for coarse level
441  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.");
442  if ( pname == "coarse: list" ) {
443 
444  // interpret smoother/coarse solver data.
445  // Note, that we inspect the "coarse: list" sublist to define the "coarse" smoother/solver
446  // Be aware, that MueLu::CreateSublists renames the prefix of the parameters in the "coarse: list" from "coarse" to "smoother".
447  // Therefore, we have to check the values of the "smoother" parameters
448  TEUCHOS_TEST_FOR_EXCEPTION(!paramList.sublist("coarse: list").isParameter("smoother: type"), Exceptions::RuntimeError, "MueLu::MLParameterListInterpreter::Setup(): no coarse grid solver defined.");
449  mueluss << GetSmootherFactory(paramList.sublist("coarse: list"), adaptingParamList.sublist("coarse: list"), "coarse: type", paramList.sublist("coarse: list").get<std::string>("smoother: type"));
450 
451 
452  }
453  } // for
454 
455  mueluss << "</ParameterList>" << std::endl;
456 
457  return mueluss.str();
458  }
459 
460 
461 } // namespace MueLu
static std::string SetParameterList(const Teuchos::ParameterList &paramList_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)
std::string tolower(const std::string &str)
Namespace for MueLu classes and methods.
static std::string GetSmootherFactory(const Teuchos::ParameterList &paramList, 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.
void replaceAll(std::string &str, const std::string &from, const std::string &to)