File failed to load: https://cdnjs.cloudflare.com/ajax/libs/mathjax/2.7.5/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
PTWinterRye Class Reference

PTWinterRye class
. More...

#include <PTWinterRye.h>

Inheritance diagram for PTWinterRye:
Crop

Public Member Functions

virtual bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 The one and only method for a crop management plan. All farm actions go through here. More...
 
 PTWinterRye (TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
 
void SetUpFarmCategoryInformation ()
 
- Public Member Functions inherited from Crop
virtual ~Crop ()
 
 Crop (TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
 
int GetFirstDate (void)
 
void ChooseNextCrop (int a_no_dates)
 Chooses the next crop to grow in a field. More...
 
int GetCropClassification ()
 
void SetCropClassification (int a_classification)
 
void GetCropType (TTypesOfCrops a_toc)
 
TTypesOfCrops GetCropType ()
 
FarmManagementCategory LookUpManagementCategory (int a_todo)
 
bool GetForceSpringOK ()
 

Additional Inherited Members

- Public Attributes inherited from Crop
TTypesOfVegetation m_tov
 
- Protected Member Functions inherited from Crop
void SimpleEvent (long a_date, int a_todo, bool a_lock)
 Adds an event to this crop management. More...
 
void SimpleEvent_ (long a_date, int a_todo, bool a_lock, Farm *a_farm, LE *a_field)
 Adds an event to this crop management without relying on member variables. More...
 
bool StartUpCrop (int a_spring, std::vector< std::vector< int >> a_flexdates, int a_todo)
 
Holds the translation between the farm operation enum for each cropand the farm management category associated with it More...
 
bool AphidDamage (LE *a_field)
 Compares aphid numbers per m2 with a threshold to return true if threshold is exceeded. More...
 
- Protected Attributes inherited from Crop
Farmm_farm
 
LEm_field
 
FarmEventm_ev
 
int m_first_date
 
int m_count
 
int m_last_date
 
int m_ddegstoharvest
 
int m_base_elements_no
 
Landscapem_OurLandscape
 
bool m_forcespringpossible = false
 Used to signal that the crop can be forced to start in spring. More...
 
TTypesOfCrops m_toc
 The Crop type in terms of the TTypesOfCrops list (smaller list than tov, no country designation) More...
 
int m_CropClassification
 Contains information on whether this is a winter crop, spring crop, or catch crop that straddles the year boundary (0,1,2) More...
 
vector< FarmManagementCategorym_ManagementCategories
 Holds the translation between the farm operation enum for each crop and the farm management category associated with it. More...
 
- Static Protected Attributes inherited from Crop
static int m_date_modifier = 0
 Holds a value that shifts test pesticide use by this many days in crops modified to use it. More...
 

Detailed Description

PTWinterRye class
.

See PTWinterRye.h::PTWinterRyeToDo for a complete list of all possible events triggered codes by the Winter Rye management plan. When triggered these events are handled by Farm and are available as information for other objects such as animal and bird models.

Constructor & Destructor Documentation

◆ PTWinterRye()

PTWinterRye::PTWinterRye ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
90  : Crop(a_tov, a_toc, a_L)
91  {
92  // When we start it off, the first possible date for a farm operation is 15th November
93  // This information is used by other crops when they decide how much post processing of
94  // the management is allowed after harvest before the next crop starts.
95  m_first_date=g_date->DayInYear( 15,11 );
97  }

References Calendar::DayInYear(), g_date, Crop::m_first_date, and SetUpFarmCategoryInformation().

Member Function Documentation

◆ Do()

bool PTWinterRye::Do ( Farm a_farm,
LE a_field,
FarmEvent a_ev 
)
virtual

The one and only method for a crop management plan. All farm actions go through here.

Called every time something is done to the crop by the farmer in the first instance it is always called with m_ev->todo set to start, but subsequently will be called whenever the farmer wants to carry out a new operation.
This method details all the management and relationships between operations necessary to grow and ALMaSS crop - in this case conventional Winter Rye.

Reimplemented from Crop.

55 {
56  /******************** This block can be added to the top of all Crop::Do methods ***********************************************/
57  m_farm = a_farm; // These assignments are necessary, not for this method but for related event calls
58  m_field = a_field;
59  m_ev = a_ev;
60  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
61  int d1 = 0;
62  TTypesOfVegetation l_tov = tov_PTWinterRye; // The current type - change to match the crop you have
63 /**********************************************To Here *************************************************************************/
64 
65  // Depending what event has occured jump to the correct bit of code
66  switch (m_ev->m_todo)
67  {
68  case pt_wr_start:
69  {
71 
72  m_last_date = g_date->DayInYear(10, 8); // Should match the last flexdate below
73  //Create a 2d array of 1 plus the number of operations you use. Change only 4+1 to what you need in the line below
74  std::vector<std::vector<int>> flexdates(1 + 1, std::vector<int>(2, 0));
75  // Set up the date management stuff
76  // Start and stop dates for all events after harvest
77  flexdates[0][1] = g_date->DayInYear(10, 8); // last possible day of harvest - this is in effect day before the earliest date that a following crop can use
78 
79  flexdates[1][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 1 (start op 1)
80  flexdates[1][1] = g_date->DayInYear(10, 8); // This date will be moved back as far as necessary and potentially to flexdates 1 (end op 1)
81 
82  // Below if this is a spring crop use 365, otherwise set this to 0, second parameter is fixed, and the third is the start up operation in the first year
83  int isSpring = 0;
84  if (StartUpCrop(isSpring, flexdates, int(pt_wr_harvest1))) break;
85 
86  // End single block date checking code. Please see next line comment as well.
87  // Reinit d1 to first possible starting date.
88  d1 = g_date->OldDays() + g_date->DayInYear(10, 9) + isSpring;
89  // OK, let's go.
90  // Here we queue up the first event which changes dependent on whether it is a forced spring sow or not
92  break;
93  }
94  break;
95 
96  // This is the first real farm operation
98  if (m_ev->m_lock || m_farm->DoIt_prob(0.50))
99  {
100  if (!m_farm->StubbleHarrowing(m_field, 0.0, g_date->DayInYear(20, 11) - g_date->DayInYear())) {
102  break;
103  }// Fork of two events: NPK/organic and calcium
104  if (m_farm->IsStockFarmer()) //Stock Farmer // slurry thread
105  {
107  }
108  else SimpleEvent_(g_date->Date()+1, pt_wr_ferti_p1, false, m_farm, m_field);
109  if (m_farm->IsStockFarmer()) //Stock Farmer // calcium thread
110  {
112  }
113  else SimpleEvent_(g_date->Date()+1, pt_wr_ferti_p3, false, m_farm, m_field);
114  break;
115  }
116  d1 = g_date->Date();
117  if (d1 < g_date->OldDays() + g_date->DayInYear(15, 9)) {
118  d1 = g_date->OldDays() + g_date->DayInYear(15, 9);
119  }
121  break;
122  case pt_wr_ferti_s1:
123  if (m_ev->m_lock || m_farm->DoIt_prob(0.25))
124  {
125  if (!m_farm->FA_Slurry(m_field, 0.0, g_date->DayInYear(21, 11) - g_date->DayInYear())) {
127  break;
128  }
130  break;
131  }
133  break;
134  case pt_wr_ferti_p1:
135  if (m_ev->m_lock || m_farm->DoIt_prob(0.25))
136  {
137  if (!m_farm->FP_Slurry(m_field, 0.0, g_date->DayInYear(21, 11) - g_date->DayInYear())) {
139  break;
140  }
142  break;
143  }
145  break;
146  case pt_wr_ferti_s2:
147  if (!m_farm->FA_NPK(m_field, 0.0, g_date->DayInYear(22, 11) - g_date->DayInYear())) {
149  break;
150  }
152  break;
153  case pt_wr_ferti_p2:
154  if (!m_farm->FP_NPK(m_field, 0.0, g_date->DayInYear(22, 11) - g_date->DayInYear())) {
156  break;
157  }
159  break;
160  case pt_wr_ferti_s3:
161  if (m_ev->m_lock || m_farm->DoIt_prob(0.50))
162  {
163  if (!m_farm->FA_Calcium(m_field, 0.0, g_date->DayInYear(21, 11) - g_date->DayInYear())) {
165  break;
166  }
167  }
168  // End of thread
169  break;
170  case pt_wr_ferti_p3:
171  if (m_ev->m_lock || m_farm->DoIt_prob(0.50))
172  {
173  if (!m_farm->FP_Calcium(m_field, 0.0, g_date->DayInYear(21, 11) - g_date->DayInYear())) {
175  break;
176  }
177  }
178  // End of thread
179  break;
180  case pt_wr_autumn_harrow:
181  if (!m_farm->AutumnHarrow(m_field, 0.0, g_date->DayInYear(23, 11) - g_date->DayInYear())) {
183  break;
184  }
186  break;
187  case pt_wr_autumn_sow:
188  if (!m_farm->AutumnSow(m_field, 0.0, g_date->DayInYear(24, 11) - g_date->DayInYear())) {
190  break;
191  }
192  if (m_farm->DoIt_prob(0.90))
193  {
195  }
196  else
197  {
198  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 7) + 365, pt_wr_harvest2, false, m_farm, m_field);
199  }
200  break;
204  break;
205  }
206  // Fork of two events: NPK/organic and calcium
207  if (m_farm->IsStockFarmer()) //Stock Farmer // NPK thread
208  {
210  }
211  else SimpleEvent_(g_date->Date()+1, pt_wr_ferti_p4, false, m_farm, m_field);
212  if (m_farm->IsStockFarmer()) //Stock Farmer // calcium thread
213  {
215  }
216  else SimpleEvent_(g_date->Date()+1, pt_wr_ferti_p3, false, m_farm, m_field);
217  break;
218  case pt_wr_ferti_s4:
219  if (m_ev->m_lock || m_farm->DoIt_prob(0.75))
220  {
221  if (!m_farm->FA_NPK(m_field, 0.0, g_date->DayInYear(16, 11) - g_date->DayInYear())) {
223  break;
224  }
225  }
227  break;
228  case pt_wr_ferti_p4:
229  if (m_ev->m_lock || m_farm->DoIt_prob(0.75))
230  {
231  if (!m_farm->FP_NPK(m_field, 0.0, g_date->DayInYear(16, 11) - g_date->DayInYear())) {
233  break;
234  }
235  }
237  break;
238  case pt_wr_harvest1:
239  if (!m_farm->Harvest(m_field, 0.0, g_date->DayInYear(25, 5) - g_date->DayInYear())) {
241  break;
242  }
244  break;
245  case pt_wr_wait:
246  done = true;
247  break;
248  // End of Thread
249  case pt_wr_harvest2:
250  if (!m_farm->Harvest(m_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
252  break;
253  }
254  done = true;
255  // So we are done, and somwhere else the farmer will queue up the start event of the next crop
256  // END of MAIN THREAD
257  break;
258  default:
259  g_msg->Warn(WARN_BUG, "PTWinterRye::Do(): "
260  "Unknown event type! ", "");
261  exit(1);
262  }
263  return done;
264 }

References Farm::AutumnHarrow(), Farm::AutumnSow(), LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt_prob(), Farm::FA_Calcium(), Farm::FA_NPK(), Farm::FA_Slurry(), Farm::FP_Calcium(), Farm::FP_NPK(), Farm::FP_Slurry(), g_date, g_msg, LE::GetMDates(), Farm::Harvest(), Farm::IsStockFarmer(), Crop::m_ev, Crop::m_farm, Crop::m_field, Crop::m_last_date, FarmEvent::m_lock, FarmEvent::m_todo, Calendar::OldDays(), Farm::PreseedingCultivatorSow(), pt_wr_autumn_harrow, pt_wr_autumn_sow, pt_wr_ferti_p1, pt_wr_ferti_p2, pt_wr_ferti_p3, pt_wr_ferti_p4, pt_wr_ferti_s1, pt_wr_ferti_s2, pt_wr_ferti_s3, pt_wr_ferti_s4, pt_wr_harvest1, pt_wr_harvest2, pt_wr_preseeding_cultivator_sow, pt_wr_start, pt_wr_stubble_harrow, pt_wr_wait, Crop::SimpleEvent(), Crop::SimpleEvent_(), Crop::StartUpCrop(), Farm::StubbleHarrowing(), tov_PTWinterRye, MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void PTWinterRye::SetUpFarmCategoryInformation ( )
inline
98  {
99  const int elements = 2 + (pt_wr_foobar - PTWINTERRYE_BASE);
101 
102  FarmManagementCategory catlist[elements] =
103  {
104  fmc_Others, // zero element unused but must be here
105  fmc_Others, //pt_wr_start = 1, // Compulsory, must always be 1 (one).
106  fmc_Others, //pt_wr_sleep_all_day = PTWINTERRYE_BASE,
107  fmc_Cultivation, //pt_wr_stubble_harrow,
108  fmc_Fertilizer, //pt_wr_ferti_p1, // slurry
109  fmc_Fertilizer, //pt_wr_ferti_s1,
110  fmc_Fertilizer, //pt_wr_ferti_p2, // NPK
111  fmc_Fertilizer, //pt_wr_ferti_s2,
112  fmc_Fertilizer, //pt_wr_ferti_p3, // Calcium
113  fmc_Fertilizer, //pt_wr_ferti_s3,
114  fmc_Fertilizer, //pt_wr_ferti_p4, // NPK
115  fmc_Fertilizer, //pt_wr_ferti_s4,
116  fmc_Cultivation, //pt_wr_autumn_harrow,
117  fmc_Others, //pt_wr_autumn_sow,
118  fmc_Cultivation, //pt_wr_preseeding_cultivator_sow,
119  fmc_Harvest, //pt_wr_harvest1,
120  fmc_Others, //pt_wr_wait,
121  fmc_Harvest, //pt_wr_harvest2,
122 
123  // no foobar entry
124 
125  };
126  // Iterate over the catlist elements and copy them to vector
127  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
128 
129  }

References fmc_Cultivation, fmc_Fertilizer, fmc_Harvest, fmc_Others, Crop::m_base_elements_no, Crop::m_ManagementCategories, pt_wr_foobar, and PTWINTERRYE_BASE.

Referenced by PTWinterRye().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
Farm::FA_Slurry
virtual bool FA_Slurry(LE *a_field, double a_user, int a_days)
Spready slurry on a_field owned by an stock farmer.
Definition: FarmFuncs.cpp:1067
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: Farm.h:961
Farm::Harvest
virtual bool Harvest(LE *a_field, double a_user, int a_days)
Carry out a harvest on a_field.
Definition: FarmFuncs.cpp:1364
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
pt_wr_autumn_harrow
Definition: PTWinterRye.h:67
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
Farm::FP_NPK
virtual bool FP_NPK(LE *a_field, double a_user, int a_days)
Apply NPK fertilizer, on a_field owned by an arable farmer.
Definition: FarmFuncs.cpp:645
pt_wr_ferti_s3
Definition: PTWinterRye.h:64
pt_wr_harvest1
Definition: PTWinterRye.h:70
Farm::DoIt_prob
bool DoIt_prob(double a_probability)
Return chance out of 0 to 1.
Definition: Farm.cpp:864
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
Farm::FA_NPK
virtual bool FA_NPK(LE *a_field, double a_user, int a_days)
Apply NPK fertilizer to a_field owned by an stock farmer.
Definition: FarmFuncs.cpp:982
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
pt_wr_ferti_p3
Definition: PTWinterRye.h:63
pt_wr_ferti_s1
Definition: PTWinterRye.h:60
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
pt_wr_start
Definition: PTWinterRye.h:56
pt_wr_autumn_sow
Definition: PTWinterRye.h:68
pt_wr_ferti_p1
Definition: PTWinterRye.h:59
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
Farm::FA_Calcium
virtual bool FA_Calcium(LE *a_field, double a_user, int a_days)
Calcium applied on a_field owned by a stock farmer.
Definition: FarmFuncs.cpp:1168
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
Farm::FP_Calcium
virtual bool FP_Calcium(LE *a_field, double a_user, int a_days)
Calcium applied on a_field owned by an arable farmer.
Definition: FarmFuncs.cpp:954
Crop::StartUpCrop
bool StartUpCrop(int a_spring, std::vector< std::vector< int >> a_flexdates, int a_todo)
Holds the translation between the farm operation enum for each cropand the farm management category a...
Definition: Farm.cpp:652
pt_wr_ferti_p2
Definition: PTWinterRye.h:61
Crop::m_farm
Farm * m_farm
Definition: Farm.h:498
Crop::m_field
LE * m_field
Definition: Farm.h:499
Crop::m_ManagementCategories
vector< FarmManagementCategory > m_ManagementCategories
Holds the translation between the farm operation enum for each crop and the farm management category ...
Definition: Farm.h:530
pt_wr_stubble_harrow
Definition: PTWinterRye.h:58
pt_wr_preseeding_cultivator_sow
Definition: PTWinterRye.h:69
Farm::PreseedingCultivatorSow
virtual bool PreseedingCultivatorSow(LE *a_field, double a_user, int a_days, double a_seed_coating_amount=-1, PlantProtectionProducts a_ppp=ppp_foobar)
Carry out preseeding cultivation together with sow on a_field (tilling and sowing set including culti...
Definition: FarmFuncs.cpp:325
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
Farm::FP_Slurry
virtual bool FP_Slurry(LE *a_field, double a_user, int a_days)
Apply slurry to a_field owned by an arable farmer.
Definition: FarmFuncs.cpp:823
PTWinterRye::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: PTWinterRye.h:98
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
Farm::AutumnHarrow
virtual bool AutumnHarrow(LE *a_field, double a_user, int a_days)
Carry out a harrow event in the autumn on a_field.
Definition: FarmFuncs.cpp:285
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
pt_wr_wait
Definition: PTWinterRye.h:71
Farm::AutumnSow
virtual bool AutumnSow(LE *a_field, double a_user, int a_days, double a_seed_coating_amount=-1, PlantProtectionProducts a_ppp=ppp_foobar)
Carry out a sowing event in the autumn on a_field.
Definition: FarmFuncs.cpp:360
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
pt_wr_ferti_s4
Definition: PTWinterRye.h:66
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
pt_wr_foobar
Definition: PTWinterRye.h:73
PTWINTERRYE_BASE
#define PTWINTERRYE_BASE
Definition: PTWinterRye.h:45
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
pt_wr_ferti_p4
Definition: PTWinterRye.h:65
pt_wr_ferti_s2
Definition: PTWinterRye.h:62
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
tov_PTWinterRye
Definition: LandscapeFarmingEnums.h:323
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
pt_wr_harvest2
Definition: PTWinterRye.h:72
Farm::StubbleHarrowing
virtual bool StubbleHarrowing(LE *a_field, double a_user, int a_days)
Carry out stubble harrowing on a_field.
Definition: FarmFuncs.cpp:1523
Crop::SimpleEvent_
void SimpleEvent_(long a_date, int a_todo, bool a_lock, Farm *a_farm, LE *a_field)
Adds an event to this crop management without relying on member variables.
Definition: Farm.cpp:751