1. Variables and Scripting

Variables and scripts allow you to parameterize your model and create dynamic relationships between values. This is essential for setting up parameter studies with condition sets and condition spaces.

For a step-by-step tutorial, see How to make a parameterized model.

1.1. Variables

You can create variables and assign them to an object value. In the picture below we have created two variables; HS (wave height) and TP (wave period). HS has been assigned to the significant wave height and TP has been assigned to the peak period in the wind wave object of the environment (You assign a variable to an object value by right clicking the value without entering the edit mode first and select set script from the pop-up menu).

image

The following variable types are available:

1.2. Using variables in conditions

A good example where using variables comes in handy is when setting up a condition space. Here you get access to all your defined variables and may define as many value combinations as needed for this case.

In the case shown below, the user has defined 3 variations of HS and 3 variations of TP, and by this specifying 9 runs.

image

After all runs are done you end up with a list of results in your condition space where the name of the result folder matches the full combination of variables you set up.

image

You can also use variable modifications inside model variations to override variable values for specific conditions.

1.3. Scriptable values / scripts

You can define variables in a task for different purposes. One purpose could be to vary wave height and wave period thus creating a set or space (matrix) of weather conditions to be used in condition sets or condition spaces. Another purpose could be to connect objects to each other. For instance you could say that a body always should be positioned at another body’s position + 50 meters in the x-axis. This has the effect that if the other body is moved the first body that has the scriptable value attached to it also will move according to the given formula.

First create the variables you need, that being double, integer or string variables.

image

It is also possible to create a new variable from an existing value in a double, integer, or string field.

Right-click the wanted value (in grids you need to be editing the value when right-clicking) and select set as variable. In the subsequent dialogue you need to specify a name for the new variable. The new variable will be created using the selected value and it will be assigned as script.

image

Use the variables to create scripts in your model. Note that fields where a script has been set has a changed background color.

To open the scripts editor use the keys Ctrl+2 or right click the field and select Set script.
If you use the mouse to hover over a scripted field you will get a tooltip showing the script which results in the displayed value.

image

There is included support for using a Java Math library.

This enables you to create mathematical expression in your scripts.

image

Note that you do not have to write Math. in front of the function you would like to use.

Inside the script editor you may use Ctrl+space to show the list of available objects to use in your script.

When you have selected an object and want to dig deeper - add a . and use Ctrl+space to get a list of the current available objects.

image

See also Script for information on the script task item.