9
9
#include " dendrite.h"
10
10
using std::endl;
11
11
12
+ /* *
13
+ @brief Computes the derivatives of the dendritic response function.
14
+
15
+ The dendritic response function is given by:
16
+ \f{eqnarray*}{
17
+ \frac{dv}{dt}&=&W \\
18
+ \frac{dW}{dt}&=&\left(\nu\phi - V - \left(\frac{1}{\alpha} + \frac{1}{\beta}\right) W\right) \alpha \beta \\
19
+ \frac{d\nu\phi}{dt}&=&0
20
+ \f}
21
+ */
22
+ void Dendrite::DendriteDE::rhs ( const vector<double >& y, vector<double >& dydt ) {
23
+ // y = {V,W==dv/dt,nuphi}
24
+ // dydt = {dv/dt==W, dW/dt==d^2V/dt^2,dnuphi/dt} d(nuphi)/dt from precouple
25
+ dydt[0 ] = y[1 ];
26
+
27
+ dydt[1 ] = (y[2 ] - y[0 ] - factorab * y[1 ]) * alphaxbeta;
28
+
29
+ dydt[2 ] = 0.0 ;
30
+ }
31
+
12
32
void Dendrite::init ( Configf& configf ) {
13
33
if ( !configf.next ( label (" Dendrite " ,index+1 ) )) {
14
34
std::cerr<<" Dendrite " <<index+1 <<" not found." <<endl;
@@ -23,51 +43,53 @@ void Dendrite::init( Configf& configf ) {
23
43
} else {
24
44
v.resize (nodes,atof (buffer.c_str ()));
25
45
}
26
- oldnp = v;
46
+
27
47
configf.param (" alpha" ,alpha);
28
48
configf.param (" beta" ,beta);
29
49
30
- aminusb = alpha - beta;
31
- expa = exp (-alpha*deltat);
32
- expb = exp (-beta*deltat);
50
+ // Initialize constant factors to speed up computation.
33
51
factorab = 1 ./alpha + 1 ./beta;
52
+ alphaxbeta = alpha * beta;
53
+
54
+ de->init (v[0 ]); // call Dendrite::DendriteDE::init
55
+ de->factorab = factorab;
56
+ de->alphaxbeta = alphaxbeta;
57
+ }
58
+
59
+ void Dendrite::DendriteDE::init (const double vinit) {
60
+ variables[0 ].clear ();
61
+ variables[1 ].clear ();
62
+ variables[2 ].clear ();
63
+ variables[0 ].resize (nodes, vinit);
64
+ variables[1 ].resize (nodes, 0.0 );
65
+ variables[2 ].resize (nodes, 0.0 );
34
66
}
35
67
36
68
Dendrite::Dendrite ( size_type nodes, double deltat, size_type index,
37
69
const Propagator& prepropag, const Coupling& precouple )
38
- : NF(nodes,deltat,index), v(nodes), dvdt(nodes,0 ), oldnp(nodes),
39
- prepropag(prepropag), precouple(precouple) {
70
+ : NF(nodes,deltat,index), v(nodes), prepropag(prepropag), precouple(precouple) {
71
+ de = new DendriteDE (nodes, deltat);
72
+ rk4 = new RK4 (*de);
40
73
}
41
74
42
- Dendrite::~Dendrite () = default ;
75
+ Dendrite::~Dendrite () {
76
+ delete de;
77
+ delete rk4;
78
+ }
43
79
44
80
void Dendrite::step () {
45
- // assume that alpha, beta are constant and nu*phi is linear for the time step
46
- if (alpha!=beta) {
47
- for (size_type i=0 ; i<nodes; i++) {
48
- dpdt = ( precouple[i] -oldnp[i] )/deltat;
49
- adjustednp = oldnp[i] -factorab*dpdt -v[i];
50
- C1 = ( adjustednp*beta -dvdt[i] +dpdt )/aminusb;
51
- C1expa = C1*expa;
52
- C2expb = expb*(-C1-adjustednp);
53
- v[i] = C1expa+C2expb+precouple[i] -factorab*dpdt;
54
- dvdt[i] = C1expa*(-alpha) +C2expb*(-beta)+dpdt;
55
- oldnp[i]=precouple[i]; // Save current pulse density for next step
56
- }
57
- } else { // alpha==beta
58
- for (size_type i=0 ; i<nodes; i++) {
59
- dpdt = ( precouple[i] -oldnp[i] )/deltat;
60
- adjustednp = oldnp[i] -factorab*dpdt -v[i];
61
- C1 = dvdt[i] -alpha*adjustednp -dpdt;
62
- C1dtplusC2 = C1*deltat -adjustednp;
63
- v[i] = C1dtplusC2*expa +precouple[i] -factorab*dpdt;
64
- dvdt[i] = (C1-alpha*C1dtplusC2)*expa +dpdt;
65
- oldnp[i]=precouple[i]; // Save current pulse density for next step
66
- }
81
+ // Copy the \nu\phi into their corresponding variable in the DE.
82
+ for ( size_type i=0 ; i<nodes; i++ ) {
83
+ (*de)[2 ][i] = precouple[i]; // \nu\phi
84
+ }
85
+ // Integrate the dendritic response one step forward in time.
86
+ rk4->step ();
87
+ // Copy the voltages from the updated DE to the local variable v.
88
+ for ( size_type i=0 ; i<nodes; i++ ) {
89
+ v[i] = (*de)[0 ][i]; // Voltage
67
90
}
68
91
}
69
92
70
-
71
93
void Dendrite::output ( Output& output ) const {
72
94
output (" Dendrite" ,index+1 ," V" ,v);
73
95
}
0 commit comments