MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
RC.cpp
Go to the documentation of this file.
1 // RC.cpp ---
2 //
3 // Filename: RC.cpp
4 // Description:
5 // Author: subhasis ray
6 // Maintainer:
7 // Created: Wed Dec 31 15:47:45 2008 (+0530)
8 // Version:
9 // Last-Updated: Tue Jun 11 17:01:03 2013 (+0530)
10 // By: subha
11 // Update #: 247
12 // URL:
13 // Keywords:
14 // Compatibility:
15 //
16 //
17 
18 // Commentary:
19 //
20 //
21 //
22 //
23 
24 // Change log:
25 //
26 //
27 //
28 //
29 /**********************************************************************
30 ** This program is part of 'MOOSE', the
31 ** Messaging Object Oriented Simulation Environment,
32 ** also known as GENESIS 3 base code.
33 ** copyright (C) 2003-2013 Upinder S. Bhalla. and NCBS
34 ** It is made available under the terms of the
35 ** GNU Lesser General Public License version 2.1
36 ** See the file COPYING.LIB for the full notice.
37 **********************************************************************/
38 
39 // Code:
40 
41 #include "RC.h"
42 
44 {
45  static SrcFinfo1< double > outputOut( "output",
46  "Current output level.");
47  return &outputOut;
48 }
49 
51 {
52  static DestFinfo process("process",
53  "Handles process call.",
55  static DestFinfo reinit( "reinit",
56  "Handle reinitialization",
57  new ProcOpFunc<RC>( &RC::reinit ));
58  static Finfo* processShared[] = {
59  &process, &reinit
60  };
61  static SharedFinfo proc("proc",
62  "This is a shared message to receive Process messages "
63  "from the scheduler objects."
64  "The first entry in the shared msg is a MsgDest "
65  "for the Process operation. It has a single argument, "
66  "ProcInfo, which holds lots of information about current "
67  "time, thread, dt and so on. The second entry is a MsgDest "
68  "for the Reinit operation. It also uses ProcInfo. ",
69  processShared,
70  sizeof( processShared ) / sizeof( Finfo* ));
71  static ValueFinfo<RC, double> V0( "V0",
72  "Initial value of 'state'",
73  &RC::setV0,
74  &RC::getV0 );
75  static ValueFinfo<RC, double> R( "R",
76  "Series resistance of the RC circuit.",
79  static ValueFinfo<RC, double> C( "C",
80  "Parallel capacitance of the RC circuit.",
83  static ReadOnlyValueFinfo<RC, double> state("state",
84  "Output value of the RC circuit. This is the voltage across the"
85  " capacitor.",
86  &RC::getState);
87  static ValueFinfo<RC, double> inject( "inject",
88  "Input value to the RC circuit.This is handled as an input current to"
89  " the circuit.",
91  &RC::getInject );
92  static DestFinfo injectIn( "injectIn",
93  "Receives input to the RC circuit. All incoming messages are summed up"
94  " to give the total input current." ,
96  static Finfo* rcFinfos[] = {
97  &V0,
98  &R,
99  &C,
100  &state,
101  &inject,
102  outputOut(),
103  &injectIn,
104  &proc,
105  };
106  static string doc[] = {
107  "Name", "RC",
108  "Author", "Subhasis Ray, 2008, NCBS",
109  "Description", "RC circuit: a series resistance R shunted by a capacitance C." };
110  static Dinfo<RC> dinfo;
111  static Cinfo rcCinfo("RC",
113  rcFinfos,
114  sizeof( rcFinfos ) / sizeof( Finfo* ),
115  &dinfo,
116  doc,
117  sizeof(doc)/sizeof(string)
118  );
119  return &rcCinfo;
120 }
121 
122 static const Cinfo* rcCinfo = RC::initCinfo();
123 
124 
126  v0_(0),
127  resistance_(1.0),
128  capacitance_(1.0),
129  state_(0),
130  inject_(0),
131  msg_inject_(0.0),
132  expTau_(0.0),
133  dt_tau_(0.0)
134 {
135  ; // Do nothing
136 }
137 
138 void RC::setV0( double v0 )
139 {
140 
141  v0_ = v0;
142 }
143 
144 double RC::getV0() const
145 {
146 
147  return v0_;
148 }
149 
150 void RC::setResistance( double resistance )
151 {
152 
153  resistance_ = resistance;
154 }
155 
156 double RC::getResistance( ) const
157 {
158 
159  return resistance_;
160 }
161 
162 void RC::setCapacitance( double capacitance )
163 {
164 
165  capacitance_ = capacitance;
166 }
167 
168 double RC::getCapacitance() const
169 {
170 
171  return capacitance_;
172 }
173 
174 double RC::getState() const
175 {
176 
177  return state_;
178 }
179 
180 void RC::setInject( double inject )
181 {
182 
183  inject_ = inject;
184 }
185 
186 double RC::getInject() const
187 {
188 
189  return inject_;
190 }
191 
192 void RC::setInjectMsg( double inject )
193 {
194 
195  msg_inject_ += inject;
196 }
197 
204 void RC::process(const Eref& e, const ProcPtr proc )
205 {
206  /*
207  double sum_inject_prev = inject_ + msg_inject_;
208  double sum_inject = inject_ + msg_inject_;
209  double dVin = (sum_inject - sum_inject_prev) * resistance_;
210  double Vin = sum_inject * resistance_;
211  state_ = Vin + dVin - dVin / dt_tau_ +
212  (state_ - Vin + dVin / dt_tau_) * expTau_;
213  sum_inject_prev = sum_inject;
214  msg_inject_ = 0.0;
215  outputOut()->send(e, state_);
216  */
217 
219  // double A = inject + msgInject_;
220  // double B = 1.0/resistance_;
221  // double x = exp( -B * proc->dt / capacitance_ );
222  // state_ = state_ * x + (A/B) * (1.0-x);
223  // double x = exp( -dt_tau_ );
224  state_ = state_ * expTau_ +
226 
228  // state_ += (inject_ + msgInject_ - state_/resistance_ ) * proc->dt / capacitance_;
229 
230  msg_inject_ = 0.0;
231  outputOut()->send(e, state_);
232 }
233 
234 void RC::reinit(const Eref& e, const ProcPtr proc)
235 {
236 
237  dt_tau_ = proc->dt / (resistance_ * capacitance_);
238  state_ = v0_;
239  if (dt_tau_ > 1e-15){
240  expTau_ = exp(-dt_tau_);
241  } else {// use approximation
242  expTau_ = 1 - dt_tau_;
243  }
244  msg_inject_ = 0.0;
245  outputOut()->send(e, state_);
246 }
247 
248 
249 //
250 // RC.cpp ends here
double inject_
Definition: RC.h:67
void process(const Eref &e, ProcPtr proc)
Definition: RC.cpp:204
double resistance_
Definition: RC.h:64
double getInject() const
Definition: RC.cpp:186
void setResistance(double resistance)
Definition: RC.cpp:150
void reinit(const Eref &e, ProcPtr proc)
Definition: RC.cpp:234
double getState() const
Definition: RC.cpp:174
Definition: Dinfo.h:60
void setInjectMsg(double inject)
Definition: RC.cpp:192
double getV0() const
Definition: RC.cpp:144
double capacitance_
Definition: RC.h:65
double getResistance() const
Definition: RC.cpp:156
double state_
Definition: RC.h:66
double dt
Definition: ProcInfo.h:18
Definition: OpFunc.h:27
Definition: Eref.h:26
void setCapacitance(double capacitance)
Definition: RC.cpp:162
double expTau_
Definition: RC.h:69
static const Cinfo * rcCinfo
Definition: RC.cpp:122
static SrcFinfo1< double > * outputOut()
Definition: RC.cpp:43
double v0_
Definition: RC.h:63
double msg_inject_
Definition: RC.h:68
void setInject(double inject)
Definition: RC.cpp:180
RC()
Definition: RC.cpp:125
static const Cinfo * initCinfo()
Definition: Neutral.cpp:16
void setV0(double voltage)
Definition: RC.cpp:138
double getCapacitance() const
Definition: RC.cpp:168
Definition: Cinfo.h:18
double dt_tau_
Definition: RC.h:70
static const Cinfo * initCinfo()
Definition: RC.cpp:50
Definition: Finfo.h:12