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

FI_GrasslandPasturePerennial2 class
. More...

#include <FI_GrasslandPasturePerennial2.h>

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

FI_GrasslandPasturePerennial2 class
.

See FI_GrasslandPasturePerennial2.h::FI_GrasslandPasturePerennial2ToDo for a complete list of all possible events triggered codes by the GrasslandPasturePerennial2 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

◆ FI_GrasslandPasturePerennial2()

FI_GrasslandPasturePerennial2::FI_GrasslandPasturePerennial2 ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
94  : Crop(a_tov, a_toc, a_L)
95  {
96  // When we start it off, the first possible date for a farm operation is 1st October
97  // This information is used by other crops when they decide how much post processing of
98  // the management is allowed after harvest before the next crop starts.
100  m_forcespringpossible = true;
102  }

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

Member Function Documentation

◆ Do()

bool FI_GrasslandPasturePerennial2::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 a_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 spring barley Fodder.

Reimplemented from Crop.

99 {
100  m_field = a_field; // this is needed because of possible calls to other methods and currently we do not pass parameters.
101  m_farm = a_farm; // this is needed because of possible calls to other methods and currently we do not pass parameters.
102  m_ev = a_ev;
103  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
104  int d1 = 0;
106  int l_nextcropstartdate;
107  // Depending what event has occured jump to the correct bit of code e.g. for ww_start jump to line 67 below
108  switch (m_ev->m_todo)
109  {
110  case fi_gpp2_start:
111  {
112 
113  a_field->ClearManagementActionSum();
114 
115  m_last_date = g_date->DayInYear(1, 11); // Should match the last flexdate below
116  //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
117  std::vector<std::vector<int>> flexdates(1 + 1, std::vector<int>(2, 0));
118  // Set up the date management stuff
119  // Start and stop dates for all events after
120  flexdates[0][1] = g_date->DayInYear(1, 11); // last possible day of strigling in this case
121  // Now these are done in pairs, start & end for each operation. If its not used then -1
122 
123 
124  // Below if this is a spring crop use 365, otherwise first parameter is always 0, second parameter is fixed, and the third is the start up operation in the first year
125  int isSpring = 365;
126  if (StartUpCrop(isSpring, flexdates, int(fi_gpp2_npk1))) break;
127  d1 = g_date->OldDays() + g_date->DayInYear(20, 4) + 365;
128  if (m_ev->m_forcespring) {
129  int day_num_shift = 365;
130  if (g_date->DayInYear() < 70) day_num_shift = 0;
131  SimpleEvent(g_date->OldDays() + g_date->DayInYear(20, 4) + day_num_shift, fi_gpp2_npk1, false);
132  break;
133  }
134  else SimpleEvent(d1, fi_gpp2_npk1, false);
135  break;
136  }
137  break;
138 
139  case fi_gpp2_npk1: // 90% do this
140  if (m_ev->m_lock || m_farm->DoIt(90)) {
141  if (!m_farm->FA_NPK(m_field, 0.0,
142  g_date->DayInYear(30, 5) - g_date->DayInYear())) {
143  SimpleEvent(g_date->Date() + 1, fi_gpp2_npk1, true);
144  break;
145  }
146  }
148  break;
149  case fi_gpp2_grazing1: // 100% do grazing - end time is a suggestion
150  if (m_ev->m_lock || m_farm->DoIt(100)) {
151  if (!m_farm->CattleOut(m_field, 0.0,
152  g_date->DayInYear(1, 7) - g_date->DayInYear())) {
153  SimpleEvent(g_date->Date() + 1, fi_gpp2_grazing1, true);
154  break;
155  } // Keep them out there
157  break;
158  }
159  SimpleEvent(g_date->Date() < 5, fi_gpp2_npk2, false);
160  break;
161  case fi_ggp2_cattle_is_out1: // Keep the cattle out there
162  // CattleIsOut() returns false if it is not time to stop grazing
163  if (!m_farm->CattleIsOut(m_field, 0.0, g_date->DayInYear(5, 7) - g_date->DayInYear(), g_date->DayInYear(5, 7))) {
165  break;
166  }
167  SimpleEvent(g_date->Date() <5, fi_gpp2_npk2, false);
168  break;
169  case fi_gpp2_npk2: // 90% do this
170  if (m_ev->m_lock || m_farm->DoIt(90)) {
171  if (!m_farm->FA_NPK(m_field, 0.0,
172  g_date->DayInYear(10, 7) - g_date->DayInYear())) {
173  SimpleEvent(g_date->Date() + 1, fi_gpp2_npk2, true);
174  break;
175  }
176  }
177  SimpleEvent(g_date->Date() + 21, fi_gpp2_grazing2, false);
178  break;
179  case fi_gpp2_grazing2: // 90% do grazing
180  if (m_ev->m_lock || m_farm->DoIt(90)) {
181  if (!m_farm->CattleOut(m_field, 0.0,
182  g_date->DayInYear(31, 7) - g_date->DayInYear())) {
183  SimpleEvent(g_date->Date() + 1, fi_gpp2_grazing2, true);
184  break;
185  }
187  break;
188  }
189  else done = true;
190  break;
191  case fi_ggp2_cattle_is_out2: // Keep the cattle out there
192  // CattleIsOut() returns false if it is not time to stop grazing
193  if (!m_farm->CattleIsOut(m_field, 0.0, g_date->DayInYear(15, 8) - g_date->DayInYear(), g_date->DayInYear(15, 9))) {
195  break;
196  }
197  SimpleEvent(g_date->Date() <5, fi_gpp2_npk3, false);
198  break;
199  case fi_gpp2_npk3: // 50% of the 90% (45% of all farmers)
200  if (m_ev->m_lock || m_farm->DoIt(50)) {
201  if (!m_farm->FA_NPK(m_field, 0.0,
202  g_date->DayInYear(20, 8) - g_date->DayInYear())) {
203  SimpleEvent(g_date->Date() + 1, fi_gpp2_npk3, true);
204  break;
205  }
206  }
207  SimpleEvent(g_date->Date() + 21, fi_gpp2_grazing3, false);
208  break;
209  case fi_gpp2_grazing3: // 40% do grazing of all farmers (44% of the 90%)
210  if (m_ev->m_lock || m_farm->DoIt(44)) {
211  if (!m_farm->CattleOut(m_field, 0.0,
212  g_date->DayInYear(10, 9) - g_date->DayInYear())) {
213  SimpleEvent(g_date->Date() + 1, fi_gpp2_grazing3, true);
214  break;
215  }
217  break;
218  }
219  else done = true;
220  break;
221  case fi_ggp2_cattle_is_out3: // Keep the cattle out there
222  // CattleIsOut() returns false if it is not time to stop grazing
223  if (!m_farm->CattleIsOut(m_field, 0.0, g_date->DayInYear(25, 9) - g_date->DayInYear(), g_date->DayInYear(25, 9))) {
225  break;
226  }
227  SimpleEvent(g_date->Date() <5, fi_gpp2_npk4, false);
228  break;
229  case fi_gpp2_npk4: // 10% of the 44% (4.4% of all farmers))
230  if (m_ev->m_lock || m_farm->DoIt(10)) {
231  if (!m_farm->FA_NPK(m_field, 0.0,
232  g_date->DayInYear(1, 10) - g_date->DayInYear())) {
233  SimpleEvent(g_date->Date() + 1, fi_gpp2_npk4, true);
234  break;
235  }
236  }
237  SimpleEvent(g_date->Date() + 21, fi_gpp2_grazing4, false);
238  break;
239  case fi_gpp2_grazing4: // 5% do grazing (11% of the 44% left)
240  if (m_ev->m_lock || m_farm->DoIt(11)) {
241  if (!m_farm->CattleOut(m_field, 0.0,
242  g_date->DayInYear(24, 10) - g_date->DayInYear())) {
243  SimpleEvent(g_date->Date() + 1, fi_gpp2_grazing4, true);
244  break;
245  }
247  break;
248  }
249  else done = true;
250  break;
251  case fi_ggp2_cattle_is_out4: // Keep the cattle out there
252  // CattleIsOut() returns false if it is not time to stop grazing
253  if (!m_farm->CattleIsOut(m_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear(), m_field->GetMDates(1, 0))) {
255  break;
256  }
257  done = true;
258  // So we are done, and somewhere else the farmer will queue up the start event of the next crop
259  // END OF MAIN THREAD
260  break;
261  default:
262  g_msg->Warn(WARN_BUG, "FI_GrasslandPasturePerennial2::Do(): "
263  "Unknown event type! ", "");
264  exit(1);
265  }
266  if (done) m_ev->m_forcespring = true; // Here we need to force the next crop to spring operation, so set the ev->forcespring to true
267  return done;
268 }

