Skip to content

Commit

Permalink
Bump to PSY3, PF 0.6 and PNM 0.9 (#359)
Browse files Browse the repository at this point in the history
* bump toml to PSY3

* update bustypes and ACBus

* update solve_ac_powerflow

* update inverter models dispatch to include limiter

* update docs

* add utils to remove

* update test cases ACBus

* update raw files to use 0 angle at slack

* update test data for Ybuses

* update data utils to use ACBus

* update init conditions if slack angle is zero

* remove reactive limits of Source
  • Loading branch information
rodrigomha committed Dec 12, 2023
1 parent 4a7cca9 commit 94db9e1
Show file tree
Hide file tree
Showing 39 changed files with 291 additions and 166 deletions.
10 changes: 7 additions & 3 deletions Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,14 @@ FastClosures = "^0.3"
ForwardDiff = "~v0.10"
InfrastructureSystems = "^1.21"
NLsolve = "4"
PowerSystems = "^2.4"
PowerFlows = "^0.3"
PowerNetworkMatrices = "^0.7"
PowerSystems = "^3"
PowerFlows = "^0.6"
PowerNetworkMatrices = "^0.9"
PrettyTables = "1, 2"
SciMLBase = "^1.45"
TimerOutputs = "~0.5"
LinearAlgebra = "1"
Logging = "1"
Random = "1"
SparseArrays = "1"
julia = "^1.6"
4 changes: 2 additions & 2 deletions docs/src/tutorials/tutorial_continuation_pf.md
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ for p in P_range
q_power = power * tan(acos(load_pf))
set_reactive_power!(load, q_power)
# Run Power Flow
status = solve_powerflow!(sys_static)
status = solve_ac_powerflow!(sys_static)
if !status
# Finish the loop if the power flow fails
print("Power Flow failed at p = $(power)")
Expand Down Expand Up @@ -143,7 +143,7 @@ for p in P_range
q_power = power * tan(acos(load_pf))
set_reactive_power!(load, q_power)
# Run Power Flow
status = solve_powerflow!(sys_static)
status = solve_ac_powerflow!(sys_static)
if !status
# Finish the loop if the power flow fails
print("Power Flow failed at p = $(power)")
Expand Down
2 changes: 1 addition & 1 deletion docs/src/tutorials/tutorial_dynamic_data.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ This system does not have an injection device in bus 1 (the reference bus).
We can add a source with small impedance directly as follows:

```@repl dyn_data
slack_bus = [b for b in get_components(Bus, sys) if get_bustype(b) == BusTypes.REF][1]
slack_bus = [b for b in get_components(ACBus, sys) if get_bustype(b) == ACBusTypes.REF][1]
inf_source = Source(
name = "InfBus", #name
available = true, #availability
Expand Down
4 changes: 2 additions & 2 deletions docs/src/tutorials/tutorial_inverter_modeling.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ Using `PowerSimulationsDynamics` tools for exploring the results, we can plot al
```@repl inv_sys
result = read_results(sim)
p = plot();
for b in get_components(Bus, sys)
for b in get_components(ACBus, sys)
voltage_series = get_voltage_magnitude_series(result, get_number(b))
plot!(
p,
Expand Down Expand Up @@ -226,7 +226,7 @@ Using `PowerSimulationsDynamics` tools for exploring the results, we can plot al
```@repl inv_sys
result = read_results(sim)
p = plot();
for b in get_components(Bus, sys)
for b in get_components(ACBus, sys)
voltage_series = get_voltage_magnitude_series(result, get_number(b))
plot!(
p,
Expand Down
8 changes: 4 additions & 4 deletions src/base/bus_categories.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ struct PQBus <: BusCategory end
struct SLACKBus <: BusCategory end

const BUS_MAP = Dict(
PSY.BusTypes.REF => SLACKBus,
PSY.BusTypes.PV => PVBus,
PSY.BusTypes.SLACK => SLACKBus,
PSY.BusTypes.PQ => PQBus,
PSY.ACBusTypes.REF => SLACKBus,
PSY.ACBusTypes.PV => PVBus,
PSY.ACBusTypes.SLACK => SLACKBus,
PSY.ACBusTypes.PQ => PQBus,
)
4 changes: 2 additions & 2 deletions src/base/frequency_reference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ function get_frequency_reference!(
if length(dyn_devices) < 1
throw(
IS.ConflictingInputsError(
"ConstantFrequency model requires at least one generation unit at the Bus BusTypes.REF",
"ConstantFrequency model requires at least one generation unit at the Bus ACBusTypes.REF",
),
)
end
Expand Down Expand Up @@ -59,7 +59,7 @@ function get_frequency_reference!(
elseif length(ref_devices) < 1
throw(
IS.ConflictingInputsError(
"ReferenceBus model requires at least one bus of type BusTypes.REF with a DynamicInjection or Source device connected to it",
"ReferenceBus model requires at least one bus of type ACBusTypes.REF with a DynamicInjection or Source device connected to it",
),
)
elseif length(ref_devices) != 1
Expand Down
2 changes: 1 addition & 1 deletion src/base/simulation_initialization.jl
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ function power_flow_solution!(
sys::PSY.System,
inputs::SimulationInputs,
)
res = PF.solve_powerflow!(sys)
res = PF.solve_ac_powerflow!(sys)
if !res
@error("PowerFlow failed to solve")
return BUILD_FAILED
Expand Down
5 changes: 4 additions & 1 deletion src/initialization/inverter_components/init_DCside.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,17 @@
function initialize_DCside!(
device_states,
static::PSY.StaticInjection,
dynamic_device::DynamicWrapper{PSY.DynamicInverter{C, O, IC, PSY.FixedDCSource, P, F}},
dynamic_device::DynamicWrapper{
PSY.DynamicInverter{C, O, IC, PSY.FixedDCSource, P, F, L},
},
inner_vars::AbstractVector,
) where {
C <: PSY.Converter,
O <: PSY.OuterControl,
IC <: PSY.InnerControl,
P <: PSY.FrequencyEstimator,
F <: PSY.Filter,
L <: Union{Nothing, PSY.InverterLimiter},
}

#Update inner_vars
Expand Down
9 changes: 6 additions & 3 deletions src/initialization/inverter_components/init_converter.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function initialize_converter!(
device_states,
static::PSY.StaticInjection,
dynamic_device::DynamicWrapper{
PSY.DynamicInverter{PSY.AverageConverter, O, IC, DC, P, F},
PSY.DynamicInverter{PSY.AverageConverter, O, IC, DC, P, F, L},
},
inner_vars::AbstractVector,
) where {
Expand All @@ -11,13 +11,14 @@ function initialize_converter!(
DC <: PSY.DCSource,
P <: PSY.FrequencyEstimator,
F <: PSY.Filter,
L <: Union{Nothing, PSY.InverterLimiter},
} end

function initialize_converter!(
device_states,
static::PSY.StaticInjection,
dynamic_device::DynamicWrapper{
PSY.DynamicInverter{PSY.RenewableEnergyConverterTypeA, O, IC, DC, P, F},
PSY.DynamicInverter{PSY.RenewableEnergyConverterTypeA, O, IC, DC, P, F, L},
},
inner_vars::AbstractVector,
) where {
Expand All @@ -26,6 +27,7 @@ function initialize_converter!(
DC <: PSY.DCSource,
P <: PSY.FrequencyEstimator,
F <: PSY.Filter,
L <: Union{Nothing, PSY.InverterLimiter},
}
#Get inner vars
V_R = inner_vars[Vr_cnv_var]
Expand Down Expand Up @@ -71,7 +73,7 @@ function initialize_converter!(
device_states,
static::PSY.StaticInjection,
dynamic_device::DynamicWrapper{
PSY.DynamicInverter{PSY.RenewableEnergyVoltageConverterTypeA, O, IC, DC, P, F},
PSY.DynamicInverter{PSY.RenewableEnergyVoltageConverterTypeA, O, IC, DC, P, F, L},
},
inner_vars::AbstractVector,
) where {
Expand All @@ -80,6 +82,7 @@ function initialize_converter!(
DC <: PSY.DCSource,
P <: PSY.FrequencyEstimator,
F <: PSY.Filter,
L <: Union{Nothing, PSY.InverterLimiter},
}
#Get inner vars
Vr_filter = inner_vars[Vr_filter_var]
Expand Down
6 changes: 4 additions & 2 deletions src/initialization/inverter_components/init_filter.jl
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
function initialize_filter!(
device_states,
static::PSY.StaticInjection,
dynamic_device::DynamicWrapper{PSY.DynamicInverter{C, O, IC, DC, P, PSY.LCLFilter}},
dynamic_device::DynamicWrapper{PSY.DynamicInverter{C, O, IC, DC, P, PSY.LCLFilter, L}},
inner_vars::AbstractVector,
) where {
C <: PSY.Converter,
O <: PSY.OuterControl,
IC <: PSY.InnerControl,
DC <: PSY.DCSource,
P <: PSY.FrequencyEstimator,
L <: Union{Nothing, PSY.InverterLimiter},
}
#PowerFlow Data
P0 = PSY.get_active_power(static)
Expand Down Expand Up @@ -92,14 +93,15 @@ end
function initialize_filter!(
device_states,
static::PSY.StaticInjection,
dynamic_device::DynamicWrapper{PSY.DynamicInverter{C, O, IC, DC, P, PSY.RLFilter}},
dynamic_device::DynamicWrapper{PSY.DynamicInverter{C, O, IC, DC, P, PSY.RLFilter, L}},
inner_vars::AbstractVector,
) where {
C <: PSY.Converter,
O <: PSY.OuterControl,
IC <: PSY.InnerControl,
DC <: PSY.DCSource,
P <: PSY.FrequencyEstimator,
L <: Union{Nothing, PSY.InverterLimiter},
}
#PowerFlow Data
P0 = PSY.get_active_power(static)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
function initialize_frequency_estimator!(
device_states,
static::PSY.StaticInjection,
dynamic_device::DynamicWrapper{PSY.DynamicInverter{C, O, IC, DC, PSY.KauraPLL, F}},
dynamic_device::DynamicWrapper{PSY.DynamicInverter{C, O, IC, DC, PSY.KauraPLL, F, L}},
inner_vars::AbstractVector,
) where {
C <: PSY.Converter,
O <: PSY.OuterControl,
IC <: PSY.InnerControl,
DC <: PSY.DCSource,
F <: PSY.Filter,
L <: Union{Nothing, PSY.InverterLimiter},
}
Vr_filter = inner_vars[Vr_filter_var]
Vi_filter = inner_vars[Vi_filter_var]
Expand Down Expand Up @@ -66,7 +67,7 @@ function initialize_frequency_estimator!(
device_states,
static::PSY.StaticInjection,
dynamic_device::DynamicWrapper{
PSY.DynamicInverter{C, O, IC, DC, PSY.ReducedOrderPLL, F},
PSY.DynamicInverter{C, O, IC, DC, PSY.ReducedOrderPLL, F, L},
},
inner_vars::AbstractVector,
) where {
Expand All @@ -75,6 +76,7 @@ function initialize_frequency_estimator!(
IC <: PSY.InnerControl,
DC <: PSY.DCSource,
F <: PSY.Filter,
L <: Union{Nothing, PSY.InverterLimiter},
}
Vr_filter = inner_vars[Vr_filter_var]
Vi_filter = inner_vars[Vi_filter_var]
Expand Down Expand Up @@ -128,7 +130,7 @@ function initialize_frequency_estimator!(
device_states,
static::PSY.StaticInjection,
dynamic_device::DynamicWrapper{
PSY.DynamicInverter{C, O, IC, DC, PSY.FixedFrequency, F},
PSY.DynamicInverter{C, O, IC, DC, PSY.FixedFrequency, F, L},
},
inner_vars::AbstractVector,
) where {
Expand All @@ -137,6 +139,7 @@ function initialize_frequency_estimator!(
IC <: PSY.InnerControl,
DC <: PSY.DCSource,
F <: PSY.Filter,
L <: Union{Nothing, PSY.InverterLimiter},
}
#Get parameters
pll_control = PSY.get_freq_estimator(dynamic_device)
Expand Down
9 changes: 6 additions & 3 deletions src/initialization/inverter_components/init_inner.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ function initialize_inner!(
device_states,
static::PSY.StaticInjection,
dynamic_device::DynamicWrapper{
PSY.DynamicInverter{C, O, PSY.VoltageModeControl, DC, P, F},
PSY.DynamicInverter{C, O, PSY.VoltageModeControl, DC, P, F, L},
},
inner_vars::AbstractVector,
) where {
Expand All @@ -11,6 +11,7 @@ function initialize_inner!(
DC <: PSY.DCSource,
P <: PSY.FrequencyEstimator,
F <: PSY.Filter,
L <: Union{Nothing, PSY.InverterLimiter},
}

#Obtain external states inputs for component
Expand Down Expand Up @@ -146,7 +147,7 @@ function initialize_inner!(
device_states,
static::PSY.StaticInjection,
dynamic_device::DynamicWrapper{
PSY.DynamicInverter{C, O, PSY.CurrentModeControl, DC, P, F},
PSY.DynamicInverter{C, O, PSY.CurrentModeControl, DC, P, F, L},
},
inner_vars::AbstractVector,
) where {
Expand All @@ -155,6 +156,7 @@ function initialize_inner!(
DC <: PSY.DCSource,
P <: PSY.FrequencyEstimator,
F <: PSY.Filter,
L <: Union{Nothing, PSY.InverterLimiter},
}

#Obtain external states inputs for component
Expand Down Expand Up @@ -231,7 +233,7 @@ function initialize_inner!(
device_states,
static::PSY.StaticInjection,
dynamic_device::DynamicWrapper{
PSY.DynamicInverter{C, O, PSY.RECurrentControlB, DC, P, F},
PSY.DynamicInverter{C, O, PSY.RECurrentControlB, DC, P, F, L},
},
inner_vars::AbstractVector,
) where {
Expand All @@ -240,6 +242,7 @@ function initialize_inner!(
DC <: PSY.DCSource,
P <: PSY.FrequencyEstimator,
F <: PSY.Filter,
L <: Union{Nothing, PSY.InverterLimiter},
}
# Obtain inner variables for component
Vr_filter = inner_vars[Vr_filter_var]
Expand Down
10 changes: 10 additions & 0 deletions src/initialization/inverter_components/init_outer.jl
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ function initialize_outer!(
DC,
P,
F,
L,
},
},
inner_vars::AbstractVector,
Expand All @@ -18,6 +19,7 @@ function initialize_outer!(
DC <: PSY.DCSource,
P <: PSY.FrequencyEstimator,
F <: PSY.Filter,
L <: Union{Nothing, PSY.InverterLimiter},
}

#Obtain external states inputs for component
Expand Down Expand Up @@ -74,6 +76,7 @@ function initialize_outer!(
DC,
P,
F,
L,
},
},
inner_vars::AbstractVector,
Expand All @@ -83,6 +86,7 @@ function initialize_outer!(
DC <: PSY.DCSource,
P <: PSY.FrequencyEstimator,
F <: PSY.Filter,
L <: Union{Nothing, PSY.InverterLimiter},
}

#Obtain external states inputs for component
Expand Down Expand Up @@ -138,6 +142,7 @@ function initialize_outer!(
DC,
P,
F,
L,
},
},
inner_vars::AbstractVector,
Expand All @@ -147,6 +152,7 @@ function initialize_outer!(
DC <: PSY.DCSource,
P <: PSY.FrequencyEstimator,
F <: PSY.Filter,
L <: Union{Nothing, PSY.InverterLimiter},
}

#Obtain external states inputs for component
Expand Down Expand Up @@ -201,6 +207,7 @@ function initialize_outer!(
DC,
P,
F,
L,
},
},
inner_vars::AbstractVector,
Expand All @@ -210,6 +217,7 @@ function initialize_outer!(
DC <: PSY.DCSource,
P <: PSY.FrequencyEstimator,
F <: PSY.Filter,
L <: Union{Nothing, PSY.InverterLimiter},
}

#Obtain external states inputs for component
Expand Down Expand Up @@ -283,6 +291,7 @@ function initialize_outer!(
DC,
P,
F,
L,
},
},
inner_vars::AbstractVector,
Expand All @@ -292,6 +301,7 @@ function initialize_outer!(
DC <: PSY.DCSource,
P <: PSY.FrequencyEstimator,
F <: PSY.Filter,
L <: Union{Nothing, PSY.InverterLimiter},
}
# Read inner vars
Vr_filter = inner_vars[Vr_filter_var]
Expand Down
Loading

0 comments on commit 94db9e1

Please sign in to comment.