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

DE_SpringBarley class
. More...

#include <DE_SpringBarley.h>

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

DE_SpringBarley class
.

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

◆ DE_SpringBarley()

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

When we start it off, the first possible date for a farm operation is 15th September This information is used by other crops when they decide how much post processing of the management is allowed after harvest before the next crop starts.

96  : Crop(a_tov, a_toc, a_L)
97  {
103  m_first_date = g_date->DayInYear(19, 3);
105  }

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

Member Function Documentation

◆ Do()

bool DE_SpringBarley::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 m_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 winter wheat.

Reimplemented from Crop.

90 {
91 /******************** This block can be added to the top of all Crop::Do methods ***********************************************/
92  m_farm = a_farm; // These assignments are necessary, not for this method but for related event calls
93  m_field = a_field;
94  m_ev = a_ev;
95  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
96  bool flag = false;
97  int d1 = 0;
98  int noDates = 1;
99  TTypesOfVegetation l_tov = tov_DESpringBarley; // The current type - change to match the crop you have
100 /**********************************************To Here *************************************************************************/
101  // Depending what event has occured jump to the correct bit of code
102  switch (m_ev->m_todo)
103  {
104  case de_sb_start:
105  {
107 
108  m_last_date = g_date->DayInYear(31, 8); // Should match the last flexdate below
109  //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
110  std::vector<std::vector<int>> flexdates(2 + 1, std::vector<int>(2, 0));
111  // Set up the date management stuff
112  // Start and stop dates for all events after harvest
113  flexdates[0][1] = g_date->DayInYear(30, 8); // last possible day of harvest - this is in effect day before the earliest date that a following crop can use
114 
115  flexdates[1][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 1 (start op 1)
116  flexdates[1][1] = g_date->DayInYear(31, 8); // This date will be moved back as far as necessary and potentially to flexdates 1 (end op 1)
117  flexdates[2][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 1 (start op 1)
118  flexdates[2][1] = g_date->DayInYear(31, 8); // This date will be moved back as far as necessary and potentially to flexdates 1 (end op 1)
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(de_sb_ferti_s1))) 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 - this differs depending on whether we have field on sandy (2) or clay (1) soils
129  if (a_farm->IsStockFarmer()) //Stock Farmer
130  {
131  SimpleEvent(d1, de_sb_ferti_s1, false);
132  break;
133  }
134  else SimpleEvent(d1, de_sb_ferti_p1, false);
135  break;
136  }
137  break;
138 
139  // This is the first real farm operation
140  case de_sb_ferti_p1:
141  if (m_ev->m_lock || m_farm->DoIt_prob(1.0))
142  {
143  if (!m_farm->FP_PK(m_field, 0.0, g_date->DayInYear(19, 4) - g_date->DayInYear())) {
145  break;
146  }
147  }
149  break;
150  case de_sb_ferti_s1:
151  if (m_ev->m_lock || m_farm->DoIt_prob(1.0))
152  {
153  if (!m_farm->FA_PK(m_field, 0.0, g_date->DayInYear(19, 4) - g_date->DayInYear())) {
155  break;
156  }
157  }
159  break;
160  case de_sb_spring_plough:
161  if (m_ev->m_lock || m_farm->DoIt_prob(1.0))
162  {
163  if (!m_farm->SpringPlough(m_field, 0.0, g_date->DayInYear(20, 4) - g_date->DayInYear())) {
165  break;
166  }
167  }
169  break;
170 
174  break;
175  }
176  // here comes a fork of events:
179  SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 5), de_sb_growth_regulator1, false, m_farm, m_field); // main thread
180  if (m_farm->IsStockFarmer()) //Stock Farmer // N thread
181  {
183  }
185  break;
186 
187  case de_sb_herbicide:
188  if (!m_farm->HerbicideTreat(m_field, 0.0, g_date->DayInYear(31, 5) - g_date->DayInYear())) {
190  break;
191  }
192  break;
193 
194  case de_sb_ferti_p2:
195  if (m_ev->m_lock || m_farm->DoIt_prob(1.0))
196  {
197  if (!m_farm->FP_AmmoniumSulphate(m_field, 0.0, g_date->DayInYear(31, 5) - g_date->DayInYear())) {
199  break;
200  }
201  }
202  break;
203 
204  case de_sb_ferti_s2:
205  if (m_ev->m_lock || m_farm->DoIt_prob(1.0))
206  {
207  if (!m_farm->FA_AmmoniumSulphate(m_field, 0.0, g_date->DayInYear(31, 5) - g_date->DayInYear())) {
209  break;
210  }
211  }
212  break;
213 
214  case de_sb_fungicide:
215  // Here comes the fungicide thread
216  if (m_ev->m_lock || m_farm->DoIt_prob(0.95))
217  {
218  if (!m_farm->FungicideTreat(m_field, 0.0, g_date->DayInYear(31, 5) - g_date->DayInYear())) {
220  break;
221  }
222  }
223  break;
224 
226  // Here comes the GR thread - main thread
227  if (m_ev->m_lock || m_farm->DoIt_prob(0.60))
228  {
229  if (!m_farm->GrowthRegulator(m_field, 0.0, g_date->DayInYear(30, 6) - g_date->DayInYear())) {
231  break;
232  }
234  break;
235  }
237  break;
238 
240  if (m_ev->m_lock || m_farm->DoIt_prob(0.20 / 0.40))
241  {
242  if (!m_farm->GrowthRegulator(m_field, 0.0, g_date->DayInYear(30, 6) - g_date->DayInYear())) {
244  break;
245  }
246  }
248  break;
249 
250  case de_sb_insecticide:
251  // Here comes the insecticide thread = MAIN THREAD
252  // here we check whether we are using ERA pesticide or not
253  d1 = g_date->DayInYear(31, 7) - g_date->DayInYear();
254  if (m_ev->m_lock || m_farm->DoIt_prob(0.40))
255  {
256  if (!cfg_pest_springbarley_on.value() || !m_field->GetLandscape()->SupplyShouldSpray()) // Not using pesticide spray
257  {
258  flag = m_farm->InsecticideTreat(m_field, 0.0, d1);
259  }
260  else {
262  }
263  if (!flag) {
265  break;
266  }
267  }
269  break;
270 
271  case de_sb_harvest:
272  // Here the MAIN thread continues
273  // We don't move harvest days
274  if (!m_farm->Harvest(m_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
276  break;
277  }
279  break;
281  if (m_ev->m_lock || m_farm->DoIt_prob(0.50))
282  {
283  if (!m_farm->StrawChopping(m_field, 0.0, m_field->GetMDates(1, 1) - g_date->DayInYear())) {
285  break;
286  }
287  done = true;
288  break;
289  }
291  break;
292  case de_sb_hay_bailing:
293  if (!m_farm->HayBailing(m_field, 0.0, m_field->GetMDates(1, 2) - g_date->DayInYear())) {
295  break;
296  }
297  done = true;
298  break;
299  default:
300  g_msg->Warn(WARN_BUG, "DE_SPRINGBARLEY::Do(): "
301  "Unknown event type! ", "");
302  exit(1);
303  }
304  return done;
305 }

