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

DK_OCloverGrassGrazed3 class
. More...

#include <DK_OCloverGrassGrazed3.h>

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

DK_OCloverGrassGrazed3 class
.

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

◆ DK_OCloverGrassGrazed3()

DK_OCloverGrassGrazed3::DK_OCloverGrassGrazed3 ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
98  : Crop(a_tov, a_toc, a_L)
99  {
100  // When we start it off, the first possible date for a farm operation
101  // This information is used by other crops when they decide how much post processing of
102  // the management is allowed after harvest before the next crop starts.
103  m_first_date = g_date->DayInYear(1, 4);
105  }

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

Member Function Documentation

◆ Do()

bool DK_OCloverGrassGrazed3::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 spring barley Fodder.

Reimplemented from Crop.

88 {
89  m_field = a_field; // this is needed because of possible calls to other methods and currently we do not pass parameters.
90  m_farm = a_farm; // this is needed because of possible calls to other methods and currently we do not pass parameters.
91  m_ev = a_ev;
92  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
93  int d1 = 0;
95  // Depending what event has occured jump to the correct bit of code e.g. for ww_start jump to line 67 below
96  switch (a_ev->m_todo)
97  {
98  case dk_oc3_start:
99  {
100  a_field->ClearManagementActionSum();
101 
102  m_last_date = g_date->DayInYear(10, 10); // Should match the last flexdate below
103  //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
104  std::vector<std::vector<int>> flexdates(4 + 1, std::vector<int>(2, 0));
105  // Set up the date management stuff
106  // Start and stop dates for all events after harvest
107  flexdates[0][1] = g_date->DayInYear(10, 7); // last possible day of ferti
108  // Now these are done in pairs, start & end for each operation. If its not used then -1
109  flexdates[1][0] = -1;
110  flexdates[1][1] = g_date->DayInYear(20, 7); // This date will be moved back as far as necessary and potentially to flexdates 1 (end op 1) - cutting
111  flexdates[2][0] = -1;
112  flexdates[2][1] = g_date->DayInYear(20, 8); // This date will be moved back as far as necessary and potentially to flexdates 2 (end op 2) - cutting
113  flexdates[3][0] = -1;
114  flexdates[3][1] = g_date->DayInYear(20, 9); // This date will be moved back as far as necessary and potentially to flexdates 3 (end op 3) - cutting
115  flexdates[4][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 4 (start op 4)
116  flexdates[4][1] = g_date->DayInYear(10, 10); // This date will be moved back as far as necessary and potentially to flexdates 4 (end op 4) - cattle is out // changed back from 1/11 to 10/10 to fit rots
117  //flexdates[5][0] = -1;
118  //flexdates[5][1] = g_date->DayInYear(1, 11); - we need to update grazing / cutting managements (grazing model)
119 
120  // Below if this is a spring crop use 365, otherwise set this to 0, second parameter is fixed, and the third is the start up operation in the first year
121  int isSpring = 365;
122  if (StartUpCrop(isSpring, flexdates, int(dk_oc3_manure1_s))) break;
123 
124  // End single block date checking code. Please see next line comment as well.
125  // Reinit d1 to first possible starting date.
126  d1 = g_date->OldDays() + g_date->DayInYear(1, 3) + isSpring;
127  // OK, let's go.
128  // Here we queue up the first event which changes dependent on whether it is a forced spring sow or not
129  if (a_farm->IsStockFarmer()) {
130  SimpleEvent(d1, dk_oc3_manure1_s, false);
131  break;
132  }
133  else SimpleEvent(d1, dk_oc3_manure1_p, false);
134  break;
135  }
136  break;
137 
138  case dk_oc3_manure1_s:
139  if (!a_farm->FA_Manure(a_field, 0.0, g_date->DayInYear(1, 4) - g_date->DayInYear())) {
140  SimpleEvent(g_date->Date() + 1, dk_oc3_manure1_s, true);
141  break;
142  }
143  //fork of parallel events:
144  SimpleEvent(g_date->OldDays() + g_date->DayInYear(10, 4), dk_oc3_grazing, false); // main thread
145  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 6), dk_oc3_water, false); // water thread
146  break;
147  case dk_oc3_manure1_p:
148  if (!a_farm->FP_Manure(a_field, 0.0, g_date->DayInYear(1, 4) - g_date->DayInYear())) {
149  SimpleEvent(g_date->Date() + 1, dk_oc3_manure1_p, true);
150  break;
151  }
152  //fork of parallel events:
153  SimpleEvent(g_date->OldDays() + g_date->DayInYear(10, 4), dk_oc3_grazing, false); // main thread
154  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 6), dk_oc3_water, false); // water thread
155  break;
156  case dk_oc3_water:
157  if (a_ev->m_lock || a_farm->DoIt_prob(0.50)) {
158  if (!a_farm->Water(a_field, 0.0,
159  g_date->DayInYear(1, 9) - g_date->DayInYear())) {
160  SimpleEvent(g_date->Date() + 1, dk_oc3_water, true);
161  break;
162  }
163  }
164  break;
165 
166  case dk_oc3_grazing: //80% do grazing, rest do cutting
167  if (a_ev->m_lock || a_farm->DoIt(80)) {
169  if (a_field->GetVegHeight() < cfg_farm_cattle_grass_low.value()) GRASS_READY_OC3 = false;
170  if (!a_farm->CattleOut(a_field, 0.0, g_date->DayInYear(15, 4) - g_date->DayInYear(), GRASS_READY_OC3)) {
171  SimpleEvent(g_date->Date() + 1, dk_oc3_grazing, true);
172  break;
173  }
175  break;
176  }
177  else SimpleEvent(g_date->OldDays() + g_date->DayInYear(10, 5), dk_oc3_cutting1, false);
178  break;
179 
180  case dk_oc3_cutting1:
181  if (!a_farm->CutToSilage(a_field, 0.0,
182  g_date->DayInYear(20, 5) - g_date->DayInYear())) {
183  SimpleEvent(g_date->Date() + 1, dk_oc3_cutting1, true);
184  break;
185  }
186  if (a_farm->IsStockFarmer()) {
188  break;
189  }
190  else SimpleEvent(g_date->OldDays() + g_date->DayInYear(20, 5), dk_oc3_manure2_p, false);
191  break;
192 
193  case dk_oc3_cattle_is_out: // Keep the cattle out there
194  // CattleIsOut() returns false if it is not time to stop grazing
196  if (a_field->GetVegHeight() < cfg_farm_cattle_grass_low.value()) GRASS_READY_OC3 = false;
197  if (!a_farm->CattleIsOut(a_field, 0.0, g_date->DayInYear(10, 10) - g_date->DayInYear(), g_date->DayInYear(10, 10), GRASS_READY_OC3)) {
199  break;
200  }
201  done = true; // end of plan
202  break;
203 
204  case dk_oc3_manure2_s:
205  if (!a_farm->FA_Manure(a_field, 0.0, g_date->DayInYear(10, 6) - g_date->DayInYear())) {
206  SimpleEvent(g_date->Date() + 1, dk_oc3_manure2_s, true);
208  break;
209  }
211  break;
212 
213  case dk_oc3_manure2_p:
214  if (!a_farm->FP_Manure(a_field, 0.0, g_date->DayInYear(10, 6) - g_date->DayInYear())) {
215  SimpleEvent(g_date->Date() + 1, dk_oc3_manure2_p, true);
216  break;
217  }
219  break;
220 
221  case dk_oc3_cutting2: //
222  if (!a_farm->CutToSilage(a_field, 0.0,
223  g_date->DayInYear(20, 6) - g_date->DayInYear())) {
224  SimpleEvent(g_date->Date() + 1, dk_oc3_cutting2, true);
225  break;
226  }
227  if (a_farm->IsStockFarmer()) {
229  break;
230  }
231  else SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 7), dk_oc3_manure3_p, false);
232  break;
233 
234  case dk_oc3_manure3_s: // only if still available (allowed to apply more on field, 25% of 50% = 12.5% as suggestion)
235  if (a_ev->m_lock || a_farm->DoIt(25)) {
236  if (!a_farm->FA_Manure(a_field, 0.0, a_field->GetMDates(1, 0) - g_date->DayInYear())) {
237  SimpleEvent(g_date->Date() + 1, dk_oc3_manure3_s, true);
238  break;
239  }
240  }
241  SimpleEvent(g_date->Date() + 7, dk_oc3_cutting3, false); //main thread
242  break;
243 
244  case dk_oc3_manure3_p: // only if still available (allowed to apply more on field, 25% of 50% = 12.5% as suggestion)
245  if (a_ev->m_lock || a_farm->DoIt(25)) {
246  if (!a_farm->FP_Manure(a_field, 0.0, a_field->GetMDates(1, 0) - g_date->DayInYear())) {
247  SimpleEvent(g_date->Date() + 1, dk_oc3_manure3_p, true);
248  break;
249  }
250  }
251  SimpleEvent(g_date->Date() + 7, dk_oc3_cutting3, false); //main thread
252  break;
253 
254  case dk_oc3_cutting3: //
255  if (!a_farm->CutToSilage(a_field, 0.0, a_field->GetMDates(1, 1) - g_date->DayInYear())) {
256  SimpleEvent(g_date->Date() + 1, dk_oc3_cutting3, true);
257  break;
258  }
259  SimpleEvent(g_date->Date() + 20, dk_oc3_cutting4, false);
260  break;
261 
262  case dk_oc3_cutting4: //
263  if (!a_farm->CutToSilage(a_field, 0.0, a_field->GetMDates(1, 2) - g_date->DayInYear())) {
264  SimpleEvent(g_date->Date() + 1, dk_oc3_cutting4, true);
265  break;
266  }
267  SimpleEvent(g_date->Date() + 20, dk_oc3_cutting5, false);
268  break;
269 
270  case dk_oc3_cutting5: //
271  if (!a_farm->CutToSilage(a_field, 0.0, a_field->GetMDates(1, 3) - g_date->DayInYear())) {
272  SimpleEvent(g_date->Date() + 1, dk_oc3_cutting5, true);
273  break;
274  }
275  done = true; // end of plan
276  break;
277  // So we are done, and somewhere else the farmer will queue up the start event of the next crop
278  // END OF MAIN THREAD
279  default:
280  g_msg->Warn(WARN_BUG, "DK_OCloverGrassGrazed3::Do(): "
281  "Unknown event type! ", "");
282  exit(1);
283  }
284  if (done) a_ev->m_forcespring = true; // Here we need to force the next crop to spring operation, so set the ev->forcespring to true
285  return done;
286 }

