Expressions
What are expressions in Allsolve
Quanscient Allsolve uses the power of expressions all around the application. You can define and use these for most inputs, wherever you see this icon. An expression can consist of numbers, matrices, simple arithmetics and use of defined variables and functions among other things.
The expression language of Allsolve is a subset of Octave/Matlab. Some functions and variables are predefined for all expressions but a project can have any amount of custom expression.
Expression language
The expression language of Allsolve is a subset of Octave/Matlab. In expressions everything is a matrix of doubles. Even scalars are considered 1x1 matrices.
The supported features are listed below
Numbers
Double precision number in any format, like 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
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 , or component of a field with subfields.
compx
The compx function
compy
The compy function
compz
The compz function
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
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 () 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 () 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.
curl
The curl function
- input: expression
Computes the curl of a vector expression. The returned expression is a vector.
norm
The norm function
- input: expression
gives the 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.
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.
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
where values go linearly from start
to end
-
start: float
-
end: float
-
numValues: int
linspace produces a row vector of length numValues
where values go linearly from start
to end
.
linspace(1, 3, 5)
is resolved to [1, 1.5, 2, 2.5, 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.