1 #include <../../nrnconf.h> 16 #include "ida/ida_impl.h" 41 extern booleantype
IDAEwtSet(IDAMem IDA_mem, N_Vector ycur);
45 #define nt_dt nrn_threads->_dt 46 #define nt_t nrn_threads->_t 53 realtype
t, N_Vector y, N_Vector yp, N_Vector delta,
57 static int minit(IDAMem);
59 static int msetup(IDAMem mem, N_Vector y, N_Vector ydot, N_Vector delta,
60 N_Vector tempv1, N_Vector tempv2, N_Vector tempv3
63 static int msolve(IDAMem mem, N_Vector b, N_Vector ycur, N_Vector ypcur,
67 static int mfree(IDAMem);
72 #define thread_t nrn_thread_t 93 realtype
t, N_Vector y, N_Vector yp, N_Vector delta,
96 thread_cv = (
Cvode*)rdata;
113 static int msetup(IDAMem mem, N_Vector y, N_Vector yp, N_Vector,
114 N_Vector, N_Vector, N_Vector
132 static int msolve(IDAMem mem, N_Vector b, N_Vector w, N_Vector ycur, N_Vector, N_Vector){
133 thread_cv = (
Cvode*)mem->ida_rdata;
142 static int mfree(IDAMem) {
return IDA_SUCCESS;}
160 IDAFree((IDAMem)
mem_);
174 IDAMem mem = (IDAMem) IDACreate();
178 IDASetRdata(mem,
cv_);
182 mem->ida_linit =
minit;
185 mem->ida_lfree =
mfree;
186 mem->ida_setupNonNull =
false;
216 double norm = N_VWrmsNorm(ida->
delta_, ((IDAMem)(ida->
mem_))->ida_ewt);
217 Printf(
"ida check t=%.15g norm=%g\n", t, norm);
220 printf(
" %3d %22.15g %22.15g %22.15g\n",
i,
221 N_VGetArrayPointer(ida->
cv_->
y_)[
i],
222 N_VGetArrayPointer(ida->
yp_)[
i],
223 N_VGetArrayPointer(ida->
delta_)[
i]);
233 printf(
"Daspk_init t_=%20.12g t-t_=%g t0_-t_=%g\n",
275 N_VScale(dtinv,
yp_,
yp_);
292 double norm = N_VWrmsNorm(
parasite_, ((IDAMem)mem_)->ida_ewt);
297 Printf(
"IDA initialization failure, weighted norm of residual=%g\n", norm);
301 Printf(
"IDA initialization warning, weighted norm of residual=%g\n", norm);
304 Printf(
"IDA initialization warning, weighted norm of residual=%g\n", norm);
307 Printf(
" subtracting (for next 1e-6 ms): f(y', y, %g)*exp(-1e7*(t-%g))\n",
nt_t,
nt_t);
312 printf(
" %d %g %g %g %g\n", i,
nt_t, N_VGetArrayPointer(
cv_->
y_)[i], N_VGetArrayPointer(
yp_)[i], N_VGetArrayPointer(
delta_)[i]);
332 IDASetStopTime(
mem_, tstop);
339 if (ier > 0 && t < cv_->t_) {
358 IDASetStopTime(
mem_, tt);
361 Printf(
"DASPK interpolate error\n");
376 printf(
"rwork size = %d\n", iwork_[18-1]);
377 printf(
"iwork size = %d\n", iwork_[17-1]);
378 printf(
"Number of time steps = %d\n", iwork_[11-1]);
379 printf(
"Number of residual evaluations = %d\n", iwork_[12-1]);
380 printf(
"Number of Jac evaluations = %d\n", iwork_[13-1]);
381 printf(
"Number of preconditioner solves = %d\n", iwork_[21-1]);
382 printf(
"Number of nonlinear iterations = %d\n", iwork_[19-1]);
383 printf(
"Number of linear iterations = %d\n", iwork_[20-1]);
384 double avlin = double(iwork_[20-1])/double(iwork_[19-1]);
385 printf(
"Average Krylov subspace dimension = %g\n", avlin);
386 printf(
"nonlinear conv. failures = %d\n", iwork_[15-1]);
387 printf(
"linear conv. failures = %d\n", iwork_[16-1]);
416 for (i=0; i <
n; ++
i) {
438 for (i=0; i <
n; ++
i) {
464 printf(
"Cvode::res enter tt=%g\n", tt);
466 printf(
" %d %g %g %g\n", i, y[i], yprime[i], delta[i]);
470 daspk_scatter_y(y, nt->
id);
472 play_continuous_thread(tt, nt);
476 gather_ydot(delta, nt->
id);
490 printf(
"Cvode::res after ode and gather_ydot into delta\n");
492 printf(
" %d %g %g %g\n", i, y[i], yprime[i], delta[i]);
508 for (i=0; i <
n; ++
i) {
509 double* cd = ml->
data[
i];
515 cdvm = 1
e-3 * cd[0] * (yprime[
j] - yprime[j+1]);
526 cdvm = 1
e-3 * cd[0] * yprime[
j];
541 for (i=0; i <
n; ++
i) {
542 double* cd = ml->
data[
i];
555 delta[
j] -= 1
e-3 * cd[2] * yprime[
j];
561 delta[jj] -= 1
e-3*cd[2*
nlayer+
k]*(yprime[jj]);
562 for (k=
nlayer-2; k >= 0; --
k) {
566 x = 1
e-3*cd[2*
nlayer+
k]*(yprime[jj] - yprime[jj+1]);
580 delta[
i] -= yprime[
i];
586 if (daspk_->use_parasite_ && tt - daspk_->t_parasite_ < 1
e-6) {
587 double fac =
exp(1e7*(daspk_->t_parasite_ - tt));
588 double* tps = n_vector_data(daspk_->parasite_, nt->
id);
590 delta[
i] -= tps[
i]*fac;
595 printf(
"Cvode::res exit res_=%d tt=%20.12g\n", res_, tt);
597 printf(
" %d %g %g %g\n", i, y[i], yprime[i], delta[i]);
604 e += delta[
i]*delta[
i];
606 printf(
"Cvode::res %d e=%g t=%.15g\n", res_, e, tt);
629 daspk_scatter_y(y, _nt->
id);
638 scatter_ydot(b, _nt->
id);
640 printf(
"before nrn_solve matrix cj=%g\n", cj);
642 printf(
"before nrn_solve actual_rhs=\n");
644 printf(
"%d %g\n", i+1, actual_rhs[i+1]);
651 printf(
"after nrn_solve actual_rhs=\n");
652 for (i=0; i < neq_v_; ++
i) {
653 printf(
"%d %g\n", i+1, actual_rhs[i+1]);
658 gather_ydot(b, _nt->
id);
676 return ((IDAMem)
mem_)->ida_ewt;
680 return ((IDAMem)
mem_)->ida_delta;
void daspk_gather_y(N_Vector)
void nrn_multithread_job(void *(*job)(NrnThread *))
static void daspk_nrn_solve(NrnThread *nt)
double * n_vector_data(N_Vector, int)
Represent main neuron object computed by single thread.
void nrn_rhs(NrnThread *)
static int init_failure_style_
static philox4x32_key_t k
BAMechList * after_solve_
booleantype IDAEwtSet(IDAMem IDA_mem, N_Vector ycur)
_nrn_Fast_Imem * _nrn_fast_imem
static int res_gvardt(realtype t, N_Vector y, N_Vector yp, N_Vector delta, void *rdata)
static N_Vector nvec_delta
void nrn_solve(NrnThread *)
void nrn_daspk_init_step(double, double, int)
int const size_t const size_t n
int res(double, double *, double *, double *, NrnThread *)
static double check(double t, Daspk *ida)
int advance_tn(double tstop)
void hoc_execerror(const char *, const char *)
static void * msolve_thread(NrnThread *nt)
static bool eq(double x, double y, double e)
static void * res_thread(NrnThread *nt)
static double eps(double x)
static void * daspk_gather_thread(NrnThread *nt)
void play_continuous(double t)
void nrn_lhs(NrnThread *)
static int init_try_again_
void nrndae_dkres(double *, double *, double *)
static void * do_ode_thread(NrnThread *nt)
static int msetup(IDAMem mem, N_Vector y, N_Vector ydot, N_Vector delta, N_Vector tempv1, N_Vector tempv2, N_Vector tempv3)
int psol(double, double *, double *, double, NrnThread *)
static int msolve(IDAMem mem, N_Vector b, N_Vector ycur, N_Vector ypcur, N_Vector deltacur)
void nrndae_dkpsol(double)
void gather_ydot(N_Vector)
static int first_try_init_failures_
static void * daspk_scatter_thread(NrnThread *nt)
int interpolate(double tout)
void daspk_scatter_y(N_Vector)