CoreNEURON
membfunc.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
9 
13 
14 #include <cmath>
15 #include <vector>
16 
17 namespace coreneuron {
18 
19 using Pfrpdat = Datum* (*) (void);
20 
21 struct NrnThread;
22 
23 using mod_alloc_t = void (*)(double*, Datum*, int);
24 using mod_f_t = void (*)(NrnThread*, Memb_list*, int);
25 using pnt_receive_t = void (*)(Point_process*, int, double);
27  void (*)(int, int, double*, Datum*, ThreadDatum*, NrnThread*, Memb_list*, int);
28 
29 /*
30  * Memb_func structure contains all related informations of a mechanism
31  */
32 struct Memb_func {
39  mod_f_t destructor; /* only for point processes */
40  // These are used for CoreNEURON-internal allocation/cleanup; they are kept
41  // separate from the CONSTRUCTOR/DESTRUCTOR functions just above (one of
42  // which is apparently only for point processes) for simplicity.
47  int thread_size_; /* how many Datum needed in Memb_list if vectorized */
48  void (*thread_mem_init_)(ThreadDatum*); /* after Memb_list._thread is allocated */
49  void (*thread_cleanup_)(ThreadDatum*); /* before Memb_list._thread is freed */
51  int is_point;
52  void (*setdata_)(double*, Datum*);
53  int* dparam_semantics; /* for nrncore writing. */
54  ~Memb_func();
55 };
56 
57 #define VINDEX -1
58 #define CABLESECTION 1
59 #define MORPHOLOGY 2
60 #define CAP 3
61 #define EXTRACELL 5
62 
63 #define nrnocCONST 1
64 #define DEP 2
65 #define STATE 3 /*See init.c and cabvars.h for order of nrnocCONST, DEP, and STATE */
66 
67 #define BEFORE_INITIAL 0
68 #define AFTER_INITIAL 1
69 #define BEFORE_BREAKPOINT 2
70 #define AFTER_SOLVE 3
71 #define BEFORE_STEP 4
72 #define BEFORE_AFTER_SIZE 5 /* 1 more than the previous */
73 struct BAMech {
75  int type;
76  struct BAMech* next;
77 };
78 
79 extern int nrn_ion_global_map_size;
80 extern double** nrn_ion_global_map;
81 extern const int ion_global_map_member_size;
82 
83 #define NRNPOINTER \
84  4 /* added on to list of mechanism variables.These are \
85 pointers which connect variables from other mechanisms via the _ppval array. \
86 */
87 
88 #define _AMBIGUOUS 5
89 
90 
91 extern int nrn_get_mechtype(const char*);
92 extern const char* nrn_get_mechname(int); // slow. use memb_func[i].sym if posible
93 extern int register_mech(const char** m,
94  mod_alloc_t alloc,
95  mod_f_t cur,
96  mod_f_t jacob,
97  mod_f_t stat,
98  mod_f_t initialize,
99  mod_f_t private_constructor,
100  mod_f_t private_destructor,
101  int nrnpointerindex,
102  int vectorized);
103 extern int point_register_mech(const char**,
104  mod_alloc_t alloc,
105  mod_f_t cur,
106  mod_f_t jacob,
107  mod_f_t stat,
108  mod_f_t initialize,
109  mod_f_t private_constructor,
110  mod_f_t private_destructor,
111  int nrnpointerindex,
112  mod_f_t constructor,
113  mod_f_t destructor,
114  int vectorized);
115 extern void register_constructor(mod_f_t constructor);
116 using NetBufReceive_t = void (*)(NrnThread*);
118 
120 
121 using nrn_watch_check_t = void (*)(NrnThread*, Memb_list*);
123 
125 extern void nrn_writes_conc(int, int);
126 constexpr double ktf(double celsius) {
127  return 1000. * units::gasconstant * (celsius + 273.15) / units::faraday;
128 }
129 // std::log isn't constexpr, but there are argument values for which nrn_nernst
130 // is a constant expression
131 constexpr double nrn_nernst(double ci, double co, double z, double celsius) {
132  if (z == 0) {
133  return 0.;
134  }
135  if (ci <= 0.) {
136  return 1e6;
137  } else if (co <= 0.) {
138  return -1e6;
139  } else {
140  return ktf(celsius) / z * std::log(co / ci);
141  }
142 }
143 constexpr void nrn_wrote_conc(int type,
144  double* p1,
145  int p2,
146  int it,
147  double** gimap,
148  double celsius,
149  int _cntml_padded) {
150  if (it & 040) {
151  constexpr int _iml = 0;
152  int const STRIDE{_cntml_padded + _iml};
153  /* passing _nt to this function causes cray compiler to segfault during compilation
154  * hence passing _cntml_padded
155  */
156  double* pe = p1 - p2 * STRIDE;
157  pe[0] = nrn_nernst(pe[1 * STRIDE], pe[2 * STRIDE], gimap[type][2], celsius);
158  }
159 }
160 inline double nrn_ghk(double v, double ci, double co, double z, double celsius) {
161  auto const efun = [](double x) {
162  if (std::abs(x) < 1e-4) {
163  return 1. - x / 2.;
164  } else {
165  return x / (std::exp(x) - 1.);
166  }
167  };
168  double const temp{z * v / ktf(celsius)};
169  double const eco{co * efun(+temp)};
170  double const eci{ci * efun(-temp)};
171  return .001 * z * units::faraday * (eci - eco);
172 }
173 extern void hoc_register_prop_size(int, int, int);
174 extern void hoc_register_dparam_semantics(int type, int, const char* name);
175 extern void hoc_reg_ba(int, mod_f_t, int);
176 
177 struct DoubScal {
178  const char* name;
179  double* pdoub;
180 };
181 struct DoubVec {
182  const char* name;
183  double* pdoub;
184  int index1;
185 };
186 struct VoidFunc {
187  const char* name;
188  void (*func)(void);
189 };
190 extern void hoc_register_var(DoubScal*, DoubVec*, VoidFunc*);
191 
192 extern void _nrn_layout_reg(int, int);
193 extern void _nrn_thread_reg0(int i, void (*f)(ThreadDatum*));
194 extern void _nrn_thread_reg1(int i, void (*f)(ThreadDatum*));
195 
196 using bbcore_read_t = void (*)(double*,
197  int*,
198  int*,
199  int*,
200  int,
201  int,
202  double*,
203  Datum*,
204  ThreadDatum*,
206  Memb_list*,
207  double);
208 
209 using bbcore_write_t = void (*)(double*,
210  int*,
211  int*,
212  int*,
213  int,
214  int,
215  double*,
216  Datum*,
217  ThreadDatum*,
219  Memb_list*,
220  double);
221 
222 extern int nrn_mech_depend(int type, int* dependencies);
223 extern int nrn_fornetcon_cnt_;
224 extern int* nrn_fornetcon_type_;
225 extern int* nrn_fornetcon_index_;
226 extern void add_nrn_fornetcons(int, int);
227 extern void add_nrn_has_net_event(int);
228 extern void net_event(Point_process*, double);
229 extern void net_send(void**, int, Point_process*, double, double);
230 extern void net_move(void**, Point_process*, double);
231 extern void artcell_net_send(void**, int, Point_process*, double, double);
232 extern void artcell_net_move(void**, Point_process*, double);
233 extern void nrn2ncs_outputevent(int netcon_output_index, double firetime);
234 extern bool nrn_use_localgid_;
235 extern void net_sem_from_gpu(int sendtype, int i_vdata, int, int ith, int ipnt, double, double);
236 
237 // _OPENACC and/or NET_RECEIVE_BUFFERING
238 extern void net_sem_from_gpu(int, int, int, int, int, double, double);
239 
240 extern void hoc_malchk(void); /* just a stub */
241 extern void* hoc_Emalloc(size_t);
242 
243 } // namespace coreneuron
coreneuron::BAMech::type
int type
Definition: membfunc.hpp:75
coreneuron::net_event
void net_event(Point_process *, double)
Definition: netcvode.cpp:107
mechanism.hpp
coreneuron::nrn_use_localgid_
bool nrn_use_localgid_
coreneuron::Memb_func::thread_size_
int thread_size_
Definition: membfunc.hpp:47
coreneuron::thread_table_check_t
void(*)(int, int, double *, Datum *, ThreadDatum *, NrnThread *, Memb_list *, int) thread_table_check_t
Definition: membfunc.hpp:27
coreneuron::nrn2ncs_outputevent
void nrn2ncs_outputevent(int netcon_output_index, double firetime)
coreneuron::BAMech::f
mod_f_t f
Definition: membfunc.hpp:74
coreneuron::nrn_fornetcon_type_
int * nrn_fornetcon_type_
Definition: register_mech.cpp:51
coreneuron::nrn_get_mechtype
int nrn_get_mechtype(const char *name)
Get mechanism type by the mechanism name.
Definition: mk_mech.cpp:138
coreneuron::Memb_func::sym
Symbol * sym
Definition: membfunc.hpp:45
coreneuron::nrn_fornetcon_cnt_
int nrn_fornetcon_cnt_
Definition: register_mech.cpp:50
coreneuron::nrn_jacob_capacitance
void nrn_jacob_capacitance(NrnThread *, Memb_list *, int)
Definition: capac.cpp:58
coreneuron::pnt_receive_t
void(*)(Point_process *, int, double) pnt_receive_t
Definition: membfunc.hpp:25
coreneuron::_nrn_thread_reg1
void _nrn_thread_reg1(int i, void(*f)(ThreadDatum *))
Definition: register_mech.cpp:426
coreneuron::units::faraday
constexpr double faraday
Definition: units.hpp:32
coreneuron::DoubVec
Definition: membfunc.hpp:179
coreneuron::DoubScal
Definition: membfunc.hpp:175
coreneuron::Point_process
Definition: mechanism.hpp:35
coreneuron::nrn_fornetcon_index_
int * nrn_fornetcon_index_
Definition: register_mech.cpp:52
coreneuron::nrn_watch_check_t
void(*)(NrnThread *, Memb_list *) nrn_watch_check_t
Definition: membfunc.hpp:119
coreneuron::Datum
int Datum
Definition: nrnconf.h:23
coreneuron::nrn_nernst
constexpr double nrn_nernst(double ci, double co, double z, double celsius)
Definition: membfunc.hpp:129
coreneuron::hoc_reg_ba
void hoc_reg_ba(int, mod_f_t, int)
Definition: register_mech.cpp:378
coreneuron::add_nrn_fornetcons
void add_nrn_fornetcons(int, int)
Definition: register_mech.cpp:54
coreneuron::ion_global_map_member_size
const int ion_global_map_member_size
coreneuron::DoubScal::name
const char * name
Definition: membfunc.hpp:176
coreneuron::point_register_mech
int point_register_mech(const char **, mod_alloc_t alloc, mod_f_t cur, mod_f_t jacob, mod_f_t stat, mod_f_t initialize, mod_f_t private_constructor, mod_f_t private_destructor, int nrnpointerindex, mod_f_t constructor, mod_f_t destructor, int vectorized)
Definition: register_mech.cpp:339
coreneuron::nrn_wrote_conc
constexpr void nrn_wrote_conc(int type, double *p1, int p2, int it, double **gimap, double celsius, int _cntml_padded)
Definition: membfunc.hpp:141
coreneuron::register_mech
int register_mech(const char **m, mod_alloc_t alloc, mod_f_t cur, mod_f_t jacob, mod_f_t stat, mod_f_t initialize, mod_f_t private_constructor, mod_f_t private_destructor, int nrnpointerindex, int vectorized)
Definition: register_mech.cpp:112
coreneuron::net_move
void net_move(void **, Point_process *, double)
Definition: netcvode.cpp:296
coreneuron::DoubVec::pdoub
double * pdoub
Definition: membfunc.hpp:181
coreneuron::Memb_list
Definition: mechanism.hpp:131
coreneuron::hoc_Emalloc
void * hoc_Emalloc(size_t)
Definition: nrnoc_aux.cpp:80
coreneuron::units::gasconstant
constexpr double gasconstant
Definition: units.hpp:34
coreneuron::Memb_func::~Memb_func
~Memb_func()
Definition: register_mech.cpp:447
coreneuron::VoidFunc::name
const char * name
Definition: membfunc.hpp:185
coreneuron::Pfrpdat
Datum *(*)(void) Pfrpdat
Definition: membfunc.hpp:19
coreneuron::DoubVec::index1
int index1
Definition: membfunc.hpp:182
coreneuron::Memb_func::private_destructor
mod_f_t private_destructor
Definition: membfunc.hpp:44
coreneuron
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
Definition: corenrn_parameters.cpp:12
coreneuron::_nrn_layout_reg
void _nrn_layout_reg(int, int)
Definition: register_mech.cpp:176
coreneuron::Memb_func::alloc
mod_alloc_t alloc
Definition: membfunc.hpp:33
units.hpp
coreneuron::Memb_func::destructor
mod_f_t destructor
Definition: membfunc.hpp:39
coreneuron::i
int i
Definition: cellorder.cpp:485
coreneuron::BAMech::next
struct BAMech * next
Definition: membfunc.hpp:76
coreneuron::register_constructor
void register_constructor(mod_f_t constructor)
Definition: register_mech.cpp:317
coreneuron::Symbol
char Symbol
Definition: nrnconf.h:25
coreneuron::Memb_func::dparam_semantics
int * dparam_semantics
Definition: membfunc.hpp:53
coreneuron::hoc_register_net_receive_buffering
void hoc_register_net_receive_buffering(NetBufReceive_t, int)
Definition: register_mech.cpp:180
coreneuron::nrn_ion_global_map
double ** nrn_ion_global_map
coreneuron::Memb_func::private_constructor
mod_f_t private_constructor
Definition: membfunc.hpp:43
coreneuron::mod_f_t
void(*)(NrnThread *, Memb_list *, int) mod_f_t
Definition: membfunc.hpp:24
coreneuron::Memb_func::thread_mem_init_
void(* thread_mem_init_)(ThreadDatum *)
Definition: membfunc.hpp:48
coreneuron::Memb_func::thread_table_check_
thread_table_check_t thread_table_check_
Definition: membfunc.hpp:50
coreneuron::nrn_ion_global_map_size
int nrn_ion_global_map_size
coreneuron::Memb_func::current
mod_f_t current
Definition: membfunc.hpp:34
coreneuron::NrnThread
Definition: multicore.hpp:75
coreneuron::Memb_func
Definition: membfunc.hpp:32
coreneuron::Memb_func::jacob
mod_f_t jacob
Definition: membfunc.hpp:35
coreneuron::nrn_mech_depend
int nrn_mech_depend(int type, int *dependencies)
Definition: register_mech.cpp:294
coreneuron::mod_alloc_t
void(*)(double *, Datum *, int) mod_alloc_t
Definition: membfunc.hpp:23
coreneuron::DoubScal::pdoub
double * pdoub
Definition: membfunc.hpp:177
coreneuron::nrn_writes_conc
void nrn_writes_conc(int, int)
Definition: register_mech.cpp:163
coreneuron::bbcore_read_t
void(*)(double *, int *, int *, int *, int, int, double *, Datum *, ThreadDatum *, NrnThread *, Memb_list *, double) bbcore_read_t
Definition: membfunc.hpp:205
coreneuron::Memb_func::vectorized
int vectorized
Definition: membfunc.hpp:46
coreneuron::Memb_func::state
mod_f_t state
Definition: membfunc.hpp:36
coreneuron::hoc_register_net_send_buffering
void hoc_register_net_send_buffering(int)
Definition: register_mech.cpp:184
coreneuron::net_send
void net_send(void **, int, Point_process *, double, double)
Definition: netcvode.cpp:77
coreneuron::ThreadDatum
Definition: mechanism.hpp:26
coreneuron::DoubVec::name
const char * name
Definition: membfunc.hpp:180
coreneuron::hoc_register_watch_check
void hoc_register_watch_check(nrn_watch_check_t, int)
Definition: register_mech.cpp:188
coreneuron::hoc_malchk
void hoc_malchk(void)
Definition: nrnoc_aux.cpp:83
coreneuron::artcell_net_move
void artcell_net_move(void **, Point_process *, double)
Definition: netcvode.cpp:310
coreneuron::nrn_get_mechname
const char * nrn_get_mechname(int type)
Definition: mk_mech.cpp:145
coreneuron::add_nrn_has_net_event
void add_nrn_has_net_event(int)
Definition: register_mech.cpp:42
coreneuron::hoc_register_dparam_semantics
void hoc_register_dparam_semantics(int type, int, const char *name)
Definition: register_mech.cpp:207
coreneuron::Memb_func::constructor
mod_f_t constructor
Definition: membfunc.hpp:38
coreneuron::hoc_register_var
void hoc_register_var(DoubScal *ds, DoubVec *dv, VoidFunc *)
Definition: global_vars.cpp:31
coreneuron::VoidFunc::func
void(* func)(void)
Definition: membfunc.hpp:186
coreneuron::BAMech
Definition: membfunc.hpp:73
coreneuron::celsius
double celsius
Definition: register_mech.cpp:22
coreneuron::Memb_func::initialize
mod_f_t initialize
Definition: membfunc.hpp:37
v
#define v
Definition: md1redef.h:11
coreneuron::ktf
constexpr double ktf(double celsius)
Definition: membfunc.hpp:124
coreneuron::Memb_func::setdata_
void(* setdata_)(double *, Datum *)
Definition: membfunc.hpp:52
coreneuron::bbcore_write_t
void(*)(double *, int *, int *, int *, int, int, double *, Datum *, ThreadDatum *, NrnThread *, Memb_list *, double) bbcore_write_t
Definition: membfunc.hpp:218
coreneuron::nrn_ghk
double nrn_ghk(double v, double ci, double co, double z, double celsius)
Definition: membfunc.hpp:158
coreneuron::artcell_net_send
void artcell_net_send(void **, int, Point_process *, double, double)
Definition: netcvode.cpp:103
offload.hpp
coreneuron::hoc_register_prop_size
void hoc_register_prop_size(int, int, int)
Definition: register_mech.cpp:192
coreneuron::Memb_func::thread_cleanup_
void(* thread_cleanup_)(ThreadDatum *)
Definition: membfunc.hpp:49
coreneuron::net_sem_from_gpu
void net_sem_from_gpu(int sendtype, int i_vdata, int, int ith, int ipnt, double, double)
Definition: netcvode.cpp:59
coreneuron::Memb_func::is_point
int is_point
Definition: membfunc.hpp:51
coreneuron::NetBufReceive_t
void(*)(NrnThread *) NetBufReceive_t
Definition: membfunc.hpp:114
coreneuron::_nrn_thread_reg0
void _nrn_thread_reg0(int i, void(*f)(ThreadDatum *))
Definition: register_mech.cpp:419
coreneuron::VoidFunc
Definition: membfunc.hpp:184