Utopia  2
Framework for studying models of complex & adaptive systems.
Public Types | Public Member Functions | Private Member Functions | Private Attributes | List of all members
Utopia::Models::SandPile::SandPile Class Reference

The SandPile Model. More...

#include <SandPile.hh>

Inheritance diagram for Utopia::Models::SandPile::SandPile:
Inheritance graph
[legend]
Collaboration diagram for Utopia::Models::SandPile::SandPile:
Collaboration graph
[legend]

Public Types

using Base = Model< SandPile, SandPileTypes >
 The base model's type. More...
 
using CellManager = Utopia::CellManager< CellTraits, SandPile >
 The type of the cell manager. More...
 
using Cell = typename CellManager::Cell
 Cell type. More...
 
using CellContainer = std::vector< std::shared_ptr< Cell > >
 Cell container type. More...
 
using RuleFunc = typename CellManager::RuleFunc
 Supply a type for rule functions that are applied to cells. More...
 
using DataSet = typename Base::DataSet
 Data type for a dataset. More...
 
using UniformIntDist = typename std::uniform_int_distribution< std::size_t >
 The uniform integer distribution type to use. More...
 
- Public Types inherited from Utopia::Model< SandPile, SandPileTypes >
using Config = typename ModelTypes::Config
 Data type that holds the configuration. More...
 
using DataManager = DataIO::Default::DefaultDataManager< SandPile >
 The data manager to use, specialized with the derived model. More...
 
using DataGroup = typename ModelTypes::DataGroup
 Data type that is used for storing datasets. More...
 
using DataSet = typename ModelTypes::DataSet
 Data type that is used for storing data. More...
 
using RNG = typename ModelTypes::RNG
 Data type of the shared RNG. More...
 
using Space = typename ModelTypes::Space
 Data type of the space this model resides in. More...
 
using Time = typename ModelTypes::Time
 Data type for the model time. More...
 
using Monitor = typename ModelTypes::Monitor
 Data type for the monitor. More...
 
using MonitorManager = typename ModelTypes::MonitorManager
 Data type for the monitor manager. More...
 
using Level = typename ModelTypes::Level
 Data type for the hierarchical level. More...
 

Public Member Functions

template<class ParentModel >
 SandPile (const std::string &name, ParentModel &parent_model, const DataIO::Config &custom_cfg={})
 Construct the SandPile model. More...
 
void perform_step ()
 Perform an iteration step. More...
 
void monitor ()
 Supply monitor information to the frontend. More...
 
void write_data ()
 Write the cell slope and avalanche flag to the datasets. More...
 
- Public Member Functions inherited from Utopia::Model< SandPile, SandPileTypes >
 Model (const std::string &name, const ParentModel &parent_model, const Config &custom_cfg={}, std::tuple< WriterArgs... > w_args={}, const DataIO::Default::DefaultDecidermap< SandPile > &w_deciders=DataIO::Default::default_deciders< SandPile >, const DataIO::Default::DefaultTriggermap< SandPile > &w_triggers=DataIO::Default::default_triggers< SandPile >)
 Constructs a Model instance. More...
 
const std::shared_ptr< Space > & get_space () const
 Return the space this model resides in. More...
 
Time get_time () const
 Return the current time of this model. More...
 
Time get_time_max () const
 Return the maximum time possible for this model. More...
 
Config get_cfg () const
 Return the config node of this model. More...
 
std::string get_name () const
 Return the name of this model instance. More...
 
std::string get_full_name () const
 Return the full name of this model within the model hierarchy. More...
 
std::shared_ptr< DataGroupget_hdfgrp () const
 Return a pointer to the HDF group this model stores data in. More...
 
Time get_write_start () const
 Return the parameter that controls when write_data is called first. More...
 
Time get_write_every () const
 Return the parameter that controls how often write_data is called. More...
 
DataManager get_datamanager () const
 return the datamanager More...
 
hsize_t get_remaining_num_writes () const
 Return the number of remaining write_data calls this model will make. More...
 
std::shared_ptr< RNGget_rng () const
 Return a pointer to the shared RNG. More...
 
std::shared_ptr< spdlog::logger > get_logger () const
 Return a pointer to the logger of this model. More...
 
Monitor get_monitor () const
 Return the monitor of this model. More...
 
