Loading [MathJax]/extensions/ams.js
ALMaSS  1.2 (after EcoStack, March 2024)
The Animal, Landscape and Man Simulation System
All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
Pesticide Class Reference

#include <Pesticide.h>

Public Member Functions

void Tick (void)
 Main pesticide method that is called every day. More...
 
void DailyQueueAdd (LE *a_element_sprayed, double a_amount, PlantProtectionProducts a_ppp, int a_drifttype=0)
 Adds new pesticide spray event to the daily queue. More...
 
void DailyQueueAddSeedCoating (LE *a_element_sprayed, double a_amount, PlantProtectionProducts a_ppp)
 Adds new seed coating event to the daily queue. More...
 
void DailyQueueAddGranular (LE *a_element_sprayed, double a_amount, PlantProtectionProducts a_ppp)
 Adds new granular application event to the daily queue. More...
 
bool GetAnythingToDecay (PlantProtectionProducts a_ppp)
 Checks if there are any pesticides to decay. More...
 
void RemovePlantPesticide (int a_minx, int a_maxx, int a_miny, int a_maxy, int a_map_index)
 Sets all plant pesticide maps (so all except soil) to 0. More...
 
void ReducePlantPesticide (int a_minx, int a_maxx, int a_miny, int a_maxy, int a_map_index, float a_reduc, bool a_remove_from_surface=false)
 Reduce the amount in plant pesticide maps. Everything is removed for surface if boolean is true (used for harvest but not cutting) More...
 
void DecreaseVegetationPesticide (int a_x, int a_y, PlantProtectionProducts a_ppp, double a_amount)
 Decrease the amount of pesticide in the vegetation compartment (used by foraging bees) More...
 
double SupplyPesticideSeed (int a_x, int a_y, PlantProtectionProducts a_ppp)
 Supplies the seed coating pesticide amount in cell. More...
 
double SupplyPesticideSeed (int a_polyref, PlantProtectionProducts a_ppp)
 Supplies the seed coating pesticide amount in polygon. Note that the result is not precise, since pesticide amount can vary within polygon. More...
 
double SupplyPesticide (int a_x, int a_y, PlantProtectionProducts a_ppp)
 Supplies the pesticide amount in cell. More...
 
double SupplyPesticide (int a_polyref, PlantProtectionProducts a_ppp)
 Supplies the pesticide amount in polygon. Note that the result is not precise, since pesticide amount can vary within polygon. More...
 
 Pesticide (Landscape *a_map)
 Constructer of pesticide engine. More...
 
virtual ~Pesticide (void)
 Destructor of pesticide engine. More...
 
bool RecordPesticideLoad (int a_ppp)
 Records the pesticide load at landscape level. More...
 
bool RecordPesticideMap (int a_ppp, ofstream &outfile, vector< Eigen::MatrixXf > &map)
 Records the current pesticide amount in map. More...
 
void RecordPesticideConcentrationPollenNectar (int a_x, int a_y, PlantProtectionProducts a_ppp, ofstream &outfile)
 Records the current pesticide concentration in pollen and nectar. More...
 
void RecordAllPesticideCompartments (int a_x, int a_y, PlantProtectionProducts a_ppp, ofstream &outfile)
 Records the current pesticide in all compartments + biomass. More...
 
bool SavePPM (double *a_map, int a_beginx, int a_width, int a_beginy, int a_height, char *a_filename)
 For testing of the pesticide engine. More...
 
void DiffusionVectorTest (void)
 For saving diffusion vector in file. More...
 

Protected Member Functions

void DailyQueueClear (PlantProtectionProducts a_ppp)
 Resets the pesticide action queue. More...
 
void DailyQueueProcess (PlantProtectionProducts a_ppp)
 Sprays the pesticides that are listed in the daily queue. More...
 
bool ElementIsWater (int a_x, int a_y)
 Checks if cell has a water type. More...
 
void MainMapDecay (PlantProtectionProducts a_ppp)
 Applies rain washoff and decays the pesticides in all maps by calling Pesticide::DecayMap. More...
 
void DecayMap (vector< Eigen::MatrixXf > &map, vector< double > &decay_frac, int a_ppp)
 Decays the pesticide in the entire map in a parallel manner. More...
 
void TwinMapClear ()
 Clears the twin map. More...
 
void TwinMapSpray (LE *a_element_spryaed, double a_amount, int a_minx, int a_miny, int a_maxx, int a_maxy)
 Sprays a_amount of the pesticide in each cell in the polygon in the twin map by calling Pesticide::TwinMapSprayPixel. More...
 
void TwinMapSprayPixel (int a_large_map_x, int a_large_map_y, double a_fractional_amount)
 Sprays pesticide in the cell. More...
 
void TwinMapSprayCorrectBorders (void)
 Corrects the border in case the pesticide map size doens't fit the landscape map size. More...
 
void TwinMapDiffusion (int a_minx, int a_miny, int a_maxx, int a_maxy, double a_cover, PlantProtectionProducts a_ppp)
 Diffuses the pesticide in the twin map and adds it to the main map. More...
 
void TwinMapDiffusionMatrix (int a_minx, int a_miny, int a_maxx, int a_maxy, double a_cover, PlantProtectionProducts a_ppp, vector< Eigen::MatrixXf > *a_drift_matrices_ptr)
 Diffuses the pesticide in the twin map and adds it to the main map using Eigen. More...
 
void DiffusionVectorInit (void)
 Initializes the diffusion vector that is used to drift the pesticide. More...
 
void DiffusionMatrixInit (void)
 Initializes the diffusion matrices that are used to drift the pesticide. More...
 
void DiffusionSprayPixel (int a_x, int a_limit_x, int a_y, int a_limit_y, double a_amount, double a_cover, PlantProtectionProducts a_ppp)
 Adds the diffused pesticide to the cell in the main map(s) More...
 
void AddGranularPesticide (int a_minx, int a_miny, int a_maxx, int a_maxy, double a_cover, PlantProtectionProducts a_ppp)
 Adds granular pesticide to polygon. More...
 

Protected Attributes

bool m_something_to_decay [ppp_foobar]
 Main class for pesticide engine. More...
 
bool m_seedcoating_to_decay [ppp_foobar]
 Structure to keep track of whether there is any seed coating to decay or transfer. More...
 
int m_NoPPPs
 The number of active PPPs to track. More...
 
int m_x_excess
 
int m_y_excess
 
double m_prop
 Constant related to the grid area (i.e. how many landscape map squares are in one grid square). More...
 
double m_corr_x
 Corrected proportions for the edge squares along the x-axis. More...
 
double m_corr_y
 Corrected proportions for the edge squares along the y-axis. More...
 
int m_wind
 The daily wind direction. More...
 
int m_pest_drift_max
 The maximum distance away from the spraying point we want to consider the pesticide drift downwind. More...
 
vector< double > m_pest_daily_decay_frac
 Daily decay fraction, precalculated from the pesticide environmental half life parameter, for one pesticide compartment use. More...
 
vector< double > m_dead_biomass
 Vector saving the dead biomass in each polygon from the previous day. More...
 
vector< double > m_green_biomass
 Vector saving the green biomass in each polygon from the previous day. More...
 
vector< double > m_pollen_mass
 Vector saving the pollen in each polygon from the previous day. More...
 
vector< double > m_nectar_mass
 Vector saving the nectar in each polygon from the previous day. More...
 
RasterMapm_land
 Local copy of pointer to the main map object. More...
 
Landscapem_map
 Local copy of pointer to the main landscape object.
More...
 
vector< Eigen::MatrixXf > m_pest_map_main
 Map to track the pesticide amount. More...
 
Eigen::MatrixXf m_pest_map_twin
 A temporary map used when new pesticide is sprayed. More...
 
vector< vector< double > > m_pest_map_record
 If we are recording pesticide load we need this map. More...
 
unsigned int m_pest_map_size
 The total size of one map in cellsize resolution. More...
 
unsigned int m_pest_map_width
 The width of one map in cellsize resolution. More...
 
unsigned int m_pest_map_height
 The height of one map in cellsize resolution. More...
 
vector< vector< double > > m_RainWashoffFactor
 a structure to hold pre-calculated pesticide rain washoff factor (Rw) More...
 
unsigned m_rainfallcategory
 Daily rainfall saved here * 100 to use as an index to the Pesticide::m_RainWashoffFactor array - an optimisation to stop repeated calls to Landscape::SupplyRain. More...
 
vector< double > m_diffusion_vector
 Pre-calculated diffusion vector. More...
 
vector< Eigen::MatrixXf > m_diffusion_matrices
 Pre-calculated diffusion matrices
Used after spraying an element in the pesticide map to determine how much of the sprayed material spreads into the surroundings. More...
 
vector< Eigen::MatrixXf > m_diffusion_matrices_orchard_early
 Pre-calculated diffusion matrices for orchards (early application) More...
 
vector< Eigen::MatrixXf > m_diffusion_matrices_orchard_late
 Pre-calculated diffusion matrices for orchards (late application) More...
 
vector< Eigen::MatrixXf > m_diffusion_matrices_vineyard_early
 Pre-calculated diffusion matrices for vineyards (early application) More...
 
vector< Eigen::MatrixXf > m_diffusion_matrices_vineyard_late
 Pre-calculated diffusion matrices for vineyards (late application) More...
 
vector< Eigen::MatrixXf > m_diffusion_matrices_dust_drift
 Pre-calculated diffusion matrices for dust drift, used for seed coating and granular application. More...
 
float m_dust_drift_remainder
 Remaining pesticide at 0 meter after dust drift, used for seed coating and granular application. More...
 
int m_orchard_drift_type
 Type of orchard drift, can be early or late application. More...
 
int m_drift_distance
 Length of drift vector. How far away from spraying point we consider drift. More...
 
vector< vector< PesticideEvent * > > m_daily_spray_queue
 List of landscape elements, which was sprayed on a given day. One for each PPP we track. More...
 
vector< vector< PesticideEvent * > > m_daily_seedcoating_queue
 List of landscape elements, which had seed coating on a given day. One for each PPP we track. More...
 
vector< vector< PesticideEvent * > > m_daily_granular_queue
 List of landscape elements, which had a granular application on a given day. One for each PPP we track. More...
 
ofstream m_pesticideRecord
 a file for recording pesticide loads More...
 
ofstream m_pesticide_file_rec
 
ofstream m_pesticide_file_rec_all_comp
 File for recording pesticide in all compartments including biomass etc. More...
 

Constructor & Destructor Documentation

◆ Pesticide()

Pesticide::Pesticide ( Landscape a_map)

Constructer of pesticide engine.

If the pesticide engine is on, then maps and vectors are initialized here. The rain washoff factor and diffusion vector are also calculated.

990 {
996  // Initialize daily queues which are also used when pesticide engine is off
1001  for (int p = 0; p < m_NoPPPs; p++) {
1002  m_daily_spray_queue[p].resize(0);
1003  m_daily_seedcoating_queue[p].resize(0);
1004  m_daily_granular_queue[p].resize(0);
1005  }
1006 
1008  {
1009  // Set the maximum drift distance downwind
1010  m_pest_drift_max = 10;
1011 
1012  // Determine the size of the maps we need in terms of the number of PPPs to track
1013  m_map = a_map;
1014  m_land = a_map->SupplyRasterMap();
1015  for (int i = 0; i < m_NoPPPs; i++) m_something_to_decay[i] = false;
1016  for (int i = 0; i < m_NoPPPs; i++) m_seedcoating_to_decay[i] = false;
1017 
1018  // Figure out critical border coordinates, proportional fractions etc.
1019  m_prop = 1.0 / ((double)(PEST_GRIDAREA));
1020  m_x_excess = m_land->MapWidth() & (PEST_GRIDSIZE - 1);
1021  if (m_x_excess) {
1022  m_corr_x = (double)PEST_GRIDSIZE / (double)m_x_excess;
1023  }
1025  if (m_y_excess) {
1026  m_corr_y = (double)PEST_GRIDSIZE / (double)m_y_excess;
1027  }
1028 
1029  // Calculate width, height and size of pesticide map
1030  m_pest_map_width = m_land->MapWidth() >> PEST_GRIDSIZE_POW2; // landscape width divided by the sqrt(cellsize) e.g. cellsize 4 and landscape width = 10000, result is 10000/(sqrt(4) = 5000
1031  if (m_land->MapWidth() & (PEST_GRIDSIZE - 1))
1032  m_pest_map_width++;
1033 
1035  if (m_land->MapHeight() & (PEST_GRIDSIZE - 1))
1037 
1039 
1040  // Initialize twin map
1042  m_pest_map_twin.setZero();
1043 
1044  // Initialize the pesticide load map
1045  if (l_pest_record_used.value()) {
1046  m_pest_map_record.resize(m_NoPPPs);
1047  for (int p = 0; p < m_NoPPPs; p++) {
1049  std::fill(m_pest_map_record[p].begin(), m_pest_map_record[p].end(), 0.0);
1050  }
1051  }
1052 
1053 #ifdef __DETAILED_PESTICIDE_FATE
1054  // Initialize maps and vectors for detailed pesticide model
1055  m_pest_map_vegcanopy.resize(m_NoPPPs);
1056  if (l_pest_enable_rain_washoff.value()) m_pest_map_vegcanopy_washoff.resize(m_NoPPPs);
1057  m_pest_map_soil.resize(m_NoPPPs);
1058  m_RainWashoffFactor.resize(m_NoPPPs);
1059  for (int p = 0; p < m_NoPPPs; p++) {
1060  m_pest_map_vegcanopy[p].resize(m_pest_map_height, m_pest_map_width);
1061  m_pest_map_vegcanopy[p].setZero();
1062  if (l_pest_enable_rain_washoff.value()) m_pest_map_vegcanopy_washoff[p].resize(m_pest_map_height, m_pest_map_width);
1063  if (l_pest_enable_rain_washoff.value()) m_pest_map_vegcanopy_washoff[p].setZero();
1064  m_pest_map_soil[p].resize(m_pest_map_height, m_pest_map_width);
1065  m_pest_map_soil[p].setZero();
1066  if (l_pest_enable_rain_washoff.value()) m_RainWashoffFactor[p].resize(10000);
1067  }
1069  fill(m_dead_biomass.begin(), m_dead_biomass.end(), 99999);
1071  fill(m_green_biomass.begin(), m_green_biomass.end(), 99999);
1073  fill(m_pollen_mass.begin(), m_pollen_mass.end(), 0);
1075  fill(m_nectar_mass.begin(), m_nectar_mass.end(), 0);
1076 
1077 #ifdef __FLOWER_PESTICIDE
1078  // Initialize maps for flower pesticide model
1079  m_pest_map_in_vegetation.resize(m_NoPPPs);
1080  m_pest_map_pollen.resize(m_NoPPPs);
1081  m_pest_map_nectar.resize(m_NoPPPs);
1082  m_pest_map_overspray.resize(m_NoPPPs);
1083  for (int p = 0; p < m_NoPPPs; p++) {
1084  m_pest_map_in_vegetation[p].resize(m_pest_map_height, m_pest_map_width);
1085  m_pest_map_in_vegetation[p].setZero();
1086  m_pest_map_pollen[p].resize(m_pest_map_height, m_pest_map_width);
1087  m_pest_map_pollen[p].setZero();
1088  m_pest_map_nectar[p].resize(m_pest_map_height, m_pest_map_width);
1089  m_pest_map_nectar[p].setZero();
1090  m_pest_map_overspray[p].resize(m_pest_map_height, m_pest_map_width);
1091  m_pest_map_overspray[p].setZero();
1092  }
1093 
1094  // Initialize the seed coating map
1095  if (l_pest_enable_seed_coating.value()) {
1096  m_pest_map_seed.resize(m_NoPPPs);
1097  for (int p = 0; p < m_NoPPPs; p++) {
1098  m_pest_map_seed[p].resize(m_pest_map_height, m_pest_map_width);
1099  m_pest_map_seed[p].setZero();
1100  }
1101  }
1102 #endif
1103 #else
1104  // Initialize map for one compartment pesticide model
1105  m_pest_map_main.resize(m_NoPPPs);
1106  for (int p = 0; p < m_NoPPPs; p++) {
1108  m_pest_map_main[p].setZero();
1109  }
1110 #endif
1111 
1112 #ifdef __DETAILED_PESTICIDE_FATE
1113  // Calculate rain washoff factors
1114  if (l_pest_enable_rain_washoff.value()) {
1115  for (int p = 0; p < m_NoPPPs; p++) {
1116  CalcRainWashOffFactors(p);
1117  }
1118  }
1119 #endif
1121  // Calculate diffusion vector due to drift
1123 #ifdef PEST_DEBUG
1125 #endif
1126  }
1127  else {
1128  DiffusionMatrixInit(); // Create matrices for fields, orchards and vineyards
1129  }
1130  // If turned on, create output files for saving pesticide load and concentration
1131  if (l_pest_record_used.value()) {
1132  m_pesticideRecord.open("PesticideGridRecord.txt", ios::out);
1133  m_pesticideRecord << "GridSize:" << '\t' << l_pest_record_grid_size.value() << '\t' << " GridsWide:" << '\t' << int(m_land->MapWidth() / l_pest_record_grid_size.value()) << endl;
1134  }
1136 #ifdef __DETAILED_PESTICIDE_FATE
1137  m_pesticide_file_rec_soil.open("PesticideMapSoil.txt", ios::out);
1138  m_pesticide_file_rec_vegcanopy.open("PesticideMapVegCanopy.txt", ios::out);
1139 #ifdef __FLOWER_PESTICIDE
1140  m_pesticide_file_rec_in_vegetation.open("PesticideMapInVegetation.txt", ios::out);
1141  m_pesticide_file_rec_pollen_nectar.open("PesticideConcentrationPollenNectar.txt", ios::out);
1142  if (l_pest_enable_seed_coating.value()) {
1143  m_pesticide_file_rec_seed.open("PesticideMapSeed.txt", ios::out);
1144  }
1145 
1146 #endif
1147 #else
1148  m_pesticide_file_rec.open("PesticideMap.txt", ios::out);
1149 #endif
1150  }
1152 #ifdef __DETAILED_PESTICIDE_FATE
1153 #ifdef __FLOWER_PESTICIDE
1154  m_pesticide_file_rec_all_comp.open("PesticideAllCompartments.txt", ios::out);
1155  m_pesticide_file_rec_all_comp << "Date" << '\t' << "Biomass" << '\t' << "GreenBiomass" << '\t' << "DeadBiomass" << '\t' << "Height" << '\t';
1156  m_pesticide_file_rec_all_comp << "PPP" << '\t' << "VegCanopy" << '\t' << "Pollen" << '\t' << "Nectar" << '\t' << "Soil" << '\t' << "InPlant" << '\t' << "SeedCoating" << '\t';
1157  m_pesticide_file_rec_all_comp << "PollenConc" << '\t' << "NectarConc" << '\t' << "PollenMass" << '\t' << "NectarMass" << '\t' << "DegreeDays" << '\t' << "OversprayToday" << endl;
1158 #else
1159  m_pesticide_file_rec_all_comp.open("PesticideBothCompartments.txt", ios::out);
1160  m_pesticide_file_rec_all_comp << "Date" << '\t' << "Biomass" << '\t' << "GreenBiomass" << '\t' << "DeadBiomass" << '\t' << "Height" << '\t' << "PPP" << '\t' << "VegCanopy" << '\t' << "Soil" << endl;
1161 #endif
1162 #else
1163  m_pesticide_file_rec_all_comp.open("PesticideCompartment.txt", ios::out);
1164  m_pesticide_file_rec_all_comp << "Date" << '\t' << "Biomass" << '\t' << "GreenBiomass" << '\t' << "DeadBiomass" << '\t' << "Height" << '\t' << "PPP" << '\t' << "TotalPesticide" << endl;
1165 #endif
1166  }
1167  //m_pesticide_file_rec.open("PesticideMapFineGrainedRightAfterSpray.txt", ios::out);
1168  }
1169 }

References DiffusionMatrixInit(), DiffusionVectorInit(), DiffusionVectorTest(), g_landscape_ptr, l_pest_enable_pesticide_engine, l_pest_NoPPPs, l_pest_record_grid_size, l_pest_record_used, l_pest_save_all_compartments, l_pest_save_map_daily, l_pest_use_single_nozzle_drift, m_corr_x, m_corr_y, m_daily_granular_queue, m_daily_seedcoating_queue, m_daily_spray_queue, m_dead_biomass, m_green_biomass, m_land, m_map, m_nectar_mass, m_NoPPPs, m_pest_drift_max, m_pest_map_height, m_pest_map_main, m_pest_map_record, m_pest_map_size, m_pest_map_twin, m_pest_map_width, m_pesticide_file_rec, m_pesticide_file_rec_all_comp, m_pesticideRecord, m_pollen_mass, m_prop, m_RainWashoffFactor, m_seedcoating_to_decay, m_something_to_decay, m_x_excess, m_y_excess, RasterMap::MapHeight(), RasterMap::MapWidth(), PEST_GRIDAREA, PEST_GRIDSIZE, PEST_GRIDSIZE_POW2, Landscape::SupplyMaxPoly(), Landscape::SupplyRasterMap(), CfgInt::value(), and CfgBool::value().

Referenced by CreatePesticide().

◆ ~Pesticide()

virtual Pesticide::~Pesticide ( void  )
inlinevirtual

Destructor of pesticide engine.

414 {};

Member Function Documentation

◆ AddGranularPesticide()

void Pesticide::AddGranularPesticide ( int  a_minx,
int  a_miny,
int  a_maxx,
int  a_maxy,
double  a_cover,
PlantProtectionProducts  a_ppp 
)
protected

Adds granular pesticide to polygon.

961 {
963  {
964  // Apply dust drift to soil and plant surface
965  TwinMapDiffusionMatrix(a_minx, a_miny, a_maxx, a_maxy, a_cover, a_ppp, &m_diffusion_matrices_dust_drift);
966 #ifdef __DETAILED_PESTICIDE_FATE
967  // Add the remaining pesticide to the soil in the field
968  m_pest_map_soil[a_ppp] += m_pest_map_twin * m_dust_drift_remainder;
969  }
970  else
971  {
972  // Apply all the pesticide to the soil in the field
973  m_pest_map_soil[a_ppp] += m_pest_map_twin;
974  }
975 #else
976  // Add the remaining pesticide to the field
978  }
979  else
980  {
981  // Apply all the pesticide to the field
983  }
984 #endif
985  m_something_to_decay[a_ppp] = true;
986 }

References l_pest_enable_dust_drift, m_diffusion_matrices_dust_drift, m_dust_drift_remainder, m_pest_map_main, m_pest_map_twin, TwinMapDiffusionMatrix(), and CfgBool::value().

Referenced by DailyQueueProcess().

◆ DailyQueueAdd()

void Pesticide::DailyQueueAdd ( LE a_element_sprayed,
double  a_amount,
PlantProtectionProducts  a_ppp,
int  a_drifttype = 0 
)

Adds new pesticide spray event to the daily queue.

Pesticide spraying event is added to the end of the daily spraying queue.

344 {
348  PesticideEvent *l_event = new PesticideEvent( a_element_sprayed, a_amount, a_ppp, a_drifttype);
349  m_daily_spray_queue[a_ppp].push_back(l_event);
350 }

References m_daily_spray_queue.

Referenced by Orchard::DoDevelopment(), OrchardBand::DoDevelopment(), Farm::ProductApplication(), and Farm::ProductApplication_DateLimited().

◆ DailyQueueAddGranular()

void Pesticide::DailyQueueAddGranular ( LE a_element_sprayed,
double  a_amount,
PlantProtectionProducts  a_ppp 
)

Adds new granular application event to the daily queue.

Pesticide granular applicaiton event is added to the end of the daily granular queue.

364 {
368  PesticideEvent* l_event = new PesticideEvent(a_element_sprayed, a_amount, a_ppp);
369  m_daily_granular_queue[a_ppp].push_back(l_event);
370 }

References m_daily_granular_queue.

Referenced by Farm::ProductApplication(), and Farm::ProductApplication_DateLimited().

◆ DailyQueueAddSeedCoating()

void Pesticide::DailyQueueAddSeedCoating ( LE a_element_sprayed,
double  a_amount,
PlantProtectionProducts  a_ppp 
)

Adds new seed coating event to the daily queue.

Pesticide seed coating event is added to the end of the daily seed coating queue.

354 {
358  PesticideEvent* l_event = new PesticideEvent(a_element_sprayed, a_amount, a_ppp);
359  m_daily_seedcoating_queue[a_ppp].push_back(l_event);
360 }

References m_daily_seedcoating_queue.

Referenced by Farm::AutumnSow(), Farm::AutumnSowWithFerti(), Farm::PreseedingCultivatorSow(), Farm::SpringSow(), Farm::SpringSowWithFerti(), and Farm::StriglingSow().

◆ DailyQueueClear()

void Pesticide::DailyQueueClear ( PlantProtectionProducts  a_ppp)
protected

Resets the pesticide action queue.

Empties and resets the pesticide action queue. On calling any event not yet carried out will be deleted.

872 {
876  if (!m_daily_spray_queue[a_ppp].empty()) m_daily_spray_queue[a_ppp].resize(0);
877  if (!m_daily_seedcoating_queue[a_ppp].empty()) m_daily_seedcoating_queue[a_ppp].resize(0);
878  if (!m_daily_granular_queue[a_ppp].empty()) m_daily_granular_queue[a_ppp].resize(0);
879 }

References m_daily_granular_queue, m_daily_seedcoating_queue, and m_daily_spray_queue.

Referenced by Tick().

◆ DailyQueueProcess()

void Pesticide::DailyQueueProcess ( PlantProtectionProducts  a_ppp)
protected

Sprays the pesticides that are listed in the daily queue.

Method runs if we are spraying at least one field. Sets something_to_decay to true so the decay method will run tomorrow. First we make sure the twin map is cleared. Then we add the amount m_amount to the twin map (all squares covered with the polygon get m_amount added) using TwinMapSpray
Next this twin map is added to the main map taking into acount drift and if necessary it is here we sort out the allocation between different compartments. This is done by TwinMapDiffusion

560 {
568  if (0 == m_daily_spray_queue[a_ppp].size() && 0 == m_daily_seedcoating_queue[a_ppp].size() && 0 == m_daily_granular_queue[a_ppp].size()) {
569  // Event queues empty, nobody sprayed anything today.
570  return;
571  }
572 
573  // Spraying at least one field. Force the main pesticide map decay method to run tomorrow.
574  m_something_to_decay[a_ppp] = true;
575 
576  for ( unsigned int i=0; i<m_daily_spray_queue[a_ppp].size(); i++ ){
577  int minx=m_daily_spray_queue[a_ppp][i]->m_sprayed_elem->GetMinX();
578  int maxx=m_daily_spray_queue[a_ppp][i]->m_sprayed_elem->GetMaxX();
579  int miny=m_daily_spray_queue[a_ppp][i]->m_sprayed_elem->GetMinY();
580  int maxy=m_daily_spray_queue[a_ppp][i]->m_sprayed_elem->GetMaxY();
581  // For cover we use the crop, and save this for later
582  double cover = m_daily_spray_queue[a_ppp][i]->m_sprayed_elem->GetVegCover();
583  TwinMapClear();
584  // Add the amount in m_amount to the twin map (all squares covered with the polygon get m_amount added.
585  TwinMapSpray( m_daily_spray_queue[a_ppp][i]->m_sprayed_elem, m_daily_spray_queue[a_ppp][i]->m_amount, minx, miny, maxx, maxy);
587  // This adds it to the main map and if necessary sorts out the allocation between veg and soil.
588  TwinMapDiffusion(minx, miny, maxx, maxy, cover, a_ppp);
589  }
590  else{
591  if (m_daily_spray_queue[a_ppp][i]->m_sprayed_elem->GetElementType() == tole_Orchard) // Use orchard drift
592  {
593  if (m_daily_spray_queue[a_ppp][i]->m_drift_type == 1) TwinMapDiffusionMatrix(minx, miny, maxx, maxy, cover, a_ppp, &m_diffusion_matrices_orchard_early);
594  else if (m_daily_spray_queue[a_ppp][i]->m_drift_type == 2) TwinMapDiffusionMatrix(minx, miny, maxx, maxy, cover, a_ppp, &m_diffusion_matrices_orchard_late);
595  else {
596  g_msg->Warn(WARN_FATAL, "Pesticide::DailyQueueProcess(): Orchard drift type (early or late) is not given!", "");
597  exit(1);
598  }
599  }
600  else if(m_daily_spray_queue[a_ppp][i]->m_sprayed_elem->GetElementType() == tole_Vineyard) // Use vineyard drift
601  {
602  if (m_daily_spray_queue[a_ppp][i]->m_drift_type == 1) TwinMapDiffusionMatrix(minx, miny, maxx, maxy, cover, a_ppp, &m_diffusion_matrices_vineyard_early);
603  else if (m_daily_spray_queue[a_ppp][i]->m_drift_type == 2) TwinMapDiffusionMatrix(minx, miny, maxx, maxy, cover, a_ppp, &m_diffusion_matrices_vineyard_late);
604  else {
605  g_msg->Warn(WARN_FATAL, "Pesticide::DailyQueueProcess(): Vineyard drift type (early or late) is not given!", "");
606  exit(1);
607  }
608  }
609  // For vegetables, ornamentals and small fruit UNDER 50 cm use field crop drift (this is specified in crop code)
610  else if (m_daily_spray_queue[a_ppp][i]->m_drift_type == 3) TwinMapDiffusionMatrix(minx, miny, maxx, maxy, cover, a_ppp, &m_diffusion_matrices);
611  // For vegetables, ornamentals and small fruit OVER 50 cm use late vineyard drift (this is specified in crop code)
612  else if (m_daily_spray_queue[a_ppp][i]->m_drift_type == 4) TwinMapDiffusionMatrix(minx, miny, maxx, maxy, cover, a_ppp, &m_diffusion_matrices_vineyard_late);
613  // Else if nothing is specified and it is not orchard or vineyard use field drift
614  else TwinMapDiffusionMatrix(minx, miny, maxx, maxy, cover, a_ppp, &m_diffusion_matrices);
615  }
616  // add the type and rate to the field
617  m_daily_spray_queue[a_ppp][i]->m_sprayed_elem->SetSprayPPPType(a_ppp);
618  m_daily_spray_queue[a_ppp][i]->m_sprayed_elem->SetSprayPPPRate(m_daily_spray_queue[a_ppp][i]->m_amount);
619  }
620 #ifdef __DETAILED_PESTICIDE_FATE
621 #ifdef __FLOWER_PESTICIDE
622  // Apply seed coating
623  if (l_pest_enable_seed_coating.value()) {
624  for (unsigned int i = 0; i < m_daily_seedcoating_queue[a_ppp].size(); i++) {
625  int minx = m_daily_seedcoating_queue[a_ppp][i]->m_sprayed_elem->GetMinX();
626  int maxx = m_daily_seedcoating_queue[a_ppp][i]->m_sprayed_elem->GetMaxX();
627  int miny = m_daily_seedcoating_queue[a_ppp][i]->m_sprayed_elem->GetMinY();
628  int maxy = m_daily_seedcoating_queue[a_ppp][i]->m_sprayed_elem->GetMaxY();
629  // For cover we use the crop, and save this for later
630  double cover = m_daily_seedcoating_queue[a_ppp][i]->m_sprayed_elem->GetVegCover();
631  TwinMapClear();
632  // Add the amount in m_amount to the twin map (all squares covered with the polygon get m_amount added.
633  TwinMapSpray(m_daily_seedcoating_queue[a_ppp][i]->m_sprayed_elem, m_daily_seedcoating_queue[a_ppp][i]->m_amount, minx, miny, maxx, maxy);
634  // Add it to the seed coating map
635  AddSeedCoating(minx, miny, maxx, maxy, cover, a_ppp);
636  }
637  }
638 #endif
639 #endif
640  // Apply granular pesticide
641  for (unsigned int i = 0; i < m_daily_granular_queue[a_ppp].size(); i++) {
642  int minx = m_daily_granular_queue[a_ppp][i]->m_sprayed_elem->GetMinX();
643  int maxx = m_daily_granular_queue[a_ppp][i]->m_sprayed_elem->GetMaxX();
644  int miny = m_daily_granular_queue[a_ppp][i]->m_sprayed_elem->GetMinY();
645  int maxy = m_daily_granular_queue[a_ppp][i]->m_sprayed_elem->GetMaxY();
646  // For cover we use the crop, and save this for later
647  double cover = m_daily_granular_queue[a_ppp][i]->m_sprayed_elem->GetVegCover();
648  TwinMapClear();
649  // Add the amount in m_amount to the twin map (all squares covered with the polygon get m_amount added.
650  TwinMapSpray(m_daily_granular_queue[a_ppp][i]->m_sprayed_elem, m_daily_granular_queue[a_ppp][i]->m_amount, minx, miny, maxx, maxy);
651  // Add it to the soil map
652  AddGranularPesticide(minx, miny, maxx, maxy, cover, a_ppp);
653  }
654 }

References AddGranularPesticide(), g_msg, l_pest_use_single_nozzle_drift, m_daily_granular_queue, m_daily_seedcoating_queue, m_daily_spray_queue, m_diffusion_matrices, m_diffusion_matrices_orchard_early, m_diffusion_matrices_orchard_late, m_diffusion_matrices_vineyard_early, m_diffusion_matrices_vineyard_late, m_something_to_decay, tole_Orchard, tole_Vineyard, TwinMapClear(), TwinMapDiffusion(), TwinMapDiffusionMatrix(), TwinMapSpray(), CfgBool::value(), MapErrorMsg::Warn(), and WARN_FATAL.

Referenced by Tick().

◆ DecayMap()

void Pesticide::DecayMap ( vector< Eigen::MatrixXf > &  map,
vector< double > &  decay_frac,
int  a_ppp 
)
protected

Decays the pesticide in the entire map in a parallel manner.

Loops over each cell in the map and decays the pesticide.

551 {
555  map[a_ppp] *= decay_frac[a_ppp];
556 }

Referenced by MainMapDecay().

◆ DecreaseVegetationPesticide()

void Pesticide::DecreaseVegetationPesticide ( int  a_x,
int  a_y,
PlantProtectionProducts  a_ppp,
double  a_amount 
)

Decrease the amount of pesticide in the vegetation compartment (used by foraging bees)

436 {
437 #ifdef __DETAILED_PESTICIDE_FATE
438 #ifdef __FLOWER_PESTICIDE
440  int l_y = a_y >> PEST_GRIDSIZE_POW2;
441  int t = l_y * m_pest_map_width;
442  int l_x = a_x >> PEST_GRIDSIZE_POW2;
443  m_pest_map_in_vegetation[a_PPP](l_y,l_x) -= a_amount;
444  }
445 #endif
446 #endif
447 }

References l_pest_enable_pesticide_engine, m_pest_map_width, PEST_GRIDSIZE_POW2, and CfgBool::value().

◆ DiffusionMatrixInit()

void Pesticide::DiffusionMatrixInit ( void  )
protected

Initializes the diffusion matrices that are used to drift the pesticide.

