Skip to content

Expressions

Expressions in Quanscient Allsolve

Quanscient Allsolve uses the power of expressions all around the application. You can define and use them for most inputs, wherever you see an icon. An expression can consist of numbers, matrices, simple arithmetics and predefined variables and functions among other things.

Some functions and variables are predefined as expressions for all projects but a project can have any amount of custom shared expressions.

Expression language

The expression language of Allsolve is a subset of Octave. In expressions, everything is a matrix of doubles. Even scalars are considered 1 x 1 matrices.

The supported features are listed below.

Numbers

Double precision number in any format, such as 41, 8.91, -0.91233, +4.655e-23.

Constants

Basic mathematical constants are predefined: pi, mu0 and epsilon0. Constants can be used in place of numbers, like 2 * pow(pi,2).

Expression API

Basic math constants

pi

The constant pi

mu0

Vacuum magnetic permeability

epsilon0

Vacuum electric permittivity

Quanscient variables

t

Time in a transient simulation

x

The x-coordinate of the geometry

y

The y-coordinate of the geometry

z

The z-coordinate of the geometry

Basic math functions

sin

The sine function

  • input: expression

cos

The cosine function

  • input: expression

tan

The tangent function

  • input: expression

asin

The inverse sine function

  • input: expression

acos

The inverse cosine function

  • input: expression

atan

The inverse tangent function

  • input: expression

abs

The absolute value function

  • input: expression

sqrt

The square root function

  • input: expression

log

The log function

  • input: expression

log10

The log10 function

  • input: expression

exp

The exponent function

  • input: expression

pow

The power function

  • base: expression

  • exponent: expression

Return an expression equal to base to the power of exponent

mod

The modulo function

  • input: expression

  • modval: float - divisor value

Returns an expression equal to the remainder resulting from the division of input by modval

Quanscient functions

dx

The dx function

  • input: expression

Returns the x space derivative expression.

dy

The dy function

  • input: expression

Returns the y space derivative expression.

dz

The dz function

  • input: expression

Returns the z space derivative expression.

dt

The dt function

  • input: expression

Returns the first-order time derivative expression.

dtdt

The dtdt function

  • input: expression

Returns the second-order time derivative expression.

dtdtdt

The dtdtdt function

  • input: expression

Returns the third-order time derivative expression.

dtdtdtdt

The dtdtdtdt function

  • input: expression

Returns the fourth-order time derivative expression.

max

The max function

  • a: expression

  • b: expression

Returns the maximum value of given values. Can be used with 2 expressions, fields or parameters.

min

The min function

  • a: expression

  • b: expression

Returns the minimum value of given values. Can be used with 2 expressions, fields or parameters.

maxvalue

The expression max function

  • region: Region

  • expression: expression

  • refinement: int

Returns the maximum value of a scalar expression on a region. For example maxvalue(reg.surface, compx(u), 5). Vector expressions needs to be converted to scalar with eg. norm or compx functions. The accuracy of the value of an expression can be improved by providing a higher refinement value.

minvalue

The expression min function

  • region: Region

  • expression: expression

  • refinement: int

Returns the minimum value of a scalar expression on a region. For example minvalue(reg.surface, compx(u), 5). Vector expressions need to be converted to scalar with eg. norm or compx functions. The accuracy of the value of an expression can be improved by providing a higher refinement value.

probe

Probe the value of an expression on a point region

  • region: Region - A point region

  • expression: expression - Expression to evaluate at point.

interpolate

Interpolate the value of an expression on a region in given coordinates.

  • region: Region

  • expression: expression

  • coords: [float, float, float]

Interpolate the value of an expression on a region in given coordinates [x, y, z].

The expression must be scalar. Vector expressions needs to be converted to scalar with eg. norm or compx functions.

ifpositive

Return separate values based on compared value.

  • condExpr: expression

  • trueExpr: expression

  • falseExpr: expression

Returns a conditional expression. The expression value is trueExpr for all evaluation points where condExpr is larger or equal to zero. Otherwise, its value is falseExpr.

Example

At points, where x + y >= 0, value is 1, otherwise -1. ifpositive(x+y, 1, -1)

