NEURON
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<std::vector<int>> nrn_array_dims;
94  std::vector<int> nrn_prop_param_size;
95  std::vector<int> nrn_prop_dparam_size;
96  std::vector<int> nrn_mech_data_layout; /* 1 AoS (default), 0 SoA */
97  /* array is parallel to memb_func. All are 0 except 1 for ARTIFICIAL_CELL */
98  std::vector<short> nrn_artcell_qindex;
99  std::vector<bool> nrn_is_artificial;
100 
101  /**
102  * Net Receive function pointer lookup tables
103  */
104  std::vector<pnt_receive_t> pnt_receive; /* for synaptic events. */
105  std::vector<pnt_receive_t> pnt_receive_init;
106  std::vector<short> pnt_receive_size;
107 
108  /**
109  * Holds function pointers for WATCH callback
110  */
111  std::vector<nrn_watch_check_t> nrn_watch_check;
112 
113  /**
114  * values are type numbers of mechanisms which do net_send call
115  * related to NMODL net_event()
116  *
117  */
118  std::vector<int> nrn_has_net_event;
119 
120  /**
121  * inverse of nrn_has_net_event_ maps the values of nrn_has_net_event_ to the index of
122  * ptntype2presyn
123  */
124  std::vector<int> pnttype2presyn;
125 
126 
127  std::vector<bbcore_read_t> nrn_bbcore_read;
128  std::vector<bbcore_write_t> nrn_bbcore_write;
129 
130  public:
131  auto& get_memb_funcs() {
132  return memb_funcs;
133  }
134 
135  auto& get_memb_func(size_t idx) {
136  return memb_funcs[idx];
137  }
138 
141  }
142 
143  auto& get_pnt_map() {
144  return pnt_map;
145  }
146 
148  return ion_write_dependency;
149  }
150 
152  return net_buf_receive;
153  }
154 
156  return net_buf_send_type;
157  }
158 
159  auto& get_bamech() {
160  return bamech;
161  }
162 
163  auto& get_array_dims() {
164  return nrn_array_dims;
165  }
166 
168  return nrn_prop_param_size;
169  }
170 
172  return nrn_prop_dparam_size;
173  }
174 
176  return nrn_mech_data_layout;
177  }
178 
180  return nrn_is_artificial;
181  }
182 
184  return nrn_artcell_qindex;
185  }
186 
187  auto& get_pnt_receive() {
188  return pnt_receive;
189  }
190 
192  return pnt_receive_init;
193  }
194 
196  return pnt_receive_size;
197  }
198 
199  auto& get_watch_check() {
200  return nrn_watch_check;
201  }
202 
204  return nrn_has_net_event;
205  }
206 
208  return pnttype2presyn;
209  }
210 
211  auto& get_bbcore_read() {
212  return nrn_bbcore_read;
213  }
214 
216  return nrn_bbcore_write;
217  }
218 };
219 
220 extern CoreNeuron corenrn;
221 
222 } // namespace coreneuron
A class representing the CoreNEURON state, holding pointers to the various data structures.
Definition: coreneuron.hpp:56
auto & get_memb_func(size_t idx)
Definition: coreneuron.hpp:135
std::vector< char > pnt_map
map if mech is a point process In the future only a field of Mechanism class
Definition: coreneuron.hpp:61
std::vector< int > nrn_prop_param_size
Definition: coreneuron.hpp:94
std::vector< bbcore_read_t > nrn_bbcore_read
Definition: coreneuron.hpp:127
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:124
auto & get_net_buf_send_type()
Definition: coreneuron.hpp:155
DependencyTable ion_write_dependency
dependency helper filled by calls to hoc_register_dparam_semantics used when nrn_mech_depend is calle...
Definition: coreneuron.hpp:73
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:118
auto & get_ion_write_dependency()
Definition: coreneuron.hpp:147
std::array< BAMech *, BEFORE_AFTER_SIZE > bamech
before-after-blocks from nmodl are registered here as function pointers
Definition: coreneuron.hpp:87
std::vector< std::vector< int > > nrn_array_dims
Internal lookup tables.
Definition: coreneuron.hpp:93
auto & get_different_mechanism_type()
Definition: coreneuron.hpp:139
std::vector< int > nrn_prop_dparam_size
Definition: coreneuron.hpp:95
std::vector< pnt_receive_t > pnt_receive_init
Definition: coreneuron.hpp:105
std::vector< Memb_func > memb_funcs
Definition: coreneuron.hpp:75
std::vector< int > nrn_mech_data_layout
Definition: coreneuron.hpp:96
std::vector< pnt_receive_t > pnt_receive
Net Receive function pointer lookup tables.
Definition: coreneuron.hpp:104
std::vector< short > pnt_receive_size
Definition: coreneuron.hpp:106
std::vector< bbcore_write_t > nrn_bbcore_write
Definition: coreneuron.hpp:128
std::vector< bool > nrn_is_artificial
Definition: coreneuron.hpp:99
std::vector< int > net_buf_send_type
Definition: coreneuron.hpp:82
std::vector< short > nrn_artcell_qindex
Definition: coreneuron.hpp:98
std::vector< nrn_watch_check_t > nrn_watch_check
Holds function pointers for WATCH callback.
Definition: coreneuron.hpp:111
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:81
std::vector< int > different_mechanism_type
Vector mapping the types (IDs) of different mechanisms of mod files between NEURON and CoreNEURON.
Definition: coreneuron.hpp:66
#define pdata
Definition: md1redef.h:37
THIS FILE IS AUTO GENERATED DONT MODIFY IT.
void nrn_init_ion(NrnThread *, Memb_list *, int)
void nrn_cur_capacitance(NrnThread *_nt, Memb_list *ml, int type)
Definition: capac.cpp:98
std::vector< std::vector< int > > DependencyTable
Definition: coreneuron.hpp:47
void second_order_cur(NrnThread *_nt, int secondorder)
int Datum
Definition: nrnconf.h:23
void nrn_alloc_capacitance(double *data, Datum *pdata, int type)
Definition: capac.cpp:127
void nrn_alloc_ion(double *data, Datum *pdata, int type)
CoreNeuron corenrn
Definition: multicore.cpp:53
void nrn_init_capacitance(NrnThread *, Memb_list *, int)
Definition: capac.cpp:80
void nrn_cur_ion(NrnThread *_nt, Memb_list *ml, int type)
short type
Definition: cabvars.h:10
A view into a set of mechanism instances.
Definition: nrnoc_ml.h:34
Represent main neuron object computed by single thread.
Definition: multicore.h:58
Non-template stable handle to a generic value.