Skip to content
Snippets Groups Projects
Commit eb730224 authored by Andreas Gattringer's avatar Andreas Gattringer
Browse files

butterflies: more changes to random walk debug

parent d86854f1
No related branches found
No related tags found
No related merge requests found
......@@ -41,10 +41,7 @@ static void inline single_random_walk(struct cats_thread_info *ts, struct cats_g
const struct grid_data_butterflies *data = grid->grid_modules[module_id].module_data;
const struct conf_data_butterflies *module_conf = CATS_MODULE_DATA;
const bool debug_rw = module_conf->debug_rw;
FILE *f = NULL;
if (debug_rw) {
f = fopen(ts->conf->run_name, "a");
}
int32_t eggs_left = eggs;
const cats_dt_coord max_steps = module_conf->animal_dispersal_max_radius;
......@@ -71,14 +68,13 @@ static void inline single_random_walk(struct cats_thread_info *ts, struct cats_g
col += col_offset;
if (row >= rows || row < 0 || col >= cols || col < 0) {
if (debug_rw) { fclose(f); }
return; // we escaped the simulation extent and got lost
}
// is the cell a valid dispersal target location?
if (!(data->info_layer[row][col] & BF_CELL_VALID_DISPERSAL_TARGET)) {
if (debug_rw) {
fprintf(f, "%d,%d,%d,%d,%d,%d,%d\n", rw_num, row, col, steps + 1,
fprintf(module_conf->debug_rw_file, "%d,%d,%d,%d,%d,%d,%d\n", rw_num, row, col, steps + 1,
module_conf->animal_dispersal_max_radius - steps - 1, 0, eggs_left);
}
......@@ -97,7 +93,7 @@ static void inline single_random_walk(struct cats_thread_info *ts, struct cats_g
data->eggs[row][col] += (float) eggs_to_deposit;
ts->temp2++;
if (debug_rw) {
fprintf(f, "%d,%d,%d,%d,%d,%d,%d\n", rw_num, row, col, steps + 1,
fprintf(module_conf->debug_rw_file, "%d,%d,%d,%d,%d,%d,%d\n", rw_num, row, col, steps + 1,
module_conf->animal_dispersal_max_radius - steps - 1, eggs_to_deposit, eggs_left);
}
......@@ -105,7 +101,7 @@ static void inline single_random_walk(struct cats_thread_info *ts, struct cats_g
if (eggs_left == 0) break;
steps++;
}
if (debug_rw) fclose(f);
assert(eggs_left >= 0);
}
......@@ -210,20 +206,20 @@ butterflies_cell_dispersal(struct cats_grid *grid, struct cats_thread_info *ts,
//printf("thread %d: row %d col %d: doing %d rws\n", ts->id, row, col, wandering_females);
if (debug_rw) {
FILE *f = fopen(conf->run_name, "w");
fprintf(f, "id,row,col,step,steps left,eggs deposited,eggs left\n");
fclose(f);
fprintf(module_conf->debug_rw_file, "id,row,col,step,steps left,eggs deposited,eggs left\n");
}
for (int32_t rw_number = 0; rw_number < wandering_females; rw_number++) {
if (debug_rw) {
FILE *f = fopen(conf->run_name, "a");
fprintf(f, "%d,%d,%d,%d,0,%d,%d\n", rw_number, row, col,
fprintf(module_conf->debug_rw_file, "%d,%d,%d,%d,0,%d,%d\n", rw_number, row, col,
module_conf->animal_dispersal_max_radius,
(int) ceill(eggs_per_female * module_conf->egg_fraction_source),
(int) ceill(eggs_to_disperse_per_female));
fclose(f);
}
......
......@@ -8,6 +8,8 @@
#include "butterflies_vital_rates.h"
#include "cats_ini/cats_ini.h"
#include "butterflies_action_helpers.h"
#include "paths/output_paths.h"
#include "paths/directory_helper.h"
struct cats_global global;
struct cats_debug_options cats_debug;
......@@ -86,9 +88,26 @@ void load_butterflies_species_params(struct cats_configuration *conf, struct cat
}
data->debug_rw = false;
data->debug_rw_file = NULL;
data->debug_rw_filename = NULL;
load_conf_value(true, ini, section_name, "butterflies probability to stay", &data->probability_to_stay);
load_conf_value(false, ini, section_name, "butterflies debug random walks", &data->debug_rw);
if (data->debug_rw) {
struct string_array *path = get_output_directory(conf, "debug");
check_and_create_directory_if_needed(path);
struct string_array *name = new_string_array_init("rw-debug");
string_array_add(name, conf->run_name);
data->debug_rw_filename = assemble_filename(path, name, "_", ".csv");
data->debug_rw_file = fopen(data->debug_rw_filename, "w");
ENSURE_FILE_OPENED(data->debug_rw_file, data->debug_rw_filename);
free_string_array(&path);
free_string_array(&name);
log_message(LOG_IMPORTANT, "Random walk debugging is enabled, reducing number of threads to one");
conf->param_max_threads = 1;
}
if (data->probability_to_stay < 0.0 || data->probability_to_stay > 1.0) {
log_message(LOG_ERROR, "butterflies probability to stay has to be in range [0, 1]");
exit_cats(EXIT_FAILURE);
......
......@@ -40,6 +40,8 @@ struct conf_data_butterflies {
int32_t animal_dispersal_max_radius; ///< maximal flight/dispersal distance
cats_dt_rates probability_to_stay;
bool debug_rw;
FILE *debug_rw_file;
char *debug_rw_filename;
cats_dt_rates egg_fraction_source;
cats_dt_rates egg_fraction_step;
struct cats_vital_rate eggs_per_female;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment