diff --git a/src/modules/butterflies/butterflies_populations.c b/src/modules/butterflies/butterflies_populations.c index a06db76118ad8f38e90d61027cf62f26c999e555..f47ede186ddfcad169a8faec4dd0c3e808b8d388 100644 --- a/src/modules/butterflies/butterflies_populations.c +++ b/src/modules/butterflies/butterflies_populations.c @@ -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; if (data->eggs[row][col] == 0) return; + 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]); exit(EXIT_FAILURE); } - //int orig_eggs = data->eggs[row][col]; - // 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 // 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 // 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 - + struct conf_data_butterflies *module_conf = CATS_MODULE_DATA; float this_generation_fraction = 1.0f; - int32_t local_max_generation = (int32_t) ceilf(data->generations[row][col]); - - if (data->generation_current == local_max_generation) { - this_generation_fraction = (float) local_max_generation - data->generations[row][col]; - assert(this_generation_fraction >= 0); - assert(this_generation_fraction <= 1.0); + float local_generation = data->generations[row][col]; + int32_t local_max_generation = (int32_t) ceilf(local_generation); + float current_generation_float = (float) data->generation_current; + + 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); + //cats_dt_population max_cc = (cats_dt_population) grid->param.carrying_capacity.max_rate; 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 if (eggs == 0) return; // 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_rates reproduction_rate = calculate_rate(&module_conf->reproduction_rate, NAN, &grid->param, grid, row, col, NULL);