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

butterflies: clean-ups

parent 04b9919a
No related branches found
No related tags found
No related merge requests found
...@@ -14,6 +14,7 @@ ...@@ -14,6 +14,7 @@
#include "butterflies_dispersal.h" #include "butterflies_dispersal.h"
#include "butterflies_overlays.h" #include "butterflies_overlays.h"
#include "butterflies_filenames.h" #include "butterflies_filenames.h"
#include "inline.h"
enum action_status bf_action_stats_reset(struct cats_grid *grid, struct cats_configuration *conf) enum action_status bf_action_stats_reset(struct cats_grid *grid, struct cats_configuration *conf)
...@@ -116,13 +117,65 @@ enum action_status bf_action_stats_gather(struct cats_grid *grid, struct cats_co ...@@ -116,13 +117,65 @@ enum action_status bf_action_stats_gather(struct cats_grid *grid, struct cats_co
} }
enum action_status bf_action_stats_write(__attribute__((unused)) struct cats_grid *grid, __attribute__((unused)) struct cats_configuration *conf) enum action_status bf_action_stats_write(__attribute__((unused)) struct cats_grid *grid,
__attribute__((unused)) struct cats_configuration *conf)
{ {
bf_stats_write(conf, grid); bf_stats_write(conf, grid);
return ACTION_RUN; return ACTION_RUN;
} }
int64_t count_populated_cells(const struct cats_grid *grid)
{
int64_t cells = 0;
cats_dt_coord rows = grid->dimension.rows;
cats_dt_coord cols = grid->dimension.cols;
for (cats_dt_coord row = 0; row < rows; row++) {
for (cats_dt_coord col = 0; col < cols; col++) {
if (get_adult_population(grid, row, col)) {
cells += 1;
}
}
}
return cells;
}
int64_t butterflies_prune_invalid_cells(struct cats_grid *grid)
{
int64_t invalid_habitat = 0;
int module_id = CATS_MODULE_ID;
struct grid_data_butterflies *data = grid->grid_modules[module_id].module_data;
cats_dt_coord rows = grid->dimension.rows;
cats_dt_coord cols = grid->dimension.cols;
for (cats_dt_coord row = 0; row < rows; row++) {
for (cats_dt_coord col = 0; col < cols; col++) {
if (!(data->info_layer[row][col] & BF_CELL_VALID_DISPERSAL_TARGET)) {
set_population_ignore_cc(grid, row, col, 0);
invalid_habitat += 1;
}
}
}
return invalid_habitat;
}
void initial_population_adjustment(struct cats_configuration *conf, struct cats_grid *grid)
{
int64_t init_populated_cells = count_populated_cells(grid);
int64_t invalid_habitat = butterflies_prune_invalid_cells(grid);
if (grid->param.initial_population.set_to_cc == true) increase_initial_population_to_cc(grid, conf);
if (grid->param.initial_population.suitability_threshold > 0.0) {
prune_initial_population_under_threshold(conf, grid);
}
int64_t after_populated_cells = count_populated_cells(grid);
log_message(LOG_IMPORTANT, "Pruned initial populations from %ld cells to %ld, (%ld wrong habitat)",
init_populated_cells, after_populated_cells, invalid_habitat);
grid->param.initial_population.adjusted = true;
}
// only run at the start of the year // only run at the start of the year
enum action_status bf_action_generation_update(struct cats_grid *grid, struct cats_configuration *conf) enum action_status bf_action_generation_update(struct cats_grid *grid, struct cats_configuration *conf)
{ {
...@@ -132,11 +185,9 @@ enum action_status bf_action_generation_update(struct cats_grid *grid, struct ca ...@@ -132,11 +185,9 @@ enum action_status bf_action_generation_update(struct cats_grid *grid, struct ca
data->generation_current = module_conf->generations_max; data->generation_current = module_conf->generations_max;
log_message(LOG_IMPORTANT, "resetting generation to %d", module_conf->generations_max); log_message(LOG_IMPORTANT, "resetting generation to %d", module_conf->generations_max);
if (grid->param.initial_population.adjusted == false) { if (grid->param.initial_population.adjusted == false) {
if (grid->param.initial_population.set_to_cc == true) increase_initial_population_to_cc(grid, conf); initial_population_adjustment(conf, grid);
if (grid->param.initial_population.suitability_threshold > 0.0) {
prune_initial_population_under_threshold(conf, grid);
}
grid->param.initial_population.adjusted = true; grid->param.initial_population.adjusted = true;
} }
...@@ -166,7 +217,8 @@ enum action_status bf_action_generation_finish(struct cats_grid *grid, struct ca ...@@ -166,7 +217,8 @@ enum action_status bf_action_generation_finish(struct cats_grid *grid, struct ca
return ACTION_RUN; return ACTION_RUN;
} }
enum action_status bf_action_generation_start(struct cats_grid *grid, __attribute__((unused)) struct cats_configuration *conf) enum action_status
bf_action_generation_start(struct cats_grid *grid, __attribute__((unused)) struct cats_configuration *conf)
{ {
int module_id = CATS_MODULE_ID; int module_id = CATS_MODULE_ID;
......
...@@ -26,7 +26,7 @@ void bf_area_generation_update(struct cats_grid *grid, struct cats_thread_info * ...@@ -26,7 +26,7 @@ void bf_area_generation_update(struct cats_grid *grid, struct cats_thread_info *
for (cats_dt_coord col = start_col; col < end_col; col++) { for (cats_dt_coord col = start_col; col < end_col; col++) {
if (cell_excluded_by_overlay(conf, row, col) if (cell_excluded_by_overlay(conf, row, col)
|| (data->info_layer[row][col] & BF_CELL_VALID_DISPERSAL_TARGET) == false) { || ! (data->info_layer[row][col] & BF_CELL_VALID_DISPERSAL_TARGET)) {
data->eggs[row][col] = 0.0f; data->eggs[row][col] = 0.0f;
data->generations[row][col] = 0.0f; data->generations[row][col] = 0.0f;
set_population_ignore_cc(grid, row, col, 0); set_population_ignore_cc(grid, row, col, 0);
......
...@@ -100,6 +100,7 @@ void cats_module_init(struct cats_configuration *conf) ...@@ -100,6 +100,7 @@ void cats_module_init(struct cats_configuration *conf)
register_cats_grid_init_function(conf, butterfly_grid_init, butterfly_grid_cleanup); register_cats_grid_init_function(conf, butterfly_grid_init, butterfly_grid_cleanup);
register_load_species_param_config_func(conf, load_butterflies_species_params); register_load_species_param_config_func(conf, load_butterflies_species_params);
bf_add_vital_rates(conf, data); bf_add_vital_rates(conf, data);
log_message(LOG_INFO, "Hello from %s (id: %d)\n", module_name, id); log_message(LOG_INFO, "Hello from %s (id: %d)\n", module_name, id);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment