1 #include <../../nrnconf.h>
27 #if NRN_ENABLE_THREADS
49 #include "cvodes/cvodes.h"
50 #include "cvodes/cvodes_impl.h"
51 #include "cvodes/cvdense.h"
52 #include "cvodes/cvdiag.h"
53 #include "shared/dense.h"
58 #define nt_dt nrn_threads->_dt
59 #define nt_t nrn_threads->_t
70 extern void nrn2ncs_netcons();
74 extern N_Vector N_VNew_Parallel(
int comm,
long int local_length,
long int global_length);
83 #define SUCCESS CV_SUCCESS
127 hoc_warning(
"CVode.queue_mode with second arg == 1 requires",
128 "configuration --with-mpi or related");
174 "Cannot find the symbol associated with the pointer when called from Python",
175 "Use a string instead of pointer argument");
208 return double(d->
stiff());
285 int i = (int)
chkarg(1, 0, 1e9);
288 style = (int)
chkarg(3, 0, 2);
369 int i = (int)
chkarg(1, 0, 10);
405 if (y > 1 &&
fabs(
floor(y + 1e-6) - y) < 1e-6) {
419 reinit = int(
chkarg(4, 0, 1));
446 return double(modeltype + 10 *
use_sparse13 + 100 * methodtype + 1000 * localtype);
485 d->
gcv_->use_partrans_ =
true;
510 for (
Object* callable: *esl) {
519 int direction = int(
chkarg(1, 0, 1));
534 for (
int direction = 0; direction < 2; ++direction) {
537 for (
auto it = esl->begin(); it != esl->end();) {
602 {
"print_event_queue",
peq},
661 static int minit(CVodeMem cv_mem);
662 static int msetup(CVodeMem cv_mem,
666 booleantype* jcurPtr,
670 static int msolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, N_Vector ycur, N_Vector fcur);
676 static void mfree(CVodeMem cv_mem);
677 static void f_gvardt(realtype
t, N_Vector y, N_Vector ydot,
void* f_data);
678 static void f_lvardt(realtype
t, N_Vector y, N_Vector ydot,
void* f_data);
723 use_partrans_ =
false;
731 return ((CVodeMem)
mem_)->cv_gamma;
739 return ((CVodeMem)
mem_)->cv_h;
771 if (te <= tstop_ && te >
t0_) {
794 return N_VNew_Parallel(0,
n, global_neq_);
822 return N_VNew_Serial(
n);
906 if (on &&
neq_ > 0) {
962 for (
int i = 0;
i <
n; ++
i) {
975 for (
int i = 0;
i <
n; ++
i) {
992 CVodeGetLastOrder(
mem_, &
i);
1004 CVodeSetMaxOrd(
mem_, maxord);
1011 CVodeSetMinStep(
mem_, x);
1015 ((CVodeMem)
mem_)->cv_hmin = 0.;
1026 CVodeSetMaxStep(
mem_, x);
1067 Printf(
"Cvode %p %s CVReInit error %d\n",
1074 mem_ = CVodeCreate(CV_BDF,
ncv_->
stiff() ? CV_NEWTON : CV_FUNCTIONAL);
1083 Printf(
"Cvode %p %s CVodeMalloc error %d\n",
1092 ((CVodeMem)
mem_)->cv_gamma = 0.;
1093 ((CVodeMem)
mem_)->cv_h = 0.;
1097 std::pair<Cvode*, neuron::model_sorted_token const&> opaque{
this, sorted_token};
1098 pf_(
t_,
y_,
nullptr, &opaque);
1211 if (use_partrans_) {
1268 Printf(
"Cvode::interpolate assert error t0=%g tout-t0=%g eps*t_=%g\n",
1276 Printf(
"Cvode::interpolate assert error tn=%g tn-tout=%g eps*t_=%g\n",
1302 Printf(
"Cvode::cvode_advance_tn %p %d initialize_=%d tstop=%.20g t_=%.20g to ",
1310 std::pair<Cvode*, neuron::model_sorted_token const&> opaque{
this, sorted_token};
1311 CVodeSetFdata(
mem_, &opaque);
1315 CVodeSetFdata(
mem_,
nullptr);
1322 Printf(
"CVode %p %s advance_tn failed, err=%d.\n",
1326 pf_(
t_,
y_,
nullptr, &opaque);
1331 pf_(
t_,
y_,
nullptr, &opaque);
1332 tn_ = ((CVodeMem)
mem_)->cv_tn;
1344 Printf(
"Cvode::cvode_interpolate %p %d initialize_%d t=%.20g to ",
1354 std::pair<Cvode*, neuron::model_sorted_token const&> opaque{
this, sorted_token};
1355 CVodeSetFdata(
mem_, &opaque);
1357 int err = CVode(
mem_, tout,
y_, &
t_, CV_NORMAL);
1358 CVodeSetFdata(
mem_,
nullptr);
1365 Printf(
"CVode %p %s interpolate failed, err=%d.\n",
1371 pf_(
t_,
y_,
nullptr, &opaque);
1395 return ((CVodeMem)
mem_)->cv_ewt;
1403 return ((CVodeMem)
mem_)->cv_acor;
1409 Printf(
"\nCvode instance %p %s statistics : %d %s states\n",
1414 Printf(
" %d advance_tn, %d interpolate, %d init (%d due to at_time)\n",
1419 Printf(
" %d function evaluations, %d mx=b solves, %d jacobian setups\n",
1428 Printf(
"\nCVode Statistics.. \n\n");
1429 Printf(
"internal steps = %d\nfunction evaluations = %d\n", iopt_[NST], iopt_[NFE]);
1431 "newton iterations = %d setups = %d\n nonlinear convergence failures = %d\n\
1432 local error test failures = %ld\n",
1437 Printf(
"order=%d stepsize=%g\n", iopt_[QU],
h());
1451 if (((CVodeMem)
mem_)->cv_lfree) {
1452 ((CVodeMem)
mem_)->cv_lfree((CVodeMem)
mem_);
1453 ((CVodeMem)
mem_)->cv_lfree =
NULL;
1458 ((CVodeMem)
mem_)->cv_setupNonNull =
TRUE;
1471 return CV_NO_FAILURES;
1478 booleantype* jcurPtr,
1485 static_cast<std::pair<Cvode*, neuron::model_sorted_token const&>*
>(m->cv_f_data)->first;
1486 return cv->setup(yp,
fp);
1492 static int msolve(CVodeMem m, N_Vector b, N_Vector weight, N_Vector ycur, N_Vector fcur) {
1497 auto*
const f_typed_data =
static_cast<std::pair<Cvode*, neuron::model_sorted_token const&>*
>(
1500 auto const& sorted_token = f_typed_data->second;
1506 if (cv.
gam() == 0.) {
1520 static int msolve_lvardt(CVodeMem m, N_Vector b, N_Vector weight, N_Vector ycur, N_Vector fcur) {
1521 auto*
const f_typed_data =
static_cast<std::pair<Cvode*, neuron::model_sorted_token const&>*
>(
1523 auto*
const cv = f_typed_data->first;
1524 auto const& sorted_token = f_typed_data->second;
1526 if (cv->ncv_->stiff() == 0) {
1529 if (cv->gam() == 0.) {
1532 cv->nth_->_vcv = cv;
1533 cv->solvex_thread(sorted_token, cv->n_vector_data(b, 0), cv->n_vector_data(ycur, 0), cv->nth_);
1575 static void f_gvardt(realtype
t, N_Vector y, N_Vector ydot,
void* f_data) {
1576 auto*
const f_typed_data =
static_cast<std::pair<Cvode*, neuron::model_sorted_token const&>*
>(
1578 f_cv_ = f_typed_data->first;
1593 (*nrnmpi_v_transfer_)();
1602 (*nrnmpi_v_transfer_)();
1612 static void f_lvardt(realtype
t, N_Vector y, N_Vector ydot,
void* f_data) {
1613 auto*
const f_typed_data =
static_cast<std::pair<Cvode*, neuron::model_sorted_token const&>*
>(
1615 auto*
const cv = f_typed_data->first;
1616 auto const& sorted_token = f_typed_data->second;
1618 cv->nth_->_vcv = cv;
1619 cv->fun_thread(sorted_token,
t, cv->n_vector_data(y, 0), cv->n_vector_data(ydot, 0), cv->nth_);
1624 auto*
const nt = &ntr;
1634 auto*
const nt = &ntr;
1642 auto*
const nt = &ntr;
const char * secname(Section *sec)
name of section (for use in error messages)
void fun_thread_transfer_part2(neuron::model_sorted_token const &, double *ydot, NrnThread *nt)
void fun_thread_ms_part2(NrnThread *nt)
void do_nonode(neuron::model_sorted_token const &, NrnThread *nt=0)
int solvex_thread_part2(NrnThread *nt)
void fun_thread_transfer_part1(neuron::model_sorted_token const &, double t, double *y, NrnThread *nt)
bool at_time(double, NrnThread *)
int solvex_thread(neuron::model_sorted_token const &, double *b, double *y, NrnThread *nt)
void fun_thread_ms_part4(double *ydot, NrnThread *nt)
void fun_thread_ms_part34(double *ydot, NrnThread *nt)
void fun_thread_ms_part1(double t, double *y, NrnThread *nt)
int solvex_thread_part3(double *b, NrnThread *nt)
void fun_thread(neuron::model_sorted_token const &, double t, double *y, double *ydot, NrnThread *nt)
void fun_thread_ms_part3(NrnThread *nt)
virtual int init(double t)
double * n_vector_data(N_Vector, int)
virtual int interpolate(double t)
int cvode_advance_tn(neuron::model_sorted_token const &)
void activate_maxstate(bool)
int solvex_thread_part1(double *b, NrnThread *nt)
int cvode_interpolate(double)
virtual int advance_tn(neuron::model_sorted_token const &)
int interpolate(double tout)
static int first_try_init_failures_
int advance_tn(double tstop)
static int init_failure_style_
static bool le(double x, double y, double e)
static bool eq(T x, T y, T e)
double state_magnitudes()
std::string statename(int, int style=1)
static double eps(double x)
void hoc_event(double, const char *hoc_stmt, Object *ppobj=nullptr, int reinit=0, Object *pyact=nullptr)
void re_init(double t0=0.)
Symbol * name2sym(const char *)
void class2oc(const char *, ctor_f *cons, dtor_f *destruct, Member_func *, Member_ret_obj_func *, Member_ret_str_func *)
HocReturnType hoc_return_type_code
void(* nrn_multisplit_setup_)()
static void mfree(CVodeMem cv_mem)
static void f_thread_transfer_part2(neuron::model_sorted_token const &, NrnThread &)
double nrn_hoc2scatter_y(void *v)
static void f_lvardt(realtype t, N_Vector y, N_Vector ydot, void *f_data)
static double statistics(void *v)
void(* nrnthread_v_transfer_)(NrnThread *)
static double n_remove(void *v)
static double ncs_netcons(void *v)
static double extra_scatter_gather_remove(void *v)
static double nrn_diam_change_count(void *v)
static void * f_thread_ms_part2(NrnThread *)
Symbol * hoc_get_last_pointer_symbol()
static double solve(void *v)
static double state_magnitudes(void *v)
static double tstop_event(void *v)
static double poolshrink(void *)
static double store_events(void *v)
static Cvode * msolve_cv_
static void * f_thread_ms_part1(NrnThread *)
static void f_thread(neuron::model_sorted_token const &, NrnThread &)
double nrn_hoc2gather_y(void *v)
static double debug_event(void *v)
static Member_func members[]
static void * cons(Object *)
static void * msolve_thread_part3(NrnThread *)
static double event_queue_info(void *v)
static void f_thread_transfer_part1(neuron::model_sorted_token const &, NrnThread &)
static double condition_order(void *v)
static Section * cv_rootsec(const Cvode *cv)
static void * msolve_thread_part1(NrnThread *)
static double error_weights(void *v)
static double use_daspk(void *v)
static void destruct(void *v)
static double extra_scatter_gather(void *v)
static int minit(CVodeMem cv_mem)
short * nrn_is_artificial_
static double order(void *v)
static double nrn_atol(void *v)
static ExtraScatterList * extra_scatterlist[2]
static double use_local_dt(void *v)
double nrn_hoc2fun(void *v)
static double states(void *v)
static void * maxstate_thread(NrnThread *nt)
int linmod_extra_eqn_count()
static double maxorder(void *v)
static double acor(void *v)
static double statename(void *v)
static void msolve_thread(neuron::model_sorted_token const &, NrnThread &)
static double stiff(void *v)
static double cache_efficient(void *v)
static void * msolve_thread_part2(NrnThread *)
double nrn_hoc2fixed_step(void *v)
static double peq(void *v)
static double use_long_double(void *v)
static Member_ret_obj_func omembers[]
static double use_mxb(void *v)
static int msolve(CVodeMem cv_mem, N_Vector b, N_Vector weight, N_Vector ycur, N_Vector fcur)
void hoc_symbol_tolerance(Symbol *, double)
static int msetup(CVodeMem cv_mem, int convfail, N_Vector ypred, N_Vector fpred, booleantype *jcurPtr, N_Vector vtemp, N_Vector vtemp2, N_Vector vtemp3)
static void * f_thread_ms_part4(NrnThread *)
static double abstol(void *v)
static N_Vector msolve_ycur_
static double dstates(void *v)
static Cvode * maxstate_cv
static double minstep(void *v)
static int msolve_lvardt(CVodeMem cv_mem, N_Vector b, N_Vector weight, N_Vector ycur, N_Vector fcur)
static void * f_thread_ms_part34(NrnThread *)
std::vector< Object * > ExtraScatterList
static double nrn_structure_change_count(void *v)
static N_Vector msolve_b_
static void static_mutex_for_at_time(bool b)
static double jacobian(void *v)
static double free_event_queues(void *)
static double current_method(void *v)
void nrn_extra_scatter_gather(int direction, int tid)
static double use_parallel(void *v)
static double re_init(void *v)
NetCvode * net_cvode_instance
static double dae_init_dteps(void *v)
static Object ** netconlist(void *v)
static void f_gvardt(realtype t, N_Vector y, N_Vector ydot, void *f_data)
static void * f_thread_ms_part3(NrnThread *)
static double use_fast_imem(void *v)
static double spikestat(void *v)
static double n_record(void *v)
static double active(void *v)
static double simgraph_remove(void *v)
static double queue_mode(void *v)
static double rtol(void *v)
static double maxstep(void *v)
void(* nrnmpi_v_transfer_)()
void nrn_poolshrink(int shrink)
double chkarg(int, double low, double high)
int hoc_is_object_arg(int narg)
int hoc_is_str_arg(int narg)
void hoc_assign_str(char **cpp, const char *buf)
void check_obj_type(Object *obj, const char *type_name)
void hoc_obj_ref(Object *obj)
char * hoc_object_name(Object *ob)
void hoc_obj_unref(Object *obj)
char ** hoc_pgargstr(int narg)
Point_process * ob2pntproc(Object *ob)
Object ** hoc_objgetarg(int)
auto for_threads(NrnThread *threads, int num_threads)
void nrn_fast_imem_alloc()
void hoc_execerror(const char *s1, const char *s2)
void nrn_multithread_job(F &&job, Args &&... args)
void hoc_warning(const char *s1, const char *s2)
impl_ptrs methods
Collection of pointers to functions with python-version-specific implementations.
#define nrn_nonvint_block_ode_reinit(size, y, tid)
neuron::model_sorted_token nrn_ensure_model_data_are_sorted()
Ensure neuron::container::* data are sorted.
int const size_t const size_t n
#define MUTCONSTRUCT(mkmut)
int nrn_vartype(const Symbol *sym)
void nrn_thread_error(const char *s)
static int hoccommand_exec(Object *ho)
static int pysame(Object *o1, Object *o2)
N_Vector N_VNew_NrnParallelLD(MPI_Comm comm, long int local_length, long int global_length)
N_Vector N_VNew_NrnSerialLD(long int length)
N_Vector N_VNew_NrnThread(long int length, int nthread, long int *sizes)
N_Vector N_VNew_NrnThreadLD(long int length, int nthread, long int *sizes)
Represent main neuron object computed by single thread.
struct Symbol::@45::@46 rng
int Printf(const char *fmt, Args... args)