1 #include <../../nrnconf.h>
24 static constexpr
auto nparm = 5;
56 #define global_conci(type) ion_global_map[type][0]
57 #define global_conco(type) ion_global_map[type][1]
58 #define global_charge(type) ion_global_map[type][2]
76 auto const buf_size = strlen(
name) + 10;
77 char*
const buf =
static_cast<char*
>(
emalloc(buf_size));
78 std::snprintf(
buf, buf_size,
"%s_ion",
name);
84 hoc_execerr_ext(
"%s already defined with charge %g, cannot redefine with charge %g",
95 std::snprintf(
buf, buf_size,
"e%s",
name);
99 std::snprintf(
buf, buf_size,
"%si",
name);
103 std::snprintf(
buf, buf_size,
"%so",
name);
107 std::snprintf(
buf, buf_size,
"i%s",
name);
111 std::snprintf(
buf, buf_size,
"di%s_dv_",
name);
123 if (strcmp(
name,
"ca") == 0 &&
charge != 2.0) {
129 hoc_execerr_ext(
"ca_ion already defined with charge 2, cannot redefine with charge %g\n",
134 std::snprintf(
buf, buf_size,
"%s_ion",
name);
166 std::array<std::string, 7>
buf{};
167 std::string name_s{
name};
168 #define VAL_SENTINAL -10000.
169 buf[0] = name_s +
"_ion";
170 buf[1] =
"e" + name_s;
171 buf[2] = name_s +
"i";
172 buf[3] = name_s +
"o";
173 buf[5] =
"i" + name_s;
174 buf[6] =
"di" + name_s +
"_dv_";
175 for (
i = 0;
i < 7;
i++) {
194 field<double>{
buf[1]},
195 field<double>{
buf[2]},
196 field<double>{
buf[3]},
197 field<double>{
buf[5]},
198 field<double>{
buf[6]},
199 field<int>{
"iontype",
"iontype"});
203 if (ion_global_map_size <= s->
subtype) {
209 buf[0] = name_s +
"i0_" +
s->name;
212 buf[1] = name_s +
"o0_" +
s->name;
218 if (strcmp(
"na",
name) == 0) {
223 }
else if (strcmp(
"k",
name) == 0) {
228 }
else if (strcmp(
"ca",
name) == 0) {
238 for (
i = 0;
i < 3; ++
i) {
245 "%s ion charge defined differently in\n\
246 two USEION statements (%g and %g)\n",
270 "%s USEION CHARGE (or VALENCE) must be defined in\n\
271 at least one model using this ion\n",
278 #define ktf (1000. * _gasconstant_codata2018 * (celsius + 273.15) / _faraday_codata2018)
286 }
else if (co <= 0.) {
289 return ktf / z *
log(co / ci);
317 switch (
s->u.rng.index) {
323 val = *co *
exp(-z /
ktf * *e);
327 val = *ci *
exp(z /
ktf * *e);
342 if (
fabs(x) < 1e-4) {
345 return x / (
exp(x) - 1);
349 double nrn_ghk(
double v,
double ci,
double co,
double z) {
350 double eco, eci, temp;
352 eco = co *
efun(temp);
353 eci = ci *
efun(-temp);
384 #define charge global_charge(type)
385 #define conci0 global_conci(type)
386 #define conco0 global_conco(type)
411 set_of_ionconctypes.insert(2 *
iontype +
i);
416 auto& set_of_ionconctypes = search->second;
417 return set_of_ionconctypes.count(2 *
iontype +
i) == 1;
445 for (
p = pion->
next;
p;
p =
p->next) {
452 "%.*s%c is being written at the same location by %s and %s",
455 ((
i == 1) ?
'i' :
'o'),
468 int istyle,
i, oldstyle;
485 istyle = (int)
chkarg(2, 0., 3.);
486 istyle += 010 * (int)
chkarg(3, 0., 3.);
487 istyle += 040 * (int)
chkarg(4, 0., 1.);
488 istyle += 0100 * (int)
chkarg(5, 0., 1.);
489 istyle += 04 * (int)
chkarg(6, 0., 1.);
490 for (
i = 0;
i <
sec->nnode; ++
i) {
516 if (sym->
u.
rng.index == 0) {
529 int oldconc = (it & 03);
530 int oldrev = (it & 030) >> 3;
532 if (oldconc < conc) {
539 if (oldconc > 0 && oldrev < 2) {
543 it += oldconc + 010 * oldrev;
550 if (oldconc > 0 && oldrev == 2) {
574 for (
int i = 0;
i < count; ++
i) {
597 for (
i = 0;
i < count; ++
i) {
604 for (
i = 0;
i < count; ++
i) {
623 }
else if (
p->_type ==
k_ion) {
627 }
else if (
p->_type ==
ca_ion) {
645 constexpr
auto c = 3;
646 constexpr
auto dc = 4;
648 for (tml = nt->
tml; tml; tml = tml->
next)
652 for (
i = 0;
i < i2; ++
i) {
Prop * nrn_mechanism(int type, Node *nd)
Section * nrn_noerr_access(void)
return 0 if no accessed section
neuron::container::data_handle< double > nrn_rangepointer(Section *sec, Symbol *s, double d)
Datum * nrn_prop_datum_alloc(int type, int count, Prop *p)
double chkarg(int, double low, double high)
void hoc_execerr_ext(const char *fmt,...)
printf style specification of hoc_execerror message.
int hoc_is_str_arg(int narg)
void hoc_retpushx(double x)
void hoc_symbol_limits(Symbol *sym, float low, float high)
Symbol * hoc_lookup(const char *)
Symlist * hoc_top_level_symlist
char * hoc_symbol_units(Symbol *, const char *)
void nrn_writes_conc(int, int)
void hoc_execerror(const char *s1, const char *s2)
void hoc_register_dparam_semantics(int type, int, const char *name)
void hoc_register_var(DoubScal *ds, DoubVec *dv, VoidFunc *)
void * erealloc(void *ptr, size_t size)
static void * emalloc(size_t size)
int nrn_get_mechtype(const char *name)
Get mechanism type by the mechanism name.
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 hoc_warning(const char *s1, const char *s2)
static void register_data_fields(int mech_type, Fields const &... fields)
Type- and array-aware version of hoc_register_prop_size.
int Sprintf(char(&buf)[N], const char *fmt, Args &&... args)
Redirect sprintf to snprintf if the buffer size can be deduced.
int iontype(char *s1, char *s2)
std::vector< Memb_func > memb_func
static bool mech_uses_ionconctype(int mechtype, int iontype, int i)
static double ** ion_global_map
static constexpr auto erev_index
static constexpr auto cur_index
double nrn_ion_charge(Symbol *sym)
void nrn_verify_ion_charge_defined()
static std::vector< double > kparmdflt
static std::vector< double > naparmdflt
void second_order_cur(NrnThread *nt)
#define global_conco(type)
static constexpr auto ndparam
int nrn_vartype(const Symbol *sym)
static double efun(double x)
static constexpr auto iontype_index_dparam
void nrn_promote(Prop *p, int conc, int rev)
void nrn_wrote_conc(Symbol *sym, double &erev, double ci, double co, int it)
static int ion_global_map_size
static constexpr auto conci_index
static void ion_cur(neuron::model_sorted_token const &, NrnThread *, Memb_list *, int)
static std::vector< double > ionparmdflt
static void add_mechtype2ionconctype(int mechtype, int iontype, int i)
static std::vector< double > caparmdflt
#define global_charge(type)
double nrn_ghk(double v, double ci, double co, double z)
static constexpr auto nparm
void nrn_check_conc_write(Prop *pmech, Prop *pion, int i)
static constexpr auto conco_index
static void ion_alloc(Prop *)
static std::map< int, std::set< int > > mechtype2ionconctype
double nrn_nernst(double ci, double co, double z)
static constexpr auto dcurdv_index
double nrn_nernst_coef(int type)
static const char * mechanism[]
void ion_reg(const char *name, double valence)
static void ion_init(neuron::model_sorted_token const &, NrnThread *, Memb_list *, int)
#define global_conci(type)
void reg_parm_default(int mechtype, const std::string &name)
void hoc_register_parm_default(int mechtype, const std::vector< double > *pd)
constexpr double _faraday_codata2018
Symlist * hoc_built_in_symlist
A view into a set of mechanism instances.
std::vector< double * > data()
Get a vector of double* representing the model data.
Represent main neuron object computed by single thread.
struct NrnThreadMembList * next
struct Symbol::@45::@46 rng
Version of Memb_list for use in performance-critical code.
T get() const
Explicit conversion to any T.
int Fprintf(FILE *stream, const char *fmt, Args... args)