MOOSE - Multiscale Object Oriented Simulation Environment
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
moose::VClamp Class Reference

#include <VClamp.h>

+ Collaboration diagram for moose::VClamp:

Public Member Functions

double getCommand () const
 
double getCurrent () const
 
double getGain () const
 
unsigned int getMode () const
 
double getTau () const
 
double getTd () const
 
double getTi () const
 
double getVin () const
 
void process (const Eref &e, ProcPtr p)
 
void reinit (const Eref &e, ProcPtr p)
 
void setCommand (double v)
 
void setGain (double value)
 
void setMode (unsigned int mode)
 
void setTau (double value)
 
void setTd (double value)
 
void setTi (double value)
 
void setVin (double v)
 
 VClamp ()
 
 ~VClamp ()
 

Static Public Member Functions

static SrcFinfo1< double > * currentOut ()
 
static const CinfoinitCinfo ()
 

Protected Attributes

double cmdIn_
 
double command_
 
double current_
 
double dtByTi_
 
double e1_
 
double e2_
 
double e_
 
double expt_
 
double Kp_
 
unsigned int mode_
 
double oldCmdIn_
 
double tau_
 
double tauByDt_
 
double td_
 
double tdByDt_
 
double ti_
 
double v1_
 
double vIn_
 

Static Private Attributes

static const unsigned DERIVATIVE_ON_PV = 1
 
static const unsigned PROPORTIONAL_ON_PV = 2
 

Detailed Description

Definition at line 51 of file VClamp.h.

Constructor & Destructor Documentation

VClamp::VClamp ( )

Definition at line 196 of file VClamp.cpp.

196  : vIn_(0.0), command_(0.0), current_(0.0), mode_(0), ti_(0.0), td_(-1.0),
197  Kp_(0.0),
198  tau_(0.0),
199  tdByDt_(1.0),
200  dtByTi_(1.0),
201  e_(0.0),
202  e1_(0.0),
203  e2_(0.0)
204 {
205 }
double tau_
Definition: VClamp.h:91
double dtByTi_
Definition: VClamp.h:93
double ti_
Definition: VClamp.h:88
double vIn_
Definition: VClamp.h:82
double e2_
Definition: VClamp.h:97
double command_
Definition: VClamp.h:83
unsigned int mode_
Definition: VClamp.h:85
double tdByDt_
Definition: VClamp.h:92
double e_
Definition: VClamp.h:95
double td_
Definition: VClamp.h:89
double Kp_
Definition: VClamp.h:90
double e1_
Definition: VClamp.h:96
double current_
Definition: VClamp.h:84
VClamp::~VClamp ( )

Definition at line 207 of file VClamp.cpp.

208 {
209  ;
210 }

Member Function Documentation

SrcFinfo1< double > * VClamp::currentOut ( )
static

Definition at line 58 of file VClamp.cpp.

Referenced by initCinfo(), process(), and reinit().

59 {
60  static SrcFinfo1< double > currentOut("currentOut",
61  "Sends out current output of the clamping circuit. This should be"
62  " connected to the `injectMsg` field of a compartment to voltage clamp"
63  " it.");
64  return &currentOut;
65 }
static SrcFinfo1< double > * currentOut()
Definition: VClamp.cpp:58

+ Here is the caller graph for this function:

double VClamp::getCommand ( ) const

Definition at line 217 of file VClamp.cpp.

References cmdIn_.

Referenced by initCinfo().

218 {
219  return cmdIn_;
220 }
double cmdIn_
Definition: VClamp.h:99

+ Here is the caller graph for this function:

double VClamp::getCurrent ( ) const

Definition at line 261 of file VClamp.cpp.

References current_.

Referenced by initCinfo().

262 {
263  return current_;
264 }
double current_
Definition: VClamp.h:84

+ Here is the caller graph for this function:

double VClamp::getGain ( ) const

Definition at line 256 of file VClamp.cpp.

References Kp_.

Referenced by initCinfo().

257 {
258  return Kp_;
259 }
double Kp_
Definition: VClamp.h:90

+ Here is the caller graph for this function:

unsigned int VClamp::getMode ( ) const

Definition at line 282 of file VClamp.cpp.

References mode_.

Referenced by initCinfo().

283 {
284  return mode_;
285 }
unsigned int mode_
Definition: VClamp.h:85

+ Here is the caller graph for this function:

double VClamp::getTau ( ) const

Definition at line 246 of file VClamp.cpp.

References tau_.

Referenced by initCinfo().

