> For the complete documentation index, see [llms.txt](https://www.opal-rt.com/docs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.opal-rt.com/docs/smart-power-simulation-software-sps/simulation-and-analysis/simulate-discretized-electrical-systems.md).

# Simulate Discretized Electrical Systems

## Introduction

To perform a discrete simulation, open the powergui block and set **Simulation type** to *Discrete*, and specify the sample time. The electrical system is discretized using the Tustin/Backward Euler (TBE) method. This method combines the Tustin method and the Backward Euler method. It allows you to simulate snubberless diode and thyristor converters. It eliminates numerical oscillations seen with the Tustin method and provides better accuracy than the Backward Euler method.

The TBE discretization method combines the accuracy of the Tustin method and the numerical oscillation damping property of the Backward-Euler method. It allows you to simulate power electronic circuits with virtually no snubber, using purely resistive snubbers with a very large resistance value resulting in negligible leakage currents.

The precision of the simulation is controlled by the time step that you choose for the discretization. Usually sample times of 20 µs to 50 µs give good results for simulation of switching transients on 50 Hz or 60 Hz power systems or on systems using line-commutated power electronic devices such as diodes and thyristors. Systems using forced-commutated power electronic switches are usually operating at high switching frequencies and require smaller sample times. For example, simulating a pulse-width-modulated (PWM) inverter operating at 5 kHz requires a maximum time step of 1 µs.

{% hint style="info" %}
Even if you discretize your electric circuit, you can still use a continuous control system. However, the simulation speed is improved by use of a discrete control system.
{% endhint %}

## Discretizing switches and power electronics

Switches and power electronic devices are nonlinear elements which are represented by a purely resistive element having a low Ron resistance when the switch is closed and an infinite resistance when the switch is opened. Each time a switch status is changed during the simulation, the discrete state-space model of the linear part of the circuit is re-evaluated to take into account the change in circuit topology.

Due to the way the state-space model is computed, switches cannot be connected in series with inductive circuits. In such situations, snubber circuits have to be connected across power electronic devices. For forced-commutated devices, the snubber circuit can be made negligible by using purely resistive snubbers with a high resistance. However, for circuits containing naturally commutated devices such as diodes and thyristors, because a fixed simulation time step is used, when the device is blocked, the current zero-crossing is not detected accurately.

## Discretizing electrical machines

Electrical machines are nonlinear elements simulated as current sources. These elements cannot be connected to an inductive network unless a parasitic resistive or capacitive element is connected at machine terminals. When using electrical machines in discrete systems, you might have to increase these parasitic resistive load to avoid numerical oscillations. The amount of parasitic load depends on the sample time and on the integration method used to discretize the electrical machine.

The Synchronous Machine model and the Asynchronous Machine model use a Trapezoidal discretization method. All other machine models use a Forward Euler discretization method. For the Synchronous Machine and the Asynchronous Machine, you select the machine discretization method in the **Advanced** tab of the block menu.

<mark style="background-color:orange;">**Two integration methods**</mark> <mark style="background-color:orange;">were available in the Advanced tab of the Synchronous Machine and Asynchronous Machine blocks: the</mark> <mark style="background-color:orange;">**Trapezoidal noniterative method**</mark> <mark style="background-color:orange;">or the</mark> <mark style="background-color:orange;">**Trapezoidal iterative method**</mark><mark style="background-color:orange;">.</mark>

<mark style="background-color:orange;">The Trapezoidal non iterative method provides a stable and fast solution. However, to preserve simulation stability, a resistive parasitic load must be connected at machine terminals. For example, for a sample time of 50 µs, the minimum resistive load can be as large as 5 to 10% of machine nominal power. For some applications, the only way to reduce these loads to an acceptable level, say below 0.1% of nominal power, was to simulate machines with the Trapezoidal iterative method. But, with this method, simulation becomes very slow and even fails to converge when the number of machines is increased in a model.</mark>

<mark style="background-color:orange;">Two additional methods have been introduced to discretize the machine models: the Trapezoidal robust method and the Backward Euler robust method. These methods are part of a robust solver that allows simulating machines faster and more accurately. This solver allows you to eliminate the parasitic load and simulate a machine at no load or with a circuit breaker directly connected in series (a circuit topology that was not possible in previous releases). This robust solver does not use an iterative technique, making it suitable for real time applications.</mark>

The new solver addresses a stability problem of the Trapezoidal non iterative method that occurs when large parasitic load are used, and convergence and slow simulation problems of the Trapezoidal iterative method. The following example demonstrates the advantages of using the robust solver.

## **Example of discrete model using SM and ASM blocks**

The following example illustrates impact of the machine discretization methods and amount of parallel load on model stability.

{% stepper %}
{% step %}

### Open example model

Open the **Emergency Diesel-Generator and Asynchronous Motor** example model. This model contains a synchronous machine (SM) and an asynchronous machine (ASM) connected at the same bus in parallel with a 1 MW load.
{% endstep %}

{% step %}

### Configure powergui for discrete simulation

In the Powergui menu, select **Simulation type** = **discrete**, and specify a **sample time** of Ts = 50 μs. In the **Preferences** tab, select **Tustin/Backward Euler discrete solver**.
{% endstep %}

{% step %}

### Initialize machines

Use the Load Flow tool to initialize the machine models.
{% endstep %}

{% step %}

### Start simulation and observe stability with large load

Start the simulation and observe that the model starts in a steady-state. In this model, the default discretization method specified in the Advanced Tab of the synchronous machine block and of the asynchronous machine block is Trapezoidal noniterative. The model is stable because a relative large load of 1 MW is connected at the machine terminals. This load represents 32% of the SM nominal power and 60% of the ASM nominal power.
{% endstep %}

{% step %}

### Test with virtually no load

Now simulate this discrete model with virtually no load connected at machine terminals. Decrease the 1 MW load to 1 kW (representing 0.032% and 0.06% of SM and ASM nominal powers respectively). Change the resistive load from 1 MW to 1 kW and start simulation. Notice numerical oscillations because the 1 kW load is too small to guarantee stability of the machine models.

If you vary the load by steps of 50 kW, you'll find the minimum load required to obtain a stable model with the Trapezoidal noniterative method is 300 kW, corresponding to 6.2% of the total machine nominal power (4.80 MVA = 3.125 MVA for ASM + 1.678 MVA for SM).
{% endstep %}

{% step %}

### Try iterative trapezoidal on SM

In the Advanced tab of the Synchronous Machine block, change the solver to **Trapezoidal iterative**, and leave the **Trapezoidal non iterative** selection for the Asynchronous Machine block solver.\
Simulate the model. Simulation results are the same and as accurate as for a continuous model but return an algebraic loop warning. The drawback of using this solver is the simulation speed.

{% hint style="info" %}
If you attempt to use the Trapezoidal iterative solver for both machines, Simulink® fails to converge.
{% endhint %}
{% endstep %}

{% step %}

### Use robust solvers to simulate at very low load

To simulate this discrete model with a 1 kW load, use either the Trapezoidal robust method or the Backward Euler robust method for both machine blocks. The Trapezoidal robust method is slightly more accurate than the Backward Euler robust method, especially for larger sample times. The Trapezoidal robust method tends to produce slight damped numerical oscillations on voltages when the machines are at no load. The Backward Euler robust method prevents oscillations and maintains acceptable simulation accuracy. The robust solver allows you to eliminate the parallel load at the machine terminals.

Specify the Trapezoidal robust method in both machine blocks and comment out the load. Reconnect the voltage measurement block between phases A and B (otherwise, Simulink returns an error because the ground point that was defined by the load no longer exists). Start the simulation and zoom on the Vab machine voltage to observe small numerical oscillations when the fault is applied and cleared. These oscillations can be avoided if you use the Backward Euler robust method for both machines. The simulation speed obtained with the two types of robust solvers is approximately the same as the one obtained with the Trapezoid non iterative method.
{% endstep %}
{% endstepper %}

## Discretizing Nonlinear Resistors and Inductors

The robust solver provides an accurate modeling of discretized nonlinear resistors and nonlinear inductors by using an iterative method. When using the robust solver to discretize nonlinear resistors and nonlinear inductors, the solution is usually found in one or two iterations. For real time applications, you may need to limit the number of iterations. See the **Solver details for nonlinear elements** preference in the [powergui](broken://pages/6b675cafd3186c01ab96c7f95b67c853a6337435) block reference page.

### **Discretizing Nonlinear Resistors**

A nonlinear resistor is a resistive element where current (model output) is a nonlinear function of voltage (model input). This type of element contains no state. Its output varies instantaneously with input. This means that a direct feedthrough exists between input and output, producing an algebraic loop. Solving this algebraic loop requires an iterative method.

Nonlinear resistor is used, for example, to model the Surge Arrester block. When the Simulation type in the powergui block type is set to *Discrete*, the discretization method is selected in the **Advanced** tab of the Surge Arrester block. Three solution method options can be specified using the **Break Algebraic loop in discrete model** and **Use robust solver in discrete model** checkboxes in the discrete model.

{% stepper %}
{% step %}

### Option: No robust solver (both checkboxes cleared)

The robust solver is not enabled, and the model contains an algebraic loop solved by Simulink, which iterates until the solution is found. Although this method produces correct results, it is not recommended because simulation may fail to converge when the number of Surge Arrester blocks is increased in the model. This method cannot be used in real time applications due to the presence of algebraic loops.
{% endstep %}

{% step %}

### Option: Break algebraic loop in discrete model (only that checkbox selected)

A delay is inserted at the current output of the nonlinear resistor model to break the algebraic loop. This delay requires using small sample times. This method is not recommended because it becomes unstable when sample time is increased.
{% endstep %}

{% step %}

### Option: Use robust solver in discrete model (recommended)

The robust solver provides stable iterations and accurate simulation results. This is the recommended method for discretizing Surge Arrester blocks.
{% endstep %}
{% endstepper %}

### **Discretizing Nonlinear Inductors**

A nonlinear inductor is an inductive element where the current (model output) is a nonlinear function of flux linkage corresponding to the integral of the voltage (model input). To achieve good accuracy, the flux linkage must be computed by using an implicit integration method, such as Trapezoidal or Backward Euler methods. The drawback is a direct feedthrough between input and output, which requires an iterative solution.

The nonlinear inductor is used to implement saturation in single-phase and three-phase transformer blocks. When the **Simulation type** in the powergui block is set to *Discrete*, the discretization method is selected in the **Advanced** tab of the transformer blocks. You can specify four solution methods using the **Break Algebraic loop in discrete model** check box and the **Discrete solver model** parameter.

{% stepper %}
{% step %}

### Option: Break algebraic loop in discrete model (delay inserted at output)

A delay is inserted at the output of the nonlinear inductor model to avoid iterations. This delay requires small sample times to remain stable and produce accurate results.
{% endstep %}

{% step %}

### Option: Trapezoidal iterative (no break checkbox, iterative trapezoidal)

When the **Break Algebraic loop in discrete model** parameter is cleared and the **Trapezoidal iterative** method is used to compute the flux (integration of voltage), Simulink iterates to find the solution. Although this method produces correct results, it is not recommended because simulation may fail to converge when the number of Saturable Transformer blocks is increased in the model. This method cannot be used in real time applications due to the presence of algebraic loops.
{% endstep %}

{% step %}

### Option: Trapezoidal robust

When the **Trapezoidal robust** method is used to compute the flux, the robust solver iterates to find the solution. This is a recommended method. The Trapezoidal robust method is slightly more accurate than the Backward Euler robust method. The Trapezoidal robust method may produce slightly damped numerical oscillations on transformer voltages when transformers are at no load.
{% endstep %}

{% step %}

### Option: Backward Euler robust

When the **Backward Euler robust** method is used to compute the flux, the robust solver iterates to find the solution. This is a recommended method. The Backward Euler robust method prevents oscillations while maintaining acceptable accuracy in no-load scenarios.
{% endstep %}
{% endstepper %}


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation by asking a question.

Perform an HTTP GET request on the following URL with the `ask` and `goal` query parameters:

```
GET https://www.opal-rt.com/docs/smart-power-simulation-software-sps/simulation-and-analysis/simulate-discretized-electrical-systems.md?ask=<question>&goal=<user_goal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is what the user is ultimately trying to achieve, the reason they need the answer. Sharing it helps GitBook give you a better, more relevant answer. A goal is most helpful when it describes the outcome the user wants rather than restating the question. For example, with `ask=how do I create an API token`, a goal like `automate deployments from our CI pipeline` lets GitBook tailor the answer to that use case.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
