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