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

#include <DK_OCatchCrop.h>

Inheritance diagram for DK_OCatchCrop:
Crop

Public Member Functions

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...
 
 DK_OCatchCrop (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

◆ DK_OCatchCrop()

DK_OCatchCrop::DK_OCatchCrop ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
58  : Crop(a_tov, a_toc, a_L)
59  {
60  m_first_date = g_date->DayInYear(16, 10);
62  }

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

Member Function Documentation

◆ Do()

bool DK_OCatchCrop::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 OCatchPeaCrop.

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.

42 {
43  /******************** This block can be added to the top of all Crop::Do methods ***********************************************/
44  m_farm = a_farm; // These assignments are necessary, not for this method but for related event calls
45  m_field = a_field;
46  m_ev = a_ev;
47  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
48  int d1 = 0;
49  int noDates = 1;
50  TTypesOfVegetation l_tov = tov_DKOCatchCrop; // The current type - change to match the crop you have
51 /**********************************************To Here *************************************************************************/
52 
53  // Depending what event has occured jump to the correct bit of code
54  switch (a_ev->m_todo)
55  {
56  case dk_occ_start:
57  {
58  a_field->ClearManagementActionSum();
59 
68  int noDates = 1;
69  m_field->SetMDates(0, 0, g_date->DayInYear(1, 1)); // This is the first day of sleep all day
70  m_field->SetMDates(1, 0, g_date->DayInYear(1, 2)); // This is the last day of sleep all day
71  m_field->SetMDates(0, 1, g_date->DayInYear(1, 2)); // This is the first day of spring plough
72  m_field->SetMDates(1, 1, g_date->DayInYear(10, 3)); // This is the last day of spring plough
73  // Now test for fixable late finishing problems
74  if (m_field->GetMDates(0, 0) >= m_ev->m_startday)
75  {
76  g_msg->Warn(WARN_BUG, "DK_OCatchCrop::Do(): Harvest too late for the next crop to start!!!", "");
77  exit(l_tov);
78  }
79  // 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])
80  for (int i = 0; i < noDates; i++) {
81  if (m_field->GetMDates(0, i) >= m_ev->m_startday) {
82  m_field->SetMDates(0, i, m_ev->m_startday - 1); //move the starting date
83  }
84  if (m_field->GetMDates(1, i) >= m_ev->m_startday) {
85  m_field->SetMConstants(i, 0);
86  m_field->SetMDates(1, i, m_ev->m_startday - 1); //move the finishing date
87  }
88  }
89  // Now all the date management things are checked we can start with the main code
90  d1 = g_date->OldDays() + g_date->DayInYear();
91  // Because we don't know the sow date when coding we have to use a variable here, hence GCCR_ENDDATE
92  DK_OCC_ENDDATE = g_date->DayInYear() + 7; // we allow 7 days for sowing
93  // Here we queue up the first event - this differs depending on whether we have a
94  // stock or arable farmer
95  SimpleEvent_(d1, dk_occ_stubble_harrow, false, a_farm, a_field);
96  }
97  break;
98 
99  // This is the first real farm operation
101  if (m_ev->m_lock || m_farm->DoIt_prob(0.50)) { // suggests 50% do a harrow before sowing, the rest sow directly in the stubble
102  if (!a_farm->StubbleHarrowing(a_field, 0.0, DK_OCC_ENDDATE - g_date->DayInYear())) {
104  break;
105  }
106  }
107  SimpleEvent(g_date->Date() + 1, dk_occ_sow, false);
108  break;
109  case dk_occ_sow:
110  if (!a_farm->AutumnSow(m_field, 0.0, g_date->DayInYear(16, 10) - g_date->DayInYear())) {
111  SimpleEvent(g_date->Date() + 1, dk_occ_sow, true);
112  break;
113  }
114  SimpleEvent(g_date->Date() + 40, dk_occ_winter_plough, false);
115  break;
117  if (m_field->GetSoilType() != tos_Sand && m_field->GetSoilType() != tos_LoamySand && m_field->GetSoilType() != tos_SandyLoam && m_field->GetSoilType() != tos_SandyClayLoam) // on clay soils (NL KLEI & VEEN)
118  {
119  if (!m_farm->WinterPlough(m_field, 0.0, g_date->DayInYear(31, 12) - g_date->DayInYear())) {
121  break;
122  }
123  // The plan is finished on clay soils (catch crop in incorporated into soil on autumn)
124  // Calling sleep_all_day to move to the next year d1 = g_date->OldDays() + 365 + m_field->GetMDates(0, 0);
125  d1 = g_date->OldDays() + 365 + m_field->GetMDates(0, 0);
126  SimpleEvent(d1, dk_occ_sleep_all_day, false);
127  break;
128  }
129  else d1 = g_date->OldDays() + 365 + m_field->GetMDates(0, 1);
130  SimpleEvent(d1, dk_occ_spring_plough, false);
131  break;
132 
134  if (!a_farm->SleepAllDay(a_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
136  break;
137  }
138  done = true;
139  break;
140 
142  if (!a_farm->SpringPlough(a_field, 0.0, m_field->GetMDates(1, 1) - g_date->DayInYear())) {
144  break;
145  }
146  done = true;
147  break;
148 
149  default:
150  g_msg->Warn(WARN_BUG, "DK_OCatchCrop::Do(): "
151  "Unknown event type! ", "");
152  exit(1);
153  }
154  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
155  return done;
156 }

References Farm::AutumnSow(), LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), DK_OCC_ENDDATE, dk_occ_sleep_all_day, dk_occ_sow, dk_occ_spring_plough, dk_occ_start, dk_occ_stubble_harrow, dk_occ_winter_plough, Farm::DoIt_prob(), g_date, g_msg, LE::GetMDates(), LE::GetSoilType(), 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(), Crop::SimpleEvent_(), Farm::SleepAllDay(), Farm::SpringPlough(), Farm::StubbleHarrowing(), tos_LoamySand, tos_Sand, tos_SandyClayLoam, tos_SandyLoam, tov_DKOCatchCrop, MapErrorMsg::Warn(), WARN_BUG, and Farm::WinterPlough().

◆ SetUpFarmCategoryInformation()

void DK_OCatchCrop::SetUpFarmCategoryInformation ( )
inline
63  {
64  const int elements = 2 + (dk_occ_foobar - DK_OCC_BASE);
66 
67  FarmManagementCategory catlist[elements] =
68  {
69  fmc_Others, // zero element unused but must be here
70  fmc_Others, // dk_occ_start = 1, // Compulsory, start event must always be 1 (one).
71  fmc_Others, // dk_occ_sleep_all_day = DK_OCC_BASE,
72  fmc_Cultivation, // dk_occ_stubble_harrow
73  fmc_Others, // dk_occ_sow
74  fmc_Cultivation, // dk_occ_winter_plough
75  fmc_Cultivation, // dk_occ_spring_plough
76  // No foobar entry
77  };
78  // Iterate over the catlist elements and copy them to vector
79  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
80  }

References DK_OCC_BASE, dk_occ_foobar, fmc_Cultivation, fmc_Others, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DK_OCatchCrop().


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
DK_OCC_BASE
#define DK_OCC_BASE
Definition: DK_OCatchCrop.h:39
LE::SetMDates
void SetMDates(int a, int b, int c)
Definition: Elements.h:406
Farm::SpringPlough
virtual bool SpringPlough(LE *a_field, double a_user, int a_days)
Carry out a ploughing event in the spring on a_field.
Definition: FarmFuncs.cpp:421
dk_occ_spring_plough
Definition: DK_OCatchCrop.h:48
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
dk_occ_foobar
Definition: DK_OCatchCrop.h:49
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
DK_OCatchCrop::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DK_OCatchCrop.h:63
tos_SandyClayLoam
Definition: LandscapeFarmingEnums.h:722
dk_occ_stubble_harrow
Definition: DK_OCatchCrop.h:45
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
tos_SandyLoam
Definition: LandscapeFarmingEnums.h:721
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
dk_occ_sleep_all_day
Definition: DK_OCatchCrop.h:44
tov_DKOCatchCrop
Definition: LandscapeFarmingEnums.h:421
dk_occ_sow
Definition: DK_OCatchCrop.h:46
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
LE::GetSoilType
int GetSoilType()
Definition: Elements.h:302
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
dk_occ_winter_plough
Definition: DK_OCatchCrop.h:47
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
dk_occ_start
Definition: DK_OCatchCrop.h:43
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
tos_Sand
Definition: LandscapeFarmingEnums.h:719
Farm::SleepAllDay
virtual bool SleepAllDay(LE *a_field, double a_user, int a_days)
Nothing to to today on a_field.
Definition: FarmFuncs.cpp:272
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
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
Farm::WinterPlough
virtual bool WinterPlough(LE *a_field, double a_user, int a_days)
Carry out a ploughing event in the winter on a_field.
Definition: FarmFuncs.cpp:395
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
DK_OCC_ENDDATE
#define DK_OCC_ENDDATE
Definition: DK_OCatchCrop.h:40
LE::SetMConstants
void SetMConstants(int a, int c)
Definition: Elements.h:408
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
tos_LoamySand
Definition: LandscapeFarmingEnums.h:720
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
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