Hi there. I have a problem with this code here. I’m trying to simulate a three-phase short circuit fault in a power system according to the instructions in Example 2 here:
https://github.com/NREL-Sienna/PowerSimulationsDynamics.jl/blob/main/docs/src/perturbations.md
The power system is also taken from the SIIPExamples repository. The main thing to do for simulating this scenario is using the NetworkSwitch function, which accepts complex numbers as input, and I don’t want to define new method for this function because the numbers are meant to be complex. Anyway, in this scenario, we introduce two perturbations and feed it into a simulation function. My code executes up until the last line. When I attempt to execute the simulation using IDA solver, I get this error:
Error: Execution failed
│ exception =
│ BoundsError: attempt to access 28×28 SparseMatrixCSC{Float64, Int64} with 257 stored entries at index [785]
│ Stacktrace:
│ [1] throw_boundserror(A::SparseMatrixCSC{Float64, Int64}, I::Tuple{Int64})
│ @ Base ./abstractarray.jl:737
│ [2] checkbounds
│ @ ./abstractarray.jl:702 [inlined]
│ [3] _setindex!
│ @ ./abstractarray.jl:1430 [inlined]
│ [4] setindex!
│ @ ./abstractarray.jl:1396 [inlined]
│ [5] (::PowerSimulationsDynamics.var"#27#28"{NetworkSwitch})
which is strange because the apply_fault and clear_fault are both 28*28 matrices, which mean that there should only be 784 cells. I double checked all the matrices and made sure that they all have proper dimensions and the code is still not running.
What was confusing to me was that IDA solver works with non-complex values. But I have to have complex values. I have tried several other solvers but could not find anything that works. I’m a newbie to Julia so I suspect that the problem is with something different and I have no clue. Can you help me?
This is the code:
using SIIPExamples
using PowerSimulationsDynamics
import PowerSimulationsDynamics as PSD
using PowerSystems
using Sundials
using SparseArrays
using OrdinaryDiffEq
# Load the power system model
file_dir = joinpath(dirname(dirname(pathof(SIIPExamples))), "script", "4_PowerSimulationsDynamics_examples", "Data")
sys = System(joinpath(file_dir, "14bus.raw"), joinpath(file_dir, "dyn_data.dyr"))
# Retrieve the Y-bus matrix and bus mapping
(ybus_matrix, bus_mapping) = PowerSimulationsDynamics._get_ybus(sys)
# Transform ybus_matrix into Complex type
ybus_matrix = SparseMatrixCSC{ComplexF64, Int64}(ybus_matrix)
# Store the original Y-Bus Matrix
original_ybus_matrix = copy(ybus_matrix)
# The original Y-Bus Matrix is already in Complex type
typeof(original_ybus_matrix)
# Modify Y-Bus Matrix for Fault Condition
bus_index = bus_mapping[6]
large_value = 1.0e4 + 0.0im
ybus_matrix[bus_index, bus_index] += large_value
# Create Sparse Matrices for Fault Condition and Clearing Fault
fault_admittance = sparse(ybus_matrix)
clear_fault_matrix = sparse(original_ybus_matrix)
# Define NetworkSwitch Events
time_of_fault = 1.0 # Time when the fault occurs
time_of_clear = 1.1 # Time when the fault is cleared
# fault_admittance = SparseMatrixCSC{Float64, Int64}(fault_admittance)
apply_fault = NetworkSwitch(time_of_fault, fault_admittance)
clear_fault = NetworkSwitch(time_of_clear, clear_fault_matrix)
three_phase_fault = [apply_fault, clear_fault]
# Define and Run Simulation
sim = PSD.Simulation(
ResidualModel, # Type of model used
sys, # System
file_dir, # Path for the simulation output
(0.0, 10.0), # Time span
three_phase_fault, # Events
)
# Execute the simulation with IDA
PSD.execute!(sim, IDA(); abstol = 1e-8)