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

butterflies: fractional generation calculation in function

parent 1c056e1a
Branches
Tags
No related merge requests found
......@@ -63,6 +63,35 @@ bf_egg_to_adult_survival_rate(cats_dt_rates reproduction_rate, cats_dt_rates egg
return reproduction_rate / eggs;
}
float get_fractional_generation(struct cats_grid *grid, cats_dt_coord row, cats_dt_coord col)
{
struct conf_data_butterflies *module_conf = CATS_MODULE_DATA;
const int module_id = CATS_MODULE_ID;
struct grid_data_butterflies *data = grid->grid_modules[module_id].module_data;
float this_generation_fraction = 1.0f;
float local_generation = data->generations[row][col];
int32_t global_max_generation = module_conf->generations_max;
int32_t local_max_generation = (int32_t) ceilf(local_generation);
int32_t global_current_generation = data->generation_current;
float current_generation_float = (float) data->generation_current;
if (global_current_generation == global_max_generation) {
this_generation_fraction = 1.0f;
} else if (current_generation_float == local_generation
|| data->generation_current == module_conf->generations_min) {
this_generation_fraction = 1.0f;
} else if (data->generation_current == local_max_generation) {
this_generation_fraction = (float) local_max_generation - local_generation;
}
assert(this_generation_fraction > 0);
assert(this_generation_fraction <= 1.0);
return this_generation_fraction;
}
void bf_cell_maturation(struct cats_grid *grid, struct cats_thread_info *ts, cats_dt_coord row, cats_dt_coord col,
bool check_exclusion)
......@@ -100,24 +129,10 @@ void bf_cell_maturation(struct cats_grid *grid, struct cats_thread_info *ts, cat
// ...
// at last all cells with have at least 1 generation are modelled
struct conf_data_butterflies *module_conf = CATS_MODULE_DATA;
float this_generation_fraction = 1.0f;
float local_generation = data->generations[row][col];
int32_t global_max_generation = module_conf->generations_max;
int32_t local_max_generation = (int32_t) ceilf(local_generation);
int32_t global_current_generation = data->generation_current;
float current_generation_float = (float) data->generation_current;
if (global_current_generation == global_max_generation) {
this_generation_fraction = 1.0f;
} else if (current_generation_float == local_generation
|| data->generation_current == module_conf->generations_min) {
this_generation_fraction = 1.0f;
} else if (data->generation_current == local_max_generation) {
this_generation_fraction = (float) local_max_generation - local_generation;
}
float this_generation_fraction = get_fractional_generation(grid, row, col);
assert(this_generation_fraction > 0);
assert(this_generation_fraction <= 1.0);
//cats_dt_population max_cc = (cats_dt_population) grid->param.carrying_capacity.max_rate;
const float eggs = this_generation_fraction * data->eggs[row][col];
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment