> 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-with-continuous-integration-algorithms.md).

# Simulate with Continuous Integration Algorithms

## State-Space Equations

Assuming a circuit containing *nx* states, *ns* switches, and *ny* voltage or current outputs, the software determines:

* nx state derivatives to be computed from the A and B matrices of\
  $$\dot{x} = A \cdot x + B \cdot u$$
* ns switch variables (either voltages across open switches or currents through closed switches)
* ny output variables to be computed from the C and D matrices of

$$
y = C  \cdot  x +D \cdot u
$$

A total of *nx* + *ns* + *ny* equations is obtained.

Unknown variables are state derivatives *dx/dt*, outputs *y*, and switch variables (switch voltages or switch currents). Known variables are state variables *x* and inputs *u* (voltage sources or current sources).

As the switch status (open or closed) is undetermined, circuit equations are expressed using both switch voltages (v<sub>D1</sub>, v<sub>D2</sub>) and switch currents (i<sub>D1</sub>, i<sub>D2</sub>).

These equations express Kirchhoff current laws (KCL) at circuit nodes and Kirchhoff voltage laws (KVL) for the independent loops. These equations are completed by the output equations.

Computation of the state-space model is incorporated in an S-function and performed each time a switch status is changing.

To get a list of the circuit equations in the Diagnostic Viewer, select the **Display circuit differential equations** check box in the **Solver** tab of the Powergui block parameters dialog box.

## Choosing an integration algorithm

Simulink® software provides a variety of solvers. Most of the variable-step solvers work well with linear circuits. However circuits containing nonlinear models, especially circuits with circuit breakers and power electronics, require stiff solvers.

Best accuracy and fastest simulation speed is usually achieved with **ode23tb**.

| Parameter               | Value   |
| ----------------------- | ------- |
| **Solver**              | ode23tb |
| **Relative tolerance**  | 1e-4    |
| **Absolute tolerance**  | auto    |
| **Maximum step size**   | auto    |
| **Initial step size**   | auto    |
| **Solver reset method** | fast    |

Normally, you can choose auto for the absolute tolerance and the maximum step size. In some instances you might have to limit the maximum step size and the absolute tolerance. Selecting too small a tolerance can slow down the simulation considerably. The choice of the absolute tolerance depends on the maximum expected magnitudes of the state variables (inductor currents, capacitor voltages, and control variables).

For example, if you work with high-power circuit where expected voltage and currents are thousands of volts and amperes, an absolute tolerance of 0.1 or even 1.0 is sufficient for the electric states. However, if your electrical circuit is associated with a control system using normalized control signals (varying around 1), the absolute tolerance is imposed by the control states. In this case, choosing an absolute tolerance of 1e-3 (1% of control signal) would be appropriate. If you are working with a very low power circuit with expected currents of milliamperes, set the absolute tolerance to 1e-6.

{% hint style="info" %}
Usually, keeping the **Solver reset method** parameter of the ode23tb solver to its default value (Fast) produces the best simulation performance.\
However, for some highly nonlinear circuits it might be necessary to set this parameter to **Robust**. When you build a new model, we recommend that you try both the Robust and the Fast reset methods. If you do not notice a difference in simulation results, then keep the Fast method, which provides fastest simulation speed.
{% endhint %}

## Simulating switches and power electronic devices

In the **Preferences** tab of the powergui block, you can select **Disable snubbers in switching devices**, which disables snubbers of all switches in your model. Otherwise, you may individually disable snubbers of selected switches by specifying Rs=inf in their block menus. You can also simulate perfectly ideal switches by disabling the resistances (Ron) and the forward voltages (Vf).

Eliminating the snubbers reduces the circuit stiffness and lets you use a non-stiff solver, for example, **ode45** instead of ode23tb, to achieve correct results and good simulation speed.

If you specify resistive snubber values that are too large, the circuit model might become badly conditioned and cause the simulation to stop. In such a case, reduce snubber resistances so that the resulting leakage current remains acceptable (for example 0.01% to 0.1% of switch nominal current).

{% hint style="info" %}
In some circuits, using switches with a forward voltage Vf greater than zero and Ron=0 might cause simulation to stop and display an error message due to a State-Source dependency. To avoid this problem, specify a small Ron value.
{% endhint %}


---

# 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-with-continuous-integration-algorithms.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.
