|
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 FamilyType, typename EntryType> 00035 Sacado::ParameterLibraryBase<FamilyType,EntryType>:: 00036 ParameterLibraryBase() 00037 { 00038 } 00039 00040 template <typename FamilyType, typename EntryType> 00041 Sacado::ParameterLibraryBase<FamilyType,EntryType>:: 00042 ~ParameterLibraryBase() 00043 { 00044 } 00045 00046 template <typename FamilyType, typename EntryType> 00047 bool 00048 Sacado::ParameterLibraryBase<FamilyType,EntryType>:: 00049 isParameter(const std::string& name) const 00050 { 00051 // Get family 00052 typename FamilyMap::const_iterator it = library.find(name); 00053 00054 return (it != library.end()); 00055 } 00056 00057 template <typename FamilyType, typename EntryType> 00058 template <class EvalType> 00059 bool 00060 Sacado::ParameterLibraryBase<FamilyType,EntryType>:: 00061 isParameterForType(const std::string& name) const 00062 { 00063 // Get family 00064 typename FamilyMap::const_iterator it = library.find(name); 00065 00066 // First check parameter is in the library 00067 if (it == library.end()) 00068 return false; 00069 00070 // Determine if type is in the family 00071 return (*it).second->template hasType<EvalType>(); 00072 } 00073 00074 template <typename FamilyType, typename EntryType> 00075 bool 00076 Sacado::ParameterLibraryBase<FamilyType,EntryType>:: 00077 addParameterFamily(const std::string& name, 00078 bool supports_ad, 00079 bool supports_analytic) 00080 { 00081 // Check that the parameter is not in the library 00082 if (isParameter(name)) 00083 return false; 00084 00085 Teuchos::RCP<FamilyType> f = 00086 Teuchos::rcp(new FamilyType(name, supports_ad, supports_analytic)); 00087 library.insert(std::pair< std::string, 00088 Teuchos::RCP<FamilyType> >(name, f)); 00089 00090 return true; 00091 } 00092 00093 template <typename FamilyType, typename EntryType> 00094 template <class EvalType> 00095 bool 00096 Sacado::ParameterLibraryBase<FamilyType,EntryType>:: 00097 addEntry(const std::string& name, 00098 const Teuchos::RCP< typename Sacado::mpl::apply<EntryType,EvalType>::type >& entry) 00099 { 00100 // Get family 00101 typename FamilyMap::iterator it = library.find(name); 00102 00103 // First check parameter is in the library 00104 TEUCHOS_TEST_FOR_EXCEPTION(it == library.end(), 00105 std::logic_error, 00106 std::string("Sacado::ParameterLibraryBase::addEntry(): ") 00107 + "Parameter family " + name 00108 + " is not in the library"); 00109 00110 // Call family's addEntry method 00111 return (*it).second->template addEntry<EvalType>(entry); 00112 } 00113 00114 template <typename FamilyType, typename EntryType> 00115 template <class EvalType> 00116 Teuchos::RCP< typename Sacado::mpl::apply<EntryType,EvalType>::type > 00117 Sacado::ParameterLibraryBase<FamilyType,EntryType>:: 00118 getEntry(const std::string& name) 00119 { 00120 // Get family 00121 typename FamilyMap::iterator it = library.find(name); 00122 00123 // First check parameter is in the library 00124 TEUCHOS_TEST_FOR_EXCEPTION(it == library.end(), 00125 std::logic_error, 00126 std::string("Sacado::ParameterLibraryBase::getEntry(): ") 00127 + "Parameter family " + name 00128 + " is not in the library"); 00129 00130 // Call family's getEntry method 00131 return (*it).second->template getEntry<EvalType>(); 00132 } 00133 00134 template <typename FamilyType, typename EntryType> 00135 template <class EvalType> 00136 Teuchos::RCP< const typename Sacado::mpl::apply<EntryType,EvalType>::type > 00137 Sacado::ParameterLibraryBase<FamilyType,EntryType>:: 00138 getEntry(const std::string& name) const 00139 { 00140 // Get family 00141 typename FamilyMap::const_iterator it = library.find(name); 00142 00143 // First check parameter is in the library 00144 TEUCHOS_TEST_FOR_EXCEPTION(it == library.end(), 00145 std::logic_error, 00146 std::string("Sacado::ParameterLibraryBase::getEntry(): ") 00147 + "Parameter family " + name 00148 + " is not in the library"); 00149 00150 // Call family's getEntry method 00151 return (*it).second->template getEntry<EvalType>(); 00152 } 00153 00154 template <typename FamilyType, typename EntryType> 00155 template <typename BaseValueType> 00156 void 00157 Sacado::ParameterLibraryBase<FamilyType,EntryType>:: 00158 fillVector(const Teuchos::Array<std::string>& names, 00159 const Teuchos::Array<BaseValueType>& values, 00160 ParameterVectorBase<FamilyType,BaseValueType>& pv) 00161 { 00162 typename FamilyMap::iterator it; 00163 00164 // Fill in parameters 00165 for (unsigned int i=0; i<names.size(); i++) { 00166 it = library.find(names[i]); 00167 TEUCHOS_TEST_FOR_EXCEPTION( 00168 it == library.end(), 00169 std::logic_error, 00170 std::string("Sacado::ParameterLibraryBase::fillVector(): ") 00171 + "Invalid parameter family " + names[i]); 00172 pv.addParam((*it).second, values[i]); 00173 } 00174 } 00175 00176 template <typename FamilyType, typename EntryType> 00177 void 00178 Sacado::ParameterLibraryBase<FamilyType,EntryType>:: 00179 print(std::ostream& os, bool print_values) const 00180 { 00181 os << "Library of all registered parameters:" << std::endl; 00182 typename FamilyMap::const_iterator it = this->library.begin(); 00183 for (; it != this->library.end(); ++it) { 00184 (*it).second->print(os, print_values); 00185 } 00186 }
1.7.4