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

#include <DK_OSpringBarley.h>

Inheritance diagram for DK_OSpringBarley:
Crop

Public Member Functions

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

DK_OSpringBarley::DK_OSpringBarley ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
65  : Crop(a_tov, a_toc, a_L)
66  {
69  }

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

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

36 {
37 
38  m_farm = a_farm;
39  m_field = a_field;
40  m_ev = a_ev;
41  int d1 = 0;
42 
43  bool done = false;
44  int l_nextcropstartdate;
46  switch ( m_ev->m_todo )
47  {
48  case dk_osbm_start:
49  {
50 
51  a_field->ClearManagementActionSum();
52  DK_OSB_FORCESPRING = false;
53  m_last_date = g_date->DayInYear(21, 8); // Should match the last flexdate below
54  //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
55  std::vector<std::vector<int>> flexdates(3 + 1, std::vector<int>(2, 0));
56  // Set up the date management stuff
57  // Start and stop dates for all events after harvest
58  flexdates[0][1] = g_date->DayInYear(12, 8); // last possible day of in this case swathing - this is in effect day before the earliest date that a following crop can use
59  // Now these are done in pairs, start & end for each operation. If its not used then -1
60  flexdates[1][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 1 (start op 1)
61  flexdates[1][1] = g_date->DayInYear(15, 8); // This date will be moved back as far as necessary and potentially to flexdates 1 (end op 1) // harvest
62  flexdates[2][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 2 (start op 2)
63  flexdates[2][1] = g_date->DayInYear(16, 8); // This date will be moved back as far as necessary and potentially to flexdates 2 (end op 2) // straw chopping
64  flexdates[3][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 3 (start op 3)
65  flexdates[3][1] = g_date->DayInYear(16, 8); // This date will be moved back as far as necessary and potentially to flexdates 3 (end op 3) // hay baling
66 
67  // 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
68  int isSpring = 365;
69  if (StartUpCrop(isSpring, flexdates, int(dk_osbm_spring_harrow1))) break;
70 
71  // End single block date checking code. Please see next line comment as well.
72  // Reinit d1 to first possible starting date.
73  d1 = g_date->OldDays() + g_date->DayInYear(1, 3) + isSpring;
74  if (m_ev->m_forcespring) {
75  int day_num_shift = 365;
76  if (g_date->DayInYear() < 70) day_num_shift = 0;
77  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 3) + day_num_shift, dk_osbm_spring_harrow1, false);
78  DK_OSB_FORCESPRING = true;
79  break;
80  }
81  else
82  // OK, let's go.
84  break;
85  }
86  break;
87 
89  if (m_ev->m_lock || m_farm->DoIt(100)) {
90  if (!m_farm->SpringHarrow(m_field, 0.0,
91  g_date->DayInYear(29, 3) - g_date->DayInYear())) {
93  break;
94  }
95  }
97  break;
98 
100  if (m_ev->m_lock || m_farm->DoIt(50)) { //suggestion as done 1-2 times
101  if (!m_farm->SpringHarrow(m_field, 0.0,
102  g_date->DayInYear(30, 3) - g_date->DayInYear())) {
104  break;
105  }
106  }
108  break;
109  case dk_osbm_slurry_s:
110  if (a_farm->IsStockFarmer()) {
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_osbm_slurry_s, true);
114  break;
115  }
117  break;
118  }
119  else SimpleEvent(g_date->Date(), dk_osbm_slurry_p, false);
120  break;
121 
122  case dk_osbm_slurry_p:
123  if (!m_farm->FP_Slurry(m_field, 0.0,
124  g_date->DayInYear(30, 3) - g_date->DayInYear())) {
125  SimpleEvent(g_date->Date() + 1, dk_osbm_slurry_p, true);
126  break;
127  }
129  break;
130 
132  if (!m_farm->SpringPlough(m_field, 0.0,
133  g_date->DayInYear(29, 4) - g_date->DayInYear())) {
135  break;
136  }
137  SimpleEvent(g_date->Date() + 1, dk_osbm_spring_sow, false);
138  break;
139  case dk_osbm_spring_sow:
140  if (!m_farm->SpringSow( m_field, 0.0,
141  g_date->DayInYear( 30,4 ) - g_date->DayInYear())) {
142  SimpleEvent( g_date->Date() + 1, dk_osbm_spring_sow, true );
143  break;
144  }
146  break;
148  if (m_ev->m_lock || m_farm->DoIt(80)) {
149  if (!m_farm->ShallowHarrow(m_field, 0.0,
150  g_date->DayInYear(10, 5) - g_date->DayInYear())) {
152  break;
153  }
155  break;
156  }
158  break;
160  if (!m_farm->ShallowHarrow(m_field, 0.0,
161  g_date->DayInYear(20, 5) - g_date->DayInYear())) {
163  break;
164  }
166  break;
168  if (!m_farm->RowCultivation(m_field, 0.0,
169  g_date->DayInYear(10, 5) - g_date->DayInYear())) {
171  break;
172  }
174  break;
176  if (!m_farm->RowCultivation(m_field, 0.0,
177  g_date->DayInYear(20, 5) - g_date->DayInYear())) {
179  break;
180  }
182  break;
183  case dk_osbm_water:
184  if (m_ev->m_lock || m_farm->DoIt_prob(0.50)) {
185  if (!m_farm->Water(m_field, 0.0,
186  g_date->DayInYear(30, 7) - g_date->DayInYear())) {
187  SimpleEvent(g_date->Date() + 1, dk_osbm_water, true);
188  break;
189  }
190  }
192  break;
193  case dk_osbm_swathing:
194  if (m_ev->m_lock || m_farm->DoIt_prob(0.10)) {
195  if (!m_farm->Swathing(m_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
196  SimpleEvent(g_date->Date() + 1, dk_osbm_swathing, true);
197  break;
198  }
199  }
200  SimpleEvent(g_date->Date()+2, dk_osbm_harvest, false);
201  break;
202  case dk_osbm_harvest:
203  // We don't move harvest days
204  if (!a_farm->Harvest(a_field, 0.0, m_field->GetMDates(1, 1) - g_date->DayInYear())) {
205  SimpleEvent(g_date->Date() + 1, dk_osbm_harvest, true);
206  break;
207  }
209  break;
211  if (m_ev->m_lock || m_farm->DoIt(10)) //10% (suggestion) do straw chopping and leave on field
212  {
213  // Force straw chopping to happen on the same day as harvest.
214  if (!m_farm->StrawChopping(m_field, 0.0, m_field->GetMDates(1, 2) - g_date->DayInYear())) {
216  break;
217  }
218  done = true;
219  break;
220  }
221  // Do hay baling first.
223  break;
224 
225  case dk_osbm_hay_baling:
226  if (!m_farm->HayBailing(m_field, 0.0, m_field->GetMDates(1, 3) - g_date->DayInYear())) {
227  SimpleEvent(g_date->Date() + 1, dk_osbm_hay_baling, true);
228  break;
229  }
230  done = true;
231  break;
232 
233  default:
234  g_msg->Warn( WARN_BUG, "DK_OSpringBarley::Do(): "
235  "Unknown event type! ", "" );
236  exit( 1 );
237  }
238  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
239  return done;
240 }

References LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), DK_OSB_FORCESPRING, dk_osbm_harvest, dk_osbm_hay_baling, dk_osbm_row_cultivation1, dk_osbm_row_cultivation2, dk_osbm_shallow_harrow1, dk_osbm_shallow_harrow2, dk_osbm_slurry_p, dk_osbm_slurry_s, dk_osbm_spring_harrow1, dk_osbm_spring_harrow2, dk_osbm_spring_plough, dk_osbm_spring_sow, dk_osbm_start, dk_osbm_straw_chopping, dk_osbm_swathing, dk_osbm_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::RowCultivation(), Farm::ShallowHarrow(), Crop::SimpleEvent(), Farm::SpringHarrow(), Farm::SpringPlough(), Farm::SpringSow(), Crop::StartUpCrop(), Farm::StrawChopping(), Farm::Swathing(), tov_DKOSpringBarley, MapErrorMsg::Warn(), WARN_BUG, and Farm::Water().

◆ SetUpFarmCategoryInformation()

void DK_OSpringBarley::SetUpFarmCategoryInformation ( )
inline
70  {
71  const int elements = 2 + (dk_osbm_foobar - DK_OSBM_BASE);
73 
74  FarmManagementCategory catlist[elements] =
75  {
76  fmc_Others, // zero element unused but must be here
77  fmc_Others, // dk_osbm_start = 1, // Compulsory, start event must always be 1 (one).
78  fmc_Cultivation, // dk_osbm_spring_harrow1 = DK_OSBM_BASE,
79  fmc_Cultivation, // dk_osbm_spring_harrow2,
80  fmc_Fertilizer, // dk_osbm_slurry,
81  fmc_Fertilizer, // dk_osbm_slurry,
82  fmc_Cultivation, // dk_osbm_spring_plough,
83  fmc_Others, // dk_osbm_spring_sow,
84  fmc_Cultivation, // dk_osbm_shallow_harrow1,
85  fmc_Cultivation, // dk_osbm_shallow_harrow2,
86  fmc_Cultivation, // dk_osbm_row_cultivation1,
87  fmc_Cultivation, // dk_osbm_row_cultivation2,
88  fmc_Watering, // dk_osbm_water,
89  fmc_Cutting, // dk_osbm_swathing,
90  fmc_Harvest, // dk_osbm_harvest,
91  fmc_Others, // dk_osbm_straw_chopping,
92  fmc_Others, // dk_osbm_hay_baling,
93  fmc_Cutting, // dk_osbm_cut_to_hay,
94  fmc_Cultivation, // dk_osbm_stubble_harrow,
95  fmc_Cultivation, // dk_osbm_plough,
96  fmc_Others, // dk_osbm_wait,
97 
98 
99  // no foobar entry
100 
101  };
102  // Iterate over the catlist elements and copy them to vector
103  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
104 
105  }

