apply_adjust Scheme Example
This example shows how to use the ReservoirModel.apply_adjust() scheme when modelling a single reservoir model.
Note
For details about the full model file structure please see Basic Single Reservoir.
We consider a reservoir with a single inflow, Q_in, and an outflow Q_out.
There are observed volumes for the first portion of timesteps (until 13th of June). At these times, the simulation should
be adjusted based upon these observed values. Hence the outflow from the reservoir will be corrected to prevent diverging
water balances between simulation and observation. At times without volume observations, reservoir outflow should be 0.4 m3/s.
The ReservoirModel.apply_adjust() scheme can be applied to model these operations.
Main Model (python) File
An example of the main model file adjust_example.py is given below.
1"""Example that illustrates use of the adjust scheme."""
2
3from pathlib import Path
4
5from rtctools.util import run_simulation_problem
6
7from rtctools_simulation.reservoir.model import InputVar, ModelConfig, ReservoirModel
8
9CONFIG = ModelConfig(base_dir=Path(__file__).parent)
10
11
12class SingleReservoir(ReservoirModel):
13 """Example single reservoir model."""
14
15 def apply_schemes(self):
16 """Apply schemes for controlling the reservoir."""
17
18 # Apply schemes.
19 self.set_q(
20 target_variable=InputVar.Q_OUT,
21 input_type="parameter",
22 input_data=0.4,
23 )
24 self.apply_adjust()
25
26
27# Create and run the model.
28if __name__ == "__main__":
29 run_simulation_problem(SingleReservoir, config=CONFIG)
The template file mentioned in the Basic Single Reservoir will look very similar to this file,
except that the apply_schemes() method still needs to be filled out.
The line
CONFIG = ModelConfig(base_dir=Path(__file__).parent)
sets the model configuration.
This model configuration is defined by the base directory base_dir.
In most cases, the base directory is Path(__file__).parent,
which is the directory of the current file.
The line
class SingleReservoir(ReservoirModel):
defines a class SingleReservoir
that inherits all properties and functionalities
of the predefined class ReservoirModel.
An overview of this class can be found in Reservoir API
and details of the underlying model it uses can be found in Single Reservoir Model.
The method ReservoirModel.apply_schemes() is called every timestep and contains the logic
for which schemes are applied.
The first argument self is the SingleReservoir object itself.
Since SingleReservoir inherits from ReservoirModel,
self can call any of the ReservoirModel methods, such as
ReservoirModel.apply_adjust().
An overview of all available ReservoirModel methods
can be found in Reservoir API.
The ReservoirModel.set_q() scheme is applied to set reservoir outflow to 0.4 m3/s.
The ReservoirModel.apply_adjust() scheme is then applied to correct for volume observations
when they are supplied to the model.
Lookup tables
This model uses only the standard lookup table h_from_v, for other lookup tables, defaults from the generated template files can be used.
Lookup table h_from_v is also used to convert the observed elevations (H_observed) into observed volumes.
Note
For further details about the lookup tables please see Basic Single Reservoir.
Input Data Files
The ReservoirModel.apply_adjust() scheme requires observed volume data supplied via the timeseries_import.xml
<event date="2022-06-07" time="07:00:00" value="1598.32" flag="8"/>
<event date="2022-06-07" time="08:00:00" value="1598.32" flag="8"/>
<event date="2022-06-07" time="09:00:00" value="1598.32" flag="8"/>
<event date="2022-06-07" time="10:00:00" value="1598.32" flag="8"/>
<event date="2022-06-07" time="11:00:00" value="1598.32" flag="8"/>
<event date="2022-06-07" time="12:00:00" value="1598.32" flag="8"/>
<event date="2022-06-07" time="13:00:00" value="1598.32" flag="8"/>
<event date="2022-06-07" time="14:00:00" value="1598.32" flag="8"/>
<event date="2022-06-07" time="15:00:00" value="1598.32" flag="8"/>
<event date="2022-06-07" time="16:00:00" value="1598.32" flag="8"/>
<event date="2022-06-07" time="17:00:00" value="1598.32" flag="8"/>
<event date="2022-06-07" time="18:00:00" value="1598.32" flag="8"/>
<event date="2022-06-07" time="19:00:00" value="1598.32" flag="8"/>
<event date="2022-06-07" time="20:00:00" value="1598.32" flag="8"/>
<event date="2022-06-07" time="21:00:00" value="1598.32" flag="8"/>
<event date="2022-06-07" time="22:00:00" value="1598.32" flag="8"/>
<event date="2022-06-07" time="23:00:00" value="1598.32" flag="8"/>
<event date="2022-06-08" time="00:00:00" value="1598.32" flag="8"/>
<event date="2022-06-08" time="01:00:00" value="1598.32" flag="8"/>
<event date="2022-06-08" time="02:00:00" value="1598.32" flag="8"/>
<event date="2022-06-08" time="03:00:00" value="1598.32" flag="8"/>
<event date="2022-06-08" time="04:00:00" value="1598.32" flag="8"/>
<event date="2022-06-08" time="05:00:00" value="1598.32" flag="8"/>
<event date="2022-06-08" time="06:00:00" value="1598.32" flag="8"/>
<event date="2022-06-08" time="07:00:00" value="1598.32" flag="8"/>
This additional input data is mapped to the internal variable, H_observed, using the rtcDataConfig.xml.
<!--States of model at t0-->
<timeSeries id="Q_turbine">
<PITimeSeries>
<locationId>reservoir</locationId>
<parameterId>Q.turbine</parameterId>
</PITimeSeries>
Note
For further details about input file structure please see Basic Single Reservoir.
Output Data
The results of the simulation will appear in the output folder in a file called timeseries_export.xml. The data is linked to model variables via the rtcDataConfig.xml in the same way as with timeseries_import.xml.
Automatic Plotting
You can optionally include a plot_table.csv in the input folder. This is used by the rtc-tools-interfaces module (automatically installed with this package) to plot the model output. For more details on how to use this file and visualize results, see RTC-Tools-Interface.
The results of the simulation run can be seen in the plot below. Observed (constant) volumes are provided for the initial time period.
By choosing Show results from previous run, results are shown without the ReservoirModel.apply_adjust() scheme.
It can be seen that in this case the simulated volumes differ from observations.