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

#include <DK_OWinterRye.h>

Inheritance diagram for DK_OWinterRye:
Crop

Public Member Functions

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

DK_OWinterRye::DK_OWinterRye ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
62  : Crop(a_tov, a_toc, a_L)
63  {
64  m_first_date = g_date->DayInYear(1, 10);
66  }

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

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

33 {
34  m_farm = a_farm;
35  m_field = a_field;
36  m_ev = a_ev;
37  bool done = false;
38  int d1;
40 
41  switch ( m_ev->m_todo ) {
42  case dk_owr_start:
43  {
44  a_field->ClearManagementActionSum();
45 
46  m_last_date = g_date->DayInYear(11, 8); // Should match the last flexdate below
47  //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
48  std::vector<std::vector<int>> flexdates(1 + 2, std::vector<int>(2, 0));
49  // Set up the date management stuff
50  // Start and stop dates for all events after harvest
51  flexdates[0][1] = g_date->DayInYear(10, 8); // last possible day
52  // Now these are done in pairs, start & end for each operation. If its not used then -1
53  flexdates[1][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 1 (start op 1)
54  flexdates[1][1] = g_date->DayInYear(11, 8); // This date will be moved back as far as necessary and potentially to flexdates 1 (end op 1) // straw chopping
55  flexdates[2][0] = -1; //
56  flexdates[2][1] = g_date->DayInYear(11, 8); // hay bailing
57 
58  // 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
59  int isSpring = 0;
60  if (StartUpCrop(isSpring, flexdates, int(dk_owr_slurry_s1))) break;
61 
62  // End single block date checking code. Please see next line comment as well.
63  // Reinit d1 to first possible starting date.
64  d1 = g_date->OldDays() + g_date->DayInYear(15, 9) + isSpring;
65  // OK, let's go.
67  }
68  break;
69 
71  if (m_ev->m_lock || m_farm->DoIt_prob(1.0)) {
72  if (!m_farm->AutumnPlough(m_field, 0.0,
73  g_date->DayInYear(1, 10) - g_date->DayInYear())) {
75  break;
76  }
77  }
78  SimpleEvent(g_date->Date() + 1, dk_owr_autumn_sow, false);
79  break;
80 
81  case dk_owr_autumn_sow:
82  if (m_ev->m_lock || m_farm->DoIt_prob(1.0)) {
83  if (!m_farm->AutumnSow(m_field, 0.0,
84  g_date->DayInYear(2, 10) - g_date->DayInYear())) {
86  break;
87  }
88  }
89  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 2) + 365, dk_owr_slurry_s1, false);
90  break;
91 
92  case dk_owr_slurry_s1:
93  if (a_farm->IsStockFarmer()) {
94  if (m_ev->m_lock || m_farm->DoIt_prob(1.0)) {
95  if (!m_farm->FA_Slurry(m_field, 0.0,
96  g_date->DayInYear(31, 3) - g_date->DayInYear())) {
97  SimpleEvent(g_date->Date() + 1, dk_owr_slurry_s1, true);
98  break;
99  }
101  break;
102  }
103  }
105  break;
106 
107  case dk_owr_slurry_p1:
108  if (m_ev->m_lock || m_farm->DoIt_prob(1.0)) {
109  if (!m_farm->FP_Slurry(m_field, 0.0,
110  g_date->DayInYear(31, 3) - g_date->DayInYear())) {
111  SimpleEvent(g_date->Date() + 1, dk_owr_slurry_p1, true);
112  break;
113  }
114 
115  }
117  break;
118 
119  case dk_owr_slurry_s2:
120  if (m_ev->m_lock || m_farm->DoIt_prob(1.0)) {
121  if (!m_farm->FA_Slurry(m_field, 0.0,
122  g_date->DayInYear(30, 4) - g_date->DayInYear())) {
123  SimpleEvent(g_date->Date() + 1, dk_owr_slurry_s2, true);
124  break;
125  }
126  }
127  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 5), dk_owr_water, false);
128  break;
129 
130  case dk_owr_slurry_p2:
131  if (m_ev->m_lock || m_farm->DoIt_prob(1.0)) {
132  if (!m_farm->FP_Slurry(m_field, 0.0,
133  g_date->DayInYear(30, 4) - g_date->DayInYear())) {
134  SimpleEvent(g_date->Date() + 1, dk_owr_slurry_p2, true);
135  break;
136  }
137  }
138  SimpleEvent(g_date->OldDays() + g_date->DayInYear(1, 5), dk_owr_water, false);
139  break;
140 
141  case dk_owr_water:
142  if (m_ev->m_lock || m_farm->DoIt_prob(0.5)) {
143  if (!m_farm->Water(m_field, 0.0,
144  g_date->DayInYear(30, 6) - g_date->DayInYear())) {
145  SimpleEvent(g_date->Date() + 1, dk_owr_water, true);
146  break;
147  }
148  }
150  break;
151 
152  case dk_owr_harvest:
153  if (m_ev->m_lock || m_farm->DoIt_prob(1.0)) {
154  if (!m_farm->Harvest(m_field, 0.0, m_field->GetMDates(1, 0) - g_date->DayInYear())) {
155  SimpleEvent(g_date->Date() + 1, dk_owr_harvest, true);
156  break;
157  }
158  }
160  break;
161 
163  if (m_ev->m_lock || m_farm->DoIt_prob(0.75)) { // 75% do straw chopping, 25% do hay bailing
164  if (!m_farm->StrawChopping(m_field, 0.0, m_field->GetMDates(1, 1) - g_date->DayInYear())) {
166  break;
167  }
168  done = true;
169  break;
170  }
172  break;
173 
174  case dk_owr_hay_bailing:
175  if (!m_farm->HayBailing(m_field, 0.0, m_field->GetMDates(1, 2) - g_date->DayInYear())) {
176  SimpleEvent(g_date->Date() + 1, dk_owr_hay_bailing, true);
177  break;
178  }
179 
180  done = true;
181  break;
182 
183  default:
184  g_msg->Warn( WARN_BUG, "DK_OWinterRye::Do(): "
185  "Unknown event type! ", "" );
186  exit( 1 );
187  }
188 
189  return done;
190 }

References Farm::AutumnPlough(), Farm::AutumnSow(), LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), dk_owr_autumn_plough, dk_owr_autumn_sow, dk_owr_harvest, dk_owr_hay_bailing, dk_owr_slurry_p1, dk_owr_slurry_p2, dk_owr_slurry_s1, dk_owr_slurry_s2, dk_owr_start, dk_owr_straw_chopping, dk_owr_water, 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, Crop::m_last_date, FarmEvent::m_lock, FarmEvent::m_todo, Calendar::OldDays(), Crop::SimpleEvent(), Crop::StartUpCrop(), Farm::StrawChopping(), tov_DKOWinterRye, MapErrorMsg::Warn(), WARN_BUG, and Farm::Water().

◆ SetUpFarmCategoryInformation()

void DK_OWinterRye::SetUpFarmCategoryInformation ( )
inline
67  {
68  const int elements = 2 + (dk_owr_foobar - DK_OWR_BASE);
70 
71  FarmManagementCategory catlist[elements] =
72  {
73  fmc_Others, // zero element unused but must be here
74  fmc_Others, // dk_owr_start = 1, // Compulsory, start event must always be 1 (one).
75  fmc_Cultivation, // dk_owr_autumn_plough = DK_OWR_BASE,
76  fmc_Others, // dk_owr_autumn_sow,
77  fmc_Fertilizer, // dk_owr_slurry_s1,
78  fmc_Fertilizer, // dk_owr_slurry_p1,
79  fmc_Fertilizer, // dk_owr_slurry_s2,
80  fmc_Fertilizer, // dk_owr_slurry_p2,
81  fmc_Watering, // dk_owr_water,
82  fmc_Harvest, // dk_owr_harvest,
83  fmc_Cutting, // dk_owr_straw_chopping,
84  fmc_Others, // dk_owr_hay_bailing,
85  // No foobar entry
86  };
87  // Iterate over the catlist elements and copy them to vector
88  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
89  }

References DK_OWR_BASE, dk_owr_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_OWinterRye().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
dk_owr_hay_bailing
Definition: DK_OWinterRye.h:52
dk_owr_foobar
Definition: DK_OWinterRye.h:53
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_owr_start
Definition: DK_OWinterRye.h:42
dk_owr_slurry_s2
Definition: DK_OWinterRye.h:47
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
dk_owr_harvest
Definition: DK_OWinterRye.h:50
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
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
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_owr_water
Definition: DK_OWinterRye.h:49
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
dk_owr_straw_chopping
Definition: DK_OWinterRye.h:51
Calendar::Date
long Date(void)
Definition: Calendar.h:57
dk_owr_slurry_p2
Definition: DK_OWinterRye.h:48
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_owr_slurry_p1
Definition: DK_OWinterRye.h:46
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
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_OWinterRye::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DK_OWinterRye.h:67
Crop::m_farm
Farm * m_farm
Definition: Farm.h:498
Crop::m_field
LE * m_field
Definition: Farm.h:499
dk_owr_autumn_sow
Definition: DK_OWinterRye.h:44
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_owr_autumn_plough
Definition: DK_OWinterRye.h:43
DK_OWR_BASE
#define DK_OWR_BASE
Definition: DK_OWinterRye.h:39
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
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
Farm::AutumnPlough
virtual bool AutumnPlough(LE *a_field, double a_user, int a_days)
Carry out a ploughing event in the autumn on a_field.
Definition: FarmFuncs.cpp:212
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
tov_DKOWinterRye
Definition: LandscapeFarmingEnums.h:403
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
Farm::AutumnSow
virtual bool AutumnSow(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 autumn on a_field.
Definition: FarmFuncs.cpp:360
fmc_Harvest
Definition: LandscapeFarmingEnums.h:1012
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
dk_owr_slurry_s1
Definition: DK_OWinterRye.h:45
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
WARN_BUG
Definition: MapErrorMsg.h:34
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001