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

GenericCatchCrop class
. More...

#include <GenericCatchCrop.h>

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

GenericCatchCrop class
.

See GenericCatchCrop.h:: GenericCatchCropToDo 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

◆ GenericCatchCrop()

GenericCatchCrop::GenericCatchCrop ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline

Member Function Documentation

◆ Do()

bool GenericCatchCrop::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 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.

53 {
54  /******************** This block can be added to the top of all Crop::Do methods ***********************************************/
55  m_farm = a_farm; // These assignments are necessary, not for this method but for related event calls
56  m_field = a_field;
57  m_ev = a_ev;
58  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
59  int d1 = 0;
60  int noDates = 1;
61  TTypesOfVegetation l_tov = tov_GenericCatchCrop; // The current type - change to match the crop you have
62 /**********************************************To Here *************************************************************************/
63  // Depending what event has occured jump to the correct bit of code
64  switch (a_ev->m_todo)
65  {
66  case gccr_start:
67  {
68  a_field->ClearManagementActionSum();
69 
78  int noDates = 1;
79  m_field->SetMDates(0, 0, g_date->DayInYear(24, 2)); // This is the first harvest date
80  m_field->SetMDates(1, 0, g_date->DayInYear(10, 3)); // This is the last harvest date
81  // If the start date is after summer then this is likely a mistake, so warn about this and exit
82  if (m_ev->m_startday > g_date->DayInYear(1, 7))
83  {
84  g_msg->Warn(WARN_BUG, "GenericCatchCrop::Do(): "
85  "Autumn crop following catch crop - if this is correct remove this check from the code", "");
86  exit(l_tov);
87  }
88  // Now test for fixable late finishing problems
89  if (m_field->GetMDates(0, 0) >= m_ev->m_startday)
90  {
91  g_msg->Warn(WARN_BUG, "GenericCatchCrop::Do(): Harvest too late for the next crop to start!!!", "");
92  exit(l_tov);
93  }
94  // 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])
95  for (int i = 0; i < noDates; i++) {
96  if (m_field->GetMDates(0, i) >= m_ev->m_startday) {
97  m_field->SetMDates(0, i, m_ev->m_startday - 1); //move the starting date
98  }
99  if (m_field->GetMDates(1, i) >= m_ev->m_startday) {
100  m_field->SetMConstants(i, 0);
101  m_field->SetMDates(1, i, m_ev->m_startday - 1); //move the finishing date
102  }
103  }
104  // Now all the date management things are checked we can start with the main code
105  d1 = g_date->OldDays() + g_date->DayInYear();
106  // Because we don't know the sow date when coding we have to use a variable here, hence GCCR_ENDDATE
107  GCCR_ENDDATE = g_date->DayInYear() + 7; // we allow 7 days for sowing
108  // Here we queue up the first event - this differs depending on whether we have a
109  // stock or arable farmer
110  SimpleEvent_(d1, gccr_sow, false, a_farm, a_field);
111  }
112  break;
113 
114  // This is the first real farm operation
115  case gccr_sow:
116  if (!a_farm->AutumnSow(a_field, 0.0, GCCR_ENDDATE - g_date->DayInYear()))
117  {
118  SimpleEvent(g_date->Date() + 1, gccr_sow, true);
119  break;
120  }
121  d1 = g_date->OldDays() + 365 + m_field->GetMDates(0, 0);
122  SimpleEvent(d1, gccr_harvest, false);
123  break;
124  case gccr_harvest:
125  if (!a_farm->Harvest(a_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear()))
126  {
127  SimpleEvent(g_date->Date() + 1, gccr_harvest, true);
128  break;
129  }
130  done = true;
131  break;
132 
133 
134  default:
135  g_msg->Warn(WARN_BUG, "GenericCatchCrop::Do(): "
136  "Unknown event type! ", "");
137  exit(1);
138  }
139  return done;
140 }

References Farm::AutumnSow(), LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), g_date, g_msg, GCCR_ENDDATE, gccr_harvest, gccr_sow, gccr_start, LE::GetMDates(), Farm::Harvest(), Crop::m_ev, Crop::m_farm, Crop::m_field, FarmEvent::m_startday, FarmEvent::m_todo, Calendar::OldDays(), LE::SetMConstants(), LE::SetMDates(), Crop::SimpleEvent(), Crop::SimpleEvent_(), tov_GenericCatchCrop, MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void GenericCatchCrop::SetUpFarmCategoryInformation ( )
inline
58  {
59  const int elements = 2 + (gccr_foobar - GENERIC_CATCH_CROP_BASE);
61 
62  FarmManagementCategory catlist[elements] =
63  {
64  fmc_Others, // zero element unused but must be here
65  fmc_Others, // gccr_start = 1, // Compulsory, must always be 1 (one).
66  fmc_Others, // gccr_sleep_all_day = GENERIC_CATCH_CROP_BASE,
67  fmc_Others, // gccr_sow,
68  fmc_Harvest // gccr_harvest,
69 
70 
71  // no foobar entry
72 
73  };
74  // Iterate over the catlist elements and copy them to vector
75  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
76 
77  }

References fmc_Harvest, fmc_Others, gccr_foobar, GENERIC_CATCH_CROP_BASE, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by GenericCatchCrop().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
GENERIC_CATCH_CROP_BASE
#define GENERIC_CATCH_CROP_BASE
Definition: GenericCatchCrop.h:21
LE::SetMDates
void SetMDates(int a, int b, int c)
Definition: Elements.h:406
Farm::Harvest
virtual bool Harvest(LE *a_field, double a_user, int a_days)
Carry out a harvest on a_field.
Definition: FarmFuncs.cpp:1364
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
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
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
gccr_start
Definition: GenericCatchCrop.h:31
Calendar::Date
long Date(void)
Definition: Calendar.h:57
gccr_sow
Definition: GenericCatchCrop.h:33
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
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
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
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
GCCR_ENDDATE
#define GCCR_ENDDATE
Definition: GenericCatchCrop.h:23
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
GenericCatchCrop::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: GenericCatchCrop.h:58
Farm::AutumnSow
virtual bool AutumnSow(LE *a_field, double a_user, int a_days, double a_seed_coating_amount=-1, PlantProtectionProducts a_ppp=ppp_foobar)
Carry out a sowing event in the autumn on a_field.
Definition: FarmFuncs.cpp:360
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
gccr_harvest
Definition: GenericCatchCrop.h:34
tov_GenericCatchCrop
Definition: LandscapeFarmingEnums.h:339
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
Crop::SetCropClassification
void SetCropClassification(int a_classification)
Definition: Farm.h:549
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
gccr_foobar
Definition: GenericCatchCrop.h:35
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
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