Sacado Package Browser (Single Doxygen Collection)
Version of the Day
Toggle main menu visibility
Loading...
Searching...
No Matches
src
parameter
Sacado_ParameterLibraryBaseImp.hpp
Go to the documentation of this file.
1
// @HEADER
2
// ***********************************************************************
3
//
4
// Sacado Package
5
// Copyright (2006) Sandia Corporation
6
//
7
// Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation,
8
// the U.S. Government retains certain rights in this software.
9
//
10
// This library is free software; you can redistribute it and/or modify
11
// it under the terms of the GNU Lesser General Public License as
12
// published by the Free Software Foundation; either version 2.1 of the
13
// License, or (at your option) any later version.
14
//
15
// This library is distributed in the hope that it will be useful, but
16
// WITHOUT ANY WARRANTY; without even the implied warranty of
17
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18
// Lesser General Public License for more details.
19
//
20
// You should have received a copy of the GNU Lesser General Public
21
// License along with this library; if not, write to the Free Software
22
// Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301
23
// USA
24
// Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps
25
// (etphipp@sandia.gov).
26
//
27
// ***********************************************************************
28
// @HEADER
29
30
#include "Teuchos_Assert.hpp"
31
32
template
<
typename
FamilyType,
typename
EntryType>
33
Sacado::ParameterLibraryBase<FamilyType,EntryType>::
34
ParameterLibraryBase
()
35
{
36
}
37
38
template
<
typename
FamilyType,
typename
EntryType>
39
Sacado::ParameterLibraryBase<FamilyType,EntryType>::
40
~ParameterLibraryBase
()
41
{
42
}
43
44
template
<
typename
FamilyType,
typename
EntryType>
45
bool
46
Sacado::ParameterLibraryBase<FamilyType,EntryType>::
47
isParameter
(
const
std::string& name)
const
48
{
49
// Get family
50
typename
FamilyMap::const_iterator it =
library
.find(name);
51
52
return
(it !=
library
.end());
53
}
54
55
template
<
typename
FamilyType,
typename
EntryType>
56
template
<
class
EvalType>
57
bool
58
Sacado::ParameterLibraryBase<FamilyType,EntryType>::
59
isParameterForType
(
const
std::string& name)
const
60
{
61
// Get family
62
typename
FamilyMap::const_iterator it =
library
.find(name);
63
64
// First check parameter is in the library
65
if
(it ==
library
.end())
66
return
false
;
67
68
// Determine if type is in the family
69
return
(*it).second->template hasType<EvalType>();
70
}
71
72
template
<
typename
FamilyType,
typename
EntryType>
73
bool
74
Sacado::ParameterLibraryBase<FamilyType,EntryType>::
75
addParameterFamily
(
const
std::string& name,
76
bool
supports_ad,
77
bool
supports_analytic)
78
{
79
// Check that the parameter is not in the library
80
if
(
isParameter
(name))
81
return
false
;
82
83
Teuchos::RCP<FamilyType> f =
84
Teuchos::rcp(
new
FamilyType(name, supports_ad, supports_analytic));
85
library
.insert(std::pair< std::string,
86
Teuchos::RCP<FamilyType> >(name, f));
87
88
return
true
;
89
}
90
91
template
<
typename
FamilyType,
typename
EntryType>
92
template
<
class
EvalType>
93
bool
94
Sacado::ParameterLibraryBase<FamilyType,EntryType>::
95
addEntry
(
const
std::string& name,
96
const
Teuchos::RCP<
typename
Sacado::mpl::apply<EntryType,EvalType>::type
>& entry,
97
const
bool
allow_overwrite)
98
{
99
// Get family
100
typename
FamilyMap::iterator it =
library
.find(name);
101
102
// First check parameter is in the library
103
TEUCHOS_TEST_FOR_EXCEPTION(it ==
library
.end(),
104
std::logic_error,
105
std::string(
"Sacado::ParameterLibraryBase::addEntry(): "
)
106
+
"Parameter family "
+ name
107
+
" is not in the library"
);
108
109
// Call family's addEntry method
110
return
(*it).second->template
addEntry<EvalType>
(entry, allow_overwrite);
111
}
112
113
template
<
typename
FamilyType,
typename
EntryType>
114
template
<
class
EvalType>
115
Teuchos::RCP< typename Sacado::mpl::apply<EntryType,EvalType>::type >
116
Sacado::ParameterLibraryBase<FamilyType,EntryType>::
117
getEntry
(
const
std::string& name)
118
{
119
// Get family
120
typename
FamilyMap::iterator it =
library
.find(name);
121
122
// First check parameter is in the library
123
TEUCHOS_TEST_FOR_EXCEPTION(it ==
library
.end(),
124
std::logic_error,
125
std::string(
"Sacado::ParameterLibraryBase::getEntry(): "
)
126
+
"Parameter family "
+ name
127
+
" is not in the library"
);
128
129
// Call family's getEntry method
130
return
(*it).second->template
getEntry<EvalType>
();
131
}
132
133
template
<
typename
FamilyType,
typename
EntryType>
134
template
<
class
EvalType>
135
Teuchos::RCP< const typename Sacado::mpl::apply<EntryType,EvalType>::type >
136
Sacado::ParameterLibraryBase<FamilyType,EntryType>::
137
getEntry
(
const
std::string& name)
const
138
{
139
// Get family
140
typename
FamilyMap::const_iterator it =
library
.find(name);
141
142
// First check parameter is in the library
143
TEUCHOS_TEST_FOR_EXCEPTION(it ==
library
.end(),
144
std::logic_error,
145
std::string(
"Sacado::ParameterLibraryBase::getEntry(): "
)
146
+
"Parameter family "
+ name
147
+
" is not in the library"
);
148
149
// Call family's getEntry method
150
return
(*it).second->template
getEntry<EvalType>
();
151
}
152
153
template
<
typename
FamilyType,
typename
EntryType>
154
template
<
typename
BaseValueType>
155
void
156
Sacado::ParameterLibraryBase<FamilyType,EntryType>::
157
fillVector
(
const
Teuchos::Array<std::string>& names,
158
const
Teuchos::Array<BaseValueType>& values,
159
ParameterVectorBase<FamilyType,BaseValueType>
& pv)
160
{
161
typename
FamilyMap::iterator it;
162
163
// Fill in parameters
164
for
(
unsigned
int
i=0; i<names.size(); i++) {
165
it =
library
.find(names[i]);
166
TEUCHOS_TEST_FOR_EXCEPTION(
167
it ==
library
.end(),
168
std::logic_error,
169
std::string(
"Sacado::ParameterLibraryBase::fillVector(): "
)
170
+
"Invalid parameter family "
+ names[i]);
171
pv.
addParam
((*it).second, values[i]);
172
}
173
}
174
175
template
<
typename
FamilyType,
typename
EntryType>
176
void
177
Sacado::ParameterLibraryBase<FamilyType,EntryType>::
178
print
(std::ostream& os,
bool
print_values)
const
179
{
180
os <<
"Library of all registered parameters:"
<< std::endl;
181
typename
FamilyMap::const_iterator it = this->
library
.begin();
182
for
(; it != this->
library
.end(); ++it) {
183
(*it).second->print(os, print_values);
184
}
185
}
Sacado::ParameterLibraryBase::~ParameterLibraryBase
virtual ~ParameterLibraryBase()
Destructor.
Definition
Sacado_ParameterLibraryBaseImp.hpp:40
Sacado::ParameterLibraryBase::addEntry
bool addEntry(const std::string &name, const Teuchos::RCP< typename Sacado::mpl::apply< EntryType, EvalType >::type > &entry, const bool allow_overwrite=false)
Add a new parameter using custom entry.
Definition
Sacado_ParameterLibraryBaseImp.hpp:95
Sacado::ParameterLibraryBase::library
FamilyMap library
Scalar parameter library.
Definition
Sacado_ParameterLibraryBase.hpp:151
Sacado::ParameterLibraryBase::isParameter
bool isParameter(const std::string &name) const
Determine if parameter of name name is in the library.
Definition
Sacado_ParameterLibraryBaseImp.hpp:47
Sacado::ParameterLibraryBase::addParameterFamily
bool addParameterFamily(const std::string &name, bool supports_ad, bool supports_analytic)
Create a new parameter family.
Definition
Sacado_ParameterLibraryBaseImp.hpp:75
Sacado::ParameterLibraryBase::ParameterLibraryBase
ParameterLibraryBase()
Default constructor.
Definition
Sacado_ParameterLibraryBaseImp.hpp:34
Sacado::ParameterLibraryBase::isParameterForType
bool isParameterForType(const std::string &name) const
Determine if parameter of name name has type type.
Definition
Sacado_ParameterLibraryBaseImp.hpp:59
Sacado::ParameterLibraryBase::print
void print(std::ostream &os, bool print_values=false) const
Print parameter library.
Definition
Sacado_ParameterLibraryBaseImp.hpp:178
Sacado::ParameterLibraryBase::getEntry
Teuchos::RCP< typename Sacado::mpl::apply< EntryType, EvalType >::type > getEntry(const std::string &name)
Return parameter entry.
Definition
Sacado_ParameterLibraryBaseImp.hpp:117
Sacado::ParameterLibraryBase::fillVector
void fillVector(const Teuchos::Array< std::string > &names, const Teuchos::Array< BaseValueType > &values, ParameterVectorBase< FamilyType, BaseValueType > &pv)
Fill a vector with the supplied parameter names and values.
Definition
Sacado_ParameterLibraryBaseImp.hpp:157
Sacado::ParameterVectorBase
A class to store the active parameters in a code in an ordered fashion, along with their "base" value...
Definition
Sacado_ParameterVectorBase.hpp:47
Sacado::ParameterVectorBase::addParam
void addParam(const Teuchos::RCP< FamilyType > &family, BaseValueType baseValue)
Add entry.
Definition
Sacado_ParameterVectorBase.hpp:94
Sacado::mpl::apply_wrap5< F, mpl::none, mpl::none, mpl::none, mpl::none, mpl::none >::type
F::template apply< mpl::none, mpl::none, mpl::none, mpl::none, mpl::none >::type type
Definition
Sacado_mpl_apply_wrap.hpp:84
Generated by
1.17.0