Plugins
Loading...
Searching...
No Matches
rivers.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2025 Gesellschaft fuer Anlagen- und Reaktorsicherheit gGmbH
3 * SPDX-License-Identifier: EUPL-1.2
4 * SPDX-FileContributor: Dmitry Logashenko
5 * SPDX-FileContributor: Goethe Universität Frankfurt
6 * SPDX-FileType: SOURCE
7 *
8 * This file is part of d3f++.
9 * d3f++ is an extension for UG4. Licensing information and citation requirements of UG4 are provided in LICENSES/UG4-LGPL_2.1
10 */
11
12/*
13 * Contribution of the surface rivers represented as sets of 1d segments in 3d.
14 */
15#ifndef __H__UG__PLUGINS__D3F__RIVERS__
16#define __H__UG__PLUGINS__D3F__RIVERS__
17
18#include <vector>
19#include <limits>
20#include <string>
21
22// ug4 headers
23#include "common/common.h"
27
28// d3f headers
29#include "level_set_pos.h"
30#include "segment_network.h"
31
32namespace ug {
33namespace d3f {
34
40template <int dim>
42(
43 number d,
44 number smooth_len
45);
46
50template <>
52(
53 number d,
54 number smooth_len
55)
56{
57 d /= smooth_len;
58 if (d >= 1) return 0;
59 return (1 - d) / (smooth_len / 2);
60}
61
65template <>
67(
68 number d,
69 number smooth_len
70)
71{
72 d /= smooth_len;
73 if (d >= 1) return 0;
74 return (1 - d) / (PI * smooth_len * smooth_len / 3);
75}
76
82template <typename TGridFunction>
84{
85public:
86
88 typedef TGridFunction grid_func_type;
89
91 typedef typename TGridFunction::domain_type domain_type;
92
94 typedef typename TGridFunction::algebra_type algebra_type;
95
97 typedef typename domain_type::grid_type grid_type;
98
100 static const int dim = TGridFunction::dim;
101
103 static const int mol_dim = dim - 1;
104
107
110
113
114public:
115
118 (
119 number smoothLen,
121 )
122 : m_density (998.2), m_viscosity (1e-3),
123 m_perm (1), m_e (1), m_gravity (- 9.81),
124 m_smoothLen (smoothLen),
125 m_restrict_depth (false),
127 m_no_inflow (false),
128 m_lsPosZ (spLSF),
129 m_is_constant (false), m_constant_flux (0)
130 {}
131
133 number smooth_len () const {return m_smoothLen;}
134
137
140
142 void set_density (number rho) {m_density = rho;}
143
146
149
156
158 bool restrict_depth () const {return m_restrict_depth;}
159
162
164 void set_no_inflow (bool b) {m_no_inflow = b;}
165
167 bool no_inflow () const {return m_no_inflow;}
168
170 void set_relative_to (const char* subsetNames, number top_tolerance, int top_grid_level);
171
173 void set_relative_to (const char* subsetNames, number top_tolerance)
174 {
175 set_relative_to (subsetNames, top_tolerance, -1);
176 }
177
179 void set_relative_to (const char* subsetNames)
180 {
181 set_relative_to (subsetNames, 1e-6, -1);
182 }
183
186 {
187 m_is_constant = true;
188 m_constant_flux = flux;
189 }
190
192 void compute
193 (
194 SmartPtr<grid_func_type> spRecharge
195 );
196
198 void simple_compute
199 (SmartPtr<grid_func_type> spRecharge);
200
201
202protected:
203
206
209 {
210 number fs_depth;
211 if (! m_lsPosZ.get_height_at (x, fs_depth))
212 fs_depth = - std::numeric_limits<number>::max (); // the segment is not covered by the free surface
213 return fs_depth;
214 }
215
217 bool ls_depth_is_relative () {return m_spTopTracerTree.valid ();}
218
220 size_t min_top_depth (MathVector<dim-1>& x, number& min_depth)
221 {
223 for (size_t i = 0; i < dim - 1; i++) X[i] = x[i];
224 X[dim-1] = 0;
225 size_t n = get_top_z (X);
226 if (n != 0)
227 {
228 // get the minimum z:
229 min_depth = m_topTracePoints[0][dim-1];
230 for (size_t i = 1; i < m_topTracePoints.size (); i++)
231 if (min_depth > m_topTracePoints[i][dim-1])
232 min_depth = m_topTracePoints[i][dim-1];
233 }
234 return n;
235 }
236
239 (
240 number h_s,
241 number h_fs,
242 number w
243 ) const
244 {
245 if (! m_is_constant)
246 return (- m_perm * m_density * m_gravity * (h_s - h_fs) / m_e / m_viscosity) * w;
247 else
248 return m_constant_flux;
249 }
250
252 size_t get_top_z (const MathVector<dim> & over);
253
255 virtual void compute_depths () = 0;
256
259 (
260 MathVector<dim> & x
261 ) const = 0;
262
264 (
265 MathVector<dim> & x
266 ) const = 0;
267
268protected:
269
272
275
278
281
284
287
290
293
296
299
302
304 std::vector<top_intersection_record_t> m_topIntersectionRecords;
305
307 std::vector<MathVector<dim> > m_topTracePoints;
308
311
312//--- Some debugging facilities
313
318};
319
328template <typename TGridFunction>
330: public VertexLowDimRecharge<TGridFunction>
331{
334
335public:
336
338 typedef TGridFunction grid_func_type;
339
341 typedef typename TGridFunction::domain_type domain_type;
342
344 typedef typename TGridFunction::algebra_type algebra_type;
345
347 typedef typename domain_type::grid_type grid_type;
348
350 static const int dim = TGridFunction::dim;
351
352private:
353
356 {
359
362
364 (
365 MathVector<dim-1> the_x,
366 number the_well_depth_spec
367 )
368 : x (the_x), well_depth_spec (the_well_depth_spec)
369 {}
370 };
371
372public:
373
376 (
377 number smoothLen,
379 )
380 : VertexLowDimRecharge<TGridFunction> (smoothLen, spLSF),
381 m_width (1)
382 {}
383
386
388 void set_width (number riverWidth) {m_width = riverWidth;}
389
392 {
393 m_wells.push_back (well_recharge_data_t (x, depth));
394 }
395
397 void add_well (std::vector<number> coord, number depth)
398 {
399 if (coord.size () != (size_t) (dim - 1))
400 UG_THROW ("VertexWellRecharge::add_well: Wrong number of coordinates specified.\n");
401 MathVector<dim-1> x;
402 for (size_t i = 0; i < dim-1; i++) x[i] = coord[i];
403 m_wells.push_back (well_recharge_data_t (x, depth));
404 }
405
406private:
407
409 virtual void compute_depths ();
410
413 (
414 MathVector<dim> & x
415 ) const;
416
419 (
420 MathVector<dim> & x
421 ) const;
422
423private:
424
427
429 std::vector<well_recharge_data_t> m_wells;
430};
431
440template <typename TGridFunction>
442: public VertexLowDimRecharge<TGridFunction>
443{
446
447public:
448
450 typedef TGridFunction grid_func_type;
451
453 typedef typename TGridFunction::domain_type domain_type;
454
456 typedef typename TGridFunction::algebra_type algebra_type;
457
459 typedef typename domain_type::grid_type grid_type;
460
462 static const int dim = TGridFunction::dim;
463
464private:
465
468
471
472public:
473
476 (
477 SmartPtr<SegmentNetwork> spRiverNetwork,
478 number smoothLen,
480 )
481 : VertexLowDimRecharge<TGridFunction> (smoothLen, spLSF),
482 m_spRiverNetwork (spRiverNetwork),
483 m_bNodalFSDepth (false),
486 {
487 Grid & riverGrid = m_spRiverNetwork->grid ();
488
489 riverGrid.attach_to_edges (m_aFSDepth);
490 m_aaFSDepth.access (riverGrid, m_aFSDepth);
491
492 riverGrid.attach_to_edges (m_aRiverDepth);
494
495 riverGrid.attach_to_edges (m_aRiverWidth);
497
498 set_river_width (1); // a "very default" value
499 }
500
503 {
504 Grid & riverGrid = m_spRiverNetwork->grid ();
505 riverGrid.detach_from_edges (m_aFSDepth);
508 }
509
511 void set_river_width (number riverWidth);
512
514 void set_river_width (number riverWidth, int ssi);
515
517 void set_river_width (number riverWidth, const char * ss_name);
518
521
524
527
530
532 void print_total_recharge (const char * f_name)
533 {
535 m_sTotalRechargeFile = f_name;
536 }
537
539 void file_output_prefix (const char * s) {m_sOutputPrefix = s;}
540
542 void reset_river_depth ();
543
545 void save_river_depth (const char * file_name);
546
549
551 number fs_depth_for (const Edge * seg) const {return m_aaFSDepth [seg];}
552
554 number river_depth_for (const Edge * seg) const {return m_aaRiverDepth [seg];}
555
557 number river_width_for (const Edge * seg) const {return m_aaRiverWidth [seg];}
558
559private:
560
563
566
568 virtual void compute_depths ();
569
572 (
573 MathVector<dim> & x
574 ) const;
575
578 (
579 MathVector<dim> & x
580 ) const;
581
584
585private:
586
589
592
595
598
601
604
607
610
613
616
619
623 std::string m_sOutputPrefix;
624};
625
626} // namespace d3f
627} // end namespace ug
628
629#include "rivers_impl.h"
630
631#endif // __H__UG__PLUGINS__D3F__RIVERS__
632/* End of File */
parameterString s
Definition Biogas.lua:2
bool access(Grid &grid, TAttachment &a)
void attach_to_edges(IAttachment &attachment)
void detach_from_edges(IAttachment &attachment)
Definition level_set_pos.h:48
bool get_height_at(const MathVector< dim-1 > &xy, number &height)
gets the largest z-coordinate (returns false if no intersections found)
Definition level_set_pos.h:163
void reinit()
initialize the object: find the intersected elements and prepare the tree
Definition level_set_pos.h:139
Definition rivers.h:84
virtual number simple_smoothed_recharge_at(MathVector< dim > &x) const =0
VertexLowDimRecharge(number smoothLen, SmartPtr< grid_func_type > spLSF)
constructor
Definition rivers.h:118
bool m_no_inflow
whether to switch the possible inflow off
Definition rivers.h:295
number m_max_depth_diff
max. depth difference (if restricted)
Definition rivers.h:292
void prepare_ls_height()
initializes the level-set z-coordinate computations
Definition rivers.h:205
void set_bottom_thickness(number e)
sets the thickness of the bottom
Definition rivers.h:139
bool m_restrict_depth
if to restrict the depth
Definition rivers.h:289
void set_no_inflow(bool b)
switches the possible inflow on/off
Definition rivers.h:164
static const int dim
world dimension
Definition rivers.h:100
number m_top_tolerance
tolerance for the projection to the top
Definition rivers.h:310
static const int mol_dim
dimension of the mollifier
Definition rivers.h:103
number m_e
thickness of the bottom
Definition rivers.h:280
void set_relative_to(const char *subsetNames, number top_tolerance)
specifyes the subsets of the top
Definition rivers.h:173
void set_gravity(number g)
sets the gravity
Definition rivers.h:148
number m_gravity
gravity
Definition rivers.h:283
std::vector< MathVector< dim > > m_topTracePoints
intersection points with the top subsets
Definition rivers.h:307
TGridFunction::domain_type domain_type
type of the domain
Definition rivers.h:91
number object_recharge(number h_s, number h_fs, number w) const
the river recharge intensivity (according to the model)
Definition rivers.h:239
bool ls_depth_is_relative()
returns true iff the depths should be relative
Definition rivers.h:217
void set_viscosity(number mu)
sets the viscosity of the water
Definition rivers.h:145
void simple_compute(SmartPtr< grid_func_type > spRecharge)
computes the recharge at the vertices
Definition rivers_impl.h:95
bool m_is_constant
if to use the constant intensity
Definition rivers.h:315
TGridFunction grid_func_type
grid function type
Definition rivers.h:88
void set_density(number rho)
sets the density of the water
Definition rivers.h:142
number m_smoothLen
smoothing parameter (of the mollifier)
Definition rivers.h:286
number m_constant_flux
the intensity per unit length if constant (all other parameters are ignored)
Definition rivers.h:317
void set_relative_to(const char *subsetNames, number top_tolerance, int top_grid_level)
specifyes the subsets of the top
Definition rivers_impl.h:29
TGridFunction::algebra_type algebra_type
type of the algebra
Definition rivers.h:94
grid_dim_traits< dim >::side_type g_surf_elem_t
type of the elements constituting surfaces in the grid
Definition rivers.h:106
domain_type::grid_type grid_type
grid type
Definition rivers.h:97
LSPositionZ< grid_func_type > m_lsPosZ
depth measurer for the level set
Definition rivers.h:298
geometry_traits< g_surf_elem_t >::iterator g_surf_iter_t
type of the iterator of the grid surface elements
Definition rivers.h:109
void compute(SmartPtr< grid_func_type > spRecharge)
computes the recharge at the vertices
Definition rivers_impl.h:119
number get_ls_height_at(MathVector< dim-1 > &x)
computes the z-coordinate of the level set at a given point
Definition rivers.h:208
number m_perm
permeability of the bottom
Definition rivers.h:277
SmartPtr< top_tracer_tree_t > m_spTopTracerTree
tree for the top ray traicer
Definition rivers.h:301
void set_permeability(number k)
sets the permeability of the bottom
Definition rivers.h:136
number smooth_len() const
returns the smoothing parameter
Definition rivers.h:133
number max_depth_diff() const
returns the set maximum depth difference
Definition rivers.h:161
number m_viscosity
viscosity of the water
Definition rivers.h:274
size_t get_top_z(const MathVector< dim > &over)
get the intersection with the top
Definition rivers_impl.h:72
std::vector< top_intersection_record_t > m_topIntersectionRecords
top intersection tracer auxiliary data struction
Definition rivers.h:304
RayElemIntersectionRecord< g_surf_elem_t * > top_intersection_record_t
Definition rivers.h:112
void set_relative_to(const char *subsetNames)
specifyes the subsets of the top
Definition rivers.h:179
bool no_inflow() const
returns the state of the possible inflow
Definition rivers.h:167
bool restrict_depth() const
returns the state of the depth restriction
Definition rivers.h:158
virtual void compute_depths()=0
prepares the depth of the recharge objects
lg_ntree< dim-1, dim, g_surf_elem_t > top_tracer_tree_t
Definition rivers.h:111
void restrict_depth(number max_depth_diff)
restricts the depth
Definition rivers.h:151
void set_constant_flux(number flux)
sets the constant flux (mainly for debugging purposes)
Definition rivers.h:185
size_t min_top_depth(MathVector< dim-1 > &x, number &min_depth)
computes the minimum z-coordinate of the top surface (returns the number of the intersections)
Definition rivers.h:220
number m_density
density of the water
Definition rivers.h:271
virtual number smoothed_recharge_at(MathVector< dim > &x) const =0
computes the smoothed recharge at a given point
Definition rivers.h:443
ANumber depth_attachment_type
attachment type for the depth of segments of the rivers
Definition rivers.h:467
void save_river_depth(const char *file_name)
save the river network with the fs depth in a file
Definition rivers_impl.h:708
void do_print_total_recharge()
prints the total recharge
Definition rivers_impl.h:536
void use_nodal_fs_height(bool v)
sets measuring the depth of the free surface from the centers of the segments to the nodes and back
Definition rivers.h:520
depth_attachment_type m_aRiverDepth
attachment for the specified depth of the rivers at the segments
Definition rivers.h:597
void compute_fs_depths_at_nodes()
computes the depths of the free surface at the nodes of the river vertices
Definition rivers_impl.h:319
bool m_bCheckFSCovering
whether to check the covering of the river segments by the free surface
Definition rivers.h:612
static const int dim
world dimension
Definition rivers.h:462
depth_accessor_type m_aaFSDepth
accessor for the attachment for the depth of the free surface
Definition rivers.h:594
domain_type::grid_type grid_type
grid type
Definition rivers.h:459
TGridFunction::domain_type domain_type
type of the domain
Definition rivers.h:453
void set_river_width(number riverWidth)
sets river width for all segments
Definition rivers_impl.h:264
void check_top_covering(bool v)
sets the verification of the covering by the top subset
Definition rivers.h:526
depth_accessor_type m_aaRiverWidth
accessor forthe attachment for the width of the rivers
Definition rivers.h:606
void check_fs_covering(bool v)
sets the verification of the covering by the free surface
Definition rivers.h:523
void print_total_recharge(bool v)
whether to print the total integrated recharge
Definition rivers.h:529
bool m_bNodalFSDepth
whether to measure the depth of the free surface at the nodes, not in the segments
Definition rivers.h:609
std::string m_sOutputPrefix
... and prepend the following prefix to the lines
Definition rivers.h:623
number river_depth_for(const Edge *seg) const
gets the depth of the river for a segment
Definition rivers.h:554
number fs_depth_for(const Edge *seg) const
gets the depth of the free surface for a segment
Definition rivers.h:551
virtual ~VertexRiverRecharge()
class destructor
Definition rivers.h:502
VertexRiverRecharge(SmartPtr< SegmentNetwork > spRiverNetwork, number smoothLen, SmartPtr< grid_func_type > spLSF)
class constructor
Definition rivers.h:476
SmartPtr< SegmentNetwork > river_network() const
returns the river network
Definition rivers.h:548
virtual number smoothed_recharge_at(MathVector< dim > &x) const
computes the smoothed recharge at a given point
Definition rivers_impl.h:590
bool m_bPrintTotalRecharge
whether to print the total recharge integrated over the rivers
Definition rivers.h:618
void print_total_recharge(const char *f_name)
whether to print the total integrated recharge to a file
Definition rivers.h:532
void file_output_prefix(const char *s)
sets the prefix to add to every line in the file
Definition rivers.h:539
SmartPtr< SegmentNetwork > m_spRiverNetwork
grid of the river segments
Definition rivers.h:588
VertexRiverRecharge< TGridFunction > this_type
this type
Definition rivers.h:445
virtual number simple_smoothed_recharge_at(MathVector< dim > &x) const
computes the smoothed recharge at a given point neglecting the depths, width etc.
Definition rivers_impl.h:762
void reset_river_depth()
set the river depth from the fs depth
Definition rivers_impl.h:650
depth_attachment_type m_aFSDepth
attachment for the depth of the free surface for the segments
Definition rivers.h:591
TGridFunction::algebra_type algebra_type
type of the algebra
Definition rivers.h:456
TGridFunction grid_func_type
grid function type
Definition rivers.h:450
number river_width_for(const Edge *seg) const
gets the with of the river for a segment
Definition rivers.h:557
void compute_fs_depths_at_segments()
computes the depths of the free surface at the centers of the river segments
Definition rivers_impl.h:383
bool m_bCheckTopCovering
whether to check the covering of the river segments by the top subset
Definition rivers.h:615
Grid::EdgeAttachmentAccessor< depth_attachment_type > depth_accessor_type
accessor type for the depth attachment
Definition rivers.h:470
depth_attachment_type m_aRiverWidth
attachment for the width of the rivers
Definition rivers.h:603
std::string m_sTotalRechargeFile
if yes, if to print it into a file, too
Definition rivers.h:621
virtual void compute_depths()
fills the attachment with the depths of the free surface
Definition rivers_impl.h:430
depth_accessor_type m_aaRiverDepth
accessor for the attachment for the depth of the rivers
Definition rivers.h:600
Definition rivers.h:331
VertexWellRecharge(number smoothLen, SmartPtr< grid_func_type > spLSF)
class constructor
Definition rivers.h:376
void add_well(std::vector< number > coord, number depth)
adds a well
Definition rivers.h:397
TGridFunction grid_func_type
grid function type
Definition rivers.h:338
virtual void compute_depths()
fills the attachment with the depths of the free surface
Definition rivers_impl.h:147
TGridFunction::domain_type domain_type
type of the domain
Definition rivers.h:341
static const int dim
world dimension
Definition rivers.h:350
virtual ~VertexWellRecharge()
class destructor
Definition rivers.h:385
virtual number smoothed_recharge_at(MathVector< dim > &x) const
computes the smoothed recharge at a given point
Definition rivers_impl.h:211
void add_well(MathVector< dim-1 > &x, number depth)
adds a well
Definition rivers.h:391
void set_width(number riverWidth)
sets the diameter of the wells
Definition rivers.h:388
VertexWellRecharge< TGridFunction > this_type
this type
Definition rivers.h:333
std::vector< well_recharge_data_t > m_wells
array of the wells:
Definition rivers.h:429
virtual number simple_smoothed_recharge_at(MathVector< dim > &x) const
computes the smoothed recharge at a given point
Definition rivers_impl.h:252
TGridFunction::algebra_type algebra_type
type of the algebra
Definition rivers.h:344
domain_type::grid_type grid_type
grid type
Definition rivers.h:347
number m_width
diameter of the wells - meant to be the default one
Definition rivers.h:426
#define UG_THROW(msg)
double number
number cone_mollifier< 2 >(number d, number smooth_len)
Definition rivers.h:67
number cone_mollifier< 1 >(number d, number smooth_len)
Definition rivers.h:52
number cone_mollifier(number d, number smooth_len)
const number PI
data of a recharge well
Definition rivers.h:356
MathVector< dim-1 > x
coordinates of the well
Definition rivers.h:357
number well_depth
effective level of the well
Definition rivers.h:361
number well_depth_spec
level of the well as specified
Definition rivers.h:358
number fs_depth
depth of the free surface at the well (computed)
Definition rivers.h:360
well_recharge_data_t(MathVector< dim-1 > the_x, number the_well_depth_spec)
Definition rivers.h:364