comp

The comp function

  • component: int

Get the xx, yy or zz component of a field with subfields.

compx

The compx function

Get the x component of a field. Equal to comp(0)

compy

The compy function

Get the y component of a field. Equal to comp(1)

compz

The compz function

Get the z component of a field. Equal to comp(2)

transpose

The transpose function

  • input: expression

Returns an expression that is the transpose of the input vector or matrix expression

inverse

The matrix inverse function

Returns the inverse of a square matrix.

determinant

The matrix determinant function

  • input: expression

Returns the determinant of a square matrix.

grad

The gradient function

  • input: expression

For a scalar input expression, this is mathematically treated as the gradient of a scalar (v\nabla{v}) and the output is a column vector with one entry per space derivative. For a vector input expression, this is mathematically treated as the gradient of a vector (u\nabla{\boldsymbol{u}}) and the output has one row per component of the input and one column per space derivative.

div

The divergence function

  • input: expression

Computes the divergence of a vector expression. The returned expression is a scalar. u\nabla \cdot \boldsymbol{u}

curl

The curl function

  • input: expression

Computes the curl of a vector expression. The returned expression is a vector. w=×u\boldsymbol{w} = \nabla \times \boldsymbol{u}

norm

The norm function

  • input: expression

gives the L2L2 norm of an expression input.

crossproduct

The cross product function

  • a: expression

  • b: expression

Computes the cross-product of two vector expressions. The returned expression is a vector. c=a×b\boldsymbol{c} = \boldsymbol{a} \times \boldsymbol{b}

doubledotproduct

The double dot product function

  • a: expression

  • b: expression

Computes the double-dot product of two matrix expressions. The returned expression is a scalar. A:B=i,jAijBij\boldsymbol{A:B} = \sum_{i,j} A_{ij} B_{ij}

Example

doubledotproduct([1, 2; 3, 4], [11, 12; 13, 14]) is resolved to 130

cn

cn(n) is a shortcut for cos(2 * pi * f * n * t)

  • n: float - fundamental frequency multiplier

sn

sn(n) is a shortcut for sin(2 * pi * f * n * t)

  • n: float - fundamental frequency multiplier

getharmonic

Returns the harmnum harmonic of the expression

  • harmnum: int

  • input: expression

harm

harm(n, expression) returns the nth harmonic of the expression

  • harmnum: int

  • input: expression

makeharmonic

makeharmonic creates a harmonic expression

  • harmonicNumbers: List[int]

  • expr: expression

Create harmonic expression from given harmonic indices and an expression.

on

The on function

  • physreg: Region

  • expr: expression

This function allows to use fields, unknown dof fields or general expressions across physical regions with possibly non-matching meshes by evaluating the expression argument using a (x, y, z) coordinate interpolation.

Integrate to get the total current (flux) through a surface: integrate(reg.integration_surf, on(reg.integration_vol, transpose(j)) * normal(reg.integration_vol), 5)

normal

Returns the normal of a region

  • physreg: Region - region with project dimension

Given a region of project dimension, returns the normal pointing out of the region. For example in a 3D project, the region must be a volume. For 2D, a surface.

Integrate to get the total current (flux) through a surface: integrate(reg.integration_surf, on(reg.integration_vol, transpose(j)) * normal(reg.integration_vol), 5)

linspace

Produces a row vector of length numValues with linearly spaced values from start to end

  • start: float

  • end: float

  • numValues: int

linspace produces a row vector of length numValues with linearly spaced values from start to end. Can be used to create override vectors for sweeps.

linspace(1, 3, 5) is resolved to [1, 1.5, 2, 2.5, 3]

logspace

Produces a row vector of length numValues with logarithmically spaced values from 10^(start) to 10^(end), with default base 10

  • start: float

  • end: float

  • numValues: int

  • base: int

logspace produces a row vector of length numValues with logarithmically spaced values from 10^(start) to 10^(end), with default base 10. If end is pi, values go from 10^(start) to pi instead. Can be used to create override vectors for sweeps.

logspace(1, 3, 5) is resolved to [10, 31.623, 100, 316.228, 1000]

repelem

