20 #include "petsc_compat.h"
32 using ::opencarp::timer_manager;
38 void write_global(
sf_vec* v, GVEC_DUMP *gvd, FILE *out, MULTI_IF *pMIIF, IOCtrl *io,
int numNode) {
56 #ifndef ENABLE_TESTING
61 fwrite(buf, 1, data_type_sizes[gvd->dtype[0]], out);
63 fprintf(out,
"%+.8e%s", buf[0], sep);
72 for(
int i = 0; i< 8; i++)
75 int cell_node = rand()%numNode;
76 log_msg(NULL, 0,
NONL,
"\n\t(Cell: %d) ", cell_node);
77 log_msg(NULL, 0,
NONL,
"%+.6e%s", buf[cell_node], stdsep);
86 int double_cmp(
const void *a,
const void *b) {
87 return *((
double *)a)-*((
double *)b);
103 for (
size_t i = 1; i < strlen(stl)-1; i++)
104 trg->
n += stl[i] ==
',';
105 trg->
lst =
static_cast<double *
>(malloc(trg->
n *
sizeof(
double) ));
110 while (token != NULL) {
112 trg->
lst[i++] = strtod(token, &endp);
114 fprintf(stderr,
"Error in stimulus timing list\n");
117 if (DIAs && (i > 1)) trg->
lst[i-1] += trg->
lst[i-2];
120 qsort(trg->
lst, trg->
n,
sizeof(
double), double_cmp);
144 snprintf(hd_fname,
sizeof hd_fname,
"%s_header.txt", ExpID);
145 FILE *fh = fopen(hd_fname,
"wt");
150 for (
int i = 0; i < NUM_IMP_DATA_TYPES+1; i++) {
152 fprintf(fh,
"%32s %10s %2d %10d\n", basename(gvd->
fn[i]),
153 data_type_names[gvd->
dtype[i]],
159 for (
int i = 0; i < svd->
n; i++) {
160 fprintf(fh,
"%32s %10s %2d %10d\n", basename(svd->
fn[i]), data_type_names[svd->
dtype[i]],
165 fprintf(stderr,
"Could not open %s.\n", hd_fname);
170 PetscBarrier(COMPAT_PETSC_NULLPTR);
178 char outname[] = {
"GVECS"};
212 for (p = 0; p < NUM_IMP_DATA_TYPES; p++) {
213 if (pMIIF->
gdata[p] == NULL) {
219 nptr = imp_data_names[p];
220 snprintf(nbuf,
sizeof nbuf,
"%s.%s%s", base_name, nptr, ext);
225 snprintf(nbuf,
sizeof nbuf,
"%s%s", base_name, ext);
228 if (io->
wsplt || !p) {
229 fhdls[p] = fopen(nbuf, wmode);
242 snprintf(nbuf,
sizeof nbuf,
"%s.t%s", base_name, ext);
245 fhdls[p] = fopen(nbuf, wmode);
253 fprintf(stderr,
"Outputting the following quantities at each time: \n");
254 fprintf(stderr,
"%10s\t",
"Time");
255 for (
int p = 0; p < NUM_IMP_DATA_TYPES; p++)
256 if (pMIIF->
gdata[p] != NULL)
257 fprintf(stderr,
"%10s\t", imp_data_names[p]);
258 fprintf(stderr,
"\n\n");
261 PetscBarrier(COMPAT_PETSC_NULLPTR);
274 float ft = tmo->time;
275 double t = tmo->time;
291 fwrite(&tmo->time, 1, data_type_sizes[gvd->
dtype[NUM_IMP_DATA_TYPES]], gvd->
hdls[NUM_IMP_DATA_TYPES]->
fd);
294 fprintf(fhdls[NUM_IMP_DATA_TYPES],
"%10.3f ", t);
298 for (p = 0; p < NUM_IMP_DATA_TYPES; p++)
300 write_global(pMIIF->
gdata[p], gvd, fhdls[p], pMIIF, io, numNode);
309 fprintf(fhdls[0],
"\n");
325 for (p = 0; p < NUM_IMP_DATA_TYPES+1; p++) {
344 void dump_all(
MULTI_IF *MIIF,
int reg,
char *imp,
char *plugs,
double t,
double ddt,
char *fout) {
353 snprintf(IMPS,
sizeof IMPS,
"%s:%s", imp, plugs);
354 char *plgs =
dupstr(IMPS), *p;
357 for (
int i = 0; i < nsv; i++) {
358 snprintf(file,
sizeof file,
"%s_%s.%s", fout, plgs, sv[i]);
377 if (event_duration < t->mn)
378 t->
mn = event_duration;
379 if (event_duration > t->
mx)
380 t->
mx = event_duration;
381 t->
tot += event_duration;
419 char *last_col = SVs;
422 colptr = strchr(last_col,
':');
425 tmp = strndup(last_col, colptr-last_col);
427 tmp = strdup(last_col);
429 char *pair = strtok_r(tmp,
",", &iptr);
433 if (sscanf(pair,
"%[^= ]=%lf", sv, &value) != 2) {
438 for (
int i = 0; i < num; i++) {
445 }
else if (mode == 1) {
446 snprintf(impsv,
sizeof impsv,
"%s.%s", imp, sv);
447 }
else if (mode > 1) {
449 for (
int j = 0; j < mode-2; j++)
450 ptr = strchr(ptr,
':') + 1;
451 char *ptr1 = strchr(ptr,
':');
452 snprintf(impsv,
sizeof impsv,
"%.*s.%s", (
int)(ptr1 ? ptr1-ptr : strlen(ptr)), ptr, sv);
456 pair = strtok_r(NULL,
",", &iptr);
461 }
while (colptr != NULL);
469 printf(
"Ionic model:\n");
470 printf(
"------------\n");
475 printf(
"\tState variables:\n");
476 for (
int i = 0; i < n; i++)
477 printf(
"\t\t%20s\n", sv[i]);
479 if (!plugs.empty()) {
481 printf(
"Plugins:\n");
482 printf(
"--------\n");
484 for (
auto& plug : plugs) {
485 plug.get().print_metadata();
486 plug.get().print_params();
487 n = plug.get().get_sv_list(&sv);
488 printf(
"\tState variables:\n");
489 for (
int j = 0; j < n; j++)
490 printf(
"\t\t%20s\n", sv[j]);
504 if (p->stim_times_given)
507 if (p->duration_given)
508 return p->duration_arg;
509 else if (p->restitute_given)
510 return p->duration_arg;
511 else if (p->stim_times_given)
512 return stim_lst->
lst[stim_lst->
n-1]+p->past_stim_arg;
514 return p->stim_start_arg+p->bcl_arg*(p->numstim_arg-1)+p->past_stim_arg;
double SF_real
Use the general double as real 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)
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)
int get_rank(MPI_Comm comm=PETSC_COMM_WORLD)
FILE_SPEC f_open(const char *fname, const char *mode)
Open a FILE_SPEC.
char * dupstr(const char *old_str)
void log_msg(FILE_SPEC out, int level, unsigned char flag, const char *fmt,...)
SF::abstract_vector< SF_int, SF_real > sf_vec
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