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 // @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_PARAMETERLISTACCEPTOR_HPP
11 #define MUELU_PARAMETERLISTACCEPTOR_HPP
12 
13 #include <iostream>
14 
15 #include "Teuchos_RCP.hpp"
18 #include "Teuchos_StandardParameterEntryValidators.hpp"
19 
20 // TODO See also: Teuchos::ParameterListAcceptor, Teko::Clonable
21 
22 namespace MueLu {
23 
25 
26 // Printing the valid parameter list only showing documentation fields
27 void printParameterListOptions(std::ostream &os, const Teuchos::ParameterList &p);
28 
34  public:
38 
39  virtual ~ParameterListAcceptor() = default;
40 
44 
49  // Questions:
50  // - Do we want this function to be static?
51  // => yes, but we also want it virtual. So static is not possible. But this method does not access any instance specific data.
52  // - Do we want to pass an optional param list as input parameter?
53  // yes => if some parameters depends of other parameters, this would allow to return different default / valid parameters according to already set parameters.
54  // Ex: fact: ILUT => extra param threshold; fact: ILUK => extra param level-of-fill
55  //
56  // 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).
57  // 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].
58  // One solution is to never set any unused parameter in getValidParameters().
59  // If some parameters are available only conditionnaly, do not set them by default in setValidParameters when the conditions are not met.
60  //
62 
64  //
65  // Questions:
66  // - Input: const ParameterList or not const? IE: do we want to modify user paramlist directly?
67  // => not const: user can make a copy outside if he do not want us to modify his initial paramlist.
68  // - Input: RCP or just reference? RCP avoid the copy of the parameter list but
69  // I'm afraid that a user modify the list outside of the class after doing a SetParameterList
70  // (this by-pass the validation and can create some confusion).
71  // In another hand, if we use a copy of the list, we do not set the "[used]"/["unused"] flag
72  // on the original list during Build(). GetParameterList has to be called to retrieve the list with the correct flags.
73  //
74  // What we really want is for the user to have a const version outside and MueLu having a non-const version inside.
75  // Is there a C++ pattern to do that?
76  virtual void SetParameterList(const Teuchos::ParameterList &paramList) = 0;
77 
78  // Get the parameter list.
79  // Teuchos::ParameterListAcceptor also provides a non-const version of this but I don't see why.
80  // We don't want a user to mess with the internal parameter list.
81  // To change a parameter, one can make a copy and call SetParameterList again.
82  // No need for RCP, it's just a view
83  virtual const Teuchos::ParameterList &GetParameterList() const = 0;
84 
86 
88  virtual void SetParameter(const std::string &name, const ParameterEntry &entry) = 0;
89 
91  virtual const ParameterEntry &GetParameter(const std::string &name) const = 0;
92 
93  virtual void GetDocumentation(std::ostream &os) const = 0;
94 
96 
97 }; // class ParameterListAcceptor
98 
99 // Partial implementation of ParameterListAcceptor that stores the object parameters in an internal parameterList
101  public:
103 
104  virtual ~ParameterListAcceptorImpl() = default;
105 
106  virtual void SetParameterList(const Teuchos::ParameterList &paramList);
107 
108  // The returned list always has an entry for each valid parameter.
109  // Therefore, there is not need to test if a parameter is present before getting it.
110  virtual const Teuchos::ParameterList &GetParameterList() const;
111 
113 
114  void SetParameter(const std::string &name, const ParameterEntry &entry);
115 
116  const ParameterEntry &GetParameter(const std::string &name) const;
117 
118  virtual void GetDocumentation(std::ostream &os) const;
119 
120  private:
121  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.
122  Teuchos::ParameterList paramList_; // Private: Use GetParameterList() to access this list
123  // This list might be empty before calling GetParameterList()
124  // but it is populate with automatically if needed in SetParameterList/GetParameterList/...
125  // Therefore, there is no need to test if a parameter exist before accessing it with pL.get("paramName")
126  // in sub classes.
127 
128  // Note: Teuchos::ParameterListAcceptor has a getMyParamList() function to access paramList_ without going through the logic of getParameterList()
129  // Do we need that too?
130 };
131 
132 } // namespace MueLu
133 
134 #endif // MUELU_PARAMETERLISTACCEPTOR_HPP
virtual const Teuchos::ParameterList & GetParameterList() const
virtual const Teuchos::ParameterList & GetParameterListWithoutValidation() const =0
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 const Teuchos::ParameterList & GetParameterListWithoutValidation() const
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.