1
- // Author: Lucas Berg
1
+ // -------------------------------------------------------------------------------------
2
+ // Authors: Lucas Berg, Julia Camps and Jenny Wang
3
+ // Script to calibrate the monodomain conductivities using a cable simulation.
4
+ // -------------------------------------------------------------------------------------
2
5
3
6
#include < iostream>
4
7
#include < string>
@@ -29,8 +32,13 @@ using namespace std;
29
32
30
33
const double TOLERANCE = 1.0e-02 ; // 1 cm/s
31
34
32
- double calculate_conduction_velocity_from_cable_simulation ()
33
- {
35
+ // Change your MonoAlg3D path here:
36
+ // ----------------------------------------------------------
37
+ const char MONOALG_PATH[500 ] = " /home/berg/Github/MonoAlg3D_C" ;
38
+ // ----------------------------------------------------------
39
+
40
+ double calculate_conduction_velocity_from_cable_simulation () {
41
+
34
42
string filename = " outputs/cable/tissue_activation_time_map_pulse_it_0.vtu" ;
35
43
36
44
// Read all the data from the file
@@ -94,33 +102,35 @@ double calculate_conduction_velocity_from_cable_simulation ()
94
102
}
95
103
96
104
// TODO: Maybe pass a pre-configured config file as an input parameter with the cellular model setup that the user will use
97
- void write_configuration_file (const double sigma)
98
- {
99
- FILE *file = fopen (" /home/jenny/MonoAlg3D_C/scripts/tuneCVbenchmark/configs/cable.ini" ," w+" );
105
+ void write_configuration_file (const double sigma) {
106
+
107
+ char filename[500 ];
108
+ sprintf (filename," %s/scripts/tuneCVbenchmark/configs/cable.ini" ,MONOALG_PATH);
109
+ FILE *file = fopen (filename," w+" );
100
110
101
111
fprintf (file," [main]\n " );
102
112
fprintf (file," num_threads=6\n " );
103
113
fprintf (file," dt_pde=0.01\n " );
104
- fprintf (file," simulation_time=100 .0\n " );
114
+ fprintf (file," simulation_time=150 .0\n " );
105
115
fprintf (file," abort_on_no_activity=false\n " );
106
116
fprintf (file," use_adaptivity=false\n " );
107
117
fprintf (file," quiet=true\n " );
108
118
fprintf (file," \n " );
109
119
110
120
fprintf (file," [update_monodomain]\n " );
111
121
fprintf (file," main_function=update_monodomain_default\n " );
112
- fprintf (file," library_file=/home/jenny/MonoAlg3D_C/ shared_libs/libdefault_update_monodomain.so\n " );
122
+ fprintf (file," library_file=%s/ shared_libs/libdefault_update_monodomain.so\n " ,MONOALG_PATH );
113
123
fprintf (file," \n " );
114
124
115
125
// For saving the LATs in a format that can be read for calculating the CVs
116
126
fprintf (file," [save_result]\n " );
117
127
fprintf (file," print_rate=1\n " );
118
- fprintf (file," output_dir=/home/jenny/MonoAlg3D_C/ scripts/tuneCVbenchmark/outputs/cable\n " );
128
+ fprintf (file," output_dir=%s/ scripts/tuneCVbenchmark/outputs/cable\n " ,MONOALG_PATH );
119
129
fprintf (file," save_pvd=true\n " );
120
130
fprintf (file," file_prefix=V\n " );
121
131
fprintf (file," save_activation_time=true\n " );
122
132
fprintf (file," save_apd=false\n " );
123
- fprintf (file," library_file=/home/jenny/MonoAlg3D_C/ shared_libs/libdefault_save_mesh_purkinje.so\n " );
133
+ fprintf (file," library_file=%s/ shared_libs/libdefault_save_mesh_purkinje.so\n " ,MONOALG_PATH );
124
134
fprintf (file," main_function=save_tissue_with_activation_times\n " );
125
135
fprintf (file," init_function=init_save_tissue_with_activation_times\n " );
126
136
fprintf (file," end_function=end_save_tissue_with_activation_times\n " );
@@ -132,7 +142,7 @@ void write_configuration_file (const double sigma)
132
142
fprintf (file," sigma_x=%g\n " ,sigma);
133
143
fprintf (file," sigma_y=%g\n " ,sigma);
134
144
fprintf (file," sigma_z=%g\n " ,sigma);
135
- fprintf (file," library_file=/home/jenny/MonoAlg3D_C/ shared_libs/libdefault_matrix_assembly.so\n " );
145
+ fprintf (file," library_file=%s/ shared_libs/libdefault_matrix_assembly.so\n " ,MONOALG_PATH );
136
146
fprintf (file," main_function=homogeneous_sigma_assembly_matrix\n " );
137
147
fprintf (file," \n " );
138
148
@@ -141,7 +151,7 @@ void write_configuration_file (const double sigma)
141
151
fprintf (file," use_preconditioner=no\n " );
142
152
fprintf (file," use_gpu=yes\n " );
143
153
fprintf (file," max_iterations=200\n " );
144
- fprintf (file," library_file=/home/jenny/MonoAlg3D_C/ shared_libs/libdefault_linear_system_solver.so\n " );
154
+ fprintf (file," library_file=%s/ shared_libs/libdefault_linear_system_solver.so\n " ,MONOALG_PATH );
145
155
fprintf (file," init_function=init_conjugate_gradient\n " );
146
156
fprintf (file," end_function=end_conjugate_gradient\n " );
147
157
fprintf (file," main_function=conjugate_gradient\n " );
@@ -153,15 +163,15 @@ void write_configuration_file (const double sigma)
153
163
fprintf (file," start_dy=500.0\n " );
154
164
fprintf (file," start_dz=500.0\n " );
155
165
fprintf (file," cable_length=20000.0\n " );
156
- fprintf (file," library_file=/home/jenny/MonoAlg3D_C/ shared_libs/libdefault_domains.so\n " );
166
+ fprintf (file," library_file=%s/ shared_libs/libdefault_domains.so\n " ,MONOALG_PATH );
157
167
fprintf (file," main_function=initialize_grid_with_cable_mesh\n " );
158
168
fprintf (file," \n " );
159
169
160
170
fprintf (file," [ode_solver]\n " );
161
171
fprintf (file," dt=0.01\n " );
162
172
fprintf (file," use_gpu=yes\n " );
163
173
fprintf (file," gpu_id=0\n " );
164
- fprintf (file," library_file=/home/jenny/MonoAlg3D_C/ shared_libs/libten_tusscher_tt3_mixed_endo_mid_epi.so\n " );
174
+ fprintf (file," library_file=%s/ shared_libs/libten_tusscher_tt3_mixed_endo_mid_epi.so\n " ,MONOALG_PATH );
165
175
fprintf (file," \n " );
166
176
167
177
fprintf (file," [stim_benchmark]\n " );
@@ -175,16 +185,14 @@ void write_configuration_file (const double sigma)
175
185
fprintf (file, " min_z = 0.0\n " );
176
186
fprintf (file, " max_z = 3000.0\n " );
177
187
fprintf (file," main_function=stim_x_y_z_limits\n " );
178
- fprintf (file," library_file=/home/jenny/MonoAlg3D_C/ shared_libs/libdefault_stimuli.so\n " );
188
+ fprintf (file," library_file=%s/ shared_libs/libdefault_stimuli.so\n " ,MONOALG_PATH );
179
189
fprintf (file," \n " );
180
190
181
191
fclose (file);
182
192
}
183
193
184
- int main (int argc, char *argv[])
185
- {
186
- if (argc-1 != 1 )
187
- {
194
+ int main (int argc, char *argv[]) {
195
+ if (argc-1 != 1 ) {
188
196
cerr << " =============================================================================" << endl;
189
197
cerr << " Usage:> " << argv[0 ] << " <target_CV>" << endl;
190
198
cerr << " =============================================================================" << endl;
@@ -204,20 +212,21 @@ int main (int argc, char *argv[])
204
212
double target_cv = atof (argv[1 ]);
205
213
double sigma = 0.0002 ;
206
214
207
- do
208
- {
215
+ do {
209
216
write_configuration_file (sigma);
210
217
211
218
// Run the simulation
212
- system (" /home/jenny/MonoAlg3D_C/bin/MonoAlg3D -c /home/jenny/MonoAlg3D_C/scripts/tuneCVbenchmark/configs/cable.ini" );
219
+ char command[500 ];
220
+ sprintf (command," %s/bin/MonoAlg3D -c %s/scripts/tuneCVbenchmark/configs/cable.ini" ,MONOALG_PATH,MONOALG_PATH);
221
+ system (command);
213
222
214
223
cv = calculate_conduction_velocity_from_cable_simulation ();
215
224
factor = pow (target_cv/cv,2 );
216
225
sigma = sigma*factor;
217
226
218
227
printf (" \n || Target CV = %g m/s || Computed CV = %g m/s || Factor = %g || Adjusted sigma = %g mS/um ||\n\n " ,target_cv,cv,factor,sigma);
219
228
220
- }while ( fabs (cv-target_cv) > TOLERANCE );
229
+ } while ( fabs (cv-target_cv) > TOLERANCE );
221
230
222
231
printf (" \n [+] Target conductivity = %g mS/um\n " ,sigma);
223
232
0 commit comments