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 // Sacado Package
4 //
5 // Copyright 2006 NTESS and the Sacado contributors.
6 // SPDX-License-Identifier: LGPL-2.1-or-later
7 // *****************************************************************************
8 // @HEADER
9 
10 #include "Teuchos_Assert.hpp"
11 
12 template <typename FamilyType, typename EntryType>
15 {
16 }
17 
18 template <typename FamilyType, typename EntryType>
21 {
22 }
23 
24 template <typename FamilyType, typename EntryType>
25 bool
27 isParameter(const std::string& name) const
28 {
29  // Get family
30  typename FamilyMap::const_iterator it = library.find(name);
31 
32  return (it != library.end());
33 }
34 
35 template <typename FamilyType, typename EntryType>
36 template <class EvalType>
37 bool
39 isParameterForType(const std::string& name) const
40 {
41  // Get family
42  typename FamilyMap::const_iterator it = library.find(name);
43 
44  // First check parameter is in the library
45  if (it == library.end())
46  return false;
47 
48  // Determine if type is in the family
49  return (*it).second->template hasType<EvalType>();
50 }
51 
52 template <typename FamilyType, typename EntryType>
53 bool
55 addParameterFamily(const std::string& name,
56  bool supports_ad,
57  bool supports_analytic)
58 {
59  // Check that the parameter is not in the library
60  if (isParameter(name))
61  return false;
62 
64  Teuchos::rcp(new FamilyType(name, supports_ad, supports_analytic));
65  library.insert(std::pair< std::string,
66  Teuchos::RCP<FamilyType> >(name, f));
67 
68  return true;
69 }
70 
71 template <typename FamilyType, typename EntryType>
72 template <class EvalType>
73 bool
75 addEntry(const std::string& name,
77  const bool allow_overwrite)
78 {
79  // Get family
80  typename FamilyMap::iterator it = library.find(name);
81 
82  // First check parameter is in the library
83  TEUCHOS_TEST_FOR_EXCEPTION(it == library.end(),
84  std::logic_error,
85  std::string("Sacado::ParameterLibraryBase::addEntry(): ")
86  + "Parameter family " + name
87  + " is not in the library");
88 
89  // Call family's addEntry method
90  return (*it).second->template addEntry<EvalType>(entry, allow_overwrite);
91 }
92 
93 template <typename FamilyType, typename EntryType>
94 template <class EvalType>
97 getEntry(const std::string& name)
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::getEntry(): ")
106  + "Parameter family " + name
107  + " is not in the library");
108 
109  // Call family's getEntry method
110  return (*it).second->template getEntry<EvalType>();
111 }
112 
113 template <typename FamilyType, typename EntryType>
114 template <class EvalType>
117 getEntry(const std::string& name) const
118 {
119  // Get family
120  typename FamilyMap::const_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 <typename BaseValueType>
135 void
138  const Teuchos::Array<BaseValueType>& values,
140 {
141  typename FamilyMap::iterator it;
142 
143  // Fill in parameters
144  for (unsigned int i=0; i<names.size(); i++) {
145  it = library.find(names[i]);
147  it == library.end(),
148  std::logic_error,
149  std::string("Sacado::ParameterLibraryBase::fillVector(): ")
150  + "Invalid parameter family " + names[i]);
151  pv.addParam((*it).second, values[i]);
152  }
153 }
154 
155 template <typename FamilyType, typename EntryType>
156 void
158 print(std::ostream& os, bool print_values) const
159 {
160  os << "Library of all registered parameters:" << std::endl;
161  typename FamilyMap::const_iterator it = this->library.begin();
162  for (; it != this->library.end(); ++it) {
163  (*it).second->print(os, print_values);
164  }
165 }
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.