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);
110  wave.set_labels(wfLabels[wform]);
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 
155  enum def_t {file_based, vol_based_tag, vol_based_shape};
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 {
203  SF::vector<SF_int>* nod = nullptr;
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 
220  mat(im), stimuli(is)
221  {
222  recompute_dbcs();
223  }
224 
226  {
227  clear_active_dbc();
228  }
229 
231  bool dbc_update();
233  void recompute_dbcs();
234 
235  void enforce_dbc_lhs();
236  void enforce_dbc_rhs(sf_vec & rhs);
237 
238 
239  private:
240  inline void clear_active_dbc()
241  {
242  for(auto & d : active_dbc)
243  delete d.second;
244 
245  active_dbc.clear();
246  }
247 };
248 
255 void sample_wave_form(stim_pulse& sp,int idx);
256 
257 } // namespace opencarp
258 
259 #endif
stim_electrode electrode
electrode geometry
Definition: stimulate.h:174
double scale
internal unit conversion scaling
Definition: stimulate.h:145
stim_pulse pulse
stimulus wave form
Definition: stimulate.h:171
bool is_voltage(stim_t type)
uses voltage as 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:158
std::map< int, dbc_data * > active_dbc
the DBCs that are currently active
Definition: stimulate.h:217
void assign(double _strength, double _duration, double _dt, waveform_t _wform)
Definition: stimulate.h:104
void init_stim_info(void)
Definition: stimulate.cc:49
waveform_t wform
wave form of stimulus
Definition: stimulate.h:100
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:159
define the wave form of a stimulation pulse
Definition: stimulate.h:95
Time tracing class.
Definition: signals.h:142
manager for dirichlet boundary conditions
Definition: stimulate.h:198
stim_domain_t domain
applied in intra- or extracellular space
Definition: stimulate.h:143
void set_labels(std::string _label)
Definition: signals.h:234
const std::string wfLabels[]
Definition: stimulate.h:80
double duration
duration of stimulus
Definition: stimulate.h:99
sig::time_trace wave
wave form of stimulus pulse
Definition: stimulate.h:102
sf_mat & mat
the matrix we link the dbc_manager to
Definition: stimulate.h:213
const SF::vector< stimulus > & stimuli
the stimuli we link the dbc_manager to
Definition: stimulate.h:215
Manage time signals used for stimulation and other time-dependent boundary conditions.
bool total_current
whether we apply total current scaling
Definition: stimulate.h:146
std::string input_filename
Definition: stimulate.h:160
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:142
void sample_wave_form(stim_pulse &sp, int idx)
sample a signal given in analytic form
Definition: stimulate.cc:365
double strength
strength of stimulus
Definition: stimulate.h:98
stim_protocol ptcl
applied stimulation protocol used
Definition: stimulate.h:172
stim_physics phys
physics of stimulus
Definition: stimulate.h:173
dbc_manager(sf_mat &im, const SF::vector< stimulus > &is)
Definition: stimulate.h:219
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:84
std::string unit
physical units of stimulus
Definition: stimulate.h:144
Basic physics types.