Repeats elements of a vector numRepeat times

  • vec: vector

  • numRepeat: int

Repeats elements of a vector numRepeat times. Can be used to create override vectors for multivariate sweeps so that numRepeat varies based on other vector lengths.

repelem([1, 2, 3], 3) is resolved to [1, 1, 1, 2, 2, 2, 3, 3, 3]

repmat

Repeats matrix rowRepeat times in row direction and colRepeat times in column direction

  • mat: matrix

  • rowRepeat: int

  • colRepeat: int

Repeats matrix rowRepeat times in row direction and colRepeat times in column direction. Can be used to create override vectors for multivariate sweeps so that rowRepeat is always 1 and colRepeat varies based on other vector lengths.

repmat([1, 2, 3], 1, 3) is resolved to [1, 2, 3, 1, 2, 3, 1, 2, 3]

integrate

Integrates an expression over a region

  • region: Region

  • expr: expression

  • order: int

Integrates an expression over the physical region region. Examples Calculate volume/area/length: integrate(region, 1, 3).

Integrate to get the total current (flux) through a surface: integrate(reg.integration_surf, on(reg.integration_vol, transpose(j)) * normal(reg.integration_vol), 5)

wavelet

Create a wavelet with given frequency and delay

  • frequency: expression

  • delay: expression

ramp

Create a ramp signal

  • rampuptime: expression - The time to transition linearly from value 0 to 1

  • holdtime: expression - The time the value stays at 1

  • rampdowntime: expression - The time to transition linearly from value 1 to 0

  • delay: expression - The time at which the rampup starts

It is a signal that starts initially at value 0. Then at 0 seconds + delay in seconds it transitions from value 0 to 1 in a linear increase. That transition happens in rampuptime seconds. This is followed by a flat value 1 that is held for holdtime seconds. This is followed by a linear decrease from value 1 to 0 that happens in rampdowntime seconds. The value is then forever 0 after that.

vonmises

The von Mises function

  • stress: expression

This returns the von Mises stress expression corresponding to the 3D stress tensor provided as argument. The stress tensor should be provided in Voigt form (σxx,σyy,σzz,σyz,σxz,σxy)(\sigma_{xx},\sigma_{yy},\sigma_{zz},\sigma_{yz},\sigma_{xz},\sigma_{xy}).

For 2D plane stress problems all zz related components of the stress tensor are 00. For plane strain problems do not forget the term (σzz=ν(σxx+σyy))(\sigma_{zz} = \nu \cdot (\sigma_{xx} + \sigma_{yy})).

lineinterpolate

Interpolates the expression at a series of points along a line.

  • region: Region

  • expression: expression

  • firstCoords: [float, float, float]

  • lastCoords: [float, float, float]

  • numSamples: int

This method interpolates the expression at a series of points along a line inside a region. The line for interpolation is defined by a starting and an end point whose [x,y,z] coordinates are provided in the firstCoords and lastCoords arguments.

The numSamples argument determines the number of sample points considered along the line.

If a requested interpolation point along the line cannot be found (because it is outside of region or because the interpolation algorithm fails to converge, as can happen on curved 3D elements) then an error occurs.

To be able to plot the values of nicely, another output should be created that contains the coordinate points. For example outputs:

  1. interpolatedValues = lineinterpolate(reg.box, [0, 0, 0], [0, 100, 0], 11)
  2. yCoords = linspace(0, 100, 11)

absZ

Get the magnitude of the Z = V/I complex impedance.

  • V: expression - Voltage

  • I: expression - Current

For example with a lumped port lump: absZ(lump.V, lump.I)

realZ

Get the real part of the Z = V/I complex impedance.

  • V: expression - Voltage

  • I: expression - Current

For example with a lumped port lump: realZ(lump.V, lump.I)

imagZ

Get the imaginary part of the Z = V/I complex impedance.

  • V: expression - Voltage

  • I: expression - Current

For example with a lumped port lump: imagZ(lump.V, lump.I)

argZ

Get the phase of the Z = V/I complex impedance.

  • V: expression - Voltage

  • I: expression - Current

For example with a lumped port lump: argZ(lump.V, lump.I)