NEURON
cvodestb.cpp
Go to the documentation of this file.
1 #include <../../nrnconf.h>
2 // solver CVode stub to allow cvode as dll for mswindows version.
3 
4 #include <InterViews/resource.h>
5 #include "classreg.h"
6 #include "nrnoc2iv.h"
7 #include "datapath.h"
8 #if USECVODE
9 #include "cvodeobj.h"
10 #include "netcvode.h"
11 #else
12 class Cvode;
13 #endif
14 
15 extern "C" void cvode_fadvance(double);
16 void cvode_finitialize(double t0);
17 void nrncvode_set_t(double);
18 extern "C" bool at_time(NrnThread*, double);
19 
20 extern double dt, t;
21 #define nt_t nrn_threads->_t
22 #define nt_dt nrn_threads->_dt
23 extern "C" void nrn_random_play();
24 extern int cvode_active_;
25 extern int nrn_use_daspk_;
26 
30 extern "C" void clear_event_queue();
31 void init_net_events();
32 void nrn_record_init();
33 void nrn_play_init();
36 void nrn_solver_prepare();
37 static void check_thresh(NrnThread*);
38 
39 // for fixed step thread
41  int i;
42  if (net_cvode_instance) {
43  net_cvode_instance->check_thresh(nt);
44  net_cvode_instance->deliver_net_events(nt);
45  }
46 }
47 
48 // handle events during finitialize()
50  double tsav = nt->_t;
51  if (net_cvode_instance) {
52  net_cvode_instance->deliver_events(tsav, nt);
53  }
54  nt->_t = tsav;
55 }
56 
57 extern "C" void clear_event_queue() {
58  if (net_cvode_instance) {
59  net_cvode_instance->clear_events();
60  }
61 }
62 
64  if (net_cvode_instance) {
65  net_cvode_instance->init_events();
66  }
67 }
68 
70  if (net_cvode_instance) {
71  net_cvode_instance->record_init();
72  }
73 }
74 
75 void nrn_play_init() {
76  if (net_cvode_instance) {
77  net_cvode_instance->play_init();
78  }
79 }
80 
82  if (net_cvode_instance) {
83  net_cvode_instance->fixed_play_continuous(nt);
84  }
85 }
86 
88  if (net_cvode_instance) {
89  net_cvode_instance->fixed_record_continuous(nt);
90  }
91 }
92 
94  if (net_cvode_instance) {
95  net_cvode_instance->solver_prepare();
96  }
97 }
98 
99 extern "C" int v_structure_change;
100 
101 extern "C" void cvode_fadvance(double tstop) { // tstop = -1 means single step
102 #if USECVODE
103  int err;
104  extern int tree_changed;
105  extern int diam_changed;
106  if (net_cvode_instance) {
107  if (tree_changed || v_structure_change || diam_changed) {
108  net_cvode_instance->re_init();
109  }
110  nrn_random_play();
111  err = net_cvode_instance->solve(tstop);
112  if (err != 0) {
113  printf("err=%d\n", err);
114  hoc_execerror("variable step integrator error", 0);
115  }
116  t = nt_t;
117  dt = nt_dt;
118  }
119 #endif
120 }
121 
122 void cvode_finitialize(double t0){
123 #if USECVODE
124  if (net_cvode_instance) {
125  net_cvode_instance->re_init(t0);
126  }
127 #endif
128 }
129 
130 extern "C" bool at_time(NrnThread* nt, double te) {
131 #if USECVODE
132  if (cvode_active_ && nt->_vcv) {
133  return ((Cvode*)nt->_vcv)->at_time(te, nt);
134  }
135 #endif
136  double x = te - 1e-11;
137  if (x <= nt->_t && x > (nt->_t - nt->_dt)) {
138  return 1;
139  }
140  return 0;
141 }
142 
143 void nrncvode_set_t(double tt) {
145  if (nc->gcv_) {
146  Cvode& cv = *nc->gcv_;
147  cv.tn_ = cv.t_ = cv.t0_ = tt;
148  }else{
149  for (int i=0; i < nc->pcnt_; ++i) {
150  NetCvodeThreadData& p = nc->p[i];
151  for (int j=0; j < p.nlcv_; ++j) {
152  Cvode& cv = p.lcv_[j];
153  cv.tn_ = cv.t_ = cv.t0_ = tt;
154  }
155  }
156  }
157 }
void clear_event_queue()
Definition: cvodestb.cpp:57
void deliver_events(double til, NrnThread *)
Definition: netcvode.cpp:2978
#define nt_dt
Definition: cvodestb.cpp:22
int tree_changed
Definition: cabcode.cpp:19
void re_init(double t0=0.)
Definition: netcvode.cpp:3968
NetCvode * net_cvode_instance
Definition: cvodestb.cpp:27
size_t p
Represent main neuron object computed by single thread.
Definition: multicore.h:58
virtual double t0()
Definition: cvodeobj.h:86
int diam_changed
Definition: cabcode.cpp:23
void solver_prepare()
Definition: netcvode.cpp:3935
int cvode_active_
Definition: fadvance.cpp:158
#define e
Definition: passive0.cpp:24
void cvode_finitialize(double t0)
Definition: cvodestb.cpp:122
void init_events()
Definition: netcvode.cpp:2868
double _dt
Definition: multicore.h:60
void play_init()
Definition: netcvode.cpp:4142
void nrn_record_init()
Definition: cvodestb.cpp:69
void record_init()
Definition: netcvode.cpp:4124
double t_
Definition: cvodeobj.h:97
#define printf
Definition: mwprefix.h:26
void nrn_solver_prepare()
Definition: cvodestb.cpp:93
void init_net_events()
Definition: cvodestb.cpp:63
void clear_events()
Definition: netcvode.cpp:2791
void check_thresh(NrnThread *)
Definition: netcvode.cpp:5857
void hoc_execerror(const char *, const char *)
Definition: hoc.cpp:741
void fixed_record_continuous(NrnThread *nt)
Definition: cvodestb.cpp:87
void nrncvode_set_t(double)
Definition: cvodestb.cpp:143
double t0_
Definition: cvodeobj.h:97
double t
Definition: init.cpp:123
MUTDEC int nlcv_
Definition: netcvode.h:55
size_t j
int v_structure_change
Definition: cvodestb.cpp:99
NetCvodeThreadData * p
Definition: netcvode.h:211
void fixed_play_continuous(NrnThread *nt)
Definition: cvodestb.cpp:81
bool at_time(NrnThread *, double)
Definition: cvodestb.cpp:130
#define nt_t
Definition: cvodestb.cpp:21
void deliver_net_events(NrnThread *)
Definition: netcvode.cpp:5902
static void check_thresh(NrnThread *)
Cvode * gcv_
Definition: netcvode.h:205
double _t
Definition: multicore.h:59
void nrn_random_play()
Definition: ivocrand.cpp:598
int pcnt_
Definition: netcvode.h:210
void nrn_deliver_events(NrnThread *)
Definition: cvodestb.cpp:49
Definition: cvodeobj.h:75
void fixed_play_continuous(NrnThread *)
Definition: netcvode.cpp:5554
void * _vcv
Definition: multicore.h:83
#define i
Definition: md1redef.h:12
double tn_
Definition: cvodeobj.h:97
void deliver_net_events(NrnThread *)
Definition: cvodestb.cpp:40
void nrn_play_init()
Definition: cvodestb.cpp:75
void cvode_fadvance(double)
Definition: cvodestb.cpp:101
double dt
Definition: init.cpp:123
void fixed_record_continuous(NrnThread *)
Definition: netcvode.cpp:5542
int nrn_use_daspk_
Definition: treeset.cpp:70
int solve(double t)
Definition: netcvode.cpp:2040