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

A very simple geomorphology model. More...

#include <Geomorphology.hh>

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

Public Types

using Base = Model< Geomorphology, GeomorphologyTypes >
 The base model type.
 
using DataSet = typename Base::DataSet
 Data type for a dataset.
 
using GeomorphologyCellManager = CellManager< CellTraits, Geomorphology >
 The type of the cell manager.
 
using GeomorphologyCellType = GeomorphologyCellManager::Cell
 A cell in the geomorphology model.
 
using GeomorphologyCellIndexType = Utopia::IndexType
 The index type of the Geomorphology cell manager.
 
using GmorphCellContainer = Utopia::CellContainer< GeomorphologyCellType >
 The type of a cell container in the Geomorphology model.
 
using RuleFunc = typename GeomorphologyCellManager::RuleFunc
 Rule function type, extracted from CellManager.
 
- Public Types inherited from Utopia::Model< Geomorphology, GeomorphologyTypes >
using Config = typename ModelTypes::Config
 Data type that holds the configuration.
 
using DataManager = DataIO::Default::DefaultDataManager< Geomorphology >
 The data manager to use, specialized with the derived model.
 
using DataGroup = typename ModelTypes::DataGroup
 Data type that is used for storing datasets.
 
using DataSet = typename ModelTypes::DataSet
 Data type that is used for storing data.
 
using RNG = typename ModelTypes::RNG
 Data type of the shared RNG.
 
using Space = typename ModelTypes::Space
 Data type of the space this model resides in.
 
using Time = typename ModelTypes::Time
 Data type for the model time.
 
using Monitor = typename ModelTypes::Monitor
 Data type for the monitor.
 
using MonitorManager = typename ModelTypes::MonitorManager
 Data type for the monitor manager.
 
using Level = typename ModelTypes::Level
 Data type for the hierarchical level.
 

Public Member Functions

template<class ParentModel >
 Geomorphology (const std::string &name, ParentModel &parent_model, const DataIO::Config &custom_cfg={})
 Dataset of watercolumn.
 
void build_network ()
 The set of seperately applied rules to build the drainage network.
 
void perform_step ()
 Perform step.
 
void monitor ()
 Provide monitoring data: tree density and number of clusters.
 
void write_data ()
 Write the cell states (aka water content)
 
- Public Member Functions inherited from Utopia::Model< Geomorphology, GeomorphologyTypes >
 Model (const std::string &name, const ParentModel &parent_model, const Config &custom_cfg={}, std::tuple< WriterArgs... > w_args={}, const DataIO::Default::DefaultDecidermap< Geomorphology > &w_deciders=DataIO::Default::default_deciders< Geomorphology >, const DataIO::Default::DefaultTriggermap< Geomorphology > &w_triggers=DataIO::Default::default_triggers< Geomorphology >)
 Constructs a Model instance.
 
const std::shared_ptr< Space > & get_space () const
 Return the space this model resides in.
 
Time get_time () const
 Return the current time of this model.
 
Time get_time_max () const
 Return the maximum time possible for this model.
 
Config get_cfg () const
 Return the config node of this model.
 
std::string get_name () const
 Return the name of this model instance.
 
std::string get_full_name () const
 Return the full name of this model within the model hierarchy.
 
std::shared_ptr< DataGroupget_hdfgrp () const
 Return a pointer to the HDF group this model stores data in.
 
Time get_write_start () const
 Return the parameter that controls when write_data is called first.
 
Time get_write_every () const
 Return the parameter that controls how often write_data is called.
 
DataManager get_datamanager () const
 return the datamanager
 
hsize_t get_remaining_num_writes () const
 Return the number of remaining write_data calls this model will make.
 
std::shared_ptr< RNGget_rng () const
 Return a pointer to the shared RNG.
 
std::shared_ptr< spdlog::logger > get_logger () const
 Return a pointer to the logger of this model.
 
Monitor get_monitor () const
 Return the monitor of this model.
 
std::shared_ptr< MonitorManagerget_monitor_manager () const
 Get the monitor manager of the root model.
 
Level get_level () const
 Return the hierarchical level within the model hierarchy.
 
