Loading [MathJax]/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
FR_Grassland_Perm Class Reference

FR_Grassland_Perm class
. More...

#include <FR_Grassland_Perm.h>

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

FR_Grassland_Perm class
.

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

◆ FR_Grassland_Perm()

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

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

Member Function Documentation

◆ Do()

bool FR_Grassland_Perm::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 winter wheat.

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  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
103  int d1 = 0;
104  m_ev = a_ev;
106  // Depending what event has occured jump to the correct bit of code e.g. for ww_start jump to line 67 below
107  switch (a_ev->m_todo)
108  {
109  case fr_gp_start:
110  {
111  // This is just to hold a local variable in scope and prevent compiler errors
112  // ww_start just sets up all the starting conditions and reference dates that are needed to start a ww
113  // crop off
114  FR_GP_GRAZE = false;
115 
116  a_field->ClearManagementActionSum();
117 
118  // Record whether skylark scrapes are present and adjust flag accordingly
120  a_field->m_skylarkscrapes = true;
121  }
122  else {
123  a_field->m_skylarkscrapes = false;
124  }
125  // Set up the date management stuff
126  // The next bit of code just allows for altering dates after harvest if it is necessary
127  // to allow for a crop which starts its management early.
128 
129  // 3 start and stop dates for all events after harvest for this crop
130  int noDates = 3;
131  a_field->SetMDates(0, 0, g_date->DayInYear(30, 8)); // last possible day of harvest
132  a_field->SetMDates(1, 0, g_date->DayInYear(3, 9)); // last possible day of straw chopping
133  a_field->SetMDates(0, 1, 0); // start day of hay bailing (not used as it depend on previous treatment)
134  a_field->SetMDates(1, 1, g_date->DayInYear(7, 9)); // end day of hay bailing
135  // Can be up to 10 of these. If the shortening code is triggered
136  // then these will be reduced in value to 0
137 
138  a_field->SetMConstants(0, 1);
139 
140  // Check the next crop for early start, unless it is a spring crop
141  // in which case we ASSUME that no checking is necessary!!!!
142  // So DO NOT implement a crop that runs over the year boundary (i.e. from spring to spring!), at least not without fixing this.
143 
144  //new if: do the check only for non-optimising farms and if year>0. (030713 - m_rotation used only in the hidden year, so I modified the condition from >7 to >0)
145  int d1;
146  if (!(a_farm->GetType() == tof_OptimisingFarm && g_date->GetYearNumber() > 0)) {
147 
148  if (a_ev->m_startday > g_date->DayInYear(1, 7)) {
149  if (a_field->GetMDates(0, 0) >= a_ev->m_startday)
150  {
151  g_msg->Warn(WARN_BUG, "FR_Grassland_Perm::Do(): ", "Harvest too late for the next crop to start!!!");
152  int almassnum = a_field->GetLandscape()->BackTranslateVegTypes(a_ev->m_next_tov);
153  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
154  }
155  // Now fix any late finishing problems
156  for (int i = 0; i < noDates; i++) {
157  if (a_field->GetMDates(0, i) >= a_ev->m_startday) {
158  a_field->SetMDates(0, i, a_ev->m_startday - 1); //move the starting date
159  }
160  if (a_field->GetMDates(1, i) >= a_ev->m_startday) {
161  a_field->SetMConstants(i, 0); //change the default value of the MConst (=1) to 0 (necessary to correctly execute farm events in case the finishing date (MDate) was moved)
162  a_field->SetMDates(1, i, a_ev->m_startday - 1); //move the finishing date
163  }
164  }
165  }
166  // Now no operations can be timed after the start of the next crop.
167 
168  if (!a_ev->m_first_year) {
169  // Are we before July 1st?
170  d1 = g_date->OldDays() + g_date->DayInYear(1, 7);
171  if (g_date->Date() < d1) {
172  // Yes, too early. We assumme this is because the last crop was late
173  printf("Poly: %d\n", a_field->GetPoly());
174  g_msg->Warn(WARN_BUG, "FR_Grassland_Perm::Do(): ", "Crop start attempt between 1st Jan & 1st July");
175  int prev = a_field->GetLandscape()->BackTranslateVegTypes(a_field->GetOwner()->GetPreviousTov(a_field->GetRotIndex()));
176  g_msg->Warn(WARN_BUG, "Previous Crop ", prev);
177  int almassnum = a_field->GetLandscape()->BackTranslateVegTypes(a_ev->m_next_tov);
178  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
179  }
180  else {
181  d1 = g_date->OldDays() + m_first_date; // Add 365 for spring crop
182  if (g_date->Date() > d1) {
183  // Yes too late - should not happen - raise an error
184  g_msg->Warn(WARN_BUG, "FR_Grassland_Perm::Do(): ", "Crop start attempt after last possible start date");
185  g_msg->Warn(WARN_BUG, "Previous Crop ", "");
186  a_field->GetOwner()->GetPreviousTov(a_field->GetRotIndex());
187  int almassnum = a_field->GetLandscape()->BackTranslateVegTypes(a_ev->m_next_tov);
188  g_msg->Warn("Next Crop ", (double)almassnum); // this causes exit
189  }
190  }
191  }
192  else {
193  // Is the first year
194  // Some special code to cope with that first start-up year in ALMaSS - ignore for all practical purposes (start woth the first event on the after winter time) - Date here is a suggestion (not stated in crop scheme!)
196  break;
197  }
198  }//if
199 
200  // End single block date checking code. Please see next line comment as well.
201  // Reinit d1 to first possible starting date.
202  d1 = g_date->OldDays() + g_date->DayInYear(1, 3);
203  if (g_date->Date() >= d1) d1 += 365;
204  SimpleEvent(d1, fr_gp_grazing, false);
205 
206  }
207  break;
208  case fr_gp_grazing:
209  if (a_ev->m_lock || a_farm->DoIt_prob(.90)) {
210  if (!a_farm->CattleOut(a_field, 0.0,
211  g_date->DayInYear(25, 7) - g_date->DayInYear())) {
212  SimpleEvent(g_date->Date() + 1, fr_gp_grazing, true);
213  break;
214  }
215  else
216  {
217  //remember who do grazing
218  FR_GP_GRAZE = true;
219  }
220  SimpleEvent(g_date->Date() + 1, fr_gp_cattle_is_out, false);
221  SimpleEvent(g_date->OldDays() + g_date->DayInYear(5, 4), fr_gp_n_mineral, false); // no timing or info on 40% of all or not?
222  break;
223  }
224  else SimpleEvent(g_date->OldDays() + g_date->DayInYear(5, 4), fr_gp_cutting1, false);
225  break;
226 
227  case fr_gp_cattle_is_out: // Keep the cattle out there
228  // CattleIsOut() returns false if it is not time to stop grazing
229  if (!a_farm->CattleIsOut(a_field, 0.0, g_date->DayInYear(30, 9) - g_date->DayInYear(), g_date->DayInYear(30, 9))) {
230  SimpleEvent(g_date->Date() + 1, fr_gp_cattle_is_out, false);
231  break;
232  }
233  break;
234 
235  case fr_gp_cutting1:
236  if (!a_farm->CutToSilage(a_field, 0.0,
237  g_date->DayInYear(5, 5) - g_date->DayInYear())) {
238  SimpleEvent(g_date->Date() + 1, fr_gp_cutting1, true);
239  break;
240  }
241  SimpleEvent(g_date->Date()+1, fr_gp_n_mineral, false); // no timing or info on 40% of all or not?
242  break;
243 
244  case fr_gp_n_mineral:
245  if (a_ev->m_lock || a_farm->DoIt_prob(.40)) {
246  if (!a_farm->FP_N(a_field, 0.0, g_date->DayInYear(9, 5) - g_date->DayInYear())) {
247  SimpleEvent(g_date->Date() + 1, fr_gp_n_mineral, true);
248  break;
249  }
250  }
251  SimpleEvent(g_date->Date() + 21, fr_gp_cutting2, false);
252  break;
253 
254  case fr_gp_cutting2:
255  if (FR_GP_GRAZE == false) {
256  if (!a_farm->CutToSilage(a_field, 0.0, g_date->DayInYear(15, 6) - g_date->DayInYear())) {
257  SimpleEvent(g_date->Date() + 1, fr_gp_cutting2, true);
258  break;
259  }
260  }
261  SimpleEvent(g_date->Date() < 4, fr_gp_slurry, false);
262  break;
263 
264  case fr_gp_slurry:
265  if (a_ev->m_lock || a_farm->DoIt_prob(1.0)) {
266  if (!a_farm->FP_Slurry(a_field, 0.0, g_date->DayInYear(19, 6) - g_date->DayInYear())) {
267  SimpleEvent(g_date->Date() + 1, fr_gp_slurry, true);
268  break;
269  }
270  }
271 
272  d1 = g_date->Date();
273  if (d1 < g_date->OldDays() + g_date->DayInYear(1, 7)) {
274  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 7), fr_gp_wait, false);
275  break;
276  }
277  else {
278  done = true; // end of plan
279  }
280  case fr_gp_wait:
281  done = true;
282  break;
283 
284  default:
285  g_msg->Warn(WARN_BUG, "FR_Grassland_Perm::Do(): "
286  "Unknown event type! ", "");
287  exit(1);
288  }
289  return done;
290 }

