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

DE_OPermanentGrassGrazed class
. More...

#include <DE_OPermanentGrassGrazed.h>

Inheritance diagram for DE_OPermanentGrassGrazed:
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_OPermanentGrassGrazed (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_OPermanentGrassGrazed class
.

See DE_OPermanentGrassGrazed.h::DE_OPermanentGrassGrazedToDo for a complete list of all possible events triggered codes by the PermanentGrassGrazed 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_OPermanentGrassGrazed()

DE_OPermanentGrassGrazed::DE_OPermanentGrassGrazed ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
87  : Crop(a_tov, a_toc, a_L)
88  {
89  // When we start it off, the first possible date for a farm operation is 1st October
90  // This information is used by other crops when they decide how much post processing of
91  // the management is allowed after harvest before the next crop starts.
92  m_first_date = g_date->DayInYear(25, 3);
94  }

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

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

86 {
87  /******************** This block can be added to the top of all Crop::Do methods ***********************************************/
88  m_farm = a_farm; // These assignments are necessary, not for this method but for related event calls
89  m_field = a_field;
90  m_ev = a_ev;
91  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
92  int d1 = 0;
94  /**********************************************To Here *************************************************************************/
95 
96  // Depending what event has occured jump to the correct bit of code
97  switch (m_ev->m_todo)
98  {
99  case de_opgg_start:
100  {
102 
103  m_last_date = g_date->DayInYear(31, 10); // Should match the last flexdate below
104  //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
105  std::vector<std::vector<int>> flexdates(1 + 1, std::vector<int>(2, 0));
106  // Set up the date management stuff
107  // Start and stop dates for all events after harvest
108  flexdates[0][1] = g_date->DayInYear(30, 9); //
109 
110  flexdates[1][0] = -1;
111  flexdates[1][1] = g_date->DayInYear(31, 10); // last possible day of grazing
112 
113  // 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
114  int isSpring = 365;
115  if (StartUpCrop(isSpring, flexdates, int(de_opgg_grazing1))) break;
116 
117  // End single block date checking code. Please see next line comment as well.
118  // Reinit d1 to first possible starting date.
119  d1 = g_date->OldDays() + g_date->DayInYear(15, 3) + isSpring;
120  // OK, let's go.
121  SimpleEvent(g_date->Date() + 1, de_opgg_grazing1, false);
122  break;
123  }
124  break;
125 
126  case de_opgg_grazing1:
127  if (m_ev->m_lock || m_farm->DoIt_prob(1.0)) {
128  if (!m_farm->CattleOutLowGrazing(m_field, 0.0, g_date->DayInYear(25, 3) - g_date->DayInYear())) {
129  SimpleEvent(g_date->Date() + 1, de_opgg_grazing1, true);
130  break;
131  }
132  }
134  //SimpleEvent_(g_date->OldDays() + g_date->DayInYear(1, 7), de_opgg_cutting1, false, m_farm, m_field);
135  break;
137  if (m_ev->m_lock || m_farm->DoIt_prob(1.0)) {
138  if (!m_farm->CattleIsOutLow(m_field, 0.0, g_date->DayInYear(15, 6) - g_date->DayInYear(), g_date->DayInYear(15, 6))) {
140  break;
141  }
142  }
144  break;
145  case de_opgg_cutting1: //
146  if (m_ev->m_lock || m_farm->DoIt_prob(1.0)) {
147  if (!m_farm->CutToSilage(m_field, 0.0, g_date->DayInYear(31, 8) - g_date->DayInYear())) {
148  SimpleEvent(g_date->Date() + 1, de_opgg_cutting1, true);
149  break;
150  }
151  }
153  break;
154  case de_opgg_grazing2:
155  if (m_ev->m_lock || m_farm->DoIt_prob(1.0)) {
156  if (!m_farm->CattleOutLowGrazing(m_field, 0.0, g_date->DayInYear(10, 9) - g_date->DayInYear())) {
157  SimpleEvent(g_date->Date() + 1, de_opgg_grazing2, true);
158  break;
159  }
160  }
162  break;
164  if (m_ev->m_lock || m_farm->DoIt_prob(1.0)) {
165  if (!m_farm->CattleIsOutLow(m_field, 0.0, m_field->GetMDates(1, 1) - g_date->DayInYear(), m_field->GetMDates(1, 0))) {
167  break;
168  }
169  }
170  done = true;
171  break;
172  // So we are done, and somewhere else the farmer will queue up the start event of the next crop
173  // END OF MAIN THREAD
174  default:
175  g_msg->Warn(WARN_BUG, "DE_OPermanentGrassGrazed::Do(): "
176  "Unknown event type! ", "");
177  exit(1);
178  }
179  return done;
180 }

References Farm::CattleIsOutLow(), Farm::CattleOutLowGrazing(), LE::ClearManagementActionSum(), Farm::CutToSilage(), Calendar::Date(), Calendar::DayInYear(), de_opgg_cattle_is_out1, de_opgg_cattle_is_out2, de_opgg_cutting1, de_opgg_grazing1, de_opgg_grazing2, de_opgg_start, Farm::DoIt_prob(), g_date, g_msg, LE::GetMDates(), 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(), tov_DEOPermanentGrassGrazed, MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void DE_OPermanentGrassGrazed::SetUpFarmCategoryInformation ( )
inline
95  {
96  const int elements = 2 + (de_opgg_foobar - DE_OPGG_BASE);
98 
99  FarmManagementCategory catlist[elements] =
100  {
101  fmc_Others, // zero element unused but must be here
102  fmc_Others, // de_opgg_start = 1, // Compulsory, must always be 1 (one).
103  fmc_Others, // de_opgg_sleep_all_day = DE_OPGG_BASE,
104  fmc_Grazing, // de_opgg_grazing1,
105  fmc_Grazing, // de_opgg_cattle_is_out1,
106  fmc_Cutting, // de_opgg_cutting1,
107  fmc_Grazing, // de_opgg_grazing2,
108  fmc_Grazing, // de_opgg_cattle_is_out2,
109 
110 
111  // no foobar entry
112 
113  };
114  // Iterate over the catlist elements and copy them to vector
115  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
116 
117  }

References DE_OPGG_BASE, de_opgg_foobar, fmc_Cutting, fmc_Grazing, fmc_Others, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by DE_OPermanentGrassGrazed().


The documentation for this class was generated from the following files:
DE_OPGG_BASE
#define DE_OPGG_BASE
Definition: DE_OPermanentGrassGrazed.h:53
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
FarmEvent::m_lock
bool m_lock
Definition: Farm.h:384
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
de_opgg_grazing2
Definition: DE_OPermanentGrassGrazed.h:69
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
de_opgg_foobar
Definition: DE_OPermanentGrassGrazed.h:71
Farm::CattleIsOutLow
virtual bool CattleIsOutLow(LE *a_field, double a_user, int a_days, int a_max)
Generate a 'cattle_out_low' event for every day the cattle are on a_field.
Definition: FarmFuncs.cpp:2561
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
Farm::CattleOutLowGrazing
virtual bool CattleOutLowGrazing(LE *a_field, double a_user, int a_days)
Start a extensive grazing event on a_field today.
Definition: FarmFuncs.cpp:2439
DE_OPermanentGrassGrazed::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: DE_OPermanentGrassGrazed.h:95
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
de_opgg_start
Definition: DE_OPermanentGrassGrazed.h:64
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
de_opgg_grazing1
Definition: DE_OPermanentGrassGrazed.h:66
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
de_opgg_cattle_is_out2
Definition: DE_OPermanentGrassGrazed.h:70
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
de_opgg_cattle_is_out1
Definition: DE_OPermanentGrassGrazed.h:67
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
tov_DEOPermanentGrassGrazed
Definition: LandscapeFarmingEnums.h:489
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
de_opgg_cutting1
Definition: DE_OPermanentGrassGrazed.h:68
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