MueLu Version of the Day
Loading...
Searching...
No Matches
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
16#include <Teuchos_ParameterList.hpp>
17#include <Teuchos_RCPDecl.hpp>
18#include "MueLu_ConfigDefs.hpp"
19
20namespace MueLu {
21
22/* See also: ML_Epetra::UpdateList */
23void MergeParameterList(const Teuchos::ParameterList& source, Teuchos::ParameterList& dest, bool overWrite);
24
25void CreateSublists(const Teuchos::ParameterList& List, Teuchos::ParameterList& newList);
26
27// Usage: GetMLSubList(paramList, "smoother", 2);
28const 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)
31Teuchos::RCP<Teuchos::ParameterList> ExtractSetOfParameters(const Teuchos::ParameterList& paramList, const std::string& str);
32
38void replaceAll(std::string& str, const std::string& from, const std::string& to);
39
41template <typename Type>
42bool 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
49template <typename Type>
50bool 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
Namespace for MueLu classes and methods.
void CreateSublists(const Teuchos::ParameterList &List, Teuchos::ParameterList &newList)
Teuchos::RCP< Teuchos::ParameterList > ExtractSetOfParameters(const Teuchos::ParameterList &paramList, const std::string &str)
void replaceAll(std::string &str, const std::string &from, const std::string &to)
bool actionInterpretParameter(Teuchos::ParameterList &mlParams, const std::string &paramName, std::string &str)
bool replacePlaceholder(std::string &str, const std::string &placeholder, Type data)
templated version to replace placeholder by data in "str"
void MergeParameterList(const Teuchos::ParameterList &source, Teuchos::ParameterList &dest, bool overWrite)
: merge two parameter lists
const Teuchos::ParameterList & GetMLSubList(const Teuchos::ParameterList &paramList, const std::string &type, int levelID)