apply_minq Scheme Example
This example shows how to use the ReservoirModel.apply_minq() 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.
The outflow is determined in such a way that the peak outflow is minimum
while making sure that the elevation remains within given bounds.
The ReservoirModel.apply_minq() scheme
can be applied to calculate an optimal outflow and apply it to the simuatlion.
Main Model (python) File
An example of the main model file minq_example.py is given below.
1"""Example illustrating the minq 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 Reservoir(ReservoirModel):
12 """Class for demonstrating the minq scheme."""
13
14 def apply_schemes(self):
15 """Apply minq within a given time period."""
16 self.apply_minq(h_min=0, h_max=40.0, h_target="rule_curve")
17
18
19# Create and run the model.
20if __name__ == "__main__":
21 model = run_simulation_problem(Reservoir, config=CONFIG, previous_run_plot_config=None)
22 results = model.extract_results()
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 Reservoir(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_minq().
An overview of all available ReservoirModel methods
can be found in Reservoir API.
In this example, the ReservoirModel.apply_schemes() method
calls the apply_minq method.
If no optimal outflow has been calculated yet,
this method will calculate the optimal outflow (i.e. outflow with a minimal peak)
given upper bounds on the elevation (h_min, h_max)
and a target elevation (h_target).
It will then use this optimized outflow to set the outflow of the simulation.
The upper and lower bounds for the elevation are set in this example to 0 and 40, respectively,
and the target elevation is set to the timeseries “rule_curve”.
This timeseries is given via the timeseries_import.xml file.
Lookup tables
This model uses the standard lookup tables h_from_v.
Note
For further details about the lookup tables please see Basic Single Reservoir.
Input Data Files
The “rule_curve” timeseries is supplied to the model via the timeseries_import.xml input file.
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.