Modular Megafauna Model 1.1.5
A physiological, dynamic herbivore simulator in C++.
Loading...
Searching...
No Matches
Fauna::HerbivoreBase Class Referenceabstract

Abstract base class for herbivores. More...

#include <herbivore_base.h>

Inheritance diagram for Fauna::HerbivoreBase:
Fauna::HerbivoreInterface Fauna::HerbivoreCohort

Public Member Functions

virtual void eat (const ForageMass &kg_per_km2, const Digestibility &digestibility, const ForageMass &N_kg_per_km2)
 Feed the herbivore dry matter forage. More...
 
virtual ForageMass get_forage_demands (const HabitatForage &available_forage)
 Get the forage the herbivore would like to eat today. More...
 
virtual std::string get_output_group () const
 The name of the HFT for aggregating output. More...
 
virtual double get_kg_per_km2 () const
 Get herbivore biomass density [kg/km²]. More...
 
virtual const Output::HerbivoreDataget_todays_output () const
 Read current output. More...
 
virtual void simulate_day (const int day, const HabitatEnvironment &environment, double &offspring)
 Simulate daily events. More...
 
int get_age_days () const
 Current age in days. More...
 
double get_age_years () const
 Current age in years. More...
 
double get_bodyfat () const
 Proportional body fat in empty body (fat mass/empty body mass). More...
 
virtual double get_bodymass () const
 Current live weight, including fat, ingesta, blood, etc. [kg/ind]. More...
 
double get_bodymass_adult () const
 Body mass at physical maturity [kg/ind]. More...
 
double get_conductance () const
 Get full-body conductance [W/°C/ind]. More...
 
double get_fatmass () const
 Current fat mass (pure lipids) [kg/ind]. More...
 
const Hftget_hft () const
 The herbivore functional type (HFT). More...
 
double get_max_fatmass () const
 Physiological maximum of fat mass [kg/ind]. More...
 
double get_structural_mass () const
 Current mass of body tissue without fat, ingesta, blood, etc. [kg/ind]. More...
 
int get_today () const
 Current day of the year, as set in simulate_day(). More...
 
Sex get_sex () const
 The sex of the herbivore. More...
 
- Public Member Functions inherited from Fauna::HerbivoreInterface
virtual ~HerbivoreInterface ()=default
 Virtual destructor, which will be called by derived classes. More...
 
virtual void eat (const ForageMass &kg_per_km2, const Digestibility &digestibility, const ForageMass &N_kg_per_km2=ForageMass(0))=0
 Feed the herbivore dry matter forage. More...
 
virtual double get_bodymass () const =0
 Body mass of one individual [kg/ind]. More...
 
virtual ForageMass get_forage_demands (const HabitatForage &available_forage)=0
 Get the forage the herbivore would like to eat today. More...
 
virtual std::string get_output_group () const =0
 The name of the HFT for aggregating output. More...
 
virtual double get_ind_per_km2 () const =0
 Individuals per km² More...
 
virtual double get_kg_per_km2 () const =0
 Get herbivore biomass density [kg/km²]. More...
 
virtual const Output::HerbivoreDataget_todays_output () const =0
 Read current output. More...
 
virtual bool is_dead () const =0
 Whether the herbivore object is dead. More...
 
virtual void kill ()=0
 Mark this herbivore as dead (see is_dead()). More...
 
virtual void simulate_day (const int day, const HabitatEnvironment &environment, double &offspring)=0
 Simulate daily events. More...
 

Protected Member Functions

 HerbivoreBase (const int age_days, const double body_condition, std::shared_ptr< const Hft > hft, const Sex sex, const ForageEnergyContent &forage_gross_energy)
 Establishment constructor. More...
 
 HerbivoreBase (std::shared_ptr< const Hft > hft, const Sex sex, const ForageEnergyContent &forage_gross_energy)
 Birth constructor. More...
 
virtual ~HerbivoreBase ()=default
 Virtual destructor, which will be called by derived classes. More...
 
