**Documentation Home Page** ◇ **HYPERSIM Home Page**

Pour la **documentation en FRANÇAIS**, utilisez l'outil de traduction de votre navigateur Chrome, Edge ou Safari. Voir un exemple.

# Variables and Expressions

# About Expressions in HYPERSIM

HYPERSIM, ScopeView and TestView allow to describe values through variables or mathematical expressions that may or may not refer to other components. These expressions can use regular mathematical symbols (sqrt, ln, pi, e, ...) and component attributes as parameters.

**Note: For expressions to work, first click Analyze to build the network topology.**

## Define a Parameter as an Expression

To designate a parameter as an expression, access the parameter form of the component. You will encounter eligible parameters displayed as text fields. To invoke the Expression Editor, simply enter '=' within the parameter value field.

Expressions are also supported on combobox and radiobutton widgets. In these cases, the Expression Editor can be accessed by right-clicking the ? mark to the right side of the widget.

The *Analyze expression* button computes the expression and checks its validity. If errors are detected, the *Ok* button is disabled, the text “*Wrongly written parameter*“ appears and a popup gives details about the error.

The *Ok* button calls the *Analyze expression* button in the case it hadn't been executed and applies the value to the field in which the *Expression Editor* was called if there are no errors. While editing the expression, you can use ENTER as a shortcut for the *Ok* button.

The *Cancel *button simply closes the window. While editing the expression, you can use ESCAPE as a shortcut for the *Cancel* button.

## Attribute name for a parameter

To discover the attribute name associated with a value, hover your mouse pointer over the parameter's name for a few seconds. The attribute name will then be revealed enclosed within square brackets, as illustrated in this example where the attribute name is* 'ConnexPrim'.*

You can also find the attribute name within the Netlist:

**Analyze the expression**

**If the expression is valid:**

If the expression is purely a number (such as 37, -54.7, 3.1415, 0 ...), the expression is not be considered as an expression when copied in the original text field, simply as a number.

If the expression is purely a mathematical expression with no circuit parameter, the text Nothing to analyze is printed, but the expression is still considered as an expression when clicking

*Ok*.If the expression contains circuit component attributes, then a table is shown at the bottom of the

*Expression Editor*. When computing the expression, all parameters are replaced by the number in the*Value*column, all units, prefixes and suffixes are ignored.Analyzing the expression will check if the result is a valid number, and if it fits within the parameter's limits

**Ok**

Once we click *Ok* with a valid expression, the original text field is updated with the text field's content in the *Expression Editor*. NB: the = is removed when an expression is a pure number. When clicking *Apply* or *Ok* in the parameter form, the field turns blue, which indicates that the field value is an expression. Clicking on it automatically opens the Expression Editor again. Now the parameters in the expression and the target parameter are bound: if one change, the target of the expression will be automatically re-evaluated. Clicking on the field will display the extended-expression in the *fx:* field at the top of the parameter form.

**Syntax**

Mathematical expressions: pi, sqrt(37), log(2) (NB:

*log*here is actually*ln*as some other software), e (=2.718), 3e3 (=3000)To get a parameter in the circuit : [ComponentName].[AttributeName], for example =DelayOn3.Td

To get a parameter in a subcircuit : [SubCircuitN].[ComponentName].[AttributeName]. For example, if we wrap RL101 in a subcircuit FR3: =FR3.RL101.pBase

To assign an expression on a parameter of a subircuit, in the subcircuit form, it is required to add an "=" symbol as the first character. If the symbol is missing, then the parameter will be considered of

*String*type instead of*Double*.The initial = is added in the

*Expression Editor*text field if it has been deleted

**Limitations**

Expressions currently cannot use most 3-phase parameters. One expects the following syntax Ld1.R[2], but it is not implemented. However, it is possible to define each phase of an attribute with an expression.

If Comp1.Attr1 = Comp2.A and the component is moved to a subcircuit, then analyzing the expression won't work because the path to the parameter has changed and is not updated automatically.

It is not recommended to cross-reference expressions, e.g. Comp1.Attr1 = Comp2.A, and then do Comp2.A = Comp1.Attr1.

If the referenced component name is changed, the expression is not updated.

The application can crash in extreme cases, e.g. take 4 constants:

Master

Slave1 = Slave2

Slave2 = Slave3

Slave3 = Slave1 + Master

Changing twice the value of master will result in a fatal error of Java. Then it is not possible to open parameter forms anymore.

In the Python API,

*setComponentParameter*can be used to set an expression. However, the since the "," symbol is used to split phase or array elements, using an expression with "," does not work. For example, see this python sample :

**API setComponentParameter example**

```
# This does not work
HyWorksApi.setComponentParameter('Sine1', 'A', '=Max(10, 5)')
# HYPERSIM understands this as 2 phases on Sine1.A, first phase being "=Max(10" and second phase being "5)"
# This works
HyWorksApi.setComponentParameter('Sine1', 'A', '=Max(10; 5)')
# HYPERSIM understands this as 1 phase because there are no comma, and then replaces the ";" with ","
```

OPAL-RT TECHNOLOGIES, Inc. | 1751, rue Richardson, bureau 1060 | Montréal, Québec Canada H3K 1G6 | opal-rt.com | +1 514-935-2323