openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
MULTI_ION_IF.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 
132 #ifndef MULTI_ION_IF_H
133 #define MULTI_ION_IF_H
134 
135 #include <ctime>
136 #include <cstdarg>
137 #include <cstddef>
138 #include <string>
139 #include <sys/resource.h>
140 
141 #include "ION_IF.h"
142 
143 #include "timer_utils.h"
144 #include "fem_types.h"
145 #include "sf_interface.h"
146 
147 #define FARADAY 96485
148 
149 namespace limpet {
150 
151 typedef double Real;
152 
153 static const unsigned int MIIF_Format = 1;
154 static const char *Magic_MIIF_ID = "Dump_MIIF_ID";
155 
160 struct SV_DUMP {
161  int active;
162  int n;
164  char** fn;
165  int* reg;
166  char** svnames;
167  double intv;
168  double t_dump;
169  int n_dumps;
170  long nwr;
171  int* offset;
172  int* size;
173  int* dtype;
174  int* num;
175  void** svtab;
176  size_t* svsize;
177 };
178 
183 struct Trace_Info {
184  bool found;
185  bool ignored;
186  int node_idx;
187  int region;
189 };
190 
194 class MULTI_IF {
195 
196  public:
197  std::string name;
198  bool doppel;
199  int* N_Nodes;
200  int** NodeLists;
201  std::vector<IonIfBase*> IIF;
203  GlobalData_t* procdata[NUM_IMP_DATA_TYPES];
205  bool* contiguous;
207  bool extUpdateVm;
208  int* numplugs;
209  int numNode;
210  int N_IIF;
212  std::vector<Target> targets;
214  std::vector<IonTypeList> plugtypes;
215  opencarp::sf_vec* gdata[NUM_IMP_DATA_TYPES];
217 
218  double dt;
219  int numSubDt;
220 
221 #ifdef HDF5
222  hid_t file;
223 #endif // ifdef HDF5
224 
225  MULTI_IF() : doppel(false), N_Nodes(NULL), NodeLists(NULL), IIF({}), extUpdateVm(false), logger(NULL)
226  {
227  zero_data();
228  }
229 
231 
232  void zero_data() {
233  name = "";
234  N_Nodes = NULL;
235  NodeLists = NULL;
236  IIF = {};
237  STRUCT_ZERO(svd);
239  ldata = NULL;
240  contiguous = NULL;
241  trace_info = NULL;
242  numplugs = NULL;
243  iontypes = {};
244  IIFmask = NULL;
245  plugtypes = {};
247  }
248 
249  void initialize_MIIF();
250  void initialize_currents(double, int);
251 
252  void compute_ionic_current(bool flag_send = 1, bool flag_receive = 1); // pMIIF
253 
254  void free_MIIF(); // pMIIF
255 
256  void sv_dump_add(int, const IonType&, int, int, int, const char *, const char *);
257  int sv_dump_add_by_name(int, char *, char *, char *, char *);
258  void sv_dump_add_by_name_list(int, char *, char *, char *, char *,
259  char *, double, double);
261  void close_svs_dumps();
262  void dump_luts_MIIF(bool);
263 
264  void dump_state(char *, float, opencarp::mesh_t gid, bool, unsigned int);
265  void transmem_stim_species(float, const char *, float, int *, int);
266  float restore_state(const char *, opencarp::mesh_t gid, bool);
267  void releaseRealData();
269  void getRealData();
270  int adjust_MIIF_variables(const char* variable,
271  const SF::vector<int> & indices,
272  const SF::vector<double> & values);
273  void MIIF_change_dt(double);
274  bool use_stretch();
275 
277 };
278 
280 
281 void doppel_MIIF(MULTI_IF *, MULTI_IF *);
282 void doppel_update(MULTI_IF *, MULTI_IF *);
283 void free_doppel(MULTI_IF *);
284 void dup_IMP_node_state(IonIfBase&, int, int, GlobalData_t **ldata);
285 
287 int get_plug_flag(char *, int *, IonTypeList&);
288 int IMPdataLabel2Index(const char *);
289 char* tokstr_r(char *s1, const char *s2, char **lasts);
290 
291 void open_trace(MULTI_IF *MIIF, int n_traceNodes, int *traceNodes, int *label, opencarp::sf_mesh* imesh);
292 void dump_trace(MULTI_IF *MIIF, limpet::Real time);
293 
294 
300 #define USED_DAT(I, F) ( (I)->get_reqdat()&F || (I)->get_moddat()&F)
301 
313 #define get_plug_params(M, R, P) (P ## _Params *)get_IIF_plugparam(*(M.IIF[R]), P ## _ID)
314 
315 
325 #define SVD_add(I, R, T, M) {T ## _state *sv; int dtype = 0; sv_dump_add(&I, R, \
326  T ## _ID, offsetof(T ## _state, \
327  M), \
328  sizeof(sv->M), dtype, # R "." # T "." # M, # T, \
329  # R); }
330 } // namespace limpet
331 
332 #endif // MULTI_ION_IF_H
#define STRUCT_ZERO(S)
Definition: basics.h:51
Represents the ionic model and plug-in (IMP) data structure.
Definition: ION_IF.h:138
Abstract class representing an ionic model type.
Definition: ion_type.h:59
int numNode
local number of nodes
Definition: MULTI_ION_IF.h:209
bool extUpdateVm
flag indicating update function for Vm
Definition: MULTI_ION_IF.h:207
int dump_svs(opencarp::base_timer *)
std::vector< IonIfBase * > IIF
array of IIF's
Definition: MULTI_ION_IF.h:201
opencarp::sf_vec * gdata[NUM_IMP_DATA_TYPES]
data used by all IMPs
Definition: MULTI_ION_IF.h:215
void sv_dump_add_by_name_list(int, char *, char *, char *, char *, char *, double, double)
int * numplugs
number of plugins for each region
Definition: MULTI_ION_IF.h:208
std::vector< Target > targets
target for each region
Definition: MULTI_ION_IF.h:212
std::vector< IonTypeList > plugtypes
plugins types for each region
Definition: MULTI_ION_IF.h:214
IonTypeList iontypes
type for each region
Definition: MULTI_ION_IF.h:211
void dump_state(char *, float, opencarp::mesh_t gid, bool, unsigned int)
SV_DUMP svd
state variable dump
Definition: MULTI_ION_IF.h:202
void sv_dump_add(int, const IonType &, int, int, int, const char *, const char *)
void * thread_initialize_MIIF()
void transmem_stim_species(float, const char *, float, int *, int)
void initialize_currents(double, int)
GlobalData_t *** ldata
data local to each IMP
Definition: MULTI_ION_IF.h:204
int adjust_MIIF_variables(const char *variable, const SF::vector< int > &indices, const SF::vector< double > &values)
float restore_state(const char *, opencarp::mesh_t gid, bool)
int N_IIF
how many different IIF's
Definition: MULTI_ION_IF.h:210
void compute_ionic_current(bool flag_send=1, bool flag_receive=1)
GPU kernel to emulate the add_scaled call made to adjust the Vm values when the update to Vm is not m...
int sv_dump_add_by_name(int, char *, char *, char *, char *)
Trace_Info * trace_info
Information about traces.
Definition: MULTI_ION_IF.h:206
double dt
time step (ms)
Definition: MULTI_ION_IF.h:218
int * N_Nodes
#nodes for each IMP
Definition: MULTI_ION_IF.h:199
int ** NodeLists
local partitioned node lists for each IMP stored
Definition: MULTI_ION_IF.h:200
GlobalData_t * procdata[NUM_IMP_DATA_TYPES]
data for this processor
Definition: MULTI_ION_IF.h:203
void dump_luts_MIIF(bool)
bool * contiguous
whether a region is contiguously numbered
Definition: MULTI_ION_IF.h:205
opencarp::FILE_SPEC logger
Definition: MULTI_ION_IF.h:216
int numSubDt
number of sub-dt time steps
Definition: MULTI_ION_IF.h:219
void MIIF_change_dt(double)
IIF_Mask_t * IIFmask
region for each node
Definition: MULTI_ION_IF.h:213
std::string name
name for MIIF region
Definition: MULTI_ION_IF.h:197
bool doppel
is this a shallow clone?
Definition: MULTI_ION_IF.h:198
void releaseRealDataDuringInit()
Structs and types for (electric) FEM.
void doppel_MIIF(MULTI_IF *orig, MULTI_IF *miif_doppel)
int get_plug_flag(char *plgstr, int *out_num_plugins, IonTypeList &out_plugins)
void doppel_update(MULTI_IF *orig, MULTI_IF *miif_doppel)
double Real
Definition: MULTI_ION_IF.h:151
void dup_IMP_node_state(IonIfBase &IF, int from, int to, GlobalData_t **localdata)
int IMPdataLabel2Index(const char *sv)
SF_real GlobalData_t
Definition: limpet_types.h:27
FILE_SPEC _nc_logf
Definition: ION_IF.cc:78
std::vector< std::reference_wrapper< IonType > > IonTypeList
Definition: ion_type.h:288
void dump_trace(MULTI_IF *MIIF, limpet::Real time)
void open_trace(MULTI_IF *MIIF, int n_traceNodes, int *traceNodes, int *label, opencarp::sf_mesh *imesh)
Set up ionic model traces at some global node numbers.
char IIF_Mask_t
Definition: ion_type.h:50
void free_doppel(MULTI_IF *m)
char * tokstr_r(char *s1, const char *s2, char **lasts)
Definition: ION_IF.cc:82
void * get_IIF_plugparam(IonIfBase &, int)
mesh_t
The enum identifying the different meshes we might want to load.
Definition: sf_interface.h:60
Interface to SlimFem.
data structure to manage state variable file dumps
Definition: MULTI_ION_IF.h:160
size_t * svsize
state variable sizes
Definition: MULTI_ION_IF.h:176
char ** fn
array to store file names
Definition: MULTI_ION_IF.h:164
double intv
time interval for sv dumps
Definition: MULTI_ION_IF.h:167
int * dtype
data type
Definition: MULTI_ION_IF.h:173
int n_dumps
keep track of number of dumped time slices
Definition: MULTI_ION_IF.h:169
long nwr
keep track of number of written tokens
Definition: MULTI_ION_IF.h:170
int * size
sizes of SV to dump
Definition: MULTI_ION_IF.h:172
void ** svtab
state variable tables
Definition: MULTI_ION_IF.h:175
int * reg
array to store region ids
Definition: MULTI_ION_IF.h:165
double t_dump
next instant for sv dump
Definition: MULTI_ION_IF.h:168
int * num
number of nodes
Definition: MULTI_ION_IF.h:174
char ** svnames
array to store sv names
Definition: MULTI_ION_IF.h:166
int n
#state variables we want to dump
Definition: MULTI_ION_IF.h:162
int * offset
offsets into structure for SV
Definition: MULTI_ION_IF.h:171
opencarp::FILE_SPEC * hdls
array of file handles to sv output files
Definition: MULTI_ION_IF.h:163
data structure to manage trace dumps. Should eventually be combined with the state variable dumps,...
Definition: MULTI_ION_IF.h:183
bool ignored
globally not found
Definition: MULTI_ION_IF.h:185
bool found
found on this node
Definition: MULTI_ION_IF.h:184
opencarp::FILE_SPEC file
Definition: MULTI_ION_IF.h:188
int node_idx
local node number
Definition: MULTI_ION_IF.h:186
File descriptor struct.
Definition: basics.h:133
Timers and timer manager.