1269  {
1270  // Get diffusion vectors for fields, orchards and vineyards
1271 
1272  vector<float> rautmannField = { 1.350E-02, 4.707E-03, 2.376E-03, 1.431E-03, 9.559E-04, 6.839E-04, 5.136E-04, 4.000E-04, 3.203E-04, 2.624E-04, 2.189E-04,
1273  1.854E-04, 1.591E-04, 1.380E-04, 1.208E-04, 1.067E-04, 9.493E-05, 8.501E-05, 7.656E-05, 6.932E-05, 6.307E-05, 5.762E-05, 5.286E-05, 4.866E-05,
1274  4.495E-05, 4.164E-05, 3.869E-05, 3.604E-05, 3.366E-05, 3.151E-05, 2.955E-05, 2.778E-05, 2.616E-05, 2.467E-05, 2.332E-05, 2.207E-05, 2.091E-05,
1275  1.985E-05, 1.887E-05, 1.795E-05, 1.711E-05, 1.632E-05, 1.558E-05, 1.490E-05, 1.425E-05, 1.365E-05, 1.309E-05, 1.256E-05, 1.206E-05, 1.159E-05,
1276  1.115E-05, 1.073E-05, 1.034E-05, 9.968E-06, 9.615E-06, 9.281E-06, 8.964E-06, 8.663E-06, 8.377E-06, 8.105E-06, 7.846E-06, 7.599E-06, 7.364E-06,
1277  7.139E-06, 6.925E-06, 6.720E-06, 6.525E-06, 6.337E-06, 6.158E-06, 5.986E-06, 5.821E-06, 5.663E-06, 5.512E-06, 5.366E-06, 5.226E-06, 5.092E-06,
1278  4.963E-06, 4.838E-06, 4.718E-06, 4.603E-06, 4.492E-06, 4.385E-06, 4.281E-06, 4.181E-06, 4.085E-06, 3.992E-06, 3.902E-06, 3.815E-06, 3.731E-06,
1279  3.650E-06, 3.572E-06, 3.496E-06, 3.422E-06, 3.351E-06, 3.281E-06, 3.214E-06, 3.150E-06, 3.087E-06, 3.025E-06, 2.966E-06, 2.908E-06, 2.853E-06,
1280  2.798E-06, 2.745E-06, 2.694E-06, 2.644E-06, 2.596E-06, 2.549E-06, 2.503E-06, 2.458E-06, 2.415E-06, 2.372E-06, 2.331E-06, 2.291E-06, 2.252E-06,
1281  2.214E-06, 2.177E-06, 2.140E-06, 2.105E-06, 2.071E-06, 2.037E-06, 2.004E-06, 1.972E-06, 1.941E-06, 1.911E-06, 1.881E-06, 1.852E-06, 1.823E-06,
1282  1.795E-06, 1.768E-06, 1.742E-06, 1.716E-06, 1.691E-06, 1.666E-06, 1.641E-06, 1.618E-06, 1.595E-06, 1.572E-06, 1.550E-06, 1.528E-06, 1.507E-06,
1283  1.486E-06, 1.465E-06, 1.445E-06, 1.426E-06, 1.406E-06, 1.388E-06, 1.369E-06, 1.351E-06, 1.333E-06, 1.316E-06, 1.299E-06, 1.282E-06, 1.266E-06,
1284  1.250E-06, 1.234E-06, 1.219E-06, 1.203E-06, 1.189E-06, 1.174E-06, 1.160E-06, 1.146E-06, 1.132E-06, 1.118E-06, 1.105E-06, 1.092E-06, 1.079E-06,
1285  1.066E-06, 1.054E-06, 1.042E-06, 1.030E-06, 1.018E-06, 1.006E-06, 9.948E-07, 9.836E-07, 9.726E-07, 9.618E-07, 9.512E-07, 9.407E-07, 9.304E-07,
1286  9.203E-07, 9.104E-07, 9.006E-07, 8.909E-07, 8.814E-07, 8.721E-07, 8.629E-07, 8.539E-07, 8.450E-07, 8.362E-07, 8.276E-07, 8.191E-07, 8.108E-07,
1287  8.025E-07, 7.944E-07, 7.864E-07, 7.786E-07, 7.708E-07, 7.632E-07, 7.557E-07, 7.483E-07, 7.410E-07, 7.338E-07, 7.267E-07, 7.197E-07, 7.128E-07,
1288  7.061E-07, 6.994E-07, 6.928E-07, 6.863E-07, 6.799E-07, 6.736E-07, 6.673E-07, 6.612E-07, 6.551E-07, 6.491E-07, 6.433E-07, 6.374E-07, 6.317E-07,
1289  6.260E-07, 6.205E-07, 6.150E-07, 6.095E-07, 6.042E-07, 5.989E-07, 5.936E-07, 5.885E-07, 5.834E-07, 5.784E-07, 5.734E-07, 5.685E-07, 5.637E-07,
1290  5.589E-07, 5.542E-07, 5.496E-07, 5.450E-07, 5.405E-07, 5.360E-07, 5.316E-07, 5.272E-07, 5.229E-07, 5.186E-07, 5.144E-07, 5.103E-07, 5.062E-07,
1291  5.021E-07, 4.981E-07, 4.941E-07, 4.902E-07, 4.864E-07 };
1292 
1293  vector<float> rautmannOrchardEarly = { 2.843E-01, 9.352E-02, 5.066E-02, 3.381E-02, 2.533E-02, 2.040E-02, 1.727E-02, 1.513E-02, 1.361E-02, 1.248E-02,
1294  1.161E-02, 1.094E-02, 1.039E-02, 9.954E-03, 8.680E-03, 6.941E-03, 5.626E-03, 4.616E-03, 3.828E-03, 3.205E-03, 2.707E-03, 2.304E-03, 1.975E-03,
1295  1.705E-03, 1.480E-03, 1.292E-03, 1.134E-03, 9.999E-04, 8.856E-04, 7.876E-04, 7.031E-04, 6.300E-04, 5.665E-04, 5.109E-04, 4.622E-04, 4.194E-04,
1296  3.815E-04, 3.479E-04, 3.181E-04, 2.915E-04, 2.677E-04, 2.464E-04, 2.272E-04, 2.099E-04, 1.942E-04, 1.801E-04, 1.673E-04, 1.556E-04, 1.449E-04,
1297  1.352E-04, 1.263E-04, 1.182E-04, 1.107E-04, 1.039E-04, 9.755E-05, 9.172E-05, 8.634E-05, 8.136E-05, 7.675E-05, 7.248E-05, 6.852E-05, 6.483E-05,
1298  6.140E-05, 5.821E-05, 5.523E-05, 5.245E-05, 4.985E-05, 4.742E-05, 4.514E-05, 4.300E-05, 4.100E-05, 3.912E-05, 3.735E-05, 3.569E-05, 3.412E-05,
1299  3.265E-05, 3.126E-05, 2.994E-05, 2.871E-05, 2.753E-05, 2.643E-05, 2.538E-05, 2.438E-05, 2.344E-05, 2.255E-05, 2.170E-05, 2.090E-05, 2.014E-05,
1300  1.941E-05, 1.872E-05, 1.806E-05, 1.744E-05, 1.684E-05, 1.628E-05, 1.573E-05, 1.522E-05, 1.472E-05, 1.425E-05, 1.380E-05, 1.337E-05, 1.296E-05,
1301  1.257E-05, 1.219E-05, 1.183E-05, 1.149E-05, 1.115E-05, 1.084E-05, 1.053E-05, 1.024E-05, 9.960E-06, 9.690E-06, 9.431E-06, 9.183E-06, 8.944E-06,
1302  8.714E-06, 8.493E-06, 8.280E-06, 8.075E-06, 7.878E-06, 7.688E-06, 7.505E-06, 7.329E-06, 7.159E-06, 6.995E-06, 6.837E-06, 6.684E-06, 6.537E-06,
1303  6.395E-06, 6.258E-06, 6.125E-06, 5.997E-06, 5.873E-06, 5.753E-06, 5.637E-06, 5.525E-06, 5.417E-06, 5.312E-06, 5.211E-06, 5.112E-06, 5.017E-06,
1304  4.925E-06, 4.836E-06, 4.749E-06, 4.665E-06, 4.584E-06, 4.505E-06, 4.429E-06, 4.355E-06, 4.283E-06, 4.213E-06, 4.145E-06, 4.079E-06, 4.015E-06,
1305  3.953E-06, 3.893E-06, 3.834E-06, 3.777E-06, 3.722E-06, 3.668E-06, 3.616E-06, 3.565E-06, 3.515E-06, 3.467E-06, 3.420E-06, 3.375E-06, 3.330E-06,
1306  3.287E-06, 3.245E-06, 3.204E-06, 3.164E-06, 3.125E-06, 3.087E-06, 3.051E-06, 3.015E-06, 2.980E-06, 2.945E-06, 2.912E-06, 2.880E-06, 2.848E-06,
1307  2.817E-06, 2.787E-06, 2.758E-06, 2.729E-06, 2.701E-06, 2.674E-06, 2.647E-06, 2.621E-06, 2.596E-06, 2.571E-06, 2.547E-06, 2.523E-06, 2.500E-06,
1308  2.477E-06, 2.455E-06, 2.433E-06, 2.412E-06, 2.392E-06, 2.372E-06, 2.352E-06, 2.333E-06, 2.314E-06, 2.295E-06, 2.277E-06, 2.260E-06, 2.242E-06,
1309  2.226E-06, 2.209E-06, 2.193E-06, 2.177E-06, 2.162E-06, 2.146E-06, 2.131E-06, 2.117E-06, 2.103E-06, 2.089E-06, 2.075E-06, 2.062E-06, 2.049E-06,
1310  2.036E-06, 2.023E-06, 2.011E-06, 1.999E-06, 1.987E-06, 1.975E-06, 1.964E-06, 1.953E-06, 1.942E-06, 1.931E-06, 1.921E-06, 1.910E-06, 1.900E-06,
1311  1.890E-06, 1.881E-06, 1.871E-06, 1.862E-06, 1.853E-06, 1.844E-06, 1.835E-06, 1.826E-06, 1.817E-06, 1.809E-06, 1.801E-06, 1.793E-06, 1.785E-06,
1312  1.777E-06, 1.769E-06, 1.762E-06, 1.755E-06, 1.747E-06, 1.740E-06 };
1313 
1314  vector<float> rautmannOrchardLate = { 3.519E-01, 9.550E-02, 4.450E-02, 2.586E-02, 1.696E-02, 1.201E-02, 8.963E-03, 6.950E-03, 5.550E-03, 4.534E-03,
1315  3.774E-03,3.189E-03, 2.729E-03, 2.361E-03, 2.125E-03, 1.774E-03, 1.497E-03, 1.276E-03, 1.097E-03, 9.504E-04, 8.291E-04, 7.280E-04, 6.429E-04,
1316  5.708E-04, 5.092E-04, 4.563E-04, 4.106E-04, 3.709E-04, 3.363E-04, 3.059E-04, 2.791E-04, 2.554E-04, 2.344E-04, 2.157E-04, 1.989E-04, 1.839E-04,
1317  1.703E-04, 1.581E-04, 1.471E-04, 1.371E-04, 1.279E-04, 1.196E-04, 1.120E-04, 1.051E-04, 9.872E-05, 9.286E-05, 8.747E-05, 8.250E-05, 7.790E-05,
1318  7.365E-05, 6.971E-05, 6.605E-05, 6.265E-05, 5.948E-05, 5.653E-05, 5.378E-05, 5.121E-05, 4.880E-05, 4.655E-05, 4.443E-05, 4.245E-05, 4.058E-05,
1319  3.883E-05, 3.718E-05, 3.562E-05, 3.416E-05, 3.277E-05, 3.146E-05, 3.023E-05, 2.905E-05, 2.794E-05, 2.689E-05, 2.590E-05, 2.495E-05, 2.405E-05,
1320  2.319E-05, 2.238E-05, 2.161E-05, 2.087E-05, 2.017E-05, 1.949E-05, 1.886E-05, 1.824E-05, 1.766E-05, 1.710E-05, 1.657E-05, 1.606E-05, 1.557E-05,
1321  1.510E-05, 1.466E-05, 1.423E-05, 1.381E-05, 1.342E-05, 1.304E-05, 1.267E-05, 1.232E-05, 1.199E-05, 1.166E-05, 1.135E-05, 1.105E-05, 1.076E-05,
1322  1.049E-05, 1.022E-05, 9.961E-06, 9.712E-06, 9.472E-06, 9.241E-06, 9.017E-06, 8.802E-06, 8.593E-06, 8.392E-06, 8.198E-06, 8.010E-06, 7.828E-06,
1323  7.652E-06, 7.482E-06, 7.318E-06, 7.158E-06, 7.004E-06, 6.854E-06, 6.710E-06, 6.569E-06, 6.433E-06, 6.301E-06, 6.174E-06, 6.049E-06, 5.929E-06,
1324  5.812E-06, 5.699E-06, 5.589E-06, 5.482E-06, 5.378E-06, 5.277E-06, 5.179E-06, 5.083E-06, 4.991E-06, 4.900E-06, 4.813E-06, 4.727E-06, 4.644E-06,
1325  4.564E-06, 4.485E-06, 4.408E-06, 4.334E-06, 4.261E-06, 4.190E-06, 4.121E-06, 4.054E-06, 3.989E-06, 3.925E-06, 3.863E-06, 3.802E-06, 3.743E-06,
1326  3.685E-06, 3.629E-06, 3.574E-06, 3.520E-06, 3.468E-06, 3.417E-06, 3.367E-06, 3.318E-06, 3.271E-06, 3.224E-06, 3.179E-06, 3.134E-06, 3.091E-06,
1327  3.048E-06, 3.007E-06, 2.967E-06, 2.927E-06, 2.888E-06, 2.850E-06, 2.813E-06, 2.777E-06, 2.741E-06, 2.707E-06, 2.673E-06, 2.640E-06, 2.607E-06,
1328  2.575E-06, 2.544E-06, 2.513E-06, 2.483E-06, 2.454E-06, 2.425E-06, 2.397E-06, 2.370E-06, 2.343E-06, 2.316E-06, 2.290E-06, 2.265E-06, 2.240E-06,
1329  2.216E-06, 2.192E-06, 2.168E-06, 2.145E-06, 2.123E-06, 2.100E-06, 2.079E-06, 2.057E-06, 2.036E-06, 2.016E-06, 1.996E-06, 1.976E-06, 1.957E-06,
1330  1.937E-06, 1.919E-06, 1.900E-06, 1.882E-06, 1.865E-06, 1.847E-06, 1.830E-06, 1.813E-06, 1.797E-06, 1.781E-06, 1.765E-06, 1.749E-06, 1.734E-06,
1331  1.719E-06, 1.704E-06, 1.689E-06, 1.675E-06, 1.661E-06, 1.647E-06, 1.633E-06, 1.620E-06, 1.607E-06, 1.594E-06, 1.581E-06, 1.569E-06, 1.556E-06,
1332  1.544E-06, 1.532E-06, 1.520E-06, 1.509E-06, 1.498E-06, 1.486E-06, 1.475E-06, 1.465E-06, 1.454E-06, 1.443E-06, 1.433E-06, 1.423E-06, 1.413E-06,
1333  1.403E-06, 1.393E-06, 1.384E-06, 1.374E-06, 1.365E-06, 1.356E-06 };
1334 
1335  vector<float> rautmannVineyardEarly = { 1.047E-01, 2.575E-02, 1.039E-02, 5.303E-03, 3.108E-03, 1.995E-03, 1.366E-03, 9.809E-04, 7.313E-04, 5.616E-04,
1336  4.419E-04, 3.548E-04, 2.897E-04, 2.401E-04, 2.015E-04, 1.709E-04, 1.465E-04, 1.266E-04, 1.102E-04, 9.666E-05, 8.530E-05, 7.571E-05, 6.754E-05,
1337  6.055E-05, 5.452E-05, 4.929E-05, 4.472E-05, 4.073E-05, 3.721E-05, 3.409E-05, 3.133E-05, 2.886E-05, 2.666E-05, 2.468E-05, 2.290E-05, 2.130E-05,
1338  1.984E-05, 1.852E-05, 1.731E-05, 1.622E-05, 1.521E-05, 1.429E-05, 1.345E-05, 1.267E-05, 1.196E-05, 1.129E-05, 1.068E-05, 1.012E-05, 9.589E-06,
1339  9.100E-06, 8.644E-06, 8.220E-06, 7.824E-06, 7.454E-06, 7.107E-06, 6.783E-06, 6.478E-06, 6.192E-06, 5.924E-06, 5.671E-06, 5.433E-06, 5.208E-06,
1340  4.996E-06, 4.796E-06, 4.607E-06, 4.428E-06, 4.258E-06, 4.097E-06, 3.945E-06, 3.800E-06, 3.663E-06, 3.532E-06, 3.408E-06, 3.289E-06, 3.176E-06,
1341  3.069E-06, 2.966E-06, 2.868E-06, 2.775E-06, 2.686E-06, 2.600E-06, 2.519E-06, 2.441E-06, 2.366E-06, 2.294E-06, 2.225E-06, 2.159E-06, 2.096E-06,
1342  2.035E-06, 1.977E-06, 1.921E-06, 1.867E-06, 1.815E-06, 1.766E-06, 1.718E-06, 1.672E-06, 1.627E-06, 1.584E-06, 1.543E-06, 1.503E-06, 1.465E-06,
1343  1.428E-06, 1.392E-06, 1.357E-06, 1.324E-06, 1.292E-06, 1.260E-06, 1.230E-06, 1.201E-06, 1.173E-06, 1.145E-06, 1.119E-06, 1.093E-06, 1.069E-06,
1344  1.045E-06, 1.021E-06, 9.988E-07, 9.769E-07, 9.556E-07, 9.350E-07, 9.150E-07, 8.956E-07, 8.768E-07, 8.585E-07, 8.407E-07, 8.235E-07, 8.067E-07,
1345  7.904E-07, 7.745E-07, 7.591E-07, 7.441E-07, 7.295E-07, 7.153E-07, 7.014E-07, 6.880E-07, 6.749E-07, 6.621E-07, 6.497E-07, 6.376E-07, 6.258E-07,
1346  6.143E-07, 6.031E-07, 5.922E-07, 5.815E-07, 5.711E-07, 5.610E-07, 5.511E-07, 5.414E-07, 5.320E-07, 5.228E-07, 5.138E-07, 5.051E-07, 4.965E-07,
1347  4.882E-07, 4.800E-07, 4.720E-07, 4.642E-07, 4.566E-07, 4.492E-07, 4.419E-07, 4.348E-07, 4.278E-07, 4.210E-07, 4.143E-07, 4.078E-07, 4.014E-07,
1348  3.952E-07, 3.891E-07, 3.831E-07, 3.773E-07, 3.716E-07, 3.660E-07, 3.605E-07, 3.551E-07, 3.498E-07, 3.447E-07, 3.396E-07, 3.347E-07, 3.298E-07,
1349  3.250E-07, 3.204E-07, 3.158E-07, 3.113E-07, 3.069E-07, 3.026E-07, 2.984E-07, 2.943E-07, 2.902E-07, 2.862E-07, 2.823E-07, 2.785E-07, 2.747E-07,
1350  2.710E-07, 2.674E-07, 2.638E-07, 2.603E-07, 2.569E-07, 2.535E-07, 2.502E-07, 2.470E-07, 2.438E-07, 2.406E-07, 2.376E-07, 2.345E-07, 2.316E-07,
1351  2.286E-07, 2.258E-07, 2.229E-07, 2.202E-07, 2.175E-07, 2.148E-07, 2.121E-07, 2.096E-07, 2.070E-07, 2.045E-07, 2.020E-07, 1.996E-07, 1.972E-07,
1352  1.949E-07, 1.926E-07, 1.903E-07, 1.881E-07, 1.859E-07, 1.838E-07, 1.816E-07, 1.796E-07, 1.775E-07, 1.755E-07, 1.735E-07, 1.715E-07, 1.696E-07,
1353  1.677E-07, 1.658E-07, 1.640E-07, 1.622E-07, 1.604E-07, 1.586E-07, 1.569E-07, 1.552E-07, 1.535E-07, 1.518E-07, 1.502E-07, 1.486E-07, 1.470E-07,
1354  1.455E-07, 1.439E-07, 1.424E-07, 1.409E-07, 1.394E-07, 1.380E-07 };
1355 
1356  vector<float> rautmannVineyardLate = { 2.884E-01, 7.310E-02, 3.007E-02, 1.557E-02, 9.226E-03, 5.977E-03, 4.124E-03, 2.983E-03, 2.237E-03, 1.728E-03,
1357  1.366E-03, 1.102E-03, 9.036E-04, 7.517E-04, 6.331E-04, 5.390E-04, 4.632E-04, 4.015E-04, 3.507E-04, 3.084E-04, 2.729E-04, 2.428E-04, 2.171E-04,
1358  1.951E-04, 1.760E-04, 1.595E-04, 1.450E-04, 1.323E-04, 1.211E-04, 1.111E-04, 1.023E-04, 9.443E-05, 8.736E-05, 8.101E-05, 7.528E-05, 7.010E-05,
1359  6.541E-05, 6.114E-05, 5.724E-05, 5.369E-05, 5.043E-05, 4.744E-05, 4.470E-05, 4.217E-05, 3.983E-05, 3.767E-05, 3.567E-05, 3.381E-05, 3.209E-05,
1360  3.049E-05, 2.899E-05, 2.760E-05, 2.629E-05, 2.507E-05, 2.393E-05, 2.286E-05, 2.186E-05, 2.091E-05, 2.002E-05, 1.919E-05, 1.840E-05, 1.765E-05,
1361  1.695E-05, 1.628E-05, 1.565E-05, 1.506E-05, 1.449E-05, 1.396E-05, 1.345E-05, 1.296E-05, 1.250E-05, 1.207E-05, 1.165E-05, 1.125E-05, 1.088E-05,
1362  1.052E-05, 1.017E-05, 9.842E-06, 9.528E-06, 9.228E-06, 8.940E-06, 8.665E-06, 8.402E-06, 8.150E-06, 7.908E-06, 7.676E-06, 7.453E-06, 7.239E-06,
1363  7.034E-06, 6.836E-06, 6.646E-06, 6.464E-06, 6.288E-06, 6.119E-06, 5.956E-06, 5.800E-06, 5.648E-06, 5.503E-06, 5.362E-06, 5.226E-06, 5.096E-06,
1364  4.969E-06, 4.847E-06, 4.729E-06, 4.615E-06, 4.505E-06, 4.398E-06, 4.295E-06, 4.196E-06, 4.099E-06, 4.006E-06, 3.915E-06, 3.827E-06, 3.742E-06,
1365  3.660E-06, 3.580E-06, 3.502E-06, 3.427E-06, 3.354E-06, 3.283E-06, 3.215E-06, 3.148E-06, 3.083E-06, 3.020E-06, 2.959E-06, 2.899E-06, 2.841E-06,
1366  2.785E-06, 2.730E-06, 2.677E-06, 2.625E-06, 2.575E-06, 2.526E-06, 2.478E-06, 2.431E-06, 2.386E-06, 2.342E-06, 2.299E-06, 2.257E-06, 2.216E-06,
1367  2.176E-06, 2.137E-06, 2.099E-06, 2.062E-06, 2.026E-06, 1.991E-06, 1.956E-06, 1.923E-06, 1.890E-06, 1.858E-06, 1.827E-06, 1.796E-06, 1.766E-06,
1368  1.737E-06, 1.709E-06, 1.681E-06, 1.654E-06, 1.627E-06, 1.601E-06, 1.576E-06, 1.551E-06, 1.527E-06, 1.503E-06, 1.480E-06, 1.457E-06, 1.434E-06,
1369  1.413E-06, 1.391E-06, 1.370E-06, 1.350E-06, 1.330E-06, 1.310E-06, 1.291E-06, 1.272E-06, 1.254E-06, 1.235E-06, 1.218E-06, 1.200E-06, 1.183E-06,
1370  1.167E-06, 1.150E-06, 1.134E-06, 1.118E-06, 1.103E-06, 1.088E-06, 1.073E-06, 1.058E-06, 1.044E-06, 1.030E-06, 1.016E-06, 1.003E-06, 9.893E-07,
1371  9.763E-07, 9.635E-07, 9.509E-07, 9.386E-07, 9.264E-07, 9.145E-07, 9.028E-07, 8.914E-07, 8.801E-07, 8.690E-07, 8.581E-07, 8.474E-07, 8.369E-07,
1372  8.265E-07, 8.164E-07, 8.064E-07, 7.966E-07, 7.869E-07, 7.774E-07, 7.681E-07, 7.589E-07, 7.499E-07, 7.410E-07, 7.323E-07, 7.237E-07, 7.152E-07,
1373  7.069E-07, 6.987E-07, 6.907E-07, 6.828E-07, 6.750E-07, 6.673E-07, 6.598E-07, 6.523E-07, 6.450E-07, 6.378E-07, 6.307E-07, 6.237E-07, 6.169E-07,
1374  6.101E-07, 6.034E-07, 5.969E-07, 5.904E-07, 5.840E-07, 5.777E-07, 5.716E-07, 5.655E-07, 5.595E-07, 5.536E-07, 5.477E-07, 5.420E-07, 5.363E-07,
1375  5.308E-07, 5.253E-07, 5.199E-07, 5.145E-07, 5.092E-07, 5.041E-07 };
1376 
1377  vector<float> dustDrift = { 3.583E-03, 3.455E-03, 3.331E-03, 3.212E-03, 3.096E-03, 2.986E-03, 2.879E-03, 2.775E-03, 2.676E-03, 2.580E-03, 2.488E-03,
1378  2.399E-03, 2.313E-03, 2.230E-03, 2.150E-03, 2.073E-03, 1.999E-03, 1.927E-03, 1.858E-03, 1.791E-03, 1.727E-03, 1.665E-03, 1.606E-03, 1.548E-03,
1379  1.493E-03, 1.439E-03, 1.388E-03, 1.338E-03, 1.290E-03, 1.244E-03, 1.199E-03, 1.156E-03, 1.115E-03, 1.075E-03, 1.036E-03, 9.993E-04, 9.635E-04,
1380  9.290E-04, 8.957E-04, 8.636E-04, 8.327E-04, 8.029E-04, 7.741E-04, 7.464E-04, 7.196E-04, 6.939E-04, 6.690E-04, 6.450E-04, 6.219E-04, 5.997E-04,
1381  5.782E-04, 5.575E-04, 5.375E-04, 5.182E-04, 4.997E-04, 4.818E-04, 4.645E-04, 4.479E-04, 4.318E-04, 4.164E-04, 4.014E-04, 3.871E-04, 3.732E-04,
1382  3.598E-04, 3.469E-04, 3.345E-04, 3.225E-04, 3.110E-04, 2.998E-04, 2.891E-04, 2.787E-04, 2.687E-04, 2.591E-04, 2.498E-04, 2.409E-04, 2.323E-04,
1383  2.239E-04, 2.159E-04, 2.082E-04, 2.007E-04, 1.935E-04, 1.866E-04, 1.799E-04, 1.735E-04, 1.673E-04, 1.613E-04, 1.555E-04, 1.499E-04, 1.445E-04,
1384  1.394E-04, 1.344E-04, 1.296E-04, 1.249E-04, 1.204E-04, 1.161E-04, 1.120E-04, 1.080E-04, 1.041E-04, 1.004E-04, 9.676E-05, 9.330E-05, 8.996E-05,
1385  8.673E-05, 8.363E-05, 8.063E-05, 7.774E-05, 7.496E-05, 7.227E-05, 6.968E-05, 6.719E-05, 6.478E-05, 6.246E-05, 6.022E-05, 5.806E-05, 5.598E-05,
1386  5.398E-05, 5.204E-05, 5.018E-05, 4.838E-05, 4.665E-05, 4.498E-05, 4.337E-05, 4.181E-05, 4.032E-05, 3.887E-05, 3.748E-05, 3.614E-05, 3.484E-05,
1387  3.359E-05, 3.239E-05, 3.123E-05, 3.011E-05, 2.903E-05, 2.799E-05, 2.699E-05, 2.602E-05, 2.509E-05, 2.419E-05, 2.332E-05, 2.249E-05, 2.168E-05,
1388  2.091E-05, 2.016E-05, 1.944E-05, 1.874E-05, 1.807E-05, 1.742E-05, 1.680E-05, 1.619E-05, 1.561E-05, 1.506E-05, 1.452E-05, 1.400E-05, 1.349E-05,
1389  1.301E-05, 1.254E-05, 1.210E-05, 1.166E-05, 1.124E-05, 1.084E-05, 1.045E-05, 1.008E-05, 9.718E-06, 9.370E-06, 9.034E-06, 8.710E-06, 8.398E-06,
1390  8.097E-06, 7.807E-06, 7.528E-06, 7.258E-06, 6.998E-06, 6.747E-06, 6.506E-06, 6.272E-06, 6.048E-06, 5.831E-06, 5.622E-06, 5.421E-06, 5.227E-06,
1391  5.039E-06, 4.859E-06, 4.685E-06, 4.517E-06, 4.355E-06, 4.199E-06, 4.049E-06, 3.904E-06, 3.764E-06, 3.629E-06, 3.499E-06, 3.374E-06, 3.253E-06,
1392  3.136E-06, 3.024E-06, 2.916E-06, 2.811E-06, 2.710E-06, 2.613E-06, 2.520E-06, 2.429E-06, 2.342E-06, 2.258E-06, 2.178E-06, 2.100E-06, 2.024E-06,
1393  1.952E-06, 1.882E-06, 1.814E-06, 1.749E-06, 1.687E-06, 1.626E-06, 1.568E-06, 1.512E-06, 1.458E-06, 1.406E-06, 1.355E-06, 1.307E-06, 1.260E-06,
1394  1.215E-06, 1.171E-06, 1.129E-06, 1.089E-06, 1.050E-06, 1.012E-06, 9.759E-07, 9.410E-07, 9.072E-07, 8.747E-07, 8.434E-07, 8.132E-07, 7.841E-07,
1395  7.560E-07, 7.289E-07, 7.028E-07, 6.776E-07, 6.533E-07, 6.299E-07, 6.074E-07, 5.856E-07, 5.646E-07, 5.444E-07, 5.249E-07, 5.061E-07, 4.880E-07,
1396  4.705E-07, 4.536E-07, 4.374E-07, 4.217E-07, 4.066E-07 };
1397 
1398  vector<float> driftVector;
1399  for (int m = 0; m < 6; m++) {
1400  if (m == 0) driftVector = rautmannField;
1401  else if (m == 1) driftVector = rautmannOrchardEarly;
1402  else if (m == 2) driftVector = rautmannOrchardLate;
1403  else if (m == 3) driftVector = rautmannVineyardEarly;
1404  else if (m == 4) driftVector = rautmannVineyardLate;
1405  else if (m == 5) driftVector = dustDrift;
1406 
1407  vector<float> l_diffusion_vector;
1408  m_drift_distance = driftVector.size();
1409  l_diffusion_vector.push_back(0);
1410  float sum = 0;
1411  for (int i = 1; i <= m_drift_distance; i++)
1412  {
1413  l_diffusion_vector.push_back(driftVector[i - 1]);
1414  sum += driftVector[i - 1];
1415  }
1416  if (m == 5) {
1417  l_diffusion_vector[0] = l_diffusion_vector[1]; // Assuming same dust drift at 0 meter as at 1 meter
1418  sum += l_diffusion_vector[0];
1419  m_dust_drift_remainder = 1 - sum;
1420  }
1421  else
1422  {
1423  l_diffusion_vector[0] = 1 - sum;
1424  }
1425  // Find biggest x and y length of field
1426  int max_dist = 0;
1427 
1428  for (int i = 0; i < g_landscape_ptr->SupplyMaxPoly(); i++) {
1429  if ((g_landscape_ptr->SupplyElementTypeFromVector(i) == tole_Field && (m==0 || m == 5)) ||
1430  (g_landscape_ptr->SupplyElementTypeFromVector(i) == tole_Orchard && (m == 1 || m == 2)) ||
1431  (g_landscape_ptr->SupplyElementTypeFromVector(i) == tole_Vineyard && (m == 3 || m == 4))) {
1434  if (temp_dist_x > max_dist) max_dist = temp_dist_x;
1435  if (temp_dist_y > max_dist) max_dist = temp_dist_y;
1436  }
1437  }
1438  // West / South
1439  Eigen::MatrixXf west_matrix(max_dist + l_diffusion_vector.size(), max_dist + l_diffusion_vector.size());
1440  west_matrix.setZero();
1441  for (int row = 0; row < max_dist + l_diffusion_vector.size(); row++) {
1442  for (int col = 0; col < l_diffusion_vector.size(); col++) {
1443  if (col + row < max_dist + l_diffusion_vector.size())
1444  west_matrix(row, col + row) = l_diffusion_vector[col];
1445  }
1446  }
1447  // East / North
1448  Eigen::MatrixXf east_matrix = west_matrix.transpose();
1449 
1450  if (m==0)
1451  {
1452  m_diffusion_matrices.push_back(west_matrix);
1453  m_diffusion_matrices.push_back(east_matrix);
1454  }
1455  else if (m==1)
1456  {
1457  m_diffusion_matrices_orchard_early.push_back(west_matrix);
1458  m_diffusion_matrices_orchard_early.push_back(east_matrix);
1459  }
1460  else if (m==2)
1461  {
1462  m_diffusion_matrices_orchard_late.push_back(west_matrix);
1463  m_diffusion_matrices_orchard_late.push_back(east_matrix);
1464  }
1465  else if (m==3)
1466  {
1467  m_diffusion_matrices_vineyard_early.push_back(west_matrix);
1468  m_diffusion_matrices_vineyard_early.push_back(east_matrix);
1469  }
1470  else if (m == 4)
1471  {
1472  m_diffusion_matrices_vineyard_late.push_back(west_matrix);
1473  m_diffusion_matrices_vineyard_late.push_back(east_matrix);
1474  }
1475  else if (m == 5)
1476  {
1477  m_diffusion_matrices_dust_drift.push_back(west_matrix);
1478  m_diffusion_matrices_dust_drift.push_back(east_matrix);
1479  }
1480  }
1481  /*
1482  // Temp test
1483  std::ofstream file("temp_matrix.txt");
1484  file << "West/South:" << endl;
1485  file << west_matrix;
1486  file << std::endl;
1487  file << "East/North:" << endl;
1488  file << east_matrix;
1489  file.close();
1490  */
1491 }

