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

PTShrubPastures class
. More...

#include <PTShrubPastures.h>

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

PTShrubPastures class
.

See PTShrubPastures.h::PTShrubPasturesToDo for a complete list of all possible events triggered codes by the ShrubPastures 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

◆ PTShrubPastures()

PTShrubPastures::PTShrubPastures ( 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 31th November
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( 10,1 );//Last possible date to do the first operation, i.e. plough or sow
94  }

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

Member Function Documentation

◆ Do()

bool PTShrubPastures::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 PermanentGrassGrazed.

Reimplemented from Crop.

56 {
57  /******************** This block can be added to the top of all Crop::Do methods ***********************************************/
58  m_farm = a_farm; // These assignments are necessary, not for this method but for related event calls
59  m_field = a_field;
60  m_ev = a_ev;
61  bool done = false; // The boolean value done indicates when we are totally finished with this plan (i.e. it is set to true).
62  int d1 = 0;
63  TTypesOfVegetation l_tov = tov_PTShrubPastures; // The current type - change to match the crop you have
64 /**********************************************To Here *************************************************************************/
65 
66  // Depending what event has occured jump to the correct bit of code
67  switch (m_ev->m_todo)
68  {
69  case pt_sp_start:
70  {
74  PT_SP_YEARS_AFTER_PLOUGH = 0; // Here, similar to PTPermanentGrassGrazed, the initial conditions for field (no of years after ploughing) should be defined outside the crop management plan,
75  // at the beginning of simulation. For now all fields are starting with 0
76 
78 
79  m_last_date = g_date->DayInYear(28, 12); // Should match the last flexdate below
80  //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
81  std::vector<std::vector<int>> flexdates(1 + 1, std::vector<int>(2, 0));
82  // Set up the date management stuff
83  // Start and stop dates for all events after harvest
84  flexdates[0][1] = g_date->DayInYear(28, 12); // last possible day of harvest - this is in effect day before the earliest date that a following crop can use
85 
86  flexdates[1][0] = -1; // This date will be moved back as far as necessary and potentially to flexdates 1 (start op 1)
87  flexdates[1][1] = g_date->DayInYear(28, 12); // This date will be moved back as far as necessary and potentially to flexdates 1 (end op 1)
88 
89  // 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
90  int isSpring = 365;
91  if (StartUpCrop(isSpring, flexdates, int(pt_sp_cattle_out2))) break;
92 
93  // End single block date checking code. Please see next line comment as well.
94  // Reinit d1 to first possible starting date.
95  d1 = g_date->OldDays() + g_date->DayInYear(1, 1) + isSpring;
96  // OK, let's go.
97  // Here we queue up the first event which changes dependent on whether it is a forced spring sow or not
98  if ((PT_SP_YEARS_AFTER_PLOUGH + g_date->GetYearNumber()) % 3 == 0)
99  {
101  }
103  break;
104 
105  }
106  break;
107 
108  // This is the first real farm operation
109  case pt_sp_cattle_out1:
110  if (!m_farm->CattleOutLowGrazing(m_field, 0.0, g_date->DayInYear(10, 1) - g_date->DayInYear())) {
112  break;
113  }
114  // Keep them out there
117  break;
118  case pt_sp_cattle_is_out1: // Keep the cattle out there
119  // CattleIsOutLow() returns false if it is not time to stop grazing
122  break;
123  }
124  done = true;
125  break;
126  case pt_sp_cattle_out2:
127  if (!m_farm->CattleOutLowGrazing(m_field, 0.0, g_date->DayInYear(10, 1) - g_date->DayInYear())) {
129  break;
130  }
131  // Keep them out there
134  break;
135  case pt_sp_cattle_is_out2: // Keep the cattle out there
136  // CattleIsOutLow() returns false if it is not time to stop grazing
139  break;
140  }
142  break;
143  case pt_sp_spring_plough:
144  if (!m_farm->SpringPlough(m_field, 0.0, g_date->DayInYear(15, 3) - g_date->DayInYear())) {
146  break;
147  }
148  SimpleEvent_(g_date->Date() + 1, pt_sp_cattle_out3, false, m_farm, m_field); //need to check if cattle can go out next day after ploughing or the soil needs to rest a little bit
149  break;
150  case pt_sp_cattle_out3:
151  if (!m_farm->CattleOutLowGrazing(m_field, 0.0, g_date->Date() + 3 - g_date->DayInYear())) {
153  break;
154  }
156  // Keep them out there
158  break;
159  case pt_sp_cattle_is_out3: // Keep the cattle out there
160  // CattleIsOutLow() returns false if it is not time to stop grazing
163  break;
164  }
165  done = true;
166  break;
167  default:
168  g_msg->Warn(WARN_BUG, "PTShrubPastures::Do(): "
169  "Unknown event type! ", "");
170  exit(1);
171  }
172  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
173  return done;
174 }

References Farm::CattleIsOutLow2(), Farm::CattleOutLowGrazing(), LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), g_date, g_msg, LE::GetMDates(), Calendar::GetYearNumber(), Crop::m_ev, Crop::m_farm, Crop::m_field, FarmEvent::m_forcespring, Crop::m_last_date, FarmEvent::m_todo, Calendar::OldDays(), PT_SP1_CATTLEOUT_DATE, PT_SP2_CATTLEOUT_DATE, PT_SP3_CATTLEOUT_DATE, pt_sp_cattle_is_out1, pt_sp_cattle_is_out2, pt_sp_cattle_is_out3, pt_sp_cattle_out1, pt_sp_cattle_out2, pt_sp_cattle_out3, pt_sp_spring_plough, pt_sp_start, PT_SP_YEARS_AFTER_PLOUGH, Crop::SimpleEvent_(), Farm::SpringPlough(), Crop::StartUpCrop(), tov_PTShrubPastures, MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void PTShrubPastures::SetUpFarmCategoryInformation ( )
inline
95  {
96  const int elements = 2 + (pt_sp_foobar - PTSHRUBPASTURES_BASE);
98 
99  FarmManagementCategory catlist[elements] =
100  {
101  fmc_Others, // zero element unused but must be here
102  fmc_Others, //pt_sp_start = 1, // Compulsory, must always be 1 (one).
103  fmc_Others, //pt_sp_sleep_all_day = PTSHRUBPASTURES_BASE,
104  fmc_Grazing, //pt_sp_cattle_out1,
105  fmc_Grazing, //pt_sp_cattle_is_out1,
106  fmc_Grazing, //pt_sp_spring_plough,
107  fmc_Grazing, //pt_sp_cattle_out2,
108  fmc_Grazing, //pt_sp_cattle_is_out2,
109  fmc_Grazing, //pt_sp_cattle_out3,
110  fmc_Grazing, //pt_sp_cattle_is_out3,
111  fmc_Others, //pt_sp_wait,
112 
113  // no foobar entry
114 
115  };
116  // Iterate over the catlist elements and copy them to vector
117  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
118 
119  }

References fmc_Grazing, fmc_Others, Crop::m_base_elements_no, Crop::m_ManagementCategories, pt_sp_foobar, and PTSHRUBPASTURES_BASE.

Referenced by PTShrubPastures().


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
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
pt_sp_cattle_is_out2
Definition: PTShrubPastures.h:66
LE::ClearManagementActionSum
void ClearManagementActionSum()
clears the management action counters
Definition: Elements.h:247
Calendar::GetYearNumber
int GetYearNumber(void)
Definition: Calendar.h:72
PT_SP3_CATTLEOUT_DATE
#define PT_SP3_CATTLEOUT_DATE
Definition: PTShrubPastures.h:51
PT_SP1_CATTLEOUT_DATE
#define PT_SP1_CATTLEOUT_DATE
A flag used to indicate cattle out dates.
Definition: PTShrubPastures.h:49
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
Farm::CattleIsOutLow2
virtual bool CattleIsOutLow2(LE *a_field, double a_user, int a_days, int a_max, int a_max_days)
Generate a 'cattle_out_low2' event for every day the cattle are on a_field, cattle is low grazing and...
Definition: FarmFuncs.cpp:2607
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
tov_PTShrubPastures
Definition: LandscapeFarmingEnums.h:318
pt_sp_start
Definition: PTShrubPastures.h:60
pt_sp_cattle_out3
Definition: PTShrubPastures.h:67
Calendar::Date
long Date(void)
Definition: Calendar.h:57
pt_sp_cattle_out1
Definition: PTShrubPastures.h:62
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
pt_sp_cattle_is_out1
Definition: PTShrubPastures.h:63
pt_sp_spring_plough
Definition: PTShrubPastures.h:64
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
Crop::m_farm
Farm * m_farm
Definition: Farm.h:498
Crop::m_field
LE * m_field
Definition: Farm.h:499
PT_SP2_CATTLEOUT_DATE
#define PT_SP2_CATTLEOUT_DATE
Definition: PTShrubPastures.h:50
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
pt_sp_cattle_out2
Definition: PTShrubPastures.h:65
PT_SP_YEARS_AFTER_PLOUGH
#define PT_SP_YEARS_AFTER_PLOUGH
Definition: PTShrubPastures.h:52
Crop::m_last_date
int m_last_date
Definition: Farm.h:503
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
PTSHRUBPASTURES_BASE
#define PTSHRUBPASTURES_BASE
Definition: PTShrubPastures.h:45
fmc_Grazing
Definition: LandscapeFarmingEnums.h:1010
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
PTShrubPastures::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: PTShrubPastures.h:95
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
pt_sp_cattle_is_out3
Definition: PTShrubPastures.h:68
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
WARN_BUG
Definition: MapErrorMsg.h:34
pt_sp_foobar
Definition: PTShrubPastures.h:70
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
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