References DK_OSBM_BASE, dk_osbm_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_OSpringBarley().


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_osbm_water
Definition: DK_OSpringBarley.h:47
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
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
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
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_osbm_slurry_s
Definition: DK_OSpringBarley.h:39
dk_osbm_shallow_harrow1
Definition: DK_OSpringBarley.h:43
tov_DKOSpringBarley
Definition: LandscapeFarmingEnums.h:363
dk_osbm_swathing
Definition: DK_OSpringBarley.h:48
DK_OSBM_BASE
#define DK_OSBM_BASE
Definition: DK_OSpringBarley.h:33
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_OSpringBarley::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DK_OSpringBarley.h:70
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
dk_osbm_hay_baling
Definition: DK_OSpringBarley.h:51
dk_osbm_harvest
Definition: DK_OSpringBarley.h:49
dk_osbm_slurry_p
Definition: DK_OSpringBarley.h:40
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
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
dk_osbm_row_cultivation1
Definition: DK_OSpringBarley.h:45
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
dk_osbm_spring_sow
Definition: DK_OSpringBarley.h:42
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
DK_OSB_FORCESPRING
#define DK_OSB_FORCESPRING
Definition: DK_OSpringBarley.h:31
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
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
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::RowCultivation
virtual bool RowCultivation(LE *a_field, double a_user, int a_days)
Carry out a harrowing between crop rows on a_field.
Definition: FarmFuncs.cpp:1183
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
dk_osbm_spring_harrow2
Definition: DK_OSpringBarley.h:38
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
dk_osbm_spring_harrow1
Definition: DK_OSpringBarley.h:37
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
dk_osbm_straw_chopping
Definition: DK_OSpringBarley.h:50
dk_osbm_row_cultivation2
Definition: DK_OSpringBarley.h:46
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
dk_osbm_foobar
Definition: DK_OSpringBarley.h:56
dk_osbm_start
Definition: DK_OSpringBarley.h:36
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
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_osbm_shallow_harrow2
Definition: DK_OSpringBarley.h:44
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
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
dk_osbm_spring_plough
Definition: DK_OSpringBarley.h:41