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
PollenNectar.h
Go to the documentation of this file.
1 //
2 // PollenNectar.h
3 //
4 /*
5 *******************************************************************************************************
6 Copyright (c) 2021, Christopher John Topping, Aarhus University
7 All rights reserved.
8 
9 Version for B-GOOD, Oct. 2023, Xiaodong Duan Aarhus University
10 
11 Redistribution and use in source and binary forms, with or without modification, are permitted provided
12 that the following conditions are met:
13 
14 Redistributions of source code must retain the above copyright notice, this list of conditions and the
15 following disclaimer.
16 Redistributions in binary form must reproduce the above copyright notice, this list of conditions and
17 the following disclaimer in the documentation and/or other materials provided with the distribution.
18 
19 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR
20 IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
21 FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS
22 BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
23 BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR
24 BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
26 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 ********************************************************************************************************
28 */
29 
30 
31 #ifndef POLLEN_NECTAR_H
32 #define POLLEN_NECTAR_H
33 
34 #include <vector>
35 #include <algorithm>
36 #include <climits> // gcc built fails without explicitly including climits
37 #include <Eigen/Dense>
38 
39 
45 public:
51  bool m_flag_not_enough_data = false;
55  double m_DDthreshold = 0;
57  double m_MaxDDeg;
87  vector <double> m_nectar_per_phase;
89  vector <double> m_sugar_per_phase;
91  vector <double> m_pollen_per_phase;
93  vector <int> m_day_flowering_phases;
94 
96  double getNectar(int a_given_day) {
97  return getResource(a_given_day, m_nectar_per_phase);
98  }
99 
101  double getSugar(int a_given_day) {
102  return getResource(a_given_day, m_sugar_per_phase);
103  }
104 
106  double getPollen(int a_given_day) {
107  return getResource(a_given_day, m_pollen_per_phase);
108  }
109 
111  double getPollenQuality(int a_given_day){
112  if(a_given_day < m_day_flowering_phases.front() || a_given_day > m_day_flowering_phases.back()) return 0;
113  else return m_pollen_quality;
114  }
115 
117  double getResource(int a_given_day, vector<double>& a_resource_per_phase) {
118  //before or after the flowering period, return 0
119  if (a_given_day < m_day_flowering_phases.front() || a_given_day >= m_day_flowering_phases.back()) return 0;
120 
121  //check which phase the given day is in
122  for (int i = 0; i < m_num_flowering_phases; i++) {
123  if (a_given_day >= m_day_flowering_phases[i] && a_given_day < m_day_flowering_phases[i + 1]) {
124  if(a_resource_per_phase[i] < 0) return 0; //data missing, return 0
125  return a_resource_per_phase[i];
126  }
127  }
128  }
129 
131  void ClearAll()
132  {
134  m_nectar_per_phase.clear();
135  m_sugar_per_phase.clear();
136  m_pollen_per_phase.clear();
137  m_day_flowering_phases.clear();
138  }
139 
141  double GetThreshold() { return m_DDthreshold; }
143  double GetMaxDDeg() {return m_MaxDDeg;}
145  int GetRef() { return m_curve_number; }
155  void SetStartingDayFlowering(int a_starting_day_flowering) {m_starting_day_flowering = a_starting_day_flowering;}
157  void SetEndingDayFlowering(int a_ending_day_flowering) {m_ending_day_flowering = a_ending_day_flowering;}
159  void UpdateFlowerResource(void);
160 };
161 
164 public:
166  PollenNectarData(double a_quantity, double a_quality);
167  double m_quantity = 0.0; // The quantity of nectar or pollen
168  double m_quality = 0.0; // The quality of nectar or pollen //Jordan
170  double GetNectarSugarConc();
171 };
172 
175 {
176 protected:
178  Eigen::ArrayXd m_year_temp = Eigen::ArrayXd::Zero(365);
180  std::map<int, PollenNectarDevelopmentCurveSet> m_ResourceCurves;
182  std::map<int, std::vector<PollenNectarData>> m_pollen_habitat_species;
184  std::map<int, std::vector<PollenNectarData>> m_nectar_habitat_species;
192  std::map<int, double> m_flower_number_crop;
193 
194 public:
195  PollenNectarDevelopmentData(string a_toleinputfile = "default", string a_tovinputfile = "default");
197 
200 
202  void ReadFlowerNumberCrop(void);
203 
205  {
209  int refnum = m_tov_PollenCurveTable[a_tov_ref];
210  return GetPollenNectarCurve(refnum);
211  }
212 
214  {
218  return m_tov_PollenCurveTable[a_tov_ref];
219  }
220 
222  {
226  return m_tov_PollenCurveTable_sowing_flag[a_tov_ref];
227  }
228 
230  {
231  return &m_ResourceCurves[a_ref];
232  }
233 
235  void updateHabitatFlowerResource(void);
236 
242  PollenNectarData supplyPollenHabitatSpeciesGivenDay(int a_curve_num, int a_given_day);
244  PollenNectarData supplyNectarHabitatSpeciesGivenDay(int a_curve_num, int a_given_day);
245 };
246 
248 
249 #endif
PollenNectarDevelopmentData::m_tov_PollenCurveTable_sowing_flag
vector< bool > m_tov_PollenCurveTable_sowing_flag
This is a look-up table for the the crops to indicate it starts to accumulate degree days from sowing...
Definition: PollenNectar.h:188
PollenNectarDevelopmentCurveSet::SetEndingDayFlowering
void SetEndingDayFlowering(int a_ending_day_flowering)
Set the ending day of flowering period.
Definition: PollenNectar.h:157
PollenNectarDevelopmentCurveSet::m_pollen_per_phase
vector< double > m_pollen_per_phase
The array to store the pollen in different period, the size is the number of the flowering period pha...
Definition: PollenNectar.h:91
PollenNectarDevelopmentData::m_num_species_habitat
int m_num_species_habitat
This is used to store the number of species for habitat.
Definition: PollenNectar.h:190
PollenNectarDevelopmentCurveSet::m_starting_day_flowering
int m_starting_day_flowering
The starting day number for flowering period in a year.
Definition: PollenNectar.h:79
PollenNectarDevelopmentData::PollenNectarDevelopmentData
PollenNectarDevelopmentData(string a_toleinputfile="default", string a_tovinputfile="default")
Definition: PollenNectar.cpp:98
PollenNectarDevelopmentData::supplyPollenHabitatSpeciesGivenDay
PollenNectarData supplyPollenHabitatSpeciesGivenDay(int a_curve_num, int a_given_day)
Supply the pollen for the given species for the given day after today.
Definition: PollenNectar.cpp:345
PollenNectarDevelopmentCurveSet::PollenNectarDevelopmentCurveSet
PollenNectarDevelopmentCurveSet()
Definition: PollenNectar.cpp:57
PollenNectarDevelopmentCurveSet::getNectar
double getNectar(int a_given_day)
Returns the nectar quantity for the given day after day 0 in a year.
Definition: PollenNectar.h:96
PollenNectarDevelopmentCurveSet::GetEndingDayFlowering
int GetEndingDayFlowering(void)
Returns the ending day of flowering period.
Definition: PollenNectar.h:153
PollenNectarDevelopmentCurveSet::m_ending_DD_flowering
double m_ending_DD_flowering
The ending degree days for ending flowering period.
Definition: PollenNectar.h:69
PollenNectarDevelopmentCurveSet::m_MinFlowerLength
double m_MinFlowerLength
The minimum flowering length.
Definition: PollenNectar.h:59
PollenNectarDevelopmentCurveSet::m_starting_DD_flowering
double m_starting_DD_flowering
The starting degree days for starting flowering period.
Definition: PollenNectar.h:67
TOP_Bombus
Definition: PopulationManager.h:73
CfgStr::value
char * value() const
Definition: Configurator.h:182
PollenNectarDevelopmentCurveSet::m_MeanFlowerLength
double m_MeanFlowerLength
The mean flowering length.
Definition: PollenNectar.h:63
TOP_Osmia
Definition: PopulationManager.h:69
PollenNectarDevelopmentCurveSet::m_MaxFlowerLength
double m_MaxFlowerLength
The maximum flowering length.
Definition: PollenNectar.h:61
PollenNectarDevelopmentData::m_tov_PollenCurveTable
vector< int > m_tov_PollenCurveTable
This is a look-up table, it contains for each tov the corresponding curve number to use.
Definition: PollenNectar.h:186
PollenNectarDevelopmentCurveSet::GetStartingDayFlowering
int GetStartingDayFlowering(void)
Returns the starting day of flowering period.
Definition: PollenNectar.h:151
CfgStr
String configurator entry class.
Definition: Configurator.h:173
PollenNectarDevelopmentCurveSet::m_MaxDDeg
double m_MaxDDeg
The maximum temperature that one day can accumulate.
Definition: PollenNectar.h:57
g_date
class Calendar * g_date
Definition: Calendar.cpp:37
PollenNectarDevelopmentCurveSet
This class justs holds the set of resource curves related to a specific plant community or crop....
Definition: PollenNectar.h:44
PollenNectarDevelopmentData::supplyNectarHabitatSpeciesCurrentDay
PollenNectarData supplyNectarHabitatSpeciesCurrentDay(int a_curve_num)
Supply the current nectar for the given species.
Definition: PollenNectar.cpp:338
CfgFloat::value
double value() const
Definition: Configurator.h:142
ls.h
PollenNectarDevelopmentCurveSet::m_curve_number
int m_curve_number
The reference number for the curve.
Definition: PollenNectar.h:53
PollenNectarDevelopmentCurveSet::GetMaxDDeg
double GetMaxDDeg()
Returns the maximum day degrees that one day can have.
Definition: PollenNectar.h:143
l_map_nectarpollen
static CfgStr l_map_nectarpollen("MAP_NECTARPOLLEN_FILE", CFG_CUSTOM, "species_production_curves.csv")
cfg_GeneralColdWeatherThresholdFlower
CfgFloat cfg_GeneralColdWeatherThresholdFlower("GENERAL_COLD_WEATHER_THRESHOLD_FLOWER", CFG_CUSTOM, 2800)
The threshold of ending accumulated degrees for colder weather.
PollenNectarDevelopmentCurveSet::m_total_sugar_whole_flowering
double m_total_sugar_whole_flowering
The total amount of sugar in the whole flowering period –mg.
Definition: PollenNectar.h:73
PollenNectarDevelopmentData::GetPollenNectarCurve
PollenNectarDevelopmentCurveSet * GetPollenNectarCurve(int a_ref)
Definition: PollenNectar.h:229
PollenNectarDevelopmentCurveSet::getPollenQuality
double getPollenQuality(int a_given_day)
Returns the pollen quality for the given day after day 0 in a year.
Definition: PollenNectar.h:111
PollenNectarDevelopmentData::m_flower_number_crop
std::map< int, double > m_flower_number_crop
The array to store the flower numbers for crop species.
Definition: PollenNectar.h:192
CreatePollenNectarDevelopmentData
PollenNectarDevelopmentData * CreatePollenNectarDevelopmentData()
Definition: PollenNectar.cpp:294
cfg_GeneralColdWeatherAdjustFlower
CfgFloat cfg_GeneralColdWeatherAdjustFlower("GENERAL_COLD_WEATHER_ADJUST_FLOWER", CFG_CUSTOM, 3)
Adjust of the base development for colder weather in colder areas, for flower development in natural ...
g_nectarpollen
class PollenNectarDevelopmentData * g_nectarpollen
Definition: Plants.cpp:41
PollenNectarDevelopmentCurveSet::m_flowering_length
int m_flowering_length
The flowering length in days.
Definition: PollenNectar.h:83
PollenNectarDevelopmentData::RecalculatePollenNectarCurvesForYear
void RecalculatePollenNectarCurvesForYear(void)
Recalculate the pollen and nectar curves for a year for the habitat species. This function only be ca...
Definition: PollenNectar.cpp:396
PollenNectarData::m_quantity
double m_quantity
Definition: PollenNectar.h:167
CfgBool::value
bool value() const
Definition: Configurator.h:164
PollenNectarDevelopmentCurveSet::m_total_pollen_whole_flowering
double m_total_pollen_whole_flowering
The total amount of pollen in the whole flowering period –mg.
Definition: PollenNectar.h:75
PollenNectarData::PollenNectarData
PollenNectarData()
Definition: PollenNectar.cpp:281
Configurator.h
PollenNectarDevelopmentData::m_pollen_habitat_species
std::map< int, std::vector< PollenNectarData > > m_pollen_habitat_species
This is the dictionary to store the pollen for every habitat species in a year.
Definition: PollenNectar.h:182
cfg_GeneralMaxFloweringPeriod
CfgFloat cfg_GeneralMaxFloweringPeriod("GENERAL_MAX_FLOWERING_PERIOD", CFG_CUSTOM, 60.0)
The general max flowering period when there is no data in the input file.
CreatePollenNectarDevelopmentData
PollenNectarDevelopmentData * CreatePollenNectarDevelopmentData()
Definition: PollenNectar.cpp:294
PollenNectarDevelopmentCurveSet::m_sugar_per_phase
vector< double > m_sugar_per_phase
The array to store the sugar in different period, the size is the number of the flowering period phas...
Definition: PollenNectar.h:89
PollenNectarDevelopmentCurveSet::m_flag_not_enough_data
bool m_flag_not_enough_data
Flag to show not enough data is available, so this curve can't be used.
Definition: PollenNectar.h:51
PollenNectarDevelopmentCurveSet::GetThreshold
double GetThreshold()
Returns the day degrees temperature threshold.
Definition: PollenNectar.h:141
CfgBool
Bool configurator entry class.
Definition: Configurator.h:155
PollenNectarDevelopmentData::m_year_temp
Eigen::ArrayXd m_year_temp
This is used to store one year temperature data.
Definition: PollenNectar.h:178
PollenNectarDevelopmentCurveSet::m_nectar_per_phase
vector< double > m_nectar_per_phase
The array to store the nectar in different period, the size is the number of the flowering period pha...
Definition: PollenNectar.h:87
l_map_tov_nectarpollen
static CfgStr l_map_tov_nectarpollen("MAP_TOV_NECTARPOLLEN_FILE", CFG_CUSTOM, "tovALMaSSNectarPollenInput.txt")
PollenNectarDevelopmentCurveSet::SetStartingDayFlowering
void SetStartingDayFlowering(int a_starting_day_flowering)
Set the starting day of flowering period.
Definition: PollenNectar.h:155
PollenNectarDevelopmentData
A class to manage a range of pollen and nectar development curves based on indexed rates.
Definition: PollenNectar.h:174
l_flower_number_crops
static CfgStr l_flower_number_crops("FLOWER_NUMBER_CROPS_FILE", CFG_CUSTOM, "crop_stacks.csv")
MapErrorMsg::Warn
void Warn(MapErrorState a_level, std::string a_msg1, std::string a_msg2)
Definition: MapErrorMsg.cpp:69
CfgArray_Double
Definition: Configurator.h:208
CfgArray_Double::get_array_size
int get_array_size()
Definition: Configurator.h:222
PollenNectarDevelopmentCurveSet::ClearAll
void ClearAll()
Definition: PollenNectar.h:131
TTypesOfPopulation
TTypesOfPopulation
An enum to hold all the possible types of population handled by a Population_Manager class.
Definition: PopulationManager.h:57
PollenNectarDevelopmentCurveSet::getResource
double getResource(int a_given_day, vector< double > &a_resource_per_phase)
Returns the resource for the given day after day o in a year.
Definition: PollenNectar.h:117
CfgArray_Double::value
std::vector< double > value() const
Definition: Configurator.h:219
PollenNectarDevelopmentData::supplyNectarHabitatSpeciesGivenDay
PollenNectarData supplyNectarHabitatSpeciesGivenDay(int a_curve_num, int a_given_day)
Supply the current nectar for the given species for the given day after today.
Definition: PollenNectar.cpp:354
PollenNectarDevelopmentData::tovGetPollenNectarCurve
PollenNectarDevelopmentCurveSet * tovGetPollenNectarCurve(TTypesOfVegetation a_tov_ref)
Definition: PollenNectar.h:204
PollenNectarDevelopmentCurveSet::getSugar
double getSugar(int a_given_day)
Returns the sugar quantity for the given day after day 0 in a year.
Definition: PollenNectar.h:101
PollenNectarDevelopmentData::m_nectar_habitat_species
std::map< int, std::vector< PollenNectarData > > m_nectar_habitat_species
This is the dictionary to store the nectar for every habitat species in a year.
Definition: PollenNectar.h:184
tov_Undefined
Definition: LandscapeFarmingEnums.h:610
PollenNectarDevelopmentCurveSet::GetRef
int GetRef()
Returns the reference number for the curve.
Definition: PollenNectar.h:145
LE_TypeClass::TranslateVegTypes
TTypesOfVegetation TranslateVegTypes(int VegReference)
Definition: Elements.cpp:3724
cfg_FloweringPeriodPhasesProportionArray
CfgArray_Double cfg_FloweringPeriodPhasesProportionArray("FLOWERING_PERIOD_PHASES_PROPORTION_ARRAY", CFG_CUSTOM, 3, vector< double >{0.15, 0.7, 0.15})
Vector to store the proportions for flowering period phases, for now there are three phases; beginnin...
cfg_pollen_nectar_on
CfgBool cfg_pollen_nectar_on
Flag to determine whether nectar and pollen models are used - should be set to true for pollinator mo...
g_Species
TTypesOfPopulation g_Species
Definition: PopulationManager.cpp:101
PollenNectarDevelopmentCurveSet::m_total_nectar_whole_flowering
double m_total_nectar_whole_flowering
The total amount of nectar in the whole flowering period –mg.
Definition: PollenNectar.h:71
PollenNectarData
A data class to store nectar or pollen data.
Definition: PollenNectar.h:163
MapErrorMsg.h
g_weather
class Weather * g_weather
Definition: Weather.cpp:49
PollenNectarDevelopmentCurveSet::m_ending_day_flowering
int m_ending_day_flowering
The ending day number of flowering period in a year.
Definition: PollenNectar.h:81
g_msg
MapErrorMsg * g_msg
Definition: MapErrorMsg.cpp:41
PollenNectarDevelopmentData::updateHabitatFlowerResource
void updateHabitatFlowerResource(void)
The function to update the development of flower resource for all the habitat speccies.
Definition: PollenNectar.cpp:364
TTypesOfVegetation
TTypesOfVegetation
Values that represent the types of vegetation that are represented in ALMaSS.
Definition: LandscapeFarmingEnums.h:192
cfg_FlowerPollenNectarScaler
CfgFloat cfg_FlowerPollenNectarScaler
The scalear to reduce flower resource, default 1 which means no reduction.
Definition: PollenNectar.cpp:53
PollenNectarDevelopmentCurveSet::m_StdFlowerLength
double m_StdFlowerLength
The standard value of flower length.
Definition: PollenNectar.h:65
CfgFloat
Double configurator entry class.
Definition: Configurator.h:126
PollenNectarDevelopmentCurveSet::GetEndingDDFlowering
double GetEndingDDFlowering(void)
Returns the ending dd of flowering period.
Definition: PollenNectar.h:149
PollenNectarData::m_quality
double m_quality
Definition: PollenNectar.h:168
PollenNectarDevelopmentCurveSet::m_num_flowering_phases
int m_num_flowering_phases
The number of flowering phases.
Definition: PollenNectar.h:85
PollenNectarDevelopmentCurveSet::getPollen
double getPollen(int a_given_day)
Returns the pollen quantity for the given day after day 0 in a year.
Definition: PollenNectar.h:106
CFG_CUSTOM
Definition: Configurator.h:70
PollenNectarData::GetNectarSugarConc
double GetNectarSugarConc()
Returns volume of sugar in volume of nectar (vol/vol).
Definition: PollenNectar.cpp:303
Calendar::DayInYear
int DayInYear(void)
Definition: Calendar.h:58
PollenNectarDevelopmentData::tovGetPollenNectarCurveSowingFlag
bool tovGetPollenNectarCurveSowingFlag(TTypesOfVegetation a_tov_ref)
Definition: PollenNectar.h:221
cfg_FloweringPeriodPhasesLengthArray
CfgArray_Double cfg_FloweringPeriodPhasesLengthArray("FLOWERING_PERIOD_PHASES_LENGTH_ARRAY", CFG_CUSTOM, 3, vector< double >{0.275, 0.45, 0.275})
Vector to store the length proportion for flowering period phases.
PollenNectarDevelopmentCurveSet::m_pollen_quality
double m_pollen_quality
The pollen quality when there is pollen, this also depends the species, by default it uses the apis v...
Definition: PollenNectar.h:77
Weather::GetTempAfterDays
double GetTempAfterDays(int days)
Get the temperature at the given number of days which is the number of days after today.
Definition: Weather.h:484
g_letype
class LE_TypeClass * g_letype
Definition: Elements.cpp:806
PollenNectarDevelopmentData::tovGetPollenNectarCurveRef
int tovGetPollenNectarCurveRef(TTypesOfVegetation a_tov_ref)
Definition: PollenNectar.h:213
PollenNectarDevelopmentData::ReadFlowerNumberCrop
void ReadFlowerNumberCrop(void)
Function to read the flower number for crops.
Definition: PollenNectar.cpp:72
PollenNectarDevelopmentCurveSet::m_DDthreshold
double m_DDthreshold
The threshold temperature to calculate day degrees.
Definition: PollenNectar.h:55
PollenNectarDevelopmentCurveSet::m_day_flowering_phases
vector< int > m_day_flowering_phases
The array to store the day number for different flowering periods, the size is the number of the flow...
Definition: PollenNectar.h:93
PollenNectarDevelopmentCurveSet::GetStartingDDFlowering
double GetStartingDDFlowering(void)
Returns the staring dd of flowering period.
Definition: PollenNectar.h:147
PollenNectarDevelopmentData::~PollenNectarDevelopmentData
~PollenNectarDevelopmentData()
Definition: PollenNectar.cpp:274
PollenNectarDevelopmentData::m_ResourceCurves
std::map< int, PollenNectarDevelopmentCurveSet > m_ResourceCurves
This is the main data set, it contains the resource curves for each species.
Definition: PollenNectar.h:180
PollenNectarDevelopmentCurveSet::UpdateFlowerResource
void UpdateFlowerResource(void)
Update the flower resource for a year.
Definition: PollenNectar.cpp:454
PollenNectarDevelopmentData::supplyPollenHabitatSpeciesCurrentDay
PollenNectarData supplyPollenHabitatSpeciesCurrentDay(int a_curve_num)
Supply the current pollen for the given species.
Definition: PollenNectar.cpp:331