CoreNEURON
coreneuron.hpp
Go to the documentation of this file.
1 /*
2 # =============================================================================
3 # Copyright (c) 2016 - 2021 Blue Brain Project/EPFL
4 #
5 # See top-level LICENSE file for details.
6 # =============================================================================.
7 */
8 #pragma once
9 
10 /***
11  * Includes all headers required to communicate and run all methods
12  * described in CoreNEURON, neurox, and mod2c C-generated mechanisms
13  * functions.
14  **/
15 
16 
17 #include <cstdio>
18 #include <cstdlib>
19 #include <cmath>
20 #include <string.h>
21 #include <vector>
22 #include <array>
23 
24 #include "coreneuron/utils/randoms/nrnran123.h" //Random Number Generator
25 #include "coreneuron/sim/scopmath/newton_struct.h" //Newton Struct
26 #include "coreneuron/membrane_definitions.h" //static definitions
27 #include "coreneuron/mechanism/mechanism.hpp" //Memb_list and mechs info
28 
29 #include "coreneuron/utils/memory.h" //Memory alignments and padding
30 #include "coreneuron/nrnconf.h"
33 
34 namespace coreneuron {
35 
36 // from nrnoc/capac.c
37 extern void nrn_init_capacitance(NrnThread*, Memb_list*, int);
38 extern void nrn_cur_capacitance(NrnThread* _nt, Memb_list* ml, int type);
39 extern void nrn_alloc_capacitance(double* data, Datum* pdata, int type);
40 
41 // from nrnoc/eion.c
42 extern void nrn_init_ion(NrnThread*, Memb_list*, int);
43 extern void nrn_cur_ion(NrnThread* _nt, Memb_list* ml, int type);
44 extern void nrn_alloc_ion(double* data, Datum* pdata, int type);
45 extern void second_order_cur(NrnThread* _nt, int secondorder);
46 
47 using DependencyTable = std::vector<std::vector<int>>;
48 
49 /**
50  * A class representing the CoreNEURON state, holding pointers to the various data structures
51  *
52  * The pointers to "global" data such as the NrnThread, Memb_list and Memb_func data structures
53  * are managed here. they logically share their lifetime and runtime scope with instances of
54  * this class.
55  */
56 class CoreNeuron {
57  /**
58  * map if mech is a point process
59  * In the future only a field of Mechanism class
60  */
61  std::vector<char> pnt_map; /* so prop_free can know its a point mech*/
62 
63  /** Vector mapping the types (IDs) of different mechanisms of mod files between NEURON and
64  * CoreNEURON
65  */
66  std::vector<int> different_mechanism_type;
67 
68  /**
69  * dependency helper filled by calls to hoc_register_dparam_semantics
70  * used when nrn_mech_depend is called
71  * vector-of-vector DS. First idx is the mech, second idx is the dependent mech.
72  */
74 
75  std::vector<Memb_func> memb_funcs;
76 
77  /**
78  * Net send / Net receive
79  * only used in CoreNEURON for book keeping synapse mechs, should go into CoreNEURON class
80  */
81  std::vector<std::pair<NetBufReceive_t, int>> net_buf_receive;
82  std::vector<int> net_buf_send_type;
83 
84  /**
85  * before-after-blocks from nmodl are registered here as function pointers
86  */
87  std::array<BAMech*, BEFORE_AFTER_SIZE> bamech;
88 
89  /**
90  * Internal lookup tables. Number of float and int variables in each mechanism and memory layout
91  * future --> mech class
92  */
93  std::vector<int> nrn_prop_param_size;
94  std::vector<int> nrn_prop_dparam_size;
95  std::vector<int> nrn_mech_data_layout; /* 1 AoS (default), 0 SoA */
96  /* array is parallel to memb_func. All are 0 except 1 for ARTIFICIAL_CELL */
97  std::vector<short> nrn_artcell_qindex;
98  std::vector<bool> nrn_is_artificial;
99 
100  /**
101  * Net Receive function pointer lookup tables
102  */
103  std::vector<pnt_receive_t> pnt_receive; /* for synaptic events. */
104  std::vector<pnt_receive_t> pnt_receive_init;
105  std::vector<short> pnt_receive_size;
106 
107  /**
108  * Holds function pointers for WATCH callback
109  */
110  std::vector<nrn_watch_check_t> nrn_watch_check;
111 
112  /**
113  * values are type numbers of mechanisms which do net_send call
114  * related to NMODL net_event()
115  *
116  */
117  std::vector<int> nrn_has_net_event;
118 
119  /**
120  * inverse of nrn_has_net_event_ maps the values of nrn_has_net_event_ to the index of
121  * ptntype2presyn
122  */
123  std::vector<int> pnttype2presyn;
124 
125 
126  std::vector<bbcore_read_t> nrn_bbcore_read;
127  std::vector<bbcore_write_t> nrn_bbcore_write;
128 
129  public:
130  auto& get_memb_funcs() {
131  return memb_funcs;
132  }
133 
134  auto& get_memb_func(size_t idx) {
135  return memb_funcs[idx];
136  }
137 
140  }
141 
142  auto& get_pnt_map() {
143  return pnt_map;
144  }
145 
147  return ion_write_dependency;
148  }
149 
151  return net_buf_receive;
152  }
153 
155  return net_buf_send_type;
156  }
157 
158  auto& get_bamech() {
159  return bamech;
160  }
161 
163  return nrn_prop_param_size;
164  }
165 
167  return nrn_prop_dparam_size;
168  }
169 
171  return nrn_mech_data_layout;
172  }
173 
175  return nrn_is_artificial;
176  }
177 
179  return nrn_artcell_qindex;
180  }
181 
182  auto& get_pnt_receive() {
183  return pnt_receive;
184  }
185 
187  return pnt_receive_init;
188  }
189 
191  return pnt_receive_size;
192  }
193 
194  auto& get_watch_check() {
195  return nrn_watch_check;
196  }
197 
199  return nrn_has_net_event;
200  }
201 
203  return pnttype2presyn;
204  }
205 
206  auto& get_bbcore_read() {
207  return nrn_bbcore_read;
208  }
209 
211  return nrn_bbcore_write;
212  }
213 };
214 
215 extern CoreNeuron corenrn;
216 
217 } // namespace coreneuron
coreneuron::CoreNeuron::memb_funcs
std::vector< Memb_func > memb_funcs
Definition: coreneuron.hpp:79
coreneuron::CoreNeuron::get_mech_data_layout
auto & get_mech_data_layout()
Definition: coreneuron.hpp:174
mechanism.hpp
coreneuron::CoreNeuron::nrn_has_net_event
std::vector< int > nrn_has_net_event
values are type numbers of mechanisms which do net_send call related to NMODL net_event()
Definition: coreneuron.hpp:121
coreneuron::CoreNeuron::pnt_receive_init
std::vector< pnt_receive_t > pnt_receive_init
Definition: coreneuron.hpp:108
nrnran123.h
coreneuron::CoreNeuron::pnt_receive_size
std::vector< short > pnt_receive_size
Definition: coreneuron.hpp:109
coreneuron::nrn_cur_ion
void nrn_cur_ion(NrnThread *_nt, Memb_list *ml, int type)
coreneuron::Datum
int Datum
Definition: nrnconf.h:23
coreneuron::CoreNeuron::get_net_buf_send_type
auto & get_net_buf_send_type()
Definition: coreneuron.hpp:158
data
Definition: alignment.cpp:18
coreneuron::CoreNeuron::pnttype2presyn
std::vector< int > pnttype2presyn
inverse of nrn_has_net_event_ maps the values of nrn_has_net_event_ to the index of ptntype2presyn
Definition: coreneuron.hpp:127
coreneuron::CoreNeuron::get_is_artificial
auto & get_is_artificial()
Definition: coreneuron.hpp:178
coreneuron::CoreNeuron::get_memb_func
auto & get_memb_func(size_t idx)
Definition: coreneuron.hpp:138
coreneuron::CoreNeuron::ion_write_dependency
DependencyTable ion_write_dependency
dependency helper filled by calls to hoc_register_dparam_semantics used when nrn_mech_depend is calle...
Definition: coreneuron.hpp:77
coreneuron::nrn_init_ion
void nrn_init_ion(NrnThread *, Memb_list *, int)
coreneuron::CoreNeuron::get_bbcore_write
auto & get_bbcore_write()
Definition: coreneuron.hpp:214
coreneuron::CoreNeuron::nrn_mech_data_layout
std::vector< int > nrn_mech_data_layout
Definition: coreneuron.hpp:99
coreneuron::CoreNeuron::different_mechanism_type
std::vector< int > different_mechanism_type
Vector mapping the types (IDs) of different mechanisms of mod files between NEURON and CoreNEURON.
Definition: coreneuron.hpp:70
coreneuron::CoreNeuron::nrn_bbcore_write
std::vector< bbcore_write_t > nrn_bbcore_write
Definition: coreneuron.hpp:131
coreneuron::CoreNeuron::nrn_bbcore_read
std::vector< bbcore_read_t > nrn_bbcore_read
Definition: coreneuron.hpp:130
coreneuron::CoreNeuron::nrn_artcell_qindex
std::vector< short > nrn_artcell_qindex
Definition: coreneuron.hpp:101
pdata
#define pdata
Definition: md1redef.h:37
coreneuron::CoreNeuron::get_ion_write_dependency
auto & get_ion_write_dependency()
Definition: coreneuron.hpp:150
coreneuron
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
Definition: corenrn_parameters.cpp:12
coreneuron::CoreNeuron::pnt_receive
std::vector< pnt_receive_t > pnt_receive
Net Receive function pointer lookup tables.
Definition: coreneuron.hpp:107
mech_mapping.hpp
coreneuron::CoreNeuron::get_prop_dparam_size
auto & get_prop_dparam_size()
Definition: coreneuron.hpp:170
coreneuron::CoreNeuron::nrn_is_artificial
std::vector< bool > nrn_is_artificial
Definition: coreneuron.hpp:102
coreneuron::CoreNeuron::get_memb_funcs
auto & get_memb_funcs()
Definition: coreneuron.hpp:134
coreneuron::CoreNeuron::get_has_net_event
auto & get_has_net_event()
Definition: coreneuron.hpp:202
coreneuron::CoreNeuron::get_bbcore_read
auto & get_bbcore_read()
Definition: coreneuron.hpp:210
coreneuron::CoreNeuron::get_watch_check
auto & get_watch_check()
Definition: coreneuron.hpp:198
coreneuron::DependencyTable
std::vector< std::vector< int > > DependencyTable
Definition: coreneuron.hpp:51
coreneuron::CoreNeuron::nrn_prop_param_size
std::vector< int > nrn_prop_param_size
Internal lookup tables.
Definition: coreneuron.hpp:97
coreneuron::CoreNeuron::nrn_prop_dparam_size
std::vector< int > nrn_prop_dparam_size
Definition: coreneuron.hpp:98
newton_struct.h
coreneuron::CoreNeuron::get_artcell_qindex
auto & get_artcell_qindex()
Definition: coreneuron.hpp:182
coreneuron::CoreNeuron::get_pnt_receive_init
auto & get_pnt_receive_init()
Definition: coreneuron.hpp:190
coreneuron::corenrn
CoreNeuron corenrn
Definition: multicore.cpp:53
coreneuron::CoreNeuron::nrn_watch_check
std::vector< nrn_watch_check_t > nrn_watch_check
Holds function pointers for WATCH callback.
Definition: coreneuron.hpp:114
coreneuron::nrn_alloc_capacitance
void nrn_alloc_capacitance(double *data, Datum *pdata, int type)
Definition: capac.cpp:130
coreneuron::nrn_init_capacitance
void nrn_init_capacitance(NrnThread *, Memb_list *, int)
Definition: capac.cpp:83
membrane_definitions.h
coreneuron::CoreNeuron::get_net_buf_receive
auto & get_net_buf_receive()
Definition: coreneuron.hpp:154
coreneuron::CoreNeuron::get_different_mechanism_type
auto & get_different_mechanism_type()
Definition: coreneuron.hpp:142
coreneuron::second_order_cur
void second_order_cur(NrnThread *_nt, int secondorder)
nrnconf.h
coreneuron::nrn_cur_capacitance
void nrn_cur_capacitance(NrnThread *_nt, Memb_list *ml, int type)
Definition: capac.cpp:101
coreneuron::CoreNeuron::bamech
std::array< BAMech *, BEFORE_AFTER_SIZE > bamech
before-after-blocks from nmodl are registered here as function pointers
Definition: coreneuron.hpp:91
coreneuron::CoreNeuron::get_pnt_map
auto & get_pnt_map()
Definition: coreneuron.hpp:146
multicore.hpp
coreneuron::CoreNeuron::get_prop_param_size
auto & get_prop_param_size()
Definition: coreneuron.hpp:166
coreneuron::secondorder
int secondorder
Definition: register_mech.cpp:21
coreneuron::CoreNeuron::net_buf_send_type
std::vector< int > net_buf_send_type
Definition: coreneuron.hpp:86
coreneuron::nrn_alloc_ion
void nrn_alloc_ion(double *data, Datum *pdata, int type)
coreneuron::CoreNeuron::get_bamech
auto & get_bamech()
Definition: coreneuron.hpp:162
coreneuron::CoreNeuron::net_buf_receive
std::vector< std::pair< NetBufReceive_t, int > > net_buf_receive
Net send / Net receive only used in CoreNEURON for book keeping synapse mechs, should go into CoreNEU...
Definition: coreneuron.hpp:85
coreneuron::CoreNeuron
A class representing the CoreNEURON state, holding pointers to the various data structures.
Definition: coreneuron.hpp:60
coreneuron::CoreNeuron::get_pnttype2presyn
auto & get_pnttype2presyn()
Definition: coreneuron.hpp:206
memory.h
coreneuron::CoreNeuron::get_pnt_receive_size
auto & get_pnt_receive_size()
Definition: coreneuron.hpp:194
coreneuron::CoreNeuron::pnt_map
std::vector< char > pnt_map
map if mech is a point process In the future only a field of Mechanism class
Definition: coreneuron.hpp:65
coreneuron::CoreNeuron::get_pnt_receive
auto & get_pnt_receive()
Definition: coreneuron.hpp:186