# Adding reservoir control curves and demand savings (reductions)

## Introduction

Control curves can be used to implement a demand reductions when reservoir levels go below certain thresholds. This represents the implementation of temporary demand management measures. In this exercise the demand will be incrementally reduced as the reservoir goes below certain storage thresholds. This exercise will demonstrate the[ Control Curve Index Parameter](https://water-strategy.gitbook.io/water-strategy/modelling-fundamentals/parameters/control-curve-index-parameter), the [Indexd Array Parameter](https://water-strategy.gitbook.io/water-strategy/modelling-fundamentals/parameters/indexed-array-parameter) as well as the [Aggregated Parameter](https://water-strategy.gitbook.io/water-strategy/modelling-fundamentals/parameters/aggregated-parameter) as well as parameter nesting.

## Clone the scenario and define a control curve

1. Clone the **'Balanced sources'** scenario and name the new one **'Demand reductions'**
2. First we will define a **control curve** which uses storage volume thresholds to progressively reduce demand to model demand restrictions being placed on a demand. The first curve is a [Monthly Profile](https://water-strategy.gitbook.io/water-strategy/modelling-fundamentals/parameters/monthly-profile) (60% in come months and 45% in others) allowing for seasonal changes while the two subsequent curves are [Constants ](https://water-strategy.gitbook.io/water-strategy/modelling-fundamentals/parameters/constant)(40% and 10% of reservoir storage capacity).

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2FYS4OBMtVpQHvAN9UnI1C%2Fimage.png?alt=media&#x26;token=c8a31753-6f34-4202-91c6-2b5fa0b93f18" alt=""><figcaption><p>Reservoir control curve</p></figcaption></figure>

The Control Curve will be defined in the **Parameters** tab. In the Parameters tab add a **Pywr\_Parameter**.

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2FxCDf0rs0qK54MyDjzwBR%2Fimage.png?alt=media&#x26;token=6bc3de9d-d471-4c5c-9e76-5ba0145a8dbc" alt="" width="375"><figcaption><p>Add a Pywr_Parameter</p></figcaption></figure>

Name the parameter **'storage control curve'** and press *Enter***.**

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2FE3bzw65NrFWT0NMgaLsC%2Fimage.png?alt=media&#x26;token=9a189adf-b82c-4905-88b0-5dac48b6da93" alt="" width="335"><figcaption><p><strong>storage control curve</strong></p></figcaption></figure>

Paste in the following JSON code snippet below. Please note how the `"Example reservoir"` is referenced in the `"storage_node"`attribute.

```
{
	"type": "controlcurveindexparameter",
	"storage_node": "Example reservoir",
	"control_curves": [
		{
			"type": "monthlyprofileparameter",
			"values": [
				0.45,
				0.45,
				0.45,
				0.45,
				0.45,
				0.45,
				0.45,
				0.45,
				0.45,
				0.45,
				0.6,
				0.6
			]
		},
		{
			"type": "constant",
			"value": 0.4
		},
		{
			"type": "constant",
			"value": 0.1
		}
	],
	"__recorder__": {
		"timeseries": true
	}
}
```

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2F9oG8GYLLs76cbuWIcwO5%2Fimage.png?alt=media&#x26;token=9e203750-ae0f-4884-838a-023b64d807f0" alt=""><figcaption><p>Paste the code and save</p></figcaption></figure>

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2F1cbvGXuBO4gwlAq9uWMl%2Fimage.png?alt=media&#x26;token=0821ddef-1a14-4210-9a39-db6ace0f101e" alt=""><figcaption><p>Select recording timeseries and save</p></figcaption></figure>

At each time step the [Control Curve Index Parameter](https://water-strategy.gitbook.io/water-strategy/modelling-fundamentals/parameters/control-curve-index-parameter) will return an Index Value as shown below:

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2FhdQ9iiNgKavrsdqkYb95%2Fimage.png?alt=media&#x26;token=89b83b17-18d1-420f-8b5a-5be94edb8562" alt=""><figcaption><p>Reservoir control curve</p></figcaption></figure>

These Indices can be associated to a Demand Factor which will be defined using an [Indexed Array Parameter](https://water-strategy.gitbook.io/water-strategy/modelling-fundamentals/parameters/indexed-array-parameter). The Demand factor will be used to reduce demand when each control curve threshold is passed.

## Associate demand factor

1. We will associate the following **Demand Factors** to the different control curve failure levels:

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2FWgNrx846WacginEpch9l%2Fimage.png?alt=media&#x26;token=91e0cfff-d66b-4b71-8dd5-2b0f52e175d0" alt=""><figcaption><p>Reservoir control curve</p></figcaption></figure>

These will reduce demand to 90%, 80% and 50% of the Baseline demand corresponding to 10%, 20% and 50% demand reductions.

2. Create a new **Pywr\_Parameter**

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2Frx1MRvK9UVDfyvfQ7wld%2Fimage.png?alt=media&#x26;token=e69f04c8-0fd3-4b97-bb1e-4f9ab58ad97e" alt=""><figcaption><p>Create a new Pywr_Parameter</p></figcaption></figure>

3. Name the parameter **'control curve demand factor'** and press *Enter***.**

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2FJANfc1Y8d5Z1GaSDI7Fo%2Fimage.png?alt=media&#x26;token=a87d8bc7-d83c-4224-9020-2ae48f6a9ee7" alt="" width="275"><figcaption><p>Name the parameter</p></figcaption></figure>

4. Paste in the following JSON code snippet below. Please note how the`"`storage `control curve"` is referenced in the `"index_parameter"`attribute.

```
{
	"type": "indexedarrayparameter",
	"index_parameter": "storage control curve",
	"params": [
		1,
		0.9,
		0.8,
		0.5
	],
}
```

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2FlCzHmBxcw88cEFoG7vvY%2Fimage.png?alt=media&#x26;token=98dcd685-20b8-44b9-a31c-16919aa63443" alt=""><figcaption><p>Paste the code and save</p></figcaption></figure>

The `Params`attribute takes in either scalars or Pywr parameters and the index of the array corresponds to index in the Parameter referenced in the **index\_parameter** which in this case is the control curve.

5. Select to make this Parameter output.

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2F0evzF9SqYOqfWdHzjOxC%2Fimage.png?alt=media&#x26;token=dcb2c24a-51a3-4e07-8b51-fbf0a36368b7" alt=""><figcaption><p>Select recording timeseries and save</p></figcaption></figure>

## Define the baseline demand

Next we will define the baseline demand. This is the demand that the reservoir has before any reductions are implemented. In previous tutorial, the Example demand is defined as a scalar (0.1) on the Max\_flow attribute of the Example demand output node:

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2FYryfjGQmRk4HNeCsnNlD%2Fimage.png?alt=media&#x26;token=9ca28658-a9a9-4320-a4dd-16f1fb9a14c5" alt=""><figcaption><p>Example demand</p></figcaption></figure>

We will replace this with a **Parameter reference.**

1. First, we will define the baseline demand using a **Constant Parameter.**

Add a new **Pywr\_parameter.**

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2FI4KDtSZHzjmKYamDLNZ5%2Fimage.png?alt=media&#x26;token=df411955-1348-4b2c-bc36-98d1f389ec7b" alt=""><figcaption><p>Add a new Pywr_parameter</p></figcaption></figure>

And name it **Baseline demand** and press *Enter*.

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2F3D2W56WZSD1pOr3RNYVC%2Fimage.png?alt=media&#x26;token=8ccabe84-0c9b-4776-a366-2fe071c1bc6d" alt="" width="274"><figcaption><p>Name the new Pywr_parameter</p></figcaption></figure>

2. The baseline demand will remain 0.1 Mm3/day. Copy and paste the JSON code snippet into the JSON tab.

```
{
	"type": "constant",
	"value": 0.1
}
```

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2FToCh4UpDVOJy5RcAZsFx%2Fimage.png?alt=media&#x26;token=645fdaf6-1207-4845-bd7e-4489a3b9b8c2" alt=""><figcaption><p>Paste the code and save</p></figcaption></figure>

At each time step, the modeled demand will be the Baseline Demand multiplied by the Demand Factor:

`Timestep demand = Baseline demand x Demand Factor`

## Calculate **timestep demand**

This can be accomplished by using an [Aggregated Parameter](https://water-strategy.gitbook.io/water-strategy/modelling-fundamentals/parameters/aggregated-parameter).

1. Add a new **Pywr\_parameter.**

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2FT5MDtCixeO6oFIxndZdy%2Fimage.png?alt=media&#x26;token=0159eb3f-2f7e-4ac6-92c3-4c0a4f2cb36d" alt=""><figcaption><p>Add a new Pywr_parameter</p></figcaption></figure>

Name the new parameter **'timestep demand'**

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2Fa9pCQ0F5Z7zZAndDW0kW%2Fimage.png?alt=media&#x26;token=a6d14f5e-e956-40ae-a603-76f469d01bd5" alt="" width="274"><figcaption><p>Name the new parameter</p></figcaption></figure>

2. Copy and paste the JSON code snippet into the JSON tab.

```
{
	"type": "AggregatedParameter",
	"agg_func": "product",
	"parameters": [
		"baseline demand",
		"control curve demand factor"
	]
}
```

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2FA5etUqHKj00ZcpqsA1wV%2Fimage.png?alt=media&#x26;token=8550ee4c-a5d4-49de-8219-f2f238948585" alt=""><figcaption><p>Paste the code and save</p></figcaption></figure>

Select to make this Paramter value be output in each time step.

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2FmKeHGx4CdXloMrLoXxa3%2Fimage.png?alt=media&#x26;token=85650524-0ca3-4a3a-8495-0544860b005e" alt=""><figcaption><p>Select recording the timeserries</p></figcaption></figure>

3. The **'timestep demand'** defines the demand at each time step taking into account the state (i.e. real-time storage) in the Reservoir.

This **Parameter** needs to be referenced on the **max\_flow** attribute of the Demand node.

4. Click on the Demand node and write or paste '**timestep demand'** in the max\_flow attribute replacing the scalar value (0.1).

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2F5ahaW2yNsjgUy6LzXScq%2Fimage.png?alt=media&#x26;token=36b857ff-b466-46a8-b145-893f3cbdbfcb" alt=""><figcaption><p>Enter max_flow attribute name</p></figcaption></figure>

Please note, if the Parameter name does not save, change the type of the entry to **"Descriptor"**.

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2FkNzJjhWe0PfgKooZrqsx%2Fimage.png?alt=media&#x26;token=24b7f660-cb52-49f1-92b4-e79ed4d72969" alt=""><figcaption><p>Click on edit the max_flow</p></figcaption></figure>

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2Fx5dnaplIToRkAqr4WVny%2Fimage.png?alt=media&#x26;token=9d6c28b8-ce4f-4e7f-ae4e-d0893c2afa01" alt=""><figcaption><p>Select DESCRIPTOR</p></figcaption></figure>

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2FDJ0IqCl9YyG8s2zMb3LF%2Fimage.png?alt=media&#x26;token=84d46c9f-e04a-4193-bd2f-aee1359732f1" alt=""><figcaption><p>Enter the name</p></figcaption></figure>

Don't forget to save the changes.

## Run the model and view the results

1. **Run** the model.

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2FWJxhpw2fUKOnHqXFiyST%2Fimage.png?alt=media&#x26;token=111112ca-a204-4c0e-a1db-dc6f46525283" alt="" width="327"><figcaption><p>Click on to run the model</p></figcaption></figure>

2. View the **simulated** \_volume on the Reservoir

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2FclB7lRmdtbyx6pu9ekwm%2Fimage.png?alt=media&#x26;token=2c22e032-0f57-4c87-a31d-bfb4a340c6a8" alt=""><figcaption><p>Simulated _volume on the Reservoir</p></figcaption></figure>

You can **zoom** into the drought, for example this is the drought that occurred in 2042-2044.

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2FunU14odanZ9I66NnuCsz%2Fimage.png?alt=media&#x26;token=865ed9f0-535d-47dd-8f4d-dc062d5db269" alt=""><figcaption><p>Simulated _volume on the Reservoir in 2042-2044</p></figcaption></figure>

In the the Scenario with demand reductions, the Reservoir did not go to as low of storage (9.4 vs 8.17 Mm3).

3. Click on the simulated\_flow of the Demand node. The demand reductions can be seen.

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2FBL6IxBG4gNhnsJv6pBx7%2Fimage.png?alt=media&#x26;token=b41d14ba-e9c9-4157-bcf7-efb795bf6077" alt=""><figcaption><p>simulated_flow of the Demand node</p></figcaption></figure>

4. You can view the control cure parameter output by clicking on the **Network Data** view.

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2F5N5CJEGIECT7bZbp8uX1%2Fimage.png?alt=media&#x26;token=aa18b9bd-5666-420a-8bb3-43d95e4b71b6" alt=""><figcaption><p>Click to view the control cure parameter output</p></figcaption></figure>

Clicking on **simulated\_storage control curve** shows what index the storage control curve is returning at each time step. This varies between 0-2.

<figure><img src="https://2363830371-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FODCd8VK2OOl9jOdp5KFf%2Fuploads%2F7vHgxoh07Jb68gNDkeS7%2Fimage.png?alt=media&#x26;token=f7460241-cf1e-49c7-b92a-6966f33f2c0d" alt=""><figcaption><p>Control cure parameter output</p></figcaption></figure>

## Exercise <a href="#exercise" id="exercise"></a>

1. Increase the Baseline Demand Parameter. How high can baseline demand be before the reservoir fully empties?
