NEURON
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,
114  int vectorized);
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*,
205  NrnThread*,
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*,
218  NrnThread*,
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
#define v
Definition: md1redef.h:11
#define i
Definition: md1redef.h:19
exp
Definition: extdef.h:5
log
Definition: extdef.h:4
const char * name
Definition: init.cpp:16
constexpr double faraday
Definition: units.hpp:28
constexpr double gasconstant
Definition: units.hpp:30
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
void(*)(NrnThread *, Memb_list *, int) mod_f_t
Definition: membfunc.hpp:24
void artcell_net_move(void **, Point_process *, double)
Definition: netcvode.cpp:310
void _nrn_layout_reg(int, int)
void _nrn_thread_reg0(int i, void(*f)(ThreadDatum *))
void net_move(void **, Point_process *, double)
Definition: netcvode.cpp:296
void hoc_malchk(void)
Definition: nrnoc_aux.cpp:83
constexpr double nrn_nernst(double ci, double co, double z, double celsius)
Definition: membfunc.hpp:129
void hoc_reg_ba(int, mod_f_t, int)
void nrn_writes_conc(int, int)
int * nrn_fornetcon_type_
double ** nrn_ion_global_map
void nrn2ncs_outputevent(int netcon_output_index, double firetime)
void add_nrn_fornetcons(int, int)
void(*)(int, int, double *, Datum *, ThreadDatum *, NrnThread *, Memb_list *, int) thread_table_check_t
Definition: membfunc.hpp:27
constexpr void nrn_wrote_conc(int type, double *p1, int p2, int it, double **gimap, double celsius, int _cntml_padded)
Definition: membfunc.hpp:141
const int ion_global_map_member_size
int Datum
Definition: nrnconf.h:23
void hoc_register_net_receive_buffering(NetBufReceive_t, int)
int * nrn_fornetcon_index_
const char * nrn_get_mechname(int type)
Definition: mk_mech.cpp:152
void(*)(double *, int *, int *, int *, int, int, double *, Datum *, ThreadDatum *, NrnThread *, Memb_list *, double) bbcore_read_t
Definition: membfunc.hpp:205
int nrn_fornetcon_cnt_
void register_constructor(mod_f_t constructor)
void(*)(NrnThread *, Memb_list *) nrn_watch_check_t
Definition: membfunc.hpp:119
double nrn_ghk(double v, double ci, double co, double z, double celsius)
Definition: membfunc.hpp:158
void(*)(Point_process *, int, double) pnt_receive_t
Definition: membfunc.hpp:25
int nrn_mech_depend(int type, int *dependencies)
double celsius
void _nrn_thread_reg1(int i, void(*f)(ThreadDatum *))
Datum *(*)(void) Pfrpdat
Definition: membfunc.hpp:19
void hoc_register_dparam_semantics(int type, int, const char *name)
void hoc_register_var(DoubScal *ds, DoubVec *dv, VoidFunc *)
Definition: global_vars.cpp:31
int nrn_get_mechtype(const char *name)
Get mechanism type by the mechanism name.
Definition: mk_mech.cpp:145
void net_event(Point_process *, double)
Definition: netcvode.cpp:107
void(*)(double *, Datum *, int) mod_alloc_t
Definition: membfunc.hpp:23
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)
void net_send(void **, int, Point_process *, double, double)
Definition: netcvode.cpp:77
void hoc_register_prop_size(int, int, int)
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)
void(*)(NrnThread *) NetBufReceive_t
Definition: membfunc.hpp:114
constexpr double ktf(double celsius)
Definition: membfunc.hpp:124
void(*)(double *, int *, int *, int *, int, int, double *, Datum *, ThreadDatum *, NrnThread *, Memb_list *, double) bbcore_write_t
Definition: membfunc.hpp:218
void net_sem_from_gpu(int sendtype, int i_vdata, int, int ith, int ipnt, double, double)
Definition: netcvode.cpp:59
void nrn_jacob_capacitance(NrnThread *, Memb_list *, int)
Definition: capac.cpp:55
void artcell_net_send(void **, int, Point_process *, double, double)
Definition: netcvode.cpp:103
bool nrn_use_localgid_
void hoc_register_net_send_buffering(int)
void hoc_register_watch_check(nrn_watch_check_t, int)
void * hoc_Emalloc(size_t)
Definition: nrnoc_aux.cpp:80
int nrn_ion_global_map_size
void add_nrn_has_net_event(int)
short type
Definition: cabvars.h:10
static double efun(double x)
Definition: eion.cpp:341
static void * constructor(Object *ho)
Definition: seclist.cpp:52
static void destructor(void *v)
Definition: seclist.cpp:61
Definition: model.h:47
struct BAMech * next
Definition: membfunc.hpp:76
const char * name
Definition: membfunc.hpp:176
const char * name
Definition: membfunc.hpp:180
thread_table_check_t thread_table_check_
Definition: membfunc.hpp:50
void(* thread_mem_init_)(ThreadDatum *)
Definition: membfunc.hpp:48
void(* setdata_)(double *, Datum *)
Definition: membfunc.hpp:52
mod_alloc_t alloc
Definition: membfunc.hpp:33
mod_f_t private_destructor
Definition: membfunc.hpp:44
mod_f_t private_constructor
Definition: membfunc.hpp:43
void(* thread_cleanup_)(ThreadDatum *)
Definition: membfunc.hpp:49
const char * name
Definition: membfunc.hpp:185
void(* func)(void)
Definition: membfunc.hpp:186