References Farm::CattleIsOut(), Farm::CattleOut(), LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt(), Farm::FA_NPK(), fi_ggp2_cattle_is_out1, fi_ggp2_cattle_is_out2, fi_ggp2_cattle_is_out3, fi_ggp2_cattle_is_out4, fi_gpp2_grazing1, fi_gpp2_grazing2, fi_gpp2_grazing3, fi_gpp2_grazing4, fi_gpp2_npk1, fi_gpp2_npk2, fi_gpp2_npk3, fi_gpp2_npk4, fi_gpp2_start, g_date, g_msg, LE::GetMDates(), Crop::m_ev, Crop::m_farm, Crop::m_field, FarmEvent::m_forcespring, Crop::m_last_date, FarmEvent::m_lock, FarmEvent::m_todo, Calendar::OldDays(), Crop::SimpleEvent(), Crop::StartUpCrop(), tov_FIGrasslandPasturePerennial2, MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void FI_GrasslandPasturePerennial2::SetUpFarmCategoryInformation ( )
inline
103  {
104  const int elements = 2 + (fi_ggp2_foobar - FI_GPP2_BASE);
106 
107  FarmManagementCategory catlist[elements] =
108  {
109  fmc_Others, // zero element unused but must be here
110  fmc_Others, // fi_gpp2_start = 1, // Compulsory, must always be 1 (one).
111  fmc_Others, // fi_gpp2_sleep_all_day = FI_GPP2_BASE,
112  fmc_Fertilizer, // fi_gpp2_npk1,
113  fmc_Grazing, // fi_gpp2_grazing1,
114  fmc_Grazing, // fi_ggp2_cattle_is_out1,
115  fmc_Fertilizer, // fi_gpp2_npk2,
116  fmc_Grazing, // fi_gpp2_grazing2,
117  fmc_Grazing, // fi_ggp2_cattle_is_out2,
118  fmc_Fertilizer, // fi_gpp2_npk3,
119  fmc_Grazing, // fi_gpp2_grazing3,
120  fmc_Grazing, // fi_ggp2_cattle_is_out3,
121  fmc_Fertilizer, // fi_gpp2_npk4,
122  fmc_Grazing, // fi_gpp2_grazing4,
123  fmc_Grazing // fi_ggp2_cattle_is_out4,
124 
125 
126  // no foobar entry
127 
128  };
129  // Iterate over the catlist elements and copy them to vector
130  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
131 
132  }

