00001 /* 00002 ------------------------------------------------------------------- 00003 00004 Copyright (C) 2006, 2007, Andrew W. Steiner 00005 00006 This file is part of O2scl. 00007 00008 O2scl is free software; you can redistribute it and/or modify 00009 it under the terms of the GNU General Public License as published by 00010 the Free Software Foundation; either version 3 of the License, or 00011 (at your option) any later version. 00012 00013 O2scl is distributed in the hope that it will be useful, 00014 but WITHOUT ANY WARRANTY; without even the implied warranty of 00015 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00016 GNU General Public License for more details. 00017 00018 You should have received a copy of the GNU General Public License 00019 along with O2scl. If not, see <http://www.gnu.org/licenses/>. 00020 00021 ------------------------------------------------------------------- 00022 */ 00023 #ifndef O2SCL_TPTR_GEOSERIES_H 00024 #define O2SCL_TPTR_GEOSERIES_H 00025 00026 #include <iostream> 00027 #include <o2scl/collection.h> 00028 #include <o2scl/tptr_schedule.h> 00029 00030 #ifndef DOXYGENP 00031 namespace o2scl { 00032 #endif 00033 00034 /** 00035 \brief Temperature schedule for a geometric series 00036 00037 The temperature begins at \c start, and is divided by \c ratio, 00038 until it is smaller than \c end. The ending value is divided by 00039 \c sqrt(ratio) to avoid finite precision problems for series 00040 when \c start/end is an integral power of \c ratio. 00041 00042 The default schedule is \f$T=1/(1.01)^{n}\f$ for 00043 \f$n=0,1,2,3,...,463\f$ (until \f$T<0.01\f$) 00044 given by \c ustart=1, \c uend=0.01, \c uratio=1.01. 00045 00046 */ 00047 template<class vec_t=ovector_view> 00048 class tptr_geoseries : public tptr_schedule<vec_t> { 00049 public: 00050 00051 tptr_geoseries() { 00052 dstart=1.0; 00053 end=1.0e-2; 00054 ratio=1.01; 00055 last=dstart*ratio; 00056 } 00057 00058 virtual ~tptr_geoseries() {} 00059 00060 /// Set the limits for the geometric series 00061 int set_series(double udstart, double uend, double uratio) { 00062 if ((udstart>uend && uratio<1.0) || (udstart<uend && uratio>1.0)) { 00063 set_err_ret("Series will never end in tptr_geoseries::set_series()", 00064 gsl_einval); 00065 } 00066 dstart=udstart; 00067 end=uend; 00068 ratio=uratio; 00069 last=dstart*ratio; 00070 return 0; 00071 } 00072 00073 /// Get the number of temperatures in the series 00074 int get_npoints() { 00075 double n=log(dstart/end*sqrt(ratio))/log(ratio); 00076 return ((int)n)+1; 00077 } 00078 00079 /// Return the first temperature 00080 virtual double start(double min, int nv, const vec_t &best, void *vp) { 00081 last=dstart; 00082 return last; 00083 } 00084 00085 /// Return the next temperature 00086 virtual double next(double min, int nv, const vec_t &best, void *vp) { 00087 last=last/ratio; 00088 return last; 00089 } 00090 00091 /// Return true if the last step made the temperature too small 00092 virtual bool done(double min, int nv, const vec_t &best, void *vp) { 00093 if (last<end/sqrt(ratio)) return true; 00094 return false; 00095 } 00096 00097 /// Return string denoting type ("tptr_geoseries") 00098 virtual const char *type() { return "tptr_geoseries"; } 00099 00100 protected: 00101 00102 #ifndef DOXYGEN_INTERNAL 00103 00104 /// \name parameters for the schedule 00105 //@{ 00106 double dstart, end, ratio; 00107 //@} 00108 00109 /// The last temperature returned 00110 double last; 00111 00112 #endif 00113 00114 }; 00115 00116 #ifndef DOXYGENP 00117 } 00118 #endif 00119 00120 #endif 00121
Documentation generated with Doxygen and provided under the GNU Free Documentation License. See License Information for details.
Project hosting provided by
,
O2scl Sourceforge Project Page