MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_ParameterListUtils.hpp
Go to the documentation of this file.
1 // @HEADER
2 // *****************************************************************************
3 // MueLu: A package for multigrid based preconditioning
4 //
5 // Copyright 2012 NTESS and the MueLu contributors.
6 // SPDX-License-Identifier: BSD-3-Clause
7 // *****************************************************************************
8 // @HEADER
9 
10 #ifndef MUELU_PARAMETERLISTUTILS_HPP
11 #define MUELU_PARAMETERLISTUTILS_HPP
12 
13 #include <string>
14 #include <sstream>
15 
17 #include <Teuchos_RCPDecl.hpp>
18 #include "MueLu_ConfigDefs.hpp"
19 
20 namespace MueLu {
21 
22 /* See also: ML_Epetra::UpdateList */
23 void MergeParameterList(const Teuchos::ParameterList& source, Teuchos::ParameterList& dest, bool overWrite);
24 
26 
27 // Usage: GetMLSubList(paramList, "smoother", 2);
28 const Teuchos::ParameterList& GetMLSubList(const Teuchos::ParameterList& paramList, const std::string& type, int levelID);
29 
30 // Extract all the parameters that begin with "str:" (but skip sublist)
32 
38 void replaceAll(std::string& str, const std::string& from, const std::string& to);
39 
41 template <typename Type>
42 bool replacePlaceholder(std::string& str, const std::string& placeholder, Type data) {
43  std::stringstream s;
44  s << data;
45  replaceAll(str, placeholder, s.str());
46  return true;
47 }
48 
49 template <typename Type>
50 bool actionInterpretParameter(Teuchos::ParameterList& mlParams, const std::string& paramName, std::string& str) {
51  // MUELU_READ_PARAM(mlParams, paramName, int, 0, data);
52 
53  Type varName; // = defaultValue; // extract from master list
54  if (mlParams.isParameter(paramName)) varName = mlParams.get<Type>(paramName);
55 
56  std::stringstream placeholder;
57  placeholder << "$" << paramName << "$";
58 
59  return MueLu::replacePlaceholder<Type>(str, placeholder.str(), varName);
60 }
61 
62 } // namespace MueLu
63 
64 #endif // MUELU_PARAMETERLISTUTILS_HPP
void MergeParameterList(const Teuchos::ParameterList &source, Teuchos::ParameterList &dest, bool overWrite)
: merge two parameter lists
bool replacePlaceholder(std::string &str, const std::string &placeholder, Type data)
templated version to replace placeholder by data in &quot;str&quot;
T & get(const std::string &name, T def_value)
const Teuchos::ParameterList & GetMLSubList(const Teuchos::ParameterList &paramList, const std::string &type, int levelID)
bool isParameter(const std::string &name) const
void CreateSublists(const ParameterList &List, ParameterList &newList)
Teuchos::RCP< Teuchos::ParameterList > ExtractSetOfParameters(const Teuchos::ParameterList &paramList, const std::string &str)
bool actionInterpretParameter(Teuchos::ParameterList &mlParams, const std::string &paramName, std::string &str)
void replaceAll(std::string &str, const std::string &from, const std::string &to)