std::shared_ptr< MonitorManagerget_monitor_manager () const
 Get the monitor manager of the root model. More...
 
Level get_level () const
 Return the hierarchical level within the model hierarchy. More...
 
virtual void prolog ()
 A function that is called before starting model iteration. More...
 
virtual void epilog ()
 A function that is called after the last iteration of a model. More...
 
void iterate ()
 Iterate one (time) step of this model. More...
 
void run ()
 Run the model from the current time to the maximum time. More...
 
std::shared_ptr< DataSetcreate_dset (const std::string name, const std::shared_ptr< DataGroup > &hdfgrp, std::vector< hsize_t > add_write_shape, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={})
 Create a new dataset within the given group. More...
 
std::shared_ptr< DataSetcreate_dset (const std::string name, const std::vector< hsize_t > add_write_shape, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={})
 Create a new dataset within the model's base data group. More...
 
std::shared_ptr< DataSetcreate_cm_dset (const std::string name, const CellManager &cm, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={})
 Create a dataset storing data from a CellManager. More...
 
std::shared_ptr< DataSetcreate_am_dset (const std::string name, const AgentManager &am, const std::size_t compression_level=1, const std::vector< hsize_t > chunksize={})
 Create a dataset storing data from a AgentManager. More...
 

Private Member Functions

unsigned int avalanche_size () const
 Calculate the avalanche size. More...
 
const std::shared_ptr< Cell > & add_sand_grain ()
 Select a random cell, add a grain of sand to it, and return it. More...
 
void topple (const std::shared_ptr< Cell > &first_cell)
 Topple cells if the critical slope is exceeded. More...
 

Private Attributes

CellManager _cm
 The grid manager. More...
 
const Slope _critical_slope
 The critical slope of the cells. More...
 
const unsigned int _topple_num_grains
 The number of grains that topple; depends on the neighborhood size. More...
 
const bool _write_only_avalanche_size
 If true, will only store the avalanche size, not the spatial data. More...
 
UniformIntDist _cell_distr
 A distribution to select a random cell. More...
 
const std::shared_ptr< DataSet_dset_slope
 Dataset to store the slopes of all cells for all time steps. More...
 
const std::shared_ptr< DataSet_dset_avalanche
 Dataset to store the avalanche state of all cells for all time steps. More...
 
const std::shared_ptr< DataSet_dset_avalanche_size
 Dataset to store the avalanche size for each time step. More...
 
RuleFunc _reset
 Resets cells for the next iteration. More...
 

Additional Inherited Members

- Protected Member Functions inherited from Utopia::Model< SandPile, SandPileTypes >
void __perform_step ()
 Perform the computation of a step. More...
 
void __monitor ()
 Monitor information in the terminal. More...
 
void __write_data ()
 Write data; calls the implementation's write_data method. More...
 
void __write_initial_state ()
 Write the initial state. More...
 
void increment_time (const Time dt=1)
 Increment time. More...
 
void __prolog ()
 The default prolog of a model. More...
 
void __epilog ()
 The default epilog of a model. More...
 
SandPile & impl ()
 cast to the derived class More...
 
const SandPile & impl () const
 const cast to the derived interface More...
 
- Protected Attributes inherited from Utopia::Model< SandPile, SandPileTypes >
const std::string _name
 Name of the model instance. More...
 
const std::string _full_name
 The full name within the model hierarchy. More...
 
const Level _level
 The level within the model hierarchy. More...
 
const Config _cfg
 Config node belonging to this model instance. More...
 
const std::shared_ptr< RNG_rng
 The RNG shared between models. More...
 
const std::shared_ptr< spdlog::logger > _log
 The (model) logger. More...
 
std::shared_ptr< Space_space
 The space this model resides in. More...
 
Time _time
 Model-internal current time stamp. More...
 
const Time _time_max
 Model-internal maximum time stamp. More...
 
const std::shared_ptr< DataGroup_hdfgrp
 The HDF group this model instance should write its data to. More...
 
const Time _write_start
 First time at which write_data is called. More...
 
const Time _write_every
 How often to call write_data from iterate. More...
 
Monitor _monitor
 The monitor. More...
 
DataManager _datamanager
 Manager object for handling data output; see DataManager. More...
 
- Static Protected Attributes inherited from Utopia::Model< SandPile, SandPileTypes >
static constexpr WriteMode _write_mode
 Which data-writing mode the base model should use. More...
 

