Examples
Nordic Test System
Section titled “Nordic Test System”The Nordic test system is included in the stepss-PyRAMSES repository as a ready-to-run example.
Running the Example
Section titled “Running the Example”import pyramsesimport os
# Change to the example directoryos.chdir("examples/Nordic")
# Load the case configurationcase = pyramses.cfg("cmd.txt")
# Initialize the simulatorram = pyramses.sim()
# Run the simulationram.execSim(case)
# Extract and visualize resultsext = pyramses.extractor(case.getTrj())
# Plot bus voltage magnitudesext.getBus('1041').mag.plot()ext.getBus('1044').mag.plot()Step-by-Step: Building a Case Programmatically
Section titled “Step-by-Step: Building a Case Programmatically”1. Define the Test Case
Section titled “1. Define the Test Case”import pyramses
# Create case from scratchcase = pyramses.cfg()
# Add data filescase.addData("network.dat") # Network topologycase.addData("dynamic_data.dat") # Dynamic modelscase.addData("settings.dat") # Solver settings
# Set disturbance filecase.addDst("fault_scenario.dst")
# Set output filescase.addInit("init.trace")case.addTrj("results.rtrj")case.addObs("observables.obs")case.addCont("continuous.trace")case.addDisc("discrete.trace")2. Run with Pause Points
Section titled “2. Run with Pause Points”ram = pyramses.sim()
# Start simulation paused at t = 0ram.execSim(case, 0)
# Read an observablev = ram.getObs('BUS', '1041', 'mag')print(f"Initial voltage at bus 1041: {v:.4f} pu")
# Continue to t = 10 sram.contSim(10.0)
# Check voltage after disturbancev = ram.getObs('BUS', '1041', 'mag')print(f"Voltage at t=10s: {v:.4f} pu")
# Continue to endram.contSim()3. Extract and Plot Results
Section titled “3. Extract and Plot Results”ext = pyramses.extractor(case.getTrj())
# Bus voltagesimport matplotlib.pyplot as plt
bus_1041 = ext.getBus('1041')bus_1044 = ext.getBus('1044')
plt.figure(figsize=(10, 6))plt.plot(bus_1041.mag.time, bus_1041.mag.value, label='Bus 1041')plt.plot(bus_1044.mag.time, bus_1044.mag.value, label='Bus 1044')plt.xlabel('Time (s)')plt.ylabel('Voltage (pu)')plt.title('Bus Voltage Magnitudes')plt.legend()plt.grid(True)plt.show()Eigenanalysis with PyRAMSES
Section titled “Eigenanalysis with PyRAMSES”Combining PyRAMSES with the RAMSES Eigenanalysis tool:
1. Export Jacobian
Section titled “1. Export Jacobian”Create a disturbance file that exports the Jacobian at s:
0.000 CONTINUE SOLVER BD 0.0200 0.001 0. ALL1.000 JAC 'jac'2.000 STOPEnsure the solver settings include:
$OMEGA_REF SYN ;$SCHEME IN ;2. Run Simulation
Section titled “2. Run Simulation”import pyramses
ram = pyramses.sim()case = pyramses.cfg("cmd_jac.txt")ram.execSim(case)3. Analyze in MATLAB
Section titled “3. Analyze in MATLAB”addpath('path/to/RAMSES-Eigenanalysis')addpath('path/to/RAMSES-Eigenanalysis/scripts')
% Run eigenanalysis (QZ method)ssa('jac_val.dat', 'jac_eqs.dat', 'jac_var.dat', 'jac_struc.dat')
% With custom filtering (eigenvalues with real part > -2, damping < 10%)ssa('jac_val.dat', 'jac_eqs.dat', 'jac_var.dat', 'jac_struc.dat', ... -2.0, 0.10, 'QZ')Runtime Observables
Section titled “Runtime Observables”Display real-time plots during simulation (requires Gnuplot):
import pyramses
case = pyramses.cfg()case.addData("network.dat")case.addData("dynamic.dat")case.addDst("disturbance.dst")
# Add runtime observablescase.addRunObs("BUS 1041 mag")case.addRunObs("BUS 1044 mag")case.addRunObs("SYNC g1 speed")
ram = pyramses.sim()ram.execSim(case) # Gnuplot windows will show live tracesWriting Command Files
Section titled “Writing Command Files”Export the case configuration to a standard command file:
case = pyramses.cfg()case.addData("network.dat")case.addData("dynamic.dat")case.addDst("scenario.dst")case.addTrj("result.rtrj")case.addObs("obs.obs")
# Save to filecase.writeCmdFile("generated_cmd.txt")
# Or get as stringcmd_string = case.writeCmdFile()print(cmd_string)