References g_landscape_ptr, LE::GetMaxX(), LE::GetMaxY(), LE::GetMinX(), LE::GetMinY(), m_diffusion_matrices, m_diffusion_matrices_dust_drift, m_diffusion_matrices_orchard_early, m_diffusion_matrices_orchard_late, m_diffusion_matrices_vineyard_early, m_diffusion_matrices_vineyard_late, m_drift_distance, m_dust_drift_remainder, Landscape::SupplyElementTypeFromVector(), Landscape::SupplyMaxPoly(), Landscape::SupplyPolyLEptr(), tole_Field, tole_Orchard, and tole_Vineyard.

Referenced by Pesticide().

◆ DiffusionSprayPixel()

void Pesticide::DiffusionSprayPixel ( int  a_x,
int  a_limit_x,
int  a_y,
int  a_limit_y,
double  a_amount,
double  a_cover,
PlantProtectionProducts  a_ppp 
)
inlineprotected

Adds the diffused pesticide to the cell in the main map(s)

This sprays the pesticide (a_amount) by placing this into a pesticide cell in the main map. If more detailed pesticide fate is needed then a_amount will be partitioned between soil and canopy.
First a test is made to ensure that the coordinates given are within the landscape. If not the pesticide is sprayed off world, and lost.
Partioning, if occuring, is done based on two components - the canopy and the soil. The pesticide is partioned between the two based on the asssumed vegetation cover of the crop based on Beer's Law.

774 {
782  // First we have to do the typical out of bounds checks - if these fail do nothing, the pesticide fell off the world
783  if (a_x < 0 || a_x >= a_limit_x || a_y < 0 || a_y >= a_limit_y) return;
784  // Now calculate the coordinate entry in the array and store this as l_coord
785  int l_coord = a_y * a_limit_x + a_x;
786 #ifdef __DETAILED_PESTICIDE_FATE
787  // Here we need to calculate the partition of pesticide into two compartments.
788  m_pest_map_vegcanopy[a_ppp](a_y, a_x) += a_amount * a_cover;
789  m_pest_map_soil[a_ppp](a_y, a_x) += a_amount * (1-a_cover);
790 #else
791  m_pest_map_main[a_ppp](a_y,a_x) += a_amount;
792 #endif
793  if (l_pest_record_used.value()) {
794  m_pest_map_record[a_ppp][l_coord] += a_amount;
795  }
796 }

References l_pest_record_used, m_pest_map_main, m_pest_map_record, and CfgBool::value().

Referenced by TwinMapDiffusion().

◆ DiffusionVectorInit()

void Pesticide::DiffusionVectorInit ( void  )
protected

Initializes the diffusion vector that is used to drift the pesticide.

The diffusion vector depends on the type of nozzle and the driving speed (7.2 or 14.4 km/h) The diffusion vectors are derived from the results in "Single Nozzle spray drift measurements of drift reducing nozzles at two forward speed" by H Stallinga et al. The results are found in table form in the Dutch report names "Enkeldops validatiemetingen driftreducerende spuitdoppen en rijsnelheid". The first entry is 1 meter up wind, the second is at the spraying point and the rest are from 1 to 10 meter downwind.

1201 {
1209  if (l_pest_driving_slow.value()){
1210  // Drift vectors when speed is 7.2 km/h
1211  vector<vector<double>> diffusion_7 = {
1212  // Reference nozzles
1213  {0.0946500, 0.5908325, 0.0995116, 0.0136143, 0.0051604, 0.0025927, 0.0015202, 0.0009828, 0.0006796, 0.0004938, 0.0003725, 0.0002895}, // BCPC-F/M
1214  {0.0432200, 0.7634369, 0.0828425, 0.0137543, 0.0047395, 0.0022256, 0.0012382, 0.0007669, 0.0005115, 0.0003601, 0.0002643, 0.0002004}, // XR11004
1215  // 50% drift reduction
1216  {0.0572400, 0.7475241, 0.0664164, 0.0084972, 0.0027859, 0.0012628, 0.0006836, 0.0004140, 0.0002710, 0.0001877, 0.0001357, 0.0001016}, // DG11004
1217  {0.0396900, 0.7551131, 0.0950668, 0.0158802, 0.0061956, 0.0031773, 0.0018927, 0.0012396, 0.0008667, 0.0006357, 0.0004836, 0.0003787}, // XR11006
1218  {0.0141300, 0.8947145, 0.0537316, 0.0055267, 0.0017660, 0.0007860, 0.0004195, 0.0002512, 0.0001628, 0.0001118, 0.0000803, 0.0000597}, // LD11004
1219  {0.0107300, 0.9218496, 0.0381427, 0.0045720, 0.0014580, 0.0006998, 0.0003960, 0.0002487, 0.0001678, 0.0001194, 0.0000884, 0.0000676}, // AM11003
1220  {0.0263500, 0.8585409, 0.0528231, 0.0054158, 0.0018954, 0.0008999, 0.0005050, 0.0003149, 0.0002113, 0.0001495, 0.0001102, 0.0000839}, // MD D-11003
1221  {0.0803500, 0.7176895, 0.0392098, 0.0012929, 0.0003698, 0.0001638, 0.0000871, 0.0000520, 0.0000336, 0.0000230, 0.0000165, 0.0000122}, // TTI11004 3bar
1222  // 75% drift reduction
1223  {0.0101000, 0.9444316, 0.0208394, 0.0024289, 0.0007198, 0.0004138, 0.0002693, 0.0001896, 0.0001409, 0.0001090, 0.0000869, 0.0000709}, // ID12002
1224  {0.0131100, 0.9334853, 0.0251643, 0.0012600, 0.0003823, 0.0001640, 0.0000851, 0.0000498, 0.0000316, 0.0000214, 0.0000151, 0.0000111}, // IDN12003
1225  {0.0155400, 0.9168038, 0.0327689, 0.0022153, 0.0007452, 0.0003440, 0.0001889, 0.0001157, 0.0000765, 0.0000534, 0.0000389, 0.0000293}, // AVITwin11003
1226  {0.0045800, 0.9618518, 0.0213008, 0.0017977, 0.0006095, 0.0002829, 0.0001560, 0.0000959, 0.0000636, 0.0000445, 0.0000325, 0.0000246}, // TD Hispeed11002
1227  // 90% drift reduction
1228  {0.0616300, 0.7710808, 0.0388870, 0.0027857, 0.0010078, 0.0005054, 0.0002959, 0.0001911, 0.0001320, 0.0000958, 0.0000722, 0.0000561}, // XLTD11004
1229  {0.0017200, 0.9840101, 0.0087083, 0.0012300, 0.0003162, 0.0001837, 0.0001205, 0.0000854, 0.0000638, 0.0000496, 0.0000397, 0.0000326}, // AIXR11004
1230  {0.0018700, 0.9884460, 0.0051915, 0.0004368, 0.0001474, 0.0000682, 0.0000375, 0.0000230, 0.0000152, 0.0000107, 0.0000078, 0.0000059}, // MD D-11004
1231  {0.0059100, 0.9310884, 0.0435343, 0.0048984, 0.0012437, 0.0005930, 0.0003339, 0.0002088, 0.0001404, 0.0000996, 0.0000735, 0.0000561}, // TD Hispeed11004
1232  // 95% drift reduction
1233  {0.0020100, 0.9818440, 0.0099543, 0.0012092, 0.0004312, 0.0002075, 0.0001177, 0.0000740, 0.0000500, 0.0000356, 0.0000264, 0.0000202}, // AM11005
1234  {0.0490100, 0.8299659, 0.0214655, 0.0008437, 0.0002644, 0.0001458, 0.0000919, 0.0000630, 0.0000458, 0.0000347, 0.0000272, 0.0000219} // TTI11004 1bar
1235  };
1236  m_diffusion_vector = diffusion_7[l_pest_nozzle_type.value()];
1237  }
1238  else {
1239  // Drift vectors when speed is 14.4 km/h
1240  vector<vector<double>> diffusion_14 = {
1241  // Reference nozzles
1242  {0.0837400, 0.6167160, 0.1010477, 0.0171194, 0.0061729, 0.0029935, 0.0017075, 0.0010794, 0.0007324, 0.0005234, 0.0003892, 0.0002986}, // BCPC-FM
1243  {0.0408400, 0.7450414, 0.0974050, 0.0187157, 0.0070222, 0.0035028, 0.0020423, 0.0013143, 0.0009054, 0.0006556, 0.0004931, 0.0003822}, // XR11004
1244  // 50% drift reduction
1245  {0.0607900, 0.7152813, 0.0819283, 0.0112292, 0.0040678, 0.0019791, 0.0011318, 0.0007169, 0.0004873, 0.0003488, 0.0002597, 0.0001995}, // DG11004
1246  {0.0360900, 0.7650499, 0.0937292, 0.0164280, 0.0066606, 0.0035102, 0.0021358, 0.0014232, 0.0010097, 0.0007500, 0.0005770, 0.0004564}, // XR11006
1247  {0.0112200, 0.8719614, 0.0758447, 0.0113258, 0.0035478, 0.0015570, 0.0008220, 0.0004877, 0.0003137, 0.0002140, 0.0001528, 0.0001130}, // LD11004
1248  {0.0141100, 0.9081141, 0.0382995, 0.0056791, 0.0023806, 0.0011959, 0.0007011, 0.0004532, 0.0003134, 0.0002277, 0.0001718, 0.0001335}, // AM11003
1249  {0.0266600, 0.8392638, 0.0684921, 0.0063971, 0.0024678, 0.0012555, 0.0007433, 0.0004843, 0.0003372, 0.0002464, 0.0001868, 0.0001459}, // MD D-11003
1250  {0.1146700, 0.6103928, 0.0438362, 0.0011629, 0.0003007, 0.0001290, 0.0000669, 0.0000392, 0.0000249, 0.0000168, 0.0000119, 0.0000087}, // TTI11004 3bar
1251  // 75% drift reduction
1252  {0.0043800, 0.9595753, 0.0225982, 0.0025739, 0.0008852, 0.0004518, 0.0002682, 0.0001751, 0.0001221, 0.0000894, 0.0000679, 0.0000530}, // ID12002
1253  {0.0115400, 0.9399671, 0.0233666, 0.0012008, 0.0003992, 0.0001827, 0.0000997, 0.0000607, 0.0000400, 0.0000278, 0.0000202, 0.0000152}, // IDN12003
1254  {0.0160200, 0.9129386, 0.0329166, 0.0036015, 0.0011827, 0.0005368, 0.0002908, 0.0001763, 0.0001154, 0.0000800, 0.0000579, 0.0000433}, // AVITwin11003
1255  {0.0015400, 0.9526325, 0.0357322, 0.0038604, 0.0013972, 0.0006794, 0.0003884, 0.0002459, 0.0001671, 0.0001196, 0.0000890, 0.0000683}, // TD Hispeed11002
1256  // 90% drift reduction
1257  {0.0682000, 0.7551538, 0.0361000, 0.0022640, 0.0007920, 0.0004028, 0.0002384, 0.0001553, 0.0001081, 0.0000790, 0.0000599, 0.0000467}, // XLTD11004
1258  {0.0021400, 0.9782461, 0.0121061, 0.0017100, 0.0005657, 0.0003169, 0.0002022, 0.0001400, 0.0001027, 0.0000785, 0.0000619, 0.0000501}, // AIXR11004
1259  {0.0026100, 0.9855037, 0.0056548, 0.0005154, 0.0002041, 0.0001058, 0.0000635, 0.0000419, 0.0000295, 0.0000217, 0.0000166, 0.0000130}, // MD D-11004
1260  {0.0074100, 0.9133355, 0.0553420, 0.0043700, 0.0017993, 0.0009913, 0.0006243, 0.0004279, 0.0003109, 0.0002358, 0.0001847, 0.0001485}, // TD Hispeed11004
1261  // 95% drift reduction
1262  {0.0019400, 0.9767227, 0.0140734, 0.0017640, 0.0006810, 0.0003466, 0.0002053, 0.0001338, 0.0000932, 0.0000681, 0.0000517, 0.0000403}, // AM11005
1263  {0.0581600, 0.7849858, 0.0376759, 0.0015704, 0.0005404, 0.0002755, 0.0001634, 0.0001066, 0.0000743, 0.0000543, 0.0000412, 0.0000322} // TTI11004 1bar
1264  };
1265  m_diffusion_vector = diffusion_14[l_pest_nozzle_type.value()];
1266  }
1267 }

