Log in

How to Build a Model in Just 11 Lines of Code

By Chloe Allison 07 November 2019

In this article, we will discuss scripting in OnScale and show you how to build the most basic model in OnScale using only 11 lines of code.

Scripting in OnScale

Scripting a model in OnScale via Analyst Mode offers some benefits over our graphical approach, Designer Mode:

  • Greater control of simulation conditions
  • All solver functionality available
  • Simple to batch process

For creating transient simulations, scripting affords users much greater control and flexibility with not only parameters and model set-up, but also with the chronology of the simulation. For example, both static and dynamic models can be run in a single simulation. All that is required is for the user to issue two commands to turn on/off static simulation conditions.

The symbol language is an interpretive language that was developed specifically to handle I/O communication with the Flex family of codes. It is a high-level language that is based on FORTRAN and allows users to:

  • Define variables
  • Issue Flex specific commands
  • Data I/O Perform mathematical operations
  • Perform logic (if, else, goto, procedures)
  • Facilities the creation of Input Files (*.flxinp)

Symbol is a command language with 100s of commands available to build different types of Finite Element (FE) models such as the following:

  • Mechanical
  • Electrical
  • Thermal
  • Piezoelectric
  • Acoustic

Find out more about symbol in our Help Center!

How to build a model in 11 lines of code

The model we are going to build in 11 lines of code is a simple wave propagation model. It is a 2D steel plate and we are going to apply a velocity load at the minimum Y boundary and plot the wave propagation.

Figure 1: Basic Wave Propagation Model Set Up

Only 10 commands and 7 subcommands are required for this model and all commands are used in nearly every model you will ever build in OnScale, so it is important to know these basics.

Note: Primary commands are written at the start of a line and are highlighted in blue, subcommands should be indented and are highlighted green.


Figure 2: Code Line 1 (grid command)

The grid command is used to define the number of nodes that make up the computational grid (or mesh). Here we are setting up a 399 x 399 grid which has a total number of 159201 elements.


Figure 3: Code Line 2&3 (geom command)

The geom command is used to define nodal co-ordinates, so the mesh defined above is mapped as co-ordinates. Here we are making the 399 elements in each direction of the grid fit between 0 and 0.1 m.


Figure 4: Code Line 4 (matr command)

The matr command is required as we must define a material for every element in the model. These materials can be defined using wave speeds or moduli. This line of code defines steel using density and bulk and shear moduli.


Figure 5: Code Line 5 (site command)

The site command assigns material properties to each element of the grid. In this example, we are defining the whole region of the model to be steel.


Figure 6: Code Line 6 (func command)

The func command defines the characteristics of a special purpose function. Here, we are defining a ricker wavelet drive function centred at 1 MHz with amplitude of 1.


Figure 7: Code Line 7 (boun command)

The boun command is used to assign boundary conditions to the entire side of the grid. In this line of code, we are applying our drive function defined above as a velocity boundary condition at the base of the model.


Figure 8: Code Line 8 (prcs command)

The prcs command is used to construct an internal formulation of the defined problem and to allow efficient solution of the model’s response. Every script must contain this command.


Figure 9: Code Line 9 (exec command)

The exec command computes the response of the model. In this example we are executing the model for 400 timesteps.


Figure 10: Code Line 10 (grph command)


The exec command computes the response of the model. In this example we are executing the model for 400 timesteps.


The last command is the term command, and this can be used to pause the simulation and is very useful for debugging purposes.

Figure 11: Output of wave propagation simulation (yvel = velocity in Y direction)

Try it for yourself

This model highlights the basic commands you need to script an OnScale model. In only 11 lines of code you can run a FEA simulation. Here are some more scripted example models!


Chloe Allison
Chloe Allison

Chloe Allison is an Application Engineer at OnScale. She received her MA in Electrical and Electronics Engineering from the University of Strathclyde. As part of our engineering team Chloe assists with developing applications, improving our existing software and providing technical support to our customers.