Skip to content

Commit cd6a2d3

Browse files
committed
Preparing repository for pull request to 'rsachetto-master' ...
1 parent 973afe0 commit cd6a2d3

File tree

11 files changed

+136
-346
lines changed

11 files changed

+136
-346
lines changed

ToDo

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,4 +18,4 @@
1818
#KNOW ISSUES:
1919
The logger symbols are only exported to an executable if an static library linked to a shared library uses then. For now this is ok. But I think it will be a pain in future releases.
2020
The GPU linear system solver is not working for purkinje-only simulations
21-
When the minimum number of PMJs is not reached the solver will be in an infinite loop
21+
When the minimum number of PMJs is not reached the solver will be in an infinite loop

example_configs/cable_mesh_with_ToRORd_fkatp_endo_mid_epi.ini

+1-5
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
# ====================================================================
22
# Author: Lucas Berg
33
# Description: Simple simulation to test the ToRORd_fkatp model in a cable.
4-
# With the [extra_data] section we consider:
5-
# 45% of the cable ENDO
6-
# 25% of the cable MID
7-
# 30% of the cable EPI
84
# When no [extra_data] information is provided all cells are
95
# considered to be control ENDO.
106
# ====================================================================
@@ -80,4 +76,4 @@ x_limit = 500.0
8076
main_function=stim_if_x_less_than
8177

8278
[extra_data]
83-
main_function=set_extra_data_mixed_torord_fkatp_epi_mid_endo
79+
main_function=set_extra_data_mixed_torord_fkatp_epi_mid_endo

scripts/evaluateBenchmarkCV/main.cpp

+4-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
1-
// Author: Lucas Berg
1+
// ------------------------------------------------------------------------------------
2+
// Author: Lucas Berg, Julia Camps and Jenny Wang
3+
// Script to evaluate the conductivities calibrated using the 'tuneCV' on a 3D wedge.
4+
// ------------------------------------------------------------------------------------
25

36
#include <iostream>
47
#include <string>

scripts/tuneCV/main.cpp

+11-1
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ using namespace std;
2828
const char MONOALG_PATH[500] = "/home/berg/Github/MonoAlg3D_C";
2929
// ----------------------------------------------------------
3030

31-
const double TOLERANCE = 1.0e-03;
31+
const double TOLERANCE = 5.0e-03;
3232

3333
double calculate_conduction_velocity_from_simulation ()
3434
{
@@ -135,6 +135,16 @@ void write_configuration_file (const double sigma) {
135135
fprintf(file,"library_file=%s/shared_libs/libdefault_matrix_assembly.so\n", MONOALG_PATH);
136136
fprintf(file,"main_function=homogeneous_sigma_assembly_matrix\n");
137137
fprintf(file,"\n");
138+
139+
//fprintf(file,"[assembly_matrix]\n");
140+
//fprintf(file,"init_function=set_initial_conditions_fvm\n");
141+
//fprintf(file,"sigma_l=%g\n",sigma);
142+
//fprintf(file,"sigma_t=%g\n",sigma);
143+
//fprintf(file,"sigma_n=%g\n",sigma);
144+
//fprintf(file,"f=[1,0,0]\n");
145+
//fprintf(file,"library_file=%s/shared_libs/libdefault_matrix_assembly.so\n", MONOALG_PATH);
146+
//fprintf(file,"main_function=anisotropic_sigma_assembly_matrix\n");
147+
//fprintf(file,"\n");
138148

139149
fprintf(file,"[linear_system_solver]\n");
140150
fprintf(file,"tolerance=1e-16\n");
+3-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
cmake_minimum_required(VERSION 2.8)
22

3-
PROJECT(tuneCV)
3+
PROJECT(tuneCVbenchmark)
44

55
find_package(VTK REQUIRED)
66
include(${VTK_USE_FILE})
77

88
set( CMAKE_RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/bin )
99

10-
add_executable(tuneCV main.cpp )
10+
add_executable(tuneCVbenchmark main.cpp )
1111

12-
target_link_libraries(tuneCV ${VTK_LIBRARIES})
12+
target_link_libraries(tuneCVbenchmark ${VTK_LIBRARIES})

scripts/tuneCVbenchmark/main.cpp

+32-23
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
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+
// -------------------------------------------------------------------------------------
25

36
#include <iostream>
47
#include <string>
@@ -29,8 +32,13 @@ using namespace std;
2932

3033
const double TOLERANCE = 1.0e-02; // 1 cm/s
3134

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+
3442
string filename = "outputs/cable/tissue_activation_time_map_pulse_it_0.vtu";
3543

3644
// Read all the data from the file
@@ -94,33 +102,35 @@ double calculate_conduction_velocity_from_cable_simulation ()
94102
}
95103

96104
// 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+");
100110

101111
fprintf(file,"[main]\n");
102112
fprintf(file,"num_threads=6\n");
103113
fprintf(file,"dt_pde=0.01\n");
104-
fprintf(file,"simulation_time=100.0\n");
114+
fprintf(file,"simulation_time=150.0\n");
105115
fprintf(file,"abort_on_no_activity=false\n");
106116
fprintf(file,"use_adaptivity=false\n");
107117
fprintf(file,"quiet=true\n");
108118
fprintf(file,"\n");
109119

110120
fprintf(file,"[update_monodomain]\n");
111121
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);
113123
fprintf(file,"\n");
114124