References l_pest_driving_slow, l_pest_nozzle_type, m_diffusion_vector, CfgInt::value(), and CfgBool::value().

Referenced by Pesticide().

◆ DiffusionVectorTest()

void Pesticide::DiffusionVectorTest ( void  )

For saving diffusion vector in file.

For debugging purposes. Allows us to see the diffusion used for the point source in each cell.

1654  {
1658  int l_grid = m_pest_drift_max;
1659  ofstream ofile("diffusion.txt", ios::out);
1660 
1661  for (int x = 0; x <= l_grid; x++) {
1662  ofile << m_diffusion_vector[x] << '\t';
1663  }
1664  ofile << endl;
1665  ofile.close();
1666 }

References m_diffusion_vector, and m_pest_drift_max.

Referenced by Pesticide().

◆ ElementIsWater()

bool Pesticide::ElementIsWater ( int  a_x,
int  a_y 
)
inlineprotected

Checks if cell has a water type.

437 {
438  TTypesOfLandscapeElement l_eletype = m_map->SupplyElementType( a_x, a_y );
439 
440  if (l_eletype == tole_Freshwater ||
441  l_eletype == tole_River ||
442  l_eletype == tole_Pond ||
443  l_eletype == tole_FishFarm ||
444  l_eletype == tole_Saltwater
445  )
446  return true;
447 
448  return false;
449 }

References m_map, Landscape::SupplyElementType(), tole_FishFarm, tole_Freshwater, tole_Pond, tole_River, and tole_Saltwater.

Referenced by SupplyPesticide().

◆ GetAnythingToDecay()

bool Pesticide::GetAnythingToDecay ( PlantProtectionProducts  a_ppp)
inline

Checks if there are any pesticides to decay.

356 { return (m_something_to_decay[a_ppp]); }

References m_something_to_decay.

Referenced by Landscape::SupplyPesticideDecay().

◆ MainMapDecay()

void Pesticide::MainMapDecay ( PlantProtectionProducts  a_ppp)
protected

Applies rain washoff and decays the pesticides in all maps by calling Pesticide::DecayMap.

This is where the environmental decay takes place. Here we assume a first order decay based on a daily proportion of the cell total. If using detailed fate modelling first the rain wash-off is calculated, transfering some of the pesticide from the plant surface to the soil. The decay of each map is done by calling the DecayMap method.

450 {
457  if (!m_something_to_decay[a_ppp]) return;
458  double l_zero = l_pest_zero_threshold.value();
459  //m_something_to_decay[a_ppp] = false;
460  Eigen::ArrayXXi* temp_polyid_map = g_landscape_ptr->SupplyPolyIdMapPtr();
461 
462 #ifdef __DETAILED_PESTICIDE_FATE
463 
464  int temp_minx = 0;
465  int temp_maxx = 0;
466  int temp_miny = 0;
467  int temp_maxy = 0;
468  if (l_pest_enable_rain_washoff.value()) m_pest_map_vegcanopy_washoff[a_ppp].setZero();
469  for (int i=0; i<g_landscape_ptr->SupplyMaxPoly(); i++){
470  temp_minx = g_landscape_ptr->SupplyPolyLEptr(i)->GetMinX();
471  temp_maxx = g_landscape_ptr->SupplyPolyLEptr(i)->GetMaxX();
472  temp_miny = g_landscape_ptr->SupplyPolyLEptr(i)->GetMinY();
473  temp_maxy = g_landscape_ptr->SupplyPolyLEptr(i)->GetMaxY();
474  if (g_landscape_ptr->SupplyPesticide(i, a_ppp) < l_zero) {
475  if (g_landscape_ptr->SupplyPesticide(i, a_ppp) == 0) continue;
476  // Need to set pesticide to zero because it is under threshold, but not 0
477 #ifdef __FLOWER_PESTICIDE
478  m_pest_map_in_vegetation[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) = ((*temp_polyid_map)(Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) == i).select(0, m_pest_map_in_vegetation[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)));
479  m_pest_map_pollen[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) = ((*temp_polyid_map)(Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) == i).select(0, m_pest_map_pollen[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)));
480  m_pest_map_nectar[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) = ((*temp_polyid_map)(Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) == i).select(0, m_pest_map_nectar[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)));
481 #endif
482  m_pest_map_vegcanopy[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) = ((*temp_polyid_map)(Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) == i).select(0, m_pest_map_vegcanopy[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)));
483  m_pest_map_soil[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) = ((*temp_polyid_map)(Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) == i).select(0, m_pest_map_soil[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)));
484  continue;
485  }
486  // Calculate rain wash-off
487  if (l_pest_enable_rain_washoff.value()) {
488  double cover = g_landscape_ptr->SupplyVegCover(i);
489  unsigned cov = 100 * cover; // cov is steps of zero to 99
490  if (cov == 100) {
491  std::cout << "Warning: Cover is 100% so it is set to 99% to be within bounds" << std::endl;
492  cov = 99;
493  }
494  m_pest_map_vegcanopy_washoff[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) = ((*temp_polyid_map)(Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) == i).select(m_pest_map_vegcanopy[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) * m_RainWashoffFactor[a_ppp][m_rainfallcategory + cov], m_pest_map_vegcanopy_washoff[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)));
495  }
496 #ifdef __FLOWER_PESTICIDE
497  // Check whether dead biomass is increasing (plant dying)
498  double dead_biomass_today = g_landscape_ptr->SupplyPolyLEptr(i)->GetDeadBiomass();
499  double diff_dead = dead_biomass_today - m_dead_biomass[i];
500  double green_biomass_today = g_landscape_ptr->SupplyPolyLEptr(i)->GetGreenBiomass();
501  double diff_green = green_biomass_today - m_green_biomass[i];
502  if (diff_dead > 0 && diff_green < 0) { // Make sure that dead biomass is increasing and green biomass is decreasing (plant is dying and is not cut or similar)
503  double frac = 1 + diff_green / m_green_biomass[i];
504  // Decrease in plant pesticide by fraction of dead biomass
505  m_pest_map_in_vegetation[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) = ((*temp_polyid_map)(Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) == i).select(m_pest_map_in_vegetation[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) * frac, m_pest_map_in_vegetation[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)));
506  }
507  // Update dead and green biomass for tomorrow's calculation
508  m_dead_biomass[i] = dead_biomass_today;
509  m_green_biomass[i] = green_biomass_today;
510 
511  // Check if pollen and nectar quantity has decrease since yesterday (if yes then remove same proportion from maps)
512  double pollen_today = m_map->SupplyPollenQuantity(i);
513  double diff_pollen = pollen_today - m_pollen_mass[i];
514  if (diff_pollen < 0) {
515  double frac = 1 + diff_pollen / m_pollen_mass[i];
516  m_pest_map_pollen[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) = ((*temp_polyid_map)(Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) == i).select(m_pest_map_pollen[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) * frac, m_pest_map_pollen[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)));
517  }
518  double nectar_today = m_map->SupplyNectarQuantity(i);
519  double diff_nectar = nectar_today - m_nectar_mass[i];
520  if (diff_nectar < 0) {
521  double frac = 1 + diff_nectar / m_nectar_mass[i];
522  m_pest_map_nectar[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) = ((*temp_polyid_map)(Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) == i).select(m_pest_map_nectar[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)) * frac, m_pest_map_nectar[a_ppp](Eigen::seq(temp_miny, temp_maxy), Eigen::seq(temp_minx, temp_maxx)));
523  }
524  // Update pollen and nectar mass for tomorrow's calculation
525  m_pollen_mass[i] = pollen_today;
526  m_nectar_mass[i] = nectar_today;
527 #endif
528  }
529  if (l_pest_enable_rain_washoff.value()) {
530  m_pest_map_vegcanopy[a_ppp] -= m_pest_map_vegcanopy_washoff[a_ppp];
531  m_pest_map_soil[a_ppp] += m_pest_map_vegcanopy_washoff[a_ppp];
532  }
533  // Decay the pesticide on plant surface and in soil
534  DecayMap(m_pest_map_vegcanopy, m_pest_daily_decay_frac_vegcanopy, a_ppp);
535  DecayMap(m_pest_map_soil, m_pest_daily_decay_frac_soil, a_ppp);
536 #ifdef __FLOWER_PESTICIDE
537  // Decay the pesticide in plant
538  DecayMap(m_pest_map_in_vegetation, m_pest_daily_decay_frac_in_vegetation, a_ppp);
539  DecayMap(m_pest_map_pollen, m_pest_daily_decay_frac_pollen, a_ppp);
540  DecayMap(m_pest_map_nectar, m_pest_daily_decay_frac_nectar, a_ppp);
541 #endif
542 #else
543  // Decay pesticide
545 #endif
546 
547 }

References DecayMap(), g_landscape_ptr, LE::GetDeadBiomass(), LE::GetGreenBiomass(), LE::GetMaxX(), LE::GetMaxY(), LE::GetMinX(), LE::GetMinY(), l_pest_zero_threshold, m_dead_biomass, m_green_biomass, m_map, m_nectar_mass, m_pest_daily_decay_frac, m_pest_map_main, m_pollen_mass, m_rainfallcategory, m_RainWashoffFactor, m_something_to_decay, Landscape::SupplyMaxPoly(), Landscape::SupplyNectarQuantity(), Landscape::SupplyPesticide(), Landscape::SupplyPollenQuantity(), Landscape::SupplyPolyIdMapPtr(), Landscape::SupplyPolyLEptr(), Landscape::SupplyVegCover(), and CfgFloat::value().

Referenced by Tick().

◆ RecordAllPesticideCompartments()

void Pesticide::RecordAllPesticideCompartments ( int  a_x,
int  a_y,
PlantProtectionProducts  a_ppp,
ofstream &  outfile 
)

Records the current pesticide in all compartments + biomass.

Print out pesticide in all compartments and biomass

1587 {
1591  int l_x = a_x >> PEST_GRIDSIZE_POW2;
1592  int l_y = a_y >> PEST_GRIDSIZE_POW2;
1593  double l_bio = m_map->SupplyVegBiomass(l_x, l_y) * 0.001; // in kg
1594  double l_bio_green = m_map->SupplyGreenBiomass(l_x, l_y) * 0.001; // in kg
1595  double l_bio_dead = m_map->SupplyDeadBiomass(l_x, l_y) * 0.001; // in kg
1596  double l_bio_height = m_map->SupplyVegHeight(l_x, l_y); // in cm
1597 #ifdef __DETAILED_PESTICIDE_FATE
1598  double l_pest_vegcanopy = m_pest_map_vegcanopy[a_ppp](l_y, l_x) * 1000; // in mg
1599  double l_pest_soil = m_pest_map_soil[a_ppp](l_y, l_x) * 1000; // in mg
1600 #ifdef __FLOWER_PESTICIDE
1601  double l_pest_pollen = m_pest_map_pollen[a_ppp](l_y, l_x) * 1000; // in mg
1602  double l_pest_nectar = m_pest_map_nectar[a_ppp](l_y, l_x) * 1000; // in mg
1603  double l_pest_in_plant = m_pest_map_in_vegetation[a_ppp](l_y, l_x) * 1000; // in mg
1604  double l_mass_nectar = m_map->SupplyNectarQuantity(l_x, l_y); // in mg
1605  double l_mass_pollen = m_map->SupplyPollenQuantity(l_x, l_y); // in mg
1606  double l_conc_nectar = 0;
1607  double l_conc_pollen = 0;
1608  double l_DD = m_map->SupplyPolyLEptr(l_x, l_y)->GetVegDDegs();
1609  double l_overspray = SupplyPesticideOverspray(a_x, a_y, a_ppp) * 1000; // in mg
1610 
1611  if (l_mass_nectar > 0) l_conc_nectar = SupplyPesticideNectar(l_x, l_y, a_ppp) / l_mass_nectar * 1000000000; // in ppm
1612  if (l_mass_pollen > 0) l_conc_pollen = SupplyPesticidePollen(l_x, l_y, a_ppp) / l_mass_pollen * 1000000000; // in ppm
1613 #endif
1614 #else
1615  double l_pest_total = m_pest_map_main[a_ppp](l_y, l_x) * 1000; // in mg
1616 #endif
1617 
1618  outfile << g_date->Date() - 365 << '\t';
1619  outfile << l_bio << '\t';
1620  outfile << l_bio_green << '\t';
1621  outfile << l_bio_dead << '\t';
1622  outfile << l_bio_height << '\t';
1623  outfile << a_ppp << '\t';
1624 #ifdef __DETAILED_PESTICIDE_FATE
1625  outfile << l_pest_vegcanopy << '\t';
1626 #ifdef __FLOWER_PESTICIDE
1627  outfile << l_pest_pollen << '\t';
1628  outfile << l_pest_nectar << '\t';
1629  outfile << l_pest_soil << '\t';
1630  outfile << l_pest_in_plant << '\t';
1631  if (l_pest_enable_seed_coating.value()) {
1632  double l_pest_seed = m_pest_map_seed[a_ppp](l_y, l_x) * 1000; // in mg
1633  outfile << l_pest_seed << '\t';
1634  }
1635  else {
1636  outfile << 0 << '\t';
1637  }
1638  outfile << l_conc_pollen << '\t';
1639  outfile << l_conc_nectar << '\t';
1640  outfile << l_mass_pollen << '\t';
1641  outfile << l_mass_nectar << '\t';
1642  outfile << l_DD << '\t';
1643  outfile << l_overspray;
1644 #else
1645  outfile << l_pest_soil;
1646 #endif
1647 #else
1648  outfile << l_pest_total;
1649 #endif
1650  outfile << endl;
1651 }

References Calendar::Date(), g_date, LE::GetVegDDegs(), m_map, m_pest_map_main, PEST_GRIDSIZE_POW2, Landscape::SupplyDeadBiomass(), Landscape::SupplyGreenBiomass(), Landscape::SupplyNectarQuantity(), Landscape::SupplyPollenQuantity(), Landscape::SupplyPolyLEptr(), Landscape::SupplyVegBiomass(), and Landscape::SupplyVegHeight().

Referenced by Tick().

◆ RecordPesticideConcentrationPollenNectar()

void Pesticide::RecordPesticideConcentrationPollenNectar ( int  a_x,
int  a_y,
PlantProtectionProducts  a_ppp,
ofstream &  outfile 
)

Records the current pesticide concentration in pollen and nectar.

Referenced by Tick().

◆ RecordPesticideLoad()

bool Pesticide::RecordPesticideLoad ( int  a_ppp)

Records the pesticide load at landscape level.

The challenge here is that we do not know in advance the size of the pesticide grid, so this needs to be included in the translation of the pesticide grid to the output grid. This is done here rather than when m_pest_map_record is filled since this needs to be done only once here, rather than every time a pesticide amount is applied. To get to the pesticide grid the formula is (PEST_GRID_SIZE * grid ref) = ALMaSS Coord. ALMaSS Coord/Grid Size = index.

1495 {
1503  int recordgridsz = l_pest_record_grid_size.value();
1504  int no_grids = (m_land->MapWidth() / recordgridsz) * (m_land->MapHeight() / recordgridsz);
1505  int grids_x = m_land->MapWidth() / recordgridsz;
1506  vector<double> pestrecoutput(no_grids);
1507  for (int i = 0; i < no_grids; i++) pestrecoutput[i] = 0.0;
1508  for (unsigned int j = 0; j < m_pest_map_height; j++)
1509  for (unsigned int i = 0; i < m_pest_map_width; i++)
1510  {
1511  int x = (i * PEST_GRIDSIZE) / recordgridsz;
1512  int y = (j * PEST_GRIDSIZE) / recordgridsz;
1513  int index = i + m_pest_map_width * j;
1514  pestrecoutput[x+y*grids_x] += m_pest_map_record[a_ppp][index];
1515  }
1516  m_pesticideRecord << "ppp" << a_ppp << '\t';
1517  m_pesticideRecord << g_date->Date() - 365 << '\t';
1518  for (int i = 0; i < no_grids; i++)
1519  {
1520  m_pesticideRecord << pestrecoutput[i] << '\t';
1521  }
1522  m_pesticideRecord << endl;
1523  for (int i = 0; i < m_pest_map_record[a_ppp].size(); i++) m_pest_map_record[a_ppp][i] = 0.0;
1524  return true;
1525 }

References Calendar::Date(), g_date, l_pest_record_grid_size, m_land, m_pest_map_height, m_pest_map_record, m_pest_map_width, m_pesticideRecord, RasterMap::MapHeight(), RasterMap::MapWidth(), PEST_GRIDSIZE, and CfgInt::value().

Referenced by Tick().

◆ RecordPesticideMap()

bool Pesticide::RecordPesticideMap ( int  a_ppp,
ofstream &  outfile,
vector< Eigen::MatrixXf > &  map 
)

Records the current pesticide amount in map.

Saves the pesticide amount together with the type of pesticide and the date. This is a very heavy operation if it is called every day.