References cfg_pest_product_amounts, cfg_pest_springbarley_on, LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), de_sb_ferti_p1, de_sb_ferti_p2, de_sb_ferti_s1, de_sb_ferti_s2, de_sb_fungicide, de_sb_growth_regulator1, de_sb_growth_regulator2, de_sb_harvest, de_sb_hay_bailing, de_sb_herbicide, de_sb_insecticide, de_sb_preseeding_cultivator_sow, de_sb_spring_plough, de_sb_start, de_sb_straw_chopping, Farm::DoIt_prob(), Farm::FA_AmmoniumSulphate(), Farm::FA_PK(), Farm::FP_AmmoniumSulphate(), Farm::FP_PK(), Farm::FungicideTreat(), g_date, g_msg, LE::GetMDates(), Farm::GrowthRegulator(), Farm::Harvest(), Farm::HayBailing(), Farm::HerbicideTreat(), Farm::InsecticideTreat(), Farm::IsStockFarmer(), Crop::m_date_modifier, Crop::m_ev, Crop::m_farm, Crop::m_field, Crop::m_last_date, FarmEvent::m_lock, FarmEvent::m_todo, Calendar::OldDays(), ppp_1, Farm::PreseedingCultivatorSow(), Farm::ProductApplication(), Crop::SimpleEvent(), Crop::SimpleEvent_(), Farm::SpringPlough(), Crop::StartUpCrop(), Farm::StrawChopping(), tov_DESpringBarley, CfgBool::value(), CfgArray_Double::value(), MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void DE_SpringBarley::SetUpFarmCategoryInformation ( )
inline
106  {
107  const int elements = 2 + (de_sb_foobar - DE_SPRINGBARLEY_BASE);
109 
110  FarmManagementCategory catlist[elements] =
111  {
112  fmc_Others, // zero element unused but must be here
113  // ALL THE NECESSARY ENTRIES HERE
114  fmc_Others, // de_sb_start = 1, // Compulsory, must always be 1 (one).
115  fmc_Others, // de_sb_sleep_all_day
116  fmc_Fertilizer, // de_sb_ferti_p1,
117  fmc_Fertilizer, // de_sb_ferti_s1,
118  fmc_Cultivation, // de_sb_spring_plough,
119  fmc_Fertilizer, // de_sb_ferti_p2,
120  fmc_Fertilizer, // de_sb_ferti_s2,
121  fmc_Cultivation, // de_sb_preseeding_cultivator_sow,
122  fmc_Herbicide, // de_sb_herbicide,
123  fmc_Fungicide, // de_sb_fungicide,
124  fmc_Insecticide, // de_sb_insecticide,
125  fmc_Others, // de_sb_growth_regulator1,
126  fmc_Others, // de_sb_growth_regulator2,
127  fmc_Harvest, // de_sb_harvest,
128  fmc_Others, // de_sb_straw_chopping,
129  fmc_Others, // de_sb_hay_bailing,
130 
131  // no foobar entry
132 
133  };
134  // Iterate over the catlist elements and copy them to vector
135  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
136 
137  }