virtual void prolog ()
 A function that is called before starting model iteration.
 
virtual void epilog ()
 A function that is called after the last iteration of a model.
 
void iterate ()
 Iterate one (time) step of this model.
 
void run ()
 Run the model from the current time to the maximum time.
 
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.
 
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.
 
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.
 
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.
 

Private Member Functions

bool check_eq (const double &a, const double &b)
 Compare two floats for equality.
 
template<typename Cell >
bool check_eq_waterline (const Cell &a, const Cell &b)
 Compare the waterline of two cells.
 
void _initialize_cells ()
 The initialization of the cells.
 
template<typename Cell >
Cell _lowest_grid_neighbor (const Cell &cell)
 Return the lowest cell of the grid-Neighborhood, including cell itself.
 
GmorphCellContainer update_lakesites (GmorphCellContainer &lake, GmorphCellContainer &shore)
 Update the CellContainer of lake and shore cells.
 

Private Attributes

GeomorphologyCellManager _cm
 The cell manager for the forest fire model.
 
std::normal_distribution _uplift
 The random uplift as normal distribution.
 
double _stream_power_coef
 The stream power coefficient.
 
double _toppling_frequency
 The frequency of possible toppling events per cell.
 
double _toppling_critical_height
 The critical height difference to trigget a toppling event.
 
double _toppling_slope_reduction_factor
 The factor by which to reduce the slope in a toppling event.
 
std::unordered_map< GeomorphologyCellIndexType, std::shared_ptr< GeomorphologyCellType > > _lowest_neighbors
 
const double _float_precision
 
std::uniform_real_distribution _prob_dist
 precision when comparing floats
 
std::shared_ptr< DataSet_dset_height
 
std::shared_ptr< DataSet_dset_drainage_area
 Dataset of rock height.
 
std::shared_ptr< DataSet_dset_watercolumn
 Dataset of drainage area.
 
RuleFunc uplift_rule
 The rule how to uplift.
 
RuleFunc erode
 The rule how to erode with stream power.
 
RuleFunc toppling
 The rule how to topple / landslide.
 
RuleFunc reset_network
 The rule to reset the drainage network.
 
RuleFunc connect_cells
 Build a rudimentary network.
 
RuleFunc build_lake
 Fill a sink with water.
 
RuleFunc pass_drainage_area
 Make a drainage process from this cell.
 

Additional Inherited Members

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

Detailed Description

A very simple geomorphology model.

Member Typedef Documentation

◆ Base

The base model type.

◆ DataSet

Data type for a dataset.

◆ GeomorphologyCellIndexType

The index type of the Geomorphology cell manager.

◆ GeomorphologyCellManager

The type of the cell manager.

◆ GeomorphologyCellType

A cell in the geomorphology model.

◆ GmorphCellContainer

The type of a cell container in the Geomorphology model.

◆ RuleFunc

Rule function type, extracted from CellManager.

Constructor & Destructor Documentation

◆ Geomorphology()

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

Dataset of watercolumn.

Construct the Geomorphology 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
164 {}
165 )
166 :
167 // Construct the base class
169
170 // Initialize the cell manager, binding it to this model
171 _cm(*this),
172
173 _uplift{get_as<double>("uplift_mean", this->_cfg),
174 get_as<double>("uplift_var", this->_cfg)},
175 _stream_power_coef(get_as<double>("stream_power_coef", this->_cfg)),
176 _toppling_frequency(get_as<double>("toppling_frequency", this->_cfg)),
177 _toppling_critical_height(get_as<double>("toppling_critical_height",
178 this->_cfg)),
180 get_as<double>("toppling_slope_reduction_factor", this->_cfg, 3.)),
181
182 _float_precision(1e-10),
183 _prob_dist(0., 1.),
184
185 // Create datasets using the helper functions for CellManager-data
186 _dset_height(this->create_cm_dset("height", _cm)),
187 _dset_drainage_area(this->create_cm_dset("drainage_area", _cm)),
188 _dset_watercolumn(this->create_cm_dset("watercolumn", _cm))
189 {
190 if (get_as<double>("uplift_var", this->_cfg) <= 1e-10) {
191 throw std::invalid_argument("Invalid argument: uplift_var must be "
192 "> _float_precision (1e-10)!");
193 }
194 // Update initial cell states
196
197
198 this->_log->debug("{} model fully set up.", this->_name);
199 }
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
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
double _toppling_critical_height
The critical height difference to trigget a toppling event.
Definition Geomorphology.hh:121
double _stream_power_coef
The stream power coefficient.
Definition Geomorphology.hh:111
std::normal_distribution _uplift
The random uplift as normal distribution.
Definition Geomorphology.hh:108
std::shared_ptr< DataSet > _dset_watercolumn
Dataset of drainage area.
Definition Geomorphology.hh:146
std::shared_ptr< DataSet > _dset_drainage_area
Dataset of rock height.
Definition Geomorphology.hh:145
double _toppling_slope_reduction_factor
The factor by which to reduce the slope in a toppling event.
Definition Geomorphology.hh:131
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
void _initialize_cells()
The initialization of the cells.
Definition Geomorphology.hh:281
std::shared_ptr< DataSet > _dset_height
Definition Geomorphology.hh:144
const double _float_precision
Definition Geomorphology.hh:138
GeomorphologyCellManager _cm
The cell manager for the forest fire model.
Definition Geomorphology.hh:102
Model< Geomorphology, GeomorphologyTypes > Base
The base model type.
Definition Geomorphology.hh:76
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

Member Function Documentation

◆ _initialize_cells()

void Utopia::Models::Geomorphology::Geomorphology::_initialize_cells ( )
inlineprivate

The initialization of the cells.

Adds the inclination to the cells initial rock height.

Defines the outflow boundary.

Initializes the drainage network and lakes

281 {
282 this->_log->debug("Initializing cells ..");
283
284 // Initialize altitude as an inclined plane
285 // (by making use of coordinates)
286 RuleFunc set_inclined_plane = [this](const auto& cell) {
287 auto state = cell->state;
288 auto pos = _cm.barycenter_of(cell);
289 double slope = get_as<double>("initial_slope",
290 this->_cfg["cell_manager"]["cell_params"]);
291 state.rock += slope*pos[1];
292 if (state.rock < _float_precision) {
293 std::uniform_real_distribution<> dist(0.,1e-5);
294 state.rock = dist(*this->_rng);
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.");
298 }
299 return state;
300 };
302
303 // set bottom cells as outflow
305 // The rule to apply
306 [](const auto& cell){
307 auto state = cell->state;
308 state.is_outflow = true;
309 return state;
310 },
311 // The containers over which to iterate
312 _cm.boundary_cells("bottom")
313 );
314
315 // Build drainage network
316 this->_log->debug(" Initializing drainage network ...");
318
319 this->_log->debug("Cells fully set up.");
320 }
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
const CellContainer< Cell > & cells() const
Return const reference to the managed CA cells.
Definition cell_manager.hh:219
const std::shared_ptr< RNG > _rng
The RNG shared between models.
Definition model.hh:161
typename GeomorphologyCellManager::RuleFunc RuleFunc
Rule function type, extracted from CellManager.
Definition Geomorphology.hh:94
void build_network()
The set of seperately applied rules to build the drainage network.
Definition Geomorphology.hh:207

◆ _lowest_grid_neighbor()

template<typename Cell >
Cell Utopia::Models::Geomorphology::Geomorphology::_lowest_grid_neighbor ( const Cell cell)
inlineprivate

Return the lowest cell of the grid-Neighborhood, including cell itself.

327 {
329 auto lowest_neighbor = cell;
330 for (const auto& n : this->_cm.neighbors_of(cell)) {
331 double height_diff = n->state.waterline() -
332 lowest_neighbor->state.waterline();
333
335 lowest_neighbors.push_back(n);
336 }
337
338 // If neighbor is lower, update lowest_neighbor and list
339 else if (height_diff < 0) {
341 lowest_neighbors.clear();
343 }
344 }
345
346 // If there is more than one lowest neighbor, select one randomly.
347 if (lowest_neighbors.size() > 1) {
348 std::uniform_int_distribution<> dist(0, lowest_neighbors.size() -1);
350 }
351 return lowest_neighbor;
352 }
bool check_eq_waterline(const Cell &a, const Cell &b)
Compare the waterline of two cells.
Definition Geomorphology.hh:269
Utopia::CellContainer< GeomorphologyCellType > GmorphCellContainer
The type of a cell container in the Geomorphology model.
Definition Geomorphology.hh:91