virtual void apply_mortality (const double mortality)=0
 Apply a fractional mortality. More...
 
FatmassEnergyBudgetget_energy_budget ()
 The herbivore’s energy budget object. More...
 
const FatmassEnergyBudgetget_energy_budget () const
 The herbivore’s energy budget object. More...
 
const HabitatEnvironmentget_environment () const
 Current abiotic conditions in the habitat. More...
 
Output::HerbivoreDataget_todays_output ()
 Class-internal read/write access to current output. More...
 
bool constant_members_match (const HerbivoreBase &other) const
 Check whether the constant member variables match those of another object. More...
 

Private Member Functions

void apply_mortality_factors_today ()
 Calculate mortality according to user-selected mortality factors. More...
 
std::shared_ptr< const Hftcheck_hft_pointer (std::shared_ptr< const Hft >)
 Check whether the HFT pointer is NULL and throws an exception. More...
 
ForageEnergyContent get_net_energy_content (Digestibility digestibility) const
 Get forage energy content [MJ/kgDM] using selected net energy model. More...
 
double get_todays_expenditure () const
 Calculate energy expenditure as sum of given expenditure components. More...
 
double get_todays_offspring_proportion () const
 Get the proportional offspring for today using selected model. More...
 

Private Attributes

Constants
const std::shared_ptr< const Hfthft
 
const Sex sex
 
const BreedingSeason breeding_season
 
const ForageEnergyContent forage_gross_energy
 
State Variables
int age_days
 
FatmassEnergyBudget energy_budget
 
HabitatEnvironment environment
 
int today
 
Helper Classes

Body condition over the past x months (only females).

PeriodAverage body_condition_gestation
 
Output::HerbivoreData current_output
 
GetForageDemands get_forage_demands_per_ind
 

Detailed Description

Abstract base class for herbivores.

Calculations are generally performed per individual.

Constructor & Destructor Documentation

◆ HerbivoreBase() [1/2]

HerbivoreBase::HerbivoreBase ( const int  age_days,
const double  body_condition,
std::shared_ptr< const Hft hft,
const Sex  sex,
const ForageEnergyContent forage_gross_energy 
)
protected

Establishment constructor.

Parameters
age_daysage in days
body_conditionInitial fat reserve as fraction of physiological maximum [kg/kg].
hftHerbivore functional type.
sexThe sex of the herbivore.
forage_gross_energyThe (constant) gross energy content for the forage types [MJ/kgDM]. See: Parameters::forage_gross_energy
Exceptions
std::invalid_argumentIf hft==NULL or age_days <= 0 or body_condition not in [0,1].

◆ HerbivoreBase() [2/2]

HerbivoreBase::HerbivoreBase ( std::shared_ptr< const Hft hft,
const Sex  sex,
const ForageEnergyContent forage_gross_energy 
)
protected

Birth constructor.

Herbivores are born with Hft::body_fat_birth.

Parameters
hftHerbivore functional type.
sexThe sex of the herbivore.
forage_gross_energyThe (constant) gross energy content for the forage types [MJ/kgDM]. See: Parameters::forage_gross_energy
Exceptions
std::invalid_argumentIf hft==NULL.

◆ ~HerbivoreBase()

virtual Fauna::HerbivoreBase::~HerbivoreBase ( )
protectedvirtualdefault

Virtual destructor, which will be called by derived classes.

Member Function Documentation

◆ apply_mortality()

virtual void Fauna::HerbivoreBase::apply_mortality ( const double  mortality)
protectedpure virtual

Apply a fractional mortality.

Parameters
mortalityFraction of individual density/count that is dying.
Exceptions
std::invalid_argumentif not 0.0≤mortality≤1.0

Implemented in Fauna::HerbivoreCohort.

◆ apply_mortality_factors_today()

void HerbivoreBase::apply_mortality_factors_today ( )
private

Calculate mortality according to user-selected mortality factors.

Calls apply_mortality(), which is implemented by child classes.

See also
Hft::mortality_factors

◆ check_hft_pointer()

std::shared_ptr< const Hft > HerbivoreBase::check_hft_pointer ( std::shared_ptr< const Hft _hft)
private

Check whether the HFT pointer is NULL and throws an exception.

This helper function is only neededd because an exception for a NULL pointer must be thrown from the constructor. But in the initialization list there are objects that need the HFT for their own constructor. Therefore, the HFT pointer must be checked in a function first, before the HerbivoreBase constructor function body.

Exceptions
std::invalid_argumentIf HFT pointer is NULL.

◆ constant_members_match()

bool Fauna::HerbivoreBase::constant_members_match ( const HerbivoreBase other) const
inlineprotected

Check whether the constant member variables match those of another object.

◆ eat()

void HerbivoreBase::eat ( const ForageMass kg_per_km2,
const Digestibility digestibility,
const ForageMass N_kg_per_km2 
)
virtual

Feed the herbivore dry matter forage.

Parameters
kg_per_km2Dry matter forage mass [kgDM/km²].
N_kg_per_km2Nitrogen in the forage [kgN/km²].
digestibilityProportional forage digestibility.
Exceptions
std::logic_errorIf forage exceeds intake constraints of maximal foraging and digestion.
std::logic_errorIf this herbivore is dead or has no individuals.
std::invalid_argumentIf N_kg_per_km2 is larger than kg_per_km2 for a forage type. The nitrogen mass is only a fraction of dry matter, and there cannot be more then 100% nitrogen in the forage.

Implements Fauna::HerbivoreInterface.

◆ get_age_days()

int Fauna::HerbivoreBase::get_age_days ( ) const
inline

Current age in days.

◆ get_age_years()

double Fauna::HerbivoreBase::get_age_years ( ) const
inline

Current age in years.

◆ get_bodyfat()

double HerbivoreBase::get_bodyfat ( ) const

Proportional body fat in empty body (fat mass/empty body mass).

The current body fraction, $bf$ is given by the current fat mass, $FM$, and the structural mass, $SM$. Structural mass and fat mass together constitute the empty body.

\[
bf = \frac{FM}{SM + FM}
\]

See also
Body Mass and Composition

◆ get_bodymass()

double HerbivoreBase::get_bodymass ( ) const
virtual

Current live weight, including fat, ingesta, blood, etc. [kg/ind].

Current body mass, $BM$, is the sum of the empty body and the non-body parts, like ingesta, blood, etc. The empty body is given by $BM * eb$, where $eb$ is the proportion of empty body mass given by Hft::body_mass_empty.

Since the empty body consists of fat mass, $FM$, and structural mass, $SM$, we can write

\[
BM = SM + FM + BM * (1 - eb)
\]

and simplify that to:

\[
BM = \frac{SM + FM}{eb}
\]

See also
Body Mass and Composition

Implements Fauna::HerbivoreInterface.

◆ get_bodymass_adult()

double HerbivoreBase::get_bodymass_adult ( ) const

Body mass at physical maturity [kg/ind].

Hft::body_mass_female for females and Hft::body_mass_male for males.

◆ get_conductance()

double HerbivoreBase::get_conductance ( ) const

Get full-body conductance [W/°C/ind].

See also
Hft::thermoregulation_conductance
Exceptions
std::logic_errorIf ConductanceModel not implemented.

◆ get_energy_budget() [1/2]

FatmassEnergyBudget & Fauna::HerbivoreBase::get_energy_budget ( )
inlineprotected

The herbivore’s energy budget object.

◆ get_energy_budget() [2/2]

const FatmassEnergyBudget & Fauna::HerbivoreBase::get_energy_budget ( ) const
inlineprotected

The herbivore’s energy budget object.

◆ get_environment()

const HabitatEnvironment & Fauna::HerbivoreBase::get_environment ( ) const
inlineprotected

Current abiotic conditions in the habitat.

Exceptions
std::logic_errorIf simulate_day() hasn’t been called yet to set the HabitatEnvironment object.

