> 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/blocks-functions-tools/basics/power_customize/repairing-custom-blocks-from-simscape-specialized-power-systems.md).

# Repairing Custom Blocks from Simscape Specialized Power Systems

## Overview <a href="#overview" id="overview"></a>

Blocks that have been customized using the MATLAB function `power_customize` on blocks from **Simscape™ Specialized Power Systems** may **not directly compatible** with the **OPAL‑RT SPS Product**.

{% hint style="info" %}

## This incompatibility is expected:

Customized SPS blocks may contain internal implementation details that differ from those required by the OPAL‑RT solver and execution environment.
{% endhint %}

To address this, a **repair utility** has been developed to update an existing customized block so that it becomes **compatible with the OPAL‑RT SPS Product**, while preserving as much of the user customization as possible.

## What the Repair Tool does <a href="#what-the-repair-tool-does" id="what-the-repair-tool-does"></a>

The repair tool operates directly on an **existing customized SPS block** and performs a series of automated corrections, including:

* Synchronizing internal implementation blocks with the supported OPAL‑RT SPS reference library
* Updating callback definitions inherited from the reference SPS block
* Restoring internal consistency of SPS blocks
* Removing obsolete or unsupported internal blocks when no valid reference exists

The goal of the repair is **structural compatibility**, not behavioral validation.

## How to use the Repair Tool <a href="#how-to-use-the-repair-tool" id="how-to-use-the-repair-tool"></a>

**Prerequisites**

* The customized block must have been created using `power_customize`
* The block must belong to a **library**, not a regular model
* The customized block name must end with `(custom)`
* The OPAL‑RT SPS Product must be available in the MATLAB path

{% stepper %}
{% step %}

### **Open the library**

where the customized SPS block is located.
{% endstep %}

{% step %}

### **Select the customized block**

<figure><img src="https://799605156-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdlNg8IbOdahCpFCyzxSN%2Fuploads%2Fgit-blob-737e73148d809a700e8a7d4752f725c4c4c0a06e%2Fimage-20260407-181346.png?alt=media" alt=""><figcaption></figcaption></figure>
{% endstep %}

{% step %}

### From the MATLAB Command Window

run: `sps.utils.repairCustomizedBlock`
{% endstep %}

{% step %}

### Observe the messages printed in the MATLAB Command Window

During execution, the function analyzes the customized block and applies updates as needed. A **summary of the actions performed** is displayed in the Command Window so that users are aware of what was modified

<details>

<summary>Example</summary>

{% code lineNumbers="true" %}

```matlab
Attempting to repair custom SPS block = power_SLmodeling_lib/Synchronous Machine
pu Fundamental (custom)...
  Reference block in OPAL-RT SPS Product: spsSynchronousMachinepuFundamentalLib/Synchronous Machine
pu Fundamental

- Replacing callbacks in power_SLmodeling_lib/Synchronous Machine
pu Fundamental (custom)...
   * CloseFcn
   * CopyFcn
   * DeleteFcn
   * InitFcn
   * LoadFcn
   * ModelCloseFcn
   * NameChangeFcn
   * OpenFcn
   * PostSaveFcn
   * PreCopyFcn
   * PreDeleteFcn
   * PreSaveFcn
   * StartFcn
   * StopFcn
   * UndoDeleteFcn

- Updating internal block power_SLmodeling_lib/Synchronous Machine
pu Fundamental (custom)/SM...
  Reference block in OPAL-RT SPS Product: spsSynchronousMachinepuFundamentalLib/Synchronous Machine
pu Fundamental/SM
  * Added new OPAL-RT SPS Product block from spsSynchronousMachinepuFundamentalLib/Synchronous Machine
pu Fundamental/SM.
  * Removed old power_SLmodeling_lib/Synchronous Machine
pu Fundamental (custom)/SM internal block.
A copy of the original file "power_SLmodeling_lib.slx" has been created because it was last saved in an earlier version of Simulink. To recover the original version, rename the file "power_SLmodeling_lib.slx.r2021b" as "power_SLmodeling_lib.slx".

You can turn this feature off using the Simulink Preferences. Click here if you don't want to see this message again.

--------------------------------------------------------------------------
Note: The expected behavior of this custom block cannot be guaranteed.
It is recommended to perform a review to ensure it still meets the initial
requirements before simulating a model that uses it.
--------------------------------------------------------------------------
```

{% endcode %}

</details>
{% endstep %}
{% endstepper %}

## Important notes and limitations <a href="#important-notes-and-limitations" id="important-notes-and-limitations"></a>

### **No behavioral guarantee**

While the tool restores compatibility with the OPAL‑RT SPS Product, it **does not guarantee** that the customized block behaves exactly as it did before customization.

Custom modifications may:

* Change solver behavior
* Affect numerical stability
* Alter simulation results

### **Manual review strongly recommended**

After running the repair:

* Open the repaired block
* Inspect its parameters and mask
* Test it in a simple model

<figure><img src="https://799605156-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdlNg8IbOdahCpFCyzxSN%2Fuploads%2Fgit-blob-0cee28214609f4229388cc519fefcd8c3ae899a5%2Fimage-20260407-183357.png?alt=media" alt=""><figcaption></figcaption></figure>

In the example model from the figure above the lines became blue as a result of repairing the custom block’s reference. This indicates the custom block has been recognized as a *valid OPAL-RT SPS Product block*. Finally, the model has been simulated and the results exhibited the expected behavior.

<figure><img src="https://799605156-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FdlNg8IbOdahCpFCyzxSN%2Fuploads%2Fgit-blob-289b89d3cce50d192c54dc74d9317fece2520032%2Fimage-20260407-183539.png?alt=media" alt=""><figcaption></figcaption></figure>

### **Backup first**

It is strongly recommended to **save a copy of the library** containing the custom block before running the repair tool.


---

# 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/blocks-functions-tools/basics/power_customize/repairing-custom-blocks-from-simscape-specialized-power-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.
