Variables overrides
When a variable is defined in Allsolve, an initial value is provided which serves as the default for a simulation. In some simulations, you might want to override this default value for one or more variables. For example:
- override the variable’s value to a vector/list of different values to run a parametric sweep simulation.
- override the variable’s value to another scalar value to run a simulation to do a sanity check of the simulation setup, especially for a large scale simulation.
The Variable overrides in the Properties
section of Allsolve allows you to override a variable’s value.
In line with the two examples above, there are two types of variable overrides available:
In both these types, Sweep or Override, you can select one or more variables from the drop-down list and provide an expression for overriding. In this context, such an expression is called an override expression. If the override expression is a vector/list then it is referred as override vector.
Any number of Variable overrides can be created and these would available, by their name, in the simulation Inputs. However, only one of them can be selected. For the variables in this selected Inputs, the override epxression is considered during the simulation. Needless to say that, for the rest of the variables their default initial values would be used.
In Overrides, the override expression provided for each variable must evaluate to scalar value.
Hence, if a vector/list is provided instead, it is not be accepted as a valid override expression by Allsolve.
Sweeps are generic and can accommodate both a vector/list and a scalar value. Usually, the override expression provided here is a vector/list. However, providing a scalar expression is still a valid override vector, since a scalar is considered as a vector/list with a length of one.
More on sweeps
With sweeps, you can easily run multiple variations of your model in one go, varying one or more defined variables. If in the simulation inputs
- a variable override of type sweep is selected and
- any of the override expressions in that sweep are a vector/list, then
parallel subsimulations are run for each value in the vector/list.
Univariate sweeps
In a univariate (1-variable) sweep, just one variable is selected in the Overrides list by clicking + Add override
.
-
If the vector/list is small, the override expression can be entered using square brackets:
-
Larger vectors can be entered using the
linspace
orlogspace
functions:
Multivariate sweeps
If the simulation requires a parametric sweep over two or more variables, then a multivariate sweep setup is needed.
It typically involves selecting more than one variable in the Overrides list by clicking + Add override
.
Multivariate sweeps run by aligning indices between the override vectors, so that subsimulation i
takes the value in index i
of each override vector.
For this reason, when using multivariate sweeps, lengths of override vectors must match.
2-variable sweeps
For example, consider a solid mechanics simulation intended to run for the following list of pairs of Young’s modulus E
and Poisson’s ratio nu
:
(150e9, 0.2), (150e9, 0.25), (160e9, 0.2), (160e9, 0.25)
Here the simulation needs to be swept over two variables: Young’s modulus E
and Poisson’s ratio nu
.
To perform this 2-variable sweep simulation:
-
add a Variable override of type Sweep.
-
select the variables
E
andnu
for override. -
provide the override vectors as in the table below.
Variable Override vector E
[150e9, 150e9, 160e9, 160e9]
nu
[0.2, 0.25, 0.2, 0.25]
Note, that the length of the E
and nu
override vectors match (4 in this case).
Now consider a mechanical warpage sweep simulation also with two variables: temperature T
and coefficient of thermal expansion CTE
.
Assume the ranges of
T = [25, 50, 75, 100, 125, 150]
and
CTE = [1e-6, 2e-6, 3e-6, 4e-6, 5e-6]
and that it is required to run the sweep simulation for all possible resulting pairs of (T, CTE)
as in the image below:
With 6 different values of T
and 5 different values of CTE
, this results in a total of 6 x 5 = 30
pairs of (T, CTE)
.
The override vectors with 30 elements each are provided as follows:
Variable | Override vector |
---|---|
T | [25,25,25,25,25, 50,50,50,50,50, 75,75,75,75,75, 100,100,100,100,100, 125,125,125,125,125, 150,150,150,150,150] |
CTE | [1,2,3,4,5, 1,2,3,4,5, 1,2,3,4,5, 1,2,3,4,5, 1,2,3,4,5, 1,2,3,4,5 ] |
Providing these lists of 30 elements manually for each of the two variables can be quite tedious.
If there are more than two variables with many different values to sweep, it becomes even more painstaking to enter all the vector/list elements.
To simplify providing these long override vectors, it is recommended to use the repelem
and repmat
functions.
For example, the same override vectors, as earlier, for T
and CTE
can now be obtained with a much simpler syntax as shown below:
Variable | Override vector |
---|---|
T | repelem([25, 50, 75, 100, 125, 150], 5) |
CTE | repmat([1e-6, 2e-6, 3e-6, 4e-6, 5e-6], 1, 6) |
As another example, let’s say you have two defined variables v1
and v2
whose sweep values are as below and that you would like to run a parametric sweep for each possible resulting pairs of (v1, v2)
:
Variable | Sweep values | Length |
---|---|---|
v1 | [1, 2] | l1 = 2 |
v2 | [10, 20, 30] | l2 = 3 |
To do so, the override vectors are defined with repelem
and repmat
as follows:
Variable | Override vector | Result |
---|---|---|
v1 | repelem([1, 2], 3) | [1, 1, 1, 2, 2, 2] |
v2 | repmat([10, 20, 30], 1, 2) | [10, 20, 30, 10, 20, 30] |
Vectors can be entered into repelem
/repmat
arguments with the linspace
or logspace
functions:
The generalized expression for a 2-variable sweep is:
Variable | Override vector |
---|---|
v1 | repelem(v1, l2) |
v2 | repmat(v2, 1, l1) |
3-variable sweeps
Let’s add a third variable to the sweep, v3
:
Variable | Sweep values | Length |
---|---|---|
v1 | [1, 2] | l1 = 2 |
v2 | [10, 20, 30] | l2 = 3 |
v3 | [100, 200, 300, 400] | l3 = 4 |
To define the override vectors, it is recommended to use a combination of the repelem
and repmat
functions:
Variable | Override vector |
---|---|
o1 | repelem([1, 2], 3 * 4) |
o2 | repelem(repmat([10, 20, 30], 1, 2), 4) |
o3 | repmat([100, 200, 300, 400], 1, 2 * 3) |
The generalized expression for a 3-variable sweep is:
Variable | Override vector |
---|---|
o1 | repelem(v1, l2 * l3) |
o2 | repelem(repmat(v2, 1, l1), l3) |
o3 | repmat(v3, 1, l1 * l2) |
4-variable sweeps
Let’s add a 4th variable to the sweep, v4
:
Variable | Sweep values | Length |
---|---|---|
v1 | [1, 2] | l1 = 2 |
v2 | [10, 20, 30] | l2 = 3 |
v3 | [100, 200, 300, 400] | l3 = 4 |
v4 | [1000, 2000, 3000, 4000, 5000] | l4 = 5 |
To define the override vectors, it is recommended to use a combination of the repelem
and repmat
functions:
Variable | Override vector |
---|---|
o1 | repelem([1, 2], 3 * 4 * 5) |
o2 | repelem(repelem(repmat([10, 20, 30], 2), 4), 5) |
o3 | repelem(repmat(repmat([100, 200, 300, 400], 1, 2), 1, 3), 5) |
o3 | repmat([1000, 2000, 3000, 4000, 5000], 1, 2 * 3 * 4) |
The generalized expression for a 4-variable sweep is:
Variable | Override vector |
---|---|
o1 | repelem(v1, l2 * l3 * l4) |
o2 | repelem(repelem(repmat(v2, l1), l3), l4) |
o3 | repelem(repmat(repmat(v3, 1, l1), 1, l2), l4) |
o3 | repmat(v4, 1, l1 * l2 * l3) |
You might see a pattern emerging at this point. You’re not likely to need more than 4 override vectors in any simulation, but if you do, the override vector definitions will follow the same logic of combining repelem
/repmat
.
Sweeps over functions
Consider a simple heat conduction problem
for which it is required to run the simulation for different values of thermal conductivity K
, for example 5
, 10
and 15
.
In Allsolve, this is achieved by doing a univariate parametric sweep and the typical workflow is as follows:
-
Define a variable, say
Cu_K
, and provide an initial value: -
Add a suitable material from the library and in the material properties set the thermal conductivity to
Cu_K
: -
In Variable overrides, we define a Sweep and provide a list of different values to sweep over
Cu_K
. -
We set the defined sweep as an input in the simulation.
-
Doing a line plot along the axis, we can see the temperature distribution for different values of thermal conductivity
[5, 10, 15]
.
In the above case, for each of the sweep simulation, the thermal conductivity was assumed to be spatially constant since it was independent of temperature.
However, the thermal conductivity is often a function of temperature K = K(T)
and hence can become field dependent instead of having a single constant value.
-
The graph below shows the interpolated function of temperature dependent thermal conductivity for Residual-resistance ratio (RRR) equal to
30
: -
Now, we can set the thermal conductivity in the material properties as follows.
-
Now let’s say we have temperature dependent thermal conductivity for three different RRR values
30
,300
and3000
, each defined as an Interpolated function. We are interested to perform a sweep over these interpolated functions.
With interpolated functions, it is not possible to create a Sweep by provide an override vector as [Cu_K_RRR30(T), Cu_K_RRR300(T), Cu_K_RRR3000(T)]
.
The values in the override vectors must be evaluable before simulation runtime, but interpolated functions are only evaluable during simulation runtime, when the temperature data is available.
Instead, the below approach is followed:
-
Define a variable, say
sweep_index
, and provide0
as an initial value. -
In material properties, Thermal conductivity, use the
comp()
function ascomp(sweep_index, [Cu_K_RRR30(T); Cu_K_RRR300(T); Cu_K_RRR3000(T)])
. -
In Variable overrides, we define a new Sweep for the variable
sweep_index
and provide the values[0, 1, 2]
. -
In the simulation inputs, we select
Sweep over sweep_index
. -
Now during the sweep simulation, an interpolated function will be chosen depending on
sweep_index
.