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

butterflies: fixed fractional generations

parent 37662ba1
No related branches found
No related tags found
No related merge requests found
...@@ -39,13 +39,12 @@ void bf_cell_maturation(struct cats_grid *grid, struct cats_thread_info *ts, cat ...@@ -39,13 +39,12 @@ void bf_cell_maturation(struct cats_grid *grid, struct cats_thread_info *ts, cat
struct grid_data_butterflies *data = grid->grid_modules[module_id].module_data; struct grid_data_butterflies *data = grid->grid_modules[module_id].module_data;
if (data->eggs[row][col] == 0) return; if (data->eggs[row][col] == 0) return;
if (data->eggs[row][col] < 0) { if (data->eggs[row][col] < 0) {
log_message(LOG_ERROR, "Number of eggs < 0: row %d col %d: %f", row, col, data->eggs[row][col]); log_message(LOG_ERROR, "Number of eggs < 0: row %d col %d: %f", row, col, data->eggs[row][col]);
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
//int orig_eggs = data->eggs[row][col];
// the number of generations per cell is usually not an integer value // the number of generations per cell is usually not an integer value
// the non-integer part of the number of generations is used in the generation which is // the non-integer part of the number of generations is used in the generation which is
// one greater than the integer part of the number of generations // one greater than the integer part of the number of generations
...@@ -60,16 +59,22 @@ void bf_cell_maturation(struct cats_grid *grid, struct cats_thread_info *ts, cat ...@@ -60,16 +59,22 @@ void bf_cell_maturation(struct cats_grid *grid, struct cats_thread_info *ts, cat
// then all the cells with have at least 4 (> 3) generations are modelled // then all the cells with have at least 4 (> 3) generations are modelled
// ... // ...
// at last all cells with have at least 1 generation are modelled // 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 this_generation_fraction = 1.0f;
int32_t local_max_generation = (int32_t) ceilf(data->generations[row][col]); float local_generation = data->generations[row][col];
int32_t local_max_generation = (int32_t) ceilf(local_generation);
if (data->generation_current == local_max_generation) { float current_generation_float = (float) data->generation_current;
this_generation_fraction = (float) local_max_generation - data->generations[row][col];
assert(this_generation_fraction >= 0); if (current_generation_float == local_generation
assert(this_generation_fraction <= 1.0); || 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);
//cats_dt_population max_cc = (cats_dt_population) grid->param.carrying_capacity.max_rate; //cats_dt_population max_cc = (cats_dt_population) grid->param.carrying_capacity.max_rate;
float eggs = this_generation_fraction * data->eggs[row][col]; float eggs = this_generation_fraction * data->eggs[row][col];
...@@ -86,7 +91,7 @@ void bf_cell_maturation(struct cats_grid *grid, struct cats_thread_info *ts, cat ...@@ -86,7 +91,7 @@ void bf_cell_maturation(struct cats_grid *grid, struct cats_thread_info *ts, cat
if (eggs == 0) return; if (eggs == 0) return;
// not capped, we can have more adults than CC // not capped, we can have more adults than CC
struct conf_data_butterflies *module_conf = CATS_MODULE_DATA;
cats_dt_environment suit = get_suitability(grid, row, col); cats_dt_environment suit = get_suitability(grid, row, col);
cats_dt_rates reproduction_rate = calculate_rate(&module_conf->reproduction_rate, NAN, &grid->param, cats_dt_rates reproduction_rate = calculate_rate(&module_conf->reproduction_rate, NAN, &grid->param,
grid, row, col, NULL); grid, row, col, NULL);
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment