Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit 68bc8a8

Browse files
committed
Reading global ion variables from NEURON and setting them in nrn_ion_init
1 parent 43e881e commit 68bc8a8

3 files changed

Lines changed: 54 additions & 13 deletions

File tree

coreneuron/apps/main1.cpp

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <dlfcn.h>
1818
#include <memory>
1919
#include <vector>
20+
#include "coreneuron/permute/data_layout.hpp"
2021

2122
#include "coreneuron/config/config.h"
2223
#include "coreneuron/utils/randoms/nrnran123.h"
@@ -218,9 +219,7 @@ void nrn_init_and_load_data(int argc,
218219
// full path of files.dat file
219220
std::string filesdat(corenrn_param.datpath + "/" + corenrn_param.filesdat);
220221

221-
// read the global variable names and set their values from globals.dat
222-
set_globals(corenrn_param.datpath.c_str(), (corenrn_param.seed >= 0), corenrn_param.seed);
223-
222+
224223
// set global variables for start time, timestep and temperature
225224
if (!corenrn_embedded) {
226225
t = checkPoints.restore_time();
@@ -514,8 +513,10 @@ extern "C" void mk_mech_init(int argc, char** argv) {
514513
out.close();
515514
}
516515

517-
// reads mechanism information from bbcore_mech.dat
516+
// read the global variable names and set their values from globals.dat
517+
set_globals(corenrn_param.datpath.c_str(), (corenrn_param.seed >= 0), corenrn_param.seed);
518518

519+
// reads mechanism information from bbcore_mech.dat
519520
mk_mech((corenrn_param.datpath).c_str());
520521
}
521522

@@ -578,6 +579,21 @@ extern "C" int run_solve_core(int argc, char** argv) {
578579
abort();
579580
}
580581

582+
// for (int i = 0; i < nrn_nthread; ++i) {
583+
// NrnThread* nt = nrn_threads + i;
584+
// for (auto tml = nt->tml; tml; tml = tml->next) {
585+
// auto ml = tml->ml;
586+
// auto type = tml->index;
587+
// int n = ml->nodecount;
588+
// int szdp = corenrn.get_prop_dparam_size()[type];
589+
// std::cout << "ml type " << type << std::endl;
590+
// int pcnt = nrn_soa_padded_size(n, SOA_LAYOUT) * szdp;
591+
// for(int i = 0 ; i < pcnt; i++) {
592+
// printf("ml->pdata[%d] = %d\n", i, ml->pdata[i]);
593+
// }
594+
// }
595+
// }
596+
581597
// TODO : if some ranks are empty then restore will go in deadlock
582598
// phase (as some ranks won't have restored anything and hence return
583599
// false in checkpoint_initialize

coreneuron/io/global_vars.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
#include <map>
1212
#include <string>
1313
#include <algorithm>
14+
#include <unordered_map>
1415

1516
#include "coreneuron/utils/randoms/nrnran123.h"
1617
#include "coreneuron/nrnconf.h"
@@ -28,6 +29,8 @@ using N2V = std::map<std::string, PSD>;
2829

2930
static N2V* n2v;
3031

32+
extern std::unordered_map<std::string, double> nrn_ion_init;
33+
3134
void hoc_register_var(DoubScal* ds, DoubVec* dv, VoidFunc*) {
3235
if (!n2v) {
3336
n2v = new N2V();
@@ -109,10 +112,14 @@ void set_globals(const char* path, bool cli_global_seed, int cli_global_seed_val
109112
if (strcmp(name, "0") == 0) {
110113
break;
111114
}
115+
printf("name %s value %lf\n", name, val);
112116
it = n2v->find(name);
113117
if (it != n2v->end()) {
114118
nrn_assert(it->second.first == 0);
115119
*(it->second.second) = val;
120+
} else if (static_cast<std::string>(name).find("ion") != std::string::npos) {
121+
printf("ion %s value %lf\n", name, val);
122+
nrn_ion_init[name] = val;
116123
}
117124
} else if (sscanf(line, "%[^[][%d]\n", name, &n) == 2) {
118125
if (strcmp(name, "0") == 0) {

coreneuron/mechanism/eion.cpp

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,15 @@ double nrn_ion_charge(int type) {
6060
return global_charge(type);
6161
}
6262

63+
std::unordered_map<std::string, double> nrn_ion_init = {
64+
{"nai0_na_ion", DEF_nai},
65+
{"nao0_na_ion", DEF_nao},
66+
{"ki0_k_ion", DEF_ki},
67+
{"ko0_k_ion", DEF_ko},
68+
{"cai0_ca_ion", DEF_cai},
69+
{"cao0_ca_ion", DEF_cao},
70+
};
71+
6372
void ion_reg(const char* name, double valence) {
6473
char buf[7][50];
6574
#define VAL_SENTINAL -10000.
@@ -109,22 +118,30 @@ void ion_reg(const char* name, double valence) {
109118
sprintf(buf[1], "%so0_%s", name, buf[0]);
110119
if (strcmp("na", name) == 0) {
111120
na_ion = mechtype;
112-
global_conci(mechtype) = DEF_nai;
113-
global_conco(mechtype) = DEF_nao;
121+
global_conci(mechtype) = nrn_ion_init["nai0_na_ion"];
122+
global_conco(mechtype) = nrn_ion_init["nao0_na_ion"];
114123
global_charge(mechtype) = 1.;
115124
} else if (strcmp("k", name) == 0) {
116125
k_ion = mechtype;
117-
global_conci(mechtype) = DEF_ki;
118-
global_conco(mechtype) = DEF_ko;
126+
global_conci(mechtype) = nrn_ion_init["ki0_k_ion"];
127+
global_conco(mechtype) = nrn_ion_init["ko0_k_ion"];
119128
global_charge(mechtype) = 1.;
120129
} else if (strcmp("ca", name) == 0) {
121130
ca_ion = mechtype;
122-
global_conci(mechtype) = DEF_cai;
123-
global_conco(mechtype) = DEF_cao;
131+
global_conci(mechtype) = nrn_ion_init["cai0_ca_ion"];
132+
global_conco(mechtype) = nrn_ion_init["cao0_ca_ion"];
124133
global_charge(mechtype) = 2.;
125134
} else {
126-
global_conci(mechtype) = DEF_ioni;
127-
global_conco(mechtype) = DEF_iono;
135+
if (nrn_ion_init[static_cast<std::string>(buf[0])]) {
136+
global_conci(mechtype) = nrn_ion_init[static_cast<std::string>(buf[0])];
137+
} else {
138+
global_conci(mechtype) = DEF_ioni;
139+
}
140+
if (nrn_ion_init[static_cast<std::string>(buf[1])]) {
141+
global_conco(mechtype) = nrn_ion_init[static_cast<std::string>(buf[0])];
142+
} else {
143+
global_conco(mechtype) = DEF_iono;
144+
}
128145
global_charge(mechtype) = VAL_SENTINAL;
129146
}
130147
}
@@ -275,6 +292,7 @@ void nrn_cur_ion(NrnThread* nt, Memb_list* ml, int type) {
275292
for (int _iml = 0; _iml < _cntml_actual; ++_iml) {
276293
dcurdv = 0.;
277294
cur = 0.;
295+
// printf("nrn_cur_ion %d iontype[%d] %d\n", type, _iml, iontype);
278296
if (iontype & 0100) {
279297
erev = nrn_nernst(conci, conco, charge, celsius);
280298
}
@@ -295,10 +313,10 @@ void nrn_init_ion(NrnThread* nt, Memb_list* ml, int type) {
295313
return;
296314
}
297315

298-
/*printf("ion_init %s\n", memb_func[type].sym->name);*/
299316
int _cntml_padded = ml->_nodecount_padded;
300317
pd = ml->data;
301318
ppd = ml->pdata;
319+
printf("nrn_init_ion %d %s conci %lf conco %lf charge %lf celsius %lf\n", type, nrn_get_mechname(type), conci0, conco0, charge, celsius);
302320
// There was no async(...) clause in the initial OpenACC implementation, so
303321
// no `nowait` clause has been added to the OpenMP implementation. TODO:
304322
// verify if this can be made asynchronous or if there is a strong reason it

0 commit comments

Comments
 (0)