MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_ParameterListAcceptor.hpp
Go to the documentation of this file.
1 #ifndef MUELU_PARAMETERLISTACCEPTOR_HPP
2 #define MUELU_PARAMETERLISTACCEPTOR_HPP
3 
4 #include <iostream>
5 
6 #include "Teuchos_RCP.hpp"
9 #include "Teuchos_StandardParameterEntryValidators.hpp"
10 
11 // TODO See also: Teuchos::ParameterListAcceptor, Teko::Clonable
12 
13 namespace MueLu {
14 
16 
17 // Printing the valid parameter list only showing documentation fields
18 void printParameterListOptions(std::ostream &os, const Teuchos::ParameterList &p);
19 
25  public:
29 
30  virtual ~ParameterListAcceptor() = default;
31 
35 
40  // Questions:
41  // - Do we want this function to be static?
42  // => yes, but we also want it virtual. So static is not possible. But this method does not access any instance specific data.
43  // - Do we want to pass an optional param list as input parameter?
44  // yes => if some parameters depends of other parameters, this would allow to return different default / valid parameters according to already set parameters.
45  // Ex: fact: ILUT => extra param threshold; fact: ILUK => extra param level-of-fill
46  //
47  // If a parameter is unused AND default, it is printed as [default] by std::cout << paramList but printed as unused by paramList.unused(std::cout).
48  // So if we set default parameters in getValidParameters() that are not used, user will get a warning message. We don't want that for [default].
49  // One solution is to never set any unused parameter in getValidParameters().
50  // If some parameters are available only conditionnaly, do not set them by default in setValidParameters when the conditions are not met.
51  //
53 
55  //
56  // Questions:
57  // - Input: const ParameterList or not const? IE: do we want to modify user paramlist directly?
58  // => not const: user can make a copy outside if he do not want us to modify his initial paramlist.
59  // - Input: RCP or just reference? RCP avoid the copy of the parameter list but
60  // I'm afraid that a user modify the list outside of the class after doing a SetParameterList
61  // (this by-pass the validation and can create some confusion).
62  // In another hand, if we use a copy of the list, we do not set the "[used]"/["unused"] flag
63  // on the original list during Build(). GetParameterList has to be called to retrieve the list with the correct flags.
64  //
65  // What we really want is for the user to have a const version outside and MueLu having a non-const version inside.
66  // Is there a C++ pattern to do that?
67  virtual void SetParameterList(const Teuchos::ParameterList &paramList) = 0;
68 
69  // Get the parameter list.
70  // Teuchos::ParameterListAcceptor also provides a non-const version of this but I don't see why.
71  // We don't want a user to mess with the internal parameter list.
72  // To change a parameter, one can make a copy and call SetParameterList again.
73  // No need for RCP, it's just a view
74  virtual const Teuchos::ParameterList &GetParameterList() const = 0;
75 
77  virtual void SetParameter(const std::string &name, const ParameterEntry &entry) = 0;
78 
80  virtual const ParameterEntry &GetParameter(const std::string &name) const = 0;
81 
82  virtual void GetDocumentation(std::ostream &os) const = 0;
83 
85 
86 }; // class ParameterListAcceptor
87 
88 // Partial implementation of ParameterListAcceptor that stores the object parameters in an internal parameterList
90  public:
92 
93  virtual ~ParameterListAcceptorImpl() = default;
94 
95  virtual void SetParameterList(const Teuchos::ParameterList &paramList);
96 
97  // The returned list always has an entry for each valid parameter.
98  // Therefore, there is not need to test if a parameter is present before getting it.
99  virtual const Teuchos::ParameterList &GetParameterList() const;
100 
101  void SetParameter(const std::string &name, const ParameterEntry &entry);
102 
103  const ParameterEntry &GetParameter(const std::string &name) const;
104 
105  virtual void GetDocumentation(std::ostream &os) const;
106 
107  private:
108  mutable // mutable can be avoid by changing return type of GetParameterList() to RCP but conceptually, I like the fact that GetParameterList returns ref to param list.
109  Teuchos::ParameterList paramList_; // Private: Use GetParameterList() to access this list
110  // This list might be empty before calling GetParameterList()
111  // but it is populate with automatically if needed in SetParameterList/GetParameterList/...
112  // Therefore, there is no need to test if a parameter exist before accessing it with pL.get("paramName")
113  // in sub classes.
114 
115  // Note: Teuchos::ParameterListAcceptor has a getMyParamList() function to access paramList_ without going through the logic of getParameterList()
116  // Do we need that too?
117 };
118 
119 } // namespace MueLu
120 
121 #endif // MUELU_PARAMETERLISTACCEPTOR_HPP
virtual const Teuchos::ParameterList & GetParameterList() const
virtual ~ParameterListAcceptor()=default
virtual const ParameterEntry & GetParameter(const std::string &name) const =0
Retrieves a const entry with the name name.
virtual void SetParameterList(const Teuchos::ParameterList &paramList)
Set parameters from a parameter list and return with default values.
virtual const Teuchos::ParameterList & GetParameterList() const =0
Abstract interface of a class accepting parameter lists.
const ParameterEntry & GetParameter(const std::string &name) const
Retrieves a const entry with the name name.
void SetParameter(const std::string &name, const ParameterEntry &entry)
Set a parameter directly as a ParameterEntry.
virtual void SetParameter(const std::string &name, const ParameterEntry &entry)=0
Set a parameter directly as a ParameterEntry.
virtual void SetParameterList(const Teuchos::ParameterList &paramList)=0
Set parameters from a parameter list and return with default values.
void printParameterListOptions(std::ostream &os, const Teuchos::ParameterList &p)
virtual ~ParameterListAcceptorImpl()=default
virtual void GetDocumentation(std::ostream &os) const =0
virtual void GetDocumentation(std::ostream &os) const
virtual Teuchos::RCP< const Teuchos::ParameterList > GetValidParameterList() const =0
Return a const parameter list of valid parameters that setParameterList() will accept.