Skip to content

Commit f317f6b

Browse files
author
Marco Dal Molin
committed
Documentation updated
1 parent c8997e2 commit f317f6b

6 files changed

Lines changed: 56 additions & 11 deletions

File tree

doc/components.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,10 @@ All components share the following methods.
492492
- **Inputs and outputs**: all components have functionalities to receive inputs
493493
and generate outputs.
494494

495-
- :code:`set_input`: set the input fluxes of the component;
495+
- :code:`set_input`: set the inputs of the component; inputs can be fluxes
496+
(e.g., precipitation) or other variables that influence the behavior of
497+
the component (e.g., temperature influencing the behavior of a snow
498+
element).
496499

497500
- :code:`get_output`: run the component (and all components contained in it)
498501
and return the output fluxes.

doc/demo.rst

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,11 @@ done with the following code, where the default settings of the solver are used
8383
:lines: 20, 18, 21
8484
:linenos:
8585

86-
The element is initialized next
86+
Note that the :code:`approximator`, while being an object, it does not have
87+
internal states and, therefore, the same instance can be assigned to multiple
88+
elements and, in terms of functioning, it can be seen as a function.
89+
90+
The element is initialized next
8791

8892
.. literalinclude:: demo_code.py
8993
:language: python

doc/demo_code.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@
196196
# Create the network
197197
net = Network(
198198
nodes=[node_1, node_2, node_3],
199-
topography={
199+
topology={
200200
'node-1': 'node-3',
201201
'node-2': 'node-3',
202202
'node-3': None

doc/model_thur_hess2020.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -206,7 +206,7 @@
206206
stgallen,
207207
waengi,
208208
],
209-
topography={
209+
topology={
210210
'andelfingen': None,
211211
'appenzell': 'stgallen',
212212
'frauenfeld': 'andelfingen',

doc/numerical_solver.rst

Lines changed: 37 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,11 @@
66
77
.. _numerical_solver:
88

9+
Numerical implementation
10+
========================
11+
912
Numerical routines for solving ODEs
10-
===================================
13+
-----------------------------------
1114

1215
:ref:`reservoirs` are the most common elements in conceptual hydrological
1316
models. Reservoirs are controlled by one (or more) ordinary differential
@@ -35,10 +38,13 @@ These steps can be performed using two SuperflexPy components:
3538
:code:`NumericalApproximator` and :code:`RootFinder`.
3639

3740
SuperflexPy provides two built-in numerical approximators (implicit and explicit
38-
Euler) and a root finder (Pegasus method).
41+
Euler) and a root finder (Pegasus method). These methods are best suited when
42+
dealing with smooth flux functions. If a user wants to experiment with
43+
discontinuous flux functions, other ODE solution algorithms should be
44+
considered.
3945

40-
Other ODE solution algorithms, e.g. Runge-Kutta, can be accommodated
41-
by extending the classes :code:`NumericalApproximator` and/or
46+
The implementation of other ODE solution algorithms, e.g. Runge-Kutta, can be
47+
done by extending the classes :code:`NumericalApproximator` and/or
4248
:code:`RootFinder`. Even more generally, ODE solvers from external libraries
4349
could be used within SuperflexPy by incorporating them in a class that respects
4450
the interface expected by the :code:`NumericalApproximator`.
@@ -47,7 +53,7 @@ The following sections describe the standard approach to create customized
4753
numerical approximators and root finders.
4854

4955
Numerical approximator
50-
----------------------
56+
......................
5157

5258
A customized numerical approximator can be implemented by extending the class
5359
:code:`NumericalApproximator` and implementing two methods: :code:`_get_fluxes`
@@ -77,7 +83,7 @@ For further details, please see the implementation of :code:`ImplicitEuler` and
7783
:code:`ExplicitEuler`.
7884

7985
Root finder
80-
-----------
86+
...........
8187

8288
A customized root finder can implemented by extending the class
8389
:code:`RootFinder` implementing the method :code:`solve`.
@@ -94,11 +100,35 @@ the fluxes, :code:`S0` is the initial state, :code:`dt` is the time step,
94100
:code:`fluxes`, and :code:`ind` is the index of the input arrays to use.
95101

96102
The method :code:`solve` is responsible for finding the numerical solution of
97-
the approximated ODE.
103+
the approximated ODE. In case of failure, the method should either raise a
104+
:code:`RuntimeError` (Python implementation) or return :code:`numpy.nan` (this
105+
is not ideal but, since Numba does not support raising exceptions, is the
106+
solution that should be adopted with the Numba implementation).
98107

99108
To understand better how this method works, please see the implementation of
100109
:code:`Pegasus`.
101110

111+
Sequential solution of the elements
112+
-----------------------------------
113+
114+
The SuperflexPy framework is built on a model representation that maps to a
115+
directional acyclic graph. Model elements are solved sequentially from upstream
116+
to downstream, with the output from each element being used as input to
117+
its downstream elements.
118+
119+
When fixed-step solvers are used (e.g. implicit Euler), this
120+
"one-element-at-a-time" strategy is equivalent to applying the same (fixed-step)
121+
solver to the entire ODE system simultaneously.
122+
123+
When more advanced solvers use internal substepping, then the
124+
"one-element-at-a-time" strategy does introduces additional approximation error.
125+
This additional approximation error is due to treating the fluxes as constant
126+
over the time step, whereas the exact solution would have varying fluxes within
127+
the time step. However, in most practical applications, this "uniform flux"
128+
approximation is already applied to the meteorological inputs (precipitation and
129+
PET), hence applying it to internal fluxes does not represent a large additional
130+
approximation.
131+
102132
Computational efficiency with Numpy and Numba
103133
---------------------------------------------
104134

doc/reference.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,14 @@ classes that should be customized to extend SuperflexPy. Particular
1414
implementations of components (i.e. the content of
1515
:code:`superflexpy/implementation/`) are not included.
1616

17+
The following diagram follows the standards of
18+
`UML <https://en.wikipedia.org/wiki/Class_diagram>`_ and shows the organization
19+
of the classes composing the framework. All the classes in the diagram can be
20+
extended through inheritance to create customized components.
21+
22+
.. image:: pics/reference/class_uml.png
23+
:align: center
24+
1725
superflexpy.framework.element
1826
-----------------------------
1927

0 commit comments

Comments
 (0)