References de_sb_foobar, DE_SPRINGBARLEY_BASE, fmc_Cultivation, fmc_Fertilizer, fmc_Fungicide, fmc_Harvest, fmc_Herbicide, fmc_Insecticide, fmc_Others, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DE_SpringBarley().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
fmc_Insecticide
Definition: LandscapeFarmingEnums.h:1005
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
de_sb_ferti_p1
Definition: DE_SpringBarley.h:66
Farm::HerbicideTreat
virtual bool HerbicideTreat(LE *a_field, double a_user, int a_days)
Apply herbicide to a_field.
Definition: FarmFuncs.cpp:2025
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
Farm::ProductApplication
virtual bool ProductApplication(LE *a_field, double a_user, int a_days, double a_applicationrate, PlantProtectionProducts a_ppp, bool a_isgranularpesticide=false, int a_orcharddrifttype=0)
Apply test pesticide to a_field.
Definition: FarmFuncs.cpp:2267
de_sb_insecticide
Definition: DE_SpringBarley.h:74
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
de_sb_growth_regulator2
Definition: DE_SpringBarley.h:76
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
fmc_Herbicide
Definition: LandscapeFarmingEnums.h:1006
de_sb_hay_bailing
Definition: DE_SpringBarley.h:79
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
de_sb_straw_chopping
Definition: DE_SpringBarley.h:78
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
Farm::FungicideTreat
virtual bool FungicideTreat(LE *a_field, double a_user, int a_days)
Apply fungicide to a_field.
Definition: FarmFuncs.cpp:2101
Farm::FP_PK
virtual bool FP_PK(LE *a_field, double a_user, int a_days)
Apply PK fertilizer, on a_field owned by an arable farmer.
Definition: FarmFuncs.cpp:673
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
CfgBool::value
bool value() const
Definition: Configurator.h:164
de_sb_herbicide
Definition: DE_SpringBarley.h:72
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
de_sb_growth_regulator1
Definition: DE_SpringBarley.h:75
Calendar::Date
long Date(void)
Definition: Calendar.h:57
cfg_pest_product_amounts
CfgArray_Double cfg_pest_product_amounts
Amount of pesticide applied in grams of active substance per hectare for each of the 10 pesticides.
Farm::FP_AmmoniumSulphate
virtual bool FP_AmmoniumSulphate(LE *a_field, double a_user, int a_days)
Apply Ammonium Sulphate to a_field owned by an arable farmer.
Definition: FarmFuncs.cpp:882
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
de_sb_ferti_p2
Definition: DE_SpringBarley.h:69
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
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
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
DE_SPRINGBARLEY_BASE
#define DE_SPRINGBARLEY_BASE
Definition: DE_SpringBarley.h:51
de_sb_harvest
Definition: DE_SpringBarley.h:77
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
DE_SpringBarley::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DE_SpringBarley.h:106
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
Crop::m_farm
Farm * m_farm
Definition: Farm.h:498
Crop::m_field
LE * m_field
Definition: Farm.h:499
de_sb_foobar
Definition: DE_SpringBarley.h:80
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
CfgArray_Double::value
std::vector< double > value() const
Definition: Configurator.h:219
de_sb_preseeding_cultivator_sow
Definition: DE_SpringBarley.h:71
Farm::PreseedingCultivatorSow
virtual bool PreseedingCultivatorSow(LE *a_field, double a_user, int a_days, double a_seed_coating_amount=-1, PlantProtectionProducts a_ppp=ppp_foobar)
Carry out preseeding cultivation together with sow on a_field (tilling and sowing set including culti...
Definition: FarmFuncs.cpp:325
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
Farm::InsecticideTreat
virtual bool InsecticideTreat(LE *a_field, double a_user, int a_days)
Apply insecticide to a_field.
Definition: FarmFuncs.cpp:2135
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
Farm::FA_AmmoniumSulphate
virtual bool FA_AmmoniumSulphate(LE *a_field, double a_user, int a_days)
Apply ammonium sulphate to a_field owned by an stock farmer.
Definition: FarmFuncs.cpp:1081
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
Crop::m_date_modifier
static int m_date_modifier
Holds a value that shifts test pesticide use by this many days in crops modified to use it.
Definition: Farm.h:514
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
cfg_pest_springbarley_on
CfgBool cfg_pest_springbarley_on
Turn on pesticides for spring barley.
Farm::GrowthRegulator
virtual bool GrowthRegulator(LE *a_field, double a_user, int a_days)
Apply growth regulator to a_field.
Definition: FarmFuncs.cpp:2070
de_sb_spring_plough
Definition: DE_SpringBarley.h:68
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
de_sb_start
Definition: DE_SpringBarley.h:64
de_sb_ferti_s2
Definition: DE_SpringBarley.h:70
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
Farm::FA_PK
virtual bool FA_PK(LE *a_field, double a_user, int a_days)
Apply PK fertilizer to a_field owned by an stock farmer.
Definition: FarmFuncs.cpp:1010
de_sb_ferti_s1
Definition: DE_SpringBarley.h:67
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
WARN_BUG
Definition: MapErrorMsg.h:34
ppp_1
Definition: LandscapeFarmingEnums.h:1079
fmc_Fungicide
Definition: LandscapeFarmingEnums.h:1007
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
tov_DESpringBarley
Definition: LandscapeFarmingEnums.h:517
de_sb_fungicide
Definition: DE_SpringBarley.h:73
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