apply_poolq Scheme Example

This example shows how to use the ReservoirModel.apply_poolq() 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 reservoir outflow should be determined by a lookup table.

The ReservoirModel.apply_poolq() scheme can be applied to model these operations.

Main Model (python) File

An example of the main model file poolq_example.py is given below.

 1"""Example that illustrates use of the poolq scheme."""
 2
 3from pathlib import Path
 4
 5from rtctools.util import run_simulation_problem
 6
 7from rtctools_simulation.reservoir.model import 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.apply_poolq()
20
21
22# Create and run the model.
23if __name__ == "__main__":
24    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_poolq(). An overview of all available ReservoirModel methods can be found in Reservoir API.

In this example, the ReservoirModel.apply_poolq() scheme is then applied inside of ReservoirModel.apply_schemes() to set the reservoir outflow.

Lookup tables

This model uses the standard lookup table h_from_v.

Additionally, the reservoir outflow is determined by a lookup table with name qout_from_v. It is possible to impose a day dependence on this lookup table to create a 2D lookup table. In this example, we consider a lookup table which is constant in time. Hence, the day column is constant.

The input file, qout_v.csv looks as follows,

<base_dir>/lookup_tables/qout_v.csv

day

volume_m3

qout_m3_per_s

1

0

0

1

13439700

0.1

1

16152300

0.2

1

21700800

0.4

1

29098800

0.8

1

36620100

1.6

1

45251100

3.2

1

54375300

4.0

1

65472300

5.0

1

76815900

5.5

1

89145900

5.9

1

102147885

6.3

1

115993242

6.8

1

123239583

7.2

1

124714251

7.4

1

126197550

7.9

1

127688247

8.5

1

129188808

9.0

1

130696767

9.5

1

132213357

9.9

1

133741044

10.0

1

135279828

10.0

1

136827243

10.0

1

137606499

10.0

1

138385755

10.0

1

139954131

10.0

1

141533604

10.0

1

143122941

10.0

1

144722142

10.0

1

146331207

10.0

1

147950136

10.0

1

149580162

10.0

1

151221285

10.0

1

154533123

10.0

1

162992736

10.0

1

171696483

10.0

1

180636966

10.0

This file is mapped to the internal qout_from_v table via the lookup_tables.csv file

<base_dir>/lookup_tables/lookup_tables.csv

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

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

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.