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 //
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 EntryBase, typename EntryType>
34 ParameterFamilyBase(const std::string& name_,
35  bool supports_ad_,
36  bool supports_analytic_) :
37  family(),
38  name(name_),
39  supports_ad(supports_ad_),
40  supports_analytic(supports_analytic_)
41 {
42 }
43 
44 template <typename EntryBase, typename EntryType>
47 {
48 }
49 
50 template <typename EntryBase, typename EntryType>
51 std::string
53 getName() const
54 {
55  return name;
56 }
57 
58 template <typename EntryBase, typename EntryType>
59 bool
61 supportsAD() const
62 {
63  return supports_ad;
64 }
65 
66 template <typename EntryBase, typename EntryType>
67 bool
70 {
71  return supports_analytic;
72 }
73 
74 template <typename EntryBase, typename EntryType>
75 template <class EvalType>
76 bool
78 hasType() const
79 {
80 
81  // Convert typename EvalType to string
82  std::string evalTypeString = getTypeName<EvalType>();
83 
84  // Find entry corresponding to this EvalType
85  const_iterator it = family.find(evalTypeString);
86  if (it == family.end())
87  return false;
88 
89  return true;
90 }
91 
92 template <typename EntryBase, typename EntryType>
93 template <class EvalType>
94 bool
97  const bool allow_overwrite)
98 {
99  // Get string representation of EvalType
100  std::string evalTypeString = getTypeName<EvalType>();
101 
102  // Determine if entry already exists for parameter and type
103  iterator it = family.find(evalTypeString);
104 
105  // If it does not, add it
106  if (it == family.end()) {
107  family.insert(std::pair<std::string,
108  Teuchos::RCP<EntryBase> >(evalTypeString, entry));
109  }
110  else if (allow_overwrite) {
111  (*it).second = entry;
112  }
113  else {
114  return false;
115  }
116 
117  return true;
118 }
119 
120 template <typename EntryBase, typename EntryType>
121 template <class EvalType>
125 
126  // Convert typename EvalType to string
127  std::string evalTypeString = getTypeName<EvalType>();
128 
129  // Find entry corresponding to this EvalType
130  iterator it = family.find(evalTypeString);
131  TEUCHOS_TEST_FOR_EXCEPTION(it == family.end(),
132  std::logic_error,
133  std::string("Sacado::ParameterFamilyBase::getEntry(): ")
134  + "Parameter entry " + name
135  + " does not have a parameter of type"
136  + evalTypeString);
137 
138  // Cast entry to LOCA::Parameter::Entry<EvalType>
141  std::logic_error,
142  std::string("Sacado::ParameterFamilyBase::getEntry(): ")
143  + "Parameter entry " + name
144  + " of type" + evalTypeString
145  + " has incorrect entry type");
146 
147  return entry;
148 }
149 
150 template <typename EntryBase, typename EntryType>
151 template <class EvalType>
154 getEntry() const {
155 
156  // Convert typename EvalType to string
157  std::string evalTypeString = getTypeName<EvalType>();
158 
159  // Find entry corresponding to this EvalType
160  const_iterator it = family.find(evalTypeString);
161  TEUCHOS_TEST_FOR_EXCEPTION(it == family.end(),
162  std::logic_error,
163  std::string("Sacado::ParameterFamilyBase::getEntry(): ")
164  + "Parameter entry " + name
165  + " does not have a parameter of type"
166  + evalTypeString);
167 
168  // Cast entry to LOCA::Parameter::Entry<EvalType>
171  std::logic_error,
172  std::string("Sacado::ParameterFamilyBase::getEntry(): ")
173  + "Parameter entry " + name
174  + " of type" + evalTypeString
175  + " has incorrect entry type");
176 
177  return entry;
178 }
179 
180 template <typename EntryBase, typename EntryType>
181 void
183 print(std::ostream& os, bool print_values) const
184 {
185  os << "\t" << name << ": Supports AD = " << supports_ad
186  << ", Supports_Analytic = " << supports_analytic << std::endl;
187  if (print_values) {
188  for (const_iterator it = family.begin(); it != family.end(); it++) {
189  os << "\t\t" << (*it).first << " = ";
190  (*it).second->print(os);
191  os << std::endl;
192  }
193  }
194 
195 }
196 
197 template <typename EntryBase, typename EntryType>
198 template <class EvalType>
199 std::string
201 getTypeName() const {
202  return typeid(EvalType).name();
203 }
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.
bool supportsAnalytic() const
Indicates whether parameter supports analytic derivatives.