{
"cells": [
{
"cell_type": "markdown",
"id": "9e1fd933",
"metadata": {},
"source": [
""
]
},
{
"cell_type": "markdown",
"id": "70d246a2",
"metadata": {},
"source": [
"(simulation)=\n",
"# Simulation in SHOP"
]
},
{
"cell_type": "markdown",
"id": "66b2ed54",
"metadata": {},
"source": [
"## Introduction\n",
"\n",
"The main purpose of SHOP is to build and solve an optimization problem. However, SHOP also includes a simulator that does not involve trying to optimize any decisions related to hydropower scheduling. The simulator takes all decisions as input, such as power generation schedules, and calculates the physical response of the hydropower system with a very fine time resolution. All non-linear physical relationships, such as tunnel network flow and the hydropower production function, can be accurately handled in the simulator since there is no optimization problem to solve. A simulation is also typically much faster than an optimization run. This is a powerful tool that is mainly used for two things:\n",
"1) Validating that production plans and other operational decisions are physically feasible, see the [simulated production plan example](sim-prod-plan-example).\n",
"2) Calculating historical inflow to all reservoirs based on historical production schedules and reservoir levels, see the the [simulated inflow example](sim-inflow-example). \n",
"\n",
"Note that the simulator does not consider any operating constraints that are normally included in a SHOP optimization run (ramping constraints, tactical reservoir limits, etc.), it will simply simulate the physical response of the system given the input data and topology.\n",
"\n",
"The commands and input attributes that constitute the SHOP simulator are licensed under the **SHOP_SIMULATION** license.\n",
"\n",
"## How it works\n",
"The SHOP simulator is based on a simple forward Euler method for calculating the [](reservoir) volume trajectories based on the input unit data (production schedules etc.), and was first described in {cite}`Skjelbred2018`. Simply put, the flow through all [generators](generator), [pumps](pump), [tunnels](tunnel), and [rivers](river) are first calculated based on the unit schedules and initial reservoir levels of the system. This may involve calculating generator discharge from generator production and simulating tunnel network flow. The reservoir volumes $V$ are then updated by assuming the calculated flows $Q$ are constant over a short time interval $\\Delta t$:\n",
"\n",
"$V_{t+1} = V_t + \\Delta t\\cdot Q^{\\textup{net}}_t(V_t).$\n",
"\n",
"New flows are then calculated for the next time step based on updated reservoir states and input data. This approach is possible since the amount of production/discharge on each unit in the system is fixed before simulation. Simulating a production plan for the whole system will then yield simulated reservoir trajectories that will likely deviate slightly from the optimization that originally created the production plan. The simulator could then also show what will happen to the physical system if the optimized production plan is slightly changed due to intra-day trading or reserve activation.\n",
"\n",
"Using the simulator for inflow calculations requires historical reservoir level measurements. The historical reservoir levels can be compared to the simulated levels with no inflow, and the difference in volume must be the resulting historical inflow.\n",
"\n",
"## Simulation time resolution\n",
"The simulator works with a much finer time resolution compared to the typical SHOP optimization run, and the default internal time step length of the simulator is 20 seconds. There are three different time scales to consider in the simulator: the input data time resolution, the resolution of the internal simulation, and the resolution of the output attributes.\n",
"\n",
"### Internal time scale\n",
"The short step size of the internal simulation calculations decide the internal time resolution. The default value of 20 seconds can be changed with the command [set simtimestep \\](set_simtimestep) before the simulation starts. This could be necessary when simulating tunnel networks where tiny [creek intakes](creek-intake-example) are coupled to larger reservoirs, as the flow and pressure changes rapidly. Lowering the internal step size will increase calculation time of the simulator, while increasing it will impact the accuracy of the results. The internal time step size is constant over the whole simulation horizon.\n",
"\n",
"### Input time scale\n",
"The start and end times of the simulation horizon and the time resolution of the input data is the same as the regular optimization resolution that has a defined start time, end time, time unit, and time step length. The following section describes the required input data for the various objects before performing a simulation, and the input TXY attributes are given in the input time scale. If the input time scale is 24 hours long with a 15 minute resolution, there will be 45 internal simulation time steps of length 20 seconds for each time step in the input data. This allows the simulator to calculate the changes in reservoir trajectories, generator discharge, etc over each 15 min interval.\n",
"\n",
"### Output time scale\n",
"The output attributes from the simulation are calculated for each internal time step. Since this can create a lot of data for simulations over longer time periods, the default behaviour is to save hourly output data in the form of TXYs. The calculated output attributes (e.g. [](generator:sim_production)) are therefore averaged over the output time scale, except for the reservoir levels that are instantaneous values at the interval changes. It is possible to change the output time step length of the simulator in the [start shopsim /\\