Variables & functions
Quanscient Allsolve uses the power of expressions all around the application. The expressions can be further enhanced with your custom variables and functions (previously shared expressions).
Hierarchy
In Quanscient Allsolve, variables and functions exist in a specific hierarchy:
- Built-in variables/functions
- Immediately usable in any project.
- Elementary constants, variables and functions such as
mu_0
,x
,cos()
, … - For an exhaustive list, see the Expressions reference.
- Global variables/functions
- Predefined variables and functions shared with all users.
- Exist only in the library.
- Local copies can be made to your projects.
- Can be copied into your organization library to make variations specific to your organization.
- Organization variables/functions
- Variables and functions shared with all users in your organization.
- Exist only in the library.
- Local copies can be made to your projects.
- Can be created by exporting a variable/function from a project to the library.
- Project variables/functions
- Are created by the user in a project and exist within the project only.
Defining variables
Variables are defined in the Properties
section. They have 3 parameters:
- Name
- A short but descriptive name, by which the variable is referred to.
freq
Bext
- A short but descriptive name, by which the variable is referred to.
- Description (optional)
- A description of the variable in a few words, along with the unit.
Fundamental frequency [Hz]
Magnetic flux density of the external field [T]
- A description of the variable in a few words, along with the unit.
- Expression
- The mathematical expression by which the variable’s value is computed.
- The expression can consist of:
- numbers in integer, double or scientific format (
42
,-1.72901
,1.2e-18
) - other variables and functions
- basic algebraic operators (
+
,-
,*
, …) - elementary constants (
pi
,mu0
, …) - elementary variables (
t
,x
, …) - elementary functions (
sin
,exp
, …)
- numbers in integer, double or scientific format (
Defining functions
Functions are defined the same as variables, with one additional parameter: Arguments must be given explicitly to the function.
Defining interpolated functions
Functions are defined by giving a set of points ([x, y]
, where y = f(x)
), from which the function is interpolated.
The points can be given manually in the GUI, or as a .csv
file.
Examples of variables/functions and the hierarchy
Let’s say that in all projects under your organization, you need to use the materials Al
and Cu
.
You add them to your organization library so they can be copied to any project within the organization.
In one of your projects you have a sphere with radius = 1
.
As a project variable, the variable radius
is project specific and accessible only within the project.
If you have the same sphere with the same radius in many organization projects, it makes sense to add an organization variable.
You add the variable sphere_radius = 1
to the library, so it’s accessible in any of your organization projects.
Now if you edit the project variable radius
, it won´t affect sphere_radius
, which is a library variable.
Similarly, editing sphere_radius
within the library won’t affect the project variable radius
or other independant copies.
When a new copy is made of sphere_radius
however, it will have the updated value.
When you need to use custom function across all your organization projects, you can define one in the library.
If you work a lot with cos(x + pi/2)
for example, you can define the library function cos_shift = cos(x + pi/2)
.
Use-cases
Variables and functions can be utilized in many different areas in projects. Below are some practical examples for each of these use-cases.
Creating geometries
Variables and functions can be very useful for parametrization during modeling.
If you want to model an object with known dimensions, you can start out by inputting them as variables and functions, and then move on to modeling. If there is a need to later modify the model dimensions, you can simply edit your variables and functions and rebuild the model.
Example: CMUT membrane disc
- CMUT membrane thickness and radius are defined as variables
thmem
andradmem
: thmem
andradmem
are used to create the CMUT membrane disc:
Source: CMUT example case
Material properties
Material properties can be defined using variables and functions. Material properties can then be modified through the variables and functions.
Example 1: Clamped-clamped beam
- Variables
density
,poisson
(Poisson’s ratio) andyoung
(Young’s modulus) are defined. density
,poisson
andyoung
are used to define theDensity
andElasticity matrix
material properties:
Source: Backbone curve of a clamped-clamped beam
Example 2: YBCO Quench
- The superconducting
YBCO
material is added. Variables are automatically created for the YBCO power law. - The current density is automatically defined as the variable
YBCO_Jc
, which has a constant value. YBCO_PowerLaw
is modified, so that the current density is now a function of temperature,Jc(T)
. The temperature variableT
and the current density functionJc
are added.
Source: Quench - Hello World Demo
Physics interactions
Many physics interactions can be parameterized using variables and functions.
Example: Steady state heat transfer
- Variables
h
(heat transfer coefficient) andTamb
(ambient temperature) are defined. - Heat source expression is given as
-h * (T - Tamb)
:
Source: Steady state heat transfer in solid materials - NAFEMS Benchmark
Overriding variables and functions
Allsolve allows you to override a variable’s value for the runtime of a simulation. This can be used in sensitivity analysis or debugging, for example, where it is useful to quickly test the effect of changing a single parameter without modifying the original setup.
Sweeps
One of the most powerful applications of variables is in simulation sweeps. Sweeps are an extension to overrides, and a sweep with a single value as the override is identical to an override. Sweeps allow you to provide a vector of different values as the override expression. In this case, a series of simulations is run - one simulation for each value in the override vector. With sweeps, you can easily run multiple variations of your model in one go, varying one or more variables. They are mainly two kinds of sweeps that can be performed:
- Parametric sweep: The variable considered for sweep is used elsewhere than the geometric creation.
- Geometric sweep: The variable considered for sweep is used in creating geometries.
The typical simulation setup for both are similar except one additional step required in geometric sweep.
Parametric sweeps
If a variable is used in material properites, physics interactions and custom value outputs, but not in geometry creation, then performing a sweep over it is categorized as Parametric sweeps. The usual workflow for a parametric sweep setup is as follows:
- Define a Variable.
- Use the variable in the simulation setup.
- Create a Variable override.
- Add the Variable override in the simulation Inputs.
Example: MEMS Pull-in analysis
- Direct current voltage is defined as a variable,
Vdc
. - A
Vdc sweep
input is added to the simulation:
Source: Pull-in analysis of a MEMS device
Geometric sweeps
If a variable is used in geometry creation, then performing a sweep over it means running the simulation for varying values of a geometric dimension and is categorized as geometric sweeps. Consequently, a corresponding mesh must generated for each value of geometric dimension and hence its workflow warrants an additional step in the sweep setup:
- Define a Variable.
- Use the variable in geometry creation.
- Create a Variable override.
- Add the Variable override in the simulation Inputs.
- In addition, add the Variable override also in the Meshes to create a mesh for each value of override vector.
Custom value outputs
Variables and functions can be used to define custom value outputs, which are single numerical values that can be extracted from your simulation results. Custom value outputs and field outputs are the two main categories of simulation outputs in Allsolve.
Using fields in functions
Fields, such as displacement field u
, current density field j
or magnetic flux density field B
can be used in functions, but they must be passed on to them as arguments.
Example: YBCO Powerlaw
When the superconducting YBCO material is added to a project, the YBCO PowerLaw
function is automatically created:
Note, that the j
field is added as an argument in the function definition.
The function is called in the actual YBCO material properties with j
passed to it inside the parentheses: