diff --git a/src/modules/butterflies/butterflies_populations.c b/src/modules/butterflies/butterflies_populations.c index 1ce531422f0946aa649381543248976f8856bf92..03f842cb3315be0c1bc4c25975729b796e79f1d0 100644 --- a/src/modules/butterflies/butterflies_populations.c +++ b/src/modules/butterflies/butterflies_populations.c @@ -18,16 +18,17 @@ 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; + const cats_dt_coord rows = grid->dimension.rows; + const 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; } @@ -35,22 +36,23 @@ int64_t count_populated_cells(const struct cats_grid *grid) 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; + const int module_id = CATS_MODULE_ID; + const struct grid_data_butterflies *data = grid->grid_modules[module_id].module_data; + const cats_dt_coord rows = grid->dimension.rows; + const 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)) { if(get_adult_population(grid, row, col)) { invalid_habitat += 1; } set_population_ignore_cc(grid, row, col, 0); - } } } + return invalid_habitat; } @@ -83,12 +85,9 @@ void bf_cell_maturation(struct cats_grid *grid, struct cats_thread_info *ts, cat } - - - - // 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 - // one greater than the integer part of the number of generations + // one greater than the integer part of the number of generations. // i.e. if the number of generations is 2.4, 40% of all eggs in the cell // will be considered as if they belonged to generation 3 // the minimum number of generations is 1 if the cell is climatically viable (and the host species is present) @@ -117,7 +116,7 @@ void bf_cell_maturation(struct cats_grid *grid, struct cats_thread_info *ts, cat 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]; + const float eggs = this_generation_fraction * data->eggs[row][col]; #ifdef BF_DEBUG printf("BFDBG::%s::row %d, col %d: local gen %f gen fraction %f, eggs %f, this gen eggs %f\n", __func__, row, col, local_generation, this_generation_fraction, data->eggs[row][col], eggs); @@ -133,7 +132,6 @@ void bf_cell_maturation(struct cats_grid *grid, struct cats_thread_info *ts, cat data->eggs[row][col] -= eggs; assert(data->eggs[row][col] >= 0); - // not capped, we can have more adults than CC cats_dt_environment suit = get_suitability(grid, row, col);