apply_rulecurve Scheme Example
This example shows how to use the ReservoirModel.apply_rulecurve() 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. Q_out is comprised of a single component,
a turbine, Q_turbine.
The reservoir outflow should be determined to achieve the rulecurve (elevation of 1600m).
The rulecurve elevation should be achieved in single timestep with a maximum outflow of 10m3/s.
The ReservoirModel.apply_rulecurve() scheme can be applied to model these operations.
Main Model (python) File
An example of the main model file rulecurve_example.py is given below.
1"""Example that illustrates use of the rulecurve scheme."""
2from pathlib import Path
3
4from rtctools.util import run_simulation_problem
5
6from rtctools_simulation.reservoir.model import ModelConfig, ReservoirModel
7
8CONFIG = ModelConfig(base_dir=Path(__file__).parent)
9
10
11class SingleReservoir(ReservoirModel):
12 """Example single reservoir model."""
13
14 def pre(self, *args, **kwargs):
15 super().pre(*args, **kwargs)
16 self.calculate_rule_curve_deviation(periods=3, h_var="H_observed")
17 self.adjust_rulecurve(
18 periods=3,
19 extrapolate_trend_linear=False,
20 )
21
22 def apply_schemes(self):
23 """Apply schemes for controlling the reservoir."""
24
25 self.apply_rulecurve()
26
27
28# Create and run the model.
29if __name__ == "__main__":
30 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_rulecurve().
An overview of all available ReservoirModel methods
can be found in Reservoir API.
The ReservoirModel.apply_rulecurve() scheme is then applied to set the reservoir outflow through the turbine.
It will aim to match the simulated elevation to the provided rule curve. There are functions provided that
can alter the originally provided rule curve to account for differences with observations (e.g. during a
very dry year, or after some maintenance project). This will need to be computed before model simulation.
In the method ReservoirModel.pre() functions are called that accomplish certain pre-processing objectives.
In this model, we compute the deviation of the observed elevations to the provided rule curve. Based on these deviations,
the original rule curve is adjusted. In this case, we take the latest known deviation and apply that to all timesteps
after the end of H_observed. There is also functionality to provide an application time, average deviations over a
moving window, or extrapolate the deviations linearly after the application time.
Lookup tables
The ReservoirModel.apply_rulecurve() scheme uses a lookup table v_from_h. This uses the same
data as the h_from_v lookup table, the data mapping can be achieved in the lookup_tables.csv file.
name |
data |
var_in |
var_out |
|---|---|---|---|
h_from_v |
v_h.csv |
volume_m3 |
height_m |
v_from_h |
v_h.csv |
height_m |
volume_m3 |
area_from_v |
v_area.csv |
volume_m3 |
area_m2 |
qout_from_v |
qout_v.csv |
day volume_m3 |
qout_m3_per_s |
qspill_from_h |
h_qspill.csv |
height_m |
qspill_m3_per_s |
This model also uses the standard lookup table h_from_v.
For other lookup tables, defaults from the generated template files can be used.
Note
For further details about the lookup tables please see Basic Single Reservoir.
Input Data Files
The ReservoirModel.apply_rulecurve() scheme requires the following parameters from the rtcParameterConfig.xml file.
Reservoir_Qmax, upper limiting discharge while blending pool elevation (m^3), and
rule_curve_blend, the factor by which to reduce the current reservoir volume difference that will be mapped to the discharge this timestep.
rule_curve_blend > 1 will cause the elevation to converge to the rule curve over time, but not match it. In this case (blend = 1)
it aims to match the rule_curve elevation at each timestep
These parameters are supplied to the model via the rtcParameterConfig.xml input file.
<parameter id="rule_curve_blend">
<dblValue>1</dblValue>
</parameter>
<parameter id="Reservoir_Qmax">
<dblValue>10</dblValue>
</parameter>
The scheme also requires an additional input timeseries, rulecurve. This data is provided in the timeseries_import.xml.
<event date="2022-06-07" time="08:00:00" value="1598" flag="8"/>
<event date="2022-06-07" time="09:00:00" value="1598" flag="8"/>
<event date="2022-06-07" time="10:00:00" value="1598" flag="8"/>
<event date="2022-06-07" time="11:00:00" value="1598" flag="8"/>
<event date="2022-06-07" time="12:00:00" value="1598" flag="8"/>
<event date="2022-06-07" time="13:00:00" value="1598" flag="8"/>
<event date="2022-06-07" time="14:00:00" value="1598" flag="8"/>
<event date="2022-06-07" time="15:00:00" value="1598" flag="8"/>
<event date="2022-06-07" time="16:00:00" value="1598" flag="8"/>
<event date="2022-06-07" time="17:00:00" value="1598" flag="8"/>
<event date="2022-06-07" time="18:00:00" value="1598" flag="8"/>
<event date="2022-06-07" time="19:00:00" value="1598" flag="8"/>
<event date="2022-06-07" time="20:00:00" value="1598" flag="8"/>
<event date="2022-06-07" time="21:00:00" value="1598" flag="8"/>
<event date="2022-06-07" time="22:00:00" value="1598" flag="8"/>
<event date="2022-06-07" time="23:00:00" value="1598" flag="8"/>
<event date="2022-06-08" time="00:00:00" value="1598" flag="8"/>
<event date="2022-06-08" time="01:00:00" value="1598" flag="8"/>
<event date="2022-06-08" time="02:00:00" value="1598" flag="8"/>
<event date="2022-06-08" time="03:00:00" value="1598" flag="8"/>
<event date="2022-06-08" time="04:00:00" value="1598" flag="8"/>
<event date="2022-06-08" time="05:00:00" value="1598" flag="8"/>
<event date="2022-06-08" time="06:00:00" value="1598" flag="8"/>
<event date="2022-06-08" time="07:00:00" value="1598" flag="8"/>
<event date="2022-06-08" time="08:00:00" value="1598" flag="8"/>
<event date="2022-06-08" time="09:00:00" value="1598" flag="8"/>
<event date="2022-06-08" time="10:00:00" value="1598" flag="8"/>
<event date="2022-06-08" time="11:00:00" value="1598" flag="8"/>
<event date="2022-06-08" time="12:00:00" value="1598" flag="8"/>
<event date="2022-06-08" time="13:00:00" value="1598" flag="8"/>
<event date="2022-06-08" time="14:00:00" value="1598" flag="8"/>
The data is mapped to the variable, rulecurve via the rtcDataConfig.xml.
<timeSeries id="rule_curve">
<PITimeSeries>
<locationId>reservoir</locationId>
<parameterId>rulecurve</parameterId>
</PITimeSeries>
</timeSeries>
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.