115125
// For saving the LATs in a format that can be read for calculating the CVs
116126
fprintf(file,"[save_result]\n");
117127
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);
119129
fprintf(file,"save_pvd=true\n");
120130
fprintf(file,"file_prefix=V\n");
121131
fprintf(file,"save_activation_time=true\n");
122132
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);
124134
fprintf(file,"main_function=save_tissue_with_activation_times\n");
125135
fprintf(file,"init_function=init_save_tissue_with_activation_times\n");
126136
fprintf(file,"end_function=end_save_tissue_with_activation_times\n");
@@ -132,7 +142,7 @@ void write_configuration_file (const double sigma)
132142
fprintf(file,"sigma_x=%g\n",sigma);
133143
fprintf(file,"sigma_y=%g\n",sigma);
134144
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);
136146
fprintf(file,"main_function=homogeneous_sigma_assembly_matrix\n");
137147
fprintf(file,"\n");
138148

@@ -141,7 +151,7 @@ void write_configuration_file (const double sigma)
141151
fprintf(file,"use_preconditioner=no\n");
142152
fprintf(file,"use_gpu=yes\n");
143153
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);
145155
fprintf(file,"init_function=init_conjugate_gradient\n");
146156
fprintf(file,"end_function=end_conjugate_gradient\n");
147157
fprintf(file,"main_function=conjugate_gradient\n");
@@ -153,15 +163,15 @@ void write_configuration_file (const double sigma)
153163
fprintf(file,"start_dy=500.0\n");
154164
fprintf(file,"start_dz=500.0\n");
155165
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);
157167
fprintf(file,"main_function=initialize_grid_with_cable_mesh\n");
158168
fprintf(file,"\n");
159169

160170
fprintf(file,"[ode_solver]\n");
161171
fprintf(file,"dt=0.01\n");
162172
fprintf(file,"use_gpu=yes\n");
163173
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);
165175
fprintf(file,"\n");
166176

167177
fprintf(file,"[stim_benchmark]\n");
@@ -175,16 +185,14 @@ void write_configuration_file (const double sigma)
175185
fprintf(file, "min_z = 0.0\n");
176186
fprintf(file, "max_z = 3000.0\n");
177187
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);
179189
fprintf(file,"\n");
180190

181191
fclose(file);
182192
}
183193

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) {
188196
cerr << "=============================================================================" << endl;
189197
cerr << "Usage:> " << argv[0] << " <target_CV>" << endl;
190198
cerr << "=============================================================================" << endl;
@@ -204,20 +212,21 @@ int main (int argc, char *argv[])
204212
double target_cv = atof(argv[1]);
205213
double sigma = 0.0002;
206214

207-
do
208-
{
215+
do {
209216
write_configuration_file(sigma);
210217

211218
// 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);
213222

214223
cv = calculate_conduction_velocity_from_cable_simulation();
215224
factor = pow(target_cv/cv,2);
216225
sigma = sigma*factor;
217226

218227
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);
219228

220-
}while ( fabs(cv-target_cv) > TOLERANCE );
229+
} while ( fabs(cv-target_cv) > TOLERANCE );
221230

222231
printf("\n[+] Target conductivity = %g mS/um\n",sigma);
223232

src/ensight_utils/ensight_grid.c

+23-15
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ void save_case_file(char *filename, uint64_t num_files, real_cpu dt, int print_r
108108
fclose(case_file);
109109
}
110110