1529 {
1533  int recordgridsz = l_pest_record_grid_size.value();
1534  int no_grids = (m_land->MapWidth() / recordgridsz) * (m_land->MapHeight() / recordgridsz);
1535  int grids_x = m_land->MapWidth() / recordgridsz;
1536  vector<double> pestrecoutput(no_grids);
1537  for (int i = 0; i < no_grids; i++) pestrecoutput[i] = 0.0;
1538  for (unsigned int j = 0; j < m_pest_map_height; j++) {
1539  for (unsigned int i = 0; i < m_pest_map_width; i++) {
1540  int x = (i * PEST_GRIDSIZE) / recordgridsz;
1541  int y = (j * PEST_GRIDSIZE) / recordgridsz;
1542  pestrecoutput[x + y * grids_x] += map[a_ppp](j,i);
1543  }
1544  }
1545  outfile << "ppp" << a_ppp << '\t';
1546  outfile << g_date->Date() - 365 << '\t';
1547  for (int i = 0; i < no_grids; i++) {
1548  outfile << pestrecoutput[i] << '\t';
1549  }
1550  outfile << endl;
1551 
1552  return true;
1553 }

References Calendar::Date(), g_date, l_pest_record_grid_size, m_land, m_pest_map_height, m_pest_map_width, RasterMap::MapHeight(), RasterMap::MapWidth(), PEST_GRIDSIZE, and CfgInt::value().

Referenced by Tick().

◆ ReducePlantPesticide()

void Pesticide::ReducePlantPesticide ( int  a_minx,
int  a_maxx,
int  a_miny,
int  a_maxy,
int  a_map_index,
float  a_reduc,
bool  a_remove_from_surface = false 
)

Reduce the amount in plant pesticide maps. Everything is removed for surface if boolean is true (used for harvest but not cutting)

Sets every entry in vegcanopy, in vegetation and seed maps to 0

400 {
404 #ifdef __DETAILED_PESTICIDE_FATE
405  if (a_reduc > 0 && a_reduc < 1) {
406  Eigen::ArrayXXi* temp_polyid_map = g_landscape_ptr->SupplyPolyIdMapPtr();
408  for (int p = 0; p < m_NoPPPs; p++) {
409  if (a_remove_from_surface) {
410  m_pest_map_vegcanopy[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) = ((*temp_polyid_map)(Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) == a_map_index).select(0, m_pest_map_vegcanopy[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)));
411 #ifdef __FLOWER_PESTICIDE
412  m_pest_map_pollen[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) = ((*temp_polyid_map)(Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) == a_map_index).select(0, m_pest_map_pollen[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)));
413  m_pest_map_nectar[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) = ((*temp_polyid_map)(Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) == a_map_index).select(0, m_pest_map_nectar[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)));
414 #endif
415  }
416  else {
417  m_pest_map_vegcanopy[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) = ((*temp_polyid_map)(Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) == a_map_index).select(m_pest_map_vegcanopy[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) * a_reduc, m_pest_map_vegcanopy[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)));
418 #ifdef __FLOWER_PESTICIDE
419  m_pest_map_pollen[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) = ((*temp_polyid_map)(Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) == a_map_index).select(m_pest_map_pollen[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) * a_reduc, m_pest_map_pollen[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)));
420  m_pest_map_nectar[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) = ((*temp_polyid_map)(Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) == a_map_index).select(m_pest_map_nectar[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) * a_reduc, m_pest_map_nectar[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)));
421 #endif
422  }
423 #ifdef __FLOWER_PESTICIDE
424  m_pest_map_in_vegetation[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) = ((*temp_polyid_map)(Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) == a_map_index).select(m_pest_map_in_vegetation[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) * a_reduc, m_pest_map_in_vegetation[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)));
425 #endif
426  }
427  }
428  }
429  else g_msg->Warn("Pesticide::ReducePlantPesticide - Reduction factor is " + to_string(a_reduc), "Should be between 0 and 1");
430 #endif
431 
432 }

References g_landscape_ptr, g_msg, l_pest_enable_pesticide_engine, m_NoPPPs, Landscape::SupplyPolyIdMapPtr(), CfgBool::value(), and MapErrorMsg::Warn().

Referenced by Farm::BulbHarvest(), FlowerStrip::Cutting(), FieldBoundary::Cutting(), RoadsideVerge::Cutting(), Orchard::Cutting(), MownGrassStrip::Cutting(), VegElement::GrazeVegetation(), VegElement::GrazeVegetationHeight(), Farm::Harvest(), Farm::HarvestLong(), VegElement::ReduceVeg(), and VegElement::ReduceVeg_Extended().

◆ RemovePlantPesticide()

void Pesticide::RemovePlantPesticide ( int  a_minx,
int  a_maxx,
int  a_miny,
int  a_maxy,
int  a_map_index 
)

Sets all plant pesticide maps (so all except soil) to 0.

Sets every entry in vegcanopy, in vegetation and seed maps to 0

374 {
379 #ifdef __DETAILED_PESTICIDE_FATE
381  Eigen::ArrayXXi* temp_polyid_map = g_landscape_ptr->SupplyPolyIdMapPtr();
382  for (int p = 0; p < m_NoPPPs; p++) {
383  m_pest_map_vegcanopy[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) = ((*temp_polyid_map)(Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) == a_map_index).select(0, m_pest_map_vegcanopy[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)));
384 #ifdef __FLOWER_PESTICIDE
385  m_pest_map_in_vegetation[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) = ((*temp_polyid_map)(Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) == a_map_index).select(0, m_pest_map_in_vegetation[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)));
386  m_pest_map_pollen[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) = ((*temp_polyid_map)(Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) == a_map_index).select(0, m_pest_map_pollen[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)));
387  m_pest_map_nectar[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) = ((*temp_polyid_map)(Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) == a_map_index).select(0, m_pest_map_nectar[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)));
388  if (l_pest_enable_seed_coating.value()) {
389  m_pest_map_seed[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) = ((*temp_polyid_map)(Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)) == a_map_index).select(0, m_pest_map_seed[p](Eigen::seq(a_miny, a_maxy), Eigen::seq(a_minx, a_maxx)));
390  }
391 #endif
392  }
393  }
394 #endif
395 
396 }

References g_landscape_ptr, l_pest_enable_pesticide_engine, m_NoPPPs, Landscape::SupplyPolyIdMapPtr(), and CfgBool::value().

Referenced by VegElement::ZeroVeg().

◆ SavePPM()

bool Pesticide::SavePPM ( double *  a_map,
int  a_beginx,
int  a_width,
int  a_beginy,
int  a_height,
char *  a_filename 
)

For testing of the pesticide engine.

1682 {
1683  a_beginx = 0;
1684  a_width = m_pest_map_width;
1685  a_beginy = 0;
1686  a_height = m_pest_map_height;
1687 
1688  SV_UINT32 linesize = a_width*3;
1689  SV_UINT8* linebuffer = (SV_UINT8*)malloc(sizeof(SV_UINT8)* linesize);
1690 
1691  if ( linebuffer == NULL ) {
1692  g_msg->Warn( WARN_FATAL,
1693  "Pesticide::SavePPM(): Out of memory!", "" );
1694  exit(1);
1695  }
1696 
1697  FILE* l_file;
1698  l_file=fopen(a_filename, "w" );
1699  if ( !l_file ) {
1700  printf("PesticideTest::SavePPM(): "
1701  "Unable to open file for writing: %s\n",
1702  a_filename );
1703  exit(1);
1704  }
1705 
1706  fprintf( l_file, "P6\n%d %d %d\n",
1707  a_width,
1708  a_height,
1709  255 );
1710 
1711  for ( int line=a_beginy; line< a_beginy + a_height; line++ ) {
1712  int i = 0;
1713  for ( int column=a_beginx; column < a_beginx + a_width; column++ ) {
1714  int localcolor = (int)( a_map[ line * m_pest_map_width + column ]
1715  * 255.0);
1716  if ( localcolor <= 255 ) {
1717  linebuffer [ i++ ] = char (localcolor & 0xff);
1718  linebuffer [ i++ ] = 0;
1719  linebuffer [ i++ ] = 0;
1720  } else {
1721  linebuffer [ i++ ] = 255;
1722  localcolor -= 255;
1723  if ( localcolor <= 255 ) {
1724  linebuffer [ i++ ] = char (localcolor);
1725  linebuffer [ i++ ] = 0;
1726  } else {
1727  linebuffer [ i++ ] = 255;
1728  localcolor -= 255;
1729  if ( localcolor <= 255 ) {
1730  linebuffer [ i++ ] = char (localcolor);
1731  } else {
1732  linebuffer [ i++ ] = 255;
1733  }
1734  }
1735  }
1736  }
1737  fwrite( linebuffer, sizeof(SV_UINT8), linesize, l_file );
1738  }
1739 
1740  fclose( l_file );
1741  free( linebuffer );
1742  return true;
1743 }

References g_msg, m_pest_map_height, m_pest_map_width, SV_UINT32, SV_UINT8, MapErrorMsg::Warn(), and WARN_FATAL.

◆ SupplyPesticide() [1/2]

double Pesticide::SupplyPesticide ( int  a_polyref,
PlantProtectionProducts  a_ppp 
)
inline

Supplies the pesticide amount in polygon. Note that the result is not precise, since pesticide amount can vary within polygon.

Parameters
a_elethe polygon reference number of the relevant polygon
a_pppthe index number of the pesticide asked for
Returns
Returns the value of the pesticide grid cell for the polygon
724 {
730  int l_c = m_map->SupplyPesticideCell(a_ele);
731  int l_x = (l_c % m_pest_map_width);
732  int l_y = (l_c / m_pest_map_width);
733  return m_pest_map_main[a_ppp](l_y, l_x);
734 }

References m_map, m_pest_map_main, m_pest_map_width, and Landscape::SupplyPesticideCell().

◆ SupplyPesticide() [2/2]

double Pesticide::SupplyPesticide ( int  a_x,
int  a_y,
PlantProtectionProducts  a_ppp 
)
inline

Supplies the pesticide amount in cell.

Parameters
a_xthe x-coord in landscape x units
a_ythe y-coord in landscape x units
a_pppthe index number of the pesticide asked for
Returns
Returns the value of the pesticide a_ppp grid cell containing a_x,a_y
705 {
712 #ifdef PEST_WATER_CHECK
713  if (ElementIsWater(a_x, a_y))
714  return 0.0;
715 #endif
716 
717  unsigned int l_x = a_x >> PEST_GRIDSIZE_POW2;
718  unsigned int l_y = a_y >> PEST_GRIDSIZE_POW2;
719 
720  return m_pest_map_main[a_ppp](l_y, l_x);
721 }

References ElementIsWater(), m_pest_map_main, and PEST_GRIDSIZE_POW2.

Referenced by Landscape::SupplyPesticide(), Landscape::SupplyPesticideInPlant(), Landscape::SupplyPesticideNectar(), Landscape::SupplyPesticideP(), Landscape::SupplyPesticidePlantSurface(), Landscape::SupplyPesticidePollen(), and Landscape::SupplyPesticideS().

◆ SupplyPesticideSeed() [1/2]

double Pesticide::SupplyPesticideSeed ( int  a_polyref,
PlantProtectionProducts  a_ppp 
)

Supplies the seed coating pesticide amount in polygon. Note that the result is not precise, since pesticide amount can vary within polygon.

◆ SupplyPesticideSeed() [2/2]

double Pesticide::SupplyPesticideSeed ( int  a_x,
int  a_y,
PlantProtectionProducts  a_ppp 
)

Supplies the seed coating pesticide amount in cell.

Referenced by Landscape::SupplySeedCoating().

◆ Tick()

void Pesticide::Tick ( void  )

Main pesticide method that is called every day.

Run once per day. If the pesticide engine is not on the daily queue is cleared and the method is ended. First the daily weather conditions are read (rainfall, wind direction and temperature) and the temperature-dependent decay rate is calculated. Then the pesticides, that are currently in the map, are decayed and the queued pesticides are sprayed whereafter the queue is emptied. If seed coating is turned on that is then decayed as well. If turned on, the pesticide load is saved to output files. Then as a last step the pesticides are transfered between the different compartments (only for detailed pesticide model).

227 {
237  for (int ppp = ppp_1; ppp < m_NoPPPs; ppp++)
238  {
240  }
241  return;
242  }
243 
244  // Get todays rainfall
245  m_rainfallcategory = (unsigned)floor(g_land->SupplyRain() * 100 + 0.5);
246  if (m_rainfallcategory >= 100) m_rainfallcategory = 99;
247  // Now make it an index to the 100x100 array.
248  m_rainfallcategory *= 100;
249  // Get todays wind
251 
252 #ifdef __DETAILED_PESTICIDE_FATE
253  // Reset daily decay frac
254  m_pest_daily_decay_frac_vegcanopy.clear();
255  m_pest_daily_decay_frac_soil.clear();
256 #ifdef __FLOWER_PESTICIDE
257  m_pest_daily_decay_frac_in_vegetation.clear();
258  m_pest_daily_decay_frac_pollen.clear();
259  m_pest_daily_decay_frac_nectar.clear();
260  if (l_pest_enable_seed_coating.value()) {
261  m_pest_daily_decay_frac_seedcoating.clear();
262  }
263 #endif
264 #else
265  m_pest_daily_decay_frac.clear();
266 #endif
267 
268  double temp = g_weather->GetTemp();
269  double tempFactor = exp(0.094779 * (20 - temp));
270  for (int ppp = ppp_1; ppp < m_NoPPPs; ppp++)
271  {
272  // Calculate DT50 rates
273  // DT50 will change by the rate of 0.22 extra per degree different from 20
275 #ifdef __DETAILED_PESTICIDE_FATE
276  m_pest_daily_decay_frac_vegcanopy.push_back(pow(10.0, log10(0.5) / (l_pest_ai_half_life_vegcanopy.value(ppp) * tempFactor)));
277  m_pest_daily_decay_frac_soil.push_back(pow(10.0, log10(0.5) / (l_pest_ai_half_life_soil.value(ppp) * tempFactor)));
278 #ifdef __FLOWER_PESTICIDE
279  m_pest_daily_decay_frac_in_vegetation.push_back(pow(10.0, log10(0.5) / (l_pest_ai_half_life_in_vegetation.value(ppp) * tempFactor)));
280  m_pest_daily_decay_frac_pollen.push_back(pow(10.0, log10(0.5) / (l_pest_ai_half_life_pollen.value(ppp) * tempFactor)));
281  m_pest_daily_decay_frac_nectar.push_back(pow(10.0, log10(0.5) / (l_pest_ai_half_life_nectar.value(ppp) * tempFactor)));
282  if (l_pest_enable_seed_coating.value()) {
283  m_pest_daily_decay_frac_seedcoating.push_back(pow(10.0, log10(0.5) / l_pest_ai_half_life_seed_coating.value(ppp)));
284  // Decay seed coating
285  SeedCoatingMapDecay((PlantProtectionProducts)ppp);
286  }
287 
288  // Reset overspray map
289  for (int ppp = ppp_1; ppp < m_NoPPPs; ppp++) {
290  m_pest_map_overspray[ppp].setZero();
291  }
292 #endif
293 #else
294  m_pest_daily_decay_frac.push_back(pow(10.0, log10(0.5) / (l_pest_ai_half_life.value(ppp) * tempFactor)));
295 #endif
296 
297 
298 
299  // Decay pesticide
301  // Apply pesticide
303  // Clear queue
305 
306  // Save pesticide load
307  if (l_pest_record_used.value()) {
308  if (g_date->GetDayInMonth() == 1) RecordPesticideLoad(ppp);
309  }
310  // Save the current pesticide amount
312 #ifdef __DETAILED_PESTICIDE_FATE
313  RecordPesticideMap(ppp, m_pesticide_file_rec_soil, m_pest_map_soil);
314  RecordPesticideMap(ppp, m_pesticide_file_rec_vegcanopy, m_pest_map_vegcanopy);
315 #ifdef __FLOWER_PESTICIDE
316  RecordPesticideMap(ppp, m_pesticide_file_rec_in_vegetation, m_pest_map_in_vegetation);
317  if (l_pest_enable_seed_coating.value()) {
318  RecordPesticideMap(ppp, m_pesticide_file_rec_seed, m_pest_map_seed);
319  }
321 
322 #endif
323 #else
325 #endif
326  }
329  }
330  //if (g_date->DayInYear() == 104) {
331  // RecordPesticideMap(ppp, m_pesticide_file_rec, m_pest_map_main);
332  //}
333  }
334  //transfer amount between different compartments
335  #ifdef __DETAILED_PESTICIDE_FATE
336  #ifdef __FLOWER_PESTICIDE
337  TransferPesticide();
338  #endif
339  #endif
340 }

References DailyQueueClear(), DailyQueueProcess(), g_date, g_land, g_weather, Calendar::GetDayInMonth(), Weather::GetTemp(), l_map_dump_veg_x, l_map_dump_veg_y, l_pest_ai_half_life, l_pest_enable_pesticide_engine, l_pest_record_used, l_pest_save_all_compartments, l_pest_save_map_daily, m_NoPPPs, m_pest_daily_decay_frac, m_pest_map_main, m_pesticide_file_rec, m_pesticide_file_rec_all_comp, m_rainfallcategory, m_wind, MainMapDecay(), ppp_1, RecordAllPesticideCompartments(), RecordPesticideConcentrationPollenNectar(), RecordPesticideLoad(), RecordPesticideMap(), Landscape::SupplyRain(), Landscape::SupplyWindDirection(), CfgInt::value(), CfgBool::value(), and CfgArray_Double::value().

Referenced by Landscape::Tick().

◆ TwinMapClear()

void Pesticide::TwinMapClear ( )
protected

Clears the twin map.

Clears the twin map

658 {
662  m_pest_map_twin.setZero();
663 }

References m_pest_map_twin.

Referenced by DailyQueueProcess().

◆ TwinMapDiffusion()

void Pesticide::TwinMapDiffusion ( int  a_minx,
int  a_miny,
int  a_maxx,
int  a_maxy,
double  a_cover,
PlantProtectionProducts  a_ppp 
)
protected

Diffuses the pesticide in the twin map and adds it to the main map.

Applies drift (which depends on the wind direction) to the pesticide from the twin map and adds it to the main map by calling DiffusionSprayPixel

718 {
722  int l_length = m_pest_drift_max;
723  // Sort out which direction the drift should be applied in.
724  int dx_min = 0, dx_max = 0;
725  int dy_min = 0, dy_max = 0;
726  if (m_wind == 0) { dy_min = -1; dy_max = l_length; } // North
727  else if (m_wind == 1) { dx_min = -l_length; dx_max = 1; } // East
728  else if (m_wind == 2) { dy_min = -l_length; dy_max = 1; } // South
729  else if (m_wind == 3) { dx_min = -1; dx_max = l_length; } // West
730  // Loop over cells in twin map
731  for ( int y=a_miny; y<a_maxy; y++ ){
732  int l_y = y >> PEST_GRIDSIZE_POW2;
733  int t = l_y*m_pest_map_width;
734  for ( int x=a_minx; x<a_maxx; x++ ){
735  int l_x = x >> PEST_GRIDSIZE_POW2;
736  double l_amount = m_pest_map_twin(l_y, l_x);
737  if ( l_amount > 0.0 ){
738  // Spray along the wind direction from -1 to 10m downwind
739  for (int dx = dx_min; dx <= dx_max; dx++) {
740  for (int dy = dy_min; dy <= dy_max; dy++) {
741  int i;
742  // If we are looking 1 meter upwind use the first entry in the diffusion vector
743  if ((dx == -1 && dx == dx_min) || (dy == -1 && dy == dy_min) || (dx == 1 && dx == dx_max) || (dy == 1 && dy == dy_max)) {
744  i = 0;
745  }
746  // Otherwise we use the entry equal to the distance + 1
747  else{
748  i = max(abs(dx), abs(dy)) + 1;
749  }
750  DiffusionSprayPixel((x + dx) >> PEST_GRIDSIZE_POW2, m_pest_map_width, (y + dy) >> PEST_GRIDSIZE_POW2, m_pest_map_height, m_diffusion_vector[i] * l_amount, a_cover, a_ppp);
751  }
752  }
753 
754  // Also spray +/- 1m perpendicular to the wind direction at the spraying point
755  if (dy_min == 0) { // Wind in x direction
758  }
759  else { // Wind in y direction
762  }
763  }
764  }
765  }
766 }

