ALMaSS Partridge ODdox
1.1
The partridge model description following ODdox protocol
|
Go to the documentation of this file.
28 #define _CRT_SECURE_NO_DEPRECATE
183 for (
int y=a_miny; y<=a_maxy; y++ )
186 for (
int x=a_minx; x<=a_maxx; x++ )
215 double l_fractional_amount = a_amount *
m_prop;
216 int l_large_map_index = a_element_sprayed->
GetMapIndex();
217 for (
int y=a_miny; y<=a_maxy; y++ ) {
218 for (
int x=a_minx; x<=a_maxx; x++ ) {
219 if (
m_land->
Get( x, y ) == l_large_map_index )
278 for (
int y=a_miny; y<a_maxy; y++ )
281 for (
int x=a_minx; x<a_maxx; x++ )
298 #ifdef __DETAILED_PESTICIDE_FATE
312 if (a_x < 0 || a_x >= a_limit_x || a_y < 0 || a_y >= a_limit_y)
return;
314 int l_coord = a_y * a_limit_x + a_x;
315 #ifdef __DETAILED_PESTICIDE_FATE
317 m_pest_map_vegcanopy[a_ppp][l_coord] += a_amount * a_cover;
318 m_pest_map_soil[a_ppp][l_coord] += a_amount - m_pest_map_vegcanopy[a_ppp][l_coord];
335 const int l_side_length = l_grid * 2 + 1;
337 l_diff =
new double[l_side_length];
341 for (
int l=1; l<l_side_length; l++)
346 for (
int l=0; l<l_side_length; l++)
353 for (
int wind=0; wind < 4; wind ++)
356 for (
int x = 0; x< l_side_length; x++ )
358 for (
int y= 0; y< l_side_length; y++ )
368 for (
int step = 0; step <= l_grid; step++)
370 for (
int cc=0; cc<fin; cc++)
372 m_diffusion_mask[0][ strtx + (cc-step) + ((strty-step)*l_side_length)]->SetFraction(l_diff[step]);
378 for (
int step = 0; step <= l_grid; step++)
380 for (
int cc=0; cc<fin; cc++)
382 m_diffusion_mask[2][ strtx + (cc-step) + ((strty+step)*l_side_length)]->SetFraction(l_diff[step]);
388 for (
int step = 0; step <= l_grid; step++)
390 for (
int cc=0; cc<fin; cc++)
392 m_diffusion_mask[3][ (strtx + step) + ((strty+(cc-step))*l_side_length)]->SetFraction(l_diff[step]);
398 for (
int step = 0; step <= l_grid; step++)
400 for (
int cc=0; cc<fin; cc++)
402 m_diffusion_mask[1][ (strtx - step) + ((strty+(cc-step))*l_side_length)]->SetFraction(l_diff[step]);
450 #ifdef __WithinOrchardPesticideSim__
451 if (a_dist_meters==0) pp=0.7784;
455 pp = (2.7705 * pow(a_dist_meters, -1.7)) * 0.01;
480 #ifdef __DETAILED_PESTICIDE_FATE
481 if ((m_pest_map_vegcanopy[a_ppp][i] > l_zero) )
487 unsigned cov = 100 * cover;
490 m_pest_map_vegcanopy[a_ppp][i] -= Rwp;
496 if (m_pest_map_soil[a_ppp][i] > l_zero)
503 m_pest_map_vegcanopy[a_ppp][i] = 0.0;
504 m_pest_map_soil[a_ppp][i] = 0.0;
560 #ifdef __DETAILED_PESTICIDE_FATE
561 m_pest_map_vegcanopy.resize(
m_NoPPPs);
566 for (
int p = 0; p <
m_NoPPPs; p++) {
567 #ifdef __DETAILED_PESTICIDE_FATE
570 fill(m_pest_map_vegcanopy[p].begin(), m_pest_map_vegcanopy[p].end(), 0.0);
571 fill(m_pest_map_soil[p].begin(), m_pest_map_soil[p].end(), 0.0);
604 double rainsteps = 0.1;
605 double coversteps = 1.0;
606 for (
int i = 0; i < 100; i++)
608 double SC = i * coversteps;
609 double LAI = log(0 - (1 - SC))*1.666666667;
610 for (
int r = 0; r < 100; r++)
612 double P = r * rainsteps;
613 double Pi = LAI*(1 - (1 / ((1 + SC * P) / LAI)));
614 double Rw = 0.25*(SC * P - Pi);
625 for (
int winddir = 0; winddir < 4; winddir++)
643 const int l_side_length = l_grid * 2 + 1;
646 ofstream ofile(
"diffusionmask.txt",ios::out);
647 for (
int i=0; i<4; i++)
649 for (
int x = 0; x< l_side_length; x++ )
651 for (
int y= 0; y< l_side_length; y++ )
665 #define CFG_CHANNEL_BITS 8
666 #define CFG_CHANNEL_MAXVAL (2^CFG_CHANNEL_BITS-1)
668 #define SV_UINT32 unsigned int
670 #define SV_UINT8 unsigned char
674 int a_beginx,
int a_width,
675 int a_beginy,
int a_height,
686 if ( linebuffer == NULL ) {
688 "Pesticide::SavePPM(): Out of memory!",
"" );
693 l_file=fopen(a_filename,
"w" );
695 printf(
"PesticideTest::SavePPM(): "
696 "Unable to open file for writing: %s\n",
701 fprintf( l_file,
"P6\n%d %d %d\n",
706 for (
int line=a_beginy; line< a_beginy + a_height; line++ ) {
708 for (
int column=a_beginx; column < a_beginx + a_width; column++ ) {
711 if ( localcolor <= 255 ) {
712 linebuffer [ i++ ] = char (localcolor & 0xff);
713 linebuffer [ i++ ] = 0;
714 linebuffer [ i++ ] = 0;
716 linebuffer [ i++ ] = 255;
718 if ( localcolor <= 255 ) {
719 linebuffer [ i++ ] = char (localcolor);
720 linebuffer [ i++ ] = 0;
722 linebuffer [ i++ ] = 255;
724 if ( localcolor <= 255 ) {
725 linebuffer [ i++ ] = char (localcolor);
727 linebuffer [ i++ ] = 255;
732 fwrite( linebuffer,
sizeof(
SV_UINT8), linesize, l_file );
771 m_typeofmap = a_typeofmap;
772 m_startyear = a_startyear;
773 m_endyear = a_startyear + a_noyears;
774 m_cellsize = a_cellsize;
775 m_OurLandscape = a_landscape;
776 m_Rastermap = a_land;
777 m_pmap_width = m_OurLandscape->SupplySimAreaWidth() / m_cellsize;
778 m_pmap_height = m_OurLandscape->SupplySimAreaHeight() / m_cellsize; ;
781 m_pmap_insecticides =
new vector<double>;
782 m_pmap_insecticides->resize(m_pmap_width*m_pmap_height);
783 fill(m_pmap_insecticides->begin(), m_pmap_insecticides->end(), 0);
785 m_PMap =
new ofstream(
"ALMaSS_InsecticideMap.txt", ios::out);
786 (*m_PMap) <<
"Years" <<
' ' << a_noyears <<
' ' <<
"Height" <<
' ' << m_pmap_height <<
' ' <<
"Width" <<
' ' << m_pmap_width <<
' ' << endl;
792 m_pmap_fungicides =
new vector<double>;
793 m_pmap_fungicides->resize(m_pmap_width*m_pmap_height);
794 fill(m_pmap_fungicides->begin(), m_pmap_fungicides->end(), 0);
795 m_PMap =
new ofstream(
"ALMaSS_FungicideMap.txt", ios::out);
796 (*m_PMap) <<
"Years" <<
' ' << a_noyears <<
' ' <<
"Height" <<
' ' << m_pmap_height <<
' ' <<
"Width" <<
' ' << m_pmap_width <<
' ' << endl;
798 m_pmap_herbicides =
new vector<double>;
799 m_pmap_herbicides->resize(m_pmap_width*m_pmap_height);
800 fill(m_pmap_herbicides->begin(), m_pmap_herbicides->end(), 0);
801 m_PMap =
new ofstream(
"ALMaSS_HerbicideMap.txt", ios::out);
802 (*m_PMap) <<
"Years" <<
' ' << a_noyears <<
' ' <<
"Height" <<
' ' << m_pmap_height <<
' ' <<
"Width" <<
' ' << m_pmap_width <<
' ' << endl;
807 m_pmap_fungicides = NULL;
808 m_pmap_herbicides = NULL;
814 delete m_pmap_insecticides;
818 delete m_pmap_fungicides;
819 delete m_pmap_herbicides;
827 if (a_map == m_pmap_insecticides) fname =
"ALMaSS_InsecticideMap.txt";
828 else if (a_map == m_pmap_fungicides) fname =
"ALMaSS_FungicideMap.txt";
829 else fname =
"ALMaSS_HerbicideMap.txt";
831 ofstream* m_PMap =
new ofstream(fname.c_str(), ios::app);
832 if (!(*m_PMap).is_open())
834 g_msg->
Warn(
WARN_FILE,
"PesticideMap::DumpMap Unable to open file for append: ", fname.c_str());
839 for (
int y = 0; y < m_pmap_height; y++)
841 for (
int x = 0; x < m_pmap_width; x++)
843 (*m_PMap) << (*a_map)[y*m_pmap_width + x] <<
' ';
849 fill(a_map->begin(), a_map->end(), 0);
867 vector<double>* ourmap = m_pmap_insecticides; ;
868 if (a_type ==
fungicide) ourmap = m_pmap_fungicides;
869 else if (a_type ==
herbicide) ourmap = m_pmap_herbicides;
870 int l_large_map_index = a_element_sprayed->
GetMapIndex();
871 int minx = a_element_sprayed->
GetMinX();
872 int miny = a_element_sprayed->
GetMinY();
873 int maxx = a_element_sprayed->
GetMaxX();
874 int maxy = a_element_sprayed->
GetMaxY();
875 for (
int y = miny; y <= maxy; y++) {
876 for (
int x = minx; x <= maxx; x++) {
877 if (m_Rastermap->Get(x, y) == l_large_map_index)
880 (*ourmap)[(x/m_cellsize)+(y/m_cellsize)*m_pmap_width]++;
void TwinMapSprayPixel(int a_large_map_x, int a_large_map_y, double a_fractional_amount)
void DailyQueueClear(PlantProtectionProducts a_ppp)
CfgBool l_pest_use_application_rate("PEST_USE_APPLICATIONRATE", CFG_CUSTOM, false)
void TwinMapDiffusion(int a_minx, int a_miny, int a_maxx, int a_maxy, double a_cover, PlantProtectionProducts a_ppp)
PlantProtectionProducts
A list PPP names for tracking by the Pesticide class.
unsigned m_rainfallcategory
Daily rainfall saved here * 100 to use as an index to the Pesticide::m_RainWashoffFactor array - an o...
CfgBool cfg_pest_springbarley_on("PEST_SPRINGBARLEY_ON", CFG_CUSTOM, false)
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 ...
CfgBool cfg_pest_cabbage_on("PEST_CABBAGE_ON", CFG_CUSTOM, false)
static CfgFloat l_pest_ai_half_life_Soil("PEST_AI_HALF_LIFE_SOIL", CFG_CUSTOM, 10.0)
CfgFloat cfg_pest_product_8_amount("PEST_PRODUCT_EIGHT_AMOUNT", CFG_CUSTOM, 1.0)
int SupplyWindDirection(void)
int Get(int a_x, int a_y)
CfgFloat cfg_pest_product_10_amount("PEST_PRODUCT_TEN_AMOUNT", CFG_CUSTOM, 1.0)
#define PEST_GRIDSIZE_POW2
static CfgFloat l_pest_zero_threshold("PEST_ZERO_THRESHOLD", CFG_CUSTOM, 0.00001)
Diffusion_mask m_diffusion_mask[4]
Pre-calculated square diffusion map, assuming wind directions (4) Used after spraying an element in...
static CfgFloat l_pest_diffusion_slope("PEST_DRIFT_SLOPE", CFG_CUSTOM, -0.6122)
CfgBool cfg_pest_beet_on("PEST_BEET_ON", CFG_CUSTOM, false)
CfgFloat cfg_pest_product_9_amount("PEST_PRODUCT_NINE_AMOUNT", CFG_CUSTOM, 1.0)
unsigned int m_pest_map_size
The total size of one map in cellsize resolution.
PesticideMap(int a_startyear, int a_noyears, int a_cellsize, Landscape *a_landscape, RasterMap *a_land, bool a_typeofmap)
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)
CfgBool l_pest_enable_pesticide_engine("PEST_ENABLE_PESTICIDE_ENGINE", CFG_CUSTOM, false)
Used to turn on or off the PPP functionality of ALMaSS.
CfgBool cfg_pest_carrots_on("PEST_CARROTS_ON", CFG_CUSTOM, false)
void Spray(LE *a_element_sprayed, TTypesOfPesticideCategory a_type)
CfgFloat l_pest_trigger_threshold2("PEST_TRIGGER_THRESHOLD_TWO", CFG_CUSTOM, 1.0)
vector< vector< PesticideEvent * > > m_daily_spray_queue
List lists of landscape elements, which was sprayed on a given day. One for each PPP we track.
CfgBool cfg_pest_winterrape_on("PEST_WINTERRAPE_ON", CFG_CUSTOM, false)
CfgFloat l_pest_daily_mort2("PEST_DAILY_MORTALITY_TWO", CFG_CUSTOM, 0.25)
class MapErrorMsg * g_msg
static CfgFloat l_pest_ai_half_life_Veg("PEST_AI_HALF_LIFE_VEG", CFG_CUSTOM, 10.0)
vector< vector< double > > m_pest_map_main
The landscape class containing all environmental and topographical data.
CfgBool cfg_pest_potatoes_on("PEST_POTATOES_ON", CFG_CUSTOM, false)
CfgBool cfg_pest_springwheat_on("PEST_SPRINGWHEAT_ON", CFG_CUSTOM, false)
double GetTemp(long a_date)
Get the temperature on a particular date.
bool m_something_to_decay[ppp_foobar]
Speed hack. Only actually run the daily decay routine on the pesticide map if and only if we are sure...
Bool configurator entry class.
void TwinMapClear(int a_minx, int a_miny, int a_maxx, int a_maxy)
CfgBool cfg_pest_winterwheat_on("PEST_WINTERWHEAT_ON", CFG_CUSTOM, false)
class Landscape * g_landscape_p
int m_NoPPPs
The number of active PPPs to track.
CfgBool cfg_pest_tulips_on("PEST_TULIPS_ON", CFG_CUSTOM, false)
void DiffusionMaskInit(void)
static CfgFloat l_pest_ai_half_life("PEST_AI_HALF_LIFE", CFG_CUSTOM, 10.0)
CfgInt cfg_pest_productapplic_startdate3("PEST_PRODUCTAPPLIC_STARTDATE_THREE", CFG_CUSTOM,-1)
void DailyQueueAdd(LE *a_element_sprayed, double a_amount, PlantProtectionProducts a_ppp)
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
CfgFloat cfg_pest_product_4_amount("PEST_PRODUCT_FOUR_AMOUNT", CFG_CUSTOM, 1.0)
static CfgInt l_pest_diffusion_grid_count("PEST_DIFFUSION_GRID_COUNT", CFG_CUSTOM, 1)
CfgBool cfg_pest_SBS_ERA("PEST_SBS_ERA", CFG_CUSTOM, false)
void MainMapDecay(PlantProtectionProducts a_ppp)
TTypesOfPesticideCategory
double m_pest_daily_decay_frac
double SupplyVegCover(int a_polyref)
CfgInt cfg_pest_productapplic_period("PEST_PRODUCTAPPLIC_PERIOD", CFG_CUSTOM, 1)
void DailyQueueProcess(PlantProtectionProducts a_ppp)
CfgFloat cfg_pest_product_3_amount("PEST_PRODUCT_THREE_AMOUNT", CFG_CUSTOM, 1.0)
double DiffusionFunction(double a_dist_meters)
unsigned int m_pest_map_width
The width of one map in cellsize resolution.
CfgInt cfg_pest_productapplic_startdate("PEST_PRODUCTAPPLIC_STARTDATE", CFG_CUSTOM, -1)
CfgBool cfg_pest_winterbarley_on("PEST_WINTERBARLEY_ON", CFG_CUSTOM, false)
CfgFloat l_pest_daily_mort("PEST_DAILY_MORTALITY", CFG_CUSTOM, 0.25)
CfgFloat cfg_pest_product_6_amount("PEST_PRODUCT_SIX_AMOUNT", CFG_CUSTOM, 1.0)
Integer configurator entry class.
CfgFloat l_pest_trigger_threshold1("PEST_TRIGGER_THRESHOLD_ONE", CFG_CUSTOM, 1.0)
This is a trigger values that can be used to trigger pesticides effects. Currently only used by the B...
CfgFloat cfg_pest_product_5_amount("PEST_PRODUCT_FIVE_AMOUNT", CFG_CUSTOM, 1.0)
Pesticide(RasterMap *a_land, Landscape *a_map)
double m_RainWashoffFactor[10000]
a structure to hold pre-calculated pesticide rain wash off factor (Rw)
Double configurator entry class.
double * m_pest_map_twin
The complete pesticide map.
CfgBool cfg_pest_wintertriticale_on("PEST_WINTERTRITICALE_ON", CFG_CUSTOM, false)
double m_pest_daily_decay_frac_Soil
CfgInt cfg_pest_productapplic_startdate2("PEST_PRODUCTAPPLIC_STARTDATE_TWO", CFG_CUSTOM,-1)
CfgBool cfg_pest_winterrye_on("PEST_WINTERRYE_ON", CFG_CUSTOM, false)
void TwinMapSprayCorrectBorders(void)
double m_pest_daily_decay_frac_Veg
CfgFloat cfg_pest_product_2_amount("PEST_PRODUCT_TWO_AMOUNT", CFG_CUSTOM, 1.0)
bool DumpPMap(vector< double > *a_map)
void DiffusionMaskInitTest(void)
CfgFloat cfg_pest_product_1_amount("PEST_PRODUCT_ONE_AMOUNT", CFG_CUSTOM, 1.0)
CfgBool cfg_pest_residue_or_rate("PEST_RESIDUE_OR_RATE", CFG_CUSTOM, true)
void CalcRainWashOffFactors()
Pre-calculates the constants required for rain wash off with increasing rainfall and stores this in m...
unsigned int m_pest_map_height
The height of one map in cellsize resolution.
CfgFloat cfg_pest_product_7_amount("PEST_PRODUCT_SEVEN_AMOUNT", CFG_CUSTOM, 1.0)
class Weather * g_weather
void TwinMapSpray(LE *a_element_spryaed, double a_amount, int a_minx, int a_miny, int a_maxx, int a_maxy)
bool SavePPM(double *a_map, int a_beginx, int a_width, int a_beginy, int a_height, char *a_filename)