Skip to content

Commit

Permalink
Merge pull request #41 from Welthulk/dev/0.4.15
Browse files Browse the repository at this point in the history
Dev/0.4.15
  • Loading branch information
scud-soptim authored Apr 13, 2024
2 parents 5723f84 + 5aa1a46 commit 2fd7356
Show file tree
Hide file tree
Showing 19 changed files with 431 additions and 300 deletions.
12 changes: 6 additions & 6 deletions Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,9 @@ version = "4.1.1"

[[deps.DataStructures]]
deps = ["Compat", "InteractiveUtils", "OrderedCollections"]
git-tree-sha1 = "0f4b5d62a88d8f59003e43c25a8a90de9eb76317"
git-tree-sha1 = "97d79461925cdb635ee32116978fc735b9463a39"
uuid = "864edb3b-99cc-5e75-8d2d-829cb0a9cfe8"
version = "0.18.18"
version = "0.18.19"

[[deps.Dates]]
deps = ["Printf"]
Expand Down Expand Up @@ -112,9 +112,9 @@ version = "1.3.1"

[[deps.Git_jll]]
deps = ["Artifacts", "Expat_jll", "JLLWrappers", "LibCURL_jll", "Libdl", "Libiconv_jll", "OpenSSL_jll", "PCRE2_jll", "Zlib_jll"]
git-tree-sha1 = "12945451c5d0e2d0dca0724c3a8d6448b46bbdf9"
git-tree-sha1 = "d18fb8a1f3609361ebda9bf029b60fd0f120c809"
uuid = "f8c6e375-362e-5223-8a59-34ff63f689eb"
version = "2.44.0+1"
version = "2.44.0+2"

[[deps.Glob]]
git-tree-sha1 = "97285bbd5230dd766e9ef6749b80fc617126d496"
Expand Down Expand Up @@ -145,9 +145,9 @@ version = "0.21.4"

[[deps.JuliaFormatter]]
deps = ["CSTParser", "CommonMark", "DataStructures", "Glob", "Pkg", "PrecompileTools", "Tokenize"]
git-tree-sha1 = "e07d6fd7db543b11cd90ed764efec53f39851f09"
git-tree-sha1 = "1c4880cb70a5c6c87ea36deccc3d7f9e7969c18c"
uuid = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
version = "1.0.54"
version = "1.0.56"

[[deps.LazilyInitializedFields]]
git-tree-sha1 = "8f7f3cabab0fd1800699663533b6d5cb3fc0e612"
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ name = "Sparlectra"
uuid = "31ce9bba-fd9d-44a1-b005-f5f509afda38"
authors = ["Udo Schmitz"]
description = "load flow calculation using newton-raphson"
version = "0.4.14"
version = "0.4.15"

[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Expand Down
6 changes: 6 additions & 0 deletions docs/src/changelog.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,10 @@
# Change Log
## Version 0.4.15 (2024-xx-xx)
### New Features
- Implemented a function to detect isolated buses and incorporate them into the network calculation (Issue #38)."
### Bug Fixes


## Version 0.4.14 (2024-04-12)
### New Features

Expand Down
2 changes: 1 addition & 1 deletion docs/src/workshop.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ addProsumer!(net = net, busName = "B3", type = "ENERGYCONSUMER", p = 1.0, q = 2.
addProsumer!(net = net, busName = "B5", type = "SYNCHRONMASCHINE", referencePri = "B5", vm_pu = 1.0, va_deg = 0.0)
addProsumer!(net = net, busName = "B1", type = "GENERATOR", p = 1.1, q = 2.0)

result, msg = validate(net = net)
result, msg = validate!(net = net)
if !result
@warn msg
return false
Expand Down
17 changes: 10 additions & 7 deletions src/Sparlectra.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"""
Sparlectra 0.4.14
Sparlectra 0.4.15
Sparlectra is a Julia package for the calculation of electrical networks. It is designed to be used in the context of power system analysis and optimization.
Expand All @@ -21,14 +21,17 @@ module Sparlectra
# The project follows the Julia Naming Conventions for the most part,
# but it's important to note that the naming convention for functions might deviate.
# In this module, functions are written in CamelCase with a lowercase initial letter.

#! format: off
using LinearAlgebra, SparseArrays, Printf, Logging

# resource data types for working with Sparlectra
const Wurzel3 = 1.7320508075688772
const SparlectraVersion = VersionNumber("0.4.14")
const SparlectraVersion = VersionNumber("0.4.15")
abstract type AbstractBranch end

export

# constants
Wurzel3, ComponentTyp,
# classes
Expand All @@ -51,12 +54,12 @@ export

# functions
# Compomnent
toComponentTyp, getRXBG,
toComponentTyp, getRXBG, getCompName,
# Transformers
getSideNumber2WT, getWinding2WT, calcTransformerRatio, recalc_trafo_model_data, create2WTRatioTransformerNoTaps, create3WTWindings!,
getTrafoImpPGMComp, getWT3AuxBusID, isPerUnit_RXGB, getWindingRatedS,
# Nodes
setRatedS!, setVmVa!, addShuntPower!, addLoadPower!, addGenPower!, getNodeVn, isSlack, isPVNode, isPQNode, toNodeType,
setRatedS!, setVmVa!, addShuntPower!, addLoadPower!, addGenPower!, getNodeVn, isSlack, isPVNode, isPQNode, isIsolated, toNodeType, setNodeType!,
busComparison, toString,
# Branch
setBranchFlow!, setBranchStatus!,
Expand All @@ -67,8 +70,8 @@ export
# ProSumer
isSlack, isGenerator, isAPUNode, setQGenReplacement!, getQGenReplacement, toProSumptionType, updatePQ!,
# Net
addBus!, addShunt!, addACLine!, addPIModelACLine!, add2WTrafo!, addPIModelTrafo!, addProsumer!, lockNet!, validate, hasBusInNet, addBusGenPower!, addBusLoadPower!, addBusShuntPower!,
getNetOrigBusIdx, geNetBusIdx, setBranchStatus!, setTotalLosses!, getTotalLosses, getBusType, get_bus_vn_kV, get_vn_kV, updateBranchParameters!, hasShunt!, getShunt!,
addBus!, addShunt!, addACLine!, addPIModelACLine!, add2WTrafo!, addPIModelTrafo!, addProsumer!, lockNet!, validate!, hasBusInNet, addBusGenPower!, addBusLoadPower!, addBusShuntPower!,
getNetOrigBusIdx, geNetBusIdx, setBranchStatus!, setTotalLosses!, getTotalLosses, getBusType, get_bus_vn_kV, get_vn_kV, updateBranchParameters!, hasShunt!, getShunt!, markIsolatedBuses!,
# create_powermat.jl
casefileparser, createNetFromMatPowerFile,
# exportMatPower.jl
Expand Down Expand Up @@ -107,5 +110,5 @@ include("exportMatPower.jl")
include("results.jl")
include("run_acpflow.jl")


#! format: on
end # module Sparlectra
1 change: 1 addition & 0 deletions src/branch.jl
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@ mutable struct Branch
new(c, from, to, branch.r, branch.x, branch.b, branch.g, 0.0, 0.0, status, branch.ratedS, nothing, nothing, nothing, nothing)
else
r, x, b, g = getRXBG(branch)
@assert !isnothing(r) && !isnothing(x) "r or x must be set for an ACLineSegment"
r_pu, x_pu, g_pu, b_pu = toPU_RXGB(r = r, x = x, g = g, b = b, v_kv = vn_kV, baseMVA = baseMVA)
new(c, from, to, r_pu, x_pu, b_pu, g_pu, 0.0, 0.0, status, branch.ratedS, nothing, nothing, nothing, nothing)
end
Expand Down
4 changes: 4 additions & 0 deletions src/component.jl
Original file line number Diff line number Diff line change
Expand Up @@ -183,3 +183,7 @@ function toComponentTyp(o::String)::ComponentTyp
return UnknownC
end
end

function getCompName(c::AbstractComponent)::String
return c.cName
end
46 changes: 24 additions & 22 deletions src/createnet_powermat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
# include-file createnet_powermat.jl

# helper
#! format: off
function _createDict()

busKeys = ["bus", "type", "Pd", "Qd", "Gs", "Bs", "area", "Vm", "Va", "baseKV", "zone", "Vmax", "Vmin"]
busDict = Dict{String,Int}()
for (idx, key) in enumerate(busKeys)
Expand All @@ -24,7 +26,7 @@ function _createDict()

return busDict, genDict, branchDict
end

#! format: on
"""
Creates a network from a MatPower case file.
Expand All @@ -51,7 +53,7 @@ function createNetFromMatPowerFile(filename, log::Bool = false)::Net

@info "create network from case-file: $(filename)"
netName, baseMVA, busData, genData, branchData = casefileparser(filename)

slackIdx = 0
# parsing the data
if debug
Expand Down Expand Up @@ -79,7 +81,7 @@ function createNetFromMatPowerFile(filename, log::Bool = false)::Net
end

busDict, genDict, branchDict = _createDict()
myNet = Net(name= string(netName), baseMVA= baseMVA)
myNet = Net(name = string(netName), baseMVA = baseMVA)

col = size(busData, 2)

Expand All @@ -104,10 +106,10 @@ function createNetFromMatPowerFile(filename, log::Bool = false)::Net
if btype == 3 && slackIdx == 0
slackIdx = kIdx
end
busName = string(kIdx)
busName = string(kIdx)

addBus!(net = myNet, busName = busName, busType = toString(toNodeType(btype)), vn_kV = vn_kv, vm_pu = vm_pu, va_deg = va_deg, vmin_pu = vmin, vmax_pu = vmax, isAux = false, oBusIdx = kIdx, zone = zone, area = area)

if pShunt != 0.0 || qShunt != 0.0
addShunt!(net = myNet, busName = busName, pShunt = pShunt, qShunt = qShunt)
end
Expand All @@ -117,7 +119,7 @@ function createNetFromMatPowerFile(filename, log::Bool = false)::Net
qMin = -qMax # approximation!
pMax = abs(mFak * pƩLoad) <= baseMVA ? abs(mFak * pƩLoad) : baseMVA # approximation!
pMin = -pMax # approximation!
addProsumer!(net = myNet, busName = busName, type = "ENERGYCONSUMER", p = pƩLoad, q = qƩLoad, pMin = pMin, pMax = pMax, qMin= qMin, qMax = qMax)
addProsumer!(net = myNet, busName = busName, type = "ENERGYCONSUMER", p = pƩLoad, q = qƩLoad, pMin = pMin, pMax = pMax, qMin = qMin, qMax = qMax)
end
end# read bus

Expand All @@ -126,36 +128,36 @@ function createNetFromMatPowerFile(filename, log::Bool = false)::Net
for row in eachrow(branchData[:, 1:col])
_fbus = Int(row[branchDict["fbus"]])
_tbus = Int(row[branchDict["tbus"]])

fbus = string(_fbus)
tbus = string(_tbus)
vn_kv_fromBus = get_bus_vn_kV(net = myNet, busName = fbus)
vn_kv_toBus = get_bus_vn_kV(net = myNet, busName = tbus)
vn_kv_fromBus = get_bus_vn_kV(net = myNet, busName = fbus)
vn_kv_toBus = get_bus_vn_kV(net = myNet, busName = tbus)

hasBusInNet(net = myNet, busName = fbus) || (@warn("bus $(fbus) not found, branch ignored."); continue)
hasBusInNet(net = myNet, busName = tbus) || (@warn("bus $(tbus) not found, branch ignored."); continue)

r_pu = float(row[branchDict["r"]])
x_pu = float(row[branchDict["x"]])
b_pu = float(row[branchDict["b"]])
ratedS = float(row[branchDict["rateA"]])
ratio = float(row[branchDict["ratio"]])
angle = float(row[branchDict["angle"]])
status = Int64(row[branchDict["status"]])
isLine = false
isLine = false
if (ratio == 1.0 && angle == 0.0 || ratio == 0.0) && vn_kv_fromBus == vn_kv_toBus
isLine = true
isLine = true
end

if isLine
addPIModelACLine!(net = myNet, fromBus = fbus, toBus = tbus, r_pu = r_pu, x_pu = x_pu, b_pu = b_pu, status = status, ratedS = ratedS)
addPIModelACLine!(net = myNet, fromBus = fbus, toBus = tbus, r_pu = r_pu, x_pu = x_pu, b_pu = b_pu, status = status, ratedS = ratedS)
else # transformer
addPIModelTrafo!(net = myNet, fromBus = fbus, toBus = tbus, r_pu = r_pu, x_pu = x_pu, b_pu = b_pu, status = status, ratedS = ratedS, ratio = ratio, shift_deg = angle)
end
end

# Generators:
col = size(genData, 2)
col = size(genData, 2)
for row in eachrow(genData[:, 1:col])
status = Int64(row[genDict["status"]])
_bus = Int(row[genDict["bus"]])
Expand All @@ -164,35 +166,35 @@ function createNetFromMatPowerFile(filename, log::Bool = false)::Net
pInfo("generator $(_bus) not in service, ignored")
continue
end

pGen = float(row[genDict["Pg"]]) < 0.0 ? (pInfo("pGen at bus $(_bus) p < 0"); float(row[genDict["Pg"]])) : float(row[genDict["Pg"]])
qGen = float(row[genDict["Qg"]]) < 0.0 ? (@debug("qGen at bus $(_bus) q < 0"); float(row[genDict["Qg"]])) : float(row[genDict["Qg"]])

if abs(pGen) < 1e-6 && abs(qGen) < 1e-6
if abs(pGen) < 1e-6 && abs(qGen) < 1e-6
busType = getBusType(net = myNet, busName = bus)
if busType == Sparlectra.PQ
pInfo("generator $(_bus) has no power output, ignored")
continue
continue
end
end
end

qMax = float(row[genDict["Qmax"]])
qMin = float(row[genDict["Qmin"]])
pMax = float(row[genDict["Pmax"]])
pMin = float(row[genDict["Pmin"]])
vm_pu = float(row[genDict["Vg"]])
mBase = float(row[genDict["mBase"]])

referencePri = slackIdx == _bus ? bus : nothing

if mBase != baseMVA
@warn "generator $(_bus) has different baseMVA than network baseMVA"
end

addProsumer!(net = myNet, busName = bus, type = "GENERATOR", vm_pu = vm_pu, referencePri = referencePri, p = pGen, q = qGen, pMax = pMax, pMin = pMin, qMax = qMax, qMin = qMin)
end# read Generators

erg, msg = validate(net=myNet)
erg, msg = validate(net = myNet)
if erg == false
@error "network is invalid: $msg"
end
Expand Down
Loading

0 comments on commit 2fd7356

Please sign in to comment.