MueLu
Version of the Day
Toggle main menu visibility
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
12
#include "
MueLu_ParameterListAcceptor.hpp
"
13
14
// TODO See also: Teuchos::ParameterListAcceptor, Teko::Clonable
15
16
namespace
MueLu
{
17
18
void
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
23
ParameterListAcceptor::ParameterListAcceptor
() {}
24
25
ParameterListAcceptorImpl::ParameterListAcceptorImpl
() {}
26
27
void
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.
35
paramList_
=
GetParameterList
();
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
50
const
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
73
const
Teuchos::ParameterList&
ParameterListAcceptorImpl::GetParameterListWithoutValidation
()
const
{
74
return
paramList_
;
75
}
76
77
void
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
83
const
ParameterEntry&
ParameterListAcceptorImpl::GetParameter
(
const
std::string& name)
const
{
84
return
GetParameterList
().getEntry(name);
85
}
86
87
void
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
MueLu_ParameterListAcceptor.hpp
MueLu::ParameterListAcceptor::ParameterListAcceptor
ParameterListAcceptor()
Definition
MueLu_ParameterListAcceptor.cpp:23
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::ParameterListAcceptorImpl::ParameterListAcceptorImpl
ParameterListAcceptorImpl()
Definition
MueLu_ParameterListAcceptor.cpp:25
MueLu::ParameterListAcceptorImpl::GetParameter
const ParameterEntry & GetParameter(const std::string &name) const
Retrieves a const entry with the name name.
Definition
MueLu_ParameterListAcceptor.cpp:83
MueLu::ParameterListAcceptorImpl::GetDocumentation
virtual void GetDocumentation(std::ostream &os) const
Definition
MueLu_ParameterListAcceptor.cpp:87
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:27
MueLu::ParameterListAcceptorImpl::GetParameterList
virtual const Teuchos::ParameterList & GetParameterList() const
Definition
MueLu_ParameterListAcceptor.cpp:50
MueLu::ParameterListAcceptorImpl::SetParameter
void SetParameter(const std::string &name, const ParameterEntry &entry)
Set a parameter directly as a ParameterEntry.
Definition
MueLu_ParameterListAcceptor.cpp:77
MueLu::ParameterListAcceptorImpl::GetParameterListWithoutValidation
virtual const Teuchos::ParameterList & GetParameterListWithoutValidation() const
Definition
MueLu_ParameterListAcceptor.cpp:73
MueLu::ParameterListAcceptorImpl::paramList_
Teuchos::ParameterList paramList_
Definition
MueLu_ParameterListAcceptor.hpp:122
MueLu
Namespace for MueLu classes and methods.
Definition
MueLu_BrickAggregationFactory_decl.hpp:42
MueLu::printParameterListOptions
void printParameterListOptions(std::ostream &os, const Teuchos::ParameterList &p)
Definition
MueLu_ParameterListAcceptor.cpp:18
src
MueCentral
MueLu_ParameterListAcceptor.cpp
Generated by
1.17.0