Shared expressions
Quanscient Allsolve makes use of public variables called shared expressions, that are visible in the scope of a project. This means that once you have defined a shared expression, it can be used in all sections of the application.
You might see fx symbols ( ) in various places throughout the application.
They serve as a reminder to the user - wherever you see an symbol, shared expressions can be used. In the image above for example, shared expression Bext
is used to define external field magnetic flux density in the Y-axis.
Definition
Shared expressions are defined in the Quanscient Allsolve Properties
section. They consist of 3 parameters:
- Name
- A short but descriptive name, by which the shared expression is referred to.
freq
Bext
- A short but descriptive name, by which the shared expression is referred to.
- Description (optional)
- A description of the shared expression in a few words, if it is not obvious from the name and expression.
fundamental frequency
external field magnetic flux density
- A description of the shared expression in a few words, if it is not obvious from the name and expression.
- Expression
- The mathematical expression by which the shared expression is defined.
- An expression can consist of:
- other shared expressions
- double precision numbers in integer, double or scientific format (
42
,-1.72901
,1.2e-18
) - basic algebraic operators (
+
,-
,*
, …) - basic math constants (
pi
,mu0
, …) - Quanscient variables (
t
,x
, …) - predefined functions (
sin
,exp
, …)
To see an exhaustive list of built-in shared expressions and further technical details, see Expressions.
Shared expression use cases
Shared expressions can be utilized in many different areas during simulation setup. These include:
- Creating geometries.
- Setting up material properties.
- Setting up physics interactions.
- Overriding other shared expressions.
- Using shared expressions for parametric sweeps.
- Custom value outputs.
Below are some general points and a practical example for each of these use cases.
Creating geometries
Shared expressions can be very useful for parametrization during modeling.
If you want to model a real world object with known dimensions, you can start out by inputting them as shared expressions, and then move on to modeling. If there is a need to later modify the model dimensions, you can simply edit the values of your shared expressions, and then rebuild the model.
Geometry creation example: Modeling a CMUT membrane disc
- Start out in the
Properties
section by defining the CMUT membrane thickness and radius as shared expressions. - Then, proceed to the
Model
section and add a cylinder. - Use your shared expressions as dimensions for the cylinder.
- Once all necessary elements are built and you’re satisfied with your model, click
Confirm model changes
.
For a more detailed example case, see source: CMUT example case.
Setting up material properties
Material properties can also be defined using shared expressions, be it setting up a new material, or modifying a predefined material. Material properties can later be easily modified through shared expressions.
Material setup example 1: Setting up a new material for a clamped-clamped beam simulation
- Start out in the
Model
section by creating a beam volume using the box element. - In the
Properties
section, create a new material and choose your beam volume as the target. - Define the shared expressions
density
,poisson
(Poisson’s ratio) andyoung
(Young’s modulus). - Add the
Density
andElasticity matrix
properties to your material. - Use your shared expressions to define the property expressions.
For a more detailed example case, see source: Backbone curve of a clamped-clamped beam.
Material setup example 2: Modifying the premade YBCO material for a quench simulation
- In the
Model
section, create a thin sheet for the YBCO layer in your tape using the box element. - In the
Properties
section, select theYBCO
material from the materials database and assign it to your sheet volume. - The current density in the YBCO material is predefined as a constant,
YBCO_Jc
. - Here, we modify the
YBCO_PowerLaw
shared expression, so that the current density is now a function of temperature,Jc(T)
. TemperatureT
and current density functionJc
are added as shared expressions.
For a more detailed example case, see source: Quench - Hello World Demo.
Setting up physics interactions
In addition to material properties, many physics interactions in the Physics
section can be parametrized using shared expressions.
Physics interaction example: Steady state heat transfer
- In the
Model
section, create your model geometry with a box element. - In the
Properties
section, create a new material and assign it to your volume. Define material properties. - Then, define shared expressions
h
(heat transfer coefficient) andTamb
(ambient temperature). - In the
Physics
section, add the physics in the image below. Define the heat source expression as-h * (T - Tamb)
.
For a detailed step-by-step tutorial, see source: Steady state heat transfer in solid materials - NAFEMS Benchmark.
Overriding other shared expressions
Sometimes you might want to modify the value of a shared expression for a specific simulation. Allsolve allows you to override a shared expression for a simulation, changing the value temporarily for the runtime of that 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 simulation setup.
Using shared expressions for parametric sweeps
One of the most powerful applications of shared expressions is in sweep simulations.
Sweeps are an extension to overrides, and a sweep with a single value as the override expression is identical to an override. Only with sweeps, a vector of values can also be input as the override expression. In this case, a series of simulations is run with each override value in the vector.
The sweep override vector can be given in two formats:
- Vectors with just a handful of terms can be given in square brackets.
[90, 95, 100, 105, 110]
- Vectors with many terms can be generated with the
linspace
command.linspace(90, 110, 5)
generates the vector[90, 95, 100, 105, 110]
.linspace(begin, end, n)
begin
is the value of the first vector term.end
is the value of the last vector term.n
is the number of terms in the vector.- The range
begin
-end
is divided inton
equal steps.
- The range
- Naturally, the parameters
begin
,end
, andn
can also be defined as shared expressions.
With sweeps, you can easily run multiple variations of your model in one go, varying one or more parameters. Parameters to be swept must be defined as shared expressions.
Sweep example: Pull-in analysis of a MEMS device
- In the
Properties
section, create the shared expressionVdc
and other shared expressions, including the model dimensions. - In the
Model
section, create the model geometry. - In the
Properties
section, define the model materials. - In the
Physics
section, define the simulation physics. - In the
Simulations
section, create a new mesh. - In the
Simulations
section, create a new simulation. - Add a
Vdc sweep
input to your simulation.
For a detailed step-by-step tutorial, see source: Pull-in analysis of a MEMS device.
Custom value outputs
Shared expressions can be used to define custom value outputs, which are single numerical values that can be extracted from your simulation results. Custom value outputs, along with field outputs, are the two main categories of simulation outputs in Quanscient Allsolve.
Custom value output example: Superconductor AC loss
- In the
Properties
section, create the necessary shared expressions. - In the
Model
section, create the model geometry. - In the
Properties
section, define the model materials. - In the
Physics
section, define the simulation physics. - In the
Simulations
section, create a new mesh. - In the
Simulations
section, create a new simulation. - Add the
HeatPowerHTS
custom value output to your simulation for AC loss results in the twisted HTS filaments.
For a detailed step-by-step tutorial, see source: Superconductor AC Loss.