MueLu
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
MueLu_ParameterListAcceptor.cpp
Go to the documentation of this file.
1
#include <iostream>
2
3
#include "
MueLu_ParameterListAcceptor.hpp
"
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
14
ParameterListAcceptor::ParameterListAcceptor
() { }
15
16
ParameterListAcceptorImpl::ParameterListAcceptorImpl
() { }
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.
26
paramList_
=
GetParameterList
();
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
MueLu_ParameterListAcceptor.hpp
MueLu::ParameterListAcceptorImpl::ParameterListAcceptorImpl
ParameterListAcceptorImpl()
Definition
MueLu_ParameterListAcceptor.cpp:16
MueLu::ParameterListAcceptorImpl::GetParameter
const ParameterEntry & GetParameter(const std::string &name) const
Retrieves a const entry with the name name.
Definition
MueLu_ParameterListAcceptor.cpp:70
MueLu::ParameterListAcceptorImpl::GetDocumentation
virtual void GetDocumentation(std::ostream &os) const
Definition
MueLu_ParameterListAcceptor.cpp:74
MueLu::ParameterListAcceptorImpl::SetParameterList
virtual void SetParameterList(const Teuchos::ParameterList ¶mList)
Set parameters from a parameter list and return with default values.
Definition
MueLu_ParameterListAcceptor.cpp:18
MueLu::ParameterListAcceptorImpl::GetParameterList
virtual const Teuchos::ParameterList & GetParameterList() const
Definition
MueLu_ParameterListAcceptor.cpp:41
MueLu::ParameterListAcceptorImpl::SetParameter
void SetParameter(const std::string &name, const ParameterEntry &entry)
Set a parameter directly as a ParameterEntry.
Definition
MueLu_ParameterListAcceptor.cpp:64
MueLu::ParameterListAcceptorImpl::paramList_
Teuchos::ParameterList paramList_
Definition
MueLu_ParameterListAcceptor.hpp:114
MueLu::ParameterListAcceptor::ParameterListAcceptor
ParameterListAcceptor()
Definition
MueLu_ParameterListAcceptor.cpp:14
MueLu::ParameterListAcceptor::GetValidParameterList
virtual Teuchos::RCP< const Teuchos::ParameterList > GetValidParameterList() const =0
Return a const parameter list of valid parameters that setParameterList() will accept.
MueLu
Namespace for MueLu classes and methods.
Definition
MueLu_BrickAggregationFactory_decl.hpp:78
MueLu::printParameterListOptions
void printParameterListOptions(std::ostream &os, const Teuchos::ParameterList &p)
Definition
MueLu_ParameterListAcceptor.cpp:9
src
MueCentral
MueLu_ParameterListAcceptor.cpp
Generated by
1.17.0