MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
StimulusTable.cpp
Go to the documentation of this file.
1 /**********************************************************************
2 ** This program is part of 'MOOSE', the
3 ** Messaging Object Oriented Simulation Environment.
4 ** Copyright (C) 2003-2010 Upinder S. Bhalla. and NCBS
5 ** It is made available under the terms of the
6 ** GNU Lesser General Public License version 2.1
7 ** See the file COPYING.LIB for the full notice.
8 **********************************************************************/
9 
10 #include "header.h"
11 #include <fstream>
12 #include "TableBase.h"
13 #include "StimulusTable.h"
14 
17  "output",
18  "Sends out tabulated data according to lookup parameters."
19  );
20  return &output;
21 }
22 
24 {
26  // Field Definitions
28  static ValueFinfo< StimulusTable, double > startTime(
29  "startTime",
30  "Start time used when table is emitting values. For lookup"
31  "values below this, the table just sends out its zero entry."
32  "Corresponds to zeroth entry of table.",
35  );
36 
38  "stopTime",
39  "Time to stop emitting values."
40  "If time exceeds this, then the table sends out its last entry."
41  "The stopTime corresponds to the last entry of table.",
44  );
45 
47  "loopTime",
48  "If looping, this is the time between successive cycle starts."
49  "Defaults to the difference between stopTime and startTime, "
50  "so that the output waveform cycles with precisely the same "
51  "duration as the table contents."
52  "If larger than stopTime - startTime, then it pauses at the "
53  "last table value till it is time to "
54  "go around again."
55  "If smaller than stopTime - startTime, then it begins the next "
56  "cycle even before the first one has reached the end of the "
57  "table.",
60  );
61 
63  "stepSize",
64  "Increment in lookup (x) value on every timestep. If it is"
65  "less than or equal to zero, the StimulusTable uses the current time"
66  "as the lookup value.",
69  );
70 
71  static ValueFinfo< StimulusTable, double > stepPosition(
72  "stepPosition",
73  "Current value of lookup (x) value."
74  "If stepSize is less than or equal to zero, this is set to"
75  "the current time to use as the lookup value.",
78  );
79 
81  "doLoop",
82  "Flag: Should it loop around to startTime once it has reached"
83  "stopTime. Default (zero) is to do a single pass.",
86  );
87 
89  // MsgDest Definitions
91 
92  static DestFinfo process( "process",
93  "Handles process call, updates internal time stamp.",
95  static DestFinfo reinit( "reinit",
96  "Handles reinit call.",
99  // SharedMsg Definitions
101  static Finfo* procShared[] = {
102  &process, &reinit
103  };
104  static SharedFinfo proc( "proc",
105  "Shared message for process and reinit",
106  procShared, sizeof( procShared ) / sizeof( const Finfo* )
107  );
108 
109  static Finfo* stimulusTableFinfos[] = {
110  &startTime,
111  &stopTime,
112  &loopTime,
113  &stepSize,
114  &stepPosition,
115  &doLoop,
116  output(), // SrcFinfo
117  &proc, // SharedFinfo
118  };
119 
120  static Dinfo< StimulusTable > dinfo;
121  static Cinfo stimulusTableCinfo (
122  "StimulusTable",
124  stimulusTableFinfos,
125  sizeof( stimulusTableFinfos ) / sizeof ( Finfo* ),
126  &dinfo
127  );
128 
129  return &stimulusTableCinfo;
130 }
131 
133 // Basic class Definitions
135 
137 
139  : start_( 0 ), stop_( 1 ), loopTime_( 1 ),
140  stepSize_( 0 ), stepPosition_( 0 ),
141  doLoop_( 0 )
142 { ; }
143 
145 // MsgDest Definitions
147 
149 {
150  if ( stepSize_ > 0 )
152  else
153  stepPosition_ = p->currTime;
154 
155  double lookupPosition = stepPosition_;
156  if ( doLoop_ && ( stepPosition_ > start_ + loopTime_ ) ) {
157  unsigned int i = floor( ( stepPosition_ - start_ ) / loopTime_ );
158  lookupPosition = stepPosition_ - loopTime_ * i;
159  }
160 
161  double y = interpolate( start_, stop_, lookupPosition );
162  setOutputValue( y );
163 
164  output()->send( e, y );
165 }
166 
167 void StimulusTable::reinit( const Eref& e, ProcPtr p )
168 {
169  stepPosition_ = 0.0;
170  double y = interpolate( start_, stop_, stepPosition_ );
171  setOutputValue( y );
172  output()->send( e, y );
173 }
174 
176 // Field Definitions
178 
180 {
181  start_ = v;
182 }
183 
185 {
186  return start_;
187 }
188 
190 {
191  if ( doLoop_ && doubleEq( loopTime_, stop_ - start_ ) )
192  loopTime_ = v - start_;
193  stop_ = v;
194 }
195 
197 {
198  return stop_;
199 }
200 
202 {
203  if ( loopTime_ >= 0 )
204  loopTime_ = v;
205  else
206  cout << "StimulusTable::setLoopTime: Warning: Cannot set to " <<
207  v << " as this value is below zero. Left unchanged at " <<
208  loopTime_ << "\n";
209 }
210 
212 {
213  return loopTime_;
214 }
215 
217 {
218  stepSize_ = v;
219 }
220 
222 {
223  return stepSize_;
224 }
225 
227 {
228  stepPosition_ = v;
229 }
230 
232 {
233  return stepPosition_;
234 }
235 
237 {
238  doLoop_ = v;
239  if ( loopTime_ == 0 )
240  loopTime_ = stop_ - start_;
241 }
242 
244 {
245  return doLoop_;
246 }
247 
double getStopTime() const
double currTime
Definition: ProcInfo.h:19
Definition: Dinfo.h:60
bool getDoLoop() const
double interpolate(double x, double xmin, double xmax) const
Definition: TableBase.cpp:440
double stepSize_
Definition: StimulusTable.h:53
double getStartTime() const
void setStopTime(double v)
void setOutputValue(double val)
Definition: TableBase.cpp:428
bool doubleEq(double x, double y)
Definition: doubleEq.cpp:16
void setDoLoop(bool v)
double loopTime_
Definition: StimulusTable.h:52
void setStepPosition(double v)
void setStepSize(double v)
static const Cinfo * initCinfo()
Definition: TableBase.cpp:15
double stepPosition_
Definition: StimulusTable.h:54
Definition: Eref.h:26
static const Cinfo * initCinfo()
void setStartTime(double v)
static const Cinfo * stimulusTableCinfo
static SrcFinfo1< double > * output()
void process(const Eref &e, ProcPtr p)
void setLoopTime(double v)
void reinit(const Eref &e, ProcPtr p)
double getStepPosition() const
double getStepSize() const
double getLoopTime() const
Definition: Cinfo.h:18
Definition: Finfo.h:12