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

BECatchPeaCrop class
. More...

#include <BECatchPeaCrop.h>

Inheritance diagram for BECatchPeaCrop:
Crop

Public Member Functions

virtual bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 The one and oBEy method for a crop management plan. All farm actions go through here. More...
 
 BECatchPeaCrop (TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
 
- 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

BECatchPeaCrop class
.

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

◆ BECatchPeaCrop()

BECatchPeaCrop::BECatchPeaCrop ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
57  : Crop(a_tov, a_toc, a_L)
58  {
59  // When we start it off, the first possible date for a farm operation is 5th November
60  // This information is used by other crops when they decide how much post processing of
61  // the management is allowed after harvest before the next crop starts.
62  m_first_date=g_date->DayInYear( 11,10 );
64  }

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

Member Function Documentation

◆ Do()

bool BECatchPeaCrop::Do ( Farm a_farm,
LE a_field,
FarmEvent a_ev 
)
virtual

The one and oBEy 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 CatchPeaCrop.

Catch crops in ALMaSS cannot be part of the normal farm plan but are created as part of another crop management. They are therefore dependend on the other crops to set up the starting conditions, hence AddNewEvent is called by the calling crop to create m_startday etc..

Date management control is done by providing pairs of dates as start and stop dates for a management. In this case only harvest can be moved but normally there will be post harvest operations too. These dates are stored using Get and SetMDates

Reimplemented from Crop.

57 {
58  /******************** This block can be added to the top of all Crop::Do methods ***********************************************/
59  m_farm = a_farm; // These assignments are necessary, not for this method but for related event calls
60  m_field = a_field;
61  m_ev = a_ev;
62  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
63  bool flag = false;
64  int d1 = 0;
65  int noDates = 1;
66  TTypesOfVegetation l_tov = tov_BECatchPeaCrop; // The current type - change to match the crop you have
67  /**********************************************To Here *************************************************************************/
68 
69  // Depending what event has occured jump to the correct bit of code
70  switch (a_ev->m_todo)
71  {
72  case BE_cpc_start:
73  {
74  a_field->ClearManagementActionSum();
75 
84  int noDates = 1;
85  m_field->SetMDates(0, 0, g_date->DayInYear(1, 1));
86  m_field->SetMDates(1, 0, g_date->DayInYear(1, 2));
87  m_field->SetMDates(0, 1, g_date->DayInYear(1, 2));
88  m_field->SetMDates(1, 1, g_date->DayInYear(15, 3)); // This is the last day o
89  // Now test for fixable late finishing problems
90  if (m_field->GetMDates(0, 0) >= m_ev->m_startday)
91  {
92  g_msg->Warn(WARN_BUG, "BECatchPeaCrop::Do(): Harvest too late for the next crop to start!!!", "");
93  exit(l_tov);
94  }
95  // Now fix any late finishing problems - for the code below will work with more than one set of MDate pairs but is not entirely necessary for this generic crop (cannot move MDates[0,0])
96  for (int i = 0; i < noDates; i++) {
97  if (m_field->GetMDates(0, i) >= m_ev->m_startday) {
98  m_field->SetMDates(0, i, m_ev->m_startday - 1); //move the starting date
99  }
100  if (m_field->GetMDates(1, i) >= m_ev->m_startday) {
101  m_field->SetMConstants(i, 0);
102  m_field->SetMDates(1, i, m_ev->m_startday - 1); //move the finishing date
103  }
104  }
105  // Now all the date management things are checked we can start with the main code
106  d1 = g_date->OldDays() + g_date->DayInYear();
107  // Because we don't know the sow date when coding we have to use a variable here, hence GCCR_ENDDATE
108  BE_CC_ENDDATE = g_date->DayInYear() + 7; // we allow 7 days for sowing
109  // Here we queue up the first event - this differs depending on whether we have a
110  // stock or arable farmer
111  SimpleEvent_(d1, BE_cpc_stubble_cultivator, false, a_farm, a_field);
112  }
113  break;
114 
115  // This is the first real farm operation
117  if (!a_farm->StubbleHarrowing(a_field, 0.0, g_date->DayInYear(11, 10) - g_date->DayInYear())) {
118  SimpleEvent_(g_date->Date() + 1, BE_cpc_stubble_cultivator, true, a_farm, a_field);
119  break;
120  }
121  if (a_field->GetSoilType() <= 5 || a_field->GetSoilType() == 7) { // on sandy soils (BE ZAND & LOSS)
122  if (a_farm->IsStockFarmer()) //Stock Farmer
123  {
124  SimpleEvent_(g_date->Date() + 5, BE_cpc_ferti_s1_sand, false, a_farm, a_field);
125  }
126  else {
127  SimpleEvent_(g_date->Date() + 5, BE_cpc_ferti_p1_sand, false, a_farm, a_field);
128  }
129  break;
130  }
131  else {
132  if (a_farm->IsStockFarmer()) //Stock Farmer
133  {
134  SimpleEvent_(g_date->Date() + 5, BE_cpc_ferti_s1_clay, false, a_farm, a_field);
135  }
136  else {
137  SimpleEvent_(g_date->Date() + 5, BE_cpc_ferti_p1_clay, false, a_farm, a_field);
138  }
139  break;
140  }
141  break;
143  if (a_ev->m_lock || a_farm->DoIt_prob(0.15)) {
144  if (!a_farm->FP_Slurry(a_field, 0.0, g_date->DayInYear(15, 10) - g_date->DayInYear())) {
145  SimpleEvent_(g_date->Date() + 1, BE_cpc_ferti_p1_sand, true, a_farm, a_field);
146  break;
147  }
148  }
149  SimpleEvent_(g_date->Date() + 1, BE_cpc_preseeding_cultivator_with_sow, false, a_farm, a_field);
150  break;
152  if (a_ev->m_lock || a_farm->DoIt_prob(0.15)) {
153  if (!a_farm->FA_Slurry(a_field, 0.0, g_date->DayInYear(15, 10) - g_date->DayInYear())) {
154  SimpleEvent_(g_date->Date() + 1, BE_cpc_ferti_s1_sand, true, a_farm, a_field);
155  break;
156  }
157  }
158  SimpleEvent_(g_date->Date() + 1, BE_cpc_preseeding_cultivator_with_sow, false, a_farm, a_field);
159  break;
161  if (a_ev->m_lock || a_farm->DoIt_prob(0.60)) {
162  if (!a_farm->FP_Slurry(a_field, 0.0, g_date->DayInYear(15, 10) - g_date->DayInYear())) {
163  SimpleEvent_(g_date->Date() + 1, BE_cpc_ferti_p1_clay, true, a_farm, a_field);
164  break;
165  }
166  }
167  SimpleEvent_(g_date->Date() + 1, BE_cpc_preseeding_cultivator_with_sow, false, a_farm, a_field);
168  break;
170  if (a_ev->m_lock || a_farm->DoIt_prob(0.60)) {
171  if (!a_farm->FA_Slurry(a_field, 0.0, g_date->DayInYear(15, 10) - g_date->DayInYear())) {
172  SimpleEvent_(g_date->Date() + 1, BE_cpc_ferti_s1_clay, true, a_farm, a_field);
173  break;
174  }
175  }
176  SimpleEvent_(g_date->Date() + 1, BE_cpc_preseeding_cultivator_with_sow, false, a_farm, a_field);
177  break;
179  if (!a_farm->PreseedingCultivatorSow(a_field, 0.0, g_date->DayInYear(16, 10) - g_date->DayInYear())) {
180  SimpleEvent_(g_date->Date() + 1, BE_cpc_preseeding_cultivator_with_sow, true, a_farm, a_field);
181  break;
182  }
183  d1 = g_date->Date() + 14;
184  if (d1 < g_date->OldDays() + g_date->DayInYear(1, 9)) {
185  d1 = g_date->OldDays() + g_date->DayInYear(1, 9);
186  }
187  if (a_field->GetSoilType() <= 5 || a_field->GetSoilType() == 7) { // on sandy soils (BE ZAND & LOSS)
188  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 1) + 365, BE_cpc_sleep_all_day, false, a_farm, a_field);
189  }
190  else {
191  SimpleEvent_(d1, BE_cpc_winter_plough_clay, false, a_farm, a_field);
192  }
193  break;
195  if (!a_farm->WinterPlough(a_field, 0.0, g_date->DayInYear(15, 12) - g_date->DayInYear())) {
196  SimpleEvent_(g_date->Date() + 1, BE_cpc_winter_plough_clay, true, a_farm, a_field);
197  break;
198  }
199  // The plan is finished on clay soils (catch crop in incorporated into soil on autumn)
200  // Calling sleep_all_day to move to the next year
201  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 1) + 365, BE_cpc_sleep_all_day, false, a_farm, a_field);
202  break;
204  if (!a_farm->SleepAllDay(a_field, 0.0, m_field->GetMDates(1, 1) - g_date->DayInYear())) {
205  SimpleEvent_(g_date->Date() + 1, BE_cpc_sleep_all_day, true, a_farm, a_field);
206  break;
207  }
208  done = true;
209  break;
210 
211 
212  default:
213  g_msg->Warn(WARN_BUG, "BECatchPeaCrop::Do(): "
214  "Unknown event type! ", "");
215  exit(1);
216  }
217  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
218  return done;
219 }

