Skip to content

Commit

Permalink
added docstrings
Browse files Browse the repository at this point in the history
  • Loading branch information
Welthulk committed Oct 25, 2024
1 parent b3d4c06 commit 9a24361
Show file tree
Hide file tree
Showing 6 changed files with 212 additions and 31 deletions.
73 changes: 64 additions & 9 deletions src/equicircuit.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,27 @@
# Author: Udo Schmitz (https://github.com/Welthulk)
# Date: 22.05.2023
# include-file equicircuit.jl
"""
cubicSplineCoefs(x::Vector{Float64}, y::Vector{Float64})::Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}, Vector{Float64}}
Calculates the coefficients of the cubic spline interpolation for the given data points.
# Arguments
- `x::Vector{Float64}`: A vector of x-coordinates of the data points.
- `y::Vector{Float64}`: A vector of y-coordinates of the data points.
# Returns
- `a::Vector{Float64}`: The coefficients for the cubic term.
- `b::Vector{Float64}`: The coefficients for the quadratic term.
- `c::Vector{Float64}`: The coefficients for the linear term.
- `d::Vector{Float64}`: The coefficients for the constant term.
# Example
```julia
x = [1.0, 2.0, 3.0, 4.0]
y = [1.0, 4.0, 9.0, 16.0]
a, b, c, d = cubicSplineCoefs(x, y)
"""
function cubicSplineCoefs(x, y)
n = length(x)
h = diff(x)
Expand Down Expand Up @@ -58,6 +79,26 @@ function evaluateCubicSpline(x, a, b, c, d, x_new)
return y_new
end

"""
calcVKDependence(xTaps::Vector{Int}, yVKs::Vector{Float64}, tapPos::Float64)::Float64
Calculates the voltage dependence on the tap position using cubic spline interpolation.
# Arguments
- `xTaps::Vector{Int}`: A vector of tap positions.
- `yVKs::Vector{Float64}`: A vector of corresponding voltage values.
- `tapPos::Float64`: The current tap position for which the voltage is to be calculated.
# Returns
- `Float64`: The interpolated voltage value at the given tap position.
# Example
```julia
xTaps = [1, 2, 3, 4, 5]
yVKs = [1.0, 1.1, 1.2, 1.3, 1.4]
tapPos = 2.5
voltage = calcVKDependence(xTaps, yVKs, tapPos)
"""
function calcVKDependence(xTaps::Vector{Int}, yVKs::Vector{Float64}, tapPos::Float64)::Float64
a, b, c, d = cubicSplineCoefs(xTaps, yVKs)
vk = evaluateCubicSpline(xTaps, a, b, c, d, [tapPos])[1]
Expand All @@ -70,6 +111,25 @@ function calcComplexRatio(tapRatio::Float64, ShiftAngle_grad::Float64)::ComplexF
return tr + ti * im
end

"""
calcNeutralU(neutralU_ratio::Float64, vn_hv::Float64, tap_min::Integer, tap_max::Integer, tap_step_percent::Float64)::Float64
Calculates the neutral voltage of a transformer based on the given parameters.
# Arguments
- `neutralU_ratio::Float64`: The ratio of the neutral voltage to the rated high voltage.
- `vn_hv::Float64`: The rated high voltage of the transformer.
- `tap_min::Integer`: The minimum tap position.
- `tap_max::Integer`: The maximum tap position.
- `tap_step_percent::Float64`: The percentage change in voltage per tap step.
# Returns
- `Float64`: The calculated neutral voltage.
# Example
```julia
neutral_voltage = calcNeutralU(1.0, 110.0, -10, 10, 1.25)
"""
function calcNeutralU(neutralU_ratio::Float64, vn_hv::Float64, tap_min::Integer, tap_max::Integer, tap_step_percent::Float64)::Float64
return round(neutralU_ratio * vn_hv + (tap_max - tap_min) * tap_step_percent / 100.0, digits = 0)
end
Expand Down Expand Up @@ -159,7 +219,6 @@ function removeIsolatedNodesFromYBUS(Y::AbstractMatrix{ComplexF64}, isolated_nod
end
=#


"""
createYBUS(branchVec::Vector{Branch}, shuntVec::Vector{Shunt}, isoNodes::Vector{Int}, sparse::Bool = true, printYBUS::Bool = false)
Expand All @@ -176,13 +235,12 @@ Creates the bus admittance matrix (YBUS) of the network.
- `Y::Matrix{ComplexF64}`: The bus admittance matrix (YBUS).
"""
function createYBUS(; net::Net, sparse::Bool = true, printYBUS::Bool = false)

function createYBUS(;net::Net, sparse::Bool = true, printYBUS::Bool = false)

# Bestimme die maximale Busnummer im Netzwerk, unter Berücksichtigung isolierter Busse
max_bus = maximum(max(branch.fromBus, branch.toBus) for branch in net.branchVec)
n = max_bus - length(net.isoNodes)

Y = sparse ? spzeros(ComplexF64, n, n) : zeros(ComplexF64, n, n)

@debug "Dimension YBus:", n
Expand All @@ -207,12 +265,9 @@ function createYBUS(;net::Net, sparse::Bool = true, printYBUS::Bool = false)
fromNode -= count(i -> i < fromNode, net.isoNodes)
toNode -= count(i -> i < toNode, net.isoNodes)


yik = calcBranchYser(branch)
susceptance = 0.5 * calcBranchYshunt(branch)
t = calcBranchRatio(branch)



Y[fromNode, fromNode] += ((yik + susceptance)) / abs2(t)
Y[toNode, toNode] += (yik + susceptance)
Expand All @@ -223,10 +278,10 @@ function createYBUS(;net::Net, sparse::Bool = true, printYBUS::Bool = false)

for sh in net.shuntVec
node = sh.busIdx
if node in net.isoNodes
if node in net.isoNodes
continue
end
node -= count(i -> i < node, net.isoNodes)
node -= count(i -> i < node, net.isoNodes)
y = sh.y_pu_shunt
Y[node, node] += y
end
Expand Down
12 changes: 12 additions & 0 deletions src/losses.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,18 @@
# Date: 04.09.2023
# include-file losses.jl

"""
calcNetLosses!(net::Net)
Calculates the network losses for the given network.
# Arguments
- `net::Net`: The network.
# Example
```julia
calcNetLosses!(net = network)
"""
function calcNetLosses!(net::Net)
@debug "\ncalcNetworkLosses\n"
# Sij = vi*exp(j*phi_i)*( (vi*exp(j*phi_i) - vk*exp(j*phi_k)*Y_ik + vi*exp(j*phi_i)*Y0ik)*
Expand Down
29 changes: 29 additions & 0 deletions src/nbi.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,21 @@
# Author: Udo Schmitz (https://github.com/Welthulk)
# Date: 08.05.2023
# include-file nbi.jl
"""
getNBI(nodeNumberVec, branchTupleVec)
Generates the Node-Branch Incidence (NBI) matrix for a given set of nodes and branches.
# Arguments
- `nodeNumberVec::Vector{Int}`: A vector containing the node numbers.
- `branchTupleVec::Vector{Tuple{Int, Int}}`: A vector of tuples where each tuple represents a branch with the from and to bus numbers.
# Returns
- `NBI_matrix::Matrix{Int}`: The Node-Branch Incidence matrix.
# Example
see function test_NBI_MDO()
"""
function getNBI(nodeNumberVec, branchTupleVec)
num_nodes = length(nodeNumberVec)
num_branches = length(branchTupleVec)
Expand All @@ -26,6 +40,21 @@ function getNBI(nodeNumberVec, branchTupleVec)
end

# RCM-algorithm: Reverse Cuthill-McKeen algorithm (https://en.wikipedia.org/wiki/Cuthill%E2%80%93McKee_algorithm)
"""
mdoRCM(n::Int, branchTupleVec::Vector{Tuple{Int, Int}})::Vector{Int}
Performs the Modified Reverse Cuthill-McKee (RCM) algorithm to reorder the nodes of a graph to reduce its bandwidth.
# Arguments
- `n::Int`: The number of nodes in the graph.
- `branchTupleVec::Vector{Tuple{Int, Int}}`: A vector of tuples where each tuple represents a branch with the from and to bus numbers.
# Returns
- `order::Vector{Int}`: A vector representing the new order of the nodes after applying the RCM algorithm.
# Example
see function test_NBI_MDO()
"""
function mdoRCM(n, branchTupleVec)::Vector{Int}
adjacency = zeros(Int, n, n)

Expand Down
Loading

0 comments on commit 9a24361

Please sign in to comment.