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

#include <DE_PermanentGrassGrazed.h>

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

Constructor & Destructor Documentation

◆ DE_PermanentGrassGrazed()

DE_PermanentGrassGrazed::DE_PermanentGrassGrazed ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
83  : Crop(a_tov, a_toc, a_L)
84  {
85  // When we start it off, the first possible date for a farm operation is 1st October
86  // This information is used by other crops when they decide how much post processing of
87  // the management is allowed after harvest before the next crop starts.
88  m_first_date = g_date->DayInYear(31, 10);
90  }

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

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

83 {
84  /******************** This block can be added to the top of all Crop::Do methods ***********************************************/
85  m_farm = a_farm; // These assignments are necessary, not for this method but for related event calls
86  m_field = a_field;
87  m_ev = a_ev;
88  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
89  int d1 = 0;
91 
92  // Depending what event has occured jump to the correct bit of code
93  switch (m_ev->m_todo)
94  {
95  case de_pgg_start:
96  {
98 
99  m_last_date = g_date->DayInYear(30, 9); // Should match the last flexdate below
100  //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
101  std::vector<std::vector<int>> flexdates(1 + 1, std::vector<int>(2, 0));
102  // Set up the date management stuff
103  // Start and stop dates for all events after harvest
104  flexdates[0][1] = g_date->DayInYear(30, 8); // last possible day of cutting2 - this is in effect day before the earliest date that a following crop can use
105 
106  flexdates[1][0] = -1;
107  flexdates[1][1] = g_date->DayInYear(30, 9); // last possible day of grazing
108 
109  // 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
110  int isSpring = 0;
111  if (StartUpCrop(isSpring, flexdates, int(de_pgg_ferti_p2))) break;
112 
113  // End single block date checking code. Please see next line comment as well.
114  // Reinit d1 to first possible starting date.
115  d1 = g_date->OldDays() + g_date->DayInYear(1, 10) + isSpring;
116  // OK, let's go.
117  if (m_farm->IsStockFarmer()) //Stock Farmer
118  {
120  }
121  else SimpleEvent_(g_date->Date() + 1, de_pgg_ferti_p1, false, m_farm, m_field);
122  break;
123  }
124  break;
125 
126  // This is the first real farm operation
127  // This happens in a non-sowing year
128  case de_pgg_ferti_s1:
129  if (m_ev->m_lock || m_farm->DoIt_prob(0.50))
130  {
131  if (!m_farm->FA_Manure(m_field, 0.0, g_date->DayInYear(31, 10) - g_date->DayInYear())) {
133  break;
134  }
135  }
136  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 2) + 365, de_pgg_ferti_s2, false, a_farm, a_field);
137  break;
138  case de_pgg_ferti_p1:
139  if (m_ev->m_lock || m_farm->DoIt_prob(0.50))
140  {
141  if (!m_farm->FP_Manure(m_field, 0.0, g_date->DayInYear(31, 10) - g_date->DayInYear())) {
143  break;
144  }
145  }
146  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 2) + 365, de_pgg_ferti_p2, false, a_farm, a_field);
147  break;
148  case de_pgg_ferti_s2:
149  if (!m_farm->FA_Slurry(m_field, 0.0, g_date->DayInYear(28, 2) - g_date->DayInYear())) {
151  break;
152  }
154  break;
155  case de_pgg_ferti_p2:
156  if (!m_farm->FP_Slurry(m_field, 0.0, g_date->DayInYear(28, 2) - g_date->DayInYear())) {
158  break;
159  }
161  break;
162  case de_pgg_cutting:
163  if (!m_farm->CutWeeds(m_field, 0.0, g_date->DayInYear(28, 2) - g_date->DayInYear())) {
165  break;
166  }
168  break;
169  case de_pgg_cattle_out1:
170  if (!m_farm->CattleOut(m_field, 0.0, g_date->DayInYear(10, 3) - g_date->DayInYear())) {
172  break;
173  }
174  // Keep them out there
176  break;
177  case de_pgg_cattle_is_out1: // Keep the cattle out there
178  // CattleIsOut() returns false if it is not time to stop grazing
179  if (!m_farm->CattleIsOut(m_field, 0.0, g_date->DayInYear(1, 4) - g_date->DayInYear(), g_date->DayInYear(1, 4))) {
181  break;
182  }
184  break;
185  case de_pgg_cattle_out2:
186  if (a_ev->m_lock || a_farm->DoIt(20)) {
187  if (!m_farm->CattleOut(m_field, 0.0, g_date->DayInYear(10, 5) - g_date->DayInYear())) {
189  break;
190  }
192  break;
193  }
195  break;
196  case de_pgg_cutting1:
197  if (!m_farm->CutToSilage(m_field, 0.0, g_date->DayInYear(30, 6) - g_date->DayInYear())) {
198  SimpleEvent(g_date->Date() + 1, de_pgg_cutting1, true);
199  break;
200  }
201  d1 = g_date->Date() + 28;
202  if (d1 < g_date->OldDays() + g_date->DayInYear(1, 7)) {
203  d1 = g_date->OldDays() + g_date->DayInYear(1, 7);
204  }
206  break;
207  case de_pgg_cutting2:
208  if (!m_farm->CutToSilage(m_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
209  SimpleEvent(g_date->Date() + 1, de_pgg_cutting2, true);
210  break;
211  }
212  done = true;
213  break;
214  case de_pgg_cattle_is_out2: // Keep the cattle out there
215  // CattleIsOutLow() returns false if it is not time to stop grazing
216  if (!m_farm->CattleIsOut(m_field, 0.0, m_field->GetMDates(1, 1) - g_date->DayInYear(), m_field->GetMDates(1, 0))) {
218  break;
219  }
220  done = true;
221  break;
222 
223  default:
224  g_msg->Warn(WARN_BUG, "DE_PermanentGrassGrazed::Do(): "
225  "Unknown event type! ", "");
226  exit(1);
227  }
228  return done;
229 }

