00001 /***************************************************************************
00002 binprobe.h
00003 -------------------
00004 begin : Mon Oct 5 2000
00005 copyright : (C) 2000 by Michael Peeters
00006 email : Michael.Peeters@vub.ac.be
00007 ***************************************************************************/
00008
00009 /***************************************************************************
00010 * *
00011 * This program is free software; you can redistribute it and/or modify *
00012 * it under the terms of the GNU General Public License as published by *
00013 * the Free Software Foundation; either version 2 of the License, or *
00014 * (at your option) any later version. *
00015 * *
00016 ***************************************************************************/
00017
00018 #ifndef BINPROBE_H
00019 #define BINPROBE_H
00020
00021 #include "probe.h"
00022 #include "bin.h"
00023
00024 namespace MODEL
00025 {
00026
00037 template<integer dims, typename nelem=number, class NT = NumericTraits<nelem,dims> >
00038 class BinProbe : public GenericProbe
00039 {
00040 public:
00041 typedef ODESystem<dims,nelem,NT> system;
00042
00043 BinProbe(TimeFrame& T,
00044 const string& n,
00045 Bin& b,
00046 system& sys,
00047 integer v) : GenericProbe (T,n), my_sys(&sys), my_b(&b), var(v)
00048 {
00049 }
00050
00051 ~BinProbe()
00052 {
00053 // Otherwise, nothing gets written
00054 write_data();
00055 }
00056
00057 virtual void print(ostream& out)
00058 {
00059 // Here, we write the data from the bin to the probe
00060 vector<number> bi=my_b->get_bins();
00061 vector<counter> hi=my_b->get_histo();
00062
00063 for(counter i=0;i<bi.size();i++)
00064 out << bi[i] << "\t" << hi[i] << endl;
00065 }
00066
00067 void probe(void)
00068 {
00069 my_b->add_value(my_sys->get_current()[var]);
00070 }
00071
00072 NO_COPY(BinProbe);
00073
00074 private:
00075 system* my_sys;
00076 Bin* my_b;
00077 integer var;
00078 };
00079
00080
00081 template<integer dims, typename nelem=number, class NT = NumericTraits<nelem,dims> >
00082 class AvgBinProbe : public GenericProbe
00083 {
00084 public:
00085 typedef ODESystem<dims,nelem,NT> system;
00086
00087
00090 AvgBinProbe(TimeFrame& T,
00091 const string& n,
00092 Bin& b,
00093 system& sys,
00094 integer v,integer no) : GenericProbe (T,n),
00095 my_sys(&sys), my_b(&b),
00096 var(v),n(no)
00097 {
00098 runningvalue=0.;
00099 }
00100
00101 ~AvgBinProbe()
00102 {
00103 // Otherwise, nothing gets written
00104 write_data();
00105 }
00106
00107 virtual void print(ostream& out)
00108 {
00109 // Here, we write the data from the bin to the probe
00110 vector<number> bi=my_b->get_bins();
00111 vector<counter> hi=my_b->get_histo();
00112
00113 for(counter i=0;i<bi.size();i++)
00114 out << bi[i] << "\t" << hi[i] << endl;
00115 }
00116
00117 void probe(void)
00118 {
00119 // This was just plain silly
00120 // const number factor=exp(-1./n);
00121 // Should have been
00122 const number factor=1.-1./n;
00123
00124 runningvalue=factor*runningvalue+(1.-factor)*my_sys->get_current()[var];
00125 my_b->add_value(runningvalue);
00126 }
00127
00128 NO_COPY(AvgBinProbe);
00129
00130 private:
00131 system* my_sys;
00132 Bin* my_b;
00133 integer var;
00134 integer n;
00135
00136 number runningvalue;
00137 };
00138
00139 }
00140
00141 #endif
00142
00143 /*********************************************************************
00144 $Id: binprobe.h,v 1.1.2.1 2001/10/04 12:57:20 mpeeters Exp $
00145 **********************************************************************
00146
00147 $Log: binprobe.h,v $
00148 Revision 1.1.2.1 2001/10/04 12:57:20 mpeeters
00149 Changed wrong calculation of 1st order digital filter for averaging.
00150
00151 Revision 1.1 2001/05/22 10:54:55 mpeeters
00152 Moved sources and headers for libModel to model/ subdirectory, in an attempt to rationalize the source tree. This should make things "netter".
00153
00154 Revision 1.2 2001/05/21 11:53:16 mpeeters
00155 Removed Makefile.in, which is automatically generated anyway.
00156
00157 Revision 1.1 2000/10/13 11:20:22 mpeeters
00158 Added two new probes (which were in the 0.9 tarball, but which I forgot
00159 to add to the CVS). Removed history.
00160
00161 *********************************************************************/
More Info? Michael Peeters. Also, check our research website: www.alna.vub.ac.be
Last update: June 2002.