◆ build_network()

void Utopia::Models::Geomorphology::Geomorphology::build_network ( )
inline

The set of seperately applied rules to build the drainage network.

  1. Reset network
  2. Connect cells to basic netork
  3. Fill sinks with water, completing the network
  4. Calculate the drainage area on every cell
207 {
208 // reset network
210
211 // connect cells to drainage network
213
214 // fill sinks with water
216
217 // get drainage area
219 _cm.cells());
220 }
RuleFunc build_lake
Fill a sink with water.
Definition Geomorphology.hh:499
RuleFunc reset_network
The rule to reset the drainage network.
Definition Geomorphology.hh:466
RuleFunc pass_drainage_area
Make a drainage process from this cell.
Definition Geomorphology.hh:611
RuleFunc connect_cells
Build a rudimentary network.
Definition Geomorphology.hh:478

◆ check_eq()

bool Utopia::Models::Geomorphology::Geomorphology::check_eq ( const double a,
const double b 
)
inlineprivate

Compare two floats for equality.

263 {
264 return (a-b < _float_precision) && (b-a < _float_precision);
265 }

◆ check_eq_waterline()

template<typename Cell >
bool Utopia::Models::Geomorphology::Geomorphology::check_eq_waterline ( const Cell a,
const Cell b 
)
inlineprivate

Compare the waterline of two cells.

269 {
270 return check_eq(a->state.waterline(), b->state.waterline());
271 }
bool check_eq(const double &a, const double &b)
Compare two floats for equality.
Definition Geomorphology.hh:263

◆ monitor()

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

Provide monitoring data: tree density and number of clusters.

239{ return; }

◆ perform_step()

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

Perform step.

223 {
224 // Erode
226
227 // Uplift
229
230 // Topple
232 *this->_rng);
233
234 // Build drainage network
236 }
RuleFunc toppling
The rule how to topple / landslide.
Definition Geomorphology.hh:436
RuleFunc uplift_rule
The rule how to uplift.
Definition Geomorphology.hh:405
RuleFunc erode
The rule how to erode with stream power.
Definition Geomorphology.hh:412

◆ update_lakesites()

GmorphCellContainer Utopia::Models::Geomorphology::Geomorphology::update_lakesites ( GmorphCellContainer lake,
GmorphCellContainer shore 
)
inlineprivate

Update the CellContainer of lake and shore cells.

updates the shore Container to match the new lake

Parameters
lakeReference to a Container of lake cells. Lake: cells of equal waterline.
shoreReference to the Cells neighboring the lake
Returns
CellContainer of all cells connected and of same waterline as the given lake Container.
366 {
367 auto it = std::begin(shore);
368 while(it != std::end(shore)) {
369 if (check_eq_waterline(*it, lake[0])) {
370 lake.push_back(*it);
371 auto nb = _cm.neighbors_of(*it);
372 for (auto it_lake : lake) {
373 nb.erase(std::remove(nb.begin(), nb.end(), it_lake),
374 nb.end());
375 }
376 for (auto it_shore : shore) {
377 nb.erase(std::remove(nb.begin(), nb.end(), it_shore),
378 nb.end());
379 }
380
381 auto next_it = it;
382 auto next = *next_it;
383 if (next_it != shore.end())
384 next_it++;
385 if (next_it != shore.end())
386 next = *next_it;
387 it = shore.erase(it);
388 if (!nb.empty()) {
389 if (it == shore.end())
390 next = nb[0];
391 shore.insert(shore.end(), nb.begin(), nb.end());
392 it = std::find(shore.begin(), shore.end(), next);
393 }
394 }
395 else
396 ++it;
397 }
398
399 return lake;
400 };
CellContainer< Cell > neighbors_of(const Cell &cell) const
Retrieve the given cell's neighbors.
Definition cell_manager.hh:458

◆ write_data()

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

