> 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/hypersim/model-and-simulation/optimize-the-model/use-variables-and-expressions/transmit-variables-within-a-subcircuit.md).

# Transmit Variables within a Subcircuit

To demonstrate how variables can be transmitted within a **subcircuit**, consider the following simple example.

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-88fe893df9452b02c661c54572763afdaf3427ee%2Fsubcircuit-variables-examle.png?alt=media" alt=""><figcaption></figcaption></figure>

| Element           | Library                     | Number |
| ----------------- | --------------------------- | ------ |
| Constant, integer | Control Sources             | 1      |
| Constant, float   | Control Sources             | 2      |
| Selector          | Control Nonlinear And Delay | 1      |

## Implementation steps

{% stepper %}
{% step %}

### Define the variables to be transmitted - Initial values

Right-click the subcircuit and select **Open Parameter Form**. In the dialog box, enter the values to be transmitted to the subcircuit, click **Execute Script**, and then verify them in the **Variables to Transmit** tab. Select the desired variables in the table, then click **Apply**.

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-02a83a98212633880c18e75c024f5e99b0b0c627%2Fparameter-form-subcircuit.gif?alt=media" alt=""><figcaption></figcaption></figure>

Because this mask uses JavaScript, **eight variable names are reserved** and cannot be used. Their values are predefined and managed internally.

<table data-search="false"><thead><tr><th>Variable</th><th>Value</th></tr></thead><tbody><tr><td>E</td><td>Euler’s number</td></tr><tr><td>PI</td><td>PI</td></tr><tr><td>SQRT2</td><td>Square root of 2</td></tr><tr><td>SQRT1_2</td><td>Square root of ½</td></tr><tr><td>LN2</td><td>Natural logarithm of 2</td></tr><tr><td>LN10</td><td>Natural logarithm of 10</td></tr><tr><td>LOG2E</td><td>Base 2 logarithm of E</td></tr><tr><td>LOG10E</td><td>Base 10 logarithm of E</td></tr></tbody></table>
{% endstep %}

{% step %}

### Link variables to a subcircuit <a href="#linking-variables-to-a-subcircuit-component" id="linking-variables-to-a-subcircuit-component"></a>

The next step is to link the transmitted variable(s) to the subcircuit blocks.

First, open the subcircuit design by right-clicking the subcircuit block and selecting **Subcircuit Info**. In the dialog box, click **Open** the subcircuit in its own window.

Double-click the block to open its **Mask Parameters** dialog box. Then, in the desired text box, enter the variable name preceded by an equal sign (=), for example: =MyVariable.

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-6d825e1c6d4bf2f38294e31bec7d6b2e69d3fd38%2Flink-variable-subcircuit.png?alt=media" alt=""><figcaption></figcaption></figure>

Do this for each blocks:

| Element                    | Value     |
| -------------------------- | --------- |
| Const1 (Constant, integer) | =selector |
| Const2 (Constant, float)   | =float1   |
| Const3 (Constant, float)   | =float2   |

The parameter values can now be edited from the parent mask, making it unnecessary to open each block mask separately.
{% endstep %}
{% endstepper %}

## Subcircuit mask parameters

### Rules tab

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-f0cc3158ce86e9bf857f988df939ab0e3e7c4b69%2Fsubcircuit-rules-parameters.png?alt=media" alt="" width="367"><figcaption></figcaption></figure>

The **Rules** tab allows you to define other variables. While the **Initial values** are meant to be directly changed at the top level, and the variables defined in rules are designed to be **calculated** based on the initial values. They can then be transmitted within the subcircuit in the same way.

For example:

1. Initial Value: "radius=4"
2. Rules: "surface=PI\*radius\*radius"
3. Execute script
4. Variable to transmit will offer both radius and surface

The final script is the concatenation of both the Initial Value and Script, the 2 sections are split for clarity when defining the variables.

A good practice is to hide the variables generated by the Rules section if a Custom View was generated for the subcircuit.

### Options tab

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-55ef613c9ceec0a8453dc0264ea6dde7b1d663f4%2Fsubcircuit-options.png?alt=media" alt="" width="367"><figcaption></figcaption></figure>

The **Options** tab provides several settings that control the behavior and appearance of the subcircuit.

<table><thead><tr><th width="200">Parameter</th><th>Description</th></tr></thead><tbody><tr><td><strong>Custom View</strong></td><td><p>Click <strong>Generate</strong> to create an XML file containing a default layout for the subcircuit form. The next time the form is opened, this layout is displayed and can be further customized manually.</p><p>The generated XML file is stored in the model's <code>_hyp/view</code> folder.</p></td></tr><tr><td><strong>Category</strong></td><td>Specifies the category assigned to the subcircuit in the netlist. Categories can be used to organize and group subcircuits.</td></tr><tr><td><strong>Read-only</strong></td><td>When enabled, this option prevents users from editing the parameters of components contained within the subcircuit. Any modifications must then be made through the subcircuit mask, providing a controlled interface for configuring the subcircuit.</td></tr><tr><td><strong>Single Block</strong></td><td>When enabled, the elements contained within the subcircuit are excluded from the netlist and treated as a single entity. This can be useful for simplifying or hiding implementation details within a subcircuit.</td></tr></tbody></table>

After a **custom form** has been generated, you can return to the subcircuit configuration dialog at any time by clicking the button located to the left of the **Sensors** form button.

<figure><img src="https://3623212549-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FLxgTpoh7kyPmQ5vuyqD7%2Fuploads%2Fgit-blob-c73862616c6f9cd8c2c8470a4071923e9cb4d826%2Fsubcircuit-custom-form.png?alt=media" alt="" width="367"><figcaption></figcaption></figure>


---

# 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/hypersim/model-and-simulation/optimize-the-model/use-variables-and-expressions/transmit-variables-within-a-subcircuit.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.
