MueLu  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
MueLu_ParameterListAcceptor.cpp
Go to the documentation of this file.
1 #include <iostream>
2 
4 
5 // TODO See also: Teuchos::ParameterListAcceptor, Teko::Clonable
6 
7 namespace 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 
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.
32  if (validParamList != Teuchos::null) {
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 
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
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
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 
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
virtual const Teuchos::ParameterList & GetParameterList() const
Ordinal numParams() const
ParameterList & setEntry(const std::string &name, const ParameterEntry &entry)
virtual void SetParameterList(const Teuchos::ParameterList &paramList)
Set parameters from a parameter list and return with default values.
void validateParametersAndSetDefaults(ParameterList const &validParamList, int const depth=1000)
const ParameterEntry & GetParameter(const std::string &name) const
Retrieves a const entry with the name name.
ParameterList & setParameters(const ParameterList &source)
void SetParameter(const std::string &name, const ParameterEntry &entry)
Set a parameter directly as a ParameterEntry.
void printParameterListOptions(std::ostream &os, const Teuchos::ParameterList &p)
ParameterEntry & getEntry(const std::string &name)
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.