diff --git a/src/JuliaGrid.jl b/src/JuliaGrid.jl index 5267eb847..0a7ebe47a 100644 --- a/src/JuliaGrid.jl +++ b/src/JuliaGrid.jl @@ -2,7 +2,7 @@ module JuliaGrid using JuMP -import LinearAlgebra: lu, lu!, ldlt, ldlt!, qr, ldiv, ldiv!, I, Factorization as LagFactorization +import LinearAlgebra: lu, lu!, ldlt, ldlt!, qr, ldiv, ldiv!, I, Factorization import SparseArrays: SparseMatrixCSC, sparse, spzeros, spdiagm, dropzeros!, nzrange, nnz import SuiteSparse: UMFPACK, SPQR, CHOLMOD diff --git a/src/definition/analysis.jl b/src/definition/analysis.jl index ef6a45b0f..a5a1ed277 100644 --- a/src/definition/analysis.jl +++ b/src/definition/analysis.jl @@ -47,7 +47,7 @@ mutable struct NewtonRaphson jacobian::SparseMatrixCSC{Float64,Int64} mismatch::Array{Float64,1} increment::Array{Float64,1} - factorization::LUQR + factorization::Factorization{Float64} pq::Array{Int64,1} pvpq::Array{Int64,1} pattern::Int64 @@ -58,7 +58,7 @@ mutable struct FastNewtonRaphsonModel jacobian::SparseMatrixCSC{Float64,Int64} mismatch::Array{Float64,1} increment::Array{Float64,1} - factorization::LUQR + factorization::Factorization{Float64} end mutable struct FastNewtonRaphson @@ -88,7 +88,7 @@ end ########### DC Power Flow ########### mutable struct DCPowerFlowMethod - factorization::LULDLtQR + factorization::Factorization{Float64} dcmodel::Int64 pattern::Int64 end @@ -246,7 +246,7 @@ mutable struct LinearWLS{T <: Union{Normal, Orthogonal}} coefficient::SparseMatrixCSC{Float64,Int64} precision::SparseMatrixCSC{Float64,Int64} mean::Array{Float64,1} - factorization::LULDLtQR + factorization::Factorization{Float64} number::Int64 pattern::Int64 run::Bool @@ -258,7 +258,7 @@ mutable struct NonlinearWLS{T <: Union{Normal, Orthogonal}} mean::Array{Float64,1} residual::Array{Float64,1} increment::Array{Float64,1} - factorization::LULDLtQR + factorization::Factorization{Float64} type::Array{Int8,1} index::Array{Int64,1} range::Array{Int64,1} diff --git a/src/definition/internal.jl b/src/definition/internal.jl index baf79a873..8bbf6f60a 100644 --- a/src/definition/internal.jl +++ b/src/definition/internal.jl @@ -287,18 +287,13 @@ end prefix = PrefixLive() ########### Matrix Factorization Type ########### -export Factorization, LU, QR, LDLt +export LU, QR, LDLt -abstract type Factorization end -abstract type QR <: Factorization end -abstract type LU <: Factorization end -abstract type LDLt <: Factorization end +abstract type QR end +abstract type LU end +abstract type LDLt end -const factorizeMatrix = Dict{DataType, LagFactorization{Float64}}() -factorizeMatrix[LU] = lu(sparse(Matrix(1.0I, 1, 1))) -factorizeMatrix[QR] = qr(sparse(Matrix(1.0I, 1, 1))) -factorizeMatrix[LDLt] = ldlt(sparse(Matrix(1.0I, 1, 1))) - -const LUQR = Union{UMFPACK.UmfpackLU{Float64, Int64}, SPQR.QRSparse{Float64, Int64}} -const LULDLt = Union{CHOLMOD.Factor{Float64}, UMFPACK.UmfpackLU{Float64, Int64}} -const LULDLtQR = Union{CHOLMOD.Factor{Float64}, LUQR} \ No newline at end of file +const factorized = Dict{DataType, Factorization{Float64}}() +factorized[LU] = lu(sparse(Matrix(1.0I, 1, 1))) +factorized[QR] = qr(sparse(Matrix(1.0I, 1, 1))) +factorized[LDLt] = ldlt(sparse(Matrix(1.0I, 1, 1))) \ No newline at end of file diff --git a/src/powerFlow/acPowerFlow.jl b/src/powerFlow/acPowerFlow.jl index f38fc4df0..4b5a672d4 100644 --- a/src/powerFlow/acPowerFlow.jl +++ b/src/powerFlow/acPowerFlow.jl @@ -137,7 +137,7 @@ function newtonRaphson(system::PowerSystem, factorization::Type{<:Union{QR, LU}} jacobian, mismatch, increment, - factorizeMatrix[factorization], + factorized[factorization], pqIndex, pvpqIndex, -1 @@ -333,13 +333,13 @@ end jacobianActive, mismatchActive, incrementActive, - factorizeMatrix[factorization], + factorized[factorization], ), FastNewtonRaphsonModel( jacobianReactive, mismatchReactive, incrementReactive, - factorizeMatrix[factorization], + factorized[factorization], ), pqIndex, pvpqIndex, diff --git a/src/powerFlow/dcPowerFlow.jl b/src/powerFlow/dcPowerFlow.jl index 2b50bf9cb..c016e225d 100644 --- a/src/powerFlow/dcPowerFlow.jl +++ b/src/powerFlow/dcPowerFlow.jl @@ -58,7 +58,7 @@ function dcPowerFlow(system::PowerSystem, factorization::Type{<:Union{QR, LDLt, CartesianReal(Float64[]) ), DCPowerFlowMethod( - factorizeMatrix[factorization], + factorized[factorization], -1, -1 ) diff --git a/src/stateEstimation/acStateEstimation.jl b/src/stateEstimation/acStateEstimation.jl index bf427e60f..da399b253 100644 --- a/src/stateEstimation/acStateEstimation.jl +++ b/src/stateEstimation/acStateEstimation.jl @@ -65,7 +65,7 @@ function gaussNewton(system::PowerSystem, device::Measurement, mean, residual, fill(0.0, 2 * system.bus.number), - factorizeMatrix[factorization], + factorized[factorization], type, index, range, @@ -94,7 +94,7 @@ function gaussNewton(system::PowerSystem, device::Measurement, method::Type{<:Or mean, residual, fill(0.0, 2 * system.bus.number), - qr(sparse(Matrix(1.0I, 1, 1))), + factorized[QR], type, index, range, diff --git a/src/stateEstimation/dcStateEstimation.jl b/src/stateEstimation/dcStateEstimation.jl index f0bbe69a3..831413f60 100644 --- a/src/stateEstimation/dcStateEstimation.jl +++ b/src/stateEstimation/dcStateEstimation.jl @@ -49,7 +49,7 @@ analysis = dcWlsStateEstimation(system, device, Orthogonal) ``` """ function dcWlsStateEstimation(system::PowerSystem, device::Measurement, - factorization::Type{<:Union{QR, LDLt, LU, Orthogonal}} = LU) + factorization::Type{<:Union{QR, LDLt, LU}} = LU) coefficient, mean, precision, power = dcStateEstimationWLS(system, device) @@ -60,7 +60,7 @@ function dcWlsStateEstimation(system::PowerSystem, device::Measurement, coefficient, precision, mean, - factorizeMatrix[factorization], + factorized[factorization], device.wattmeter.number + device.pmu.number, -1, true, @@ -69,7 +69,6 @@ function dcWlsStateEstimation(system::PowerSystem, device::Measurement, end function dcWlsStateEstimation(system::PowerSystem, device::Measurement, method::Type{<:Orthogonal}) - coefficient, mean, precision, power = dcStateEstimationWLS(system, device) return DCStateEstimation( @@ -81,7 +80,7 @@ function dcWlsStateEstimation(system::PowerSystem, device::Measurement, method:: coefficient, precision, mean, - qr(sparse(Matrix(1.0I, 1, 1))), + factorized[QR], device.wattmeter.number + device.pmu.number, -1, true, diff --git a/src/stateEstimation/pmuStateEstimation.jl b/src/stateEstimation/pmuStateEstimation.jl index 3c9aa0d79..81ec7ae74 100644 --- a/src/stateEstimation/pmuStateEstimation.jl +++ b/src/stateEstimation/pmuStateEstimation.jl @@ -63,7 +63,7 @@ function pmuWlsStateEstimation(system::PowerSystem, device::Measurement, coefficient, precision, mean, - factorizeMatrix[factorization], + factorized[factorization], 2 * device.pmu.number, -1, true, @@ -87,7 +87,7 @@ function pmuWlsStateEstimation(system::PowerSystem, device::Measurement, method: coefficient, precision, mean, - qr(sparse(Matrix(1.0I, 1, 1))), + factorized[QR], 2 * device.pmu.number, -1, true, diff --git a/src/utility/precompile.jl b/src/utility/precompile.jl index ced3e3052..0e2349151 100644 --- a/src/utility/precompile.jl +++ b/src/utility/precompile.jl @@ -13,28 +13,66 @@ PrecompileTools.@setup_workload begin addPmu!(system, device; bus = 2, magnitude = 1.0, angle = 0.0) PrecompileTools.@compile_workload begin + ########## DC Power Flow ########### analysis = dcPowerFlow(system) solve!(system, analysis) + analysis = dcPowerFlow(system, QR) + solve!(system, analysis) + + analysis = dcPowerFlow(system, LDLt) + solve!(system, analysis) + + ########## AC Power Flow ########### analysis = newtonRaphson(system) solve!(system, analysis) - analysis = fastNewtonRaphsonBX(system) + analysis = newtonRaphson(system, QR) solve!(system, analysis) - analysis = fastNewtonRaphsonXB(system) + analysis = fastNewtonRaphsonBX(system) solve!(system, analysis) analysis = gaussSeidel(system) solve!(system, analysis) + ########## DC State Estimation ########### analysis = dcWlsStateEstimation(system, device) solve!(system, analysis) + analysis = dcWlsStateEstimation(system, device, QR) + solve!(system, analysis) + + analysis = dcWlsStateEstimation(system, device, LDLt) + solve!(system, analysis) + + analysis = dcWlsStateEstimation(system, device, Orthogonal) + solve!(system, analysis) + + ########### PMU State Estimation ########### analysis = pmuWlsStateEstimation(system, device) solve!(system, analysis) + analysis = pmuWlsStateEstimation(system, device, QR) + solve!(system, analysis) + + analysis = pmuWlsStateEstimation(system, device, LDLt) + solve!(system, analysis) + + analysis = pmuWlsStateEstimation(system, device, Orthogonal) + solve!(system, analysis) + + ########### AC State Estimation ########### analysis = gaussNewton(system, device) solve!(system, analysis) + + analysis = gaussNewton(system, device, QR) + solve!(system, analysis) + + analysis = gaussNewton(system, device, LDLt) + solve!(system, analysis) + + analysis = gaussNewton(system, device, Orthogonal) + solve!(system, analysis) end end \ No newline at end of file