Skip to content

Commit

Permalink
Merge pull request #8 from NREL-Sienna/jm/add_other_basic
Browse files Browse the repository at this point in the history
Add ACBus translation and tests
  • Loading branch information
josephmckinsey authored Jan 28, 2025
2 parents 3426c19 + 9030304 commit 15fd5c3
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 20 deletions.
2 changes: 2 additions & 0 deletions SiennaOpenAPIModels.jl/src/SiennaOpenAPIModels.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,11 @@ include("modelincludes.jl")
@batteries PiecewiseStepData
@batteries ThermalStandard
@batteries ThermalGenerationCost
@batteries ACBus

include("sienna_to_json/common.jl")
include("sienna_to_json/static_injections.jl")
include("sienna_to_json/topology.jl")

"""
Register handlers for all APIs in this module in the supplied `Router` instance.
Expand Down
4 changes: 4 additions & 0 deletions SiennaOpenAPIModels.jl/src/sienna_to_json/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,7 @@ end
function getid!(idgen::IDGenerator, component::PSY.Component)
getid!(idgen, PSY.InfrastructureSystems.get_uuid(component))
end

function getid!(::IDGenerator, ::Nothing)
nothing
end
14 changes: 14 additions & 0 deletions SiennaOpenAPIModels.jl/src/sienna_to_json/topology.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
function psy2openapi(bus::PSY.ACBus, ids::IDGenerator)
ACBus(
id = getid!(ids, bus),
number = bus.number,
name = bus.name,
bustype = string(bus.bustype),
angle = bus.angle,
magnitude = bus.magnitude,
voltage_limits = get_min_max(bus.voltage_limits),
base_voltage = bus.base_voltage,
area = getid!(ids, bus.area),
load_zone = getid!(ids, bus.load_zone),
)
end
51 changes: 31 additions & 20 deletions SiennaOpenAPIModels.jl/test/test-basic-roundtrip.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using SiennaOpenAPIModels
using OpenAPI: OpenAPI
using PowerSystemCaseBuilder: PowerSystemCaseBuilder
using PowerSystems: PowerSystems
using OpenAPI
using PowerSystemCaseBuilder
import PowerSystems
const PSY = PowerSystems
using JSON

Expand Down Expand Up @@ -47,24 +47,35 @@ function jsondiff(j1::AbstractArray{S}, j2::AbstractArray{T}) where {S,T}
return true
end

@testset "c_sys5_pjm ThermalStandard to JSON" begin
sys =
PowerSystemCaseBuilder.build_system(PowerSystemCaseBuilder.PSISystems, "c_sys5_pjm")

thermal_standard = PSY.get_component(PSY.ThermalStandard, sys, "Solitude")

ids = IDGenerator()
test_convert = SiennaOpenAPIModels.psy2openapi(thermal_standard, ids)
post_json = OpenAPI.from_json(
SiennaOpenAPIModels.ThermalStandard,
JSON.parse(OpenAPI.to_json(test_convert)),
)
@test typeof(test_convert) == typeof(post_json)
function test_roundtrip(openapi_model, data)
post_json = OpenAPI.from_json(openapi_model, JSON.parse(OpenAPI.to_json(data)))
@test typeof(data) == typeof(post_json)
@test data == post_json
@test jsondiff(
JSON.parse(OpenAPI.to_json(test_convert)),
JSON.parse(OpenAPI.to_json(data)),
JSON.parse(OpenAPI.to_json(post_json)),
)
@test test_convert == post_json
@test test_convert.id == 1
@test test_convert.bus == 2
end

@testset "c_sys5_pjm RoundTrip to JSON" begin
c_sys5 =
PowerSystemCaseBuilder.build_system(PowerSystemCaseBuilder.PSISystems, "c_sys5_pjm")
@testset "ThermalStandard to JSON" begin
thermal_standard = PSY.get_component(PSY.ThermalStandard, c_sys5, "Solitude")

test_convert = SiennaOpenAPIModels.psy2openapi(thermal_standard, IDGenerator())
test_roundtrip(SiennaOpenAPIModels.ThermalStandard, test_convert)
@test test_convert.id == 1
@test test_convert.bus == 2
end
@testset "ACBus to JSON" begin
acbus = PSY.get_bus(c_sys5, 1)
@test isa(acbus, PSY.ACBus)
test_convert = SiennaOpenAPIModels.psy2openapi(acbus, IDGenerator())
test_roundtrip(SiennaOpenAPIModels.ACBus, test_convert)
@test test_convert.id == 1
@test test_convert.number == 1
@test isnothing(test_convert.area)
@test isnothing(test_convert.load_zone)
end
end
3 changes: 3 additions & 0 deletions SiennaOpenAPIModels.jl/test/test-id-generator.jl
Original file line number Diff line number Diff line change
Expand Up @@ -12,4 +12,7 @@
@test getid!(id_generator, component) == 3
@test getid!(id_generator, component) == 3
@test getid!(id_generator, component.bus) == 4

@test isnothing(component.bus.area)
@test isnothing(getid!(id_generator, component.bus.area))
end

0 comments on commit 15fd5c3

Please sign in to comment.