Sacado Package Browser (Single Doxygen Collection)  Version of the Day
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
Sacado_ParameterFamilyBaseImp.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 EntryBase, typename EntryType>
14 ParameterFamilyBase(const std::string& name_,
15  bool supports_ad_,
16  bool supports_analytic_) :
17  family(),
18  name(name_),
19  supports_ad(supports_ad_),
20  supports_analytic(supports_analytic_)
21 {
22 }
23 
24 template <typename EntryBase, typename EntryType>
27 {
28 }
29 
30 template <typename EntryBase, typename EntryType>
31 std::string
33 getName() const
34 {
35  return name;
36 }
37 
38 template <typename EntryBase, typename EntryType>
39 bool
41 supportsAD() const
42 {
43  return supports_ad;
44 }
45 
46 template <typename EntryBase, typename EntryType>
47 bool
50 {
51  return supports_analytic;
52 }
53 
54 template <typename EntryBase, typename EntryType>
55 template <class EvalType>
56 bool
58 hasType() const
59 {
60 
61  // Convert typename EvalType to string
62  std::string evalTypeString = getTypeName<EvalType>();
63 
64  // Find entry corresponding to this EvalType
65  const_iterator it = family.find(evalTypeString);
66  if (it == family.end())
67  return false;
68 
69  return true;
70 }
71 
72 template <typename EntryBase, typename EntryType>
73 template <class EvalType>
74 bool
77  const bool allow_overwrite)
78 {
79  // Get string representation of EvalType
80  std::string evalTypeString = getTypeName<EvalType>();
81 
82  // Determine if entry already exists for parameter and type
83  iterator it = family.find(evalTypeString);
84 
85  // If it does not, add it
86  if (it == family.end()) {
87  family.insert(std::pair<std::string,
88  Teuchos::RCP<EntryBase> >(evalTypeString, entry));
89  }
90  else if (allow_overwrite) {
91  (*it).second = entry;
92  }
93  else {
94  return false;
95  }
96 
97  return true;
98 }
99 
100 template <typename EntryBase, typename EntryType>
101 template <class EvalType>
105 
106  // Convert typename EvalType to string
107  std::string evalTypeString = getTypeName<EvalType>();
108 
109  // Find entry corresponding to this EvalType
110  iterator it = family.find(evalTypeString);
111  TEUCHOS_TEST_FOR_EXCEPTION(it == family.end(),
112  std::logic_error,
113  std::string("Sacado::ParameterFamilyBase::getEntry(): ")
114  + "Parameter entry " + name
115  + " does not have a parameter of type"
116  + evalTypeString);
117 
118  // Cast entry to LOCA::Parameter::Entry<EvalType>
121  std::logic_error,
122  std::string("Sacado::ParameterFamilyBase::getEntry(): ")
123  + "Parameter entry " + name
124  + " of type" + evalTypeString
125  + " has incorrect entry type");
126 
127  return entry;
128 }
129 
130 template <typename EntryBase, typename EntryType>
131 template <class EvalType>
134 getEntry() const {
135 
136  // Convert typename EvalType to string
137  std::string evalTypeString = getTypeName<EvalType>();
138 
139  // Find entry corresponding to this EvalType
140  const_iterator it = family.find(evalTypeString);
141  TEUCHOS_TEST_FOR_EXCEPTION(it == family.end(),
142  std::logic_error,
143  std::string("Sacado::ParameterFamilyBase::getEntry(): ")
144  + "Parameter entry " + name
145  + " does not have a parameter of type"
146  + evalTypeString);
147 
148  // Cast entry to LOCA::Parameter::Entry<EvalType>
151  std::logic_error,
152  std::string("Sacado::ParameterFamilyBase::getEntry(): ")
153  + "Parameter entry " + name
154  + " of type" + evalTypeString
155  + " has incorrect entry type");
156 
157  return entry;
158 }
159 
160 template <typename EntryBase, typename EntryType>
161 void
163 print(std::ostream& os, bool print_values) const
164 {
165  os << "\t" << name << ": Supports AD = " << supports_ad
166  << ", Supports_Analytic = " << supports_analytic << std::endl;
167  if (print_values) {
168  for (const_iterator it = family.begin(); it != family.end(); it++) {
169  os << "\t\t" << (*it).first << " = ";
170  (*it).second->print(os);
171  os << std::endl;
172  }
173  }
174 
175 }
176 
177 template <typename EntryBase, typename EntryType>
178 template <class EvalType>
179 std::string
181 getTypeName() const {
182  return typeid(EvalType).name();
183 }
ParameterFamilyBase(const std::string &name, bool supports_ad, bool supports_analytic)
Constructor.
#define TEUCHOS_TEST_FOR_EXCEPTION(throw_exception_test, Exception, msg)
EvalMap::const_iterator const_iterator
Const iterator for EvalMap.
EvalMap::iterator iterator
Iterator for EvalMap.
std::string getTypeName() const
Returns a string representation of type EntryType.
std::string getName() const
Get the name of the family.
F::template apply< A1, A2, A3, A4, A5 >::type type
void print(std::ostream &os, bool print_values=false) const
Print the family.
bool addEntry(const Teuchos::RCP< typename Sacado::mpl::apply< EntryType, EvalType >::type > &entry, const bool allow_overwrite=false)
Add a new parameter using custom entry.
bool hasType() const
Determine if family has an entry for the given type EvalType.
Teuchos::RCP< typename Sacado::mpl::apply< EntryType, EvalType >::type > getEntry()
Gets the entry corresponding to type EvalType.
bool supportsAD() const
Indicates whether parameter supports AD derivatives.
std::string name_
Definition: gtest.cc:2817
bool supportsAnalytic() const
Indicates whether parameter supports analytic derivatives.