Sacado Package Browser (Single Doxygen Collection) Version of the Day
Loading...
Searching...
No Matches
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
32template <typename FamilyType, typename EntryType>
37
38template <typename FamilyType, typename EntryType>
43
44template <typename FamilyType, typename EntryType>
45bool
47isParameter(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
55template <typename FamilyType, typename EntryType>
56template <class EvalType>
57bool
59isParameterForType(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
72template <typename FamilyType, typename EntryType>
73bool
75addParameterFamily(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
91template <typename FamilyType, typename EntryType>
92template <class EvalType>
93bool
95addEntry(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);
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
113template <typename FamilyType, typename EntryType>
114template <class EvalType>
115Teuchos::RCP< typename Sacado::mpl::apply<EntryType,EvalType>::type >
117getEntry(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
133template <typename FamilyType, typename EntryType>
134template <class EvalType>
135Teuchos::RCP< const typename Sacado::mpl::apply<EntryType,EvalType>::type >
137getEntry(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
153template <typename FamilyType, typename EntryType>
154template <typename BaseValueType>
155void
157fillVector(const Teuchos::Array<std::string>& names,
158 const Teuchos::Array<BaseValueType>& values,
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
175template <typename FamilyType, typename EntryType>
176void
178print(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}
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.
bool isParameter(const std::string &name) const
Determine if parameter of name name is in the library.
bool addParameterFamily(const std::string &name, bool supports_ad, bool supports_analytic)
Create a new parameter family.
bool isParameterForType(const std::string &name) const
Determine if parameter of name name has type type.
void print(std::ostream &os, bool print_values=false) const
Print parameter library.
Teuchos::RCP< typename Sacado::mpl::apply< EntryType, EvalType >::type > getEntry(const std::string &name)
Return parameter entry.
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.
A class to store the active parameters in a code in an ordered fashion, along with their "base" value...
void addParam(const Teuchos::RCP< FamilyType > &family, BaseValueType baseValue)
Add entry.
F::template apply< A1, A2, A3, A4, A5 >::type type