|
Sacado Package Browser (Single Doxygen Collection) Version of the Day
|
00001 // $Id$ 00002 // $Source$ 00003 // @HEADER 00004 // *********************************************************************** 00005 // 00006 // Sacado Package 00007 // Copyright (2006) Sandia Corporation 00008 // 00009 // Under the terms of Contract DE-AC04-94AL85000 with Sandia Corporation, 00010 // the U.S. Government retains certain rights in this software. 00011 // 00012 // This library is free software; you can redistribute it and/or modify 00013 // it under the terms of the GNU Lesser General Public License as 00014 // published by the Free Software Foundation; either version 2.1 of the 00015 // License, or (at your option) any later version. 00016 // 00017 // This library is distributed in the hope that it will be useful, but 00018 // WITHOUT ANY WARRANTY; without even the implied warranty of 00019 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00020 // Lesser General Public License for more details. 00021 // 00022 // You should have received a copy of the GNU Lesser General Public 00023 // License along with this library; if not, write to the Free Software 00024 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 00025 // USA 00026 // Questions? Contact David M. Gay (dmgay@sandia.gov) or Eric T. Phipps 00027 // (etphipp@sandia.gov). 00028 // 00029 // *********************************************************************** 00030 // @HEADER 00031 00032 #include "Teuchos_Assert.hpp" 00033 00034 template <typename EntryBase, typename EntryType> 00035 Sacado::ParameterFamilyBase<EntryBase,EntryType>:: 00036 ParameterFamilyBase(const std::string& name_, 00037 bool supports_ad_, 00038 bool supports_analytic_) : 00039 family(), 00040 name(name_), 00041 supports_ad(supports_ad_), 00042 supports_analytic(supports_analytic_) 00043 { 00044 } 00045 00046 template <typename EntryBase, typename EntryType> 00047 Sacado::ParameterFamilyBase<EntryBase,EntryType>:: 00048 ~ParameterFamilyBase() 00049 { 00050 } 00051 00052 template <typename EntryBase, typename EntryType> 00053 std::string 00054 Sacado::ParameterFamilyBase<EntryBase,EntryType>:: 00055 getName() const 00056 { 00057 return name; 00058 } 00059 00060 template <typename EntryBase, typename EntryType> 00061 bool 00062 Sacado::ParameterFamilyBase<EntryBase,EntryType>:: 00063 supportsAD() const 00064 { 00065 return supports_ad; 00066 } 00067 00068 template <typename EntryBase, typename EntryType> 00069 bool 00070 Sacado::ParameterFamilyBase<EntryBase,EntryType>:: 00071 supportsAnalytic() const 00072 { 00073 return supports_analytic; 00074 } 00075 00076 template <typename EntryBase, typename EntryType> 00077 template <class EvalType> 00078 bool 00079 Sacado::ParameterFamilyBase<EntryBase,EntryType>:: 00080 hasType() const 00081 { 00082 00083 // Convert typename EvalType to string 00084 std::string evalTypeString = getTypeName<EvalType>(); 00085 00086 // Find entry corresponding to this EvalType 00087 const_iterator it = family.find(evalTypeString); 00088 if (it == family.end()) 00089 return false; 00090 00091 return true; 00092 } 00093 00094 template <typename EntryBase, typename EntryType> 00095 template <class EvalType> 00096 bool 00097 Sacado::ParameterFamilyBase<EntryBase,EntryType>:: 00098 addEntry(const Teuchos::RCP< typename Sacado::mpl::apply<EntryType,EvalType>::type >& entry) 00099 { 00100 // Get string representation of EvalType 00101 std::string evalTypeString = getTypeName<EvalType>(); 00102 00103 // Determine if entry already exists for parameter and type 00104 iterator it = family.find(evalTypeString); 00105 00106 // If it does not, add it 00107 if (it == family.end()) { 00108 family.insert(std::pair<std::string, 00109 Teuchos::RCP<EntryBase> >(evalTypeString, entry)); 00110 } 00111 00112 else { 00113 return false; 00114 } 00115 00116 return true; 00117 } 00118 00119 template <typename EntryBase, typename EntryType> 00120 template <class EvalType> 00121 Teuchos::RCP< typename Sacado::mpl::apply<EntryType,EvalType>::type > 00122 Sacado::ParameterFamilyBase<EntryBase,EntryType>:: 00123 getEntry() { 00124 00125 // Convert typename EvalType to string 00126 std::string evalTypeString = getTypeName<EvalType>(); 00127 00128 // Find entry corresponding to this EvalType 00129 iterator it = family.find(evalTypeString); 00130 TEUCHOS_TEST_FOR_EXCEPTION(it == family.end(), 00131 std::logic_error, 00132 std::string("Sacado::ParameterFamilyBase::getEntry(): ") 00133 + "Parameter entry " + name 00134 + " does not have a parameter of type" 00135 + evalTypeString); 00136 00137 // Cast entry to LOCA::Parameter::Entry<EvalType> 00138 Teuchos::RCP< typename Sacado::mpl::apply<EntryType,EvalType>::type > entry = Teuchos::rcp_dynamic_cast< typename Sacado::mpl::apply<EntryType,EvalType>::type >((*it).second); 00139 TEUCHOS_TEST_FOR_EXCEPTION(entry == Teuchos::null, 00140 std::logic_error, 00141 std::string("Sacado::ParameterFamilyBase::getEntry(): ") 00142 + "Parameter entry " + name 00143 + " of type" + evalTypeString 00144 + " has incorrect entry type"); 00145 00146 return entry; 00147 } 00148 00149 template <typename EntryBase, typename EntryType> 00150 template <class EvalType> 00151 Teuchos::RCP< const typename Sacado::mpl::apply<EntryType,EvalType>::type > 00152 Sacado::ParameterFamilyBase<EntryBase,EntryType>:: 00153 getEntry() const { 00154 00155 // Convert typename EvalType to string 00156 std::string evalTypeString = getTypeName<EvalType>(); 00157 00158 // Find entry corresponding to this EvalType 00159 const_iterator it = family.find(evalTypeString); 00160 TEUCHOS_TEST_FOR_EXCEPTION(it == family.end(), 00161 std::logic_error, 00162 std::string("Sacado::ParameterFamilyBase::getEntry(): ") 00163 + "Parameter entry " + name 00164 + " does not have a parameter of type" 00165 + evalTypeString); 00166 00167 // Cast entry to LOCA::Parameter::Entry<EvalType> 00168 Teuchos::RCP< const typename Sacado::mpl::apply<EntryType,EvalType>::type > entry = Teuchos::rcp_dynamic_cast< const typename Sacado::mpl::apply<EntryType,EvalType>::type >((*it).second); 00169 TEUCHOS_TEST_FOR_EXCEPTION(entry == Teuchos::null, 00170 std::logic_error, 00171 std::string("Sacado::ParameterFamilyBase::getEntry(): ") 00172 + "Parameter entry " + name 00173 + " of type" + evalTypeString 00174 + " has incorrect entry type"); 00175 00176 return entry; 00177 } 00178 00179 template <typename EntryBase, typename EntryType> 00180 void 00181 Sacado::ParameterFamilyBase<EntryBase,EntryType>:: 00182 print(std::ostream& os, bool print_values) const 00183 { 00184 os << "\t" << name << ": Supports AD = " << supports_ad 00185 << ", Supports_Analytic = " << supports_analytic << std::endl; 00186 if (print_values) { 00187 for (const_iterator it = family.begin(); it != family.end(); it++) { 00188 os << "\t\t" << (*it).first << " = "; 00189 (*it).second->print(os); 00190 os << std::endl; 00191 } 00192 } 00193 00194 } 00195 00196 template <typename EntryBase, typename EntryType> 00197 template <class EvalType> 00198 std::string 00199 Sacado::ParameterFamilyBase<EntryBase,EntryType>:: 00200 getTypeName() const { 00201 return typeid(EvalType).name(); 00202 }
1.7.4