Detailed Description

The SandPile Model.

The SandPile model simulates a sand pile under the influence of new grains of sand that get added every iteration. The sand reaches a critical state _critical_slope, after which it collapses, passing sand on to the neighboring cells

Member Typedef Documentation

◆ Base

The base model's type.

◆ Cell

Cell type.

◆ CellContainer

using Utopia::Models::SandPile::SandPile::CellContainer = std::vector<std::shared_ptr<Cell> >

Cell container type.

◆ CellManager

The type of the cell manager.

◆ DataSet

Data type for a dataset.

◆ RuleFunc

Supply a type for rule functions that are applied to cells.

◆ UniformIntDist

using Utopia::Models::SandPile::SandPile::UniformIntDist = typename std::uniform_int_distribution<std::size_t>

The uniform integer distribution type to use.

Constructor & Destructor Documentation

◆ SandPile()

template<class ParentModel >
Utopia::Models::SandPile::SandPile::SandPile ( const std::string &  name,
ParentModel &  parent_model,
const DataIO::Config custom_cfg = {} 
)
inline

Construct the SandPile model.

Parameters
nameName of this model instance; is used to extract the configuration from the parent model and set up a HDFGroup for this instance
parent_modelThe parent model this model instance resides in
custom_cfgA custom configuration to use instead of the one extracted from the parent model using the instance name

Member Function Documentation

◆ add_sand_grain()

const std::shared_ptr<Cell>& Utopia::Models::SandPile::SandPile::add_sand_grain ( )
inlineprivate

Select a random cell, add a grain of sand to it, and return it.

◆ avalanche_size()

unsigned int Utopia::Models::SandPile::SandPile::avalanche_size ( ) const
inlineprivate

Calculate the avalanche size.

Counts all cells that are marked as in_avalanche.

◆ monitor()

void Utopia::Models::SandPile::SandPile::monitor ( )
inline

Supply monitor information to the frontend.

Provides 'avalanche_size' at the current time step

◆ perform_step()

void Utopia::Models::SandPile::SandPile::perform_step ( )
inline

Perform an iteration step.

◆ topple()

void Utopia::Models::SandPile::SandPile::topple ( const std::shared_ptr< Cell > &  first_cell)
inlineprivate

Topple cells if the critical slope is exceeded.

Starting from the first_cell, every time a cell topples the neighbors are also checked whether they need to topple. This is implemented by adding them into a queue and toppling until the queue is empty.

Parameters
first_cellThe first cell from which the topple avalanche starts

◆ write_data()

void Utopia::Models::SandPile::SandPile::write_data ( )
inline

Write the cell slope and avalanche flag to the datasets.

Member Data Documentation

◆ _cell_distr

UniformIntDist Utopia::Models::SandPile::SandPile::_cell_distr
private

A distribution to select a random cell.

◆ _cm

CellManager Utopia::Models::SandPile::SandPile::_cm
private

The grid manager.

◆ _critical_slope

const Slope Utopia::Models::SandPile::SandPile::_critical_slope
private

The critical slope of the cells.

◆ _dset_avalanche

const std::shared_ptr<DataSet> Utopia::Models::SandPile::SandPile::_dset_avalanche
private

Dataset to store the avalanche state of all cells for all time steps.

◆ _dset_avalanche_size

const std::shared_ptr<DataSet> Utopia::Models::SandPile::SandPile::_dset_avalanche_size
private

Dataset to store the avalanche size for each time step.

◆ _dset_slope

const std::shared_ptr<DataSet> Utopia::Models::SandPile::SandPile::_dset_slope
private

Dataset to store the slopes of all cells for all time steps.

◆ _reset

RuleFunc Utopia::Models::SandPile::SandPile::_reset
private
Initial value:
= [](const auto& cell){
cell->state.in_avalanche = false;
return cell->state;
}

Resets cells for the next iteration.

Marks cell as untouched by the avalanche and updates the slope to the cached future slope

◆ _topple_num_grains

const unsigned int Utopia::Models::SandPile::SandPile::_topple_num_grains
private

The number of grains that topple; depends on the neighborhood size.

◆ _write_only_avalanche_size

const bool Utopia::Models::SandPile::SandPile::_write_only_avalanche_size
private

If true, will only store the avalanche size, not the spatial data.


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