References DiffusionSprayPixel(), m_diffusion_vector, m_pest_drift_max, m_pest_map_height, m_pest_map_twin, m_pest_map_width, m_wind, and PEST_GRIDSIZE_POW2.

Referenced by DailyQueueProcess().

◆ TwinMapDiffusionMatrix()

void Pesticide::TwinMapDiffusionMatrix ( int  a_minx,
int  a_miny,
int  a_maxx,
int  a_maxy,
double  a_cover,
PlantProtectionProducts  a_ppp,
vector< Eigen::MatrixXf > *  a_drift_matrices_ptr 
)
protected

Diffuses the pesticide in the twin map and adds it to the main map using Eigen.

800 {
801  vector< Eigen::MatrixXf> drift_matrices = *a_drift_matrices_ptr;
802 
803  Eigen::MatrixXf drift_matrix;
804  int minx = a_minx;
805  int maxx = a_maxx;
806  int miny = a_miny;
807  int maxy = a_maxy;
808 
809  if (m_wind == 0) // North
810  {
811  maxy = a_maxy + m_drift_distance; // drift will go south
812  if (maxy >= m_pest_map_height) maxy = m_pest_map_height - 1; // check if we are within the map
813  drift_matrix = drift_matrices[1](Eigen::seq(0, maxy - miny), Eigen::seq(0, maxy - miny));
814  }
815  else if (m_wind == 1) // East
816  {
817  minx = a_minx - m_drift_distance; // drift will go west
818  if (minx < 0) minx = 0; // check if we are within the map
819  drift_matrix = drift_matrices[1](Eigen::seq(0, maxx - minx), Eigen::seq(0, maxx - minx));
820  }
821  else if (m_wind == 2) // South
822  {
823  miny = a_miny - m_drift_distance; // drift will go north
824  if (miny < 0) miny = 0; // check if we are within the map
825  drift_matrix = drift_matrices[0](Eigen::seq(0, maxy - miny), Eigen::seq(0, maxy - miny));
826  }
827  else if (m_wind == 3) // West
828  {
829  maxx = a_maxx + m_drift_distance; // drift will go east
830  if (maxx >= m_pest_map_width) maxx = m_pest_map_width - 1; // check if we are within the map
831  drift_matrix = drift_matrices[0](Eigen::seq(0, maxx - minx), Eigen::seq(0, maxx - minx));
832  }
833 
834  // Apply pesticide (do matrix calculations)
835  // For north/south the order of the matrices is drift_matrix * application matrix
836  Eigen::ArrayXXf pest_after_drift;
837  if (m_wind == 0 || m_wind == 2) {
838  pest_after_drift = drift_matrix * m_pest_map_twin(Eigen::seq(miny, maxy), Eigen::seq(minx, maxx));
839  }
840  // For east/west the order of the matrices is application matrix * drift_matrix
841  else {
842  pest_after_drift = m_pest_map_twin(Eigen::seq(miny, maxy), Eigen::seq(minx, maxx)) * drift_matrix;
843  }
844 #ifdef __DETAILED_PESTICIDE_FATE
845 #ifdef __FLOWER_PESTICIDE
846  Eigen::ArrayXXf temp_pollen_map = (*g_landscape_ptr->SupplyPollenMapPtr())(Eigen::seq(miny, maxy), Eigen::seq(minx, maxx));
847  Eigen::ArrayXXf temp_nectar_map = (*g_landscape_ptr->SupplyNectarMapPtr())(Eigen::seq(miny, maxy), Eigen::seq(minx, maxx));
848  temp_pollen_map = (temp_pollen_map > 1000).select(1000, temp_pollen_map) * cfg_pest_overspray_rate_to_pollen.value();
849  temp_nectar_map = (temp_nectar_map > 1000).select(1000, temp_nectar_map) * cfg_pest_overspray_rate_to_nectar.value();
850 
851  Eigen::ArrayXXf pest_for_vegcanopy = pest_after_drift * a_cover;
852  Eigen::ArrayXXf pest_for_pollen = pest_for_vegcanopy * temp_pollen_map;
853  Eigen::ArrayXXf pest_for_nectar = pest_for_vegcanopy * temp_nectar_map;
854  m_pest_map_vegcanopy[a_ppp](Eigen::seq(miny, maxy), Eigen::seq(minx, maxx)) += (pest_for_vegcanopy - pest_for_pollen - pest_for_nectar).matrix();
855  m_pest_map_pollen[a_ppp](Eigen::seq(miny, maxy), Eigen::seq(minx, maxx)) += pest_for_pollen.matrix();
856  m_pest_map_nectar[a_ppp](Eigen::seq(miny, maxy), Eigen::seq(minx, maxx)) += pest_for_nectar.matrix();
857 
858  // Update overspray map
859  m_pest_map_overspray[a_ppp](Eigen::seq(miny, maxy), Eigen::seq(minx, maxx)) += pest_after_drift.matrix();
860 
861 #else
862  m_pest_map_vegcanopy[a_ppp](Eigen::seq(miny, maxy), Eigen::seq(minx, maxx)) += (pest_after_drift * a_cover).matrix();
863 #endif
864  m_pest_map_soil[a_ppp](Eigen::seq(miny, maxy), Eigen::seq(minx, maxx)) += (pest_after_drift * (1.0 - a_cover)).matrix();
865 #else
866  m_pest_map_main[a_ppp](Eigen::seq(miny, maxy), Eigen::seq(minx, maxx)) += pest_after_drift.matrix();
867 #endif
868 }

References g_landscape_ptr, m_drift_distance, m_pest_map_height, m_pest_map_main, m_pest_map_twin, m_pest_map_width, m_wind, Landscape::SupplyNectarMapPtr(), and Landscape::SupplyPollenMapPtr().

Referenced by AddGranularPesticide(), and DailyQueueProcess().

◆ TwinMapSpray()

void Pesticide::TwinMapSpray ( LE a_element_spryaed,
double  a_amount,
int  a_minx,
int  a_miny,
int  a_maxx,
int  a_maxy 
)
protected

Sprays a_amount of the pesticide in each cell in the polygon in the twin map by calling Pesticide::TwinMapSprayPixel.

This is where the initial pesticide amount is applied to the map. A twin of the real maps is used for spraying the amount of pesticide that is sprayed over each cell and then copied to the real one by using a 'diffusion' process to spread it out to all surrounding cells for drift.

Going through the whole landscape is very slow and unnecessary for small polygons. Since our polygons do not extend beyond the edge of the map ie do not wrap round, then we only need a measure of minx, maxx, miny, maxy. This is set up at the start of the simulation.

667 {
678  double l_fractional_amount = a_amount * m_prop;
679  int l_large_map_index = a_element_sprayed->GetMapIndex();
680  for ( int y=a_miny; y<=a_maxy; y++ ) {
681  for ( int x=a_minx; x<=a_maxx; x++ ) {
682  if ( m_land->Get( x, y ) == l_large_map_index )
683  {
684  // This adds the l_fractional_amount to the twin map
685  TwinMapSprayPixel( x, y, l_fractional_amount );
686  }
687  }
688  }
690 }

References RasterMap::Get(), LE::GetMapIndex(), m_land, m_prop, TwinMapSprayCorrectBorders(), and TwinMapSprayPixel().

Referenced by DailyQueueProcess().

◆ TwinMapSprayCorrectBorders()

void Pesticide::TwinMapSprayCorrectBorders ( void  )
protected

Corrects the border in case the pesticide map size doens't fit the landscape map size.

Checks if the borders of the pesticide map doesn't fit the landscape map and makes a correction to the affected cells if needed

694 {
698  if ( m_x_excess ) {
699  for ( unsigned int i=0; i<m_pest_map_width-1; i++ ) {
701  }
702  }
703 
704  if ( m_y_excess ) {
705  unsigned int l_additive = (m_pest_map_height-1)*m_pest_map_width;
706  for ( unsigned int i=0; i<m_pest_map_height-1; i++ ) {
708  }
709  }
710 
711  if ( m_x_excess && m_y_excess ) {
713  }
714 }

References m_corr_x, m_corr_y, m_pest_map_height, m_pest_map_twin, m_pest_map_width, m_x_excess, m_y_excess, and PEST_GRIDAREA.

Referenced by TwinMapSpray().

◆ TwinMapSprayPixel()

void Pesticide::TwinMapSprayPixel ( int  a_large_map_x,
int  a_large_map_y,
double  a_fractional_amount 
)
inlineprotected

Sprays pesticide in the cell.

739 {
740  int l_x = a_large_map_x >> PEST_GRIDSIZE_POW2;
741  int l_y = a_large_map_y >> PEST_GRIDSIZE_POW2;
742 
743  m_pest_map_twin(l_y, l_x) += a_fractional_amount / PEST_GRIDAREA;
744 }

References m_pest_map_twin, PEST_GRIDAREA, and PEST_GRIDSIZE_POW2.

Referenced by TwinMapSpray().

Member Data Documentation

◆ m_corr_x

double Pesticide::m_corr_x
protected

Corrected proportions for the edge squares along the x-axis.

Referenced by Pesticide(), and TwinMapSprayCorrectBorders().

◆ m_corr_y

double Pesticide::m_corr_y
protected

Corrected proportions for the edge squares along the y-axis.

Referenced by Pesticide(), and TwinMapSprayCorrectBorders().

◆ m_daily_granular_queue

vector<vector <PesticideEvent*> > Pesticide::m_daily_granular_queue
protected

List of landscape elements, which had a granular application on a given day. One for each PPP we track.

Referenced by DailyQueueAddGranular(), DailyQueueClear(), DailyQueueProcess(), and Pesticide().

◆ m_daily_seedcoating_queue

vector<vector <PesticideEvent*> > Pesticide::m_daily_seedcoating_queue
protected

List of landscape elements, which had seed coating on a given day. One for each PPP we track.

Referenced by DailyQueueAddSeedCoating(), DailyQueueClear(), DailyQueueProcess(), and Pesticide().

◆ m_daily_spray_queue

vector<vector <PesticideEvent*> > Pesticide::m_daily_spray_queue
protected

List of landscape elements, which was sprayed on a given day. One for each PPP we track.

Referenced by DailyQueueAdd(), DailyQueueClear(), DailyQueueProcess(), and Pesticide().

◆ m_dead_biomass

vector<double> Pesticide::m_dead_biomass
protected

Vector saving the dead biomass in each polygon from the previous day.

Referenced by MainMapDecay(), and Pesticide().

◆ m_diffusion_matrices

vector<Eigen::MatrixXf> Pesticide::m_diffusion_matrices
protected

Pre-calculated diffusion matrices
Used after spraying an element in the pesticide map to determine how much of the sprayed material spreads into the surroundings.

Referenced by DailyQueueProcess(), and DiffusionMatrixInit().

◆ m_diffusion_matrices_dust_drift

vector<Eigen::MatrixXf> Pesticide::m_diffusion_matrices_dust_drift
protected

Pre-calculated diffusion matrices for dust drift, used for seed coating and granular application.

Referenced by AddGranularPesticide(), and DiffusionMatrixInit().

◆ m_diffusion_matrices_orchard_early

vector<Eigen::MatrixXf> Pesticide::m_diffusion_matrices_orchard_early
protected

Pre-calculated diffusion matrices for orchards (early application)

Referenced by DailyQueueProcess(), and DiffusionMatrixInit().

◆ m_diffusion_matrices_orchard_late

vector<Eigen::MatrixXf> Pesticide::m_diffusion_matrices_orchard_late
protected

Pre-calculated diffusion matrices for orchards (late application)

Referenced by DailyQueueProcess(), and DiffusionMatrixInit().

◆ m_diffusion_matrices_vineyard_early

vector<Eigen::MatrixXf> Pesticide::m_diffusion_matrices_vineyard_early
protected

Pre-calculated diffusion matrices for vineyards (early application)

Referenced by DailyQueueProcess(), and DiffusionMatrixInit().

◆ m_diffusion_matrices_vineyard_late

vector<Eigen::MatrixXf> Pesticide::m_diffusion_matrices_vineyard_late
protected

Pre-calculated diffusion matrices for vineyards (late application)

Referenced by DailyQueueProcess(), and DiffusionMatrixInit().

◆ m_diffusion_vector

vector<double> Pesticide::m_diffusion_vector
protected

Pre-calculated diffusion vector.

Referenced by DiffusionVectorInit(), DiffusionVectorTest(), and TwinMapDiffusion().

◆ m_drift_distance

int Pesticide::m_drift_distance
protected

Length of drift vector. How far away from spraying point we consider drift.

Referenced by DiffusionMatrixInit(), and TwinMapDiffusionMatrix().

◆ m_dust_drift_remainder

float Pesticide::m_dust_drift_remainder
protected

Remaining pesticide at 0 meter after dust drift, used for seed coating and granular application.

Referenced by AddGranularPesticide(), and DiffusionMatrixInit().

◆ m_green_biomass

vector<double> Pesticide::m_green_biomass
protected

Vector saving the green biomass in each polygon from the previous day.

Referenced by MainMapDecay(), and Pesticide().

◆ m_land

RasterMap* Pesticide::m_land
protected

Local copy of pointer to the main map object.

Referenced by Pesticide(), RecordPesticideLoad(), RecordPesticideMap(), and TwinMapSpray().

◆ m_map

Landscape* Pesticide::m_map
protected

Local copy of pointer to the main landscape object.

Referenced by ElementIsWater(), MainMapDecay(), Pesticide(), RecordAllPesticideCompartments(), and SupplyPesticide().

◆ m_nectar_mass

vector<double> Pesticide::m_nectar_mass
protected

Vector saving the nectar in each polygon from the previous day.

Referenced by MainMapDecay(), and Pesticide().

◆ m_NoPPPs

int Pesticide::m_NoPPPs
protected

The number of active PPPs to track.

Referenced by Pesticide(), ReducePlantPesticide(), RemovePlantPesticide(), and Tick().

◆ m_orchard_drift_type

int Pesticide::m_orchard_drift_type
protected

Type of orchard drift, can be early or late application.

◆ m_pest_daily_decay_frac

vector<double> Pesticide::m_pest_daily_decay_frac
protected

Daily decay fraction, precalculated from the pesticide environmental half life parameter, for one pesticide compartment use.

Referenced by MainMapDecay(), and Tick().

◆ m_pest_drift_max

int Pesticide::m_pest_drift_max
protected

The maximum distance away from the spraying point we want to consider the pesticide drift downwind.

Referenced by DiffusionVectorTest(), Pesticide(), and TwinMapDiffusion().

◆ m_pest_map_height

unsigned int Pesticide::m_pest_map_height
protected

◆ m_pest_map_main

vector<Eigen::MatrixXf> Pesticide::m_pest_map_main
protected

◆ m_pest_map_record

vector<vector<double> > Pesticide::m_pest_map_record
protected

If we are recording pesticide load we need this map.

Referenced by DiffusionSprayPixel(), Pesticide(), and RecordPesticideLoad().

◆ m_pest_map_size

unsigned int Pesticide::m_pest_map_size
protected

The total size of one map in cellsize resolution.

Referenced by Pesticide().

◆ m_pest_map_twin

Eigen::MatrixXf Pesticide::m_pest_map_twin
protected

◆ m_pest_map_width

unsigned int Pesticide::m_pest_map_width
protected

◆ m_pesticide_file_rec

ofstream Pesticide::m_pesticide_file_rec
protected

Referenced by Pesticide(), and Tick().

◆ m_pesticide_file_rec_all_comp

ofstream Pesticide::m_pesticide_file_rec_all_comp
protected

File for recording pesticide in all compartments including biomass etc.

Referenced by Pesticide(), and Tick().

◆ m_pesticideRecord

ofstream Pesticide::m_pesticideRecord
protected

a file for recording pesticide loads

Referenced by Pesticide(), and RecordPesticideLoad().

◆ m_pollen_mass

vector<double> Pesticide::m_pollen_mass
protected

Vector saving the pollen in each polygon from the previous day.

Referenced by MainMapDecay(), and Pesticide().

◆ m_prop

double Pesticide::m_prop
protected

Constant related to the grid area (i.e. how many landscape map squares are in one grid square).

Referenced by Pesticide(), and TwinMapSpray().

◆ m_rainfallcategory

unsigned Pesticide::m_rainfallcategory
protected

Daily rainfall saved here * 100 to use as an index to the Pesticide::m_RainWashoffFactor array - an optimisation to stop repeated calls to Landscape::SupplyRain.

Referenced by MainMapDecay(), and Tick().

◆ m_RainWashoffFactor

vector<vector <double> > Pesticide::m_RainWashoffFactor
protected

a structure to hold pre-calculated pesticide rain washoff factor (Rw)

Referenced by MainMapDecay(), and Pesticide().

◆ m_seedcoating_to_decay

bool Pesticide::m_seedcoating_to_decay[ppp_foobar]
protected

Structure to keep track of whether there is any seed coating to decay or transfer.

Referenced by Pesticide().

◆ m_something_to_decay

bool Pesticide::m_something_to_decay[ppp_foobar]
protected

Main class for pesticide engine.

Speed hack. Only actually run the daily decay routine on the pesticide map if and only if we are sure that there is some pesticide anywhere on the map for us to process.

Cleared daily by MainMapDecay().

Set to true when either adding pesticide to the map, or by the MainMapDecay() method itself, when it finds remains of pesticide anywhere on the pesticide map during its run. One copy is needed for each active PPP

Referenced by DailyQueueProcess(), GetAnythingToDecay(), MainMapDecay(), and Pesticide().

◆ m_wind

int Pesticide::m_wind
protected

The daily wind direction.

Referenced by Tick(), TwinMapDiffusion(), and TwinMapDiffusionMatrix().

◆ m_x_excess

int Pesticide::m_x_excess
protected

Main map x-coordinate beyond which we have to use special proportional constants when adding new amounts of pesticide to the pesticide map to maintain a mass balance.

Referenced by Pesticide(), and TwinMapSprayCorrectBorders().

◆ m_y_excess

int Pesticide::m_y_excess
protected

Main map y-coordinate beyond which we have to use special proportional constants when adding new amounts of pesticide to the pesticide map to maintain a mass balance.

Referenced by Pesticide(), and TwinMapSprayCorrectBorders().


