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

FI_GrasslandSilagePerennial2 class
. More...

#include <FI_GrasslandSilagePerennial2.h>

Inheritance diagram for FI_GrasslandSilagePerennial2:
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_GrasslandSilagePerennial2 (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_GrasslandSilagePerennial2 class
.

See FI_GrasslandSilagePerennial2.h::FI_GrasslandSilagePerennial2ToDo for a complete list of all possible events triggered codes by the GrasslandSilagePerennial2 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_GrasslandSilagePerennial2()

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

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

Member Function Documentation

◆ Do()

bool FI_GrasslandSilagePerennial2::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_gsp2_start:
111  {
112 
113  a_field->ClearManagementActionSum();
114 
115  m_last_date = g_date->DayInYear(22, 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(22, 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_gsp2_npk1))) break;
127 
128  d1 = g_date->OldDays() + g_date->DayInYear(20, 4) + 365;
129  if (m_ev->m_forcespring) {
130  int day_num_shift = 365;
131  if (g_date->DayInYear() < 70) day_num_shift = 0;
132  SimpleEvent(g_date->OldDays() + g_date->DayInYear(20, 4) + day_num_shift, fi_gsp2_npk1, false);
133  break;
134  }
135  else SimpleEvent(d1, fi_gsp2_npk1, false);
136  break;
137  }
138  break;
139 
140  case fi_gsp2_npk1: // 90% do this
141  if (a_ev->m_lock || a_farm->DoIt(90)) {
142  if (!a_farm->FA_NPK(a_field, 0.0,
143  g_date->DayInYear(30, 5) - g_date->DayInYear())) {
144  SimpleEvent(g_date->Date() + 1, fi_gsp2_npk1, true);
145  break;
146  }
147  }
149  break;
150  case fi_gsp2_cutting1: // 100% do this
151  if (a_ev->m_lock || a_farm->DoIt(100)) {
152  if (!a_farm->CutToSilage(a_field, 0.0,
153  g_date->DayInYear(5, 8) - g_date->DayInYear())) {
154  SimpleEvent(g_date->Date() + 1, fi_gsp2_cutting1, true);
155  break;
156  }
157  }
158  SimpleEvent(g_date->Date() < 5, fi_gsp2_npk2, false);
159  break;
160  case fi_gsp2_npk2: // 80% do this
161  if (a_ev->m_lock || a_farm->DoIt(80)) {
162  if (!a_farm->FA_NPK(a_field, 0.0,
163  g_date->DayInYear(10, 8) - g_date->DayInYear())) {
164  SimpleEvent(g_date->Date() + 1, fi_gsp2_npk2, true);
165  break;
166  }
167  }
169  break;
170  case fi_gsp2_slurry2: // 30% do this
171  if (a_ev->m_lock || a_farm->DoIt(30)) {
172  if (!a_farm->FA_Slurry(a_field, 0.0,
173  g_date->DayInYear(10, 8) - g_date->DayInYear())) {
174  SimpleEvent(g_date->Date() + 1, fi_gsp2_slurry2, true);
175  break;
176  }
177  }
178  SimpleEvent(g_date->Date() + 21, fi_gsp2_cutting2, false);
179  break;
180  case fi_gsp2_cutting2: // 90% do this
181  if (a_ev->m_lock || a_farm->DoIt(90)) {
182  if (!a_farm->CutToSilage(a_field, 0.0,
183  g_date->DayInYear(31, 8) - g_date->DayInYear())) {
184  SimpleEvent(g_date->Date() + 1, fi_gsp2_cutting2, true);
185  break;
186  }
187  }
188  SimpleEvent(g_date->Date() < 5, fi_gsp2_npk3, false);
189  break;
190  case fi_gsp2_npk3: // 80% do this
191  if (a_ev->m_lock || a_farm->DoIt(80)) {
192  if (!a_farm->FA_NPK(a_field, 0.0,
193  g_date->DayInYear(5, 9) - g_date->DayInYear())) {
194  SimpleEvent(g_date->Date() + 1, fi_gsp2_npk3, true);
195  break;
196  }
197  }
199  break;
200  case fi_gsp2_slurry3: // 20% do this
201  if (a_ev->m_lock || a_farm->DoIt(20)) {
202  if (!a_farm->FA_Slurry(a_field, 0.0,
203  g_date->DayInYear(10, 8) - g_date->DayInYear())) {
204  SimpleEvent(g_date->Date() + 1, fi_gsp2_slurry3, true);
205  break;
206  }
207  }
208  SimpleEvent(g_date->Date() + 21, fi_gsp2_cutting3, false);
209  break;
210  case fi_gsp2_cutting3: // 40% do grazing
211  if (a_ev->m_lock || a_farm->DoIt_prob(.20)) {
212  if (!a_farm->CutToSilage(a_field, 0.0,
213  g_date->DayInYear(26, 9) - g_date->DayInYear())) {
214  SimpleEvent(g_date->Date() + 1, fi_gsp2_cutting3, true);
215  break;
216  }
217  }
218  else if (a_ev->m_lock || a_farm->DoIt_prob(.20 / .80)) {
220  break;
221  }
222  SimpleEvent(g_date->Date() < 5, fi_gsp2_npk4, false);
223  break;
224 
225  case fi_gsp2_grazing1: //
226  if (!a_farm->CattleOut(a_field, 0.0,
227  g_date->DayInYear(26, 9) - g_date->DayInYear())) {
228  SimpleEvent(g_date->Date() + 1, fi_gsp2_grazing1, true);
229  break;
230  }
231 
232  // here comes two parallel events:
234  SimpleEvent(g_date->Date() < 5, fi_gsp2_npk4, false);
235  break;
236 
237  case fi_gsp2_cattle_is_out1: // Keep the cattle out there
238  // CattleIsOut() returns false if it is not time to stop grazing
239  if (!m_farm->CattleIsOut(m_field, 0.0, g_date->DayInYear(26, 10) - g_date->DayInYear(), g_date->DayInYear(26, 10))) {
241  break;
242  }
243 
244  case fi_gsp2_npk4: // 5% do this
245  if (a_ev->m_lock || a_farm->DoIt(5)) {
246  if (!a_farm->FA_NPK(a_field, 0.0,
247  g_date->DayInYear(1, 10) - g_date->DayInYear())) {
248  SimpleEvent(g_date->Date() + 1, fi_gsp2_npk4, true);
249  break;
250  }
251  }
252  SimpleEvent(g_date->Date() + 21, fi_gsp2_cutting4, false);
253  break;
254  case fi_gsp2_cutting4: // 5% do this
255  if (a_ev->m_lock || a_farm->DoIt_prob(.025)) {
256  if (!a_farm->CutToSilage(a_field, 0.0,
257  g_date->DayInYear(22, 10) - g_date->DayInYear())) {
258  SimpleEvent(g_date->Date() + 1, fi_gsp2_cutting4, true);
259  break;
260  }
261  }
262  else if (a_ev->m_lock || a_farm->DoIt_prob(.025 / .975)) {
264  break;
265  }
266  done = true;
267  break;
268 
269  case fi_gsp2_grazing2: //
270  if (!a_farm->CattleOut(a_field, 0.0,
271  g_date->DayInYear(22, 10) - g_date->DayInYear())) {
272  SimpleEvent(g_date->Date() + 1, fi_gsp2_grazing1, true);
273  break;
274  }
276  break;
277 
278  case fi_gsp2_cattle_is_out2: // Keep the cattle out there
279  // CattleIsOut() returns false if it is not time to stop grazing
280  if (!m_farm->CattleIsOut(m_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear(), m_field->GetMDates(1, 0))) {
282  break;
283  }
284  done = true;
285  // So we are done, and somewhere else the farmer will queue up the start event of the next crop
286  // END OF MAIN THREAD
287  break;
288  default:
289  g_msg->Warn(WARN_BUG, "FI_GrasslandSilagePerennial2::Do(): "
290  "Unknown event type! ", "");
291  exit(1);
292  }
293  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
294  return done;
295 }

