Skip to content

Simulation script

In Quanscient Allsolve, all user-set options in the GUI generate python script files automatically, which can be viewed in the Script of the added simulation. The script files are grouped as follows:

  • Autogenerated scripts: These scripts cannot be edited directly, but can be modified by changing settings in the GUI.
  • Your scripts: Switch between autogenerated simulation.py script with small customizations and full scripting mode for complete control over the simulation code.
  • Extra input files: Any additional input files for simulations. This section is by default hidden and can be viewed only if the simulation.py is customized using Insert code or if Full scripting mode is enabled.

Script overview

Under the Your scripts, is the default Base script which is named simulation.py and is the main execution script. This script is composed of the following components:

  • importing packages
  • defining utility objects
  • loading mesh
  • defining fields
  • setting boundary conditions
  • defining physics
  • solving physics
  • setting filed outputs
  • setting variable outputs

The structure above will be broken down on the example case of Cantivelar beam bending. Cantileverbeam Script

Simulations in Quanscient Allsolve are scripted in Python. At the beginning the necessary packages are imported. Importing modules The math, csv and json are built-in Python modules. The rest of the imported modules are Allsolve-defined modules. The core of the Allsolve scripting is the quanscient module. All the functions and classes of this module are documented in Script API. The remaining modules (utils, expression, materials, regions and parameters) can be found in the Auto-generated scripts. Autogenerated scripts

In this section of the script, the utility objects are defined, which will manage operations such as mesh handling, variable definitions, and field interactions. Utility objects

In this section, the previously defined utility object mesh preprocesses and loads the mesh. The mesh that is loaded here corresponds to the one added to the simulation in the GUI. The pre-processing of the mesh usually includes instructions for creating skin regions and DDM partitioning. Mesh loading

Fields to be solved are defined using the field method from the qs library. The field method holds all the methods of the finite element field.

For the bending of the cantilever beam, the field defined is fld.u which corresponds to mechanical displacement. The field definition is typically followed by setting the interpolation order using the setorder method. Field definition

The setconstraint method is used to define the Dirichlet boundary condition. Note that the boundary condition of Neumann type are defined in the Physics formulation. Boundary conditions

The governing equation of the physics is defined by adding the weak formulation terms to the formulation object. Note that the load interaction in this case is the Neumann boundary condition. Physics definition

The weak formulation of the physics is solved by calling the allsolve method. The arguments passed to allsolve method controls convergence criteria and solver stability. Solving

Once the field is solved, the field outputs (u here) are written using the setoutputfield method. After the field outputs are written they are available under Results --> Visualization in the GUI.

The value outputs contain discrete values and are written using setoutputvalue method. The value outputs will be available under Results --> Summary. Setting outputs