openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
bench_utils.h
Go to the documentation of this file.
1 // ----------------------------------------------------------------------------
2 // openCARP is an open cardiac electrophysiology simulator.
3 //
4 // Copyright (C) 2020 openCARP project
5 //
6 // This program is licensed under the openCARP Academic Public License (APL)
7 // v1.0: You can use and redistribute it and/or modify it in non-commercial
8 // academic environments under the terms of APL as published by the openCARP
9 // project v1.0, or (at your option) any later version. Commercial use requires
10 // a commercial license (info@opencarp.org).
11 //
12 // This program is distributed without any warranty; see the openCARP APL for
13 // more details.
14 //
15 // You should have received a copy of the openCARP APL along with this program
16 // and can find it online: http://www.opencarp.org/license
17 // ----------------------------------------------------------------------------
18 
19 #ifndef _BENCH_UTILS_H
20 #define _BENCH_UTILS_H
21 
22 #include "cmdline.h"
23 #include "restitute.h"
24 
27 class Bisect {
28  public:
29 
37  Bisect( float min, float max, float tol=0.01 ):_min(min),_max(max),_tol(tol){}
47  bool update( float &val, bool success ){
48  if( success ){
49  _curr = (val+_min)/2.;
50  _max = val;
51  } else {
52  _curr = _max==INFINITY ? val*2 : (val+_max)/2.;
53  _min = val;
54  }
55  _found = fabs((val-_curr)/val) <= _tol;
56  val = _curr;
57  return _found;
58  }
59  float current(){ return _curr; }
60  private:
61  float _min;
62  float _max;
63  float _curr;
64  float _tol;
65  bool _found = false;
66 };
67 
68 namespace limpet {
69 
70 enum TimerIDs {
71  CON_TM_IDX, // IO timer for console output
72  SVD_TM_IDX, // IO timer for state variable output
73  STA_TM_IDX, // IO timer for state saves (checkpointing)
74  SSV_TM_IDX, // IO timer for single state vector saves
75  STM_TM_IDX, // timer for stimulus trigger
76  LIGHT_TM_IDX, // timer for illumination trigger
77  TRACE_TM_IDX, // timer for trace output
78  CLAMP_TM_IDX, // timer for trace output
80  RES_SAVE_TM_IDX, // timer for saving state vectors during restitution
81  N_TIMERS // number of IO Timers we are going to use
82 };
83 
84 #define TIME_OUT 1. // output period for data
85 #define NUMSEG 1 // number of nodes or nodes
86 
87 // STATE VARIABLE DUMPS
88 #define DT_SV_DUMP 1. // output interval for sv dumps
89 
90 // typedefs
91 struct IOCtrl {
92  char w2file;
93  char wbin;
94  char wsplt;
95  char w2stdout;
96  char first;
97 };
98 
99 struct GVEC_DUMP {
100  opencarp::FILE_SPEC hdls[NUM_IMP_DATA_TYPES+1];
101  char* fn[NUM_IMP_DATA_TYPES+1];
102  int dtype[NUM_IMP_DATA_TYPES+1];
103  int n_dumps;
104 };
105 
106 // record statistics on the duration of events
107 #define us_RESOLUTION 1
108 struct event_timing {
109  bool init;
110  double mn;
111  double mx;
112  double avg;
113  double tot;
114  int count;
115 };
116 
117 enum timingIDs {
122  N_TIMINGS
123 };
124 
126 typedef enum {
136  dtype_bool
138 
140 static const char * const data_type_names[] = {
141  "Gatetype",
142  "Real",
143  "float",
144  "char",
145  "int",
146  "double",
147  "short",
148  "GlobalData_t",
149  "long",
150  "bool"
151 };
152 
153 // Gatetype is defined in LIMPET only and typically defined as float
154 // if defined otherwise, the size has to be overruled within LIMPET
155 // in this case the const qualifier has to be removed.
156 #define GATETYPE_SIZE 4
157 #define GLOBALDATA_T_SIZE 8
159 static const int data_type_sizes[] = {
161  sizeof(limpet::Real),
162  sizeof(float),
163  sizeof(char),
164  sizeof(int),
165  sizeof(double),
166  sizeof(short),
168  sizeof(long),
169  sizeof(bool)
170 };
171 
172 
173 int write_dump_header(GVEC_DUMP *gvd, SV_DUMP *svd, const char *ExpID);
174 void open_globalvec_dump(FILE **fhdls, GVEC_DUMP *gvd, MULTI_IF *pMIIF, char *base_name, IOCtrl *io);
175 void globalvec_dump(FILE **fhdls, GVEC_DUMP *gvd, MULTI_IF *pMIIF, opencarp::timer_manager *tm, IOCtrl *io, int numNode);
176 void close_globalvec_dump(FILE **fhdls, GVEC_DUMP *gvd, IOCtrl *io);
177 void dump_all(MULTI_IF *, int, char *, char *, double, double, char *);
178 void update_timing(event_timing *t, double event_duration);
180 double getCellVal(opencarp::sf_vec* v, int ind);
181 void initial_SVs(MULTI_IF *miif, char *SVs, char *imp, char *plgins, int num);
182 void print_param_help(IonType* im, IonTypeList& plugs);
183 float determine_duration(struct gengetopt_args_info *p, TrgList *stim_lst);
184 void determine_stim_list(char *stl, TrgList *trg, bool DIAs);
185 
186 } // namespace limpet
187 
188 #endif
#define GATETYPE_SIZE
Definition: bench_utils.h:156
#define GLOBALDATA_T_SIZE
Definition: bench_utils.h:157
float current()
Definition: bench_utils.h:59
Bisect(float min, float max, float tol=0.01)
object for performing a bisection search
Definition: bench_utils.h:37
bool update(float &val, bool success)
update search
Definition: bench_utils.h:47
Abstract class representing an ionic model type.
Definition: ion_type.h:59
centralize time managment and output triggering
Definition: timer_utils.h:73
void initial_SVs(MULTI_IF *miif, char *SVs, char *imp, char *plgins, int num)
Definition: bench_utils.cc:412
int write_dump_header(GVEC_DUMP *gvd, SV_DUMP *svd, const char *ExpID)
Definition: bench_utils.cc:135
double Real
Definition: MULTI_ION_IF.h:151
void globalvec_dump(FILE **fhdls, GVEC_DUMP *gvd, MULTI_IF *pMIIF, timer_manager *tmo, IOCtrl *io, int numNode)
Definition: bench_utils.cc:272
@ LOOP_IDX
timing for main loop (including IO and ODE solve)
Definition: bench_utils.h:120
@ ODE_IDX
timing for ODE solve
Definition: bench_utils.h:121
@ INIT_IDX
timing for initialization
Definition: bench_utils.h:119
@ N_TIMINGS
number of benchmark timings we use
Definition: bench_utils.h:122
@ SETUP_IDX
timing for setup phase
Definition: bench_utils.h:118
void dump_all(MULTI_IF *MIIF, int reg, char *imp, char *plugs, double t, double ddt, char *fout)
Definition: bench_utils.cc:344
void close_globalvec_dump(FILE **fhdls, GVEC_DUMP *gvd, IOCtrl *io)
Definition: bench_utils.cc:315
double getCellVal(sf_vec *v, int ind)
Definition: bench_utils.cc:392
@ CON_TM_IDX
Definition: bench_utils.h:71
@ DOPPLE_TM_IDX
Definition: bench_utils.h:79
@ LIGHT_TM_IDX
Definition: bench_utils.h:76
@ STM_TM_IDX
Definition: bench_utils.h:75
@ TRACE_TM_IDX
Definition: bench_utils.h:77
@ N_TIMERS
Definition: bench_utils.h:81
@ SVD_TM_IDX
Definition: bench_utils.h:72
@ CLAMP_TM_IDX
Definition: bench_utils.h:78
@ RES_SAVE_TM_IDX
Definition: bench_utils.h:80
@ STA_TM_IDX
Definition: bench_utils.h:73
@ SSV_TM_IDX
Definition: bench_utils.h:74
void initialize_timings(event_timing *t)
Definition: bench_utils.cc:366
constexpr T min(T a, T b)
Definition: ion_type.h:33
void determine_stim_list(char *stl, TrgList *trg, bool DIAs)
Definition: bench_utils.cc:101
std::vector< std::reference_wrapper< IonType > > IonTypeList
Definition: ion_type.h:291
float determine_duration(struct gengetopt_args_info *p, TrgList *stim_lst)
determine time of last stimulus
Definition: bench_utils.cc:503
constexpr T max(T a, T b)
Definition: ion_type.h:31
void open_globalvec_dump(FILE **fhdls, GVEC_DUMP *gvd, MULTI_IF *pMIIF, char *base_name, IOCtrl *io)
Definition: bench_utils.cc:176
void update_timing(event_timing *t, double event_duration)
Definition: bench_utils.cc:376
DataType
data type IDs
Definition: bench_utils.h:126
@ dtype_GlobalData_t
Definition: bench_utils.h:134
@ dtype_Double
Definition: bench_utils.h:132
@ dtype_long
Definition: bench_utils.h:135
@ dtype_Char
Definition: bench_utils.h:130
@ dtype_bool
Definition: bench_utils.h:136
@ dtype_Real
Definition: bench_utils.h:128
@ dtype_Gatetype
Definition: bench_utils.h:127
@ dtype_Short
Definition: bench_utils.h:133
@ dtype_Integer
Definition: bench_utils.h:131
@ dtype_Float
Definition: bench_utils.h:129
void print_param_help(IonType *im, IonTypeList &plugs)
Definition: bench_utils.cc:468
char * fn[NUM_IMP_DATA_TYPES+1]
array to store file names
Definition: bench_utils.h:101
opencarp::FILE_SPEC hdls[NUM_IMP_DATA_TYPES+1]
array of file handles to gvec output files
Definition: bench_utils.h:100
int n_dumps
keep track of number of dumped time slices
Definition: bench_utils.h:103
int dtype[NUM_IMP_DATA_TYPES+1]
data type
Definition: bench_utils.h:102
char first
first line of output
Definition: bench_utils.h:96
char wsplt
split -> each vector goes into separate file
Definition: bench_utils.h:94
char wbin
write to file in binary format
Definition: bench_utils.h:93
char w2file
write to file
Definition: bench_utils.h:92
char w2stdout
turn on/off output to stdout
Definition: bench_utils.h:95
int count
number of events counted so far
Definition: bench_utils.h:114
double avg
average duration of event
Definition: bench_utils.h:112
double mx
maximum duration of event
Definition: bench_utils.h:111
double mn
minimum duration of event
Definition: bench_utils.h:110
double tot
total duration of all events
Definition: bench_utils.h:113
bool init
initialization flag
Definition: bench_utils.h:109
File descriptor struct.
Definition: basics.h:135