References Farm::CattleIsOut(), Farm::CattleOut(), LE::ClearManagementActionSum(), Farm::CutToSilage(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt(), Farm::DoIt_prob(), Farm::FA_NPK(), Farm::FA_Slurry(), fi_gsp2_cattle_is_out1, fi_gsp2_cattle_is_out2, fi_gsp2_cutting1, fi_gsp2_cutting2, fi_gsp2_cutting3, fi_gsp2_cutting4, fi_gsp2_grazing1, fi_gsp2_grazing2, fi_gsp2_npk1, fi_gsp2_npk2, fi_gsp2_npk3, fi_gsp2_npk4, fi_gsp2_slurry2, fi_gsp2_slurry3, fi_gsp2_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_FIGrasslandSilagePerennial2, MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void FI_GrasslandSilagePerennial2::SetUpFarmCategoryInformation ( )
inline
105  {
106  const int elements = 2 + (fi_gsp2_foobar - FI_GSP2_BASE);
108 
109  FarmManagementCategory catlist[elements] =
110  {
111  fmc_Others, // zero element unused but must be here
112  fmc_Others, // fi_gsp2_start = 1, // Compulsory, must always be 1 (one).
113  fmc_Others, // fi_gsp2_sleep_all_day = FI_GSP2_BASE,
114  fmc_Fertilizer, // fi_gsp2_npk1,
115  fmc_Cutting, // fi_gsp2_cutting1,
116  fmc_Fertilizer, // fi_gsp2_npk2,
117  fmc_Fertilizer, // fi_gsp2_slurry2,
118  fmc_Cutting, // fi_gsp2_cutting2,
119  fmc_Fertilizer, // fi_gsp2_npk3,
120  fmc_Fertilizer, // fi_gsp2_slurry3,
121  fmc_Cutting, // fi_gsp2_cutting3,
122  fmc_Grazing, // fi_gsp2_grazing1,
123  fmc_Grazing, // fi_gsp2_cattle_is_out1,
124  fmc_Fertilizer, // fi_gsp2_npk4,
125  fmc_Cutting, // fi_gsp2_cutting4,
126  fmc_Grazing, // fi_gsp2_grazing2,
127  fmc_Grazing, // fi_gsp2_cattle_is_out2,
128 
129 
130  // no foobar entry
131 
132  };
133  // Iterate over the catlist elements and copy them to vector
134  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
135 
136  }

References FI_GSP2_BASE, fi_gsp2_foobar, fmc_Cutting, fmc_Fertilizer, fmc_Grazing, fmc_Others, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by FI_GrasslandSilagePerennial2().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
FarmEvent::m_forcespring
bool m_forcespring
Definition: Farm.h:392
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
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
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
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: Farm.cpp:856
fi_gsp2_slurry2
Definition: FI_GrasslandSilagePerennial2.h:69
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
fi_gsp2_slurry3
Definition: FI_GrasslandSilagePerennial2.h:72
fi_gsp2_grazing2
Definition: FI_GrasslandSilagePerennial2.h:78
fi_gsp2_cutting1
Definition: FI_GrasslandSilagePerennial2.h:67
fi_gsp2_start
Definition: FI_GrasslandSilagePerennial2.h:64
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
fi_gsp2_cattle_is_out2
Definition: FI_GrasslandSilagePerennial2.h:79
fi_gsp2_npk1
Definition: FI_GrasslandSilagePerennial2.h:66
fi_gsp2_npk2
Definition: FI_GrasslandSilagePerennial2.h:68
fi_gsp2_grazing1
Definition: FI_GrasslandSilagePerennial2.h:74
fi_gsp2_cattle_is_out1
Definition: FI_GrasslandSilagePerennial2.h:75
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
fi_gsp2_foobar
Definition: FI_GrasslandSilagePerennial2.h:80
tov_FIGrasslandSilagePerennial2
Definition: LandscapeFarmingEnums.h:559
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
Calendar::Date
long Date(void)
Definition: Calendar.h:57
FI_GSP2_BASE
#define FI_GSP2_BASE
Definition: FI_GrasslandSilagePerennial2.h:53
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
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
fi_gsp2_cutting3
Definition: FI_GrasslandSilagePerennial2.h:73
fi_gsp2_npk3
Definition: FI_GrasslandSilagePerennial2.h:71
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_GrasslandSilagePerennial2::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: FI_GrasslandSilagePerennial2.h:105
Crop::m_farm
Farm * m_farm
Definition: Farm.h:498
Crop::m_field
LE * m_field
Definition: Farm.h:499
fi_gsp2_cutting2
Definition: FI_GrasslandSilagePerennial2.h:70
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
fi_gsp2_npk4
Definition: FI_GrasslandSilagePerennial2.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
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
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
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
fi_gsp2_cutting4
Definition: FI_GrasslandSilagePerennial2.h:77