NEURON
ssimplic_thread.hpp
Go to the documentation of this file.
1 /*
2 # =============================================================================
3 # Copyright (c) 2016 - 2022 Blue Brain Project/EPFL
4 #
5 # See top-level LICENSE file for details.
6 # =============================================================================
7 */
8 #pragma once
10 
11 namespace coreneuron {
12 
13 #if defined(scopmath_ssimplic_s)
14 #error "naming clash on ssimplic_thread.hpp-internal macros"
15 #endif
16 #define scopmath_ssimplic_s(arg) _p[CNRN_FLAT_INDEX_IML_ROW(s[arg])]
17 static int check_state(int n, int* s, _threadargsproto_) {
18  bool flag{true};
19  for (int i = 0; i < n; i++) {
20  if (scopmath_ssimplic_s(i) < -1e-6) {
21  scopmath_ssimplic_s(i) = 0.;
22  flag = false;
23  }
24  }
25  return flag;
26 }
27 #undef scopmath_ssimplic_s
28 
29 template <typename SPFUN>
31  int n,
32  int* s,
33  int* d,
34  double* t,
35  double dt,
36  SPFUN fun,
37  int linflag,
39  int err;
40  double ss_dt{1e9};
41  _nt->_dt = ss_dt;
42 
43  if (linflag) { /*iterate linear solution*/
44  err = sparse_thread(so, n, s, d, t, ss_dt, fun, 0, _threadargs_);
45  } else {
46  int ii{7};
47  err = 0;
48  while (ii) {
49  err = sparse_thread(so, n, s, d, t, ss_dt, fun, 1, _threadargs_);
50  if (!err) {
51  if (check_state(n, s, _threadargs_)) {
52  err = sparse_thread(so, n, s, d, t, ss_dt, fun, 0, _threadargs_);
53  }
54  }
55  --ii;
56  if (!err) {
57  ii = 0;
58  }
59  }
60  }
61 
62  _nt->_dt = dt;
63  return err;
64 }
65 
66 template <typename DIFUN>
67 int _ss_derivimplicit_thread(int n, int* slist, int* dlist, DIFUN fun, _threadargsproto_) {
68  double const dtsav{_nt->_dt};
69  _nt->_dt = 1e-9;
70  int err = fun(_threadargs_);
71  _nt->_dt = dtsav;
72  return err;
73 }
74 } // namespace coreneuron
#define i
Definition: md1redef.h:19
#define _threadargsproto_
#define _threadargs_
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
static int check_state(int n, int *s, _threadargsproto_)
int _ss_sparse_thread(SparseObj *so, int n, int *s, int *d, double *t, double dt, SPFUN fun, int linflag, _threadargsproto_)
int sparse_thread(SparseObj *so, int n, int *s, int *d, double *t, double dt, F fun, int linflag, _threadargsproto_)
This is an experimental numerical method for SCoP-3 which integrates kinetic rate equations.
int _ss_derivimplicit_thread(int n, int *slist, int *dlist, DIFUN fun, _threadargsproto_)
int ii
Definition: cellorder.cpp:631
int const size_t const size_t n
Definition: nrngsl.h:10
s
Definition: multisend.cpp:521
#define scopmath_ssimplic_s(arg)