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

#include <DK_CloverGrassGrazed1.h>

Inheritance diagram for DK_CloverGrassGrazed1:
Crop

Public Member Functions

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

DK_CloverGrassGrazed1::DK_CloverGrassGrazed1 ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
88  : Crop(a_tov, a_toc, a_L)
89  {
90  m_first_date = g_date->DayInYear(1, 12);
92  }

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

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

82 {
83  m_farm = a_farm;
84  m_field = a_field;
85  m_ev = a_ev;
86  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true, m_farm, m_field).
87  bool flag = false;
88  int d1 = 0;
89  int noDates = 1;
90  TTypesOfVegetation l_tov = tov_DKCloverGrassGrazed1; // The current type - change to match the crop you have
91 
92  switch (m_ev->m_todo)
93  {
94  case dk_c1_start:
95  {
96  a_field->ClearManagementActionSum();
97 
98  DK_C1_CUT = false;
99 
100  m_last_date = g_date->DayInYear(30, 9); // Should match the last flexdate below
101  //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
102  std::vector<std::vector<int>> flexdates(2 + 1, std::vector<int>(2, 0));
103  // Set up the date management stuff
104  // Start and stop dates for all events after harvest
105  flexdates[0][1] = g_date->DayInYear(28, 9); // last possible day (swathing)
106  // Now these are done in pairs, start & end for each operation. If its not used then -1
107  flexdates[1][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 1 (start op 1)
108  flexdates[1][1] = g_date->DayInYear(30, 9); // This date will be moved back as far as necessary and potentially to flexdates 1 (end op 1) harvest
109  flexdates[2][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 2 (start op 2)
110  flexdates[2][1] = g_date->DayInYear(30, 9); // This date will be moved back as far as necessary and potentially to flexdates 2 (end op 2) straw removal
111 
112  // 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
113  int isSpring = 365;
114  if (StartUpCrop(isSpring, flexdates, int(dk_c1_sow_spot))) break;
115 
116  // End single block date checking code. Please see next line comment as well.
117  // Reinit d1 to first possible starting date.
118  d1 = g_date->OldDays() + g_date->DayInYear(1, 3) + isSpring;
119  // OK, let's go.
120  SimpleEvent(d1, dk_c1_sow_spot, false);
121  }
122  break;
123 
124  case dk_c1_sow_spot:
125  if (m_ev->m_lock || m_farm->DoIt_prob(.04)) {
126  if (!m_farm->SpringSow(m_field, 0.0,
127  g_date->DayInYear(30, 4) - g_date->DayInYear())) {
128  SimpleEvent(g_date->Date() + 1, dk_c1_sow_spot, true);
129  break;
130  }
131  }
132  SimpleEvent(g_date->OldDays() + g_date->DayInYear(15, 4), dk_c1_water, false); // water thread
133  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 5), dk_c1_cutting1, false);// main thread
134  break;
135 
136  case dk_c1_water:
137  if (m_ev->m_lock || m_farm->DoIt_prob(.50)) { // 50% water
138  if (!m_farm->Water(m_field, 0.0,
139  g_date->DayInYear(31, 5) - g_date->DayInYear())) {
140  SimpleEvent(g_date->Date() + 1, dk_c1_water, true);
141  break;
142  }
143  }
144  break; // end of thread
145 
146  case dk_c1_cutting1:
147  if (m_ev->m_lock || m_farm->DoIt_prob(.90)) { // 90% cut to silage, 10% graze
148  if (!m_farm->CutToSilage(m_field, 0.0,
149  g_date->DayInYear(15, 6) - g_date->DayInYear())) {
150  SimpleEvent(g_date->Date() + 1, dk_c1_cutting1, true);
151  break;
152  }
153  DK_C1_CUT = true; //we need to remember who did cutting
154  SimpleEvent(g_date->Date() + 35, dk_c1_cutting2, false);
155  break;
156  }
157  else{
159  break;
160  }
161 
162  case dk_c1_cutting_graze:
163  if (m_ev->m_lock || m_farm->DoIt_prob(.50)) { // 50% cut to silage of the 10% that will do grazing
164  if (!m_farm->CutToSilage(m_field, 0.0,
165  g_date->DayInYear(1, 6) - g_date->DayInYear())) {
167  break;
168  }
169  SimpleEvent(g_date->Date() + 14, dk_c1_grazing, false);
170  break;
171  }
173  break;
174 
175  case dk_c1_cutting2:
176  if (DK_C1_CUT == true) {
177  if (!m_farm->CutToSilage(m_field, 0.0,
178  g_date->DayInYear(20, 7) - g_date->DayInYear())) {
179  SimpleEvent(g_date->Date() + 1, dk_c1_cutting2, true);
180  break;
181  }
182  }
184  break;
185 
186  case dk_c1_grazing:
187  if (a_field->GetVegHeight() > cfg_farm_cattle_grass_high.value()) GRASS_READY_C1 = true;
188  if (a_field->GetVegHeight() < cfg_farm_cattle_grass_low.value()) GRASS_READY_C1 = false;
189  if (!m_farm->CattleOut(m_field, 0.0, g_date->DayInYear(15, 6) - g_date->DayInYear(), GRASS_READY_C1)) {
190  SimpleEvent(g_date->Date() + 1, dk_c1_grazing, true);
191  break;
192  }
193  SimpleEvent(g_date->Date() + 1, dk_c1_cattle_out, false);
194  break;
195 
196  case dk_c1_cattle_out: // Keep the cattle out there
197  // CattleIsOut() returns false if it is not time to stop grazing
198  if (a_field->GetVegHeight() > cfg_farm_cattle_grass_high.value()) GRASS_READY_C1 = true;
199  if (a_field->GetVegHeight() < cfg_farm_cattle_grass_low.value()) GRASS_READY_C1 = false;
200  if (!a_farm->CattleIsOut(a_field, 0.0, g_date->DayInYear(10, 7) - g_date->DayInYear(), g_date->DayInYear(26, 7), GRASS_READY_C1)) {
201  SimpleEvent(g_date->Date() + 1, dk_c1_cattle_out, false);
202  break;
203  }
204  SimpleEvent(g_date->Date() + 10, dk_c1_herbicide2, false);
205  break;
206 
207  case dk_c1_herbicide2:
208  if (!m_farm->HerbicideTreat(m_field, 0.0,
209  g_date->DayInYear(6, 8) - g_date->DayInYear())) {
210  SimpleEvent(g_date->Date() + 1, dk_c1_herbicide2, true);
211  break;
212  }
214  break;
215 
216  case dk_c1_swathing:
217  if (m_ev->m_lock || m_farm->DoIt_prob(.10)) { // 10% do swathing
218  if (!m_farm->Swathing(m_field, 0.0, m_field->GetMDates(1,0) - g_date->DayInYear())) {
219  SimpleEvent(g_date->Date() + 1, dk_c1_swathing, true);
220  break;
221  }
222  }
223  SimpleEvent(g_date->Date() + 2, dk_c1_harvest, false);
224  break;
225 
226  case dk_c1_harvest:
227  if (!m_farm->Harvest(m_field, 0.0, m_field->GetMDates(1, 1) - g_date->DayInYear())) {
228  SimpleEvent(g_date->Date() + 1, dk_c1_harvest, true);
229  break;
230  }
232  break;
233 
235  if (!m_farm->StrawRemoval(m_field, 0.0, m_field->GetMDates(1, 2) - g_date->DayInYear())) {
237  break;
238  }
240  break;
241  case dk_c1_force_growth: // Need to add this in the end to make sure grass decays in winter
242  if (g_date->DayInYear() < g_date->DayInYear(1, 11)) {
243  SimpleEvent(g_date->Date() + 1, dk_c1_force_growth, true);
244  break;
245  }
246  else if (g_date->DayInYear() < g_date->DayInYear(31, 12)) {
247  a_field->ForceGrowthTest();
248  SimpleEvent(g_date->Date() + 1, dk_c1_force_growth, true);
249  break;
250  }
251  done = true;
252  break;
253 
254 
255  default:
256  g_msg->Warn(WARN_BUG, "DK_CloverGrassGrazed1::Do(): "
257  "Unknown event type! ", "");
258  exit(1);
259  }
260  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
261  return done;
262 }

