5 #include "petsc_compat.h"
17 using ::opencarp::timer_manager;
23 void write_global(
sf_vec* v, GVEC_DUMP *gvd, FILE *out, MULTI_IF *pMIIF, IOCtrl *io,
int numNode) {
41 #ifndef ENABLE_TESTING
46 fwrite(buf, 1, data_type_sizes[gvd->dtype[0]], out);
48 fprintf(out,
"%+.8e%s", buf[0], sep);
57 for(
int i = 0; i< 8; i++)
60 int cell_node = rand()%numNode;
61 log_msg(NULL, 0,
NONL,
"\n\t(Cell: %d) ", cell_node);
62 log_msg(NULL, 0,
NONL,
"%+.6e%s", buf[cell_node], stdsep);
71 int double_cmp(
const void *a,
const void *b) {
72 return *((
double *)a)-*((
double *)b);
88 for (
size_t i = 1; i < strlen(stl)-1; i++)
89 trg->
n += stl[i] ==
',';
90 trg->
lst =
static_cast<double *
>(malloc(trg->
n *
sizeof(
double) ));
95 while (token != NULL) {
97 trg->
lst[i++] = strtod(token, &endp);
99 fprintf(stderr,
"Error in stimulus timing list\n");
102 if (DIAs && (i > 1)) trg->
lst[i-1] += trg->
lst[i-2];
105 qsort(trg->
lst, trg->
n,
sizeof(
double), double_cmp);
129 snprintf(hd_fname,
sizeof hd_fname,
"%s_header.txt", ExpID);
130 FILE *fh = fopen(hd_fname,
"wt");
135 for (
int i = 0; i < NUM_IMP_DATA_TYPES+1; i++) {
137 fprintf(fh,
"%32s %10s %2d %10d\n", basename(gvd->
fn[i]),
138 data_type_names[gvd->
dtype[i]],
144 for (
int i = 0; i < svd->
n; i++) {
145 fprintf(fh,
"%32s %10s %2d %10d\n", basename(svd->
fn[i]), data_type_names[svd->
dtype[i]],
150 fprintf(stderr,
"Could not open %s.\n", hd_fname);
155 PetscBarrier(COMPAT_PETSC_NULLPTR);
163 char outname[] = {
"GVECS"};
197 for (p = 0; p < NUM_IMP_DATA_TYPES; p++) {
198 if (pMIIF->
gdata[p] == NULL) {
204 nptr = imp_data_names[p];
205 snprintf(nbuf,
sizeof nbuf,
"%s.%s%s", base_name, nptr, ext);
210 snprintf(nbuf,
sizeof nbuf,
"%s%s", base_name, ext);
213 if (io->
wsplt || !p) {
214 fhdls[p] = fopen(nbuf, wmode);
227 snprintf(nbuf,
sizeof nbuf,
"%s.t%s", base_name, ext);
230 fhdls[p] = fopen(nbuf, wmode);
238 fprintf(stderr,
"Outputting the following quantities at each time: \n");
239 fprintf(stderr,
"%10s\t",
"Time");
240 for (
int p = 0; p < NUM_IMP_DATA_TYPES; p++)
241 if (pMIIF->
gdata[p] != NULL)
242 fprintf(stderr,
"%10s\t", imp_data_names[p]);
243 fprintf(stderr,
"\n\n");
246 PetscBarrier(COMPAT_PETSC_NULLPTR);
259 float ft = tmo->time;
260 double t = tmo->time;
276 fwrite(&tmo->time, 1, data_type_sizes[gvd->
dtype[NUM_IMP_DATA_TYPES]], gvd->
hdls[NUM_IMP_DATA_TYPES]->
fd);
279 fprintf(fhdls[NUM_IMP_DATA_TYPES],
"%10.3f ", t);
283 for (p = 0; p < NUM_IMP_DATA_TYPES; p++)
285 write_global(pMIIF->
gdata[p], gvd, fhdls[p], pMIIF, io, numNode);
294 fprintf(fhdls[0],
"\n");
310 for (p = 0; p < NUM_IMP_DATA_TYPES+1; p++) {
329 void dump_all(
MULTI_IF *MIIF,
int reg,
char *imp,
char *plugs,
double t,
double ddt,
char *fout) {
338 snprintf(IMPS,
sizeof IMPS,
"%s:%s", imp, plugs);
339 char *plgs =
dupstr(IMPS), *p;
342 for (
int i = 0; i < nsv; i++) {
343 snprintf(file,
sizeof file,
"%s_%s.%s", fout, plgs, sv[i]);
362 if (event_duration < t->mn)
363 t->
mn = event_duration;
364 if (event_duration > t->
mx)
365 t->
mx = event_duration;
366 t->
tot += event_duration;
404 char *last_col = SVs;
407 colptr = strchr(last_col,
':');
410 tmp = strndup(last_col, colptr-last_col);
412 tmp = strdup(last_col);
414 char *pair = strtok_r(tmp,
",", &iptr);
418 if (sscanf(pair,
"%[^= ]=%lf", sv, &value) != 2) {
423 for (
int i = 0; i < num; i++) {
430 }
else if (mode == 1) {
431 snprintf(impsv,
sizeof impsv,
"%s.%s", imp, sv);
432 }
else if (mode > 1) {
434 for (
int j = 0; j < mode-2; j++)
435 ptr = strchr(ptr,
':') + 1;
436 char *ptr1 = strchr(ptr,
':');
437 snprintf(impsv,
sizeof impsv,
"%.*s.%s", (
int)(ptr1 ? ptr1-ptr : strlen(ptr)), ptr, sv);
441 pair = strtok_r(NULL,
",", &iptr);
446 }
while (colptr != NULL);
454 printf(
"Ionic model:\n");
455 printf(
"------------\n");
460 printf(
"\tState variables:\n");
461 for (
int i = 0; i < n; i++)
462 printf(
"\t\t%20s\n", sv[i]);
464 if (!plugs.empty()) {
466 printf(
"Plugins:\n");
467 printf(
"--------\n");
469 for (
auto& plug : plugs) {
470 plug.get().print_metadata();
471 plug.get().print_params();
472 n = plug.get().get_sv_list(&sv);
473 printf(
"\tState variables:\n");
474 for (
int j = 0; j < n; j++)
475 printf(
"\t\t%20s\n", sv[j]);
489 if (p->stim_times_given)
492 if (p->duration_given)
493 return p->duration_arg;
494 else if (p->restitute_given)
495 return p->duration_arg;
496 else if (p->stim_times_given)
497 return stim_lst->
lst[stim_lst->
n-1]+p->past_stim_arg;
499 return p->stim_start_arg+p->bcl_arg*(p->numstim_arg-1)+p->past_stim_arg;
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)
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)
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