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> class DefaultProblemStrings;
71 
72  class MasterList {
73  public:
77  static Teuchos::RCP<Teuchos::ParameterList> GetProblemSpecificList(std::string const & problemType);
78 
80  template<typename T>
81  static const T& getDefault(const std::string& name) {
82  return List()->get<T>(name);
83  }
84 
86  static const Teuchos::ParameterEntry& getEntry(const std::string& name) {
87  return List()->getEntry(name);
88  }
89 
93  template<typename T>
94  static std::string generateXMLParameterString(const std::string& name, T data) {
95  Teuchos::ParameterEntry entry = getEntry(name);
96  std::stringstream ss;
97  // TODO: check whether getAny().typeName() matches the typeid(T)
98  // One could use a technique as described here: http://stackoverflow.com/questions/4484982/how-to-convert-typename-t-to-string-in-c
99  ss << "<Parameter name=\"" << name << "\" type=\"" << entry.getAny().typeName() << "\" value=\"" << data << "\"/>";
100  return ss.str();
101  }
102 
104  static std::string ML2MueLu(const std::string& name) {
105  std::map<std::string,std::string>::iterator it;
106  it = ML2MueLuLists_.find(name);
107  if(it!=ML2MueLuLists_.end()) return it->second;
108  else return "";
109  }
110 
111  static std::string interpretParameterName(const std::string& name, const std::string& value);
112 
113  private:
114  MasterList();
115  MasterList(const MasterList&);
117 
121  static const std::string stringList_;
125  static std::string problemType_;
127  static std::map<std::string,std::string> DefaultProblemTypeLists_;
129  static std::map<std::string,std::string> ML2MueLuLists_;
130  };
131 
136  template <typename T, typename U>
137  class DefaultProblemStrings {
138  public:
139  DefaultProblemStrings(const T& key, const U& val) {
140  map_[key] = val;
141  }
142 
143  DefaultProblemStrings<T, U>& operator()(const T& key, const U& val) {
144  map_[key] = val;
145  return *this;
146  }
147 
148  operator std::map<T, U>() const {
149  return map_;
150  }
151  private:
152  std::map<T, U> map_;
153  };
154 
155 } // namespace MueLu
156 
157 #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.