Write the cell states (aka water content)

The cell height is currently not written out as in the current implementation it does not change over time (erosion is not yet included).

246 {
247 _dset_height->write(_cm.cells().begin(), _cm.cells().end(),
248 [](const auto& cell) { return cell->state.rock; }
249 );
250
251 _dset_drainage_area->write(_cm.cells().begin(), _cm.cells().end(),
252 [](const auto& cell) { return cell->state.drainage_area; }
253 );
254
255 _dset_watercolumn->write(_cm.cells().begin(), _cm.cells().end(),
256 [](const auto& cell) { return cell->state.watercolumn; }
257 );
258 }

Member Data Documentation

◆ _cm

GeomorphologyCellManager Utopia::Models::Geomorphology::Geomorphology::_cm
private

The cell manager for the forest fire model.

◆ _dset_drainage_area

std::shared_ptr<DataSet> Utopia::Models::Geomorphology::Geomorphology::_dset_drainage_area
private

Dataset of rock height.

◆ _dset_height

std::shared_ptr<DataSet> Utopia::Models::Geomorphology::Geomorphology::_dset_height
private

◆ _dset_watercolumn

std::shared_ptr<DataSet> Utopia::Models::Geomorphology::Geomorphology::_dset_watercolumn
private

Dataset of drainage area.

◆ _float_precision

const double Utopia::Models::Geomorphology::Geomorphology::_float_precision
private

◆ _lowest_neighbors

std::unordered_map<GeomorphologyCellIndexType, std::shared_ptr<GeomorphologyCellType> > Utopia::Models::Geomorphology::Geomorphology::_lowest_neighbors
private

◆ _prob_dist

std::uniform_real_distribution Utopia::Models::Geomorphology::Geomorphology::_prob_dist
private

precision when comparing floats

A re-usable uniform real distribution to evaluate probabilities

◆ _stream_power_coef

double Utopia::Models::Geomorphology::Geomorphology::_stream_power_coef
private

The stream power coefficient.

◆ _toppling_critical_height

double Utopia::Models::Geomorphology::Geomorphology::_toppling_critical_height
private

The critical height difference to trigget a toppling event.

The probability of a toppling event is given as \( p = \Delta h / h_{crit} \), where \( \Delta h \) is the difference in height between a target cell and its highest neighbor.

◆ _toppling_frequency

double Utopia::Models::Geomorphology::Geomorphology::_toppling_frequency
private

The frequency of possible toppling events per cell.

◆ _toppling_slope_reduction_factor

double Utopia::Models::Geomorphology::Geomorphology::_toppling_slope_reduction_factor
private

The factor by which to reduce the slope in a toppling event.

The difference in height between the source and target cell of the toppling event is divided by this factor. This amount of rock is removed from the source and added to the target site.

default value: 3.

◆ _uplift

std::normal_distribution Utopia::Models::Geomorphology::Geomorphology::_uplift
private

The random uplift as normal distribution.

◆ build_lake

RuleFunc Utopia::Models::Geomorphology::Geomorphology::build_lake
private

Fill a sink with water.

such that there is a shore cell to the resulting lake that is either outflow or lower than the lakes waterline.

Updates the _lowest_neighbors map for all lake cells to point to the outflow alias a Cell within lake neighboring the lower shore cell.

