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 // ***********************************************************************
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 #ifndef MUELU_MASTERLIST_HPP
47 #define MUELU_MASTERLIST_HPP
48 
49 #include <sstream>
50 #include <map>
51 
54 #include <Teuchos_any.hpp>
55 
56 namespace MueLu {
57 
70 template <typename T, typename U>
72 
73 class MasterList {
74  public:
78  static Teuchos::RCP<Teuchos::ParameterList> GetProblemSpecificList(std::string const& problemType);
79 
81  template <typename T>
82  static const T& getDefault(const std::string& name) {
83  return List()->get<T>(name);
84  }
85 
87  static const Teuchos::ParameterEntry& getEntry(const std::string& name) {
88  return List()->getEntry(name);
89  }
90 
94  template <typename T>
95  static std::string generateXMLParameterString(const std::string& name, T data) {
96  Teuchos::ParameterEntry entry = getEntry(name);
97  std::stringstream ss;
98  // TODO: check whether getAny().typeName() matches the typeid(T)
99  // One could use a technique as described here: http://stackoverflow.com/questions/4484982/how-to-convert-typename-t-to-string-in-c
100  ss << "<Parameter name=\"" << name << "\" type=\"" << entry.getAny().typeName() << "\" value=\"" << data << "\"/>";
101  return ss.str();
102  }
103 
105  static std::string ML2MueLu(const std::string& name) {
106  std::map<std::string, std::string>::iterator it;
107  it = ML2MueLuLists_.find(name);
108  if (it != ML2MueLuLists_.end())
109  return it->second;
110  else
111  return "";
112  }
113 
114  static std::string interpretParameterName(const std::string& name, const std::string& value);
115 
116  private:
117  MasterList();
118  MasterList(const MasterList&);
120 
124  static const std::string stringList_;
128  static std::string problemType_;
130  static std::map<std::string, std::string> DefaultProblemTypeLists_;
132  static std::map<std::string, std::string> ML2MueLuLists_;
133 };
134 
139 template <typename T, typename U>
140 class DefaultProblemStrings {
141  public:
142  DefaultProblemStrings(const T& key, const U& val) {
143  map_[key] = val;
144  }
145 
146  DefaultProblemStrings<T, U>& operator()(const T& key, const U& val) {
147  map_[key] = val;
148  return *this;
149  }
150 
151  operator std::map<T, U>() const {
152  return map_;
153  }
154 
155  private:
156  std::map<T, U> map_;
157 };
158 
159 } // namespace MueLu
160 
161 #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.