Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

Commit

Permalink
starting on 3
Browse files Browse the repository at this point in the history
  • Loading branch information
claytonpbarrows committed Dec 21, 2021
1 parent 2564a5f commit cd7efe8
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 59 deletions.
54 changes: 26 additions & 28 deletions script/3_PowerSimulations_examples/02_sequential_simulations.jl
Original file line number Diff line number Diff line change
Expand Up @@ -8,57 +8,54 @@
# PowerSimulations.jl supports simulations that consist of sequential optimization problems
# where results from previous problems inform subsequent problems in a variety of ways. This
# example demonstrates some of these capabilities to represent electricity market clearing.
# This example is intended to be an extension of the
# [OperationsProblem example.](https://nbviewer.jupyter.org/github/NREL-SIIP/SIIPExamples.jl/blob/master/notebook/3_PowerSimulations_examples/01_operations_problems.ipynb)

# ## Dependencies
# Since the `OperatiotnsProblem` is the fundamental building block of a sequential
# simulation in PowerSimulations, we will build on the [OperationsProblem example](https://nbviewer.jupyter.org/github/NREL-SIIP/SIIPExamples.jl/blob/master/notebook/3_PowerSimulations_examples/01_operations_problems.ipynb)
# by sourcing it as a dependency.
using SIIPExamples
pkgpath = dirname(dirname(pathof(SIIPExamples)))
include(
joinpath(pkgpath, "test", "3_PowerSimulations_examples", "01_operations_problems.jl"),
)
# ### Hourly day-ahead system
# First, we'll create a `System` with hourly data to represent day-ahead forecasted wind,
# solar, and load profiles:
sys_DA = build_system(PSITestSystems, "modified_RTS_GMLC_DA_sys")

# ### 5-Minute system
# We had already created a `sys::System` from hourly RTS data in the OperationsProblem example.
# The RTS data also includes 5-minute resolution time series data. So, we can create another
# `System`:
# `System` to represent 15 minute ahead forecasted data for a "real-time" market:
sys_RT = build_system(PSITestSystems, "modified_RTS_GMLC_RT_sys")

# ## `OperationsProblemTemplate`s define `Stage`s
# ## `ProblemTemplate`s define stages
# Sequential simulations in PowerSimulations are created by defining `OperationsProblems`
# that represent `Stages`, and how information flows between executions of a `Stage` and
# between different `Stage`s.
# that represent stages, and how information flows between executions of a stage and
# between different stages.
#
# Let's start by defining a two stage simulation that might look like a typical day-Ahead
# and real-time electricity market clearing process.

# ### We've already defined the reference model for the day-ahead unit commitment
#set_device_model!(template_ed, GenericBattery, BookKeeping)
template_uc
# ### Day-ahead unit commitment stage
# First, we can define a unit commitment template for the day ahead problem. We can use the
# included UC template, but in this example, we'll replace the `ThermalBasicUnitCommitment`
# with the slightly more complex `ThermalStandardUnitCommitment` for the thermal generators.
template_uc = template_unit_commitment()
set_device_model!(template_uc, ThermalStandard, ThermalStandardUnitCommitment)

# ### Define the reference model for the real-time economic dispatch
# In addition to the manual specification process demonstrated in the OperationsProblem
# example, PSI also provides pre-specified templates for some standard problems:
template_ed = template_economic_dispatch()

# ### Define the `SimulationProblems`
# `OperationsProblem`s define models. The actual problem will change as the stage gets updated to represent
# ### Define the `SimulationModels`
# `DecisionModel`s define the problems that are executed in the simulation.
# The actual problem will change as the stage gets updated to represent
# different time periods, but the formulations applied to the components is constant within
# a stage. In this case, we want to define two stages with the `OperationsProblemTemplate`s
# a stage. In this case, we want to define two stages with the `ProblemTemplate`s
# and the `System`s that we've already created.
models = SimulationModels(
decision_models = [
DecisionModel(template_uc, sys, optimizer = solver, name = "UC"),
DecisionModel(template_uc, sys_DA, optimizer = solver, name = "UC"),
DecisionModel(template_ed, sys_RT, optimizer = solver, name = "ED"),
]
)
# Note that the "ED" problem has a `balance_slack_variables = true` argument. This adds slack
# variables with a default penalty of 1e6 to the nodal energy balance constraint and helps
# ensure feasibility with some performance impacts.

# ### `SimulationSequence`
# Similar to an `OperationsProblemTemplate`, the `SimulationSequence` provides a template of
# Similar to an `ProblemTemplate`, the `SimulationSequence` provides a template of
# how to execute a sequential set of operations problems.

#nb # print_struct(SimulationSequence)
Expand Down Expand Up @@ -98,7 +95,7 @@ feedforward = Dict(
# - Day ahead problems should represent 48 hours, advancing 24 hours after each execution (24-hour look-ahead)
# - Real time problems should represent 1 hour (12 5-minute periods), advancing 15 min after each execution (15 min look-ahead)
# We can adjust the time series data to reflect this structure in each `System`:
# - `transform_single_time_series!(sys, 48, Hour(1))`
# - `transform_single_time_series!(sys_DA, 48, Hour(1))`
# - `transform_single_time_series!(sys_RT, 12, Minute(15))`
#
# Now we can put it all together to define a `SimulationSequence`
Expand All @@ -112,12 +109,13 @@ DA_RT_sequence = SimulationSequence(
# ## `Simulation`
# Now, we can build and execute a simulation using the `SimulationSequence` and `Stage`s
# that we've defined.
file_path = mktempdir("rts-simulation")
sim = Simulation(
name = "rts-test",
steps = 1,
steps = 2,
models = models,
sequence = DA_RT_sequence,
simulation_folder = dirname(dirname(pathof(SIIPExamples))),
simulation_folder = mktempdir(".", cleanup = true),
)

# ### Build simulation
Expand Down
60 changes: 29 additions & 31 deletions script/3_PowerSimulations_examples/03_5_bus_mkt_simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,54 +35,52 @@ ipopt_solver = optimizer_with_attributes(Ipopt.Optimizer, "print_level" => 0)
sys_DA = build_system(SIIPExampleSystems, "5_bus_matpower_DA")
sys_RT = build_system(SIIPExampleSystems, "5_bus_matpower_RT")

# ## `OperationsProblemTemplate`s
# ## `ProblemTemplate`s

template_uc = template_unit_commitment()
template_ed = template_economic_dispatch()
template_uc = template_unit_commitment(use_slacks = true)
template_ed = template_economic_dispatch(duals = [CopperPlateBalanceConstraint])

# ### Define the Simulation Sequence

problems = SimulationProblems(
UC = OperationsProblem(
template_uc,
sys_DA,
optimizer = solver,
balance_slack_variables = true,
),
ED = OperationsProblem(
template_ed,
sys_RT,
optimizer = ipopt_solver,
constraint_duals = [:CopperPlateBalance],
),
models = SimulationModels(
decision_models = [
DecisionModel(
template_uc,
sys_DA,
name = "UC",
optimizer = solver,
),
DecisionModel(
template_ed,
sys_RT,
name = "ED",
optimizer = ipopt_solver,
),
]
)

feedforward_chronologies = Dict(("UC" => "ED") => Synchronize(periods = 24))

feedforward = Dict(
("ED", :devices, :ThermalStandard) => SemiContinuousFF(
binary_source_problem = ON,
affected_variables = [ACTIVE_POWER],
),
"ED" => [
SemiContinuousFeedforward(
component_type = ThermalStandard,
source = OnVariable,
affected_values = [ActivePowerVariable],
),
],
)

#cache = Dict("UC" => [TimeStatusChange(ThermalStandard, PSI.ON)])
intervals = Dict("UC" => (Hour(24), Consecutive()), "ED" => (Hour(1), Consecutive()))

DA_RT_sequence = SimulationSequence(
problems = problems,
intervals = intervals,
models = models,
ini_cond_chronology = InterProblemChronology(),
feedforward_chronologies = feedforward_chronologies,
feedforward = feedforward,
feedforwards = feedforward,
)

# ## `Simulation`
file_path = mkpath(joinpath(".", "5-bus-simulation"))
file_path = mktempdir( "5-bus-simulation")
sim = Simulation(
name = "5bus-test",
steps = 1,
problems = problems,
models = models,
sequence = DA_RT_sequence,
simulation_folder = file_path,
)
Expand Down

0 comments on commit cd7efe8

Please sign in to comment.