NEURON
section.h
Go to the documentation of this file.
1 /* /local/src/master/nrn/src/nrnoc/section.h,v 1.4 1996/05/21 17:09:24 hines Exp */
2 #ifndef section_h
3 #define section_h
4 
5 /* In order to support oc objects containing sections, instead of vector
6  of ordered sections, we now have a list (in the nmodl sense)
7  of unordered sections. The lesser efficiency is ok because the
8  number crunching is vectorized. ie only the user interface deals
9  with sections and that needs to be convenient
10 */
11 /* Data structure for solving branching 1-D tree diffusion type equations.
12  Vector of ordered sections each of which points to a vector of nodes.
13  Each section must have at least one node. There may be 0 sections.
14  The order of last node to first node is used in triangularization.
15  First node to last is used in back substitution.
16  The first node of a section is connected to some node of a section
17  with lesser index.
18 */
19 /* An equation is associated with each node. d and rhs are the diagonal and
20  right hand side respectively. a is the effect of this node on the parent
21  node's equation. b is the effect of the parent node on this node's
22  equation.
23  d is assumed to be non-zero.
24  d and rhs is calculated from the property list.
25 */
26 
27 
28 #include "nrnredef.h"
29 #include "options.h"
30 #include "hoclist.h"
31 
32 /*#define DEBUGSOLVE 1*/
33 #define xpop hoc_xpop
34 #define pc hoc_pc
35 #define spop hoc_spop
36 #define execerror hoc_execerror
37 #include "hocdec.h"
38 
39 typedef struct Section {
40  int refcount; /* may be in more than one list */
41  short nnode; /* Number of nodes for ith section */
42  struct Section* parentsec; /* parent section of node 0 */
43  struct Section* child; /* root of the list of children
44  connected to this parent kept in
45  order of increasing x */
46  struct Section* sibling; /* used as list of sections that have same parent */
47 
48 
49  /* the parentnode is only valid when tree_changed = 0 */
50  struct Node* parentnode; /* parent node */
51  struct Node** pnode; /* Pointer to pointer vector of node structures */
52  int order; /* index of this in secorder vector */
53  short recalc_area_; /* NODEAREA, NODERINV, diam, L need recalculation */
54  short volatile_mark; /* for searching */
55  void* volatile_ptr; /* e.g. ShapeSection* */
56 #if DIAMLIST
57  short npt3d; /* number of 3-d points */
58  short pt3d_bsize; /* amount of allocated space for 3-d points */
59  struct Pt3d *pt3d; /* list of 3d points with diameter */
60  struct Pt3d *logical_connection; /* nil for legacy, otherwise specifies logical connection position (for translation) */
61 #endif
62  struct Prop *prop; /* eg. length, etc. */
63 } Section;
64 
65 #if DIAMLIST
66 typedef struct Pt3d {
67  float x,y,z,d; /* 3d point, microns */
68  double arc;
69 } Pt3d;
70 #endif
71 
72 #if METHOD3
73 typedef float NodeCoef;
74 typedef double NodeVal;
75 
76 typedef struct Info3Coef {
77  NodeVal current; /* for use in next time step */
78  NodeVal djdv0;
79  NodeCoef coef0; /* 5dx/12 */
80  NodeCoef coefn; /* 1dx/12 */
81  NodeCoef coefjdot; /* dx^2*ra/12 */
82  NodeCoef coefdg; /* dx/12 */
83  NodeCoef coefj; /* 1/(ra*dx) */
84  struct Node* nd2; /* the node dx away in the opposite direction*/
85 /* note above implies that nodes next to branches cannot have point processes
86 and still be third order correct. Also nodes next to branches cannot themselves
87 be branch points */
88 } Info3Coef;
89 
90 typedef struct Info3Val { /* storage to help build matrix efficiently */
91  NodeVal GC; /* doesn't include point processes */
92  NodeVal EC;
93  NodeCoef Cdt;
94 } Info3Val;
95 
96 /*METHOD3*/
97 #endif
98 
99 /* if any double is added after area then think about changing
100 the notify_free_val parameter in node_free in solve.cpp
101 */
102 
103 #define NODED(n) (*((n)->_d))
104 #define NODERHS(n) (*((n)->_rhs))
105 
106 #undef NODEV /* sparc-sun-solaris2.9 */
107 
108 #if CACHEVEC == 0
109 #define NODEA(n) ((n)->_a)
110 #define NODEB(n) ((n)->_b)
111 #define NODEV(n) ((n)->_v)
112 #define NODEAREA(n) ((n)->_area)
113 #else /* CACHEVEC */
114 #define NODEV(n) (*((n)->_v))
115 #define NODEAREA(n) ((n)->_area)
116 #define NODERINV(n) ((n)->_rinv)
117 #define VEC_A(i) (_nt->_actual_a[(i)])
118 #define VEC_B(i) (_nt->_actual_b[(i)])
119 #define VEC_D(i) (_nt->_actual_d[(i)])
120 #define VEC_RHS(i) (_nt->_actual_rhs[(i)])
121 #define VEC_V(i) (_nt->_actual_v[(i)])
122 #define VEC_AREA(i) (_nt->_actual_area[(i)])
123 #define NODEA(n) (VEC_A((n)->v_node_index))
124 #define NODEB(n) (VEC_B((n)->v_node_index))
125 #endif /* CACHEVEC */
126 
127 extern int use_sparse13;
128 extern int use_cachevec;
129 extern int secondorder;
130 extern int cvode_active_;
131 
132 typedef struct Node {
133 #if CACHEVEC == 0
134  double _v; /* membrane potential */
135  double _area; /* area in um^2 but see treesetup.cpp */
136  double _a; /* effect of node in parent equation */
137  double _b; /* effect of parent in node equation */
138 #else /* CACHEVEC */
139  double *_v; /* membrane potential */
140  double _area; /* area in um^2 but see treesetup.cpp */
141  double _rinv; /* conductance uS from node to parent */
142  double _v_temp; /* vile necessity til actual_v allocated */
143 #endif /* CACHEVEC */
144  double* _d; /* diagonal element in node equation */
145  double* _rhs; /* right hand side in node equation */
146  double* _a_matelm;
147  double* _b_matelm;
148  int eqn_index_; /* sparse13 matrix row/col index */
149  /* if no extnodes then = v_node_index +1*/
150  /* each extnode adds nlayer more equations after this */
151  struct Prop *prop; /* Points to beginning of property list */
152  Section* child; /* section connected to this node */
153  /* 0 means no other section connected */
154  Section* sec; /* section this node is in */
155 /* #if PARANEURON */
156  struct Node* _classical_parent; /* needed for multisplit */
157  struct NrnThread* _nt;
158 /* #endif */
159 #if EXTRACELLULAR
160  struct Extnode* extnode;
161 #endif
162 
163 #if EXTRAEQN
164  struct Eqnblock *eqnblock; /* hook to other equations which
165  need to be solved at the same time as the membrane
166  potential. eg. fast changeing ionic concentrations */
167 #endif /*MOREEQN*/
168 
169 #if DEBUGSOLVE
170  double savd;
171  double savrhs;
172 #endif /*DEBUGSOLVE*/
173 #if VECTORIZE
174  int v_node_index; /* only used to calculate parent_node_indices*/
175 #endif
176  int sec_node_index_; /* to calculate segment index from *Node */
177 #if METHOD3
178  Info3Coef toparent;
179  Info3Coef fromparent;
180  Info3Val thisnode;
181 #endif
182 } Node;
183 
184 #if EXTRACELLULAR
185 /* pruned to only work with sparse13 */
186 extern int nrn_nlayer_extracellular;
187 #define nlayer (nrn_nlayer_extracellular) /* first (0) layer is extracellular next to membrane */
188 typedef struct Extnode {
189  double *param; /* points to extracellular parameter vector */
190  /* v is membrane potential. so v internal = Node.v + Node.vext[0] */
191  /* However, the Node equation is for v internal. */
192  /* This is reconciled during update. */
193 
194  /* Following all have allocated size of nlayer */
195  double *v; /* v external. */
196  double *_a;
197  double *_b;
198  double* *_d;
199  double* *_rhs; /* d, rhs, a, and b are analogous to those in node */
200  double* *_a_matelm;
201  double* *_b_matelm;
202  double* *_x12; /* effect of v[layer] on eqn layer-1 (or internal)*/
203  double* *_x21; /* effect of v[layer-1 or internal] on eqn layer*/
204 } Extnode;
205 #endif
206 
207 #if !INCLUDEHOCH
208 #include "hocdec.h" /* Prop needs Datum and Datum needs Symbol */
209 #endif
210 
211 #define PROP_PY_INDEX 10
212 
213 typedef struct Prop {
214  struct Prop *next; /* linked list of properties */
215  short type; /* type of membrane, e.g. passive, HH, etc. */
216  short unused1; /* gcc and borland need pairs of shorts to align the same.*/
217  int param_size; /* for notifying hoc_free_val_array */
218  double *param; /* vector of doubles for this property */
219  Datum *dparam; /* usually vector of pointers to doubles
220  of other properties but maybe other things as well
221  for example one cable section property is a
222  symbol */
223  long _alloc_seq; /* for cache efficiency */
224  Object* ob; /* nil if normal property, otherwise the object containing the data*/
225 } Prop;
226 
227 #if defined(__cplusplus)
228 extern "C" {
229 #endif
230 
231 extern double* nrn_prop_data_alloc(int type, int count, Prop* p);
232 extern Datum* nrn_prop_datum_alloc(int type, int count, Prop* p);
233 extern void nrn_prop_data_free(int type, double* pd);
234 extern void nrn_prop_datum_free(int type, Datum* ppd);
235 extern Section* chk_access();
236 extern double nrn_ghk(double, double, double, double);
237 
238 
239 #if defined(__cplusplus)
240 }
241 #endif
242 
243 /* a point process is computed just like regular mechanisms. Ie it appears
244 in the property list whose type specifies which allocation, current, and
245 state functions to call. This means some nodes have more properties than
246 other nodes even in the same section. The Point_process structure allows
247 the interface to hoc variable names.
248 Each variable symbol u.rng->type refers to the point process mechanism.
249 The variable is treated as a vector
250 variable whose first index specifies "which one" of that mechanisms insertion
251 points we are talking about. Finally the variable u.rng->index tells us
252 where in the p-array to look. The number of point_process vectors is the
253 number of different point process types. This is different from the
254 mechanism type which enumerates all mechanisms including the point_processes.
255 It is the responsibility of create_point_process to set up the vectors and
256 fill in the symbol information. However only after the process is given
257 a location can the variables be set or accessed. This is because the
258 allocation function may have to connect to some ionic parameters and the
259 process exists primarily as a property of a node.
260 */
261 typedef struct Point_process {
262  Section *sec; /* section and node location for the point mechanism*/
264  Prop *prop; /* pointer to the actual property linked to the
265  node property list */
266  Object* ob; /* object that owns this process */
267  void* presyn_; /* non-threshold presynapse for NetCon */
268  void* nvi_; /* NrnVarIntegrator (for local step method) */
269  void* _vnt; /* NrnThread* (for NET_RECEIVE and multicore) */
270 } Point_process;
271 
272 #if EXTRAEQN
273 /*Blocks of equations can hang off each node of the current conservation
274 equations. These are equations which must be solved simultaneously
275 because they depend on the voltage and affect the voltage. An example
276 are fast changing ionic concentrations (or merely if we want to be
277 able to calculate steady states using a stable method).
278 */
279 typedef struct Eqnblock {
280  struct Eqnblock *eqnblock_next; /* may be several such blocks */
281  Pfri eqnblock_triang; /* triangularization function */
282  Pfri eqnblock_bksub; /* back substitution function */
283  double *eqnblock_data;
284 #if 0
285  the solving functions know how to find the following info from
286  the eqnblock_data.
287  double *eqnblock_row; /* current conservation depends on states */
288  double *eqnblock_col; /* state equations depend on voltage */
289  double *eqnblock_matrix; /* state equations depend on states */
290  double *eqnblock_rhs:
291  the functions merely take a pointer to the node and this Eqnblock
292  in order to update the values of the diagonal, v, and the rhs
293  The interface with EXTRACELLULAR makes things a bit more subtle.
294  It seems clear that we will have to change the meaning of v to
295  be membrane potential so that the internal potential is v + vext.
296  This will avoid requiring two rows and two columns since
297  the state equations will depend only on v and not vext.
298  In fact, if vext did not have longitudinal relationships with
299  other vext the extracellular mechanism could be implemented in
300  this style.
301 #endif
302 } Eqnblock;
303 #endif /*EXTRAEQN*/
304 
305 extern int nrn_global_ncell; /* note that for multiple threads all the rootnodes are no longer contiguous */
306 extern hoc_List* section_list; /* Where the Sections live */
307 
308 extern Section *sec_alloc(); /* Allocates a single section */
309 extern void node_alloc(Section*, short); /* Allocates node vectors in a section*/
310 extern double section_length(Section*), nrn_diameter(Node*);
311 extern Node* nrn_parent_node(Node*);
312 extern Section* nrn_section_alloc();
313 extern void nrn_section_free(Section*);
314 extern int nrn_is_valid_section_ptr(void*);
315 
316 /* loop over sections. Must previously declare Item* qsec. Contains the {! */
317 #define ForAllSections(sec) \
318  ITERATE(qsec, section_list) { Section* sec = hocSEC(qsec);
319 
320 #if METHOD3
321 extern int _method3;
322 #endif
323 
324 #include <multicore.h>
325 
326 extern int stoprun;
327 #define tstopbit (1 << 15)
328 #define tstopset stoprun |= tstopbit
329 #define tstopunset stoprun &= (~tstopbit)
330 /* cvode.event(tevent) sets this. Reset at beginning */
331 /* of any hoc call for integration and before returning to hoc */
332 
333 
334 
335 #include "nrn_ansi.h"
336 
337 #endif
338 
339 
double * v
Definition: section.h:195
int param_size
Definition: section.h:217
double * param
Definition: section.h:218
struct Prop * prop
Definition: section.h:62
float z
Definition: section.h:67
short type
Definition: cabvars.h:10
short nnode
Definition: section.h:41
void * _vnt
Definition: section.h:269
struct Node * parentnode
Definition: section.h:50
struct Section * parentsec
Definition: section.h:42
struct Point_process Point_process
struct Section * sibling
Definition: section.h:46
double ** _x21
Definition: section.h:203
Definition: section.h:66
short npt3d
Definition: section.h:57
struct Prop Prop
double ** _b_matelm
Definition: section.h:201
size_t p
Represent main neuron object computed by single thread.
Definition: multicore.h:58
int nrn_nlayer_extracellular
Definition: extcelln.cpp:18
double ** _d
Definition: section.h:198
static void update(NrnThread *)
Definition: fadvance.cpp:570
Object * ob
Definition: section.h:224
double * nrn_prop_data_alloc(int type, int count, Prop *p)
Definition: cxprop.cpp:262
struct Node * _classical_parent
Definition: section.h:156
long _alloc_seq
Definition: section.h:223
#define v
Definition: md1redef.h:4
void nrn_prop_datum_free(int type, Datum *ppd)
Definition: cxprop.cpp:294
#define thisnode
Definition: md1redef.h:6
struct Node Node
double * _b
Definition: section.h:197
static List * info
struct Pt3d * logical_connection
Definition: section.h:60
Node * node
Definition: section.h:263
short type
Definition: section.h:215
short volatile_mark
Definition: section.h:54
int use_sparse13
Definition: treeset.cpp:69
double _rinv
Definition: section.h:141
struct Pt3d * pt3d
Definition: section.h:59
static void take(HCONV hc, const char *name)
Definition: ms1.cpp:56
Section * sec_alloc()
Definition: solve.cpp:461
void * presyn_
Definition: section.h:267
int(* Pfri)(void)
Definition: hocdec.h:39
double * _a
Definition: section.h:196
Section * chk_access()
Definition: cabcode.cpp:437
double ** _x12
Definition: section.h:202
double arc
Definition: section.h:68
Prop * prop
Definition: section.h:264
void nrn_section_free(Section *)
Definition: cxprop.cpp:312
static VoidFunc functions[]
Definition: hocmodl.h:4
struct NrnThread * _nt
Definition: section.h:157
int secondorder
Definition: init.cpp:120
double * _b_matelm
Definition: section.h:147
double * _a_matelm
Definition: section.h:146
double nrn_diameter(Node *)
Definition: cabcode.cpp:423
short unused1
Definition: section.h:216
Section * sec
Definition: section.h:262
int nrn_global_ncell
Definition: init.cpp:127
Node * nrn_parent_node(Node *)
Definition: treeset.cpp:830
Definition: section.h:213
Section * child
Definition: section.h:152
void * volatile_ptr
Definition: section.h:55
int use_cachevec
Definition: treeset.cpp:61
Object * ob
Definition: section.h:266
struct Section * child
Definition: section.h:43
Datum * dparam
Definition: section.h:219
struct Extnode Extnode
#define rhs
Definition: lineq.h:6
Section * nrn_section_alloc()
Definition: cxprop.cpp:305
double * param
Definition: section.h:189
#define GC
Definition: md1redef.h:7
static List * current
Definition: nrnunit.cpp:12
struct Pt3d Pt3d
int v_node_index
Definition: section.h:174
hoc_List * section_list
Definition: init.cpp:126
Section * sec
Definition: section.h:154
double _v_temp
Definition: section.h:142
Definition: hocdec.h:226
double nrn_ghk(double, double, double, double)
Definition: eion.cpp:321
double * _d
Definition: section.h:144
int nrn_is_valid_section_ptr(void *)
Definition: cxprop.cpp:316
void * nvi_
Definition: section.h:268
double _area
Definition: section.h:140
struct Prop * next
Definition: section.h:214
void nrn_prop_data_free(int type, double *pd)
Definition: cxprop.cpp:287
double * _rhs
Definition: section.h:145
short pt3d_bsize
Definition: section.h:58
struct Node ** pnode
Definition: section.h:51
int cvode_active_
Definition: fadvance.cpp:158
double ** _a_matelm
Definition: section.h:200
int find(const int, const int, const int, const int, const int)
void node_alloc(Section *, short)
Definition: solve.cpp:814
int sec_node_index_
Definition: section.h:176
double section_length(Section *)
Definition: cabcode.cpp:375
int stoprun
Definition: fadvance.cpp:161
double ** _rhs
Definition: section.h:199
int order
Definition: section.h:52
int refcount
Definition: section.h:40
static Node * node(Object *)
Definition: netcvode.cpp:318
Datum * nrn_prop_datum_alloc(int type, int count, Prop *p)
Definition: cxprop.cpp:273
Definition: section.h:132
Definition: hocdec.h:176
int eqn_index_
Definition: section.h:148
struct Extnode * extnode
Definition: section.h:160
#define EC
Definition: md1redef.h:8
struct Section Section
short recalc_area_
Definition: section.h:53
struct Prop * prop
Definition: section.h:151
double * _v
Definition: section.h:139