Skip to content

Commit 292dcac

Browse files
committed
More progress in the Eikonal solver
1 parent ac28c61 commit 292dcac

File tree

5 files changed

+81
-51
lines changed

5 files changed

+81
-51
lines changed

bsbash/build_functions.sh

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ LIBRARY_OUTPUT_DIRECTORY=$ROOT_DIR
2121
GLOBAL_FORCE_COMPILATION=""
2222
QUIET=''
2323
WAIT_ENTER=''
24-
WRITE_COMPILE_COMMANDS='y'
24+
WRITE_COMPILE_COMMANDS=''
2525

2626
DEFAULT_BUILD_DIR="build_"
2727
COMPILE_COMMANDS_FILE="${ROOT_DIR}/compile_commands.json"
@@ -397,9 +397,6 @@ COMPILE_OBJECT () {
397397
ANY_COMPILED="y"
398398

399399
fi
400-
401-
402-
403400
}
404401

405402
CHECK_HEADERS() {
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
[main]
2+
simulation_time = 100
3+
dt = 1
4+
5+
[domain]
6+
;These values are mandatory
7+
name=UCLA Rabbit Mesh
8+
;this mesh always start at 250.0
9+
maximum_discretization = 250.0
10+
main_function=initialize_grid_with_rabbit_mesh
11+
;These can be optional depending on the domain main_function
12+
mesh_file=meshes/rabheart.alg
13+
14+
[save_result]
15+
;/////mandatory/////////
16+
output_dir=./outputs/rabbit_eikonal
17+
main_function=save_as_text_or_binary
18+
;//////////////////
19+
file_prefix=T

src/config/config_parser.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -246,6 +246,7 @@ void free_batch_options(struct batch_options * options);
246246
void free_visualization_options(struct visualization_options * options);
247247
void free_conversion_options(struct conversion_options *options);
248248
void free_fibers_conversion_options(struct fibers_conversion_options *options);
249+
void free_eikonal_options(struct eikonal_options *options);
249250

250251
void set_or_overwrite_common_data(struct config* config, const char *key, const char *value, const char *section, const char *config_file);
251252

src/eikonal/eikonal_solver.c

Lines changed: 16 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
//
2+
// Created by sachetto on 06/06/24.
3+
// Based on https://github.com/SCIInstitute/StructuredEikonal
4+
15
#include <assert.h>
26
#include <cuda_runtime.h>
37
#include "eikonal_solver.h"
@@ -28,7 +32,6 @@ struct eikonal_solver * new_eikonal_solver(bool verbose) {
2832

2933
void free_eikonal_solver(struct eikonal_solver *solver) {
3034

31-
//TODO: free 3D arrays
3235
FREE_3D_ARRAY(solver->speeds, solver->width, solver->height);
3336
FREE_3D_ARRAY(solver->answer, solver->width, solver->height);
3437
FREE_3D_ARRAY(solver->mask, solver->width, solver->height);
@@ -251,19 +254,26 @@ static void get_solution(struct eikonal_solver *solver) {
251254
for(int k = 0; k < BLOCK_LENGTH; k++) {
252255
for(int j = 0; j < BLOCK_LENGTH; j++) {
253256
for(int i = 0; i < BLOCK_LENGTH; i++) {
254-
double d = solver->memory_struct.h_sol[baseAddr +
255-
k * BLOCK_LENGTH * BLOCK_LENGTH +
256-
j * BLOCK_LENGTH + i];
257+
double d = solver->memory_struct.h_sol[baseAddr + k * BLOCK_LENGTH * BLOCK_LENGTH + j * BLOCK_LENGTH + i];
257258
if ((i + bx * BLOCK_LENGTH) < solver->width &&
258259
(j + by * BLOCK_LENGTH) < solver->height &&
259260
(k + bz * BLOCK_LENGTH) < solver->depth) {
260-
solver->answer[(i + bx * BLOCK_LENGTH)][(j +
261-
by * BLOCK_LENGTH)][k + bz * BLOCK_LENGTH] = d;
261+
solver->answer[(i + bx * BLOCK_LENGTH)][(j + by * BLOCK_LENGTH)][k + bz * BLOCK_LENGTH] = d;
262262
}
263263
}
264264
}
265265
}
266266
}
267+
268+
for(int i = 0 ; i < solver->num_active_cells; i++) {
269+
solver->active_cells[i]->v = solver->answer[(int)solver->active_cells[i]->center.x][(int)solver->active_cells[i]->center.y][(int)solver->active_cells[i]->center.z];
270+
271+
//Translating back to original space
272+
solver->active_cells[i]->center.x = solver->active_cells[i]->center.x * solver->active_cells[i]->discretization.x + solver->active_cells[i]->discretization.x/2.0;
273+
solver->active_cells[i]->center.y = solver->active_cells[i]->center.y * solver->active_cells[i]->discretization.y + solver->active_cells[i]->discretization.y/2.0;
274+
solver->active_cells[i]->center.z = solver->active_cells[i]->center.z * solver->active_cells[i]->discretization.z + solver->active_cells[i]->discretization.z/2.0;
275+
276+
}
267277
}
268278

269279
void map_generator(struct eikonal_solver *solver) {
@@ -389,29 +399,6 @@ void use_seeds(struct eikonal_solver *solver) {
389399
check_cuda_error( cudaMemset(solver->memory_struct.d_con, 1, volSize*sizeof(bool)) );
390400
}
391401

392-
void write_alg(struct eikonal_solver *solver, char *filename) {
393-
394-
FILE *out = fopen(filename, "w");
395-
396-
if (out == NULL) {
397-
log_error_and_exit("Error opening file: %s\n", filename);
398-
}
399-
400-
for (int k = 0; k < solver->depth; k++) {
401-
for (int j = 0; j < solver->height; j++) {
402-
for (int i = 0; i < solver->width; i++) {
403-
if(solver->mask[i][j][k] == true) {
404-
real d = solver->answer[i][j][k];
405-
fprintf(out, "%lf, %lf, %lf, 0.5, 0.5, 0.5, %lf\n", i + 0.5, j + 0.5, k + 0.5, d);
406-
}
407-
}
408-
}
409-
}
410-
411-
fclose(out);
412-
413-
}
414-
415402
void solve_eikonal(struct eikonal_solver *solver) {
416403

417404
if (solver->speeds == NULL) {

src/main_eikonal.c

Lines changed: 44 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,29 @@
1-
#include <stdlib.h>
1+
#include "3dparty/ini_parser/ini.h"
2+
#include "3dparty/stb_ds.h"
23
#include "alg/cell/cell.h"
34
#include "alg/grid/grid.h"
4-
#include "3dparty/ini_parser/ini.h"
5+
#include "config/config_parser.h"
56
#include "config/domain_config.h"
67
#include "eikonal/eikonal_solver.h"
7-
#include "3dparty/stb_ds.h"
88
#include "logger/logger.h"
9-
#include "config/config_parser.h"
10-
9+
#include "utils/file_utils.h"
10+
#include <stdlib.h>
1111

1212
static int compare_coordinates(const void *a, const void *b) {
1313

1414
struct cell_node *coord1 = *(struct cell_node **) a;
1515
struct cell_node *coord2 = *(struct cell_node **) b;
1616

1717
if (coord1->center.y != coord2->center.y) {
18-
return coord1->center.y - coord2->center.y;
18+
return (int) (coord1->center.y - coord2->center.y);
1919
}
2020

2121
if (coord1->center.x != coord2->center.x) {
22-
return coord1->center.x - coord2->center.x;
22+
return (int) (coord1->center.x - coord2->center.x);
2323
}
2424

2525

26-
return coord1->center.z - coord2->center.z;
26+
return (int) (coord1->center.z - coord2->center.z);
2727

2828
}
2929

@@ -59,10 +59,15 @@ int main(int argc, char *argv[]) {
5959

6060
}
6161

62+
//Translating to 0
6263
for(int i = 0 ; i < grid->num_active_cells; i++) {
63-
int new_pos_x = (grid->active_cells[i]->center.x-grid->active_cells[i]->discretization.x/2)/grid->active_cells[i]->discretization.x;
64-
int new_pos_y = (grid->active_cells[i]->center.y-grid->active_cells[i]->discretization.y/2)/grid->active_cells[i]->discretization.y;
65-
int new_pos_z = (grid->active_cells[i]->center.z-grid->active_cells[i]->discretization.z/2)/grid->active_cells[i]->discretization.z;
64+
double new_pos_x = (grid->active_cells[i]->center.x-grid->active_cells[i]->discretization.x/2.0)/grid->active_cells[i]->discretization.x;
65+
double new_pos_y = (grid->active_cells[i]->center.y-grid->active_cells[i]->discretization.y/2.0)/grid->active_cells[i]->discretization.y;
66+
double new_pos_z = (grid->active_cells[i]->center.z-grid->active_cells[i]->discretization.z/2.0)/grid->active_cells[i]->discretization.z;
67+
68+
if(new_pos_x != floor(new_pos_x) || new_pos_y != floor(new_pos_y) || new_pos_z != floor(new_pos_z)) {
69+
log_error_and_exit("The current version only accepts integer coordinates\n");
70+
}
6671

6772
grid->active_cells[i]->center.x = new_pos_x;
6873
grid->active_cells[i]->center.y = new_pos_y;
@@ -72,25 +77,46 @@ int main(int argc, char *argv[]) {
7277
size_t itersPerBlock = 10, type = 1;
7378

7479
struct eikonal_solver *solver = new_eikonal_solver(false);
75-
solver->width = grid->cube_side_length.x/grid->active_cells[0]->discretization.x;
76-
solver->height = grid->cube_side_length.y/grid->active_cells[0]->discretization.y;
77-
solver->depth = grid->cube_side_length.z/grid->active_cells[0]->discretization.z;
80+
solver->width = (int) (grid->cube_side_length.x/grid->active_cells[0]->discretization.x);
81+
solver->height = (int) (grid->cube_side_length.y/grid->active_cells[0]->discretization.y);
82+
solver->depth = (int) (grid->cube_side_length.z/grid->active_cells[0]->discretization.z);
7883

7984
solver->solver_type = type;
8085
solver->iters_per_block = itersPerBlock;
8186

8287
size_t *initial_seed = calloc(sizeof(size_t), 3);
83-
initial_seed[0] = grid->active_cells[0]->center.x;
84-
initial_seed[1] = grid->active_cells[0]->center.y;
85-
initial_seed[2] = grid->active_cells[0]->center.z;
88+
initial_seed[0] = 128;
89+
initial_seed[1] = 48;
90+
initial_seed[2] = 63;
8691

8792
arrput(solver->seeds, initial_seed);
8893
solver->active_cells = grid->active_cells;
8994
solver->num_active_cells = grid->num_active_cells;
9095

9196
solve_eikonal(solver);
92-
write_alg(solver, "test.alg");
9397

98+
struct config * save_result_config = eikonal_options->save_mesh_config;
99+
100+
if(save_result_config) {
101+
102+
init_config_functions(save_result_config, "./shared_libs/libdefault_save_mesh.so", "save_result");
103+
104+
print_save_mesh_config_values(save_result_config);
105+
log_msg(LOG_LINE_SEPARATOR);
106+
107+
char *out_dir_name = NULL;
108+
GET_PARAMETER_STRING_VALUE_OR_USE_DEFAULT(out_dir_name, save_result_config, "output_dir");
109+
if(out_dir_name != NULL) {
110+
create_dir(out_dir_name);
111+
struct time_info ti = ZERO_TIME_INFO;
112+
((save_mesh_fn *)save_result_config->main_function)(&ti, save_result_config, grid, NULL, NULL);
113+
} else {
114+
log_warn("Not output dir provided. The result will not be saved!");
115+
}
116+
}
117+
118+
free(initial_seed);
94119
free_eikonal_solver(solver);
120+
free_eikonal_options(eikonal_options);
95121

96122
}

0 commit comments

Comments
 (0)