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