111-
void save_en6_result_file(char *filename, struct grid *the_grid, bool binary) {
111+
void save_en6_result_file(char *filename, struct grid *the_grid, bool binary, bool save_purkinje) {
112112

113113
FILE *result_file;
114114

@@ -142,7 +142,7 @@ void save_en6_result_file(char *filename, struct grid *the_grid, bool binary) {
142142
part_number++;
143143
}
144144

145-
if(the_grid->purkinje) {
145+
if(the_grid->purkinje && save_purkinje) {
146146
write_string("part", result_file, binary);
147147
new_line(result_file, binary);
148148

@@ -366,26 +366,35 @@ static inline void set_point_data(struct point_3d center, struct point_3d half_f
366366
struct ensight_grid * new_ensight_grid_from_alg_grid(struct grid *grid, bool clip_with_plain,
367367
float *plain_coordinates, bool clip_with_bounds,
368368
float *bounds, bool read_fibers_f,
369-
bool save_fibrotic) {
369+
bool save_fibrotic, bool save_purkinje) {
370370

371371
struct ensight_grid *ensight_grid;
372372

373373
if(grid->num_active_cells > 0 && grid->purkinje) {
374374

375-
uint32_t num_active_cells = grid->num_active_cells;
376-
uint32_t number_of_purkinje_cells = grid->purkinje->num_active_purkinje_cells;
377-
ensight_grid = new_ensight_grid(2);
375+
if (save_purkinje) {
376+
uint32_t num_active_cells = grid->num_active_cells;
377+
uint32_t number_of_purkinje_cells = grid->purkinje->num_active_purkinje_cells;
378+
ensight_grid = new_ensight_grid(2);
378379

379-
arrsetcap(ensight_grid->parts[0].points, num_active_cells * 8);
380-
arrsetcap(ensight_grid->parts[0].cell_visibility, num_active_cells);
381-
arrsetcap(ensight_grid->parts[0].cells, num_active_cells);
380+
arrsetcap(ensight_grid->parts[0].points, num_active_cells * 8);
381+
arrsetcap(ensight_grid->parts[0].cell_visibility, num_active_cells);
382+
arrsetcap(ensight_grid->parts[0].cells, num_active_cells);
382383

383-
arrsetcap(ensight_grid->parts[1].points, number_of_purkinje_cells * 2);
384-
arrsetcap(ensight_grid->parts[1].cells, number_of_purkinje_cells);
384+
arrsetcap(ensight_grid->parts[1].points, number_of_purkinje_cells * 2);
385+
arrsetcap(ensight_grid->parts[1].cells, number_of_purkinje_cells);
385386

386-
ensight_grid->max_v = FLT_MIN;
387-
ensight_grid->min_v = FLT_MAX;
387+
ensight_grid->max_v = FLT_MIN;
388+
ensight_grid->min_v = FLT_MAX;
389+
}
390+
else {
391+
ensight_grid = new_ensight_grid(1);
388392

393+
uint32_t num_active_cells = grid->num_active_cells;
394+
arrsetcap(ensight_grid->parts[0].points, num_active_cells * 8);
395+
arrsetcap(ensight_grid->parts[0].cell_visibility, num_active_cells);
396+
arrsetcap(ensight_grid->parts[0].cells, num_active_cells);
397+
}
389398
} else {
390399
ensight_grid = new_ensight_grid(1);
391400

@@ -399,7 +408,6 @@ struct ensight_grid * new_ensight_grid_from_alg_grid(struct grid *grid, bool cli
399408
arrsetcap(ensight_grid->parts[0].points, number_of_purkinje_cells * 2);
400409
arrsetcap(ensight_grid->parts[0].cells, number_of_purkinje_cells);
401410
}
402-
403411
}
404412

405413
ensight_grid->max_v = FLT_MIN;
@@ -511,7 +519,7 @@ struct ensight_grid * new_ensight_grid_from_alg_grid(struct grid *grid, bool cli
511519
hash = NULL;
512520
}
513521

514-
if(grid->purkinje) {
522+
if(grid->purkinje && save_purkinje) {
515523

516524
int part_n = 0;
517525

src/ensight_utils/ensight_grid.h

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,12 @@ struct ensight_grid * new_ensight_grid(uint32_t num_parts);
3333
struct ensight_grid * new_ensight_grid_from_alg_grid(struct grid *grid, bool clip_with_plain,
3434
float *plain_coordinates, bool clip_with_bounds,
3535
float *bounds, bool read_fibers_f,
36-
bool save_fibrotic);
36+
bool save_fibrotic, bool save_purkinje);
3737

3838
void save_ensight_grid_as_ensight6_geometry(struct ensight_grid *grid, char *filename, bool binary);
3939

4040
void free_ensight_grid(struct ensight_grid *ensight_grid);
4141
void save_case_file(char *filename, uint64_t num_files, real_cpu dt, int print_rate, int num_state_var);
42-
void save_en6_result_file(char *filename, struct grid *the_grid, bool binary);
42+
void save_en6_result_file(char *filename, struct grid *the_grid, bool binary, bool save_purkinje);
4343
void save_en6_result_file_state_vars(char *filename, real *sv_cpu, size_t num_cells, size_t num_sv_entries, int sv_entry, bool binary, bool gpu);
4444
#endif //MONOALG3D_ENSIGHT_GRID_H

0 commit comments

Comments
 (0)