MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_MasterList.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_MASTERLIST_HPP
11 #define MUELU_MASTERLIST_HPP
12 
13 #include <sstream>
14 #include <map>
15 
18 #include <Teuchos_any.hpp>
19 
20 namespace MueLu {
21 
34 template <typename T, typename U>
36 
37 class MasterList {
38  public:
42  static Teuchos::RCP<Teuchos::ParameterList> GetProblemSpecificList(std::string const& problemType);
43 
45  template <typename T>
46  static const T& getDefault(const std::string& name) {
47  return List()->get<T>(name);
48  }
49 
51  static const Teuchos::ParameterEntry& getEntry(const std::string& name) {
52  return List()->getEntry(name);
53  }
54 
58  template <typename T>
59  static std::string generateXMLParameterString(const std::string& name, T data) {
60  Teuchos::ParameterEntry entry = getEntry(name);
61  std::stringstream ss;
62  // TODO: check whether getAny().typeName() matches the typeid(T)
63  // One could use a technique as described here: http://stackoverflow.com/questions/4484982/how-to-convert-typename-t-to-string-in-c
64  ss << "<Parameter name=\"" << name << "\" type=\"" << entry.getAny().typeName() << "\" value=\"" << data << "\"/>";
65  return ss.str();
66  }
67 
69  static std::string ML2MueLu(const std::string& name) {
70  std::map<std::string, std::string>::iterator it;
71  it = ML2MueLuLists_.find(name);
72  if (it != ML2MueLuLists_.end())
73  return it->second;
74  else
75  return "";
76  }
77 
78  static std::string interpretParameterName(const std::string& name, const std::string& value);
79 
80  private:
81  MasterList();
82  MasterList(const MasterList&);
84 
88  static const std::string stringList_;
92  static std::string problemType_;
94  static std::map<std::string, std::string> DefaultProblemTypeLists_;
96  static std::map<std::string, std::string> ML2MueLuLists_;
97 };
98 
103 template <typename T, typename U>
104 class DefaultProblemStrings {
105  public:
106  DefaultProblemStrings(const T& key, const U& val) {
107  map_[key] = val;
108  }
109 
110  DefaultProblemStrings<T, U>& operator()(const T& key, const U& val) {
111  map_[key] = val;
112  return *this;
113  }
114 
115  operator std::map<T, U>() const {
116  return map_;
117  }
118 
119  private:
120  std::map<T, U> map_;
121 };
122 
123 } // namespace MueLu
124 
125 #endif
static std::map< std::string, std::string > ML2MueLuLists_
Map of ML parameter strings to corresponding MueLu parametes.
static const std::string stringList_
String equivalent of the masterList_.
static Teuchos::RCP< Teuchos::ParameterList > problemSpecificList_
A ParameterList that holds all valid parameters and their default values for a particular problem typ...
static std::string interpretParameterName(const std::string &name, const std::string &value)
DefaultProblemStrings< T, U > & operator()(const T &key, const U &val)
static Teuchos::RCP< Teuchos::ParameterList > masterList_
A ParameterList that holds all valid parameters and their default values.
Static class that holds the complete list of valid MueLu parameters.
MasterList & operator=(const MasterList &)
DefaultProblemStrings(const T &key, const U &val)
any & getAny(bool activeQry=true)
static std::string ML2MueLu(const std::string &name)
Translate ML parameter to corresponding MueLu parameter.
static const Teuchos::ParameterEntry & getEntry(const std::string &name)
Returns default entry from the &quot;master&quot; list corresponding to the specified name. ...
static std::string generateXMLParameterString(const std::string &name, T data)
Create xml string for given MueLu parameter (easy xml input format)
static Teuchos::RCP< Teuchos::ParameterList > GetProblemSpecificList(std::string const &problemType)
Return default parameter settings for the specified problem type.
std::string typeName() const
static const T & getDefault(const std::string &name)
Returns default value on the &quot;master&quot; list for a parameter with the specified name and type...
static Teuchos::RCP< const Teuchos::ParameterList > List()
Return a &quot;master&quot; list of all valid parameters and their default values.
Helper class to initialize DefaultProblemTypeLists_ in class MasterList.
static std::map< std::string, std::string > DefaultProblemTypeLists_
Map of string equivalents of the problemSpecificList_. The first entry is the problem type...
static std::string problemType_
The problem type associated with the current problem-specific ParameterList.