1#ifndef GEOMORPHOLOGY_HH
2#define GEOMORPHOLOGY_HH
43 const std::shared_ptr<RNG>& rng)
72 public Model<Geomorphology, GeomorphologyTypes>
160 template<
class ParentModel>
162 const std::string& name,
191 throw std::invalid_argument(
"Invalid argument: uplift_var must be "
192 "> _float_precision (1e-10)!");
198 this->
_log->debug(
"{} model fully set up.", this->
_name);
248 [](
const auto&
cell) { return cell->state.rock; }
252 [](
const auto&
cell) { return cell->state.drainage_area; }
256 [](
const auto&
cell) { return cell->state.watercolumn; }
268 template <
typename Cell>
270 return check_eq(
a->state.waterline(),
b->state.waterline());
282 this->
_log->debug(
"Initializing cells ..");
287 auto state =
cell->state;
290 this->
_cfg[
"cell_manager"][
"cell_params"]);
291 state.rock += slope*
pos[1];
293 std::uniform_real_distribution<>
dist(0.,1
e-5);
295 this->
_log->warn(
"Received negative initial height. Was set "
296 "in [0.,1e-5]. Better chose the initial_height "
297 "distribution such that no negative values occur.");
306 [](
const auto&
cell){
307 auto state =
cell->state;
308 state.is_outflow =
true;
316 this->
_log->debug(
" Initializing drainage network ...");
319 this->
_log->debug(
"Cells fully set up.");
326 template <
typename Cell>
406 auto state =
cell->state;
413 auto state =
cell->state;
415 double slope = state.waterline();
416 if (
not state.is_outflow) {
423 * std::sqrt(state.drainage_area));
437 auto state =
cell->state;
454 - state.waterline());
467 auto state =
cell->state;
468 state.drainage_area = 1.;
469 state.was_drained =
false;
470 state.watercolumn = 0.;
479 if (
cell->state.is_outflow) {
509 double waterline =
lake[0]->state.waterline();
513 for (
const auto&
lc :
lake) {
514 if (
lc->state.is_outflow) {
535 lc->state.watercolumn = waterline -
lc->state.rock;
541 for (
const auto&
lc :
lake) {
542 if (
lc->state.is_outflow) {
551 if (
sc->state.waterline() <
561 for (
const auto&
lc :
lake) {
562 if (
lc->state.is_outflow) {
572 if (
not check_eq((*it_nb)->state.waterline(), waterline)) {
575 else if (
lake.end() == std::find(
lake.begin(),
lake.end(),
583 if (
nbs.size() > 1) {
584 std::uniform_int_distribution<>
dist(0,
nbs.size() - 1);
590 for (
const auto&
lc :
lake) {
591 if (
lc->state.is_outflow) {
592 _lowest_neighbors[
lc->id()] =
lc;
612 auto state =
cell->state;
613 state.was_drained =
true;
616 throw std::runtime_error(
"No recipient assigned to a cell!");
619 if (state.is_outflow) {
635 throw std::runtime_error(
"Drainage network has loop!");
A cell is a slightly specialized state container.
Definition cell.hh:40
typename std::function< CellState(const std::shared_ptr< Cell > &)> RuleFunc
The type of a rule function acting on cells of this cell manager.
Definition cell_manager.hh:84
SpaceVec barycenter_of(const Cell &cell) const
Returns the barycenter of the given cell.
Definition cell_manager.hh:249
CellContainer< Cell > boundary_cells(const std::string &select="all") const
Retrieve a container of cells that are at a specified boundary.
Definition cell_manager.hh:323
CellContainer< Cell > neighbors_of(const Cell &cell) const
Retrieve the given cell's neighbors.
Definition cell_manager.hh:458
const CellContainer< Cell > & cells() const
Return const reference to the managed CA cells.
Definition cell_manager.hh:219
Utopia::Cell< CellTraits > Cell
Type of the managed cells.
Definition cell_manager.hh:47
Base class interface for Models using the CRT Pattern.
Definition model.hh:112
std::shared_ptr< DataSet > create_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.
Definition model.hh:849
typename ModelTypes::DataSet DataSet
Data type that is used for storing data.
Definition model.hh:125
const Config _cfg
Config node belonging to this model instance.
Definition model.hh:158
const std::string _name
Name of the model instance.
Definition model.hh:149
const std::shared_ptr< spdlog::logger > _log
The (model) logger.
Definition model.hh:164
const std::shared_ptr< RNG > _rng
The RNG shared between models.
Definition model.hh:161
A very simple geomorphology model.
Definition Geomorphology.hh:73
RuleFunc toppling
The rule how to topple / landslide.
Definition Geomorphology.hh:436
double _toppling_critical_height
The critical height difference to trigget a toppling event.
Definition Geomorphology.hh:121
bool check_eq_waterline(const Cell &a, const Cell &b)
Compare the waterline of two cells.
Definition Geomorphology.hh:269
double _stream_power_coef
The stream power coefficient.
Definition Geomorphology.hh:111
void monitor()
Provide monitoring data: tree density and number of clusters.
Definition Geomorphology.hh:239
RuleFunc uplift_rule
The rule how to uplift.
Definition Geomorphology.hh:405
void write_data()
Write the cell states (aka water content)
Definition Geomorphology.hh:246
typename GeomorphologyCellManager::RuleFunc RuleFunc
Rule function type, extracted from CellManager.
Definition Geomorphology.hh:94
GmorphCellContainer update_lakesites(GmorphCellContainer &lake, GmorphCellContainer &shore)
Update the CellContainer of lake and shore cells.
Definition Geomorphology.hh:364
void perform_step()
Perform step.
Definition Geomorphology.hh:223
RuleFunc erode
The rule how to erode with stream power.
Definition Geomorphology.hh:412
std::normal_distribution _uplift
The random uplift as normal distribution.
Definition Geomorphology.hh:108
RuleFunc build_lake
Fill a sink with water.
Definition Geomorphology.hh:499
std::shared_ptr< DataSet > _dset_watercolumn
Dataset of drainage area.
Definition Geomorphology.hh:146
typename Base::DataSet DataSet
Data type for a dataset.
Definition Geomorphology.hh:79
std::shared_ptr< DataSet > _dset_drainage_area
Dataset of rock height.
Definition Geomorphology.hh:145
GeomorphologyCellManager::Cell GeomorphologyCellType
A cell in the geomorphology model.
Definition Geomorphology.hh:85
RuleFunc reset_network
The rule to reset the drainage network.
Definition Geomorphology.hh:466
double _toppling_slope_reduction_factor
The factor by which to reduce the slope in a toppling event.
Definition Geomorphology.hh:131
Utopia::IndexType GeomorphologyCellIndexType
The index type of the Geomorphology cell manager.
Definition Geomorphology.hh:88
void build_network()
The set of seperately applied rules to build the drainage network.
Definition Geomorphology.hh:207
double _toppling_frequency
The frequency of possible toppling events per cell.
Definition Geomorphology.hh:114
std::uniform_real_distribution _prob_dist
precision when comparing floats
Definition Geomorphology.hh:141
Geomorphology(const std::string &name, ParentModel &parent_model, const DataIO::Config &custom_cfg={})
Dataset of watercolumn.
Definition Geomorphology.hh:161
void _initialize_cells()
The initialization of the cells.
Definition Geomorphology.hh:281
std::shared_ptr< DataSet > _dset_height
Definition Geomorphology.hh:144
RuleFunc pass_drainage_area
Make a drainage process from this cell.
Definition Geomorphology.hh:611
const double _float_precision
Definition Geomorphology.hh:138
Cell _lowest_grid_neighbor(const Cell &cell)
Return the lowest cell of the grid-Neighborhood, including cell itself.
Definition Geomorphology.hh:327
Utopia::CellContainer< GeomorphologyCellType > GmorphCellContainer
The type of a cell container in the Geomorphology model.
Definition Geomorphology.hh:91
GeomorphologyCellManager _cm
The cell manager for the forest fire model.
Definition Geomorphology.hh:102
RuleFunc connect_cells
Build a rudimentary network.
Definition Geomorphology.hh:478
bool check_eq(const double &a, const double &b)
Compare two floats for equality.
Definition Geomorphology.hh:263
std::unordered_map< GeomorphologyCellIndexType, std::shared_ptr< GeomorphologyCellType > > _lowest_neighbors
Definition Geomorphology.hh:135
Model< Geomorphology, GeomorphologyTypes > Base
The base model type.
Definition Geomorphology.hh:76
YAML::Node Config
Type of a variadic dictionary-like data structure used throughout Utopia.
Definition types.hh:71
ReturnType get_as(const std::string &key, const DataIO::Config &node)
This function is a wrapper around the yaml-cpp YAML::Node::as function.
Definition cfg_utils.hh:158
Container select_entities(const Manager &mngr, const DataIO::Config &sel_cfg)
Select entities according to parameters specified in a configuration.
Definition select.hh:213
EntityContainer< CellType > CellContainer
Type of the variably sized container for cells.
Definition types.hh:26
std::size_t IndexType
Type for indices, i.e. values used for container indexing, agent IDs, ...
Definition types.hh:40
The entity traits struct gathers types to be used for specializing an entity.
Definition entity.hh:49
Wrapper struct for defining model class data types.
Definition model.hh:92
The full cell struct for the Geomorphology model.
Definition Geomorphology.hh:17
bool was_drained
Was called for drainage area calculation.
Definition Geomorphology.hh:31
double rock
The cells topgraphic height.
Definition Geomorphology.hh:19
double watercolumn
The cells watercontent.
Definition Geomorphology.hh:22
bool is_outflow
Whether the cell is an outflow boundary cell.
Definition Geomorphology.hh:34
double drainage_area
The drainage area.
Definition Geomorphology.hh:28
GeomorphologyCell(const DataIO::Config &cfg, const std::shared_ptr< RNG > &rng)
Construct a cell from a configuration node and an RNG.
Definition Geomorphology.hh:42
double waterline() const
The height of the waterline.
Definition Geomorphology.hh:25