References Farm::CattleIsOut(), Farm::CattleOut(), cfg_farm_cattle_grass_high, cfg_farm_cattle_grass_low, LE::ClearManagementActionSum(), Farm::CutToSilage(), Calendar::Date(), Calendar::DayInYear(), dk_c1_cattle_out, DK_C1_CUT, dk_c1_cutting1, dk_c1_cutting2, dk_c1_cutting_graze, dk_c1_force_growth, dk_c1_grass_collected, dk_c1_grazing, dk_c1_harvest, dk_c1_herbicide2, dk_c1_sow_spot, dk_c1_start, dk_c1_swathing, dk_c1_water, Farm::DoIt_prob(), LE::ForceGrowthTest(), g_date, g_msg, LE::GetMDates(), LE::GetVegHeight(), GRASS_READY_C1, Farm::Harvest(), Farm::HerbicideTreat(), 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(), Farm::SpringSow(), Crop::StartUpCrop(), Farm::StrawRemoval(), Farm::Swathing(), tov_DKCloverGrassGrazed1, CfgInt::value(), MapErrorMsg::Warn(), WARN_BUG, and Farm::Water().

◆ SetUpFarmCategoryInformation()

void DK_CloverGrassGrazed1::SetUpFarmCategoryInformation ( )
inline
93  {
94  const int elements = 2 + (dk_c1_foobar - DK_C1_BASE);
96 
97  FarmManagementCategory catlist[elements] =
98  {
99  fmc_Others, // zero element unused but must be here
100  fmc_Others, // dk_c1_start = 1, // Compulsory, start event must always be 1 (one).
101  fmc_Harvest, // dk_c1_harvest = DK_C1_BASE,
102  fmc_Others, // dk_c1_sow_spot,
103  fmc_Herbicide, // dk_c1_herbicide1,
104  fmc_Cutting, // dk_c1_cutting1,
105  fmc_Cutting, // dk_c1_cutting_graze,
106  fmc_Cutting, // dk_c1_cutting2,
107  fmc_Cutting, // dk_c1_cutting3,
108  fmc_Cutting, // dk_c1_cutting4,
109  fmc_Grazing, // dk_c1_grazing,
110  fmc_Grazing, // dk_c1_cattle_out,
111  fmc_Herbicide, // dk_c1_herbicide2,
112  fmc_Watering, // dk_c1_water,
113  fmc_Insecticide, // dk_c1_insecticide,
114  fmc_Cutting, // dk_c1_swathing,
115  fmc_Others, // dk_c1_grass_collected.,
116  fmc_Others, // dk_c1_wait,
117  fmc_Others // dk_c1_force_growth
118 
119  // no foobar entry
120 
121  };
122  // Iterate over the catlist elements and copy them to vector
123  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
124 
125  }