References Farm::CattleIsOut(), Farm::CattleOut(), cfg_farm_cattle_grass_high, cfg_farm_cattle_grass_low, LE::ClearManagementActionSum(), Farm::CutToSilage(), Calendar::Date(), Calendar::DayInYear(), dk_oc3_cattle_is_out, dk_oc3_cutting1, dk_oc3_cutting2, dk_oc3_cutting3, dk_oc3_cutting4, dk_oc3_cutting5, dk_oc3_grazing, dk_oc3_manure1_p, dk_oc3_manure1_s, dk_oc3_manure2_p, dk_oc3_manure2_s, dk_oc3_manure3_p, dk_oc3_manure3_s, dk_oc3_start, dk_oc3_water, Farm::DoIt(), Farm::DoIt_prob(), Farm::FA_Manure(), Farm::FP_Manure(), g_date, g_msg, LE::GetMDates(), LE::GetVegHeight(), GRASS_READY_OC3, 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(), Crop::SimpleEvent(), Crop::StartUpCrop(), tov_DKOCloverGrassGrazed3, CfgInt::value(), MapErrorMsg::Warn(), WARN_BUG, and Farm::Water().

◆ SetUpFarmCategoryInformation()

void DK_OCloverGrassGrazed3::SetUpFarmCategoryInformation ( )
inline
106  {
107  const int elements = 2 + (dk_oc3_foobar - DK_OC3_BASE);
109 
110  FarmManagementCategory catlist[elements] =
111  {
112  fmc_Others, // zero element unused but must be here
113  fmc_Others, // dk_oc3_start = 1, // Compulsory, must always be 1 (one).
114  fmc_Others, // dk_oc3_sleep_all_day = DK_oc3_BASE,
115  fmc_Fertilizer, // dk_oc3_manure1_s,
116  fmc_Fertilizer, // dk_oc3_manure1_p,
117  fmc_Watering, // dk_oc3_water,
118  fmc_Cutting, // dk_oc3_cutting1
119  fmc_Grazing, // dk_oc3_grazing,
120  fmc_Grazing, // dk_oc3_cattle_is_out,
121  fmc_Fertilizer, // dk_oc3_manure2_s,
122  fmc_Fertilizer, // dk_oc3_manure2_p,
123  fmc_Cutting, // dk_oc3_cutting2,
124  fmc_Fertilizer, // dk_oc3_manure3_s,
125  fmc_Fertilizer, // dk_oc3_manure3_p,
126  fmc_Cutting, // dk_oc3_cutting3,
127  fmc_Cutting, // dk_oc3_cutting4,
128  fmc_Cutting, // dk_oc3_cutting5,
129  // no foobar entry
130 
131  };
132  // Iterate over the catlist elements and copy them to vector
133  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
134 
135  }

References DK_OC3_BASE, dk_oc3_foobar, fmc_Cutting, fmc_Fertilizer, fmc_Grazing, fmc_Others, fmc_Watering, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DK_OCloverGrassGrazed3().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
dk_oc3_cattle_is_out
Definition: DK_OCloverGrassGrazed3.h:73
FarmEvent::m_forcespring
bool m_forcespring
Definition: Farm.h:392
Farm::IsStockFarmer
bool IsStockFarmer(void)
Definition: Farm.h:961
dk_oc3_manure1_s
Definition: DK_OCloverGrassGrazed3.h:68
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
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
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
cfg_farm_cattle_grass_high
CfgInt cfg_farm_cattle_grass_high
Farm::FA_Manure
virtual bool FA_Manure(LE *a_field, double a_user, int a_days)
Spread manure on a_field owned by an stock farmer.
Definition: FarmFuncs.cpp:1110
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
GRASS_READY_OC3
#define GRASS_READY_OC3
Definition: DK_OCloverGrassGrazed3.h:54
dk_oc3_manure3_s
Definition: DK_OCloverGrassGrazed3.h:77
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_oc3_manure2_p
Definition: DK_OCloverGrassGrazed3.h:75
Farm::FP_Manure
virtual bool FP_Manure(LE *a_field, double a_user, int a_days)
Spread manure on a_field owned by an arable farmer.
Definition: FarmFuncs.cpp:896
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
dk_oc3_start
Definition: DK_OCloverGrassGrazed3.h:66
DK_OC3_BASE
#define DK_OC3_BASE
Definition: DK_OCloverGrassGrazed3.h:53
cfg_farm_cattle_grass_low
CfgInt cfg_farm_cattle_grass_low
Calendar::Date
long Date(void)
Definition: Calendar.h:57
dk_oc3_manure1_p
Definition: DK_OCloverGrassGrazed3.h:69
dk_oc3_cutting5
Definition: DK_OCloverGrassGrazed3.h:81
dk_oc3_foobar
Definition: DK_OCloverGrassGrazed3.h:82
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
LE::GetVegHeight
virtual double GetVegHeight(void)
Definition: Elements.h:148
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_oc3_manure2_s
Definition: DK_OCloverGrassGrazed3.h:74
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_oc3_cutting3
Definition: DK_OCloverGrassGrazed3.h:79
Crop::m_farm
Farm * m_farm
Definition: Farm.h:498
Crop::m_field
LE * m_field
Definition: Farm.h:499
CfgInt::value
int value() const
Definition: Configurator.h:116
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_oc3_cutting4
Definition: DK_OCloverGrassGrazed3.h:80
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
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
fmc_Grazing
Definition: LandscapeFarmingEnums.h:1010
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
dk_oc3_cutting2
Definition: DK_OCloverGrassGrazed3.h:76
dk_oc3_manure3_p
Definition: DK_OCloverGrassGrazed3.h:78
tov_DKOCloverGrassGrazed3
Definition: LandscapeFarmingEnums.h:376
dk_oc3_cutting1
Definition: DK_OCloverGrassGrazed3.h:71
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
dk_oc3_water
Definition: DK_OCloverGrassGrazed3.h:70
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
DK_OCloverGrassGrazed3::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DK_OCloverGrassGrazed3.h:106
dk_oc3_grazing
Definition: DK_OCloverGrassGrazed3.h:72
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