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