References Farm::CattleIsOut(), Farm::CattleOut(), LE::ClearManagementActionSum(), Farm::CutToSilage(), Farm::CutWeeds(), Calendar::Date(), Calendar::DayInYear(), de_pgg_cattle_is_out1, de_pgg_cattle_is_out2, de_pgg_cattle_out1, de_pgg_cattle_out2, de_pgg_cutting, de_pgg_cutting1, de_pgg_cutting2, de_pgg_ferti_p1, de_pgg_ferti_p2, de_pgg_ferti_s1, de_pgg_ferti_s2, de_pgg_start, Farm::DoIt_prob(), Farm::FA_Manure(), Farm::FA_Slurry(), Farm::FP_Manure(), Farm::FP_Slurry(), g_date, g_msg, LE::GetMDates(), Farm::IsStockFarmer(), Crop::m_ev, Crop::m_farm, Crop::m_field, Crop::m_last_date, FarmEvent::m_lock, FarmEvent::m_todo, Calendar::OldDays(), Crop::SimpleEvent(), Crop::SimpleEvent_(), Crop::StartUpCrop(), tov_DEPermanentGrassGrazed, MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void DE_PermanentGrassGrazed::SetUpFarmCategoryInformation ( )
inline
91  {
92  const int elements = 2 + (de_pgg_foobar - DE_PGG_BASE);
94 
95  FarmManagementCategory catlist[elements] =
96  {
97  fmc_Others, // zero element unused but must be here
98  fmc_Others, // de_pgg_start = 1, // Compulsory, must always be 1 (one).
99  fmc_Others, // de_pgg_sleep_all_day = DE_PGG_BASE,
100  fmc_Fertilizer, // de_pgg_ferti_p1
101  fmc_Fertilizer, // de_pgg_ferti_s1
102  fmc_Fertilizer, // de_pgg_ferti_p2
103  fmc_Fertilizer, // de_pgg_ferti_s2
104  fmc_Cultivation, // de_pgg_cutting
105  fmc_Grazing, // de_pgg_cattle_out1,//Out means outside the barns. Out in the field to eat grass.
106  fmc_Grazing, // de_pgg_cattle_is_out1,//Time that the catle is in the field.
107  fmc_Grazing, // de_pgg_cattle_out2,
108  fmc_Grazing, // de_pgg_cattle_is_out2,
109  fmc_Others, // de_pgg_cutting1,
110  fmc_Others, // de_pgg_cutting2,
111 
112  // no foobar entry
113 
114  };
115  // Iterate over the catlist elements and copy them to vector
116  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
117 
118  }

References DE_PGG_BASE, de_pgg_foobar, fmc_Cultivation, fmc_Fertilizer, fmc_Grazing, fmc_Others, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DE_PermanentGrassGrazed().


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
de_pgg_cutting2
Definition: DE_PermanentGrassGrazed.h:73
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: Farm.h:961
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
de_pgg_ferti_p2
Definition: DE_PermanentGrassGrazed.h:65
de_pgg_cutting
Definition: DE_PermanentGrassGrazed.h:67
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
Farm::FA_Manure
virtual bool FA_Manure(LE *a_field, double a_user, int a_days)
Spread manure on a_field owned by an stock farmer.
Definition: FarmFuncs.cpp:1110
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
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
DE_PGG_BASE
#define DE_PGG_BASE
Definition: DE_PermanentGrassGrazed.h:53
de_pgg_cattle_is_out2
Definition: DE_PermanentGrassGrazed.h:71
Farm::FP_Manure
virtual bool FP_Manure(LE *a_field, double a_user, int a_days)
Spread manure on a_field owned by an arable farmer.
Definition: FarmFuncs.cpp:896
de_pgg_ferti_s2
Definition: DE_PermanentGrassGrazed.h:66
de_pgg_ferti_p1
Definition: DE_PermanentGrassGrazed.h:63
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
de_pgg_start
Definition: DE_PermanentGrassGrazed.h:61
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
de_pgg_cattle_out2
Definition: DE_PermanentGrassGrazed.h:70
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
de_pgg_ferti_s1
Definition: DE_PermanentGrassGrazed.h:64
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
DE_PermanentGrassGrazed::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DE_PermanentGrassGrazed.h:91
tov_DEPermanentGrassGrazed
Definition: LandscapeFarmingEnums.h:499
de_pgg_cattle_is_out1
Definition: DE_PermanentGrassGrazed.h:69
de_pgg_cattle_out1
Definition: DE_PermanentGrassGrazed.h:68
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
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
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
de_pgg_foobar
Definition: DE_PermanentGrassGrazed.h:74
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_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
de_pgg_cutting1
Definition: DE_PermanentGrassGrazed.h:72
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
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
Farm::CutWeeds
virtual bool CutWeeds(LE *a_field, double a_user, int a_days)
Carry out weed topping on a_field.
Definition: FarmFuncs.cpp:1629