1 #ifndef GEOMORPHOLOGY_HH
2 #define GEOMORPHOLOGY_HH
43 const std::shared_ptr<RNG>&
rng)
48 std::normal_distribution<> init_height{
49 get_as<double>(
"initial_height_mean", cfg),
50 get_as<double>(
"initial_height_var", cfg)
72 public Model<Geomorphology, GeomorphologyTypes>
160 template<
class ParentModel>
162 const std::string& name,
163 ParentModel& parent_model,
168 Base(name, parent_model, custom_cfg),
174 get_as<double>(
"uplift_var", this->
_cfg)},
180 get_as<double>(
"toppling_slope_reduction_factor", this->
_cfg, 3.)),
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)!");
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 ..");
286 RuleFunc set_inclined_plane = [
this](
const auto& cell) {
287 auto state = cell->state;
289 double slope = get_as<double>(
"initial_slope",
290 this->
_cfg[
"cell_manager"][
"cell_params"]);
291 state.rock += slope*pos[1];
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.");
301 apply_rule<Update::sync>(set_inclined_plane,
_cm.
cells());
304 apply_rule<Update::sync>(
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>
329 auto lowest_neighbor = cell;
331 double height_diff = n->state.waterline() -
332 lowest_neighbor->state.waterline();
335 lowest_neighbors.push_back(n);
339 else if (height_diff < 0) {
341 lowest_neighbors.clear();
342 lowest_neighbors.push_back(lowest_neighbor);
347 if (lowest_neighbors.size() > 1) {
348 std::uniform_int_distribution<> dist(0, lowest_neighbors.size() -1);
349 lowest_neighbor = lowest_neighbors[dist(*(this->
_rng))];
351 return lowest_neighbor;
372 for (
auto it_lake : lake) {
373 nb.erase(std::remove(nb.begin(), nb.end(), it_lake),
376 for (
auto it_shore : shore) {
377 nb.erase(std::remove(nb.begin(), nb.end(), it_shore),
382 auto next = *next_it;
383 if (next_it != shore.end())
385 if (next_it != shore.end())
387 it = shore.erase(it);
389 if (it == shore.end())
391 shore.insert(shore.end(), nb.begin(), nb.end());
392 it = std::find(shore.begin(), shore.end(), next);
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));
424 state.rock -= std::min(stream_power, state.rock);
437 auto state = cell->state;
446 auto heighest_neighbor = cell;
447 for (
auto& nb : nbrs) {
448 if (nb->state.waterline() > heighest_neighbor->state.waterline())
450 heighest_neighbor = nb;
453 double relief = ( heighest_neighbor->state.waterline()
454 - state.waterline());
458 heighest_neighbor->state.rock -= relief / factor;
459 state.rock += relief / factor;
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) {
521 auto lowest_shore_cell = shore[0];
522 for (
const auto& sc : shore) {
523 if (sc->state.waterline() < lowest_shore_cell->state.waterline())
525 lowest_shore_cell = sc;
530 while (lowest_shore_cell->state.waterline() > waterline and no_sink)
533 waterline = lowest_shore_cell->state.waterline();
534 for (
auto& lc : lake) {
535 lc->state.watercolumn = waterline - lc->state.rock;
541 for (
const auto& lc : lake) {
542 if (lc->state.is_outflow) {
549 lowest_shore_cell = shore[0];
550 for (
const auto& sc : shore) {
551 if (sc->state.waterline() <
552 lowest_shore_cell->state.waterline())
554 lowest_shore_cell = sc;
559 auto outflow_cell = lowest_shore_cell;
561 for (
const auto& lc : lake) {
562 if (lc->state.is_outflow) {
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);
575 else if (lake.end() == std::find(lake.begin(), lake.end(),
578 it_nb = nbs.erase(it_nb);
583 if (nbs.size() > 1) {
584 std::uniform_int_distribution<> dist(0, nbs.size() - 1);
585 outflow_cell = nbs[dist(*(this->
_rng))];
587 else { outflow_cell = nbs[0]; }
590 for (
const auto& lc : lake) {
591 if (lc->state.is_outflow) {
598 if (not outflow_cell->state.is_outflow) {
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) {
625 downstream_cell->state.drainage_area += state.drainage_area;
628 while(not downstream_cell->state.is_outflow and
629 downstream_cell->state.was_drained)
632 downstream_cell->state.drainage_area += state.drainage_area;
633 if (downstream_cell->state.drainage_area > size(this->_cm.
cells()))
635 throw std::runtime_error(
"Drainage network has loop!");
A cell is a slightly specialized state container.
Definition: cell.hh:40
const CellContainer< Cell > & cells() const
Return const reference to the managed CA cells.
Definition: cell_manager.hh:219
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 > neighbors_of(const Cell &cell) const
Retrieve the given cell's neighbors.
Definition: cell_manager.hh:458
Utopia::Cell< CellTraits > Cell
Type of the managed cells.
Definition: cell_manager.hh:47
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
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 clls.
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
std::mt19937 rng
– Type definitions ----------------------------------------------------—
Definition: test_revision.cc:17
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:25
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