Note
Must be updated in an asynchronous way. No shuffle needed.
499 {
500 // return if cell has lower neighbor
501 if (cell->state.is_outflow or _lowest_neighbors[cell->id()] != cell) {
502 return cell->state;
503 }
504
507 lake = update_lakesites(lake, shore);
508
509 double waterline = lake[0]->state.waterline();
510 bool no_sink = true;
511
512 // check for sink in new lake sites
513 for (const auto& lc : lake) {
514 if (lc->state.is_outflow) {
515 no_sink=false;
516 break;
517 }
518 }
519
520 // lowest shore cell is candidate for outflow
521 auto lowest_shore_cell = shore[0];
522 for (const auto& sc : shore) {
523 if (sc->state.waterline() < lowest_shore_cell->state.waterline())
524 {
526 }
527 }
528
529 // raise waterline while no outflow to lake
530 while (lowest_shore_cell->state.waterline() > waterline and no_sink)
531 {
532 // raise watercolumn to new waterline
533 waterline = lowest_shore_cell->state.waterline();
534 for (auto& lc : lake) {
535 lc->state.watercolumn = waterline - lc->state.rock;
536 }
537
538 // update lake and shore
540
541 for (const auto& lc : lake) {
542 if (lc->state.is_outflow) {
543 no_sink=false;
544 break;
545 }
546 }
547
548 // update lowest shore cell
550 for (const auto& sc : shore) {
551 if (sc->state.waterline() <
552 lowest_shore_cell->state.waterline())
553 {
555 }
556 }
557 }
558
560 if (not no_sink) {
561 for (const auto& lc : lake) {
562 if (lc->state.is_outflow) {
564 break;
565 }
566 }
567 }
568 else {
570 auto it_nb = nbs.begin();
571 while(it_nb != nbs.end()) {
572 if (not check_eq((*it_nb)->state.waterline(), waterline)) {
573 it_nb = nbs.erase(it_nb);
574 }
575 else if (lake.end() == std::find(lake.begin(), lake.end(),
576 *it_nb))
577 {
578 it_nb = nbs.erase(it_nb);
579 }
580 else { ++it_nb; }
581 }
582
583 if (nbs.size() > 1) {
584 std::uniform_int_distribution<> dist(0, nbs.size() - 1);
585 outflow_cell = nbs[dist(*(this->_rng))];
586 }
587 else { outflow_cell = nbs[0]; }
588 }
589
590 for (const auto& lc : lake) {
591 if (lc->state.is_outflow) {
592 _lowest_neighbors[lc->id()] = lc;
593 }
594 else {
596 }
597 }
598 if (not outflow_cell->state.is_outflow) {
600 }
601
602 return cell->state;
603 };
GmorphCellContainer update_lakesites(GmorphCellContainer &lake, GmorphCellContainer &shore)
Update the CellContainer of lake and shore cells.
Definition Geomorphology.hh:364
std::unordered_map< GeomorphologyCellIndexType, std::shared_ptr< GeomorphologyCellType > > _lowest_neighbors
Definition Geomorphology.hh:135

◆ connect_cells

RuleFunc Utopia::Models::Geomorphology::Geomorphology::connect_cells
private
Initial value:
= [this](const auto& cell) {
if (cell->state.is_outflow) {
return cell->state;
}
return cell->state;
}
Cell _lowest_grid_neighbor(const Cell &cell)
Return the lowest cell of the grid-Neighborhood, including cell itself.
Definition Geomorphology.hh:327

Build a rudimentary network.

Create map: cells to their lowest_neighbor (random choice if multiple). Sinks (no lower neighbor or outflow) map to themselfes.

478 {
479 if (cell->state.is_outflow) {
480 _lowest_neighbors[cell->id()] = cell; // map to itself
481 return cell->state;
482 }
483
484 // Set lowest neighbor for cell, is itself is sink
486
487 return cell->state;
488 };

◆ erode

RuleFunc Utopia::Models::Geomorphology::Geomorphology::erode
private
Initial value:
= [this](const auto& cell) {
auto state = cell->state;
double slope = state.waterline();
if (not state.is_outflow) {
slope -= _lowest_neighbors[cell->id()]->state.waterline();
}
double stream_power = ( _stream_power_coef * slope
* std::sqrt(state.drainage_area));
state.rock -= std::min(stream_power, state.rock);
return state;
}

The rule how to erode with stream power.

412 {
413 auto state = cell->state;
414
415 double slope = state.waterline();
416 if (not state.is_outflow) {
417 // slope = state->waterline - lowest_neighbor->waterline
418 slope -= _lowest_neighbors[cell->id()]->state.waterline();
419 }
420 // else: slope = state->waterline - 0.
421
422 double stream_power = ( _stream_power_coef * slope
423 * std::sqrt(state.drainage_area));
424 state.rock -= std::min(stream_power, state.rock);
425
426 return state;
427 };

◆ pass_drainage_area

