diff --git a/Project.toml b/Project.toml index f09b8b9..d3836ec 100644 --- a/Project.toml +++ b/Project.toml @@ -3,6 +3,11 @@ uuid = "20cea600-32a0-4edf-8dad-2de078d2a706" authors = ["Nick Laws and contributors"] version = "0.1.0" +[deps] +CommonOPF = "dad7ea18-2b21-482e-81c1-e84414cc4b03" +JuMP = "4076af6c-e467-56ae-b986-b466b2749572" +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + [compat] julia = "1.10" diff --git a/src/BusInjectionModel.jl b/src/BusInjectionModel.jl index 075d46d..670ec66 100644 --- a/src/BusInjectionModel.jl +++ b/src/BusInjectionModel.jl @@ -1,5 +1,28 @@ module BusInjectionModel -# Write your package code here. + +using CommonOPF +using JuMP +using LinearAlgebra + + +""" + ModelType + +An enum with values: +1. `FixedPointLinear` +""" +@enum ModelType begin + FixedPointLinear # only SinglePhase +end + + +export + build_bim!, + FixedPointLinear + + +include("single_phase_model.jl") +include("single_phase_fpl_model.jl") end diff --git a/src/single_phase_fpl_model.jl b/src/single_phase_fpl_model.jl new file mode 100644 index 0000000..3cb86b1 --- /dev/null +++ b/src/single_phase_fpl_model.jl @@ -0,0 +1,165 @@ + + +""" + build_bim!(m::JuMP.AbstractModel, net::Network{SinglePhase}, ::Val{FixedPointLinear}) + +Add variables and constraints to `m` using the values in `net` to make an FixedPointLinear branch flow +model. Calls the following functions: +- [`add_bim_variables`](@ref) +- [`constrain_voltage`](@ref) +``` +""" +function build_bim!(m::JuMP.AbstractModel, net::Network{SinglePhase}, ::Val{FixedPointLinear}) + add_bim_variables(m, net) + # constrain_voltage(m, net) +end + + +function build_lpf(m::JuMP.AbstractModel, net::Network{SinglePhase}) + add_variables(m, p) + constrain_voltage(m, p) + constrain_substation_power(m, p) + constrain_bounds(m, p) +end + + +function add_bim_variables(m::JuMP.AbstractModel, net::Network{SinglePhase}) + N = length(busses(net)) + T = net.Ntimesteps + + @variable(m, P₀[1:T]) + @variable(m, Q₀[1:T]) + # TODO Pj Qj variables and change p.P/Qref to P/Qload dicts ? + + @variable(m, v[1:N, 1:T] >=0) # vlo and vhi applied in constraints s.t. they end up in C matrix +end + + +function constrain_voltage(m::JuMP.AbstractModel, net::Network{SinglePhase}) + v = m[:v] + N = length(busses(net)) + + # Bernstein & Dall'anese 2017 equ. 5b, 9b, 9c + for t = 1:net.Ntimesteps + # TODO should we update the M matrices with each time step? Depends on if Vref is updated with time + invDiagConjVref = inv(Diagonal(vec(conj(p.vref[:, t])))) # TODO mv to Inputs so only calculated once (and Mwye) + Mwye = [p.invYLL * invDiagConjVref -im * p.invYLL * invDiagConjVref] + Kwye = inv(Diagonal(abs.(p.vref[:,t]))) * real( Diagonal(conj(p.vref[:,t])) * Mwye ) + b = abs.(p.vref[:,t]) - Kwye * vec([p.Pref[:,t] / p.Sbase; p.Qref[:,t]] / p.Sbase) + + KL = Kwye[:, 1:N] + KR = Kwye[:, N+1:end] + + @constraint(m, [j = 1:N], + v[j,t] == sum( KL[j,n] * p.Pref[n,t] / p.Sbase for n in N) + + sum( KR[j,n] * p.Qref[n,t] / p.Sbase for n in N) + + b[j] + ) + end + #= + equ (10) distributable voltage estimation, less accurate + + v₀ = [complex(net.v0, 0)] + w = -p.invYLL * p.YL0 * v₀ + W = Diagonal(w) + big_one = vec(ones(N)) + + abs.(W) * (big_one + real(inv(W) * Mwye) * vec([p.Pref[:,t] / p.Sbase; p.Qref[:,t]] / p.Sbase)) + =# + p.Nequality_cons += N * net.Ntimesteps + nothing +end + + + +""" + constrain_substation_power(m::JuMP.AbstractModel, params::YPQVarraysNodeByTime) + +P₀ & Q₀ definitions ∀ t ∈ T +""" +function constrain_substation_power(m::JuMP.AbstractModel, net::Network{SinglePhase}) + P₀ = m[:P₀] + Q₀ = m[:Q₀] + v₀ = [complex(net.v0, 0)] + # parameters using notation from Bernstein and Dall'anese 2017 equ.s 5c, 13a, 13b + w = -p.invYLL * p.YL0 * v₀ # can be replaced with ntwk.vnom? + c = Diagonal(v₀) * (conj(p.Y₀₀) * conj(v₀) + conj(p.Y0L) * conj(w)) + creal = real(c)[1] + cimag = imag(c)[1] + + # s₀ = G*x + c + for t = 1:net.Ntimesteps + invDiagConjVref = inv(Diagonal(vec(conj(p.vref[:, t])))) + Mwye = [p.invYLL * invDiagConjVref -im * p.invYLL * invDiagConjVref] + gwye = Diagonal(v₀) * conj(p.Y0L) * conj(Mwye) + + @constraint(m, + P₀[t] == 1/p.Sbase * dot(real(gwye), [p.Pref[:,t]; p.Qref[:,t]]) + creal + ) + @constraint(m, + Q₀[t] == 1/p.Sbase * dot(imag(gwye), [p.Pref[:,t]; p.Qref[:,t]]) + cimag + ) + end + + p.Nequality_cons += 2 * net.Ntimesteps + nothing +end + + +function constrain_bounds(m::JuMP.AbstractModel, net::Network{SinglePhase}) + N = length(busses(net)) + + @constraint(m, con_vhi[n=1:N, t=1:net.Ntimesteps], + m[:v][n, t] ≤ net.bounds.v_upper_mag + ) + p.Nlte_cons += N * net.Ntimesteps + + @constraint(m, con_vlo[n=1:N, t=1:net.Ntimesteps], + p.vlo - m[:v][n, t] ≤ 0 + ) + p.Nlte_cons += N * net.Ntimesteps + + @constraint(m, con_P0hi[t=1:net.Ntimesteps], + m[:P₀][t] ≤ p.P0hi + ) + p.Nlte_cons += net.Ntimesteps + + @constraint(m, con_P0lo[t=1:net.Ntimesteps], + p.P0lo - m[:P₀][t] ≤ 0 + ) + p.Nlte_cons += net.Ntimesteps + + @constraint(m, con_Q0hi[t=1:net.Ntimesteps], + m[:Q₀][t] ≤ p.Q0hi + ) + p.Nlte_cons += net.Ntimesteps + + @constraint(m, con_Q0lo[t=1:net.Ntimesteps], + p.Q0lo - m[:Q₀][t] ≤ 0 + ) + p.Nlte_cons += net.Ntimesteps + nothing +end + + +function check_existence_condition(m, net::Network{SinglePhase}) + # TODO: still applies? if so update the P,Q vectors + N = length(busses(net)) + upperbound = net.v0^2 / (4 * matrixnormstar(p.Z)) + Snorm = zeros(Float64, net.Ntimesteps) + for t in 1:net.Ntimesteps + P = value.(m[:P][:,t]) + Q = value.(m[:P][:,t]) + Snorm[t] = LinearAlgebra.norm( sqrt(sum( P[j]^2 + Q[j]^2 for j in 0:N)) ) + end + return all(Snorm[t] < upperbound for t in 1:net.Ntimesteps) +end + + +function matrixnormstar(A::AbstractArray{<:Complex{Float64}, 2}) + rownorms = zeros(Float64, size(A, 1)) + for r = 1:size(A,1) + rownorms[r] += LinearAlgebra.norm(abs.(A[r,:])) + end + return maximum(rownorms) +end diff --git a/src/single_phase_model.jl b/src/single_phase_model.jl new file mode 100644 index 0000000..eda5720 --- /dev/null +++ b/src/single_phase_model.jl @@ -0,0 +1,8 @@ +""" + build_bim!(m::JuMP.AbstractModel, net::Network{MultiPhase}, mtype::ModelType=FixedPointLinear) + +Top-level multiphase builder that dispatches the ModelType enum +""" +function build_bim!(m::JuMP.AbstractModel, net::Network{MultiPhase}, mtype::ModelType=FixedPointLinear) + build_bim!(m::JuMP.AbstractModel, net::Network{MultiPhase}, Val(mtype)) +end diff --git a/test/Manifest.toml b/test/Manifest.toml new file mode 100644 index 0000000..6f8d8e8 --- /dev/null +++ b/test/Manifest.toml @@ -0,0 +1,395 @@ +# This file is machine-generated - editing it directly is not advised + +julia_version = "1.10.5" +manifest_format = "2.0" +project_hash = "b04b12e2ae0673f3c08189b06aa9b365aa1628fb" + +[[deps.ArgTools]] +uuid = "0dad84c5-d112-42e6-8d28-ef12dabb789f" +version = "1.1.1" + +[[deps.Artifacts]] +uuid = "56f22d72-fd6d-98f1-02f0-08ddc0907c33" + +[[deps.Base64]] +uuid = "2a0f44e3-6c83-55bd-87e4-b1978d98bd5f" + +[[deps.BenchmarkTools]] +deps = ["JSON", "Logging", "Printf", "Profile", "Statistics", "UUIDs"] +git-tree-sha1 = "f1dff6729bc61f4d49e140da1af55dcd1ac97b2f" +uuid = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" +version = "1.5.0" + +[[deps.Bzip2_jll]] +deps = ["Artifacts", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "9e2a6b69137e6969bab0152632dcb3bc108c8bdd" +uuid = "6e34b625-4abd-537c-b88f-471c36dfa7a0" +version = "1.0.8+1" + +[[deps.CodecBzip2]] +deps = ["Bzip2_jll", "TranscodingStreams"] +git-tree-sha1 = "e7c529cc31bb85b97631b922fa2e6baf246f5905" +uuid = "523fee87-0ab8-5b00-afb7-3ecf72e48cfd" +version = "0.8.4" + +[[deps.CodecZlib]] +deps = ["TranscodingStreams", "Zlib_jll"] +git-tree-sha1 = "bce6804e5e6044c6daab27bb533d1295e4a2e759" +uuid = "944b1d66-785c-5afd-91f1-9de20f533193" +version = "0.7.6" + +[[deps.CommonSubexpressions]] +deps = ["MacroTools"] +git-tree-sha1 = "cda2cfaebb4be89c9084adaca7dd7333369715c5" +uuid = "bbf7d656-a473-5ed7-a52c-81e309532950" +version = "0.3.1" + +[[deps.Compat]] +deps = ["TOML", "UUIDs"] +git-tree-sha1 = "8ae8d32e09f0dcf42a36b90d4e17f5dd2e4c4215" +uuid = "34da2185-b29b-5c13-b0c7-acf172513d20" +version = "4.16.0" +weakdeps = ["Dates", "LinearAlgebra"] + + [deps.Compat.extensions] + CompatLinearAlgebraExt = "LinearAlgebra" + +[[deps.CompilerSupportLibraries_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "e66e0078-7015-5450-92f7-15fbd957f2ae" +version = "1.1.1+0" + +[[deps.DataStructures]] +deps = ["Compat", "InteractiveUtils", "OrderedCollections"] +git-tree-sha1 = "1d0a14036acb104d9e89698bd408f63ab58cdc82" +uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8" +version = "0.18.20" + +[[deps.Dates]] +deps = ["Printf"] +uuid = "ade2ca70-3891-5945-98fb-dc099432e06a" + +[[deps.DiffResults]] +deps = ["StaticArraysCore"] +git-tree-sha1 = "782dd5f4561f5d267313f23853baaaa4c52ea621" +uuid = "163ba53b-c6d8-5494-b064-1a9d43ac40c5" +version = "1.1.0" + +[[deps.DiffRules]] +deps = ["IrrationalConstants", "LogExpFunctions", "NaNMath", "Random", "SpecialFunctions"] +git-tree-sha1 = "23163d55f885173722d1e4cf0f6110cdbaf7e272" +uuid = "b552c78f-8df3-52c6-915a-8e097449b14b" +version = "1.15.1" + +[[deps.DocStringExtensions]] +deps = ["LibGit2"] +git-tree-sha1 = "2fb1e02f2b635d0845df5d7c167fec4dd739b00d" +uuid = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae" +version = "0.9.3" + +[[deps.Downloads]] +deps = ["ArgTools", "FileWatching", "LibCURL", "NetworkOptions"] +uuid = "f43a241f-c20a-4ad4-852c-f6b1247861c6" +version = "1.6.0" + +[[deps.FileWatching]] +uuid = "7b1f6079-737a-58dc-b8bc-7a2ca5c1b5ee" + +[[deps.ForwardDiff]] +deps = ["CommonSubexpressions", "DiffResults", "DiffRules", "LinearAlgebra", "LogExpFunctions", "NaNMath", "Preferences", "Printf", "Random", "SpecialFunctions"] +git-tree-sha1 = "cf0fe81336da9fb90944683b8c41984b08793dad" +uuid = "f6369f11-7733-5829-9624-2563aa707210" +version = "0.10.36" + + [deps.ForwardDiff.extensions] + ForwardDiffStaticArraysExt = "StaticArrays" + + [deps.ForwardDiff.weakdeps] + StaticArrays = "90137ffa-7385-5640-81b9-e52037218182" + +[[deps.HiGHS]] +deps = ["HiGHS_jll", "MathOptInterface", "PrecompileTools", "SparseArrays"] +git-tree-sha1 = "477bde3ee57657239b38d3bacafcb20082d9a1b2" +uuid = "87dc4568-4c63-4d18-b0c0-bb2238e4078b" +version = "1.9.2" + +[[deps.HiGHS_jll]] +deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Zlib_jll"] +git-tree-sha1 = "1f240e0fb1c4cdf39bca5d3881d1758263931ccb" +uuid = "8fd58aa0-07eb-5a78-9b36-339c94fd15ea" +version = "1.7.2+0" + +[[deps.InteractiveUtils]] +deps = ["Markdown"] +uuid = "b77e0a4c-d291-57a0-90e8-8db25a27a240" + +[[deps.IrrationalConstants]] +git-tree-sha1 = "630b497eafcc20001bba38a4651b327dcfc491d2" +uuid = "92d709cd-6900-40b7-9082-c6be49f344b6" +version = "0.2.2" + +[[deps.JLLWrappers]] +deps = ["Artifacts", "Preferences"] +git-tree-sha1 = "f389674c99bfcde17dc57454011aa44d5a260a40" +uuid = "692b3bcd-3c85-4b1f-b108-f13ce0eb3210" +version = "1.6.0" + +[[deps.JSON]] +deps = ["Dates", "Mmap", "Parsers", "Unicode"] +git-tree-sha1 = "31e996f0a15c7b280ba9f76636b3ff9e2ae58c9a" +uuid = "682c06a0-de6a-54ab-a142-c8b1cf79cde6" +version = "0.21.4" + +[[deps.JuMP]] +deps = ["LinearAlgebra", "MacroTools", "MathOptInterface", "MutableArithmetics", "OrderedCollections", "PrecompileTools", "Printf", "SparseArrays"] +git-tree-sha1 = "c95f443d4641b128d626a429b51d5185050135b5" +uuid = "4076af6c-e467-56ae-b986-b466b2749572" +version = "1.23.2" + + [deps.JuMP.extensions] + JuMPDimensionalDataExt = "DimensionalData" + + [deps.JuMP.weakdeps] + DimensionalData = "0703355e-b756-11e9-17c0-8b28908087d0" + +[[deps.LibCURL]] +deps = ["LibCURL_jll", "MozillaCACerts_jll"] +uuid = "b27032c2-a3e7-50c8-80cd-2d36dbcbfd21" +version = "0.6.4" + +[[deps.LibCURL_jll]] +deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll", "Zlib_jll", "nghttp2_jll"] +uuid = "deac9b47-8bc7-5906-a0fe-35ac56dc84c0" +version = "8.4.0+0" + +[[deps.LibGit2]] +deps = ["Base64", "LibGit2_jll", "NetworkOptions", "Printf", "SHA"] +uuid = "76f85450-5226-5b5a-8eaa-529ad045b433" + +[[deps.LibGit2_jll]] +deps = ["Artifacts", "LibSSH2_jll", "Libdl", "MbedTLS_jll"] +uuid = "e37daf67-58a4-590a-8e99-b0245dd2ffc5" +version = "1.6.4+0" + +[[deps.LibSSH2_jll]] +deps = ["Artifacts", "Libdl", "MbedTLS_jll"] +uuid = "29816b5a-b9ab-546f-933c-edad1886dfa8" +version = "1.11.0+1" + +[[deps.Libdl]] +uuid = "8f399da3-3557-5675-b5ff-fb832c97cbdb" + +[[deps.LinearAlgebra]] +deps = ["Libdl", "OpenBLAS_jll", "libblastrampoline_jll"] +uuid = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" + +[[deps.LogExpFunctions]] +deps = ["DocStringExtensions", "IrrationalConstants", "LinearAlgebra"] +git-tree-sha1 = "a2d09619db4e765091ee5c6ffe8872849de0feea" +uuid = "2ab3a3ac-af41-5b50-aa03-7779005ae688" +version = "0.3.28" + + [deps.LogExpFunctions.extensions] + LogExpFunctionsChainRulesCoreExt = "ChainRulesCore" + LogExpFunctionsChangesOfVariablesExt = "ChangesOfVariables" + LogExpFunctionsInverseFunctionsExt = "InverseFunctions" + + [deps.LogExpFunctions.weakdeps] + ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" + ChangesOfVariables = "9e997f8a-9a97-42d5-a9f1-ce6bfc15e2c0" + InverseFunctions = "3587e190-3f89-42d0-90ee-14403ec27112" + +[[deps.Logging]] +uuid = "56ddb016-857b-54e1-b83d-db4d58db5568" + +[[deps.MacroTools]] +deps = ["Markdown", "Random"] +git-tree-sha1 = "2fa9ee3e63fd3a4f7a9a4f4744a52f4856de82df" +uuid = "1914dd2f-81c6-5fcd-8719-6d5c9610ff09" +version = "0.5.13" + +[[deps.Markdown]] +deps = ["Base64"] +uuid = "d6f4376e-aef5-505a-96c1-9c027394607a" + +[[deps.MathOptInterface]] +deps = ["BenchmarkTools", "CodecBzip2", "CodecZlib", "DataStructures", "ForwardDiff", "JSON", "LinearAlgebra", "MutableArithmetics", "NaNMath", "OrderedCollections", "PrecompileTools", "Printf", "SparseArrays", "SpecialFunctions", "Test", "Unicode"] +git-tree-sha1 = "5b246fca5420ae176d65ed43a2d0ee5897775216" +uuid = "b8f27783-ece8-5eb3-8dc8-9495eed66fee" +version = "1.31.2" + +[[deps.MbedTLS_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "c8ffd9c3-330d-5841-b78e-0817d7145fa1" +version = "2.28.2+1" + +[[deps.Mmap]] +uuid = "a63ad114-7e13-5084-954f-fe012c677804" + +[[deps.MozillaCACerts_jll]] +uuid = "14a3606d-f60d-562e-9121-12d972cd8159" +version = "2023.1.10" + +[[deps.MutableArithmetics]] +deps = ["LinearAlgebra", "SparseArrays", "Test"] +git-tree-sha1 = "d0a6b1096b584a2b88efb70a92f8cb8c881eb38a" +uuid = "d8a4904e-b15c-11e9-3269-09a3773c0cb0" +version = "1.4.6" + +[[deps.NaNMath]] +deps = ["OpenLibm_jll"] +git-tree-sha1 = "0877504529a3e5c3343c6f8b4c0381e57e4387e4" +uuid = "77ba4419-2d1f-58cd-9bb1-8ffee604a2e3" +version = "1.0.2" + +[[deps.NetworkOptions]] +uuid = "ca575930-c2e3-43a9-ace4-1e988b2c1908" +version = "1.2.0" + +[[deps.OpenBLAS_jll]] +deps = ["Artifacts", "CompilerSupportLibraries_jll", "Libdl"] +uuid = "4536629a-c528-5b80-bd46-f80d51c5b363" +version = "0.3.23+4" + +[[deps.OpenLibm_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "05823500-19ac-5b8b-9628-191a04bc5112" +version = "0.8.1+2" + +[[deps.OpenSpecFun_jll]] +deps = ["Artifacts", "CompilerSupportLibraries_jll", "JLLWrappers", "Libdl", "Pkg"] +git-tree-sha1 = "13652491f6856acfd2db29360e1bbcd4565d04f1" +uuid = "efe28fd5-8261-553b-a9e1-b2916fc3738e" +version = "0.5.5+0" + +[[deps.OrderedCollections]] +git-tree-sha1 = "dfdf5519f235516220579f949664f1bf44e741c5" +uuid = "bac558e1-5e72-5ebc-8fee-abe8a469f55d" +version = "1.6.3" + +[[deps.Parsers]] +deps = ["Dates", "PrecompileTools", "UUIDs"] +git-tree-sha1 = "8489905bcdbcfac64d1daa51ca07c0d8f0283821" +uuid = "69de0a69-1ddd-5017-9359-2bf0b02dc9f0" +version = "2.8.1" + +[[deps.Pkg]] +deps = ["Artifacts", "Dates", "Downloads", "FileWatching", "LibGit2", "Libdl", "Logging", "Markdown", "Printf", "REPL", "Random", "SHA", "Serialization", "TOML", "Tar", "UUIDs", "p7zip_jll"] +uuid = "44cfe95a-1eb2-52ea-b672-e2afdf69b78f" +version = "1.10.0" + +[[deps.PrecompileTools]] +deps = ["Preferences"] +git-tree-sha1 = "5aa36f7049a63a1528fe8f7c3f2113413ffd4e1f" +uuid = "aea7be01-6a6a-4083-8856-8a6e6704d82a" +version = "1.2.1" + +[[deps.Preferences]] +deps = ["TOML"] +git-tree-sha1 = "9306f6085165d270f7e3db02af26a400d580f5c6" +uuid = "21216c6a-2e73-6563-6e65-726566657250" +version = "1.4.3" + +[[deps.Printf]] +deps = ["Unicode"] +uuid = "de0858da-6303-5e67-8744-51eddeeeb8d7" + +[[deps.Profile]] +deps = ["Printf"] +uuid = "9abbd945-dff8-562f-b5e8-e1ebf5ef1b79" + +[[deps.REPL]] +deps = ["InteractiveUtils", "Markdown", "Sockets", "Unicode"] +uuid = "3fa0cd96-eef1-5676-8a61-b3b8758bbffb" + +[[deps.Random]] +deps = ["SHA"] +uuid = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c" + +[[deps.SHA]] +uuid = "ea8e919c-243c-51af-8825-aaa63cd721ce" +version = "0.7.0" + +[[deps.Serialization]] +uuid = "9e88b42a-f829-5b0c-bbe9-9e923198166b" + +[[deps.Sockets]] +uuid = "6462fe0b-24de-5631-8697-dd941f90decc" + +[[deps.SparseArrays]] +deps = ["Libdl", "LinearAlgebra", "Random", "Serialization", "SuiteSparse_jll"] +uuid = "2f01184e-e22b-5df5-ae63-d93ebab69eaf" +version = "1.10.0" + +[[deps.SpecialFunctions]] +deps = ["IrrationalConstants", "LogExpFunctions", "OpenLibm_jll", "OpenSpecFun_jll"] +git-tree-sha1 = "2f5d4697f21388cbe1ff299430dd169ef97d7e14" +uuid = "276daf66-3868-5448-9aa4-cd146d93841b" +version = "2.4.0" + + [deps.SpecialFunctions.extensions] + SpecialFunctionsChainRulesCoreExt = "ChainRulesCore" + + [deps.SpecialFunctions.weakdeps] + ChainRulesCore = "d360d2e6-b24c-11e9-a2a3-2a2ae2dbcce4" + +[[deps.StaticArraysCore]] +git-tree-sha1 = "192954ef1208c7019899fbf8049e717f92959682" +uuid = "1e83bf80-4336-4d27-bf5d-d5a4f845583c" +version = "1.4.3" + +[[deps.Statistics]] +deps = ["LinearAlgebra", "SparseArrays"] +uuid = "10745b16-79ce-11e8-11f9-7d13ad32a3b2" +version = "1.10.0" + +[[deps.SuiteSparse_jll]] +deps = ["Artifacts", "Libdl", "libblastrampoline_jll"] +uuid = "bea87d4a-7f5b-5778-9afe-8cc45184846c" +version = "7.2.1+1" + +[[deps.TOML]] +deps = ["Dates"] +uuid = "fa267f1f-6049-4f14-aa54-33bafae1ed76" +version = "1.0.3" + +[[deps.Tar]] +deps = ["ArgTools", "SHA"] +uuid = "a4e569a6-e804-4fa4-b0f3-eef7a1d5b13e" +version = "1.10.0" + +[[deps.Test]] +deps = ["InteractiveUtils", "Logging", "Random", "Serialization"] +uuid = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[[deps.TranscodingStreams]] +git-tree-sha1 = "e84b3a11b9bece70d14cce63406bbc79ed3464d2" +uuid = "3bb67fe8-82b1-5028-8e26-92a6c54297fa" +version = "0.11.2" + +[[deps.UUIDs]] +deps = ["Random", "SHA"] +uuid = "cf7118a7-6976-5b1a-9a39-7adc72f591a4" + +[[deps.Unicode]] +uuid = "4ec0a83e-493e-50e2-b9ac-8f72acf5a8f5" + +[[deps.Zlib_jll]] +deps = ["Libdl"] +uuid = "83775a58-1f1d-513f-b197-d71354ab007a" +version = "1.2.13+1" + +[[deps.libblastrampoline_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "8e850b90-86db-534c-a0d3-1478176c7d93" +version = "5.11.0+0" + +[[deps.nghttp2_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "8e850ede-7688-5339-a07c-302acd2aaf8d" +version = "1.52.0+1" + +[[deps.p7zip_jll]] +deps = ["Artifacts", "Libdl"] +uuid = "3f19e933-33d8-53b3-aaab-bd5110c3b7a0" +version = "17.4.0+2" diff --git a/test/Project.toml b/test/Project.toml new file mode 100644 index 0000000..6b104a8 --- /dev/null +++ b/test/Project.toml @@ -0,0 +1,4 @@ +[deps] +HiGHS = "87dc4568-4c63-4d18-b0c0-bb2238e4078b" +JuMP = "4076af6c-e467-56ae-b986-b466b2749572" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" diff --git a/test/data/ieee13/IEEE13Nodeckt_no_trfxs.dss b/test/data/ieee13/IEEE13Nodeckt_no_trfxs.dss new file mode 100644 index 0000000..95a2736 --- /dev/null +++ b/test/data/ieee13/IEEE13Nodeckt_no_trfxs.dss @@ -0,0 +1,96 @@ +Clear + +new circuit.IEEE13Nodeckt +~ basekv=4.16 pu=1.05 phases=3 bus1=650 +~ MVAsc3=20000 MVASC1=20000 ! stiffen the source to approximate inf source + + +New linecode.mtx601 nphases=3 BaseFreq=60 +~ rmatrix = (0.3465 | 0.1560 0.3375 | 0.1580 0.1535 0.3414 ) +~ xmatrix = (1.0179 | 0.5017 1.0478 | 0.4236 0.3849 1.0348 ) +~ cmatrix = (0.0 | 0.0 0.0 | 0.0 0.0 0.0 ) +~ units=mi + +New linecode.mtx602 nphases=3 BaseFreq=60 +~ rmatrix = (0.7526 | 0.1580 0.7475 | 0.1560 0.1535 0.7436 ) +~ xmatrix = (1.1814 | 0.4236 1.1983 | 0.5017 0.3849 1.2112 ) +~ cmatrix = (0.0 | 0.0 0.0 | 0.0 0.0 0.0 ) +~ units=mi + +New linecode.mtx603 nphases=2 BaseFreq=60 +~ rmatrix = (1.3238 | 0.2066 1.3294 ) +~ xmatrix = (1.3569 | 0.4591 1.3471 ) +~ cmatrix = (0.0 | 0.0 0.0 ) +~ units=mi + +New linecode.mtx604 nphases=2 BaseFreq=60 +~ rmatrix = (1.3238 | 0.2066 1.3294 ) +~ xmatrix = (1.3569 | 0.4591 1.3471 ) +~ cmatrix = (0.0 | 0.0 0.0 ) +~ units=mi + +New linecode.mtx605 nphases=1 BaseFreq=60 +~ rmatrix = (1.3292 ) +~ xmatrix = (1.3475 ) +~ cmatrix = (0.0 ) +~ units=mi + +New Linecode.mtx606 nphases=3 Units=mi BaseFreq=60 +~ Rmatrix=[0.791721 |0.318476 0.781649 |0.28345 0.318476 0.791721 ] +~ Xmatrix=[0.438352 |0.0276838 0.396697 |-0.0184204 0.0276838 0.438352 ] +~ cmatrix = (0.0 | 0.0 0.0 | 0.0 0.0 0.0 ) + +New linecode.mtx607 nphases=1 BaseFreq=60 +~ rmatrix = (1.3425 ) +~ xmatrix = (0.5124 ) +~ cmatrix = (0.0 ) +~ units=mi + + +!LOAD DEFINITIONS the vminpu and vmaxpu values can change the load model! Vminpu=0.8 changes results +New Load.671 Bus1=671.1.2.3 Phases=3 Conn=Wye Model=1 kV=4.16 kW=1155 kvar=660 +New Load.633a Bus1=633.1 Phases=1 Conn=Wye Model=1 kV=(4.16 3 sqrt /) kW=160 kvar=110 +New Load.633b Bus1=633.2 Phases=1 Conn=Wye Model=1 kV=(4.16 3 sqrt /) kW=120 kvar=90 +New Load.633c Bus1=633.3 Phases=1 Conn=Wye Model=1 kV=(4.16 3 sqrt /) kW=120 kvar=90 +New Load.645 Bus1=645.2 Phases=1 Conn=Wye Model=1 kV=(4.16 3 sqrt /) kW=170 kvar=125 +New Load.646 Bus1=646.3 Phases=1 Conn=Wye Model=1 kV=(4.16 3 sqrt /) kW=230 kvar=132 +New Load.692 Bus1=692.3 Phases=1 Conn=Wye Model=1 kV=(4.16 3 sqrt /) kW=170 kvar=151 +New Load.675a Bus1=675.1 Phases=1 Conn=Wye Model=1 kV=(4.16 3 sqrt /) kW=485 kvar=190 +New Load.675b Bus1=675.2 Phases=1 Conn=Wye Model=1 kV=(4.16 3 sqrt /) kW=68 kvar=60 +New Load.675c Bus1=675.3 Phases=1 Conn=Wye Model=1 kV=(4.16 3 sqrt /) kW=290 kvar=212 +New Load.611 Bus1=611.3 Phases=1 Conn=Wye Model=1 kV=(4.16 3 sqrt /) kW=170 kvar=80 + +New Load.652 Bus1=652.1 Phases=1 Conn=Wye Model=1 kV=(4.16 3 sqrt /) kW=128 kvar=86 + +New Load.670a Bus1=670.1 Phases=1 Conn=Wye Model=1 kV=(4.16 3 sqrt /) kW=17 kvar=10 +New Load.670b Bus1=670.2 Phases=1 Conn=Wye Model=1 kV=(4.16 3 sqrt /) kW=66 kvar=38 +New Load.670c Bus1=670.3 Phases=1 Conn=Wye Model=1 kV=(4.16 3 sqrt /) kW=117 kvar=68 + +!CAPACITOR DEFINITIONS +!New Capacitor.Cap1 Bus1=675 phases=3 kVAR=600 kV=4.16 +!New Capacitor.Cap2 Bus1=611.3 phases=1 kVAR=100 kV=(4.16 3 sqrt /) + + +!LINE DEFINITIONS +New Line.650632 Phases=3 Bus1=650.1.2.3 Bus2=632.1.2.3 LineCode=mtx601 Length=0.3787878787878788 units=mi +New Line.632670 Phases=3 Bus1=632.1.2.3 Bus2=670.1.2.3 LineCode=mtx601 Length=0.12632575757575756 units=mi +New Line.670671 Phases=3 Bus1=670.1.2.3 Bus2=671.1.2.3 LineCode=mtx601 Length=0.2524621212121212 units=mi +New Line.671680 Phases=3 Bus1=671.1.2.3 Bus2=680.1.2.3 LineCode=mtx601 Length=0.1893939393939394 units=mi +New Line.632633 Phases=3 Bus1=632.1.2.3 Bus2=633.1.2.3 LineCode=mtx602 Length=0.0946969696969697 units=mi +New Line.632645 Phases=2 Bus1=632.2.3 Bus2=645.2.3 LineCode=mtx603 Length=0.0946969696969697 units=mi +New Line.645646 Phases=2 Bus1=645.2.3 Bus2=646.2.3 LineCode=mtx603 Length=0.0568181818181818 units=mi +New Line.692675 Phases=3 Bus1=692.1.2.3 Bus2=675.1.2.3 LineCode=mtx606 Length=0.0946969696969697 units=mi +New Line.671684 Phases=2 Bus1=671.1.3 Bus2=684.1.3 LineCode=mtx604 Length=0.05681818181818181 units=mi +New Line.684611 Phases=1 Bus1=684.3 Bus2=611.3 LineCode=mtx605 Length=0.05681818181818181 units=mi +New Line.684652 Phases=1 Bus1=684.1 Bus2=652.1 LineCode=mtx607 Length=0.15151515151515152 units=mi + + +!SWITCH DEFINITIONS +New Line.671692 Phases=3 Bus1=671 Bus2=692 Switch=y r1=1e-4 r0=1e-4 x1=0.000 x0=0.000 c1=0.000 c0=0.000 + +Batchedit Load..* vminpu=0.8 ! ensure that load model stays constant power +Set Voltagebases=[4.16] +Set MinIteration=500 +Set MaxIter=500 ! default is 15, not enough to get load matching +calcv +Solve diff --git a/test/runtests.jl b/test/runtests.jl index bac0a14..932d24c 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,6 +1,23 @@ using BusInjectionModel using Test +using HiGHS +using JuMP + + +# # hack for local testing +# using Pkg +# Pkg.activate("..") +# using LinearPowerFlow +# Pkg.activate(".") + @testset "BusInjectionModel.jl" begin - # Write your tests here. + + @testset "IEEE13 wye only" begin + m = Model(HiGHS.Optimizer) + dss_path = joinpath("data", "ieee13", "IEEE13Nodeckt_no_trfxs.dss") + net = BusInjectionModel.CommonOPF.dss_to_Network(dss_path) + # build_bim!(m, net, FixedPointLinear) + end + end