References DK_C1_BASE, dk_c1_foobar, fmc_Cutting, fmc_Grazing, fmc_Harvest, fmc_Herbicide, fmc_Insecticide, fmc_Others, fmc_Watering, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DK_CloverGrassGrazed1().


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
fmc_Insecticide
Definition: LandscapeFarmingEnums.h:1005
Farm::HerbicideTreat
virtual bool HerbicideTreat(LE *a_field, double a_user, int a_days)
Apply herbicide to a_field.
Definition: FarmFuncs.cpp:2025
GRASS_READY_C1
#define GRASS_READY_C1
Definition: DK_CloverGrassGrazed1.h:57
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
dk_c1_cutting1
Definition: DK_CloverGrassGrazed1.h:65
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
dk_c1_start
Definition: DK_CloverGrassGrazed1.h:60
dk_c1_foobar
Definition: DK_CloverGrassGrazed1.h:79
Farm::StrawRemoval
virtual bool StrawRemoval(LE *a_field, double a_user, int a_days)
Straw covering applied on a_field.
Definition: FarmFuncs.cpp:1752
LE::ForceGrowthTest
virtual void ForceGrowthTest(void)
Definition: Elements.h:188
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_c1_sow_spot
Definition: DK_CloverGrassGrazed1.h:63
fmc_Herbicide
Definition: LandscapeFarmingEnums.h:1006
cfg_farm_cattle_grass_high
CfgInt cfg_farm_cattle_grass_high
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_c1_grass_collected
Definition: DK_CloverGrassGrazed1.h:76
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
dk_c1_cutting_graze
Definition: DK_CloverGrassGrazed1.h:66
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
cfg_farm_cattle_grass_low
CfgInt cfg_farm_cattle_grass_low
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
DK_C1_CUT
#define DK_C1_CUT
Definition: DK_CloverGrassGrazed1.h:56
Calendar::Date
long Date(void)
Definition: Calendar.h:57
dk_c1_herbicide2
Definition: DK_CloverGrassGrazed1.h:72
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_c1_force_growth
Definition: DK_CloverGrassGrazed1.h:78
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_CloverGrassGrazed1::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DK_CloverGrassGrazed1.h:93
DK_C1_BASE
#define DK_C1_BASE
Definition: DK_CloverGrassGrazed1.h:54
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_c1_grazing
Definition: DK_CloverGrassGrazed1.h:70
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
dk_c1_water
Definition: DK_CloverGrassGrazed1.h:73
dk_c1_swathing
Definition: DK_CloverGrassGrazed1.h:75
dk_c1_harvest
Definition: DK_CloverGrassGrazed1.h:61
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_c1_cattle_out
Definition: DK_CloverGrassGrazed1.h:71
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
tov_DKCloverGrassGrazed1
Definition: LandscapeFarmingEnums.h:370
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
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_c1_cutting2
Definition: DK_CloverGrassGrazed1.h:67
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