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

butterflies: clean-ups and random walk debug

parent af2cb1d3
Branches
Tags
No related merge requests found
......@@ -40,8 +40,11 @@ static void inline single_random_walk(struct cats_thread_info *ts, struct cats_g
const int module_id = CATS_MODULE_ID;
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;
......@@ -52,6 +55,7 @@ static void inline single_random_walk(struct cats_thread_info *ts, struct cats_g
const cats_dt_coord rows = grid->dimension.rows;
const cats_dt_coord cols = grid->dimension.cols;
while (steps < max_steps) {
const unsigned long int direction = gsl_rng_uniform_int(ts->rng, N_DIRECTIONS);
......@@ -68,11 +72,16 @@ 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\n",row, col, steps + 1, module_conf->animal_dispersal_max_radius - steps -1,0, eggs_left);
}
continue;
}
......@@ -87,11 +96,15 @@ static void inline single_random_walk(struct cats_thread_info *ts, struct cats_g
eggs_left -= eggs_to_deposit;
data->eggs[row][col] += (float) eggs_to_deposit;
ts->temp2++;
if (debug_rw) {
fprintf(f, "%d,%d,%d,%d,%d,%d\n",row, col, steps + 1, module_conf->animal_dispersal_max_radius - steps - 1, eggs_to_deposit, eggs_left);
}
if (eggs_left == 0) break;
steps++;
}
if (debug_rw) fclose(f);
assert(eggs_left >= 0);
}
......@@ -173,6 +186,7 @@ butterflies_cell_dispersal(struct cats_grid *grid, struct cats_thread_info *ts,
const int module_id = CATS_MODULE_ID;
struct grid_data_butterflies *data = grid->grid_modules[module_id].module_data;
const bool debug_rw = module_conf->debug_rw;
int32_t eggs_to_disperse_per_female = (int32_t) ceill(
eggs_per_female * (1.0 - module_conf->egg_fraction_source));
......@@ -182,6 +196,7 @@ butterflies_cell_dispersal(struct cats_grid *grid, struct cats_thread_info *ts,
wandering_females * (eggs_per_female - eggs_to_disperse_per_female);
// add source cell eggs to the source cell
data->eggs[row][col] += (float) ceill(source_cell_eggs);
if (eggs_to_disperse_per_female == 0) {
......@@ -193,9 +208,17 @@ butterflies_cell_dispersal(struct cats_grid *grid, struct cats_thread_info *ts,
const cats_dt_rates egg_fraction_step = module_conf->egg_fraction_step;
//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, "row,col,step,steps left,eggs deposited,eggs left\n");
fprintf(f, "%d,%d,0,%d,%d,%d\n",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);
}
for (int32_t rw_number = 0; rw_number < wandering_females; rw_number++) {
single_random_walk(ts, grid, row, col, eggs_to_disperse_per_female, egg_fraction_step, rw_number);
ts->temp1++;
}
if (debug_rw) exit_cats(EXIT_SUCCESS);
}
\ No newline at end of file
......@@ -67,15 +67,16 @@ void load_butterflies_species_params(struct cats_configuration *conf, struct cat
load_conf_vital_rate(&data->butterfly_egg_to_adult_survival, conf, ini, section_name, param);
load_conf_value(true, ini, section_name, "butterflies random walk steps maximum", &data->animal_dispersal_max_radius);
bool l = load_conf_value(false, ini, section_name, "egg fraction step", &data->egg_fraction_step);
load_conf_value(true, ini, section_name, "butterflies egg fraction source", &data->egg_fraction_source);
bool l = load_conf_value(false, ini, section_name, "butterflies egg fraction step", &data->egg_fraction_step);
if (! l) {
data->egg_fraction_step = 0.5;
log_message(LOG_INFO, "using default value for egg fraction step: %Lf\n", data->egg_fraction_step);
log_message(LOG_INFO, "using default value for butterflies egg fraction step: %Lf\n", data->egg_fraction_step);
}
if (data->egg_fraction_step <= 0.0 || data->egg_fraction_step > 1.0) {
log_message(LOG_ERROR, "egg fraction step must be in (0, 1], is %Lf", data->egg_fraction_step);
log_message(LOG_ERROR, "butterflies egg fraction step must be in (0, 1], is %Lf", data->egg_fraction_step);
exit_cats(EXIT_FAILURE);
}
......@@ -84,7 +85,9 @@ void load_butterflies_species_params(struct cats_configuration *conf, struct cat
exit_cats(EXIT_FAILURE);
}
data->debug_rw = false;
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->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]");
......
......@@ -38,12 +38,10 @@ struct conf_data_butterflies {
int32_t generations_max;
int32_t generations_min;
int32_t animal_dispersal_max_radius; ///< maximal flight/dispersal distance
cats_dt_rates egg_to_adult_survival_rate_maximum;
cats_dt_rates egg_per_female_maximum;
cats_dt_rates probability_to_stay;
bool debug_rw;
cats_dt_rates egg_fraction_source;
cats_dt_rates egg_fraction_step;
cats_dt_rates stationary_females;
struct cats_vital_rate eggs_per_female;
struct cats_vital_rate butterfly_egg_to_adult_survival;
struct cats_vital_rate butterfly_generations;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment