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

#include <FodderGrass.h>

Inheritance diagram for FodderGrass:
Crop

Public Member Functions

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

◆ FodderGrass()

FodderGrass::FodderGrass ( TTypesOfVegetation  a_tov,
TTypesOfCrops  a_toc,
Landscape a_L 
)
inline
59  : Crop(a_tov, a_toc, a_L)
60  {
63  }

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

Member Function Documentation

◆ Do()

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

Reimplemented from Crop.

44 {
45  m_farm = a_farm;
46  m_field = a_field;
47  m_ev = a_ev;
48  long d1 = 0;
49  int noDates=2;
50  bool done = false;
51 
52  switch ( m_ev->m_todo ) {
53  case fg_start:
54 
55  FG_WATER_DATE = 0;
56  FG_CUT_DATE = 0;
57  FG_FERTI_DATE = 0;
60  a_field->ClearManagementActionSum();
61 
62 
63  // Set up the date management stuff
65 
66  // Start and stop dates for all events after harvest
67  m_field->SetMDates(0,0,g_date->DayInYear(27,7));
68 
69  // Determined by harvest date - used to see if at all possible
70  m_field->SetMDates(1,0,g_date->DayInYear(27,7));
71  m_field->SetMDates(0,1,g_date->DayInYear(28,7));
72  m_field->SetMDates(1,1,g_date->DayInYear(10,10));
73 
74  // Check the next crop for early start, unless it is a spring crop
75  // in which case we ASSUME that no checking is necessary!!!!
76  // So DO NOT implement a crop that runs over the year boundary
77 
78  //new if: do the check only for non-optimising farms and if year>0. (030713 - m_rotation used only in the hidden year, so I modified the condition from >7 to >0)
80 
81  if (m_ev->m_startday>g_date->DayInYear(1,7))
82  {
83  if (m_field->GetMDates(0,0) >=m_ev->m_startday)
84  {
85  g_msg->Warn( WARN_BUG, "FodderGrass::Do(): "
86  "Harvest too late for the next crop to start!!!", "" );
87  exit( 1 );
88  }
89  // Now fix any late finishing problems
90  for (int i=0; i<noDates; i++) {
91  if (m_field->GetMDates(0,i)>=m_ev->m_startday)
93  if (m_field->GetMDates(1,i)>=m_ev->m_startday)
95  }
96  }
97 
98  // Now no operations can be timed after the start of the next crop.
99  if ( ! m_ev->m_first_year ) {
100  // Are we before July 1st?
101  d1 = g_date->OldDays() + g_date->DayInYear( 1,7 );
102 
103  if (g_date->Date() < d1) {
104  // Yes, too early. We assumme this is because the last crop was late
105  g_msg->Warn( WARN_BUG, "FodderGrass::Do(): "
106  "Crop start attempt between 1st Jan & 1st July", "" );
107  exit( 1 );
108 
109  } else {
110 
111  d1 = g_date->OldDays() + m_first_date+365; // Add 365 for spring crop
112  if (g_date->Date() > d1) {
113  // Yes too late - should not happen - raise an error
114  g_msg->Warn( WARN_BUG, "FodderGrass::Do(): "
115  "Crop start attempt after last possible start date",
116  "" );
117  exit( 1 );
118 
119  }
120  }
121  }
122  }//if
123 
124  // End single block date checking code. Please see next line
125  // comment as well.
126 
127  // Reinit d1 to first possible starting date.
128  d1 = g_date->OldDays()+m_first_date;;
129  if ( ! m_ev->m_first_year ) d1+=365; // Add 365 for spring crop (not 1st yr)
130  SimpleEvent( d1, fg_ferti_zero, false );
131 
132  d1 = g_date->OldDays() + g_date->DayInYear( 15, 3 );
133  if (g_date->Date() >= d1) d1 += 365;
134  SimpleEvent( d1, fg_ferti_one, false );
135 
136 #ifdef __EcoSol_01
137  // THIS CODE IS ONLY NEEDED IF WE ARE TESTING A HERBICIDE WITH THE PESTICIDE ENGINE
138  /* */
139  if ( a_field->GetLandscape()->SupplyShouldSpray() ) {
141  if (g_date->Date() >= d1) d1 += 365;
142  SimpleEvent( d1, fg_productapplic_one, false );
143  }
144  /* */
145 #endif
146  break;
147 
149  if ( m_ev->m_lock || m_farm->DoIt( 100 ))
150  {
152  // We didn't do it today, try again tomorrow.
153  SimpleEvent( g_date->Date() + 1, fg_productapplic_one, true );
154  break;
155  }
156  }
157  break;
158 
159  case fg_ferti_zero:
160  if ( m_ev->m_lock || m_farm->DoIt( 60 ))
161  {
162  if (!m_farm->FA_Slurry( m_field, 0.0,
163  g_date->DayInYear( 30, 4 ) - g_date->DayInYear())) {
164  // We didn't do it today, try again tomorrow.
165  SimpleEvent( g_date->Date() + 1, fg_ferti_zero, true );
166  break;
167  }
169  }
170 
171  // This used to be broken, but is now outdated, as fg_ferti_one
172  // now is the main thread of execution. FN 15/5, 2003.
173  // Note: The line should have read: g_date->OldDays() + ...
174  //SimpleEvent( g_date->Date()+ g_date->DayInYear( 15,3 ),
175  break;
176 
177  case fg_ferti_one:
178  if (!m_farm->FA_NPK( m_field, 0.0,
179  g_date->DayInYear( 15, 4 ) - g_date->DayInYear())) {
180  // We didn't do it today, try again tomorrow.
181  SimpleEvent( g_date->Date() + 1, fg_ferti_one, true );
182  break;
183  }
185 
186  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25,4 ),
187  fg_ferti_two, false );
188 
189  // Start a watering thread
190  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 15, 5 ),
191  fg_water_zero, false );
192  break;
193 
194  case fg_ferti_two:
195  if (!m_farm->FA_NPK( m_field, 0.0,
196  g_date->DayInYear( 10, 5 ) - g_date->DayInYear())) {
197  // We didn't do it today, try again tomorrow.
198  SimpleEvent( g_date->Date() + 1, fg_ferti_two, true );
199  break;
200  }
202 
203  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25,5 ),
204  fg_cut_to_silage, false );
205  break;
206 
207  case fg_cut_to_silage:
208  if ( m_ev->m_lock || m_farm->DoIt( 100 )) {
209  // At least 7 days from last watering and 21 from
210  // last application of fertilizer.
211  if (g_date->DayInYear()<FG_FERTI_DATE+21 ||
213  ) {
214  SimpleEvent( g_date->Date() + 1, fg_cut_to_silage, true );
215  break;
216  }
217  if (!m_farm->CutToSilage( m_field, 0.0,
218  g_date->DayInYear( 10, 6 ) -
219  g_date->DayInYear())) {
220  // We didn't do it today, try again tomorrow.
221  SimpleEvent( g_date->Date() + 1, fg_cut_to_silage, true );
222  break;
223  }
225 
226  // Decide whether we got for cattle or a second silage cut.
227  // 75% go for the second cut.
228  if ( FG_FORCE_SECOND_CUT || m_farm->DoIt( 100 )) {
229  // 75% do Slurry fertilization before second cutting, 25% NPK.
230  if ( m_farm->DoIt( 75 )) {
231  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25, 5 ),
232  fg_ferti_three, false );
233  } else {
234  SimpleEvent( g_date->OldDays() + g_date->DayInYear( 25, 5 ),
235  fg_ferti_four, false );
236  }
237  break;
238  }
239  }
240  break; // Should never get here without setting up the next silage cut
241 
242  case fg_ferti_three:
243  // The percentage has already been taken care of during
244  // the decisions made under fg_cut_to_silage
245  if (!m_farm->FA_Slurry( m_field, 0.0,
246  ( FG_CUT_DATE+4 ) - g_date->DayInYear())) {
247  // We didn't do it today, try again tomorrow.
248  SimpleEvent( g_date->Date() + 1, fg_ferti_three, true );
249  break;
250  }
251 
252  {
253  // Three weeks later min
254  d1 = g_date->OldDays() + g_date->DayInYear( 16, 6 );
255  if ( d1 < g_date->Date() + 21 )
256  d1 = g_date->Date() + 21;
257  SimpleEvent( d1, fg_cut_to_silage2, false );
258  }
259  break;
260 
261  case fg_ferti_four:
262  // The percentage has already been taken care of during
263  // the decisions made under fg_cut_to_silage
264  if (!m_farm->FA_NPK( m_field, 0.0,
265  ( FG_CUT_DATE+4 ) - g_date->DayInYear())) {
266  // We didn't do it today, try again tomorrow.
267  SimpleEvent( g_date->Date() + 1, fg_ferti_four, true );
268  break;
269  }
270 
271  {
272  // Three weeks later min
273  d1 = g_date->OldDays() + g_date->DayInYear( 16, 6 );
274  if ( d1 < g_date->Date() + 21 )
275  d1 = g_date->Date() + 21;
276  SimpleEvent( d1, fg_cut_to_silage2, false );
277  }
278  break;
279 
280  case fg_cut_to_silage2:
281  // The percentage has already been taken care of during
282  // the decisions made under fg_cut_to_silage
283  if (!m_farm->CutToSilage( m_field, 0.0,
284  g_date->DayInYear( 6,7 ) -
285  g_date->DayInYear())) {
286  // We didn't do it today, try again tomorrow.
287  SimpleEvent( g_date->Date() + 1, fg_cut_to_silage2, true );
288  break;
289  }
291 
292  {
293  // Three weeks later min
294  d1 = g_date->OldDays() + g_date->DayInYear( 8, 7 );
295  if ( d1 < g_date->Date() + 21 )
296  d1 = g_date->Date() + 21;
297 
298  ChooseNextCrop (2);
299 
300  SimpleEvent( d1, fg_cut_to_silage3, false );
301  }
302  break;
303 
304  case fg_cut_to_silage3:
305  // The percentage has already been taken care of during
306  // the decisions made under fg_cut_to_silage2
307  if (!m_farm->CutToSilage( m_field, 0.0,
308  m_field->GetMDates(0,0) -
309  g_date->DayInYear())) {
310  // We didn't do it today, try again tomorrow.
311  SimpleEvent( g_date->Date() + 1, fg_cut_to_silage3, true );
312  break;
313  }
315  done=true;
316  break;
317 
318  case fg_water_zero:
319  if ( m_ev->m_lock || m_farm->DoIt( 40 ))
320  {
321  if ( g_date->Date() < FG_CUT_DATE + 3 ) {
322  // Too close to silage cutting, so try again tomorrow.
323  SimpleEvent( g_date->Date() + 1, fg_water_zero, true );
324  }
325 
326  if (!m_farm->Water( m_field, 0.0,
327  g_date->DayInYear( 1, 6 ) - g_date->DayInYear())) {
328  // We didn't do it today, try again tomorrow.
329  SimpleEvent( g_date->Date() + 1, fg_water_zero, true );
330  break;
331  }
332  // Success
334 
335  // Determine whether we want to do the second watering.
336  // If so, then force the second silage cutting as well.
337 
338  if ( m_farm->DoIt( 40 ) && !FG_HALT_SECOND_WATER ) {
339  // Do second watering.
341  d1 = g_date->OldDays() + g_date->DayInYear( 2,6 );
342  if ( d1 < g_date->Date() + 7 )
343  d1 = g_date->Date() + 7;
344  SimpleEvent( d1, fg_water_one, false );
345  }
346  }
347  // Didn't water so let the thread die
348  break;
349 
350  case fg_water_one:
351  if ( g_date->Date() < FG_CUT_DATE + 3 ) {
352  // Too close to silage cutting, so try again tomorrow.
353  SimpleEvent( g_date->Date() + 1, fg_water_one, true );
354  }
355 
356  if (!m_farm->Water( m_field, 0.0,
357  g_date->DayInYear( 30, 6 ) -
358  g_date->DayInYear())) {
359  // We didn't do it today, try again tomorrow.
360  SimpleEvent( g_date->Date() + 1, fg_water_one, true );
361  break;
362  }
364  break;
365  // End of watering thread
366 
367  default:
368  g_msg->Warn( WARN_BUG, "FodderGrass::Do(): "
369  "Unknown event type! ", "" );
370  exit( 1 );
371  }
372  return done;
373 }

References cfg_pest_product_amounts, cfg_pest_productapplic_period, cfg_pest_productapplic_startdate, LE::ClearManagementActionSum(), Calendar::Date(), Calendar::DayInYear(), FG_CUT_DATE, fg_cut_to_silage, fg_cut_to_silage2, fg_cut_to_silage3, FG_FERTI_DATE, fg_ferti_four, fg_ferti_one, fg_ferti_three, fg_ferti_two, fg_ferti_zero, FG_FORCE_SECOND_CUT, FG_HALT_SECOND_WATER, fg_productapplic_one, fg_start, FG_WATER_DATE, fg_water_one, fg_water_zero, g_date, g_msg, Calendar::GetYearNumber(), Calendar::OldDays(), ppp_1, tof_OptimisingFarm, CfgInt::value(), CfgArray_Double::value(), MapErrorMsg::Warn(), and WARN_BUG.

◆ SetUpFarmCategoryInformation()

void FodderGrass::SetUpFarmCategoryInformation ( )
inline
64  {
65  const int elements = 2 + (fg_foobar - FG_BASE);
67 
68  FarmManagementCategory catlist[elements] =
69  {
70  fmc_Others, // zero element unused but must be here
71  fmc_Others, // fg_start = 1, // Compulsory, start event must always be 1 (one).
72  fmc_Fertilizer, // fg_ferti_zero=FG_BASE,
73  fmc_Fertilizer, // fg_ferti_one,
74  fmc_Fertilizer, // fg_ferti_two,
75  fmc_Fertilizer, // fg_ferti_three,
76  fmc_Fertilizer, // fg_ferti_four,
77  fmc_Cutting, // fg_cut_to_silage,
78  fmc_Cutting, // fg_cut_to_silage2,
79  fmc_Cutting, // fg_cut_to_silage3,
80  fmc_Watering, // fg_water_zero,
81  fmc_Watering, // fg_water_one,
82  fmc_Herbicide // fg_productapplic_one,
83 
84 
85  // no foobar entry
86 
87  };
88  // Iterate over the catlist elements and copy them to vector
89  copy(begin(catlist), end(catlist), back_inserter(m_ManagementCategories));
90 
91  }

References FG_BASE, fg_foobar, fmc_Cutting, fmc_Fertilizer, fmc_Herbicide, fmc_Others, fmc_Watering, Crop::m_base_elements_no, and Crop::m_ManagementCategories.

Referenced by FodderGrass().


The documentation for this class was generated from the following files:
LE::GetMDates
int GetMDates(int a, int b)
Definition: Elements.h:405
FG_WATER_DATE
#define FG_WATER_DATE
Definition: FodderGrass.h:32
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
fg_foobar
Definition: FodderGrass.h:51
fg_cut_to_silage3
Definition: FodderGrass.h:47
FG_BASE
#define FG_BASE
Definition: FodderGrass.h:36
LE::SetMDates
void SetMDates(int a, int b, int c)
Definition: Elements.h:406
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
fg_ferti_four
Definition: FodderGrass.h:44
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
Farm::DoIt
bool DoIt(double a_probability)
Return chance out of 0 to 100.
Definition: Farm.cpp:856
Calendar::GetYearNumber
int GetYearNumber(void)
Definition: Calendar.h:72
FarmEvent::m_first_year
bool m_first_year
Definition: Farm.h:386
fg_productapplic_one
Definition: FodderGrass.h:50
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
fmc_Herbicide
Definition: LandscapeFarmingEnums.h:1006
Farm::GetType
TTypesOfFarm GetType(void)
Definition: Farm.h:956
Crop::m_base_elements_no
int m_base_elements_no
Definition: Farm.h:505
fg_water_zero
Definition: FodderGrass.h:48
fg_cut_to_silage2
Definition: FodderGrass.h:46
cfg_pest_productapplic_period
CfgInt cfg_pest_productapplic_period
Period for applying pesticide.
Definition: Elements.cpp:169
cfg_pest_productapplic_startdate
CfgInt cfg_pest_productapplic_startdate
Start date for applying pesticide the first time.
Definition: Elements.cpp:166
Crop::m_first_date
int m_first_date
Definition: Farm.h:501
FarmEvent::m_startday
int m_startday
Definition: Farm.h:385
fg_ferti_two
Definition: FodderGrass.h:42
fg_water_one
Definition: FodderGrass.h:49
Farm::FA_NPK
virtual bool FA_NPK(LE *a_field, double a_user, int a_days)
Apply NPK fertilizer to a_field owned by an stock farmer.
Definition: FarmFuncs.cpp:982
Crop::SimpleEvent
void SimpleEvent(long a_date, int a_todo, bool a_lock)
Adds an event to this crop management.
Definition: Farm.cpp:747
fmc_Cutting
Definition: LandscapeFarmingEnums.h:1009
FodderGrass::SetUpFarmCategoryInformation
void SetUpFarmCategoryInformation()
Definition: FodderGrass.h:64
fmc_Fertilizer
Definition: LandscapeFarmingEnums.h:1004
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.
Calendar::Date
long Date(void)
Definition: Calendar.h:57
fg_cut_to_silage
Definition: FodderGrass.h:45
FG_CUT_DATE
#define FG_CUT_DATE
Definition: FodderGrass.h:31
fmc_Others
Definition: LandscapeFarmingEnums.h:1003
fmc_Watering
Definition: LandscapeFarmingEnums.h:1011
Calendar::OldDays
long OldDays(void)
Definition: Calendar.h:60
FG_HALT_SECOND_WATER
#define FG_HALT_SECOND_WATER
Definition: FodderGrass.h:35
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
Crop::m_farm
Farm * m_farm
Definition: Farm.h:498
Crop::m_field
LE * m_field
Definition: Farm.h:499
CfgInt::value
int value() const
Definition: Configurator.h:116
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
FarmEvent::m_todo
int m_todo
Definition: Farm.h:388
tof_OptimisingFarm
Definition: LandscapeFarmingEnums.h:696
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
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
fg_ferti_zero
Definition: FodderGrass.h:40
fg_ferti_one
Definition: FodderGrass.h:41
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
FG_FORCE_SECOND_CUT
#define FG_FORCE_SECOND_CUT
Definition: FodderGrass.h:34
Crop::Crop
Crop(TTypesOfVegetation a_tov, TTypesOfCrops a_toc, Landscape *a_L)
Definition: Farm.cpp:733
FG_FERTI_DATE
#define FG_FERTI_DATE
Definition: FodderGrass.h:33
Crop::ChooseNextCrop
void ChooseNextCrop(int a_no_dates)
Chooses the next crop to grow in a field.
Definition: Farm.cpp:756
Crop::m_ev
FarmEvent * m_ev
Definition: Farm.h:500
WARN_BUG
Definition: MapErrorMsg.h:34
fg_start
Definition: FodderGrass.h:39
ppp_1
Definition: LandscapeFarmingEnums.h:1079
FarmManagementCategory
FarmManagementCategory
Definition: LandscapeFarmingEnums.h:1001
fg_ferti_three
Definition: FodderGrass.h:43