00001 /***************************************************************************
00002 probe.h - description
00003 -------------------
00004 begin : Mon Aug 11 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 PROBE_H
00019 #define PROBE_H
00020
00021 #include <vector>
00022 #include <string>
00023 #include <iostream>
00024 #include <fstream>
00025 #include "odesystem.h"
00026 #include "numerictraits.h"
00027
00028 namespace MODEL
00029 {
00030
00035 class GenericProbe : public TickTock
00036 {
00037 public:
00039 GenericProbe(TimeFrame& T, const string& fn);
00040
00042 GenericProbe(TimeFrame & T, ostream& os);
00043
00044 ~GenericProbe(){}
00045
00046 virtual void tick();
00047
00048 virtual void probe(void)=0;
00049
00051 void write_data(void);
00052
00059 virtual void print(ostream& out)=0;
00060
00062 NO_COPY(GenericProbe);
00063
00064 protected:
00065 string n;
00066 ostream* out;
00067 };
00068
00077 class Probe : public TickTock
00078 {
00079 public:
00080 typedef vector<number> data_record;
00081 typedef vector< data_record > data_list;
00082
00088 Probe(TimeFrame & T, const string& fn);
00089
00094 Probe(TimeFrame & T, ostream& os);
00095
00096 virtual ~Probe();
00097
00098 virtual void tick();
00099
00100 virtual void probe(void)=0;
00101
00102 void add_data(const number& d);
00103
00105 NO_COPY(Probe);
00106
00107 private:
00108 string n;
00109 ostream* out;
00110
00111 bool data_is_here;
00112 data_list* var_data;
00113 data_record* temp_data;
00114 };
00115
00116 //------------------------------------------------------------
00117
00119 template<integer dims, typename nelem=number, class NT =
00120 NumericTraits<nelem,dims> >
00121
00122 class ODEProbe : public Probe
00123 {
00124 public:
00125 typedef ODESystem<dims,nelem,NT> system;
00126
00127 ODEProbe(TimeFrame& T, system& s, const string& n)
00128 : Probe(T,n), my_sys(&s){}
00129
00130 ODEProbe(TimeFrame& T, system& s, ostream& o)
00131 : Probe(T,o), my_sys(&s){}
00132
00133 virtual void probe(void)
00134 {
00135 typename NT::vect current(my_sys->get_current());
00136 for(counter i=0;i<dims;i++) add_data(current[i]);
00137 }
00138
00139 private:
00140 system* my_sys;
00141 };
00142
00145 template<integer dims, typename nelem=number, class NT =
00146 NumericTraits<nelem,dims> >
00147
00148 class AvgProbe : public Probe
00149 {
00150 public:
00151 typedef ODESystem<dims,nelem,NT> system;
00152
00168 AvgProbe(TimeFrame& T, system& s, const string& n, integer no,
00169 integer avg, integer out = 1)
00170 : Probe(T,n), my_sys(&s),whichone(no),n(avg),o(out),ocount(0),runningvalue(0){}
00171
00172 AvgProbe(TimeFrame& T, system& s, ostream& o, integer no, integer
00173 avg)
00174 : Probe(T,o), my_sys(&s), whichone(no), n(avg){}
00175
00176 virtual void probe(void)
00177 {
00178 // This was just plain silly
00179 // const number factor=exp(-1./n);
00180 // Should have been
00181 const number factor=1.-1./n;
00182
00183 runningvalue=factor*runningvalue+(1.-factor)*my_sys->get_current()[whichone];
00184
00185 if(++ocount==o){
00186 add_data(runningvalue);
00187 ocount=0;
00188 }
00189 }
00190
00191 private:
00192 system* my_sys;
00193 integer whichone;
00194 integer n;
00195 integer o;
00196 integer ocount;
00197
00198 number runningvalue;
00199 };
00200
00201 } // end namespace
00202 #endif
00203
00204 /*********************************************************************
00205 $Id: probe.h,v 1.1.2.4 2002/02/06 12:49:39 mpeeters Exp $
00206 **********************************************************************
00207
00208 $Log: probe.h,v $
00209 Revision 1.1.2.4 2002/02/06 12:49:39 mpeeters
00210 Altered interface to make fudging easier. Will be reverted.
00211
00212 Revision 1.1.2.3 2001/10/04 12:57:20 mpeeters
00213 Changed wrong calculation of 1st order digital filter for averaging.
00214
00215 Revision 1.1.2.2 2001/09/03 12:29:17 mpeeters
00216 Bugfix: == should have been =. Bummer.
00217
00218 Revision 1.1.2.1 2001/09/03 10:06:07 mpeeters
00219 Added parameter to allow for subsampling of output.
00220
00221 Revision 1.1 2001/05/22 10:54:55 mpeeters
00222 Moved sources and headers for libModel to model/ subdirectory, in an attempt to rationalize the source tree. This should make things "netter".
00223
00224 Revision 1.4 2001/05/21 11:53:16 mpeeters
00225 Removed Makefile.in, which is automatically generated anyway.
00226
00227 Revision 1.3 2000/10/09 09:43:44 mpeeters
00228 Added GenericProbe, because Probe was too specialized already.
00229 Probe now only logs data when add_data is called, not at every timepoint.
00230 This caused a huge memory leak, which has been shut now.
00231
00232 Revision 1.2 2000/09/15 10:26:31 mpeeters
00233 Cleaned out header and added CVS tails to files, removed superfuous
00234 @author comments, inserted dates
00235
00236 *********************************************************************/
More Info? Michael Peeters. Also, check our research website: www.alna.vub.ac.be
Last update: June 2002.