OnScale Blog

Our blog covers tips for using OnScale, new features and developments, and upcoming events and webinars.  Subscribe and get the latest posts in your inbox.

All Posts

How to Build a Model in Just 11 Lines of Code

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.

Model 1Figure 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.

Grid

model 2Figure 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.

Geom

model 3Figure 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.

Matr

model 4Figure 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.

Sitemodel 5

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.

Func

model 6Figure 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.

Boun

model 7Figure 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.

Prcs

model 8Figure 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.

Exec

model 9Figure 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.

Grph

model 10Figure 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.

Term

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

model 11Figure 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!

 

Get Started With OnScale Today

Chloe Allison, Application Engineer at OnScale
Chloe Allison, Application Engineer at OnScale
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.

Related Posts

The Basic Principle of Sonic Logging Tools

Sonic Logs first appeared in 1957. Sonic logs rely on the properties inherent in Snell’s Law to propagate sound from a logging tool through the rock to receivers located on the same logging tool.

Multi-Layer Transducer Monte Carlo Study

Let’s talk about Monte Carlo Simulation (MCS) and how it can be used to optimize transducer design.

How to Build Arrays in OnScale

One of the inherent problems with old legacy FEA software is the inability to run large problems – for example legacy simulation packages lack the capability to simulate large arrays in full 3D . This has stunted the development of devices such as PMUTs as the full systems couldn’t be properly simulated.