◆ get_fatmass()

double HerbivoreBase::get_fatmass ( ) const

Current fat mass (pure lipids) [kg/ind].

See also
Body Mass and Composition

◆ get_forage_demands()

ForageMass HerbivoreBase::get_forage_demands ( const HabitatForage available_forage)
virtual

Get the forage the herbivore would like to eat today.

Call this after simulate_day().

Note
This may be called multiple times a day in order to allow switching to another forage type!
Parameters
available_forageAvailable forage in the habitat [kgDM/km²].
Returns
Dry matter forage per m² that the herbivore would eat without any food competition [kgDM/km²].

Implements Fauna::HerbivoreInterface.

◆ get_hft()

const Hft & Fauna::HerbivoreBase::get_hft ( ) const
inline

The herbivore functional type (HFT).

◆ get_kg_per_km2()

double HerbivoreBase::get_kg_per_km2 ( ) const
virtual

Get herbivore biomass density [kg/km²].

Implements Fauna::HerbivoreInterface.

◆ get_max_fatmass()

double HerbivoreBase::get_max_fatmass ( ) const

Physiological maximum of fat mass [kg/ind].

The maximum fat mass, $FM_{max}$ is given by applying the fraction Hft::body_fat_maximum, $bf_{max}$, to the empty body. The empty body mass is the sum of structural mass, $SM$, and current fat mass, which is in here the maximum $FM_{max}$.

\begin{eqnarray*}
bf_{max}                       &=& \frac{FM_{max}}{SM + FM_{max}} \\
FM_{max}                       &=& SM * bf_{max} + FM_{max} * bf_{max} \\
FM_{max} - FM_{max} * bf_{max} &=& SM * bf_{max} \\
FM_{max} * (1 - bf_{max})      &=& SM * bf_{max} \\
FM_{max}                       &=& \frac{SM * bf_{max}}{1 - bf_{max}}
\end{eqnarray*}

See also
Body Mass and Composition

◆ get_net_energy_content()

ForageEnergyContent HerbivoreBase::get_net_energy_content ( Digestibility  digestibility) const
private

Get forage energy content [MJ/kgDM] using selected net energy model.

Parameters
digestibilityForage digestibility (for ruminants). This will be adjusted with Hft::digestion_digestibility_multiplier for non-ruminants.
Returns
Net energy content in MJ/kgDM.
Exceptions
std::logic_errorIf the net energy model is not implemented.
See also
Hft::digestion_net_energy_model
NetEnergyModel

◆ get_output_group()

std::string HerbivoreBase::get_output_group ( ) const
virtual

The name of the HFT for aggregating output.

Technically, this can be a generic identifier to aggregate output of herbivores. However, herbivores used to be aggregated only by HFT, and so this is assumed to be the HFT name until the output framework is made more flexible.

Implements Fauna::HerbivoreInterface.

◆ get_sex()

Sex Fauna::HerbivoreBase::get_sex ( ) const
inline

The sex of the herbivore.

◆ get_structural_mass()

double HerbivoreBase::get_structural_mass ( ) const

Current mass of body tissue without fat, ingesta, blood, etc. [kg/ind].

This is the body component that an ontogenetic growth curve applies to. The growth curve interpolates between the neonate structural mass and the adult structural mass.

The neonate structural mass, $SM_{birth}$, is derived from the birth weight, $BM_{birth}$ (Hft::body_mass_birth), the body fat at birth, $bf_{birth}$ (Hft::body_fat_birth), and the empty body fraction, $eb$ (Hft::body_mass_empty). The structural mass is the empty body, which is $BM_{birth}*eb$, minus the fractional body fat $bf_{birth}$:

\[
SM_{birth} = BM_{birth} * eb * (1 - bf_{birth})
\]

The adult structural mass, $SM_{ad}$, is calculated in a similar way, only that the body fat fraction for the adult live weight parameter $BM_{ad}$ (Hft::body_mass_female, Hft::body_mass_male) is assumed to be half of the maximum $bf_{max}$ (Hft::body_fat_maximum):