References BE_CC_ENDDATE, BE_cpc_ferti_p1_clay, BE_cpc_ferti_p1_sand, BE_cpc_ferti_s1_clay, BE_cpc_ferti_s1_sand, BE_cpc_preseeding_cultivator_with_sow, BE_cpc_sleep_all_day, BE_cpc_start, BE_cpc_stubble_cultivator, BE_cpc_winter_plough_clay, LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), Farm::DoIt_prob(), Farm::FP_Slurry(), g_date, g_msg, LE::GetMDates(), LE::GetSoilType(), Farm::IsStockFarmer(), Crop::m_ev, Crop::m_farm, Crop::m_field, FarmEvent::m_forcespring, FarmEvent::m_lock, FarmEvent::m_startday, FarmEvent::m_todo, Calendar::OldDays(), LE::SetMConstants(), LE::SetMDates(), Crop::SimpleEvent_(), Farm::StubbleHarrowing(), tov_BECatchPeaCrop, MapErrorMsg::Warn(), and WARN_BUG.


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
LE::SetMDates
void SetMDates(int a, int b, int c)
Definition: Elements.h:406
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: Farm.h:961
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
BE_cpc_ferti_p1_clay
Definition: BECatchPeaCrop.h:38
BE_cpc_stubble_cultivator
Definition: BECatchPeaCrop.h:35
tov_BECatchPeaCrop
Definition: LandscapeFarmingEnums.h:291
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
BE_cpc_ferti_p1_sand
Definition: BECatchPeaCrop.h:36
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
FarmEvent::m_startday
int m_startday
Definition: Farm.h:385
BE_cpc_ferti_s1_sand
Definition: BECatchPeaCrop.h:37
BE_cpc_winter_plough_clay
Definition: BECatchPeaCrop.h:41
Calendar::Date
long Date(void)
Definition: Calendar.h:57
BE_CC_ENDDATE
#define BE_CC_ENDDATE
Definition: BECatchPeaCrop.h:25
LE::GetSoilType
int GetSoilType()
Definition: Elements.h:302
BE_cpc_sleep_all_day
Definition: BECatchPeaCrop.h:34
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
tocc_Catch
Definition: LandscapeFarmingEnums.h:627
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
Crop::m_farm
Farm * m_farm
Definition: Farm.h:498
Crop::m_field
LE * m_field
Definition: Farm.h:499
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
BE_cpc_preseeding_cultivator_with_sow
Definition: BECatchPeaCrop.h:40
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
BE_cpc_ferti_s1_clay
Definition: BECatchPeaCrop.h:39
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::SetCropClassification
void SetCropClassification(int a_classification)
Definition: Farm.h:549
BE_cpc_start
Definition: BECatchPeaCrop.h:33
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
LE::SetMConstants
void SetMConstants(int a, int c)
Definition: Elements.h:408
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
WARN_BUG
Definition: MapErrorMsg.h:34
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