The documentation for this class was generated from the following files:
Pesticide::TwinMapSprayPixel
void TwinMapSprayPixel(int a_large_map_x, int a_large_map_y, double a_fractional_amount)
Sprays pesticide in the cell.
Definition: Pesticide.h:738
Pesticide::DailyQueueClear
void DailyQueueClear(PlantProtectionProducts a_ppp)
Resets the pesticide action queue.
Definition: Pesticide.cpp:871
LE::GetMinX
int GetMinX(void)
Definition: Elements.h:399
Pesticide::TwinMapDiffusion
void TwinMapDiffusion(int a_minx, int a_miny, int a_maxx, int a_maxy, double a_cover, PlantProtectionProducts a_ppp)
Diffuses the pesticide in the twin map and adds it to the main map.
Definition: Pesticide.cpp:717
PlantProtectionProducts
PlantProtectionProducts
A list ofPPP names for tracking by the Pesticide class.
Definition: LandscapeFarmingEnums.h:1077
Landscape::SupplyGreenBiomass
double SupplyGreenBiomass(int a_polyref)
Returns the green biomass of the vegetation using the polygon reference number a_polyref.
Definition: Landscape.h:1612
Pesticide::m_pest_map_record
vector< vector< double > > m_pest_map_record
If we are recording pesticide load we need this map.
Definition: Pesticide.h:223
Pesticide::m_rainfallcategory
unsigned m_rainfallcategory
Daily rainfall saved here * 100 to use as an index to the Pesticide::m_RainWashoffFactor array - an o...
Definition: Pesticide.h:235
Pesticide::AddGranularPesticide
void AddGranularPesticide(int a_minx, int a_miny, int a_maxx, int a_maxy, double a_cover, PlantProtectionProducts a_ppp)
Adds granular pesticide to polygon.
Definition: Pesticide.cpp:960
Pesticide::TwinMapDiffusionMatrix
void TwinMapDiffusionMatrix(int a_minx, int a_miny, int a_maxx, int a_maxy, double a_cover, PlantProtectionProducts a_ppp, vector< Eigen::MatrixXf > *a_drift_matrices_ptr)
Diffuses the pesticide in the twin map and adds it to the main map using Eigen.
Definition: Pesticide.cpp:799
SV_UINT32
#define SV_UINT32
Definition: Pesticide.cpp:1673
Pesticide::m_nectar_mass
vector< double > m_nectar_mass
Vector saving the nectar in each polygon from the previous day.
Definition: Pesticide.h:186
Pesticide::m_x_excess
int m_x_excess
Definition: Pesticide.h:143
Landscape::SupplyElementType
TTypesOfLandscapeElement SupplyElementType(int a_polyref)
Returns the landscape type of the polygon using the polygon reference number a_polyref or coordinates...
Definition: Landscape.h:1732
RasterMap::MapHeight
int MapHeight(void)
Definition: Rastermap.h:56
Pesticide::DiffusionVectorInit
void DiffusionVectorInit(void)
Initializes the diffusion vector that is used to drift the pesticide.
Definition: Pesticide.cpp:1200
LE::GetMaxX
int GetMaxX(void)
Definition: Elements.h:397
Landscape::SupplyWindDirection
int SupplyWindDirection(void)
Passes a request on to the associated Weather class function, the wind direction in 4 directions for ...
Definition: Landscape.h:2067
Pesticide::m_drift_distance
int m_drift_distance
Length of drift vector. How far away from spraying point we consider drift.
Definition: Pesticide.h:266
Pesticide::m_y_excess
int m_y_excess
Definition: Pesticide.h:145
Pesticide::ElementIsWater
bool ElementIsWater(int a_x, int a_y)
Checks if cell has a water type.
Definition: Pesticide.h:436
RasterMap::Get
int Get(int a_x, int a_y)
Definition: Rastermap.h:82
l_pest_enable_dust_drift
CfgBool l_pest_enable_dust_drift("PEST_ENABLE_DUST_DRIFT", CFG_CUSTOM, false)
Enable dust drift for granular and seed coating applications.
Pesticide::m_dust_drift_remainder
float m_dust_drift_remainder
Remaining pesticide at 0 meter after dust drift, used for seed coating and granular application.
Definition: Pesticide.h:260
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
l_pest_NoPPPs
CfgInt l_pest_NoPPPs("PEST_NO_OF_PPPS", CFG_CUSTOM, 1, 1, 10)
The number of active Plant Protection Products to be tracked - a performance penalty if enabled with ...
Landscape::SupplyRasterMap
RasterMap * SupplyRasterMap()
Returns m_land, the pointer to the raster map instance.
Definition: Landscape.h:576
Pesticide::m_dead_biomass
vector< double > m_dead_biomass
Vector saving the dead biomass in each polygon from the previous day.
Definition: Pesticide.h:180
Pesticide::m_pest_map_main
vector< Eigen::MatrixXf > m_pest_map_main
Map to track the pesticide amount.
Definition: Pesticide.h:215
CfgFloat::value
double value() const
Definition: Configurator.h:142
WARN_FATAL
Definition: MapErrorMsg.h:35
l_pest_record_grid_size
static CfgInt l_pest_record_grid_size("PEST_RECORD_GRID_SIZE", CFG_CUSTOM, 100)
Size of the grid used for recording the pesticide amount in the landscape.
Pesticide::RecordPesticideMap
bool RecordPesticideMap(int a_ppp, ofstream &outfile, vector< Eigen::MatrixXf > &map)
Records the current pesticide amount in map.
Definition: Pesticide.cpp:1528
Pesticide::m_diffusion_matrices_dust_drift
vector< Eigen::MatrixXf > m_diffusion_matrices_dust_drift
Pre-calculated diffusion matrices for dust drift, used for seed coating and granular application.
Definition: Pesticide.h:257
Pesticide::m_pest_map_size
unsigned int m_pest_map_size
The total size of one map in cellsize resolution.
Definition: Pesticide.h:226
Calendar::GetDayInMonth
int GetDayInMonth(void)
Definition: Calendar.h:77
Pesticide::RecordAllPesticideCompartments
void RecordAllPesticideCompartments(int a_x, int a_y, PlantProtectionProducts a_ppp, ofstream &outfile)
Records the current pesticide in all compartments + biomass.
Definition: Pesticide.cpp:1586
Pesticide::m_diffusion_vector
vector< double > m_diffusion_vector
Pre-calculated diffusion vector.
Definition: Pesticide.h:238
l_pest_enable_pesticide_engine
CfgBool l_pest_enable_pesticide_engine("PEST_ENABLE_PESTICIDE_ENGINE", CFG_CUSTOM, false)
Used to turn on or off the PPP functionality of ALMaSS.
Pesticide::DiffusionSprayPixel
void DiffusionSprayPixel(int a_x, int a_limit_x, int a_y, int a_limit_y, double a_amount, double a_cover, PlantProtectionProducts a_ppp)
Adds the diffused pesticide to the cell in the main map(s)
Definition: Pesticide.cpp:772
Pesticide::m_pest_map_twin
Eigen::MatrixXf m_pest_map_twin
A temporary map used when new pesticide is sprayed.
Definition: Pesticide.h:220
LE::GetMinY
int GetMinY(void)
Definition: Elements.h:400
Pesticide::m_pesticide_file_rec
ofstream m_pesticide_file_rec
Definition: Pesticide.h:341
PEST_GRIDSIZE
#define PEST_GRIDSIZE
Definition: Pesticide.h:53
PesticideEvent
Definition: Pesticide.h:68
Landscape::SupplyPolyLEptr
LE * SupplyPolyLEptr(int a_x, int a_y)
Get the pointer to the LE object associated with the polygon at x,y location or by using the polygon ...
Definition: Landscape.h:2152
LE::GetDeadBiomass
virtual double GetDeadBiomass(void)
Definition: Elements.h:163
Pesticide::m_daily_spray_queue
vector< vector< PesticideEvent * > > m_daily_spray_queue
List of landscape elements, which was sprayed on a given day. One for each PPP we track.
Definition: Pesticide.h:269
SV_UINT8
#define SV_UINT8
Definition: Pesticide.cpp:1675
Landscape::SupplyDeadBiomass
double SupplyDeadBiomass(int a_polyref)
Returns the dead biomass of the vegetation using the polygon reference number a_polyref or based on t...
Definition: Landscape.h:1652
Pesticide::m_RainWashoffFactor
vector< vector< double > > m_RainWashoffFactor
a structure to hold pre-calculated pesticide rain washoff factor (Rw)
Definition: Pesticide.h:233
CfgBool::value
bool value() const
Definition: Configurator.h:164
Pesticide::m_diffusion_matrices_vineyard_early
vector< Eigen::MatrixXf > m_diffusion_matrices_vineyard_early
Pre-calculated diffusion matrices for vineyards (early application)
Definition: Pesticide.h:251
Pesticide::m_diffusion_matrices_orchard_early
vector< Eigen::MatrixXf > m_diffusion_matrices_orchard_early
Pre-calculated diffusion matrices for orchards (early application)
Definition: Pesticide.h:245
tole_FishFarm
Definition: LandscapeFarmingEnums.h:124
TTypesOfLandscapeElement
TTypesOfLandscapeElement
Values that represent the types of landscape polygon that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:57
Weather::GetTemp
double GetTemp(long a_date)
Get the temperature on a particular date.
Definition: Weather.h:476
Pesticide::DiffusionVectorTest
void DiffusionVectorTest(void)
For saving diffusion vector in file.
Definition: Pesticide.cpp:1654
Pesticide::m_pest_drift_max
int m_pest_drift_max
The maximum distance away from the spraying point we want to consider the pesticide drift downwind.
Definition: Pesticide.h:155
Landscape::SupplyPesticide
double SupplyPesticide(int a_x, int a_y, PlantProtectionProducts a_ppp)
Gets total pesticide for a location.
Definition: Landscape.cpp:1386
Calendar::Date
long Date(void)
Definition: Calendar.h:57
tole_Pond
Definition: LandscapeFarmingEnums.h:123
Pesticide::TwinMapClear
void TwinMapClear()
Clears the twin map.
Definition: Pesticide.cpp:657
tole_Vineyard
Definition: LandscapeFarmingEnums.h:148
Pesticide::m_something_to_decay
bool m_something_to_decay[ppp_foobar]
Main class for pesticide engine.
Definition: Pesticide.h:135
Pesticide::m_pest_daily_decay_frac
vector< double > m_pest_daily_decay_frac
Daily decay fraction, precalculated from the pesticide environmental half life parameter,...
Definition: Pesticide.h:176
Landscape::SupplyNectarQuantity
double SupplyNectarQuantity(int a_polyref)
Returns the XXX of the vegetation using the polygon reference number a_polyref or based on the x,...
Definition: Landscape.h:661
Pesticide::DecayMap
void DecayMap(vector< Eigen::MatrixXf > &map, vector< double > &decay_frac, int a_ppp)
Decays the pesticide in the entire map in a parallel manner.
Definition: Pesticide.cpp:550
Pesticide::m_NoPPPs
int m_NoPPPs
The number of active PPPs to track.
Definition: Pesticide.h:140
Pesticide::m_diffusion_matrices_orchard_late
vector< Eigen::MatrixXf > m_diffusion_matrices_orchard_late
Pre-calculated diffusion matrices for orchards (late application)
Definition: Pesticide.h:248
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
Landscape::SupplyVegBiomass
double SupplyVegBiomass(int a_polyref)
Returns the biomass of the vegetation using the polygon reference number a_polyref or based on the x,...
Definition: Landscape.h:1542
Pesticide::MainMapDecay
void MainMapDecay(PlantProtectionProducts a_ppp)
Applies rain washoff and decays the pesticides in all maps by calling Pesticide::DecayMap.
Definition: Pesticide.cpp:449
Pesticide::RecordPesticideConcentrationPollenNectar
void RecordPesticideConcentrationPollenNectar(int a_x, int a_y, PlantProtectionProducts a_ppp, ofstream &outfile)
Records the current pesticide concentration in pollen and nectar.
Landscape::SupplyPollenMapPtr
Eigen::MatrixXf * SupplyPollenMapPtr()
Returns pointer to the Eigen matrix for pollen.
Definition: Landscape.h:337
Landscape::SupplyVegCover
double SupplyVegCover(int a_polyref)
Returns the vegetation cover proportion of the vegetation using the polygon reference number a_polyre...
Definition: Landscape.h:1667
CfgInt::value
int value() const
Definition: Configurator.h:116
l_pest_use_single_nozzle_drift
CfgBool l_pest_use_single_nozzle_drift("PEST_USE_SINGLE_NOZZLE_DRIFT", CFG_CUSTOM, false)
Uses single nozzle drift result (in for-loop) if true, but uses matrix calculation (Eigen) with Rautm...
CfgArray_Double::value
std::vector< double > value() const
Definition: Configurator.h:219
Pesticide::m_land
RasterMap * m_land
Local copy of pointer to the main map object.
Definition: Pesticide.h:189
Landscape::SupplyMaxPoly
int SupplyMaxPoly()
Returns the size of the Landscape::m_elems vector.
Definition: Landscape.h:331
Pesticide::DailyQueueProcess
void DailyQueueProcess(PlantProtectionProducts a_ppp)
Sprays the pesticides that are listed in the daily queue.
Definition: Pesticide.cpp:559
Landscape::SupplyNectarMapPtr
Eigen::MatrixXf * SupplyNectarMapPtr()
Returns pointer to the Eigen matrix for nectar.
Definition: Landscape.h:339
l_pest_ai_half_life
static CfgArray_Double l_pest_ai_half_life("PEST_AI_HALF_LIFE", CFG_CUSTOM, 10, vector< double >{10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0, 10.0})
Half-life of pesticides for one compartment use.
Pesticide::m_seedcoating_to_decay
bool m_seedcoating_to_decay[ppp_foobar]
Structure to keep track of whether there is any seed coating to decay or transfer.
Definition: Pesticide.h:137
Landscape::SupplyElementTypeFromVector
TTypesOfLandscapeElement SupplyElementTypeFromVector(unsigned int a_index)
Gets the TTypesOfVegetation type of a polygon using the m_elems.
Definition: Landscape.h:1727
l_map_dump_veg_x
CfgInt l_map_dump_veg_x
LE::GetGreenBiomass
virtual double GetGreenBiomass(void)
Definition: Elements.h:160
PEST_GRIDAREA
#define PEST_GRIDAREA
Definition: Pesticide.h:54
l_pest_driving_slow
static CfgBool l_pest_driving_slow("PEST_DRIVING_SLOW", CFG_CUSTOM, false)
Used to decide the driving speed when spraying pesticides. Driving slow is 7.2 km/h,...
Landscape::SupplyRain
double SupplyRain(void)
Passes a request on to the associated Weather class function, the amount of rain for the current day.
Definition: Landscape.h:1971
tole_Freshwater
Definition: LandscapeFarmingEnums.h:86
g_weather
class Weather * g_weather
Definition: Weather.cpp:49
PEST_GRIDSIZE_POW2
#define PEST_GRIDSIZE_POW2
Definition: Pesticide.h:52
Pesticide::m_prop
double m_prop
Constant related to the grid area (i.e. how many landscape map squares are in one grid square).
Definition: Pesticide.h:147
Landscape::SupplyVegHeight
double SupplyVegHeight(int a_polyref)
Returns the height of the vegetation using the polygon reference number a_polyref or based on the x,...
Definition: Landscape.h:1527
Pesticide::m_pest_map_width
unsigned int m_pest_map_width
The width of one map in cellsize resolution.
Definition: Pesticide.h:228
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
tole_Saltwater
Definition: LandscapeFarmingEnums.h:88
l_pest_record_used
static CfgBool l_pest_record_used("PEST_RECORD_USED", CFG_CUSTOM, false)
Used to turn on or off saving the pesticide load.
l_pest_nozzle_type
static CfgInt l_pest_nozzle_type("PEST_NOZZLE_TYPE", CFG_CUSTOM, 0, 0, 17)
The type of nozzle to use for spraying pesticide. Determines the amount of drift.
tole_River
Definition: LandscapeFarmingEnums.h:87
Landscape::SupplyPolyIdMapPtr
Eigen::ArrayXXi * SupplyPolyIdMapPtr()
Returns pointer to the Eigen Array for poly id map.
Definition: Landscape.h:333
tole_Orchard
Definition: LandscapeFarmingEnums.h:93
l_pest_zero_threshold
CfgFloat l_pest_zero_threshold("PEST_ZERO_THRESHOLD", CFG_CUSTOM, 0.000001)
The threshold for when we consider the pesticide amount negligible (default is 1 microgram per square...
Landscape::SupplyPesticideCell
int SupplyPesticideCell(int a_polyref)
Gets the index to the cell used to store pesticide information from the coordinates x,...
Definition: Landscape.h:2132
Pesticide::m_pesticideRecord
ofstream m_pesticideRecord
a file for recording pesticide loads
Definition: Pesticide.h:325
Pesticide::DiffusionMatrixInit
void DiffusionMatrixInit(void)
Initializes the diffusion matrices that are used to drift the pesticide.
Definition: Pesticide.cpp:1269
Pesticide::m_diffusion_matrices
vector< Eigen::MatrixXf > m_diffusion_matrices
Pre-calculated diffusion matrices Used after spraying an element in the pesticide map to determine ...
Definition: Pesticide.h:242
Pesticide::m_corr_y
double m_corr_y
Corrected proportions for the edge squares along the y-axis.
Definition: Pesticide.h:151
Pesticide::m_pollen_mass
vector< double > m_pollen_mass
Vector saving the pollen in each polygon from the previous day.
Definition: Pesticide.h:184
Pesticide::m_corr_x
double m_corr_x
Corrected proportions for the edge squares along the x-axis.
Definition: Pesticide.h:149
tole_Field
Definition: LandscapeFarmingEnums.h:65
Pesticide::m_green_biomass
vector< double > m_green_biomass
Vector saving the green biomass in each polygon from the previous day.
Definition: Pesticide.h:182
Pesticide::m_daily_granular_queue
vector< vector< PesticideEvent * > > m_daily_granular_queue
List of landscape elements, which had a granular application on a given day. One for each PPP we trac...
Definition: Pesticide.h:275
Pesticide::m_daily_seedcoating_queue
vector< vector< PesticideEvent * > > m_daily_seedcoating_queue
List of landscape elements, which had seed coating on a given day. One for each PPP we track.
Definition: Pesticide.h:272
Landscape::SupplyPollenQuantity
double SupplyPollenQuantity(int a_polyref)
Returns the pollen quantity produced by the vegetation using the polygon reference number a_polyref o...
Definition: Landscape.h:657
l_pest_save_map_daily
static CfgBool l_pest_save_map_daily("PEST_SAVE_MAP_DAILY", CFG_CUSTOM, false)
Used to turn on or off saving the pesticide map(s) daily.
Pesticide::m_wind
int m_wind
The daily wind direction.
Definition: Pesticide.h:153
l_map_dump_veg_y
CfgInt l_map_dump_veg_y
Pesticide::m_pesticide_file_rec_all_comp
ofstream m_pesticide_file_rec_all_comp
File for recording pesticide in all compartments including biomass etc.
Definition: Pesticide.h:344
Pesticide::TwinMapSprayCorrectBorders
void TwinMapSprayCorrectBorders(void)
Corrects the border in case the pesticide map size doens't fit the landscape map size.
Definition: Pesticide.cpp:693
Pesticide::m_diffusion_matrices_vineyard_late
vector< Eigen::MatrixXf > m_diffusion_matrices_vineyard_late
Pre-calculated diffusion matrices for vineyards (late application)
Definition: Pesticide.h:254
g_landscape_ptr
Landscape * g_landscape_ptr
Definition: Landscape.cpp:352
RasterMap::MapWidth
int MapWidth(void)
Definition: Rastermap.h:55
LE::GetVegDDegs
double GetVegDDegs()
Get the total of day degrees for the crop/veg on this element.
Definition: Elements.h:410
l_pest_save_all_compartments
static CfgBool l_pest_save_all_compartments("PEST_SAVE_ALL_COMPARTMENTS", CFG_CUSTOM, false)
Used to turn on or off saving all pesticide compartments in one file for x=l_map_dump_veg_x and y=l_m...
Pesticide::m_map
Landscape * m_map
Local copy of pointer to the main landscape object.
Definition: Pesticide.h:192
LE::GetMaxY
int GetMaxY(void)
Definition: Elements.h:398
Pesticide::m_pest_map_height
unsigned int m_pest_map_height
The height of one map in cellsize resolution.
Definition: Pesticide.h:230
ppp_1
Definition: LandscapeFarmingEnums.h:1079
Pesticide::TwinMapSpray
void TwinMapSpray(LE *a_element_spryaed, double a_amount, int a_minx, int a_miny, int a_maxx, int a_maxy)
Sprays a_amount of the pesticide in each cell in the polygon in the twin map by calling Pesticide::Tw...
Definition: Pesticide.cpp:666
g_land
Landscape * g_land
Definition: skylarks_all.cpp:44
Pesticide::RecordPesticideLoad
bool RecordPesticideLoad(int a_ppp)
Records the pesticide load at landscape level.
Definition: Pesticide.cpp:1494