References fi_ggp2_foobar, FI_GPP2_BASE, fmc_Fertilizer, fmc_Grazing, fmc_Others, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by FI_GrasslandPasturePerennial2().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
fi_ggp2_foobar
Definition: FI_GrasslandPasturePerennial2.h:78
FarmEvent::m_forcespring
bool m_forcespring
Definition: Farm.h:392
fi_gpp2_grazing2
Definition: FI_GrasslandPasturePerennial2.h:70
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
Farm::CattleIsOut
virtual bool CattleIsOut(LE *a_field, double a_user, int a_days, int a_max)
Generate a 'cattle_out' event for every day the cattle are on a_field.
Definition: FarmFuncs.cpp:2470
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
fi_ggp2_cattle_is_out1
Definition: FI_GrasslandPasturePerennial2.h:68
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: Farm.cpp:856
tov_FIGrasslandPasturePerennial2
Definition: LandscapeFarmingEnums.h:557
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
fi_gpp2_npk3
Definition: FI_GrasslandPasturePerennial2.h:72
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
fi_gpp2_grazing3
Definition: FI_GrasslandPasturePerennial2.h:73
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
fi_gpp2_start
Definition: FI_GrasslandPasturePerennial2.h:64
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
fi_gpp2_npk1
Definition: FI_GrasslandPasturePerennial2.h:66
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
fi_gpp2_grazing1
Definition: FI_GrasslandPasturePerennial2.h:67
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
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
FI_GPP2_BASE
#define FI_GPP2_BASE
Definition: FI_GrasslandPasturePerennial2.h:53
fi_gpp2_npk2
Definition: FI_GrasslandPasturePerennial2.h:69
fi_ggp2_cattle_is_out4
Definition: FI_GrasslandPasturePerennial2.h:77
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
fi_ggp2_cattle_is_out3
Definition: FI_GrasslandPasturePerennial2.h:74
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
fi_gpp2_grazing4
Definition: FI_GrasslandPasturePerennial2.h:76
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
fmc_Grazing
Definition: LandscapeFarmingEnums.h:1010
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
FI_GrasslandPasturePerennial2::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: FI_GrasslandPasturePerennial2.h:103
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
fi_gpp2_npk4
Definition: FI_GrasslandPasturePerennial2.h:75
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
Crop::m_forcespringpossible
bool m_forcespringpossible
Used to signal that the crop can be forced to start in spring.
Definition: Farm.h:508
fi_ggp2_cattle_is_out2
Definition: FI_GrasslandPasturePerennial2.h:71
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
Farm::CattleOut
virtual bool CattleOut(LE *a_field, double a_user, int a_days)
Start a grazing event on a_field today.
Definition: FarmFuncs.cpp:2368
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001