\[
SM_{ad} = BM_{ad} * eb * (1 - \frac{bf_{max}}{2})
\]

See also
Body Mass and Composition

◆ get_today()

int HerbivoreBase::get_today ( ) const

Current day of the year, as set in simulate_day().

Exceptions
std::logic_errorIf current day not yet set by an initial call to simulate_day().

◆ get_todays_expenditure()

double HerbivoreBase::get_todays_expenditure ( ) const
private

Calculate energy expenditure as sum of given expenditure components.

Returns
Today’s energy needs [MJ/ind/day]
See also
Hft::expenditure_components

◆ get_todays_offspring_proportion()

double HerbivoreBase::get_todays_offspring_proportion ( ) const
private

Get the proportional offspring for today using selected model.

Reads Hft::reproduction_model and performs calculations accordingly.

Returns
Number of offspring per individual [ind/ind/day]. Zero if this herbivore is male, or has not yet reached reproductive maturity (Hft::life_history_sexual_maturity).
Exceptions
std::logic_errorIf Hft::reproduction_model is not implemented.

◆ get_todays_output() [1/2]

Output::HerbivoreData & Fauna::HerbivoreBase::get_todays_output ( )
inlineprotected

Class-internal read/write access to current output.

◆ get_todays_output() [2/2]

virtual const Output::HerbivoreData & Fauna::HerbivoreBase::get_todays_output ( ) const
inlinevirtual

Read current output.

Implements Fauna::HerbivoreInterface.

◆ simulate_day()

void HerbivoreBase::simulate_day ( const int  day,
const HabitatEnvironment environment,
double &  offspring 
)
virtual

Simulate daily events.

Call this before get_forage_demands().

Parameters
[in]dayCurrent day of year, 0=Jan. 1st.
[in]environmentCurrent environmental conditions in the habitat.
[out]offspringNumber of newborn today [ind/km²].
Exceptions
std::invalid_argumentIf day not in [0,364].
std::logic_errorIf this herbivore is dead.
  • Set current day.
  • Increase age.
  • Update records.
  • Update maximum fat mass and gain in Fauna::FatmassEnergyBudget.
  • Add new output.
  • Catabolize fat to compensate unmet energy needs.
  • Add energy needs for today.
  • Calculate offspring.
  • Apply mortality factor.

Implements Fauna::HerbivoreInterface.

Member Data Documentation

◆ age_days

int Fauna::HerbivoreBase::age_days
private

◆ body_condition_gestation

PeriodAverage Fauna::HerbivoreBase::body_condition_gestation
private

Body condition is current fat mass / max. fat mass. The record spans the lenght of a potential pregnancy, counting back from current day. This object is empty for male herbivores.

◆ breeding_season

const BreedingSeason Fauna::HerbivoreBase::breeding_season
private

◆ current_output

Output::HerbivoreData Fauna::HerbivoreBase::current_output
private

Body condition is current fat mass / max. fat mass. The record spans the lenght of a potential pregnancy, counting back from current day. This object is empty for male herbivores.

◆ energy_budget

FatmassEnergyBudget Fauna::HerbivoreBase::energy_budget
private

◆ environment

HabitatEnvironment Fauna::HerbivoreBase::environment
private

◆ forage_gross_energy

const ForageEnergyContent Fauna::HerbivoreBase::forage_gross_energy
private

◆ get_forage_demands_per_ind

GetForageDemands Fauna::HerbivoreBase::get_forage_demands_per_ind
private

Body condition is current fat mass / max. fat mass. The record spans the lenght of a potential pregnancy, counting back from current day. This object is empty for male herbivores.

◆ hft

const std::shared_ptr<const Hft> Fauna::HerbivoreBase::hft
private

◆ sex

const Sex Fauna::HerbivoreBase::sex
private

◆ today

int Fauna::HerbivoreBase::today
private

The documentation for this class was generated from the following files: