Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
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>
35 {
36 }
37 
38 template <typename FamilyType, typename EntryType>
41 {
42 }
43 
44 template <typename FamilyType, typename EntryType>
45 bool
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
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
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 
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
95 addEntry(const std::string& name,
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>
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>
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
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]);
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
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 }
void f()
bool addParameterFamily(const std::string &name, bool supports_ad, bool supports_analytic)
Create a new parameter family.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
Teuchos::RCP< typename Sacado::mpl::apply< EntryType, EvalType >::type > getEntry(const std::string &name)
Return parameter entry.
bool isParameterForType(const std::string &name) const
Determine if parameter of name name has type type.
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.
void print(std::ostream &os, bool print_values=false) const
Print parameter library.
F::template apply< A1, A2, A3, A4, A5 >::type type
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.
void addParam(const Teuchos::RCP< FamilyType > &family, BaseValueType baseValue)
Add entry.
TEUCHOS_DEPRECATED RCP< T > rcp(T *p, Dealloc_T dealloc, bool owns_mem)
A class to store the active parameters in a code in an ordered fashion, along with their &quot;base&quot; value...
size_type size() const
bool isParameter(const std::string &name) const
Determine if parameter of name name is in the library.