247 {
248  return tau_;
249 }
double tau_
Definition: VClamp.h:91

+ Here is the caller graph for this function:

double VClamp::getTd ( ) const

Definition at line 236 of file VClamp.cpp.

References td_.

Referenced by initCinfo().

237 {
238  return td_;
239 }
double td_
Definition: VClamp.h:89

+ Here is the caller graph for this function:

double VClamp::getTi ( ) const

Definition at line 227 of file VClamp.cpp.

References ti_.

Referenced by initCinfo().

228 {
229  return ti_;
230 }
double ti_
Definition: VClamp.h:88

+ Here is the caller graph for this function:

double VClamp::getVin ( ) const

Definition at line 271 of file VClamp.cpp.

References vIn_.

Referenced by initCinfo().

272 {
273  return vIn_;
274 }
double vIn_
Definition: VClamp.h:82

+ Here is the caller graph for this function:

const Cinfo * VClamp::initCinfo ( )
static

Definition at line 68 of file VClamp.cpp.

References currentOut(), getCommand(), getCurrent(), getGain(), getMode(), getTau(), getTd(), getTi(), getVin(), Neutral::initCinfo(), process(), reinit(), setCommand(), setGain(), setMode(), setTau(), setTd(), setTi(), setVin(), and vclampCinfo.

