|
Modular Megafauna Model 1.1.5
A physiological, dynamic herbivore simulator in C++.
|
Central class to construct and own megafauna habitats and populations. More...
#include <world.h>
Classes | |
| struct | InsfileContent |
| All simulation instructions from the TOML instruction file. More... | |
| struct | SimDayOptions |
| Options passed to simulate_day() More... | |
Public Member Functions | |
| World (const std::string instruction_filename, const SimMode mode=SimMode::Simulate) | |
| Constructor: Read parameters and HFTs from instruction file. More... | |
| World (const std::shared_ptr< const Parameters > params, const std::shared_ptr< const HftList > hftlist) | |
| Constructor for unit tests. More... | |
| World () | |
Constructor: Create deactivated World object. More... | |
| ~World () | |
| Default destructor. More... | |
| void | create_simulation_unit (std::shared_ptr< Habitat > habitat) |
| Compose a new simulation from an external habitat and new populations. More... | |
| const Parameters & | get_params () const |
| Get global simulation parameters. More... | |
| const std::list< SimulationUnit > & | get_sim_units () const |
| List of all the simulation units in the world. More... | |
| const bool | is_activated () const |
| Whether this World object is in SimMode::Simulate mode. More... | |
| void | simulate_day (const Date &date, const SimDayOptions &opts=SimDayOptions()) |
| Iterate through all simulation units and perform simulation for this day. More... | |
| void | simulate_day (const Date &date, const bool do_herbivores) |
| Iterate through all simulation units and perform simulation for this day. More... | |
Private Member Functions | |
| int | get_habitat_count_per_agg_unit () const |
| Get the number of habitats per aggregation unit. More... | |
| const HftList & | get_hfts () const |
| Get the immutable list of herbivore functional types. More... | |
| Output::WriterInterface * | construct_output_writer () const |
| Create Output::WriterInterface implementation according to params. More... | |
Static Private Member Functions | |
| static InsfileContent | read_instruction_file (const std::string &filename) |
| Helper function to initialize World::InsfileContent object. More... | |
Private Attributes | |
| const SimMode | mode = SimMode::Simulate |
| Whether this object is going to simulate or just lint an instruction file. More... | |
| bool | simulation_units_checked = false |
| Whether the habitat counts per aggregation unit have been checked. More... | |
| struct Fauna::World::InsfileContent | insfile |
| int | days_since_last_establishment |
| Number of days since extinct populations were re-established. More... | |
| std::unique_ptr< Fauna::Date > | last_date |
| The date from the last call to simulate_day() More... | |
| const std::unique_ptr< Output::Aggregator > | output_aggregator |
| Collects output data per time interval and aggregation unit. More... | |
| std::unique_ptr< Output::WriterInterface > | output_writer |
| Output writer as selected by Parameters::output_format. More... | |
| std::list< SimulationUnit > | sim_units |
| List of all the simulation units in the world. More... | |
| const std::unique_ptr< WorldConstructor > | world_constructor |
| Helper class to construct various elements of the megafauna world. More... | |
Central class to construct and own megafauna habitats and populations.
| World::World | ( | const std::string | instruction_filename, |
| const SimMode | mode = SimMode::Simulate |
||
| ) |
Constructor: Read parameters and HFTs from instruction file.
| instruction_filename | Path to the instruction file for the megafauna model. It contains global settings and herbivore parameters. |
| mode | Whether we are only checking the instruction file or running a simulation. If set to SimMode::Lint, no files will be created. |
| std::logic_error | If a selected instruction file parameter is not implemented. |
| World::World | ( | const std::shared_ptr< const Parameters > | params, |
| const std::shared_ptr< const HftList > | hftlist | ||
| ) |
Constructor for unit tests.
| params | Global simulation parameters that would normally be parsed from the instruction file. |
| hftlist | HFT parameters that would normally be parsed from the instruction file. |
| std::invalid_argument | If either of the shared pointers is NULL. |
| World::World | ( | ) |
Constructor: Create deactivated World object.
Even if the megafauna model should be completely deactivated, there might be a need to create a "dummy" World instance. An object created with this constructor will not simulate anything.
std::shared_ptr<Fauna::World> and leave the pointer NULL if you don’t need it.
|
default |
Default destructor.
|
private |
Create Output::WriterInterface implementation according to params.
| std::logic_error | If Parameters::output_format is not implemented. |
| void World::create_simulation_unit | ( | std::shared_ptr< Habitat > | habitat | ) |
Compose a new simulation from an external habitat and new populations.
The new simulation unit will be owned by World and released as soon as the Habitat instance is marked as to be deleted from extern.
If the World class was constructed without an instruction file, this function will do nothing, but will still throw an error if the parameter is NULL.
| habitat | Pointer to an instance of a class that implements Habitat, given externally by the vegetation model. The World object will release it after it has been marked as dead (Habitat::kill()) externally. |
| std::invalid_argument | If habitat is NULL. |
|
private |
Get the number of habitats per aggregation unit.
| std::logic_error | If the number of habitats differs between aggregation units. |
|
private |
Get the immutable list of herbivore functional types.
| const Parameters & World::get_params | ( | ) | const |
Get global simulation parameters.
The global megafauna parameters are public because they might be required by the calling vegetation model to check back against vegetation-specific settings.
| std::logic_error | If the member variable hasn’t been set (if the World class was created without an instruction file). |
|
inline |
List of all the simulation units in the world.
This is read-only. Unit tests can use it to check if create_simulation_unit() works.
|
inline |
Whether this World object is in SimMode::Simulate mode.
|
staticprivate |
Helper function to initialize World::InsfileContent object.
|
inline |
Iterate through all simulation units and perform simulation for this day.
| date | The current simulation day. |
| do_herbivores | see SimDayOptions::do_herbivores |
| void World::simulate_day | ( | const Date & | date, |
| const SimDayOptions & | opts = SimDayOptions() |
||
| ) |
Iterate through all simulation units and perform simulation for this day.
This is the central access point to start the perform the herbivore simulations.
If a Habitat instance is marked as dead (Habitat::is_dead()), the corresponding simulation unit will be released from memory.
If the World class was constructed without parameters, this function will do nothing.
| date | The current simulation day. |
| opts | Options for today’s simulation. |
| std::invalid_argument | If date has not been correctly incremented by one day since the last call. However, no exception will be thrown if SimDayOptions::reset_date is true. |
| logic_error | If Parameters::one_hft_per_habitat, but for at least one aggregation unit (Habitat::get_aggregation_unit()) the number of associated habitats is not an integer multiple of the number of HFTs. |
| logic_error | If the aggregation units (Habitat::get_aggregation_unit()) created with create_simulation_unit() do not all have the same number of habitats each. It would bias the output if the means for each aggregation unit would have different “sample counts.” |
|
private |
Number of days since extinct populations were re-established.
|
private |
|
private |
The date from the last call to simulate_day()
This is to check that the simulation days are coming in correctly from the vegetation/host model.
|
private |
Whether this object is going to simulate or just lint an instruction file.
|
private |
Collects output data per time interval and aggregation unit.
|
private |
Output writer as selected by Parameters::output_format.
|
private |
List of all the simulation units in the world.
All objects are owned by World.
|
private |
Whether the habitat counts per aggregation unit have been checked.
By setting this variable, we don’t need to check on every call of simulate_day(), which might save some calculations. Instead, habitat counts are only checked when they have changed through create_simulation_unit().
|
private |
Helper class to construct various elements of the megafauna world.