MueLu Version of the Day
Loading...
Searching...
No Matches
MueLu_ParameterListAcceptor.cpp
Go to the documentation of this file.
1#include <iostream>
2
4
5// TODO See also: Teuchos::ParameterListAcceptor, Teko::Clonable
6
7namespace MueLu {
8
9 void printParameterListOptions(std::ostream &os, const Teuchos::ParameterList & p) {
10 p.print(os, Teuchos::ParameterList::PrintOptions().showDoc(true).indent(2).showTypes(true));
11 os << std::endl;
12 }
13
15
17
18 void ParameterListAcceptorImpl::SetParameterList(const Teuchos::ParameterList& paramList) {
19 // This call is only for cosmetic reasons.
20 // If one calls SetParameterList before GetParameterList, that would mean
21 // that paramList_ has not been initialized yet. Therefore, the parameter
22 // would be put in it in the order user provided, and not in the order of
23 // valid parameter list. We'd like to have consistency in the order, so
24 // we do this extra call, which is no-op if paramList_ has already been
25 // initialized.
27
28 paramList_.setParameters(paramList);
29
30 // Validate and add defaults parameters.
31 Teuchos::RCP<const Teuchos::ParameterList> validParamList = GetValidParameterList();
32 if (validParamList != Teuchos::null) {
33 paramList_.validateParametersAndSetDefaults(*validParamList);
34 } else {
35 // Teuchos::null means that GetValidParameterList() not implemented.
36 // As such, we skip validation and have not way to set default values,
37 // which is potentially dangerous
38 }
39 }
40
41 const Teuchos::ParameterList& ParameterListAcceptorImpl::GetParameterList() const {
42 // The returned list always has an entry for each valid parameter.
43 // Therefore, there is not need to test if a parameter is present before getting it.
44 if (paramList_.numParams() == 0) {
45 // Set paramList_ to the default list
46 Teuchos::RCP<const Teuchos::ParameterList> validParamList = GetValidParameterList();
47 if (validParamList != Teuchos::null) {
48 // Instead of simply doing
49 // paramList_ = *validParamList;
50 // we use more complicated Teuchos calls, because we would like to
51 // have [default] values in the beginning
52 paramList_.validateParametersAndSetDefaults(*validParamList);
53 }
54
55 } else {
56 // We are sure that the list has all the valid parameters defined
57 // because the parameter list validation process adds the default
58 // values to the user list
59 }
60
61 return paramList_;
62 }
63
64 void ParameterListAcceptorImpl::SetParameter(const std::string& name, const ParameterEntry& entry) {
65 Teuchos::ParameterList paramList;
66 paramList.setEntry(name, entry);
67 SetParameterList(paramList); // This forces revalidation of the list
68 }
69
70 const ParameterEntry & ParameterListAcceptorImpl::GetParameter(const std::string &name) const {
71 return GetParameterList().getEntry(name);
72 }
73
74 void ParameterListAcceptorImpl::GetDocumentation(std::ostream &os) const {
75 // default implementation
76
77 Teuchos::RCP<const Teuchos::ParameterList> validParamList = GetValidParameterList();
78 if (validParamList == Teuchos::null) {
79 os << "## Documentation not available:" << std::endl;
80 return;
81 }
82
83 os << "## Parameters:" << std::endl;
84 printParameterListOptions(os, *validParamList);
85
86 os << "## Fully described default method:" << std::endl;
87 validParamList->print(os, 2, true, false);
88 os << std::endl;
89 }
90
91} //namespace MueLu
const ParameterEntry & GetParameter(const std::string &name) const
Retrieves a const entry with the name name.
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.
virtual Teuchos::RCP< const Teuchos::ParameterList > GetValidParameterList() const =0
Return a const parameter list of valid parameters that setParameterList() will accept.
Namespace for MueLu classes and methods.
void printParameterListOptions(std::ostream &os, const Teuchos::ParameterList &p)