openCARP
Doxygen code documentation for the open cardiac electrophysiology simulator openCARP
stimulate.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 
27 #ifndef _STIMULATE_H
28 #define _STIMULATE_H
29 
30 #include "signals.h"
31 #include "physics_types.h"
32 #include "fem_utils.h"
33 
34 namespace opencarp {
35 
36 // the following must be kept in jive with electrics.prm
37 #define EOStim -2
38 #define Transmembrane_I 0
39 #define Extracellular_I 1
40 #define Extracellular_V 2
41 #define Extracellular_Ground 3
42 #define Intracellular_I 4
43 #define Extracellular_V_OL 5
44 //#define Mono_Extracellular_V 6
45 #define Transmembrane_I_Grad 7
46 #define LAT_Triggered 8
47 #define Vm_clamp 9
48 #define Prescribed_Phie 10
49 #define Ignore_Stim 11
50 
51 // to be replaced by sets
52 //#define IsVoltageStim(A) ((A.stimtype==Extracellular_V) || (A.stimtype==Extracellular_V_OL) || (A.stimtype==Vm_clamp))
53 #define IsExtraV(A) ((A.stimtype==Extracellular_V) || (A.stimtype==Extracellular_V_OL))
54 //#define IsVoltageStim_(A) ((A.type==Extracellular_V) || (A.type==Extracellular_V_OL) || (A.type==Vm_clamp))
55 #define IsExtraV_(A) ((A.type==Extracellular_V) || (A.type==Extracellular_V_OL))
56 
57 #define SELECTED_STIM(A,B) ((A==B) || ((A==Extracellular_V_OL) && (B==Extracellular_V)))
58 
59 // flags for ignoring stimuli as function of simulation mode
60 #define IGNORE_NONE 0
61 #define NO_EXTRA_GND 1
62 #define NO_EXTRA_V 2
63 #define NO_EXTRA_I 4
64 
65 #define STM_IGNORE_BIDOMAIN (IGNORE_NONE) // bidomain
66 #define STM_IGNORE_MONODOMAIN (NO_EXTRA_GND | NO_EXTRA_V | NO_EXTRA_I) // monodomain
67 #define STM_IGNORE_PSEUDO_BIDM (NO_EXTRA_V | NO_EXTRA_I) // pseudo-bidomain
68 #define STM_IGNORE_FLOAT_GND (NO_EXTRA_GND | NO_EXTRA_V) // bidomain w/floating ground
69 
70 // define electrode specification method
71 #define VOL_BASED_ELEC_DEF 0
72 #define FILE_BASED_ELEC_DEF 1
73 
74 // define boundary condition specification method
75 #define VOL_BASED_BC_DEF 0
76 #define FILE_BASED_BC_DEF 1
77 
80 const std::string wfLabels [] = {"squarePulse", "truncExpPulse", "sinePulse", "arbPulse"};
81 
82 //enum stim_t {I_transmembrane = 0, I_extra};
83 enum stim_t {I_tm=0, I_ex=1, V_ex=2, GND_ex=3, I_in=4, V_ex_ol=5, Illum=6, I_tm_grad=7, I_lat=8, Vm_clmp=9, Phie_pre=10, Ignore_stim=11};
84 enum stim_domain_t {intra_stim = 1, purk_stim = 2, all_stim = 3}; // matches Stimulus.domain from carp.prm
85 
86 // stimulus info conveniene functions
87 void init_stim_info(void);
88 bool is_voltage(stim_t type);
89 bool is_current(stim_t type);
90 bool is_dbc(stim_t type);
91 bool is_extra(stim_t type);
92 
96 {
97  public:
98  double strength = 0.0;
99  double duration = 0.0;
101 
103 
104  inline void assign(double _strength, double _duration, double _dt, waveform_t _wform)
105  {
106  strength = _strength;
107  duration = _duration;
108  wform = _wform;
109  wave = sig::time_trace(_duration, _dt);
111  }
112 
118  void setup(int id);
119 };
120 
122 {
123  public:
124  double start = 0.0;
125  int npls = 0;
126  double pcl = 0.0;
127  int timer_id = -1;
128  int xtrg_id = -1;
129 
136  void setup(int idx, std::string name);
137 };
138 
140 {
141  public:
144  std::string unit;
145  double scale;
147 
148  void setup(int idx);
149 };
150 
152 {
153  public:
154 
156 
160  std::string input_filename;
161 
162  void setup(int idx);
163 };
164 
165 
166 class stimulus
167 {
168  public:
169  int idx = -1;
170  std::string name = "unnamed";
175 
181  void setup(int idx);
182  void translate(int id);
183 
191  bool value(double & v) const;
192 
194  bool is_active() const;
195 };
196 
199 {
200  public:
201 
202  struct dbc_data {
204  sf_vec* cntr = nullptr;
205 
207  if(nod) delete nod;
208  if(cntr) delete cntr;
209  }
210  };
211 
217  std::map<int, dbc_data*> active_dbc;
218 
219 // dbc_manager(sf_mat & im) :
220 // mat(im), stimuli(nullptr)
221 // {
222 // recompute_dbcs();
223 // }
224 
226  mat(im), stimuli(is)
227  {
228  recompute_dbcs();
229  }
230 
232  {
233  clear_active_dbc();
234  }
235 
237  bool dbc_update();
239  void recompute_dbcs();
240 
241  void enforce_dbc_lhs();
242  void enforce_dbc_rhs(sf_vec & rhs);
243 
244 
245  private:
246  inline void clear_active_dbc()
247  {
248  for(auto & d : active_dbc)
249  delete d.second;
250 
251  active_dbc.clear();
252  }
253 };
254 
261 void sample_wave_form(stim_pulse& sp,int idx);
262 
263 } // namespace opencarp
264 
265 #endif
manager for dirichlet boundary conditions
Definition: stimulate.h:199
std::map< int, dbc_data * > active_dbc
the DBCs that are currently active
Definition: stimulate.h:217
sf_mat & mat
the matrix we link the dbc_manager to
Definition: stimulate.h:213
dbc_manager(sf_mat &im, const SF::vector< stimulus > &is)
Definition: stimulate.h:225
void enforce_dbc_rhs(sf_vec &rhs)
Definition: stimulate.cc:716
void recompute_dbcs()
recompute the dbc data.
Definition: stimulate.cc:586
const SF::vector< stimulus > & stimuli
the stimuli we link the dbc_manager to
Definition: stimulate.h:215
bool dbc_update()
check if dbcs have updated
Definition: stimulate.cc:655
Time tracing class.
Definition: signals.h:142
void set_labels(std::string _label)
Definition: signals.h:234
SF::vector< mesh_int_t > vertices
Definition: stimulate.h:158
std::string input_filename
Definition: stimulate.h:160
SF::vector< SF_real > scaling
Definition: stimulate.h:159
void setup(int idx)
assign stimulus physics parameters
Definition: stimulate.cc:327
double scale
internal unit conversion scaling
Definition: stimulate.h:145
bool total_current
whether we apply total current scaling
Definition: stimulate.h:146
stim_t type
type of stimulus
Definition: stimulate.h:142
std::string unit
physical units of stimulus
Definition: stimulate.h:144
stim_domain_t domain
applied in intra- or extracellular space
Definition: stimulate.h:143
int timer_id
timer for stimulus
Definition: stimulate.h:127
int npls
number of stimulus pulses
Definition: stimulate.h:125
double pcl
pacing cycle length
Definition: stimulate.h:126
int xtrg_id
external trigger ID, not used for now
Definition: stimulate.h:128
double start
start time of protocol
Definition: stimulate.h:124
void setup(int idx, std::string name)
Setup from a param stimulus index.
Definition: stimulate.cc:299
define the wave form of a stimulation pulse
Definition: stimulate.h:96
sig::time_trace wave
wave form of stimulus pulse
Definition: stimulate.h:102
void assign(double _strength, double _duration, double _dt, waveform_t _wform)
Definition: stimulate.h:104
void setup(int id)
Setup from a param stimulus index.
Definition: stimulate.cc:202
double duration
duration of stimulus
Definition: stimulate.h:99
waveform_t wform
wave form of stimulus
Definition: stimulate.h:100
double strength
strength of stimulus
Definition: stimulate.h:98
stim_protocol ptcl
applied stimulation protocol used
Definition: stimulate.h:172
int idx
index in global input stimulus array
Definition: stimulate.h:169
stim_electrode electrode
electrode geometry
Definition: stimulate.h:174
stim_pulse pulse
stimulus wave form
Definition: stimulate.h:171
void translate(int id)
convert legacy definitions to new format
Definition: stimulate.cc:103
bool is_active() const
Return whether stim is active.
Definition: stimulate.cc:190
void setup(int idx)
Setup from a param stimulus index.
Definition: stimulate.cc:166
stim_physics phys
physics of stimulus
Definition: stimulate.h:173
bool value(double &v) const
Get the current value if the stimulus is active.
Definition: stimulate.cc:435
std::string name
label stimulus
Definition: stimulate.h:170
FEM utilities functions.
void sample_wave_form(stim_pulse &sp, int idx)
sample a signal given in analytic form
Definition: stimulate.cc:358
bool is_dbc(stim_t type)
whether stimulus is a dirichlet type. implies boundary conditions on matrix
Definition: stimulate.cc:79
const std::string wfLabels[]
Definition: stimulate.h:80
@ sinePulse
Definition: stimulate.h:79
@ constPulse
Definition: stimulate.h:79
@ squarePulse
Definition: stimulate.h:79
@ truncExpPulse
Definition: stimulate.h:79
@ arbPulse
Definition: stimulate.h:79
@ unsetPulse
Definition: stimulate.h:79
@ Phie_pre
Definition: stimulate.h:83
@ Ignore_stim
Definition: stimulate.h:83
@ I_tm_grad
Definition: stimulate.h:83
@ V_ex_ol
Definition: stimulate.h:83
@ GND_ex
Definition: stimulate.h:83
@ Vm_clmp
Definition: stimulate.h:83
void init_stim_info(void)
Definition: stimulate.cc:52
bool is_extra(stim_t type)
whether stimulus is on extra grid (or on intra)
Definition: stimulate.cc:84
bool is_current(stim_t type)
uses current as stimulation
Definition: stimulate.cc:74
stim_domain_t
Definition: stimulate.h:84
@ purk_stim
Definition: stimulate.h:84
@ intra_stim
Definition: stimulate.h:84
@ all_stim
Definition: stimulate.h:84
bool is_voltage(stim_t type)
uses voltage as stimulation
Definition: stimulate.cc:68
Basic physics types.
Manage time signals used for stimulation and other time-dependent boundary conditions.
SF::vector< SF_int > * nod
Definition: stimulate.h:203