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
PTFodderMix Class Reference

PTFodderMix class
. More...

#include <PTFodderMix.h>

Inheritance diagram for PTFodderMix:
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...
 
 PTFodderMix (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

PTFodderMix class
.

See PTFodderMix.h::PTFodderMixToDo for a complete list of all possible events triggered codes by the fodder lucerne1 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

◆ PTFodderMix()

PTFodderMix::PTFodderMix ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
91  : Crop(a_tov, a_toc, a_L)
92  {
93  // When we start it off, the first possible date for a farm operation is 31th October
94  // This information is used by other crops when they decide how much post processing of
95  // the management is allowed after harvest before the next crop starts.
96  m_first_date=g_date->DayInYear( 31,10 );//@AAS:Last possible date to do the first operation, i.e. stubble harrow
98  }

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

Member Function Documentation

◆ Do()

bool PTFodderMix::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 susequently 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 fodder lucerne in the first year.

Reimplemented from Crop.

56 {
57  /******************** This block can be added to the top of all Crop::Do methods ***********************************************/
58  m_farm = a_farm; // These assignments are necessary, not for this method but for related event calls
59  m_field = a_field;
60  m_ev = a_ev;
61  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
62  int d1 = 0;
63  TTypesOfVegetation l_tov = tov_PTFodderMix; // The current type - change to match the crop you have
64 /**********************************************To Here *************************************************************************/
65 
66  // Depending what event has occured jump to the correct bit of code
67  switch (m_ev->m_todo)
68  {
69  case pt_fm_start:
70  {
72 
74 
75  m_last_date = g_date->DayInYear(1, 7); // Should match the last flexdate below
76  //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
77  std::vector<std::vector<int>> flexdates(1 + 1, std::vector<int>(2, 0));
78  // Set up the date management stuff
79  // Start and stop dates for all events after harvest
80  flexdates[0][1] = g_date->DayInYear(1, 7); // last possible day of harvest - this is in effect day before the earliest date that a following crop can use
81 
82  flexdates[1][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 1 (start op 1)
83  flexdates[1][1] = g_date->DayInYear(1, 7); // This date will be moved back as far as necessary and potentially to flexdates 1 (end op 1)
84 
85  // 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
86  int isSpring = 0;
87  if (StartUpCrop(isSpring, flexdates, int(pt_fm_cut_to_silage))) break;
88 
89  // End single block date checking code. Please see next line comment as well.
90  // Reinit d1 to first possible starting date.
91  d1 = g_date->OldDays() + g_date->DayInYear(15, 9) + isSpring;
92  // OK, let's go.
93  // Here we queue up the first event which changes dependent on whether it is a forced spring sow or not
95  break;
96  }
97  break;
98 
99  // This is the first real farm operation
100 
102  if (!m_farm->StubbleHarrowing(m_field, 0.0, g_date->DayInYear(31, 10) - g_date->DayInYear())) {
104  break;
105  }
107  break;
108  case pt_fm_autumn_plough:
109  if (!m_farm->AutumnPlough(m_field, 0.0, g_date->DayInYear(31, 10) - g_date->DayInYear())) {
111  break;
112  }
113  // Fork of two events: NPK and calcium
114  if (m_farm->IsStockFarmer()) //Stock Farmer // NPK thread:main
115  {
117  }
119  if (m_farm->IsStockFarmer()) //Stock Farmer // calcium thread
120  {
122  }
124  break;
125 
126  case pt_fm_ferti_s1:
127  if (!m_farm->FA_NPK(m_field, 0.0, g_date->DayInYear(1, 11) - g_date->DayInYear())) {
129  break;
130  }
132  break;
133  case pt_fm_ferti_p1:
134  if (!m_farm->FP_NPK(m_field, 0.0, g_date->DayInYear(1, 11) - g_date->DayInYear())) {
136  break;
137  }
139  break;
140 
141  //------------------- calcium application
142  case pt_fm_ferti_s2:
143  if (!m_farm->FA_Calcium(m_field, 0.0, g_date->DayInYear(1, 11) - g_date->DayInYear())) {
145  break;
146  }
147  // End of thread
148  break;
149  case pt_fm_ferti_p2:
150  if (!m_farm->FP_Calcium(m_field, 0.0, g_date->DayInYear(1, 11) - g_date->DayInYear())) {
152  break;
153  }
154  // End of thread
155  break;
156  //------------------- calcium application
157 
158 
160  if (!m_farm->StubbleHarrowing(m_field, 0.0, g_date->DayInYear(2, 11) - g_date->DayInYear())) {
162  break;
163  }
165  break;
166 
167  case pt_fm_autumn_sow:
168  if (!m_farm->AutumnSow(m_field, 0.0, g_date->DayInYear(3, 11) - g_date->DayInYear())) {
170  break;
171  }
172  if (m_farm->DoIt_prob(0.10))
173  {
175  }
176  else SimpleEvent_(g_date->OldDays() + g_date->DayInYear(20, 4) + 365, pt_fm_harvest, false, m_farm, m_field);
177  break;
178  case pt_fm_cut_to_silage:
179  if (!m_farm->CutToSilage(m_field, 0.0, g_date->DayInYear(30, 5) - g_date->DayInYear())) {
181  break;
182  }
184  break;
185  case pt_fm_harvest:
186  if (!m_farm->Harvest(m_field, 0.0, g_date->DayInYear(30, 5) - g_date->DayInYear())) {
188  break;
189  }
190  if (m_farm->DoIt_prob(0.33))
191  {
193  }
194  else SimpleEvent_(g_date->Date() + 8, pt_fm_hay_bailing, false, m_farm, m_field);
195  break;
196  case pt_fm_hay_bailing:
197  if (!m_farm->HayBailing(m_field, 0.0, g_date->DayInYear(8, 6) - g_date->DayInYear())) {
199  break;
200  }
202  break;
203  case pt_fm_cattle_out:
204  if (!m_farm->CattleOutLowGrazing(m_field, 0.0, g_date->DayInYear(10, 6) - g_date->DayInYear())) {
206  break;
207  }
210  break;
211  case pt_fm_cattle_is_out: // Keep the cattle out there
212  // CattleIsOutLow() returns false if it is not time to stop grazing
215  break;
216  }
218  break;
219  case pt_fm_wait:
220  done = true;
221  break;
222  // End of Thread
223  default:
224  g_msg->Warn(WARN_BUG, "PTFodderMix::Do(): "
225  "Unknown event type! ", "");
226  exit(1);
227  }
228  return done;
229 }

References Farm::AutumnPlough(), Farm::AutumnSow(), Farm::CattleIsOutLow2(), Farm::CattleOutLowGrazing(), LE::ClearManagementActionSum(), Farm::CutToSilage(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt_prob(), Farm::FA_Calcium(), Farm::FA_NPK(), Farm::FP_Calcium(), Farm::FP_NPK(), g_date, g_msg, Farm::Harvest(), Farm::HayBailing(), Farm::IsStockFarmer(), Crop::m_ev, Crop::m_farm, Crop::m_field, Crop::m_last_date, FarmEvent::m_todo, Calendar::OldDays(), PT_FM1_CATTLEOUT_DATE, pt_fm_autumn_plough, pt_fm_autumn_sow, pt_fm_cattle_is_out, pt_fm_cattle_out, pt_fm_cut_to_silage, pt_fm_ferti_p1, pt_fm_ferti_p2, pt_fm_ferti_s1, pt_fm_ferti_s2, pt_fm_harvest, pt_fm_hay_bailing, pt_fm_start, pt_fm_stubble_harrow1, pt_fm_stubble_harrow2, pt_fm_wait, Crop::SimpleEvent(), Crop::SimpleEvent_(), Crop::StartUpCrop(), Farm::StubbleHarrowing(), tov_PTFodderMix, MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void PTFodderMix::SetUpFarmCategoryInformation ( )
inline
99  {
100  const int elements = 2 + (pt_fm_foobar - PTFODDERMIX_BASE);
102 
103  FarmManagementCategory catlist[elements] =
104  {
105  fmc_Others, // zero element unused but must be here
106  fmc_Others, //pt_fm_start = 1, // Compulsory, must always be 1 (one).
107  fmc_Others, //pt_fm_sleep_all_day = PTFODDERMIX_BASE,
108  fmc_Cultivation, //pt_fm_stubble_harrow1,
109  fmc_Cultivation, //pt_fm_autumn_plough,
110  fmc_Fertilizer, //pt_fm_ferti_p1,//NPK
111  fmc_Fertilizer, //pt_fm_ferti_s1,
112  fmc_Fertilizer, //pt_fm_ferti_p2,//Calcium
113  fmc_Fertilizer, //pt_fm_ferti_s2,
114  fmc_Cultivation, //pt_fm_stubble_harrow2,
115  fmc_Others, //pt_fm_autumn_sow,
116  fmc_Cutting, //pt_fm_cut_to_silage,
117  fmc_Harvest, //pt_fm_harvest,
118  fmc_Others, //pt_fm_hay_bailing,
119  fmc_Grazing, //pt_fm_cattle_out,
120  fmc_Grazing, //pt_fm_cattle_is_out,
121  fmc_Others, //pt_fm_wait,
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_Cutting, fmc_Fertilizer, fmc_Grazing, fmc_Harvest, fmc_Others, Crop::m_base_elements_no, Crop::m_ManagementCategories, pt_fm_foobar, and PTFODDERMIX_BASE.

Referenced by PTFodderMix().


The documentation for this class was generated from the following files:
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
PT_FM1_CATTLEOUT_DATE
#define PT_FM1_CATTLEOUT_DATE
A flag used to indicate cattle out dates.
Definition: PTFodderMix.h:49
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
Farm::CutToSilage
virtual bool CutToSilage(LE *a_field, double a_user, int a_days)
Cut vegetation for silage on a_field.
Definition: FarmFuncs.cpp:1644
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
pt_fm_start
Definition: PTFodderMix.h:58
Farm::CattleIsOutLow2
virtual bool CattleIsOutLow2(LE *a_field, double a_user, int a_days, int a_max, int a_max_days)
Generate a 'cattle_out_low2' event for every day the cattle are on a_field, cattle is low grazing and...
Definition: FarmFuncs.cpp:2607
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
Farm::CattleOutLowGrazing
virtual bool CattleOutLowGrazing(LE *a_field, double a_user, int a_days)
Start a extensive grazing event on a_field today.
Definition: FarmFuncs.cpp:2439
pt_fm_stubble_harrow2
Definition: PTFodderMix.h:66
PTFodderMix::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: PTFodderMix.h:99
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
pt_fm_autumn_plough
Definition: PTFodderMix.h:61
pt_fm_ferti_s1
Definition: PTFodderMix.h:63
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
Calendar::Date
long Date(void)
Definition: Calendar.h:57
tov_PTFodderMix
Definition: LandscapeFarmingEnums.h:312
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
Farm::HayBailing
virtual bool HayBailing(LE *a_field, double a_user, int a_days)
Carry out hay bailing on a_field.
Definition: FarmFuncs.cpp:1507
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
pt_fm_cattle_out
Definition: PTFodderMix.h:71
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_fm_wait
Definition: PTFodderMix.h:73
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
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
pt_fm_stubble_harrow1
Definition: PTFodderMix.h:60
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
pt_fm_harvest
Definition: PTFodderMix.h:69
Farm::AutumnPlough
virtual bool AutumnPlough(LE *a_field, double a_user, int a_days)
Carry out a ploughing event in the autumn on a_field.
Definition: FarmFuncs.cpp:212
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
pt_fm_hay_bailing
Definition: PTFodderMix.h:70
pt_fm_ferti_p1
Definition: PTFodderMix.h:62
pt_fm_foobar
Definition: PTFodderMix.h:74
fmc_Grazing
Definition: LandscapeFarmingEnums.h:1010
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
pt_fm_cut_to_silage
Definition: PTFodderMix.h:68
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
pt_fm_ferti_s2
Definition: PTFodderMix.h:65
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
pt_fm_ferti_p2
Definition: PTFodderMix.h:64
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
pt_fm_autumn_sow
Definition: PTFodderMix.h:67
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
pt_fm_cattle_is_out
Definition: PTFodderMix.h:72
PTFODDERMIX_BASE
#define PTFODDERMIX_BASE
Definition: PTFodderMix.h:45
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
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