References Farm::CattleIsOut(), Farm::CattleOut(), cfg_FR_Grassland_Perm_SkScrapes, LE::ClearManagementActionSum(), Farm::CutToSilage(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt_prob(), Farm::FP_N(), Farm::FP_Slurry(), fr_gp_cattle_is_out, fr_gp_cutting1, fr_gp_cutting2, FR_GP_GRAZE, fr_gp_grazing, fr_gp_n_mineral, fr_gp_slurry, fr_gp_start, fr_gp_wait, g_date, g_msg, LE::GetMDates(), LE::GetOwner(), LE::GetPoly(), Farm::GetPreviousTov(), LE::GetRotIndex(), Farm::GetType(), Calendar::GetYearNumber(), Crop::m_ev, Crop::m_farm, Crop::m_field, Crop::m_first_date, FarmEvent::m_first_year, FarmEvent::m_lock, FarmEvent::m_next_tov, LE::m_skylarkscrapes, FarmEvent::m_startday, FarmEvent::m_todo, Calendar::OldDays(), LE::SetMConstants(), LE::SetMDates(), Crop::SimpleEvent(), tof_OptimisingFarm, tov_FRGrassland_Perm, CfgBool::value(), MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void FR_Grassland_Perm::SetUpFarmCategoryInformation ( )
inline
93  {
94  const int elements = 2 + (fr_gp_foobar - FR_GP_BASE);
96 
97  FarmManagementCategory catlist[elements] =
98  {
99  fmc_Others, // zero element unused but must be here
100  fmc_Others, //fr_gp_start = 1, // Compulsory, must always be 1 (one).
101  fmc_Others, //fr_gp_sleep_all_day = FR_GP_BASE,
102  fmc_Cutting, //fr_gp_cutting1,
103  fmc_Grazing, //fr_gp_grazing,
104  fmc_Fertilizer, //fr_gp_n_mineral1,
105  fmc_Cutting, //fr_gp_cutting2,
106  fmc_Fertilizer, //fr_gp_slurry,
107  fmc_Grazing, //fr_gp_grazing2,
108  fmc_Others, //fr_gp_wait
109 
110  // no foobar entry
111 
112  };
113  // Iterate over the catlist elements and copy them to vector
114  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
115 
116  }

References fmc_Cutting, fmc_Fertilizer, fmc_Grazing, fmc_Others, FR_GP_BASE, fr_gp_foobar, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by FR_Grassland_Perm().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
FR_GP_GRAZE
#define FR_GP_GRAZE
A flag used to indicate autumn ploughing status.
Definition: FR_Grassland_Perm.h:53
LE::SetMDates
void SetMDates(int a, int b, int c)
Definition: Elements.h:406
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
FR_GP_BASE
#define FR_GP_BASE
Definition: FR_Grassland_Perm.h:49
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
Calendar::GetYearNumber
int GetYearNumber(void)
Definition: Calendar.h:72
FarmEvent::m_first_year
bool m_first_year
Definition: Farm.h:386
fr_gp_cattle_is_out
Definition: FR_Grassland_Perm.h:64
LE::GetPoly
int GetPoly(void)
Returns the polyref number for this polygon.
Definition: Elements.h:238
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
fr_gp_slurry
Definition: FR_Grassland_Perm.h:67
Farm::GetPreviousTov
TTypesOfVegetation GetPreviousTov(int a_index)
Definition: Farm.h:966
fr_gp_wait
Definition: FR_Grassland_Perm.h:68
Farm::GetType
TTypesOfFarm GetType(void)
Definition: Farm.h:956
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
FarmEvent::m_startday
int m_startday
Definition: Farm.h:385
fr_gp_n_mineral
Definition: FR_Grassland_Perm.h:65
tov_FRGrassland_Perm
Definition: LandscapeFarmingEnums.h:589
fr_gp_cutting1
Definition: FR_Grassland_Perm.h:62
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
CfgBool::value
bool value() const
Definition: Configurator.h:164
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
LE::m_skylarkscrapes
bool m_skylarkscrapes
For management testing of skylark scrapes.
Definition: Elements.h:95
Calendar::Date
long Date(void)
Definition: Calendar.h:57
FR_Grassland_Perm::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: FR_Grassland_Perm.h:93
fr_gp_start
Definition: FR_Grassland_Perm.h:60
Farm::FP_N
virtual bool FP_N(LE *a_field, double a_user, int a_days)
Apply N fertilizer, on a_field owned by an arable farmer.
Definition: FarmFuncs.cpp:700
fr_gp_cutting2
Definition: FR_Grassland_Perm.h:66
cfg_FR_Grassland_Perm_SkScrapes
CfgBool cfg_FR_Grassland_Perm_SkScrapes("FR_CROP_GP_SK_SCRAPES", CFG_CUSTOM, false)
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
LE::GetRotIndex
int GetRotIndex(void)
Definition: Elements.h:373
FarmEvent::m_next_tov
TTypesOfVegetation m_next_tov
Definition: Farm.h:390
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
tof_OptimisingFarm
Definition: LandscapeFarmingEnums.h:696
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
fr_gp_grazing
Definition: FR_Grassland_Perm.h:63
LE::GetOwner
Farm * GetOwner(void)
Definition: Elements.h:256
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
fr_gp_foobar
Definition: FR_Grassland_Perm.h:69
LE::SetMConstants
void SetMConstants(int a, int c)
Definition: Elements.h:408
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