openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
bench_utils.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: Copyright (c) NumeriCor GmbH
2 // SPDX-License-Identifier: LicenseRef-APL-1.1
3 
4 #ifndef _BENCH_UTILS_H
5 #define _BENCH_UTILS_H
6 
7 #include "cmdline.h"
8 #include "restitute.h"
9 
12 class Bisect {
13  public:
14 
22  Bisect( float min, float max, float tol=0.01 ):_min(min),_max(max),_tol(tol){}
32  bool update( float &val, bool success ){
33  if( success ){
34  _curr = (val+_min)/2.;
35  _max = val;
36  } else {
37  _curr = _max==INFINITY ? val*2 : (val+_max)/2.;
38  _min = val;
39  }
40  _found = fabs((val-_curr)/val) <= _tol;
41  val = _curr;
42  return _found;
43  }
44  float current(){ return _curr; }
45  private:
46  float _min;
47  float _max;
48  float _curr;
49  float _tol;
50  bool _found = false;
51 };
52 
53 namespace limpet {
54 
55 enum TimerIDs {
56  CON_TM_IDX, // IO timer for console output
57  SVD_TM_IDX, // IO timer for state variable output
58  STA_TM_IDX, // IO timer for state saves (checkpointing)
59  SSV_TM_IDX, // IO timer for single state vector saves
60  STM_TM_IDX, // timer for stimulus trigger
61  LIGHT_TM_IDX, // timer for illumination trigger
62  TRACE_TM_IDX, // timer for trace output
63  CLAMP_TM_IDX, // timer for trace output
65  RES_SAVE_TM_IDX, // timer for saving state vectors during restitution
66  N_TIMERS // number of IO Timers we are going to use
67 };
68 
69 #define TIME_OUT 1. // output period for data
70 #define NUMSEG 1 // number of nodes or nodes
71 
72 // STATE VARIABLE DUMPS
73 #define DT_SV_DUMP 1. // output interval for sv dumps
74 
75 // typedefs
76 struct IOCtrl {
77  char w2file;
78  char wbin;
79  char wsplt;
80  char w2stdout;
81  char first;
82 };
83 
84 struct GVEC_DUMP {
85  opencarp::FILE_SPEC hdls[NUM_IMP_DATA_TYPES+1];
86  char* fn[NUM_IMP_DATA_TYPES+1];
87  int dtype[NUM_IMP_DATA_TYPES+1];
88  int n_dumps;
89 };
90 
91 // record statistics on the duration of events
92 #define us_RESOLUTION 1
93 struct event_timing {
94  bool init;
95  double mn;
96  double mx;
97  double avg;
98  double tot;
99  int count;
100 };
101 
102 enum timingIDs {
107  N_TIMINGS
108 };
109 
111 typedef enum {
121  dtype_bool
123 
125 static const char * const data_type_names[] = {
126  "Gatetype",
127  "Real",
128  "float",
129  "char",
130  "int",
131  "double",
132  "short",
133  "GlobalData_t",
134  "long",
135  "bool"
136 };
137 
138 // Gatetype is defined in LIMPET only and typically defined as float
139 // if defined otherwise, the size has to be overruled within LIMPET
140 // in this case the const qualifier has to be removed.
141 #define GATETYPE_SIZE 4
142 #define GLOBALDATA_T_SIZE 8
144 static const int data_type_sizes[] = {
146  sizeof(limpet::Real),
147  sizeof(float),
148  sizeof(char),
149  sizeof(int),
150  sizeof(double),
151  sizeof(short),
153  sizeof(long),
154  sizeof(bool)
155 };
156 
157 
158 int write_dump_header(GVEC_DUMP *gvd, SV_DUMP *svd, const char *ExpID);
159 void open_globalvec_dump(FILE **fhdls, GVEC_DUMP *gvd, MULTI_IF *pMIIF, char *base_name, IOCtrl *io);
160 void globalvec_dump(FILE **fhdls, GVEC_DUMP *gvd, MULTI_IF *pMIIF, opencarp::timer_manager *tm, IOCtrl *io, int numNode);
161 void close_globalvec_dump(FILE **fhdls, GVEC_DUMP *gvd, IOCtrl *io);
162 void dump_all(MULTI_IF *, int, char *, char *, double, double, char *);
163 void update_timing(event_timing *t, double event_duration);
165 double getCellVal(opencarp::sf_vec* v, int ind);
166 void initial_SVs(MULTI_IF *miif, char *SVs, char *imp, char *plgins, int num);
167 void print_param_help(IonType* im, IonTypeList& plugs);
168 float determine_duration(struct gengetopt_args_info *p, TrgList *stim_lst);
169 void determine_stim_list(char *stl, TrgList *trg, bool DIAs);
170 
171 } // namespace limpet
172 
173 #endif
#define GATETYPE_SIZE
Definition: bench_utils.h:141
#define GLOBALDATA_T_SIZE
Definition: bench_utils.h:142
float current()
Definition: bench_utils.h:44
Bisect(float min, float max, float tol=0.01)
object for performing a bisection search
Definition: bench_utils.h:22
bool update(float &val, bool success)
update search
Definition: bench_utils.h:32
Abstract class representing an ionic model type.
Definition: ion_type.h:44
centralize time managment and output triggering
Definition: timer_utils.h:58
void initial_SVs(MULTI_IF *miif, char *SVs, char *imp, char *plgins, int num)
Definition: bench_utils.cc:397
int write_dump_header(GVEC_DUMP *gvd, SV_DUMP *svd, const char *ExpID)
Definition: bench_utils.cc:120
double Real
Definition: MULTI_ION_IF.h:136
void globalvec_dump(FILE **fhdls, GVEC_DUMP *gvd, MULTI_IF *pMIIF, timer_manager *tmo, IOCtrl *io, int numNode)
Definition: bench_utils.cc:257
@ LOOP_IDX
timing for main loop (including IO and ODE solve)
Definition: bench_utils.h:105
@ ODE_IDX
timing for ODE solve
Definition: bench_utils.h:106
@ INIT_IDX
timing for initialization
Definition: bench_utils.h:104
@ N_TIMINGS
number of benchmark timings we use
Definition: bench_utils.h:107
@ SETUP_IDX
timing for setup phase
Definition: bench_utils.h:103
void dump_all(MULTI_IF *MIIF, int reg, char *imp, char *plugs, double t, double ddt, char *fout)
Definition: bench_utils.cc:329
void close_globalvec_dump(FILE **fhdls, GVEC_DUMP *gvd, IOCtrl *io)
Definition: bench_utils.cc:300
double getCellVal(sf_vec *v, int ind)
Definition: bench_utils.cc:377
@ CON_TM_IDX
Definition: bench_utils.h:56
@ DOPPLE_TM_IDX
Definition: bench_utils.h:64
@ LIGHT_TM_IDX
Definition: bench_utils.h:61
@ STM_TM_IDX
Definition: bench_utils.h:60
@ TRACE_TM_IDX
Definition: bench_utils.h:62
@ N_TIMERS
Definition: bench_utils.h:66
@ SVD_TM_IDX
Definition: bench_utils.h:57
@ CLAMP_TM_IDX
Definition: bench_utils.h:63
@ RES_SAVE_TM_IDX
Definition: bench_utils.h:65
@ STA_TM_IDX
Definition: bench_utils.h:58
@ SSV_TM_IDX
Definition: bench_utils.h:59
void initialize_timings(event_timing *t)
Definition: bench_utils.cc:351
constexpr T min(T a, T b)
Definition: ion_type.h:18
void determine_stim_list(char *stl, TrgList *trg, bool DIAs)
Definition: bench_utils.cc:86
std::vector< std::reference_wrapper< IonType > > IonTypeList
Definition: ion_type.h:276
float determine_duration(struct gengetopt_args_info *p, TrgList *stim_lst)
determine time of last stimulus
Definition: bench_utils.cc:488
constexpr T max(T a, T b)
Definition: ion_type.h:16
void open_globalvec_dump(FILE **fhdls, GVEC_DUMP *gvd, MULTI_IF *pMIIF, char *base_name, IOCtrl *io)
Definition: bench_utils.cc:161
void update_timing(event_timing *t, double event_duration)
Definition: bench_utils.cc:361
DataType
data type IDs
Definition: bench_utils.h:111
@ dtype_GlobalData_t
Definition: bench_utils.h:119
@ dtype_Double
Definition: bench_utils.h:117
@ dtype_long
Definition: bench_utils.h:120
@ dtype_Char
Definition: bench_utils.h:115
@ dtype_bool
Definition: bench_utils.h:121
@ dtype_Real
Definition: bench_utils.h:113
@ dtype_Gatetype
Definition: bench_utils.h:112
@ dtype_Short
Definition: bench_utils.h:118
@ dtype_Integer
Definition: bench_utils.h:116
@ dtype_Float
Definition: bench_utils.h:114
void print_param_help(IonType *im, IonTypeList &plugs)
Definition: bench_utils.cc:453
char * fn[NUM_IMP_DATA_TYPES+1]
array to store file names
Definition: bench_utils.h:86
opencarp::FILE_SPEC hdls[NUM_IMP_DATA_TYPES+1]
array of file handles to gvec output files
Definition: bench_utils.h:85
int n_dumps
keep track of number of dumped time slices
Definition: bench_utils.h:88
int dtype[NUM_IMP_DATA_TYPES+1]
data type
Definition: bench_utils.h:87
char first
first line of output
Definition: bench_utils.h:81
char wsplt
split -> each vector goes into separate file
Definition: bench_utils.h:79
char wbin
write to file in binary format
Definition: bench_utils.h:78
char w2file
write to file
Definition: bench_utils.h:77
char w2stdout
turn on/off output to stdout
Definition: bench_utils.h:80
int count
number of events counted so far
Definition: bench_utils.h:99
double avg
average duration of event
Definition: bench_utils.h:97
double mx
maximum duration of event
Definition: bench_utils.h:96
double mn
minimum duration of event
Definition: bench_utils.h:95
double tot
total duration of all events
Definition: bench_utils.h:98
bool init
initialization flag
Definition: bench_utils.h:94
File descriptor struct.
Definition: basics.h:120