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

#include <DK_OSpringBarleyCloverGrass.h>

Inheritance diagram for DK_OSpringBarleyCloverGrass:
Crop

Public Member Functions

bool Do (Farm *a_farm, LE *a_field, FarmEvent *a_ev)
 
 DK_OSpringBarleyCloverGrass (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_OSpringBarleyCloverGrass()

DK_OSpringBarleyCloverGrass::DK_OSpringBarleyCloverGrass ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
61  : Crop(a_tov, a_toc, a_L)
62  {
65  }

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

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

34 {
35 
36  m_farm = a_farm;
37  m_field = a_field;
38  m_ev = a_ev;
39  int d1 = 0;
40 
41  bool done = false;
42  int l_nextcropstartdate;
44  switch ( m_ev->m_todo )
45  {
46  case dk_osbcg_start:
47  {
48 
49  a_field->ClearManagementActionSum();
50  m_last_date = g_date->DayInYear(16, 10); // Should match the last flexdate below
51  //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
52  std::vector<std::vector<int>> flexdates(3 + 1, std::vector<int>(2, 0));
53  // Set up the date management stuff
54  // Start and stop dates for all events after harvest
55  flexdates[0][1] = g_date->DayInYear(20, 8); // last possible day of harvest in this case - this is in effect day before the earliest date that a following crop can use
56  // Now these are done in pairs, start & end for each operation. If its not used then -1
57  flexdates[1][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 1 (start op 1)
58  flexdates[1][1] = g_date->DayInYear(21, 8); // This date will be moved back as far as necessary and potentially to flexdates 1 (end op 1) straw chopping
59  flexdates[2][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 2 (start op 2)
60  flexdates[2][1] = g_date->DayInYear(21, 8); // This date will be moved back as far as necessary and potentially to flexdates 1 (end op 2) hay bailing
61  flexdates[3][0] = g_date->DayInYear(2, 9); // This date will be moved back as far as necessary and potentially to flexdates 4 (start op 4)
62  flexdates[3][1] = g_date->DayInYear(16, 10); // This date will be moved back as far as necessary and potentially to flexdates 4 (end op 4) cattle is out
63 
64 
65  // Below if this is a spring crop use 365, otherwise first parameter is always 0, second parameter is fixed, and the third is the start up operation in the first year
66  int isSpring = 365;
67  if (StartUpCrop(isSpring, flexdates, int(dk_osbcg_spring_harrow1))) break;
68 
69  // End single block date checking code. Please see next line comment as well.
70  // Reinit d1 to first possible starting date.
71  d1 = g_date->OldDays() + g_date->DayInYear(1, 3) + isSpring;
72  if (m_ev->m_forcespring) {
73  int day_num_shift = 365;
74  if (g_date->DayInYear() < 70) day_num_shift = 0;
75  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 3) + day_num_shift, dk_osbcg_spring_harrow1, false);
76  break;
77  }
78  else
79  // OK, let's go.
81  break;
82  }
83  break;
84 
86  if (m_ev->m_lock || m_farm->DoIt(100)) {
87  if (!m_farm->SpringHarrow(m_field, 0.0,
88  g_date->DayInYear(29, 3) - g_date->DayInYear())) {
90  break;
91  }
92  }
94  break;
95 
97  if (m_ev->m_lock || m_farm->DoIt(50)) { //suggestion as done 1-2 times
98  if (!m_farm->SpringHarrow(m_field, 0.0,
99  g_date->DayInYear(30, 3) - g_date->DayInYear())) {
101  break;
102  }
103  }
104  if (a_farm->IsStockFarmer()) {
106  break;
107  }
108  else SimpleEvent(g_date->Date(), dk_osbcg_slurry_p, false);
109  break;
110  case dk_osbcg_slurry_s:
111  if (!m_farm->FA_Slurry(m_field, 0.0,
112  g_date->DayInYear(30, 3) - g_date->DayInYear())) {
113  SimpleEvent(g_date->Date() + 1, dk_osbcg_slurry_s, true);
114  break;
115  }
117  break;
118 
119  case dk_osbcg_slurry_p:
120  if (!m_farm->FP_Slurry(m_field, 0.0,
121  g_date->DayInYear(30, 3) - g_date->DayInYear())) {
122  SimpleEvent(g_date->Date() + 1, dk_osbcg_slurry_p, true);
123  break;
124  }
126  break;
128  if (!m_farm->SpringPlough(m_field, 0.0,
129  g_date->DayInYear(29, 4) - g_date->DayInYear())) {
131  break;
132  }
133  SimpleEvent(g_date->Date() + 1, dk_osbcg_spring_sow, false);
134  break;
135  case dk_osbcg_spring_sow:
136  if (!m_farm->SpringSow( m_field, 0.0,
137  g_date->DayInYear( 30,4 ) - g_date->DayInYear())) {
138  SimpleEvent( g_date->Date() + 1, dk_osbcg_spring_sow, true );
139  break;
140  }
142  break;
144  if (m_ev->m_lock || m_farm->DoIt_prob(1.00)) {
145  if (!m_farm->ShallowHarrow(m_field, 0.0,
146  g_date->DayInYear(10, 5) - g_date->DayInYear())) {
148  break;
149  }
150  }
152  break;
154  if (!m_farm->ShallowHarrow(m_field, 0.0,
155  g_date->DayInYear(20, 5) - g_date->DayInYear())) {
157  break;
158  }
160  break;
161 
162  case dk_osbcg_water:
163  if (m_ev->m_lock || m_farm->DoIt_prob(0.50)) {
164  if (!m_farm->Water(m_field, 0.0,
165  g_date->DayInYear(30, 7) - g_date->DayInYear())) {
166  SimpleEvent(g_date->Date() + 1, dk_osbcg_water, true);
167  break;
168  }
169  }
171  break;
172  case dk_osbcg_swathing:
173  if (m_ev->m_lock || m_farm->DoIt_prob(0.10)) {
174  if (!m_farm->Swathing(m_field, 0.0,
175  g_date->DayInYear(18, 8) -
176  g_date->DayInYear())) {
177  SimpleEvent(g_date->Date() + 1, dk_osbcg_swathing, true);
178  break;
179  }
180  }
181  SimpleEvent(g_date->Date()+2, dk_osbcg_harvest, false);
182  break;
183  case dk_osbcg_harvest:
184  if (!m_farm->Harvest(m_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
185  SimpleEvent(g_date->Date() + 1, dk_osbcg_harvest, true);
186  break;
187  }
189  break;
190 
192  if (m_ev->m_lock || m_farm->DoIt_prob(0.10)) {
193  if (!m_farm->StrawChopping(m_field, 0.0, m_field->GetMDates(1, 1) - g_date->DayInYear())) {
195  break;
196  }
197  SimpleEvent(g_date->Date(), dk_osbcg_wait, false);
198  break;
199  }
200  else SimpleEvent(g_date->Date() + 1, dk_osbcg_hay_baling, false);
201  break;
202 
203  case dk_osbcg_hay_baling:
204  if (!m_farm->HayBailing(m_field, 0.0, m_field->GetMDates(1, 2) - g_date->DayInYear())) {
206  break;
207  }
208  SimpleEvent(g_date->Date(), dk_osbcg_wait, false);
209  break;
210 
211  case dk_osbcg_wait:
212  // Something special here.
213  // If the cattle out period is very short then we don't want to do it at all
214  if (m_field->GetMDates(1, 3) - m_field->GetMDates(0, 3) < 14) {
215  d1 = g_date->Date();
216  if (d1 < g_date->OldDays() + g_date->DayInYear(1, 7)) {
218  // Because we are ending harvest before 1.7 so we need to wait until the 1.7
219  break;
220  }
221  }
222  done = true;
223  break;
224 
225  default:
226  g_msg->Warn( WARN_BUG, "DK_OSpringBarleyCloverGrass::Do(): "
227  "Unknown event type! ", "" );
228  exit( 1 );
229  }
230  return done;
231 }

References LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), dk_osbcg_harvest, dk_osbcg_hay_baling, dk_osbcg_shallow_harrow1, dk_osbcg_shallow_harrow2, dk_osbcg_slurry_p, dk_osbcg_slurry_s, dk_osbcg_spring_harrow1, dk_osbcg_spring_harrow2, dk_osbcg_spring_plough, dk_osbcg_spring_sow, dk_osbcg_start, dk_osbcg_straw_chopping, dk_osbcg_swathing, dk_osbcg_wait, dk_osbcg_water, Farm::DoIt(), Farm::DoIt_prob(), Farm::FA_Slurry(), Farm::FP_Slurry(), g_date, g_msg, LE::GetMDates(), Farm::Harvest(), Farm::HayBailing(), Farm::IsStockFarmer(), Crop::m_ev, Crop::m_farm, Crop::m_field, FarmEvent::m_forcespring, Crop::m_last_date, FarmEvent::m_lock, FarmEvent::m_todo, Calendar::OldDays(), Farm::ShallowHarrow(), Crop::SimpleEvent(), Farm::SpringHarrow(), Farm::SpringPlough(), Farm::SpringSow(), Crop::StartUpCrop(), Farm::StrawChopping(), Farm::Swathing(), tov_DKOSpringBarleyCloverGrass, MapErrorMsg::Warn(), WARN_BUG, and Farm::Water().

◆ SetUpFarmCategoryInformation()

void DK_OSpringBarleyCloverGrass::SetUpFarmCategoryInformation ( )
inline
66  {
67  const int elements = 2 + (dk_osbcg_foobar - DK_OSBCG_BASE);
69 
70  FarmManagementCategory catlist[elements] =
71  {
72  fmc_Others, // zero element unused but must be here
73  fmc_Others, // dk_osbcg_start = 1, // Compulsory, start event must always be 1 (one).
74  fmc_Cultivation, // dk_osbcg_spring_harrow = DK_OSBCG_BASE,
75  fmc_Cultivation, // dk_osbcg_spring_harrow
76  fmc_Fertilizer, // dk_osbcg_slurry,
77  fmc_Fertilizer, // dk_osbcg_slurry,
78  fmc_Cultivation, // dk_osbcg_spring_plough,
79  fmc_Others, // dk_osbcg_spring_sow,
80  fmc_Cultivation, // dk_osbcg_shallow_harrow1,
81  fmc_Cultivation, // dk_osbcg_shallow_harrow2,
82  fmc_Watering, // dk_osbcg_water,
83  fmc_Cutting, // dk_osbcg_swathing,
84  fmc_Harvest, // dk_osbcg_harvest,
85  fmc_Others, // dk_osbcg_straw_chopping,
86  fmc_Others, // dk_osbcg_hay_baling,
87  fmc_Cutting, // dk_osbcg_cut_to_hay,
88  fmc_Cultivation, // dk_osbcg_stubble_harrow,
89  fmc_Cultivation, // dk_osbcg_plough,
90  fmc_Others, // dk_osbcg_wait,
91 
92  // no foobar entry
93 
94  };
95  // Iterate over the catlist elements and copy them to vector
96  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
97 
98  }

References DK_OSBCG_BASE, dk_osbcg_foobar, fmc_Cultivation, fmc_Cutting, fmc_Fertilizer, fmc_Harvest, fmc_Others, fmc_Watering, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DK_OSpringBarleyCloverGrass().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
DK_OSBCG_BASE
#define DK_OSBCG_BASE
Definition: DK_OSpringBarleyCloverGrass.h:31
dk_osbcg_foobar
Definition: DK_OSpringBarleyCloverGrass.h:52
FarmEvent::m_forcespring
bool m_forcespring
Definition: Farm.h:392
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
dk_osbcg_water
Definition: DK_OSpringBarleyCloverGrass.h:43
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
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: Farm.h:961
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
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: Farm.cpp:856
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
dk_osbcg_shallow_harrow1
Definition: DK_OSpringBarleyCloverGrass.h:41
Farm::SpringSow
virtual bool SpringSow(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 spring on a_field.
Definition: FarmFuncs.cpp:501
dk_osbcg_slurry_s
Definition: DK_OSpringBarleyCloverGrass.h:37
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
dk_osbcg_spring_sow
Definition: DK_OSpringBarleyCloverGrass.h:40
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
dk_osbcg_harvest
Definition: DK_OSpringBarleyCloverGrass.h:45
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
dk_osbcg_spring_harrow1
Definition: DK_OSpringBarleyCloverGrass.h:35
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
tov_DKOSpringBarleyCloverGrass
Definition: LandscapeFarmingEnums.h:364
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Cultivation
Definition: LandscapeFarmingEnums.h:1008
Farm::HayBailing
virtual bool HayBailing(LE *a_field, double a_user, int a_days)
Carry out hay bailing on a_field.
Definition: FarmFuncs.cpp:1507
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
dk_osbcg_start
Definition: DK_OSpringBarleyCloverGrass.h:34
Farm::StrawChopping
virtual bool StrawChopping(LE *a_field, double a_user, int a_days)
Carry out straw chopping on a_field.
Definition: FarmFuncs.cpp:1475
fmc_Watering
Definition: LandscapeFarmingEnums.h:1011
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
dk_osbcg_spring_plough
Definition: DK_OSpringBarleyCloverGrass.h:39
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
dk_osbcg_hay_baling
Definition: DK_OSpringBarleyCloverGrass.h:47
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
DK_OSpringBarleyCloverGrass::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DK_OSpringBarleyCloverGrass.h:66
Farm::ShallowHarrow
virtual bool ShallowHarrow(LE *a_field, double a_user, int a_days)
Carry out a shallow harrow event on a_field, e.g., after grass cutting event.
Definition: FarmFuncs.cpp:473
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
Farm::Water
virtual bool Water(LE *a_field, double a_user, int a_days)
Carry out a watering on a_field.
Definition: FarmFuncs.cpp:1330
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
dk_osbcg_wait
Definition: DK_OSpringBarleyCloverGrass.h:51
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
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_osbcg_straw_chopping
Definition: DK_OSpringBarleyCloverGrass.h:46
dk_osbcg_slurry_p
Definition: DK_OSpringBarleyCloverGrass.h:38
Farm::Swathing
virtual bool Swathing(LE *a_field, double a_user, int a_days)
Cut the crop on a_field and leave it lying (probably rape)
Definition: FarmFuncs.cpp:1350
dk_osbcg_spring_harrow2
Definition: DK_OSpringBarleyCloverGrass.h:36
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
dk_osbcg_shallow_harrow2
Definition: DK_OSpringBarleyCloverGrass.h:42
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
dk_osbcg_swathing
Definition: DK_OSpringBarleyCloverGrass.h:44
Farm::SpringHarrow
virtual bool SpringHarrow(LE *a_field, double a_user, int a_days)
Carry out a harrow event in the spring on a_field.
Definition: FarmFuncs.cpp:459