Skip to content

Commit

Permalink
add startingPrimal
Browse files Browse the repository at this point in the history
  • Loading branch information
mcosovic committed Sep 26, 2023
1 parent 1e21ffc commit 12d0619
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 10 deletions.
12 changes: 11 additions & 1 deletion docs/src/api/optimalPowerFlow.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ For further information on this topic, please see the [AC Optimal Power Flow](@r
###### Solve DC Optimal Power Flow
* [`solve!`](@ref solve!(::PowerSystem, ::DCOptimalPowerFlow))

###### Additional Function
* [`startingPrimal!`](@ref startingPrimal!(::PowerSystem, ::ACOptimalPowerFlow))
---

## Build AC Optimal Power Flow Model
Expand All @@ -42,4 +44,12 @@ dcOptimalPowerFlow
## Solve DC Optimal Power Flow
```@docs
solve!(::PowerSystem, ::DCOptimalPowerFlow)
```
```

---

## Additional Function
```@docs
startingPrimal!(::PowerSystem, ::ACOptimalPowerFlow)
```

2 changes: 1 addition & 1 deletion src/JuliaGrid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ module JuliaGrid

using SparseArrays, LinearAlgebra, SuiteSparse
using HDF5, UUIDs
using HiGHS, Ipopt
using JuMP, HiGHS, Ipopt

######### Types and Constants ##########
include("definition/internal.jl")
Expand Down
45 changes: 45 additions & 0 deletions src/optimalPowerFlow/acOptimalPowerFlow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,42 @@ function updateBalance(system::PowerSystem, analysis::ACOptimalPowerFlow, index:
end
end

"""
startingPrimal!(system::PowerSystem, analysis::OptimalPowerFlow)
In the context of the `ACOptimalPowerFlow` composite type, this function retrieves the
active and reactive power outputs of the generators, as well as the voltage magnitudes and
angles from the `PowerSystem` composite type. It then assigns these values to the
`ACOptimalPowerFlow` type, allowing users to initialize starting primal values as needed.
For the `DCOptimalPowerFlow` composite type, this function retrieves the active power
outputs of the generators and the bus voltage angles from the `PowerSystem` composite type.
These values are then assigned to the `DCOptimalPowerFlow` type, enabling users to
initialize starting primal values according to their requirements.
# Updates
This function only updates the `voltage` and `generator` fields of the `OptimalPowerFlow`
abstract type.
# Abstract type
The abstract type `OptimalPowerFlow` can have the following subtypes:
- `ACOptimalPowerFlow`: employed to initializing starting primal values within the AC optimal power flow;
- `DCOptimalPowerFlow`: employed to initialize starting primal values within the DC optimal power flow.
# Example
```jldoctest
system = powerSystem("case14.h5")
acModel!(system)
analysis = acOptimalPowerFlow(system, Ipopt.Optimizer)
solve!(system, analysis)
updateBus!(system, analysis; label = 14, reactive = 0.13, magnitude = 1.2, angle = -0.17)
startingPrimal!(system, analysis)
solve!(system, analysis)
```
"""
function startingPrimal!(system::PowerSystem, analysis::ACOptimalPowerFlow)
@inbounds for i = 1:system.bus.number
analysis.voltage.magnitude[i] = system.bus.voltage.magnitude[i]
Expand All @@ -538,4 +574,13 @@ function startingPrimal!(system::PowerSystem, analysis::ACOptimalPowerFlow)
analysis.power.generator.active[i] = system.generator.output.active[i]
analysis.power.generator.reactive[i] = system.generator.output.reactive[i]
end
end

function startingPrimal!(system::PowerSystem, analysis::DCOptimalPowerFlow)
@inbounds for i = 1:system.bus.number
analysis.voltage.angle[i] = system.bus.voltage.angle[i]
end
@inbounds for i = 1:system.generator.number
analysis.power.generator.active[i] = system.generator.output.active[i]
end
end
8 changes: 0 additions & 8 deletions src/optimalPowerFlow/dcOptimalPowerFlow.jl
Original file line number Diff line number Diff line change
Expand Up @@ -272,11 +272,3 @@ function costExpr(cost::Cost, variable::JuMP.VariableRef, index::Int64, label::L
return expr, isPowerwise, isNonLin
end

function startingPrimal!(system::PowerSystem, analysis::DCOptimalPowerFlow)
@inbounds for i = 1:system.bus.number
analysis.voltage.angle[i] = system.bus.voltage.angle[i]
end
@inbounds for i = 1:system.generator.number
analysis.power.generator.active[i] = system.generator.output.active[i]
end
end

0 comments on commit 12d0619

Please sign in to comment.