16 using ::opencarp::timer_manager;
22 void write_global(
sf_vec* v, GVEC_DUMP *gvd, FILE *out, MULTI_IF *pMIIF, IOCtrl *io,
int numNode) {
40 #ifndef MLIR_ENABLE_TESTING
45 fwrite(buf, 1, data_type_sizes[gvd->dtype[0]], out);
47 fprintf(out,
"%+.8e%s", buf[0], sep);
56 for(
int i = 0; i< 8; i++)
59 int cell_node = rand()%numNode;
60 log_msg(NULL, 0,
NONL,
"\n\t(Cell: %d) ", cell_node);
61 log_msg(NULL, 0,
NONL,
"%+.6e%s", buf[cell_node], stdsep);
70 int double_cmp(
const void *a,
const void *b) {
71 return *((
double *)a)-*((
double *)b);
87 for (
size_t i = 1; i < strlen(stl)-1; i++)
88 trg->
n += stl[i] ==
',';
89 trg->
lst =
static_cast<double *
>(malloc(trg->
n *
sizeof(
double) ));
94 while (token != NULL) {
96 trg->
lst[i++] = strtod(token, &endp);
98 fprintf(stderr,
"Error in stimulus timing list\n");
101 if (DIAs && (i > 1)) trg->
lst[i-1] += trg->
lst[i-2];
104 qsort(trg->
lst, trg->
n,
sizeof(
double), double_cmp);
128 snprintf(hd_fname,
sizeof hd_fname,
"%s_header.txt", ExpID);
129 FILE *fh = fopen(hd_fname,
"wt");
134 for (
int i = 0; i < NUM_IMP_DATA_TYPES+1; i++) {
136 fprintf(fh,
"%32s %10s %2d %10d\n", basename(gvd->
fn[i]),
137 data_type_names[gvd->
dtype[i]],
143 for (
int i = 0; i < svd->
n; i++) {
144 fprintf(fh,
"%32s %10s %2d %10d\n", basename(svd->
fn[i]), data_type_names[svd->
dtype[i]],
149 fprintf(stderr,
"Could not open %s.\n", hd_fname);
162 char outname[] = {
"GVECS"};
196 for (p = 0; p < NUM_IMP_DATA_TYPES; p++) {
197 if (pMIIF->
gdata[p] == NULL) {
203 nptr = imp_data_names[p];
204 snprintf(nbuf,
sizeof nbuf,
"%s.%s%s", base_name, nptr, ext);
209 snprintf(nbuf,
sizeof nbuf,
"%s%s", base_name, ext);
212 if (io->
wsplt || !p) {
213 fhdls[p] = fopen(nbuf, wmode);
226 snprintf(nbuf,
sizeof nbuf,
"%s.t%s", base_name, ext);
229 fhdls[p] = fopen(nbuf, wmode);
237 fprintf(stderr,
"Outputting the following quantities at each time: \n");
238 fprintf(stderr,
"%10s\t",
"Time");
239 for (
int p = 0; p < NUM_IMP_DATA_TYPES; p++)
240 if (pMIIF->
gdata[p] != NULL)
241 fprintf(stderr,
"%10s\t", imp_data_names[p]);
242 fprintf(stderr,
"\n\n");
258 float ft = tmo->time;
259 double t = tmo->time;
275 fwrite(&tmo->time, 1, data_type_sizes[gvd->
dtype[NUM_IMP_DATA_TYPES]], gvd->
hdls[NUM_IMP_DATA_TYPES]->
fd);
278 fprintf(fhdls[NUM_IMP_DATA_TYPES],
"%10.3f ", t);
282 for (p = 0; p < NUM_IMP_DATA_TYPES; p++)
284 write_global(pMIIF->
gdata[p], gvd, fhdls[p], pMIIF, io, numNode);
293 fprintf(fhdls[0],
"\n");
309 for (p = 0; p < NUM_IMP_DATA_TYPES+1; p++) {
328 void dump_all(
MULTI_IF *MIIF,
int reg,
char *imp,
char *plugs,
double t,
double ddt,
char *fout) {
337 snprintf(IMPS,
sizeof IMPS,
"%s:%s", imp, plugs);
338 char *plgs =
dupstr(IMPS), *p;
341 for (
int i = 0; i < nsv; i++) {
342 snprintf(file,
sizeof file,
"%s_%s.%s", fout, plgs, sv[i]);
361 if (event_duration < t->mn)
362 t->
mn = event_duration;
363 if (event_duration > t->
mx)
364 t->
mx = event_duration;
365 t->
tot += event_duration;
403 char *last_col = SVs;
406 colptr = strchr(last_col,
':');
409 tmp = strndup(last_col, colptr-last_col);
411 tmp = strdup(last_col);
413 char *pair = strtok_r(tmp,
",", &iptr);
417 if (sscanf(pair,
"%[^= ]=%lf", sv, &value) != 2) {
422 for (
int i = 0; i < num; i++) {
429 }
else if (mode == 1) {
430 snprintf(impsv,
sizeof impsv,
"%s.%s", imp, sv);
431 }
else if (mode > 1) {
433 for (
int j = 0; j < mode-2; j++)
434 ptr = strchr(ptr,
':') + 1;
435 char *ptr1 = strchr(ptr,
':');
436 snprintf(impsv,
sizeof impsv,
"%.*s.%s", (
int)(ptr1 ? ptr1-ptr : strlen(ptr)), ptr, sv);
440 pair = strtok_r(NULL,
",", &iptr);
445 }
while (colptr != NULL);
453 printf(
"Ionic model:\n");
454 printf(
"------------\n");
459 printf(
"\tState variables:\n");
460 for (
int i = 0; i < n; i++)
461 printf(
"\t\t%20s\n", sv[i]);
463 if (!plugs.empty()) {
465 printf(
"Plugins:\n");
466 printf(
"--------\n");
468 for (
auto& plug : plugs) {
469 plug.get().print_metadata();
470 plug.get().print_params();
471 n = plug.get().get_sv_list(&sv);
472 printf(
"\tState variables:\n");
473 for (
int j = 0; j < n; j++)
474 printf(
"\t\t%20s\n", sv[j]);
488 if (p->stim_times_given)
491 if (p->duration_given)
492 return p->duration_arg;
493 else if (p->restitute_given)
494 return p->duration_arg;
495 else if (p->stim_times_given)
496 return stim_lst->
lst[stim_lst->
n-1]+p->past_stim_arg;
497 else if (p->StimThresh_mode_counter )
498 return p->bcl_arg*(p->numstim_arg-1)+p->Lap_numstim_arg*(p->Lap_max_arg+p->thresh_tm_arg)*100;
500 return p->stim_start_arg+p->bcl_arg*(p->numstim_arg-1)+p->past_stim_arg;
#define SF_COMM
the default SlimFem MPI communicator
opencarp::real_t SF_real
Global scalar type.
Abstract class representing an ionic model type.
virtual int get_sv_list(char ***list) const =0
Returns a list of SVs.
virtual void print_metadata() const =0
Prints the metadata of this model.
virtual void print_params() const =0
Prints the parameters of this model.
opencarp::sf_vec * gdata[NUM_IMP_DATA_TYPES]
data used by all IMPs
SV_DUMP svd
state variable dump
int sv_dump_add_by_name(int, char *, char *, char *, char *)
int adjust_MIIF_variables(const char *variable, const SF::vector< SF_int > &indices, const SF::vector< SF_real > &values)
#define log_msg(F, L, O,...)
void initial_SVs(MULTI_IF *miif, char *SVs, char *imp, char *plgins, int num)
int write_dump_header(GVEC_DUMP *gvd, SV_DUMP *svd, const char *ExpID)
void globalvec_dump(FILE **fhdls, GVEC_DUMP *gvd, MULTI_IF *pMIIF, timer_manager *tmo, IOCtrl *io, int numNode)
@ N_TIMINGS
number of benchmark timings we use
void dump_all(MULTI_IF *MIIF, int reg, char *imp, char *plugs, double t, double ddt, char *fout)
void close_globalvec_dump(FILE **fhdls, GVEC_DUMP *gvd, IOCtrl *io)
IonType * get_ion_type(const std::string &name)
double getCellVal(sf_vec *v, int ind)
void initialize_timings(event_timing *t)
void determine_stim_list(char *stl, TrgList *trg, bool DIAs)
std::vector< std::reference_wrapper< IonType > > IonTypeList
float determine_duration(struct gengetopt_args_info *p, TrgList *stim_lst)
determine time of last stimulus
void open_globalvec_dump(FILE **fhdls, GVEC_DUMP *gvd, MULTI_IF *pMIIF, char *base_name, IOCtrl *io)
char * get_next_list(char *lst, char delimiter)
void update_timing(event_timing *t, double event_duration)
void print_param_help(IonType *im, IonTypeList &plugs)
char * tokstr_r(char *s1, const char *s2, char **lasts)
FILE_SPEC f_open(const char *fname, const char *mode)
Open a FILE_SPEC.
char * dupstr(const char *old_str)
SF::abstract_vector< SF_int, SF_real > sf_vec
int get_rank(MPI_Comm comm=SF_COMM)
void f_close(FILE_SPEC &f)
Close a FILE_SPEC.
char * fn[NUM_IMP_DATA_TYPES+1]
array to store file names
opencarp::FILE_SPEC hdls[NUM_IMP_DATA_TYPES+1]
array of file handles to gvec output files
int n_dumps
keep track of number of dumped time slices
int dtype[NUM_IMP_DATA_TYPES+1]
data type
char first
first line of output
char wsplt
split -> each vector goes into separate file
char wbin
write to file in binary format
char w2stdout
turn on/off output to stdout
data structure to manage state variable file dumps
char ** fn
array to store file names
double intv
time interval for sv dumps
int n_dumps
keep track of number of dumped time slices
double t_dump
next instant for sv dump
int n
#state variables we want to dump
int n
number of pulses required for protocol
double * lst
store instants of pulse delivery
int count
number of events counted so far
double avg
average duration of event
double mx
maximum duration of event
double mn
minimum duration of event
double tot
total duration of all events