RuleFunc Utopia::Models::Geomorphology::Geomorphology::pass_drainage_area
private
Initial value:
= [this](auto& cell) {
auto state = cell->state;
state.was_drained = true;
if (not state.is_outflow and _lowest_neighbors[cell->id()] == cell) {
throw std::runtime_error("No recipient assigned to a cell!");
}
if (state.is_outflow) {
return state;
}
downstream_cell->state.drainage_area += state.drainage_area;
while(not downstream_cell->state.is_outflow and
downstream_cell->state.was_drained)
{
downstream_cell->state.drainage_area += state.drainage_area;
if (downstream_cell->state.drainage_area > size(this->_cm.cells()))
{
throw std::runtime_error("Drainage network has loop!");
}
}
return state;
}

Make a drainage process from this cell.

Pass the cells drainage area through the already drained downstream cells up to an outflow or not already drained cell.

Note
Must be updated in an asynchronous way. No shuffle needed.
611 {
612 auto state = cell->state;
613 state.was_drained = true;
614
615 if (not state.is_outflow and _lowest_neighbors[cell->id()] == cell) {
616 throw std::runtime_error("No recipient assigned to a cell!");
617 }
618 // nothing to do here
619 if (state.is_outflow) {
620 return state;
621 }
622
623 // get downstream neighbor
625 downstream_cell->state.drainage_area += state.drainage_area;
626
627 // pass drainage to all already drained cells
628 while(not downstream_cell->state.is_outflow and
629 downstream_cell->state.was_drained)
630 {
632 downstream_cell->state.drainage_area += state.drainage_area;
633 if (downstream_cell->state.drainage_area > size(this->_cm.cells()))
634 {
635 throw std::runtime_error("Drainage network has loop!");
636 }
637 }
638
639 return state;
640 };

◆ reset_network

RuleFunc Utopia::Models::Geomorphology::Geomorphology::reset_network
private
Initial value:
= [](const auto& cell) {
auto state = cell->state;
state.drainage_area = 1.;
state.was_drained = false;
state.watercolumn = 0.;
return state;
}

The rule to reset the drainage network.

466 {
467 auto state = cell->state;
468 state.drainage_area = 1.;
469 state.was_drained = false;
470 state.watercolumn = 0.;
471 return state;
472 };

◆ toppling

RuleFunc Utopia::Models::Geomorphology::Geomorphology::toppling
private
Initial value:
= [this](const auto& cell) {
auto state = cell->state;
) {
return state;
}
auto nbrs = this->_cm.neighbors_of(cell);
for (auto& nb : nbrs) {
if (nb->state.waterline() > heighest_neighbor->state.waterline())
{
}
}
double relief = ( heighest_neighbor->state.waterline()
- state.waterline());
if (this->_prob_dist(*(this->_rng)) < failure_prob) {
heighest_neighbor->state.rock -= relief / factor;
state.rock += relief / factor;
}
return state;
}

The rule how to topple / landslide.

Note
Only evaluated with _toppling_frequency per cell

Failure of slope occurs with p = (h_i - h_j) / h_c

On failure slope is reduced to 1/3. of its initial value.

436 {
437 auto state = cell->state;
438 if (_toppling_frequency == 0. or
440 ) {
441 // Done here.
442 return state;
443 }
444
445 auto nbrs = this->_cm.neighbors_of(cell);
446 auto heighest_neighbor = cell;
447 for (auto& nb : nbrs) {
448 if (nb->state.waterline() > heighest_neighbor->state.waterline())
449 {
451 }
452 }
453 double relief = ( heighest_neighbor->state.waterline()
454 - state.waterline());
456 if (this->_prob_dist(*(this->_rng)) < failure_prob) {
458 heighest_neighbor->state.rock -= relief / factor;
459 state.rock += relief / factor;
460 }
461
462 return state;
463 };

◆ uplift_rule

RuleFunc Utopia::Models::Geomorphology::Geomorphology::uplift_rule
private
Initial value:
= [this](const auto& cell) {
auto state = cell->state;
state.rock += this->_uplift(*(this->_rng));
return state;
}

The rule how to uplift.

405 {
406 auto state = cell->state;
407 state.rock += this->_uplift(*(this->_rng));
408 return state;
409 };

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