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 Stimulus.stimtype in openCARP.prm
37 #define Transmembrane_I 0
38 #define Extracellular_I 1
39 #define Extracellular_V 2
40 #define Extracellular_Ground 3
41 #define Intracellular_I 4
42 #define Extracellular_V_OL 5
43 #define Illumination 6
44 //#define Transmembrane_I_Grad 7
45 //#define LAT_Triggered 8
46 #define Vm_clamp 9
47 //#define Prescribed_Phie 10
48 #define Ignore_Stim 11
49 
50 #define IsExtraV(A) ((A.stimtype==Extracellular_V) || (A.stimtype==Extracellular_V_OL))
51 #define SELECTED_STIM(A,B) ((A==B) || ((A==Extracellular_V_OL) && (B==Extracellular_V)))
52 
53 // flags for ignoring stimuli as function of simulation mode
54 #define IGNORE_NONE 0
55 #define NO_EXTRA_GND 1
56 #define NO_EXTRA_V 2
57 #define NO_EXTRA_I 4
58 
59 #define STM_IGNORE_BIDOMAIN (IGNORE_NONE) // bidomain
60 #define STM_IGNORE_MONODOMAIN (NO_EXTRA_GND | NO_EXTRA_V | NO_EXTRA_I) // monodomain
61 #define STM_IGNORE_PSEUDO_BIDM (NO_EXTRA_V | NO_EXTRA_I) // pseudo-bidomain
62 #define STM_IGNORE_FLOAT_GND (NO_EXTRA_GND | NO_EXTRA_V) // bidomain w/floating ground
63 
64 // define electrode specification method
65 #define VOL_BASED_ELEC_DEF 0
66 #define FILE_BASED_ELEC_DEF 1
67 
68 // define boundary condition specification method
69 #define VOL_BASED_BC_DEF 0
70 #define FILE_BASED_BC_DEF 1
71 
74 const std::string wfLabels [] = {"squarePulse", "truncExpPulse", "sinePulse", "arbPulse"};
75 
76 //enum stim_t {I_transmembrane = 0, I_extra};
77 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};
78 enum stim_domain_t {intra_stim = 1, purk_stim = 2, all_stim = 3}; // matches Stimulus.domain from openCARP.prm
79 
80 // stimulus info conveniene functions
81 void init_stim_info(void);
82 bool is_voltage(stim_t type);
83 bool is_current(stim_t type);
84 bool is_dbc(stim_t type);
85 bool is_extra(stim_t type);
86 
90 {
91  public:
92  double strength = 0.0;
93  double duration = 0.0;
95 
97 
98  inline void assign(double _strength, double _duration, double _dt, waveform_t _wform)
99  {
100  strength = _strength;
101  duration = _duration;
102  wform = _wform;
103  wave = sig::time_trace(_duration, _dt);
104  wave.set_labels(wfLabels[wform]);
105  }
106 
112  void setup(int id);
113 };
114 
116 {
117  public:
118  double start = 0.0;
119  int npls = 0;
120  double pcl = 0.0;
121  int timer_id = -1;
122  int xtrg_id = -1;
123 
130  void setup(int idx, std::string name);
131 };
132 
134 {
135  public:
138  std::string unit;
139  double scale;
141 
142  void setup(int idx);
143 };
144 
146 {
147  public:
148 
149  enum def_t {file_based, vol_based_tag, vol_based_shape};
150 
154  std::string input_filename;
155 
156  void setup(int idx);
157 };
158 
159 
160 class stimulus
161 {
162  public:
163  int idx = -1;
164  std::string name = "unnamed";
169 
175  void setup(int idx);
176  void translate(int id);
177 
185  bool value(double & v) const;
186 
188  bool is_active() const;
189 };
190 
193 {
194  public:
195 
196  struct dbc_data {
197  SF::vector<SF_int>* nod = nullptr;
198  sf_vec* cntr = nullptr;
199 
201  if(nod) delete nod;
202  if(cntr) delete cntr;
203  }
204  };
205 
211  std::map<int, dbc_data*> active_dbc;
212 
214  mat(im), stimuli(is)
215  {
216  recompute_dbcs();
217  }
218 
220  {
221  clear_active_dbc();
222  }
223 
225  bool dbc_update();
227  void recompute_dbcs();
228 
229  void enforce_dbc_lhs();
230  void enforce_dbc_rhs(sf_vec & rhs);
231 
232 
233  private:
234  inline void clear_active_dbc()
235  {
236  for(auto & d : active_dbc)
237  delete d.second;
238 
239  active_dbc.clear();
240  }
241 };
242 
249 void sample_wave_form(stim_pulse& sp,int idx);
250 
251 } // namespace opencarp
252 
253 #endif
stim_electrode electrode
electrode geometry
Definition: stimulate.h:168
double scale
internal unit conversion scaling
Definition: stimulate.h:139
stim_pulse pulse
stimulus wave form
Definition: stimulate.h:165
bool is_voltage(stim_t type)
uses current for stimulation
Definition: stimulate.cc:65
bool is_current(stim_t type)
uses current as stimulation
Definition: stimulate.cc:71
SF::vector< mesh_int_t > vertices
Definition: stimulate.h:152
std::map< int, dbc_data * > active_dbc
the DBCs that are currently active
Definition: stimulate.h:211
void assign(double _strength, double _duration, double _dt, waveform_t _wform)
Definition: stimulate.h:98
void init_stim_info(void)
uses voltage for stimulation
Definition: stimulate.cc:49
waveform_t wform
wave form of stimulus
Definition: stimulate.h:94
FEM utilities functions.
void setup(int id)
Setup from a param stimulus index.
Definition: stimulate.cc:199
SF::vector< SF_real > scaling
Definition: stimulate.h:153
define the wave form of a stimulation pulse
Definition: stimulate.h:89
Time tracing class.
Definition: signals.h:142
manager for dirichlet boundary conditions
Definition: stimulate.h:192
stim_domain_t domain
applied in intra- or extracellular space
Definition: stimulate.h:137
void set_labels(std::string _label)
Definition: signals.h:234
const std::string wfLabels[]
Definition: stimulate.h:74
double duration
duration of stimulus
Definition: stimulate.h:93
sig::time_trace wave
wave form of stimulus pulse
Definition: stimulate.h:96
sf_mat & mat
the matrix we link the dbc_manager to
Definition: stimulate.h:207
const SF::vector< stimulus > & stimuli
the stimuli we link the dbc_manager to
Definition: stimulate.h:209
Manage time signals used for stimulation and other time-dependent boundary conditions.
bool total_current
whether we apply total current scaling
Definition: stimulate.h:140
std::string input_filename
Definition: stimulate.h:154
bool is_extra(stim_t type)
whether stimulus is on extra grid (or on intra)
Definition: stimulate.cc:81
stim_t type
type of stimulus
Definition: stimulate.h:136
void sample_wave_form(stim_pulse &sp, int idx)
sample a signal given in analytic form
Definition: stimulate.cc:363
double strength
strength of stimulus
Definition: stimulate.h:92
stim_protocol ptcl
applied stimulation protocol used
Definition: stimulate.h:166
stim_physics phys
physics of stimulus
Definition: stimulate.h:167
dbc_manager(sf_mat &im, const SF::vector< stimulus > &is)
Definition: stimulate.h:213
bool is_dbc(stim_t type)
whether stimulus is a dirichlet type. implies boundary conditions on matrix
Definition: stimulate.cc:76
stim_domain_t
Definition: stimulate.h:78
std::string unit
physical units of stimulus
Definition: stimulate.h:138
Basic physics types.