2.0.0b10
catchment modelling framework
|
In this part, we are going to create a first model. To keep things simple, the model will be extremely simple. In fact, it would be easier to do this model in a spread sheet and keep cmf out of it. But of course it is to introduce some of the elements of cmf.
The model is a simple linear storage equation to transport water from one water storage ( \(W_1\)) to another water storage ( \(W_2\)).
\[ q_{W_1,W_2}=\frac{V_1}{t_r} \]
where:
The model (without the solver) is set up with the following lines of code:
With these lines the ODE (ordinary differential equation) system is formulated:
\[ \frac{dV_1}{dt} = -\frac{V_1}{t_r} \]
\[ \frac{dV_2}{dt} = \frac{V_1}{t_r} \]
Due to the simplicity of the model, it can be integrated analytically.
\[ V_1(t) = V_1(t_0) e^{-t/t_r} \]
\[ V_2(t) = V_1(t_0) (1-e^{-t/t_r}) \]
But it is of course only a proxy model. For more interesting models with stochastic boundary conditions, we need to use a numerical solution. For numerical time integration any of the time integration schemes of cmf will do for this model. If you are using more complex models with very different velocities, error controlled and implicit solvers are necessary.
To integrate our simple system in time, we create an integrator, for example an explicit 4/5 step Runge-Kutta-Fehlberg integrator, the RKFIntegrator (other integrators are available, see later parts in the tutorial)
The code above is the setup part. Every cmf model consists of a setup part, where the hydrological system is defined. For larger models, Python's looping and conditional syntax and the possibility to read nearly any data format can help to define the system from data.
Now we have all parts of our model available to run it. The solver can be advanced for a certain time step using solver.integrate(dt), where dt is a time step. After the integration the states and fluxes of the model can be queried (see Query fluxes and storages) and, if needed, saved into a file. Or you can store the results in a Python list or a cmf timeseries and use matplotlib to plot the results immediately after running the model. The content and format of output is completely up to the user, some experience in writing and reading files with Python is therefore a prerequisite to design your own output.
In this example, we will write a csv file with the timestep, the state of w1 and the state of w2.
In principle, this is the base for all cmf models. In the next chapters, we will introduce boundary conditions, more specialized water storages, like soil layers and rivers, and have a look at solute transport.
An alternative way to the run time code above is using list comprehension. The result is then not written into a file, but stored in memory using a list. This list can be plotted using the pylab
-API of matplotlib. The setup code is as before.
And this is the result:
Next step is to include boundary conditions.