MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
DiffAmp.cpp
Go to the documentation of this file.
1 // DiffAmp.cpp ---
2 //
3 // Filename: DiffAmp.cpp
4 // Description:
5 // Author: subhasis ray
6 // Maintainer:
7 // Created: Mon Dec 29 16:01:22 2008 (+0530)
8 // Version:
9 // Last-Updated: Tue Jun 11 17:00:33 2013 (+0530)
10 // By: subha
11 // Update #: 290
12 // URL:
13 // Keywords:
14 // Compatibility:
15 //
16 //
17 
18 // Commentary:
19 // This implements an equivalent of the diffamp object in GENESIS.
20 //
21 //
22 //
23 
24 // Change log:
25 // 2008-12-30 16:21:19 (+0530) - Initial version.
26 // 2012-02-22 03:05:40 (+0530) - Ported to dh_branch
27 //
28 /**********************************************************************
29  ** This program is part of 'MOOSE', the
30  ** Messaging Object Oriented Simulation Environment,
31  ** also known as GENESIS 3 base code.
32  ** copyright (C) 2003-2013 Upinder S. Bhalla. and NCBS
33  ** It is made available under the terms of the
34  ** GNU Lesser General Public License version 2.1
35  ** See the file COPYING.LIB for the full notice.
36  **********************************************************************/
37 
38 // Code:
39 
40 #include <cfloat>
41 
42 #include "DiffAmp.h"
43 
45 {
46  static SrcFinfo1< double > outputOut( "output",
47  "Current output level.");
48  return &outputOut;
49 }
50 
52 {
53  static ValueFinfo<DiffAmp, double> gain( "gain",
54  "Gain of the amplifier. The output of the amplifier is the difference"
55  " between the totals in plus and minus inputs multiplied by the"
56  " gain. Defaults to 1" ,
59  static ValueFinfo<DiffAmp, double > saturation( "saturation",
60  "Saturation is the bound on the output. If output goes beyond the +/-"
61  "saturation range, it is truncated to the closer of +saturation and"
62  " -saturation. Defaults to the maximum double precision floating point"
63  " number representable on the system." ,
66 
67  static ReadOnlyValueFinfo<DiffAmp, double> output( "outputValue",
68  "Output of the amplifier, i.e. gain * (plus - minus)." ,
71  // Dest messages
73 
74  static DestFinfo gainIn( "gainIn",
75  "Destination message to control gain dynamically.",
77 
78  static DestFinfo plusIn( "plusIn",
79  "Positive input terminal of the amplifier. All the messages connected"
80  " here are summed up to get total positive input.",
82 
83  static DestFinfo minusIn( "minusIn",
84  "Negative input terminal of the amplifier. All the messages connected"
85  " here are summed up to get total positive input.",
88  // Shared messages
90  static DestFinfo process( "process",
91  "Handles process call, updates internal time stamp.",
93  static DestFinfo reinit( "reinit",
94  "Handles reinit call.",
96  static Finfo* processShared[] =
97  {
98  &process, &reinit
99  };
100 
101  static SharedFinfo proc( "proc",
102  "This is a shared message to receive Process messages "
103  "from the scheduler objects."
104  "The first entry in the shared msg is a MsgDest "
105  "for the Process operation. It has a single argument, "
106  "ProcInfo, which holds lots of information about current "
107  "time, thread, dt and so on. The second entry is a MsgDest "
108  "for the Reinit operation. It also uses ProcInfo. ",
109  processShared, sizeof( processShared ) / sizeof( Finfo* )
110  );
111 
112 
113  static Finfo * diffAmpFinfos[] = {
114  &gain,
115  &saturation,
116  &output,
117  &gainIn,
118  &plusIn,
119  &minusIn,
120  outputOut(),
121  &proc
122  };
123  static string doc[] = {
124  "Name", "DiffAmp",
125  "Author", "Subhasis Ray, 2008, NCBS",
126  "Description", "A difference amplifier. "
127  "Output is the difference between the total plus inputs and the total "
128  "minus inputs multiplied by gain. Gain can be set statically as a field"
129  " or can be a destination message and thus dynamically determined by the"
130  " output of another object. Same as GENESIS diffamp object."
131  };
132  static Dinfo<DiffAmp> dinfo;
133  static Cinfo diffAmpCinfo(
134  "DiffAmp",
136  diffAmpFinfos,
137  sizeof(diffAmpFinfos)/sizeof(Finfo*),
138  &dinfo,
139  doc,
140  sizeof(doc)/sizeof(string)
141 );
142 
143  return &diffAmpCinfo;
144 }
145 
147 DiffAmp::DiffAmp():gain_(1.0), saturation_(DBL_MAX), plus_(0), minus_(0), output_(0)
148 {
149 }
151  ;
152 }
153 void DiffAmp::plusFunc(double input)
154 {
155  plus_ += input;
156 }
157 
158 void DiffAmp::minusFunc(double input)
159 {
160  minus_ += input;
161 }
162 
163 void DiffAmp::setGain(double gain)
164 {
165  gain_ = gain;
166 }
167 
168 void DiffAmp::setSaturation(double saturation)
169 {
170  saturation_ = saturation;
171 }
172 
173 double DiffAmp::getGain() const
174 {
175  return gain_;
176 }
177 
179 {
180  return saturation_;
181 }
182 
183 double DiffAmp::getOutput() const
184 {
185  return output_;
186 }
187 
188 void DiffAmp::process(const Eref& e, ProcPtr p)
189 {
190  double output = gain_ * (plus_ - minus_);
191  plus_ = 0.0;
192  minus_ = 0.0;
193  if ( output > saturation_ ) {
194  output = saturation_;
195  }
196  if ( output < -saturation_ ) {
197  output = -saturation_;
198  }
199  output_ = output;
200  outputOut()->send(e, output_);
201 }
202 
203 void DiffAmp::reinit(const Eref& e, ProcPtr p)
204 {
205  // What is the right thing to do?? Should we actually do a process step??
206  output_ = 0.0;
207  plus_ = 0.0;
208  minus_ = 0.0;
209  outputOut()->send(e, output_);
210 }
211 
212 //
213 // DiffAmp.cpp ends here
DiffAmp()
Definition: DiffAmp.cpp:147
double output_
Definition: DiffAmp.h:58
double minus_
Definition: DiffAmp.h:57
double gain_
Definition: DiffAmp.h:54
void minusFunc(double input)
Definition: DiffAmp.cpp:158
double saturation_
Definition: DiffAmp.h:55
double getGain() const
Definition: DiffAmp.cpp:173
Definition: Dinfo.h:60
void process(const Eref &e, ProcPtr p)
Definition: DiffAmp.cpp:188
void setGain(double gain)
Definition: DiffAmp.cpp:163
double plus_
Definition: DiffAmp.h:56
static SrcFinfo1< double > * output()
Definition: Arith.cpp:14
void plusFunc(double input)
Definition: DiffAmp.cpp:153
~DiffAmp()
Definition: DiffAmp.cpp:150
Definition: OpFunc.h:27
Definition: Eref.h:26
static const Cinfo * diffAmpCinfo
Definition: DiffAmp.cpp:146
double getOutput() const
Definition: DiffAmp.cpp:183
static const Cinfo * initCinfo()
Definition: Neutral.cpp:16
void reinit(const Eref &e, ProcPtr p)
Definition: DiffAmp.cpp:203
void setSaturation(double saturation)
Definition: DiffAmp.cpp:168
static const Cinfo * initCinfo()
Definition: DiffAmp.cpp:51
static SrcFinfo1< double > * outputOut()
Definition: DiffAmp.cpp:44
Definition: Cinfo.h:18
double getSaturation() const
Definition: DiffAmp.cpp:178
Definition: Finfo.h:12