69 {
70  static DestFinfo process("process",
71  "Handles 'process' call on each time step.",
73  static DestFinfo reinit("reinit",
74  "Handles 'reinit' call",
76  static Finfo * processShared[] = {
77  &process,
78  &reinit
79  };
80 
81  static SharedFinfo proc("proc",
82  "Shared message to receive Process messages from the scheduler",
83  processShared, sizeof(processShared) / sizeof(Finfo*));
84 
85  static ValueFinfo< VClamp, double> command("command",
86  "Command input received by the clamp circuit.",
89  static ValueFinfo< VClamp, unsigned int> mode("mode",
90  "Working mode of the PID controller.\n"
91  "\n"
92  " mode = 0, standard PID with proportional, integral and derivative"
93  " all acting on the error.\n"
94  "\n"
95  " mode = 1, derivative action based on command input\n"
96  "\n"
97  " mode = 2, proportional action and derivative action are based on"
98  " command input.",
100  &VClamp::getMode);
101  static ValueFinfo< VClamp, double> ti("ti",
102  "Integration time of the PID controller. Defaults to 1e9, i.e. integral"
103  " action is negligibly small.",
104  &VClamp::setTi,
105  &VClamp::getTi);
106 
107  static ValueFinfo< VClamp, double> td("td",
108  "Derivative time of the PID controller. This defaults to 0,"
109  "i.e. derivative action is unused.",
110  &VClamp::setTd,
111  &VClamp::getTd);
112  static ValueFinfo< VClamp, double> tau("tau",
113  "Time constant of the lowpass filter at input of the PID"
114  " controller. This smooths out abrupt changes in the input. Set it to "
115  " 5 * dt or more to avoid overshoots.",
117  &VClamp::getTau);
118  static ValueFinfo< VClamp, double> gain("gain",
119  "Proportional gain of the PID controller.",
121  &VClamp::getGain);
122  static ReadOnlyValueFinfo< VClamp, double> current("current",
123  "The amount of current injected by the clamp into the membrane.",
125 
126 
127  static ReadOnlyValueFinfo<VClamp, double> sensed("sensed",
128  "Membrane potential read from compartment.",
129  &VClamp::getVin);
130  static DestFinfo sensedIn("sensedIn",
131  "The `VmOut` message of the Compartment object should be connected"
132  " here.",
134 
135  static DestFinfo commandIn("commandIn",
136  " The command voltage source should be connected to this.",
138 
139  static Finfo* vclampFinfos[] = {
140  currentOut(),
141  &command,
142  &current,
143  &sensed,
144  &mode,
145  &ti,
146  &td,
147  &tau,
148  &gain,
149  &sensedIn,
150  &commandIn,
151  &proc
152  };
153 
154  static string doc[] = {
155  "Name", "VClamp",
156  "Author", "Subhasis Ray",
157  "Description", "Voltage clamp object for holding neuronal compartments at a specific"
158  " voltage.\n"
159  "\n"
160  "This implementation uses a builtin RC circuit to filter the "
161  " command input and then use a PID to bring the sensed voltage (Vm from"
162  " compartment) to the filtered command potential.\n"
163  "\n"
164  "Usage: Connect the `currentOut` source of VClamp to `injectMsg`"
165  " dest of Compartment. Connect the `VmOut` source of Compartment to"
166  " `set_sensed` dest of VClamp. Either set `command` field to a"
167  " fixed value, or connect an appropriate source of command potential"
168  " (like the `outputOut` message of an appropriately configured"
169  " PulseGen) to `set_command` dest.\n"
170  "The default settings for the RC filter and PID controller should be"
171  " fine. For step change in command voltage, good defaults with"
172  "integration time step dt are as follows:\n"
173  " time constant of RC filter, tau = 5 * dt\n"
174  " proportional gain of PID, gain = Cm/dt where Cm is the membrane"
175  " capacitance of the compartment\n"
176  " integration time of PID, ti = dt\n"
177  " derivative time of PID, td = 0\n"
178  "\n",
179  };
180 
181  static Dinfo< VClamp > dinfo;
182  static Cinfo vclampCinfo(
183  "VClamp",
185  vclampFinfos,
186  sizeof(vclampFinfos) / sizeof(Finfo*),
187  &dinfo,
188  doc,
189  sizeof(doc)/sizeof(string));
190 
191  return &vclampCinfo;
192 }
void reinit(const Eref &e, ProcPtr p)
Definition: VClamp.cpp:313
unsigned int getMode() const
Definition: VClamp.cpp:282
double getVin() const
Definition: VClamp.cpp:271
void setTau(double value)
Definition: VClamp.cpp:241
static SrcFinfo1< double > * currentOut()
Definition: VClamp.cpp:58
void setVin(double v)
Definition: VClamp.cpp:266
static const Cinfo * vclampCinfo
Definition: VClamp.cpp:194
Definition: Dinfo.h:60
double getTd() const
Definition: VClamp.cpp:236
void setTd(double value)
Definition: VClamp.cpp:231
double getTau() const
Definition: VClamp.cpp:246
void setMode(unsigned int mode)
Definition: VClamp.cpp:277
void setCommand(double v)
Definition: VClamp.cpp:212
Definition: OpFunc.h:27
void setGain(double value)
Definition: VClamp.cpp:251
double getTi() const
Definition: VClamp.cpp:227
void process(const Eref &e, ProcPtr p)
Definition: VClamp.cpp:287
double getCurrent() const
Definition: VClamp.cpp:261
static const Cinfo * initCinfo()
Definition: Neutral.cpp:16
void setTi(double value)
Definition: VClamp.cpp:222
double getCommand() const
Definition: VClamp.cpp:217
Definition: Cinfo.h:18
double getGain() const
Definition: VClamp.cpp:256
Definition: Finfo.h:12

+ Here is the call graph for this function:

void VClamp::process ( const Eref e,
ProcPtr  p 
)

Definition at line 287 of file VClamp.cpp.

References cmdIn_, command_, current_, currentOut(), DERIVATIVE_ON_PV, dtByTi_, e1_, e2_, e_, expt_, Kp_, mode_, oldCmdIn_, PROPORTIONAL_ON_PV, tau_, tauByDt_, td_, tdByDt_, ti_, v1_, and vIn_.

Referenced by initCinfo().

288 {
289  assert(ti_ > 0);
290  assert(td_ >= 0);
291  assert(tau_ > 0);
292  double dCmd = cmdIn_ - oldCmdIn_;
293  command_ = cmdIn_ + dCmd * ( 1 - tauByDt_) + (command_ - cmdIn_ + dCmd * tauByDt_) * expt_;
294  oldCmdIn_ = cmdIn_;
295  e_ = command_ - vIn_;
296  if (mode_ == 0){
297  current_ += Kp_ * ((1 + dtByTi_ + tdByDt_) * e_ - ( 1 + 2 * tdByDt_) * e1_ + tdByDt_ * e2_);
298  e2_ = e1_;
299  e1_ = e_;
300  } else if (mode_ == DERIVATIVE_ON_PV){ // Here the derivative error term is replaced by process variable
301  current_ += Kp_ * ((1 + dtByTi_) * e_ - e1_ + tdByDt_ * ( vIn_ - 2 * v1_ + e2_));
302  e2_ = v1_;
303  v1_ = vIn_;
304  e1_ = e_;
305  } else if (mode_ == PROPORTIONAL_ON_PV){ // Here the proportional as well as the derivative error term is replaced by process variable
306  current_ += Kp_ * (vIn_ - v1_ + dtByTi_ * e_ + tdByDt_ * ( vIn_ - 2 * v1_ + e2_));
307  e2_ = v1_;
308  v1_ = vIn_;
309  }
310  currentOut()->send(e, current_);
311 }
static SrcFinfo1< double > * currentOut()
Definition: VClamp.cpp:58
double tau_
Definition: VClamp.h:91
double dtByTi_
Definition: VClamp.h:93
double ti_
Definition: VClamp.h:88
double vIn_
Definition: VClamp.h:82
double tauByDt_
Definition: VClamp.h:94
double e2_
Definition: VClamp.h:97
static const unsigned DERIVATIVE_ON_PV
Definition: VClamp.h:53
double command_
Definition: VClamp.h:83
unsigned int mode_
Definition: VClamp.h:85
double oldCmdIn_
Definition: VClamp.h:100
double v1_
Definition: VClamp.h:98
double tdByDt_
Definition: VClamp.h:92
double e_
Definition: VClamp.h:95
double td_
Definition: VClamp.h:89
double Kp_
Definition: VClamp.h:90
double expt_
Definition: VClamp.h:101
double cmdIn_
Definition: VClamp.h:99
double e1_
Definition: VClamp.h:96
double current_
Definition: VClamp.h:84
static const unsigned PROPORTIONAL_ON_PV
Definition: VClamp.h:54

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void VClamp::reinit ( const Eref e,
ProcPtr  p 
)

Definition at line 313 of file VClamp.cpp.

References cmdIn_, command_, currentOut(), ProcInfo::dt, dtByTi_, e1_, e2_, e_, Eref::element(), expt_, Field< A >::get(), Element::getNeighbors(), Kp_, oldCmdIn_, tau_, tauByDt_, td_, tdByDt_, ti_, v1_, and vIn_.

Referenced by initCinfo().

314 {
315 
316  vIn_ = 0.0;
317  v1_ = 0;
318  command_ = cmdIn_ = oldCmdIn_ = e_ = e1_ = e2_ = 0;
319  if (ti_ == 0){
320  ti_ = p->dt;
321  }
322  if (td_ < 0){
323  td_ = 0.0;
324  }
325  if (tau_ == 0.0){
326  tau_ = 5 * p->dt;
327  }
328  if (p->dt / tau_ > 1e-15){
329  expt_ = exp(-p->dt/tau_);
330  } else {
331  expt_ = 1 - p->dt/tau_;
332  }
333  tauByDt_ = tau_ / p->dt;
334  dtByTi_ = p->dt/ti_;
335  tdByDt_ = td_ / p->dt;
336 
337  vector<Id> compartments;
338  unsigned int numComp = e.element()->getNeighbors(compartments, currentOut());
339  if (numComp > 0){
340  double Cm = Field<double>::get(compartments[0], "Cm");
341  if (Kp_ == 0){
342  Kp_ = Cm / p->dt;
343  }
344  command_ = cmdIn_ = oldCmdIn_ =
345  Field<double>::get(compartments[0], "initVm");
346  }
347 }
static SrcFinfo1< double > * currentOut()
Definition: VClamp.cpp:58
double tau_
Definition: VClamp.h:91
double dtByTi_
Definition: VClamp.h:93
double ti_
Definition: VClamp.h:88
Element * element() const
Definition: Eref.h:42
double vIn_
Definition: VClamp.h:82
double tauByDt_
Definition: VClamp.h:94
double e2_
Definition: VClamp.h:97
double command_
Definition: VClamp.h:83
double dt
Definition: ProcInfo.h:18
double oldCmdIn_
Definition: VClamp.h:100
double v1_
Definition: VClamp.h:98
double tdByDt_
Definition: VClamp.h:92
double e_
Definition: VClamp.h:95
double td_
Definition: VClamp.h:89
double Kp_
Definition: VClamp.h:90
double expt_
Definition: VClamp.h:101
double cmdIn_
Definition: VClamp.h:99
unsigned int getNeighbors(vector< Id > &ret, const Finfo *finfo) const
Definition: Element.cpp:949
double e1_
Definition: VClamp.h:96
static A get(const ObjId &dest, const string &field)
Definition: SetGet.h:284

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

void VClamp::setCommand ( double  v)

Definition at line 212 of file VClamp.cpp.

References cmdIn_, and value.

Referenced by initCinfo().

213 {
214  cmdIn_ = value;
215 }
uint32_t value
Definition: moosemodule.h:42
double cmdIn_
Definition: VClamp.h:99

+ Here is the caller graph for this function:

void VClamp::setGain ( double  value)

Definition at line 251 of file VClamp.cpp.

References Kp_, and value.

Referenced by initCinfo().

252 {
253  Kp_ = value;
254 }
uint32_t value
Definition: moosemodule.h:42
double Kp_
Definition: VClamp.h:90

+ Here is the caller graph for this function:

void VClamp::setMode ( unsigned int  mode)

Definition at line 277 of file VClamp.cpp.

References mode_.

Referenced by initCinfo().

278 {
279  mode_ = mode;
280 }
unsigned int mode_
Definition: VClamp.h:85

+ Here is the caller graph for this function:

void VClamp::setTau ( double  value)

Definition at line 241 of file VClamp.cpp.

References tau_, and value.

Referenced by initCinfo().

242 {
243  tau_ = value;
244 }
uint32_t value
Definition: moosemodule.h:42
double tau_
Definition: VClamp.h:91

+ Here is the caller graph for this function:

void VClamp::setTd ( double  value)

Definition at line 231 of file VClamp.cpp.

References td_, and value.

Referenced by initCinfo().

232 {
233  td_ = value;
234 }
uint32_t value
Definition: moosemodule.h:42
double td_
Definition: VClamp.h:89

+ Here is the caller graph for this function:

void VClamp::setTi ( double  value)

Definition at line 222 of file VClamp.cpp.

References ti_, and value.

Referenced by initCinfo().

223 {
224  ti_ = value;
225 }
uint32_t value
Definition: moosemodule.h:42
double ti_
Definition: VClamp.h:88

+ Here is the caller graph for this function:

void VClamp::setVin ( double  v)

Definition at line 266 of file VClamp.cpp.

References value, and vIn_.

Referenced by initCinfo().

267 {
268  vIn_ = value;
269 }
uint32_t value
Definition: moosemodule.h:42
double vIn_
Definition: VClamp.h:82

+ Here is the caller graph for this function:

Member Data Documentation

double moose::VClamp::cmdIn_
protected

Definition at line 99 of file VClamp.h.

Referenced by getCommand(), process(), reinit(), and setCommand().

double moose::VClamp::command_
protected

Definition at line 83 of file VClamp.h.

Referenced by process(), and reinit().

double moose::VClamp::current_
protected

Definition at line 84 of file VClamp.h.

Referenced by getCurrent(), and process().

const unsigned int VClamp::DERIVATIVE_ON_PV = 1
staticprivate

Definition at line 53 of file VClamp.h.

Referenced by process().

double moose::VClamp::dtByTi_
protected

Definition at line 93 of file VClamp.h.

Referenced by process(), and reinit().

double moose::VClamp::e1_
protected

Definition at line 96 of file VClamp.h.

Referenced by process(), and reinit().

double moose::VClamp::e2_
protected

Definition at line 97 of file VClamp.h.

Referenced by process(), and reinit().

double moose::VClamp::e_
protected

Definition at line 95 of file VClamp.h.

Referenced by process(), and reinit().

double moose::VClamp::expt_
protected

Definition at line 101 of file VClamp.h.

Referenced by process(), and reinit().

double moose::VClamp::Kp_
protected

Definition at line 90 of file VClamp.h.

Referenced by getGain(), process(), reinit(), and setGain().

unsigned int moose::VClamp::mode_
protected

Definition at line 85 of file VClamp.h.

Referenced by getMode(), process(), and setMode().

double moose::VClamp::oldCmdIn_
protected

Definition at line 100 of file VClamp.h.

Referenced by process(), and reinit().

const unsigned int VClamp::PROPORTIONAL_ON_PV = 2
staticprivate

Definition at line 54 of file VClamp.h.

Referenced by process().

double moose::VClamp::tau_
protected

Definition at line 91 of file VClamp.h.

Referenced by getTau(), process(), reinit(), and setTau().

double moose::VClamp::tauByDt_
protected

Definition at line 94 of file VClamp.h.

Referenced by process(), and reinit().

double moose::VClamp::td_
protected

Definition at line 89 of file VClamp.h.

Referenced by getTd(), process(), reinit(), and setTd().

double moose::VClamp::tdByDt_
protected

Definition at line 92 of file VClamp.h.

Referenced by process(), and reinit().

double moose::VClamp::ti_
protected

Definition at line 88 of file VClamp.h.

Referenced by getTi(), process(), reinit(), and setTi().

double moose::VClamp::v1_
protected

Definition at line 98 of file VClamp.h.

Referenced by process(), and reinit().

double moose::VClamp::vIn_
protected

Definition at line 82 of file VClamp.h.

Referenced by getVin(), process(), reinit(), and setVin().


The documentation for this class was generated from the following files: