Samples & Guides
Worked examples showing how to configure the tool for common power systems studies.
A system with a high concentration of inductive motors is causing the bus voltage to sag below acceptable limits. The goal is to find the minimum reactive power (MVAr) of a shunt capacitor that restores the bus voltage within the standard operating range of 0.9–1.1 p.u.
- Monitored bus element:
MainBus.ElmTerm - Capacitor element:
Cap.ElmShnt - Reactive power sweep: 0 – 10 MVAr in 0.5 MVAr steps
- Voltage standard: 0.9 – 1.1 p.u.
| Name | Object | Attribute | Lower | Upper | Step |
|---|---|---|---|---|---|
.py).
The script writes a CSV file to your output directory, e.g. results.csv:
Q_cap,Converge?,bus_voltage 0.0,True,0.873 0.5,True,0.891 1.0,True,0.908 1.5,True,0.925 2.0,True,0.943 2.5,True,0.961 3.0,True,1.024 3.5,True,1.041 ...
Open the CSV in Excel or Python (pandas) to plot voltage vs. capacitor size and identify the minimum capacitor rating that satisfies your voltage standard.
The system Total Harmonic Distortion (THD) exceeds the permissible limit. The goal is to find the optimal capacitance, inductance, and resistance of a passive harmonic filter that minimises THD, subject to a maximum resistance constraint.
- Filter element:
Filter.ElmFilter - Parameters to optimise: capacitance (
capa), inductance (rrea), resistance (rres) - Target: minimise THD. Verify result manually against your standard (e.g. < 3%)
- Constraint: resistance ≤ 0.05 Ω
| Name | Object | Attribute | Lower | Upper | Step |
|---|---|---|---|---|---|
| Variable | Operator | Value |
|---|---|---|
.py).
The script prints the best parameters found by the optimiser:
Optimisation complete. Best parameters: C_f (capa) = 4.72e-04 L_f (rrea) = 1.23e-02 R_f (rres) = 0.038 Best objective (thd) = 2.61
Verify the THD value against your standard (e.g. < 3%) manually. The script does not enforce the limit; it only minimises THD within the parameter bounds and constraints you provide. You may modify the code to do this automatically.
A grid-connected synchronous condenser must be sized to satisfy two dynamic criteria simultaneously: (1) Fault Ride-Through (FRT), where the machine must stay in synchronism and provide continuous reactive current support throughout a major fault without pole-slipping; and (2) Inertial Response, where the rotating mass must be large enough to limit the frequency nadir to an acceptable level following the sudden loss of a generator. The script sweeps the number of parallel condenser units and records the worst-case dynamic response for each size, automatically identifying the minimum installation that meets both criteria.
- Synchronous condenser element:
SynCon.ElmSym - Monitored bus:
MainBus.ElmTerm - 3-phase fault event pre-configured in the PowerFactory study case dynamic event list (applied at t = 1 s, cleared at t = 1.15 s)
- Simulation window: 0–30 s (fault application, clearing, and full post-fault recovery)
- FRT pass criterion:
bus_voltage_nadir ≥ 0.85 p.u.andout_of_step = 0 - Inertia pass criterion:
rotor_speed_min ≥ 0.97 p.u.(≥ 48.5 Hz on a 50 Hz base) - Combined pass/fail evaluated automatically by the
sizing_okcustom calculation output
| Name | Object | Attribute | Lower | Upper | Step |
|---|---|---|---|---|---|
{output_dir}/graph)
{output_dir}/graph)
def sizing_ok(bus_voltage_nadir, rotor_speed_min, out_of_step):
return bus_voltage_nadir >= 0.85 and rotor_speed_min >= 0.97 and out_of_step == 0
Arguments must match names of other defined input or output variables. Returns True if all sizing criteria pass, False otherwise.
.py).
The script writes a summary CSV to your output directory, e.g. results.csv:
ngnum,Converge?,bus_voltage_nadir,synccon_q_peak,rotor_speed_min,out_of_step,sizing_ok 1,True,0.71,47.3,0.961,1,False 2,True,0.74,94.1,0.966,1,False 3,True,0.76,140.8,0.970,0,False 4,True,0.79,187.2,0.973,0,True 5,True,0.82,233.6,0.976,0,True ... 10,True,0.91,466.1,0.984,0,True
The minimum passing size is the first row where sizing_ok = True; here, that is 4 parallel units. Time-domain waveform plots for bus_voltage_nadir and rotor_speed_min are saved as .png files in {output_dir}/graph/ for each scenario.
Assess the steady-state impact of losing any single line in the network. The Contingency problem type resolves all matching lines at runtime via a wildcard query, with no manual enumeration or spreadsheet required. The script runs a base case followed by one load flow per line, recording bus voltages and line loadings alongside convergence status for every scenario.
- N-1 contingency mode will be used
- Only lines above 66 kV will be considered
- Bus voltage and line loading of all buses and lines will be monitored
Select Contingency as the Problem Type. The Input Variables section is hidden because the Contingency Config section replaces it.
| # | Element Query | Filter Attribute | Op | Filter Value |
|---|---|---|---|---|
| 1 |
.py).
The script writes a summary CSV to your output directory, e.g. results.csv. The first two columns identify the contingency and its convergence status; subsequent columns are the output values, each prefixed with the variable name and the element's loc_name (e.g. bus_voltage_Bus_HV1, loading_Line_A):
Contingent Element 1,Converge?,bus_voltage_Bus_HV1,bus_voltage_Bus_HV2,bus_voltage_Bus_HV3,loading_Line_A,loading_Line_B,loading_Line_C,loading_Line_D Base Case,True,1.023,0.998,1.005,42.1,38.5,65.3,71.2 Line_A,True,0.887,1.012,0.995,65.3,88.7,45.2,80.5 Line_B,True,1.012,0.889,1.003,88.7,55.2,40.1,75.3 Line_C,False,,,,,,,, Line_D,True,0.991,1.003,0.998,48.6,71.9,82.3,95.1
Converge? = False for Line_C indicates the load flow did not converge with that line tripped. The row is still recorded but output columns are left empty.
Frequently Asked Questions
The API Path points to the PowerFactory Python API folder. It is located inside a Python subfolder of your PowerFactory installation, with a sub-folder for each available Python version. For example:
C:\Program Files\DIgSILENT\PowerFactory 2024\Python\3.10\
Choose the sub-folder that matches the Python version you are using to run your script.
| Study Type | PF Command | Use to Analyse ... |
|---|---|---|
| Steady State | Load Flow (ldf) |
Steady state voltages, currents, loading, etc |
| Dynamic RMS | RMS simulation (rms) |
Fault response, generator dynamics, inverter dynamics, etc |
| Dynamic EMT | EMT simulation (emt) |
Switching transients, power electronics, detailed waveforms, etc |
| Harmonic | Harmonic load flow (hdf) |
Total harmonic distortion (THD), individual harmonics, etc |
Python File (.py): Best for production use, scheduled runs, or when you want to import the script as a module. Run from the terminal or your IDE.
Notebook (.ipynb): Best for exploratory work, step-by-step debugging, or when you want inline plots and tables alongside the code. Open in Jupyter.