Skip to content

Commit ad9d3d0

Browse files
author
GitHub Actions Bot
committed
References for 'nmodl@a8f1829501d0d3a4e6680823b0f0bb4fb718ca30'.
1 parent 9e7f023 commit ad9d3d0

File tree

7 files changed

+774
-15
lines changed

7 files changed

+774
-15
lines changed
Lines changed: 343 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,343 @@
1+
/*********************************************************
2+
Model Name : func_in_breakpoint
3+
Filename : func_in_breakpoint.mod
4+
NMODL Version : 7.7.0
5+
Vectorized : true
6+
Threadsafe : true
7+
Created : DATE
8+
Simulator : CoreNEURON
9+
Backend : C++ (api-compatibility)
10+
NMODL Compiler : VERSION
11+
*********************************************************/
12+
13+
#include <math.h>
14+
#include <stdio.h>
15+
#include <stdlib.h>
16+
#include <string.h>
17+
18+
#include <coreneuron/gpu/nrn_acc_manager.hpp>
19+
#include <coreneuron/mechanism/mech/mod2c_core_thread.hpp>
20+
#include <coreneuron/mechanism/register_mech.hpp>
21+
#include <coreneuron/nrnconf.h>
22+
#include <coreneuron/nrniv/nrniv_decl.h>
23+
#include <coreneuron/sim/multicore.hpp>
24+
#include <coreneuron/sim/scopmath/newton_thread.hpp>
25+
#include <coreneuron/utils/ivocvect.hpp>
26+
#include <coreneuron/utils/nrnoc_aux.hpp>
27+
#include <coreneuron/utils/randoms/nrnran123.h>
28+
29+
30+
namespace coreneuron {
31+
#ifndef NRN_PRCELLSTATE
32+
#define NRN_PRCELLSTATE 0
33+
#endif
34+
35+
36+
/** channel information */
37+
static const char *mechanism_info[] = {
38+
"7.7.0",
39+
"func_in_breakpoint",
40+
0,
41+
"il_func_in_breakpoint",
42+
0,
43+
0,
44+
0
45+
};
46+
47+
48+
/** all global variables */
49+
struct func_in_breakpoint_Store {
50+
int reset{};
51+
int mech_type{};
52+
double c{1};
53+
};
54+
static_assert(std::is_trivially_copy_constructible_v<func_in_breakpoint_Store>);
55+
static_assert(std::is_trivially_move_constructible_v<func_in_breakpoint_Store>);
56+
static_assert(std::is_trivially_copy_assignable_v<func_in_breakpoint_Store>);
57+
static_assert(std::is_trivially_move_assignable_v<func_in_breakpoint_Store>);
58+
static_assert(std::is_trivially_destructible_v<func_in_breakpoint_Store>);
59+
func_in_breakpoint_Store func_in_breakpoint_global;
60+
61+
62+
/** all mechanism instance variables and global variables */
63+
struct func_in_breakpoint_Instance {
64+
double* il{};
65+
double* v_unused{};
66+
double* g_unused{};
67+
func_in_breakpoint_Store* global{&func_in_breakpoint_global};
68+
};
69+
70+
71+
/** connect global (scalar) variables to hoc -- */
72+
static DoubScal hoc_scalar_double[] = {
73+
{"c_func_in_breakpoint", &func_in_breakpoint_global.c},
74+
{nullptr, nullptr}
75+
};
76+
77+
78+
/** connect global (array) variables to hoc -- */
79+
static DoubVec hoc_vector_double[] = {
80+
{nullptr, nullptr, 0}
81+
};
82+
83+
84+
static inline int first_pointer_var_index() {
85+
return -1;
86+
}
87+
88+
89+
static inline int first_random_var_index() {
90+
return -1;
91+
}
92+
93+
94+
static inline int float_variables_size() {
95+
return 3;
96+
}
97+
98+
99+
static inline int int_variables_size() {
100+
return 0;
101+
}
102+
103+
104+
static inline int get_mech_type() {
105+
return func_in_breakpoint_global.mech_type;
106+
}
107+
108+
109+
static inline Memb_list* get_memb_list(NrnThread* nt) {
110+
if (!nt->_ml_list) {
111+
return nullptr;
112+
}
113+
return nt->_ml_list[get_mech_type()];
114+
}
115+
116+
117+
static inline void* mem_alloc(size_t num, size_t size, size_t alignment = 16) {
118+
void* ptr;
119+
posix_memalign(&ptr, alignment, num*size);
120+
memset(ptr, 0, size);
121+
return ptr;
122+
}
123+
124+
125+
static inline void mem_free(void* ptr) {
126+
free(ptr);
127+
}
128+
129+
130+
static inline void coreneuron_abort() {
131+
abort();
132+
}
133+
134+
// Allocate instance structure
135+
static void nrn_private_constructor_func_in_breakpoint(NrnThread* nt, Memb_list* ml, int type) {
136+
assert(!ml->instance);
137+
assert(!ml->global_variables);
138+
assert(ml->global_variables_size == 0);
139+
auto* const inst = new func_in_breakpoint_Instance{};
140+
assert(inst->global == &func_in_breakpoint_global);
141+
ml->instance = inst;
142+
ml->global_variables = inst->global;
143+
ml->global_variables_size = sizeof(func_in_breakpoint_Store);
144+
}
145+
146+
// Deallocate the instance structure
147+
static void nrn_private_destructor_func_in_breakpoint(NrnThread* nt, Memb_list* ml, int type) {
148+
auto* const inst = static_cast<func_in_breakpoint_Instance*>(ml->instance);
149+
assert(inst);
150+
assert(inst->global);
151+
assert(inst->global == &func_in_breakpoint_global);
152+
assert(inst->global == ml->global_variables);
153+
assert(ml->global_variables_size == sizeof(func_in_breakpoint_Store));
154+
delete inst;
155+
ml->instance = nullptr;
156+
ml->global_variables = nullptr;
157+
ml->global_variables_size = 0;
158+
}
159+
160+
/** initialize mechanism instance variables */
161+
static inline void setup_instance(NrnThread* nt, Memb_list* ml) {
162+
auto* const inst = static_cast<func_in_breakpoint_Instance*>(ml->instance);
163+
assert(inst);
164+
assert(inst->global);
165+
assert(inst->global == &func_in_breakpoint_global);
166+
assert(inst->global == ml->global_variables);
167+
assert(ml->global_variables_size == sizeof(func_in_breakpoint_Store));
168+
int pnodecount = ml->_nodecount_padded;
169+
Datum* indexes = ml->pdata;
170+
inst->il = ml->data+0*pnodecount;
171+
inst->v_unused = ml->data+1*pnodecount;
172+
inst->g_unused = ml->data+2*pnodecount;
173+
}
174+
175+
176+
177+
static void nrn_alloc_func_in_breakpoint(double* data, Datum* indexes, int type) {
178+
// do nothing
179+
}
180+
181+
182+
void nrn_constructor_func_in_breakpoint(NrnThread* nt, Memb_list* ml, int type) {
183+
#ifndef CORENEURON_BUILD
184+
int nodecount = ml->nodecount;
185+
int pnodecount = ml->_nodecount_padded;
186+
const int* node_index = ml->nodeindices;
187+
double* data = ml->data;
188+
const double* voltage = nt->_actual_v;
189+
Datum* indexes = ml->pdata;
190+
ThreadDatum* thread = ml->_thread;
191+
auto* const inst = static_cast<func_in_breakpoint_Instance*>(ml->instance);
192+
193+
#endif
194+
}
195+
196+
197+
void nrn_destructor_func_in_breakpoint(NrnThread* nt, Memb_list* ml, int type) {
198+
#ifndef CORENEURON_BUILD
199+
int nodecount = ml->nodecount;
200+
int pnodecount = ml->_nodecount_padded;
201+
const int* node_index = ml->nodeindices;
202+
double* data = ml->data;
203+
const double* voltage = nt->_actual_v;
204+
Datum* indexes = ml->pdata;
205+
ThreadDatum* thread = ml->_thread;
206+
auto* const inst = static_cast<func_in_breakpoint_Instance*>(ml->instance);
207+
208+
#endif
209+
}
210+
211+
212+
inline int func_func_in_breakpoint(int id, int pnodecount, func_in_breakpoint_Instance* inst, double* data, const Datum* indexes, ThreadDatum* thread, NrnThread* nt, double v);
213+
inline int func_with_v_func_in_breakpoint(int id, int pnodecount, func_in_breakpoint_Instance* inst, double* data, const Datum* indexes, ThreadDatum* thread, NrnThread* nt, double v, double arg_v);
214+
inline int func_with_other_func_in_breakpoint(int id, int pnodecount, func_in_breakpoint_Instance* inst, double* data, const Datum* indexes, ThreadDatum* thread, NrnThread* nt, double v, double q);
215+
216+
217+
inline int func_func_in_breakpoint(int id, int pnodecount, func_in_breakpoint_Instance* inst, double* data, const Datum* indexes, ThreadDatum* thread, NrnThread* nt, double v) {
218+
int ret_func = 0;
219+
return ret_func;
220+
}
221+
222+
223+
inline int func_with_v_func_in_breakpoint(int id, int pnodecount, func_in_breakpoint_Instance* inst, double* data, const Datum* indexes, ThreadDatum* thread, NrnThread* nt, double v, double arg_v) {
224+
int ret_func_with_v = 0;
225+
return ret_func_with_v;
226+
}
227+
228+
229+
inline int func_with_other_func_in_breakpoint(int id, int pnodecount, func_in_breakpoint_Instance* inst, double* data, const Datum* indexes, ThreadDatum* thread, NrnThread* nt, double v, double q) {
230+
int ret_func_with_other = 0;
231+
return ret_func_with_other;
232+
}
233+
234+
235+
/** initialize channel */
236+
void nrn_init_func_in_breakpoint(NrnThread* nt, Memb_list* ml, int type) {
237+
int nodecount = ml->nodecount;
238+
int pnodecount = ml->_nodecount_padded;
239+
const int* node_index = ml->nodeindices;
240+
double* data = ml->data;
241+
const double* voltage = nt->_actual_v;
242+
Datum* indexes = ml->pdata;
243+
ThreadDatum* thread = ml->_thread;
244+
245+
setup_instance(nt, ml);
246+
auto* const inst = static_cast<func_in_breakpoint_Instance*>(ml->instance);
247+
248+
if (_nrn_skip_initmodel == 0) {
249+
#pragma omp simd
250+
#pragma ivdep
251+
for (int id = 0; id < nodecount; id++) {
252+
int node_id = node_index[id];
253+
double v = voltage[node_id];
254+
#if NRN_PRCELLSTATE
255+
inst->v_unused[id] = v;
256+
#endif
257+
}
258+
}
259+
}
260+
261+
262+
inline double nrn_current_func_in_breakpoint(int id, int pnodecount, func_in_breakpoint_Instance* inst, double* data, const Datum* indexes, ThreadDatum* thread, NrnThread* nt, double v) {
263+
double current = 0.0;
264+
func_func_in_breakpoint(id, pnodecount, inst, data, indexes, thread, nt, v);
265+
func_with_v_func_in_breakpoint(id, pnodecount, inst, data, indexes, thread, nt, v, v);
266+
func_with_other_func_in_breakpoint(id, pnodecount, inst, data, indexes, thread, nt, v, inst->global->c);
267+
current += inst->il[id];
268+
return current;
269+
}
270+
271+
272+
/** update current */
273+
void nrn_cur_func_in_breakpoint(NrnThread* nt, Memb_list* ml, int type) {
274+
int nodecount = ml->nodecount;
275+
int pnodecount = ml->_nodecount_padded;
276+
const int* node_index = ml->nodeindices;
277+
double* data = ml->data;
278+
const double* voltage = nt->_actual_v;
279+
double* vec_rhs = nt->_actual_rhs;
280+
double* vec_d = nt->_actual_d;
281+
Datum* indexes = ml->pdata;
282+
ThreadDatum* thread = ml->_thread;
283+
auto* const inst = static_cast<func_in_breakpoint_Instance*>(ml->instance);
284+
285+
#pragma omp simd
286+
#pragma ivdep
287+
for (int id = 0; id < nodecount; id++) {
288+
int node_id = node_index[id];
289+
double v = voltage[node_id];
290+
#if NRN_PRCELLSTATE
291+
inst->v_unused[id] = v;
292+
#endif
293+
double g = nrn_current_func_in_breakpoint(id, pnodecount, inst, data, indexes, thread, nt, v+0.001);
294+
double rhs = nrn_current_func_in_breakpoint(id, pnodecount, inst, data, indexes, thread, nt, v);
295+
g = (g-rhs)/0.001;
296+
#if NRN_PRCELLSTATE
297+
inst->g_unused[id] = g;
298+
#endif
299+
vec_rhs[node_id] -= rhs;
300+
vec_d[node_id] += g;
301+
}
302+
}
303+
304+
305+
/** update state */
306+
void nrn_state_func_in_breakpoint(NrnThread* nt, Memb_list* ml, int type) {
307+
int nodecount = ml->nodecount;
308+
int pnodecount = ml->_nodecount_padded;
309+
const int* node_index = ml->nodeindices;
310+
double* data = ml->data;
311+
const double* voltage = nt->_actual_v;
312+
Datum* indexes = ml->pdata;
313+
ThreadDatum* thread = ml->_thread;
314+
auto* const inst = static_cast<func_in_breakpoint_Instance*>(ml->instance);
315+
316+
#pragma omp simd
317+
#pragma ivdep
318+
for (int id = 0; id < nodecount; id++) {
319+
int node_id = node_index[id];
320+
double v = voltage[node_id];
321+
#if NRN_PRCELLSTATE
322+
inst->v_unused[id] = v;
323+
#endif
324+
}
325+
}
326+
327+
328+
/** register channel with the simulator */
329+
void _func_in_breakpoint_reg() {
330+
331+
int mech_type = nrn_get_mechtype("func_in_breakpoint");
332+
func_in_breakpoint_global.mech_type = mech_type;
333+
if (mech_type == -1) {
334+
return;
335+
}
336+
337+
_nrn_layout_reg(mech_type, 0);
338+
register_mech(mechanism_info, nrn_alloc_func_in_breakpoint, nrn_cur_func_in_breakpoint, nullptr, nrn_state_func_in_breakpoint, nrn_init_func_in_breakpoint, nrn_private_constructor_func_in_breakpoint, nrn_private_destructor_func_in_breakpoint, first_pointer_var_index(), 1);
339+
340+
hoc_register_prop_size(mech_type, float_variables_size(), int_variables_size());
341+
hoc_register_var(hoc_scalar_double, hoc_vector_double, NULL);
342+
}
343+
}

0 commit comments

Comments
 (0)