Sacado_ScalarParameterLibrary.hpp

Go to the documentation of this file.
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 #ifndef SACADO_SCALARPARAMETERLIBRARY_HPP
00033 #define SACADO_SCALARPARAMETERLIBRARY_HPP
00034 
00035 #include "Sacado_ParameterLibraryBase.hpp"
00036 #include "Sacado_ScalarParameterFamily.hpp"
00037 #include "Sacado_ScalarParameterVector.hpp"
00038 
00039 #include "Teuchos_TestForException.hpp"
00040 
00041 namespace Sacado {
00042 
00047   template <typename EvalTypeTraits = DefaultEvalTypeTraits>
00048   class ScalarParameterLibrary : 
00049     public ParameterLibraryBase<ScalarParameterFamily<EvalTypeTraits>, 
00050                                 ScalarParameterEntry<_,EvalTypeTraits> > {
00051 
00052   public:
00053 
00055     typedef ParameterLibraryBase<ScalarParameterFamily<EvalTypeTraits>, 
00056                                  ScalarParameterEntry<_,EvalTypeTraits> > 
00057     BaseT;
00058   
00060     ScalarParameterLibrary() {}
00061 
00063     virtual ~ScalarParameterLibrary() {}
00064 
00066     void setRealValueForAllTypes(const std::string& name, double value);
00067 
00069     template <class EvalType>
00070     void 
00071     setRealValue(const std::string& name, double value);
00072 
00074     template <class EvalType>
00075     void 
00076     setValue(const std::string& name, 
00077              const typename EvalTypeTraits::template apply<EvalType>::type& value);
00078 
00080     template <class EvalType>
00081     double
00082     getRealValue(const std::string& name) const;
00083 
00085     template <class EvalType>
00086     const typename EvalTypeTraits::template apply<EvalType>::type& 
00087     getValue(const std::string& name) const;
00088 
00090     static ScalarParameterLibrary& getInstance() {
00091       static ScalarParameterLibrary instance;
00092       return instance;
00093     }
00094 
00096 
00100     template <class EvalType>
00101     void
00102     fillVector(const Teuchos::Array<std::string>& names,
00103                ScalarParameterVector<EvalTypeTraits>& pv);
00104 
00105   private:
00106 
00108     ScalarParameterLibrary(const ScalarParameterLibrary&);
00109 
00111     ScalarParameterLibrary& operator = (const ScalarParameterLibrary&);
00112 
00113   };
00114 
00115 }
00116 
00117 
00118 template <typename EvalTypeTraits>
00119 void
00120 Sacado::ScalarParameterLibrary<EvalTypeTraits>::
00121 setRealValueForAllTypes(const std::string& name, double value)
00122 {
00123   typename BaseT::FamilyMap::iterator it = this->library.find(name);
00124   TEST_FOR_EXCEPTION(
00125      it == this->library.end(), 
00126      std::logic_error,
00127      std::string("Sacado::ScalararameterLibrary::setRealValueForAllTypes():  ")
00128      + "Invalid parameter family " + name);
00129   (*it).second->setRealValueForAllTypes(value);
00130 }
00131 
00132 template <typename EvalTypeTraits>
00133 template <class EvalType>
00134 void
00135 Sacado::ScalarParameterLibrary<EvalTypeTraits>::
00136 setRealValue(const std::string& name, double value)
00137 {
00138   typename BaseT::FamilyMap::iterator it = this->library.find(name);
00139   TEST_FOR_EXCEPTION(
00140      it == this->library.end(), 
00141      std::logic_error,
00142      std::string("Sacado::ScalarParameterLibrary::setValueAsConstant():  ")
00143      + "Invalid parameter family " + name);
00144   (*it).second->setRealValue<EvalType>(value);
00145 }
00146 
00147 template <typename EvalTypeTraits>
00148 template <class EvalType>
00149 void
00150 Sacado::ScalarParameterLibrary<EvalTypeTraits>::
00151 setValue(
00152       const std::string& name, 
00153       const typename EvalTypeTraits::template apply<EvalType>::type& value)
00154 {
00155   typename BaseT::FamilyMap::iterator it = this->library.find(name);
00156   TEST_FOR_EXCEPTION(
00157       it == this->library.end(), 
00158       std::logic_error,
00159       std::string("Sacado::ScalarParameterLibrary::setValueAsIndependent():  ")
00160       + "Invalid parameter family " + name);
00161   (*it).second->setValue<EvalType>(value);
00162 }
00163 
00164 template <typename EvalTypeTraits>
00165 template <class EvalType>
00166 double
00167 Sacado::ScalarParameterLibrary<EvalTypeTraits>::
00168 getRealValue(const std::string& name) const
00169 {
00170   typename BaseT::FamilyMap::const_iterator it = this->library.find(name);
00171   TEST_FOR_EXCEPTION(
00172      it == this->library.end(), 
00173      std::logic_error,
00174      std::string("Sacado::ScalarParameterLibrary::getValue():  ")
00175      + "Invalid parameter family " + name);
00176   return (*it).second->getRealValue<EvalType>();
00177 }
00178 
00179 template <typename EvalTypeTraits>
00180 template <class EvalType>
00181 const typename EvalTypeTraits::template apply<EvalType>::type&
00182 Sacado::ScalarParameterLibrary<EvalTypeTraits>::
00183 getValue(const std::string& name) const
00184 {
00185   typename BaseT::FamilyMap::const_iterator it = this->library.find(name);
00186   TEST_FOR_EXCEPTION(
00187      it == this->library.end(), 
00188      std::logic_error,
00189      std::string("Sacado::ScalarParameterLibrary::getValue():  ")
00190      + "Invalid parameter family " + name);
00191   return (*it).second->getValue<EvalType>();
00192 }
00193 
00194 template <typename EvalTypeTraits>
00195 template <class EvalType>
00196 void
00197 Sacado::ScalarParameterLibrary<EvalTypeTraits>::
00198 fillVector(const Teuchos::Array<std::string>& names,
00199            Sacado::ScalarParameterVector<EvalTypeTraits>& pv)
00200 {
00201   typename BaseT::FamilyMap::iterator it;
00202 
00203   // Fill in parameters
00204   for (unsigned int i=0; i<names.size(); i++) {
00205     it = this->library.find(names[i]);
00206     TEST_FOR_EXCEPTION(
00207        it == this->library.end(), 
00208        std::logic_error,
00209        std::string("Sacado::ParameterLibraryBase::fillVector():  ")
00210        + "Invalid parameter family " + names[i]);
00211     pv.addParam((*it).second, 0.0);
00212     pv[i].baseValue = (*it).second->getRealValue<EvalType>();
00213   }
00214 }
00215 
00216 
00217 #endif
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines
Generated on Wed Apr 13 10:19:34 2011 for Sacado Package Browser (Single Doxygen Collection) by  doxygen 1.6.3