Skip to content

Commit

Permalink
WIP: isotropic eikonal solver
Browse files Browse the repository at this point in the history
  • Loading branch information
rsachetto committed Apr 23, 2024
1 parent a08cfbb commit f361fcf
Show file tree
Hide file tree
Showing 5 changed files with 295 additions and 123 deletions.
34 changes: 17 additions & 17 deletions src/config/config_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,24 +46,24 @@ void init_config_functions(struct config *config, char *default_lib, char *confi
do { \
if((s) == NULL) { \
log_info(tag " no configuration.\n"); \
return; \
} else { \
log_info(tag " configuration:\n"); \
log_info(tag " library = %s\n", (s)->library_file_path); \
log_info(tag " main function = %s\n", (s)->main_function_name); \
\
if((s)->init_function_name) { \
log_info(tag " init function = %s\n", (s)->init_function_name); \
} \
\
if((s)->end_function_name) { \
log_info(tag " end function = %s\n", (s)->end_function_name); \
} \
\
for(int __i = 0; __i < arrlen((s)->extra_function_names); __i++) { \
log_info(tag " extra function %d = %s\n", __i+1, (s)->extra_function_names[__i]); \
} \
STRING_HASH_PRINT_KEY_VALUE_LOG(tag, (s)->config_data); \
} \
log_info(tag " configuration:\n"); \
log_info(tag " library = %s\n", (s)->library_file_path); \
log_info(tag " main function = %s\n", (s)->main_function_name); \
\
if((s)->init_function_name) { \
log_info(tag " init function = %s\n", (s)->init_function_name); \
} \
\
if((s)->end_function_name) { \
log_info(tag " end function = %s\n", (s)->end_function_name); \
} \
\
for(int __i = 0; __i < arrlen((s)->extra_function_names); __i++) { \
log_info(tag " extra function %d = %s\n", __i+1, (s)->extra_function_names[__i]); \
} \
STRING_HASH_PRINT_KEY_VALUE_LOG(tag, (s)->config_data); \
} while(0)

#define CALL_EXTRA_FUNCTIONS(fn, ...) \
Expand Down
110 changes: 108 additions & 2 deletions src/config/config_parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
static const char *batch_opt_string = "c:h?";
static const struct option long_batch_options[] = {{"config_file", required_argument, NULL, 'c'}};

#define eikonal_opt_string batch_opt_string
#define long_eikonal_options long_batch_options

static const char *conversion_opt_string = "i:o:c:h?";
static const struct option long_conversion_options[] = {{"input", required_argument, NULL, 'i'},
{"output", required_argument, NULL, 'o'},
Expand Down Expand Up @@ -134,6 +137,15 @@ void display_batch_usage(char **argv) {
exit(EXIT_FAILURE);
}

void display_eikonal_usage(char **argv) {

printf("Usage: %s [options]\n\n", argv[0]);
printf("Options:\n");
printf("--config_file | -c [configuration_file_path]. Eikonal solver configuration file. Default NULL.\n");
printf("--help | -h. Shows this help and exit \n");
exit(EXIT_FAILURE);
}

void display_conversion_usage(char **argv) {

printf("Usage: %s [options]\n\n", argv[0]);
Expand Down Expand Up @@ -168,7 +180,7 @@ void display_visualization_usage(char **argv) {
exit(EXIT_FAILURE);
}

void maybe_issue_overwrite_warning(const char *var, const char *section, const char *old_value, const char *new_value, const char *config_file) {
static void maybe_issue_overwrite_warning(const char *var, const char *section, const char *old_value, const char *new_value, const char *config_file) {
if(strcmp(old_value, new_value) != 0) {
fprintf(stderr,
"WARNING: option %s in %s was set in the file %s to %s and is being overwritten "
Expand All @@ -177,6 +189,26 @@ void maybe_issue_overwrite_warning(const char *var, const char *section, const c
}
}

struct eikonal_options *new_eikonal_options() {
struct eikonal_options *user_args = (struct eikonal_options *)calloc(1, sizeof(struct eikonal_options));

user_args->stim_configs = NULL;
sh_new_arena(user_args->stim_configs);
shdefault(user_args->stim_configs, NULL);

user_args->domain_config = NULL;
user_args->save_mesh_config = NULL;

return user_args;
}

void free_eikonal_options(struct eikonal_options *options) {
shfree(options->stim_configs);
free_config_data(options->domain_config);
free_config_data(options->save_mesh_config);
free(options);
}

struct batch_options *new_batch_options() {
struct batch_options *user_args = (struct batch_options *)calloc(1, sizeof(struct batch_options));
sh_new_arena(user_args->config_to_change);
Expand Down Expand Up @@ -1022,7 +1054,7 @@ void parse_batch_options(int argc, char **argv, struct batch_options *user_args)
while(opt != -1) {
switch(opt) {
case 'c':
user_args->batch_config_file = strdup(optarg);
user_args->config_file = strdup(optarg);
break;
case 'h': /* fall-through is intentional */
case '?':
Expand All @@ -1037,6 +1069,31 @@ void parse_batch_options(int argc, char **argv, struct batch_options *user_args)
}
}

void parse_eikonal_options(int argc, char **argv, struct eikonal_options *user_args) {

int opt = 0;
int option_index;

opt = getopt_long_only(argc, argv, eikonal_opt_string, long_eikonal_options, &option_index);

while(opt != -1) {
switch(opt) {
case 'c':
user_args->config_file = strdup(optarg);
break;
case 'h': /* fall-through is intentional */
case '?':
display_eikonal_usage(argv);
break;
default:
/* You won't actually get here. */
break;
}

opt = getopt_long(argc, argv, eikonal_opt_string, long_eikonal_options, &option_index);
}
}

void parse_conversion_options(int argc, char **argv, struct conversion_options *user_args) {

int opt = 0;
Expand Down Expand Up @@ -1799,6 +1856,53 @@ int parse_config_file(void *user, const char *section, const char *name, const c
return 1;
}

int parse_eikonal_config_file(void *options, const char *section, const char *name, const char *value) {

struct eikonal_options *pconfig = (struct eikonal_options *)options;

if(SECTION_STARTS_WITH(STIM_SECTION)) {

struct config *tmp = (struct config *)shget(pconfig->stim_configs, section);

if(tmp == NULL) {
tmp = alloc_and_init_config_data();
shput(pconfig->stim_configs, section, tmp);
}

if(MATCH_NAME("name")) {
fprintf(stderr,
"name is a reserved word and should not be used inside a stimulus config section. Found in %s. "
"Exiting!\n",
section);
exit(EXIT_FAILURE);
} else {
set_common_data(tmp, name, value);
}

} else if(MATCH_SECTION(DOMAIN_SECTION)) {

if(pconfig->domain_config == NULL) {
pconfig->domain_config = alloc_and_init_config_data();
}

set_common_data(pconfig->domain_config, name, value);
} else if(MATCH_SECTION(SAVE_RESULT_SECTION)) {

if(pconfig->save_mesh_config == NULL) {
pconfig->save_mesh_config = alloc_and_init_config_data();
}

set_common_data(pconfig->save_mesh_config, name, value);

} else {

fprintf(stderr, "\033[33;5;7mInvalid name %s in section %s on the config file!\033[0m\n", name, section);
return 0;
}

return 1;
}

int parse_preprocessor_config(void *user, const char *section, const char *name, const char *value) {

static int function_counter = 0;
Expand Down Expand Up @@ -1832,6 +1936,8 @@ int parse_preprocessor_config(void *user, const char *section, const char *name,
return 1;
}



#define WRITE_INI_SECTION(SECTION) fprintf(ini_file, "[%s]\n", SECTION)

#define WRITE_NAME_VALUE_WITHOUT_CHECK(NAME, VALUE, SPECIFIER) fprintf(ini_file, "%s = %" SPECIFIER "\n", NAME, VALUE)
Expand Down
18 changes: 14 additions & 4 deletions src/config/config_parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -163,14 +163,20 @@ struct user_options {
};

struct batch_options {
char *batch_config_file;
char *config_file;
char *output_folder;
char *initial_config;
int num_simulations;
bool skip_existing_run;
struct string_hash_entry *config_to_change;
};

struct eikonal_options {
char *config_file;
char *output_folder;
struct string_voidp_hash_entry *stim_configs;
struct config *domain_config;
struct config *save_mesh_config;
};
struct visualization_options {
char *input;
char *files_prefix;
Expand Down Expand Up @@ -198,26 +204,31 @@ struct fibers_conversion_options {
char *output_file;
};

void display_usage( char** argv );
void display_usage(char **argv);
void display_batch_usage(char **argv);
void display_eikonal_usage(char **argv);
void display_conversion_usage(char **argv);
void display_fibers_conversion_usage(char **argv);
void display_visualization_usage(char **argv);

struct user_options * new_user_options();
struct batch_options * new_batch_options();
struct eikonal_options * new_eikonal_options();
struct visualization_options * new_visualization_options();
struct conversion_options * new_conversion_options();
struct fibers_conversion_options * new_fibers_conversion_options();

void parse_options(int argc, char**argv, struct user_options *user_args);
void parse_batch_options(int argc, char**argv, struct batch_options *user_args);
void parse_eikonal_options(int argc, char**argv, struct eikonal_options *user_args);
void parse_visualization_options(int argc, char**argv, struct visualization_options *user_args);
void parse_conversion_options(int argc, char **argv, struct conversion_options *user_args);
void parse_fibers_conversion_options(int argc, char **argv, struct fibers_conversion_options *user_args);
void get_config_file(int argc, char**argv, struct user_options *user_args);

int parse_config_file(void* user, const char* section, const char* name, const char* value);
int parse_batch_config_file(void *user, const char *section, const char *name, const char *value);
int parse_eikonal_config_file(void *user, const char *section, const char *name, const char *value);
int parse_preprocessor_config(void* user, const char* section, const char* name, const char* value);
int parse_converter_config_file(void *user, const char *section, const char *name, const char *value);

Expand All @@ -231,7 +242,6 @@ void free_visualization_options(struct visualization_options * options);
void free_conversion_options(struct conversion_options *options);
void free_fibers_conversion_options(struct fibers_conversion_options *options);

void maybe_issue_overwrite_warning(const char *var, const char *section, const char *old_value, const char *new_value, const char *config_file);
void set_or_overwrite_common_data(struct config* config, const char *key, const char *value, const char *section, const char *config_file);


Expand Down
4 changes: 2 additions & 2 deletions src/main_batch.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ int main(int argc, char **argv) {

parse_batch_options(argc, argv, batch_options);

if (ini_parse(batch_options->batch_config_file, parse_batch_config_file, batch_options) < 0) {
fprintf(stderr, "Error: Can't load the config file %s\n", batch_options->batch_config_file);
if (ini_parse(batch_options->config_file, parse_batch_config_file, batch_options) < 0) {
fprintf(stderr, "Error: Can't load the config file %s\n", batch_options->config_file);
MPI_Abort(MPI_COMM_WORLD, EXIT_FAILURE);
}

Expand Down
Loading

0 comments on commit f361fcf

Please sign in to comment.