1. Mechanical#

1.1. Introduction#

A virtual experiment of the standard mechanical tensile test is performed using a linear elastic model.

In this experiment a ‘dog-bone’ shaped sample is loaded either through constant force, measuring the displacement, or constant displacement, measuring the required load. This provides information about mechanical properties such as Young’s elastic modulus.

Action

The RunFile RunTutorials.py should be set up correctly for this simulation:

#===============================================================================
# Definitions
#===============================================================================
Simulation='Tensile'
Project='Tutorials'
Parameters_Master='TrainingParameters'
Parameters_Var=None

#===============================================================================
# Environment
#===============================================================================

VirtualLab=VLSetup(
           Simulation,
           Project
           )

VirtualLab.Settings(
           Mode='Interactive',
           Launcher='Process',
           NbJobs=1
           )

VirtualLab.Parameters(
           Parameters_Master,
           Parameters_Var,
           RunMesh=True,
           RunSim=True,
           RunDA=True
           )

#===============================================================================
# Methods
#===============================================================================

VirtualLab.Mesh(
           ShowMesh=False,
           MeshCheck=None
           )

VirtualLab.Sim(
           RunPreAster=True,
           RunAster=True,
           RunPostAster=True,
           ShowRes=True
           )

VirtualLab.DA()

The setup above means that the path to the Parameters_Master file used is Input/Tensile/Tutorials/TrainingParameters.py. Open this example python file in a text editor to browse its structure.

Before any definitions are made, you will notice the import statement:

from types import SimpleNamespace as Namespace

A Namespace is essentially an empty class that attributes can be assigned to.

The Namespace Mesh and Sim are created in Parameters_Master in order to assign attributes to for the meshing and simulation stages, respectively. Since DA is not defined in Parameters_Master no data analysis will take place.

1.2. Sample#

Mesh contains all the variables required by SALOME to create the CAD geometry and subsequently generate its mesh.

Mesh.Name = 'Notch1'
Mesh.File = 'DogBone'

Mesh.File defines the script used by SALOME to generate the mesh, which in this case is Scripts/Experiments/Tensile/Mesh/DogBone.py.

Once the mesh is generated it will be saved to the sub-directory Meshes of the project directory as a MED file under the user specified name set in Mesh.Name. In this instance the mesh will be saved to Output/Tensile/Tutorials/Meshes/Notch1.med.

The attributes of Mesh used to create the sample geometry in DogBone.py are:

# Geometric Parameters
Mesh.Thickness = 0.003
Mesh.HandleWidth = 0.024
Mesh.HandleLength = 0.024
Mesh.GaugeWidth = 0.012
Mesh.GaugeLength = 0.04
Mesh.TransRad = 0.012
Mesh.HoleCentre = (0.0,0.0)
Mesh.Rad_a = 0.0005
Mesh.Rad_b = 0.001

The interpretation of these attributes in relation to the sample is shown in Fig. 1.1.

https://gitlab.com/ibsim/media/-/raw/master/images/VirtualLab/DogBone.png

Fig. 1.1 Drawing of the ‘dog-bone’ sample with the attributes of Mesh used to specify the dimensions.#

2Rad_a and 2Rad_b refer to the radii of an elliptic hole machined through a point offset from the centre by HoleCentre. The attribute TransRad is the radius of the arc which transitions from the gauge to the handle.

The remaining attributes relate to the mesh refinement parameters:

# Meshing Parameters
Mesh.Length1D = 0.001
Mesh.Length2D = 0.001
Mesh.Length3D = 0.001
Mesh.HoleSegmentN = 30

Length1D, 2D and 3D specify the discretisation size (or target seeding distance) along the edges, faces and volumes respectively, while HoleSegmentN specifies the number of segments the circumference of the hole is divided into.

The attributes of Mesh used to create the CAD geometry and its mesh are stored in Notch1.py alongside the MED file in the Meshes directory.

1.3. Simulation#

The attributes of Sim are used by Code_Aster and by accompanying pre/post-processing scripts:

Sim.Name = 'Single'
Sim.AsterFile = 'Tensile'

Sim.Name specifies the name of the sub-directory in Output/Tensile/Tutorials/ into which all information relating to the simulation will be stored. The file Parameters.py, containing all attributes of Sim, is saved here along with the output generated by Code_Aster and any pre/post-processing stages.

The attribute Sim.AsterFile specifies the file used by Code_Aster to run a virtual experiment, which in this case is Scripts/Experiments/Tensile/Sim/Tensile.comm. The extension .comm is short for command, which is the file extension for scripts used by the Code_Aster software.

The attributes used by Code_Aster are:

Sim.Mesh = 'Notch1'
Sim.Force = 1000000
Sim.Displacement = 0.01
Sim.Materials = 'Copper'

Sim.Mesh specifies which mesh is used in the simulation.

The attribute Force specifies the magnitude, in Newtons, which is used to load the sample during the force-controlled simulation, while Displacement specifies the enforced displacement, in metres, which is applied during the forced displacement simulation.

Note

If both Force and Displacement are attributed to Sim then both force-controlled and displacement-controlled simulations are run. If, for example, you only wish to run a constant force simulation, then this can be achieved either by removing the attribute Displacement or by setting it to zero.

The attribute Materials specifies the material the sample is composed of.

In this instance, since Sim has neither the attributes PreAsterFile or PostAsterFile, no pre or post processing will be carried out.

1.4. Task 1: Running a simulation#

Due to Parameters_Var being set to None, a single mesh and simulation will be run using the information from Parameters_Master.

The mesh generated for this simulation is ‘Notch1’, while the name for the simulation is ‘Single’, given by Sim.Name. All information relating to the simulation will be saved to the simulation directory Output/Tensile/Tutorials/Single.

Since Force and Displacement are attributes of Sim a force-controlled simulation (with magnitude 1000000N) is run, along with a displacement controlled simulation (with enforced displacement 0.01m). The material properties of copper will be used for the simulation.

With Mode set to ‘Interactive’ in the setup section of RunTutorials.py, when launching VirtualLab firstly you will see information relating to the mesh printed to the terminal, e.g. the number of nodes and location the mesh is saved, followed by the Code_Aster output messages for the simulation printing in a separate xterm window, see Fig. 1.2.

Note

Due to a change in X-Window implementation, ‘Interactive’ is currently not in use within VirtualLab. However, if set, it will behave the same as using ‘Terminal’. That is, output will be printed to the main terminal.

Action

Launch your first VirtualLab simulation by executing the following command from command line (CL) of the terminal whilst within the VirtualLab directory:

VirtualLab -f RunFiles/RunTutorials.py
https://gitlab.com/ibsim/media/-/raw/master/images/docs/screenshots/Xterm_01.png

Fig. 1.2 Xterm window which opens if VirtualLab is set to run with Mode as ‘Interactive’.#

Running this simulation will create the following outputs:

  • Output/Tensile/Tutorials/Meshes/Notch1.med

  • Output/Tensile/Tutorials/Meshes/Notch1.py

  • Output/Tensile/Tutorials/Meshes/Notch1.log

  • Output/Tensile/Tutorials/Single/Parameters.py

  • Output/Tensile/Tutorials/Single/Aster/Export

  • Output/Tensile/Tutorials/Single/Aster/AsterLog

  • Output/Tensile/Tutorials/Single/Aster/TensileTest.rmed

  • Output/Tensile/Tutorials/Single/Output.log

The first two output files relate to the mesh generated. The .med file contains the mesh data, while the attributes of Mesh are saved to the .py file.

The remaining outputs are all saved to the simulation directory. Parameters.py contains the attributes of Sim which has been used for the simulation.

The file Aster/Export was used to launch Code_Aster and contains information on how it was launched. Aster/AsterLog is a log file containing the Code_Aster output, which is the same information shown in the xterm window. The file Aster/TensileTest.rmed contains the results generated by Code_Aster. Since both Force and Displacement attributes were specified the results for both are stored in this file.

Note

The file extension .rmed is short for ‘results-MED’ and is used for all Code_Aster results files.

Because ShowRes is set to True in VirtualLab.Sim, TensileTest.rmed is opened in ParaVis for visualisation automatically. Here you will be able to view the following fields, see Fig. 1.3 and Fig. 1.4:

Force_Displacement - Displacement for constant force simulation.
Force_Stress - Stress for constant force simulation.
Disp_Displacement - Displacement for constant displacement simulation.
Disp_Stress - Stress for constant displacement simulation.

Note

You will need to close the xterm window once the simulation has completed for the results to open in ParaVis.

https://gitlab.com/ibsim/media/-/raw/master/images/docs/screenshots/ParaVis_01.png

Fig. 1.3 ParaVis visualisation of sample as seen when opened automatically with ShowRes set to True.#

https://gitlab.com/ibsim/media/-/raw/master/images/docs/screenshots/ParaVis_02.png

Fig. 1.4 ParaVis visualisation of Von Mises stress in the sample for a displacement controlled virtual experiment.#

File structure hierarchy

Location of the key files and directories for Task 1 of this tutorial:

| VirtualLab
| ├── .log
| ├── Config
| ├── Containers
| ├── Input
| │   ├── HIVE
| │   ├── LFA
| │   └── Tensile
| │       └── Tutorials
| │           └── TrainingParameters.py
| ├── Materials
| │   ├── Copper
| │   │   ├── Alpha.dat
| │   │   ├── Cp.dat
| │   │   ├── Lambda.dat
| │   │   ├── PoisRat.dat
| │   │   ├── Rho.dat
| │   │   └── Youngs.dat
| │   ├── Copper_NL
| │   ├── Tungsten
| │   └── Tungsten_NL
| ├── Output
| │   └── Tensile
| │       └── Tutorials
| │           ├── Meshes
| │           │   ├── Notch1.log
| │           │   ├── Notch1.med
| │           │   └── Notch1.py
| │           └── Single
| │               ├── Aster
| │               │   ├── AsterLog
| │               │   ├── Export
| │               │   └── TensileTest.rmed
| │               ├── Output.log
| │               └── Parameters.py
| ├── RunFiles
| │   └── RunTutorials.py
| ├── Scripts
| │   ├── Common
| │   ├── Experiments
| │   │   ├── HIVE
| │   │   ├── LFA
| │   │   └── Tensile
| │   │       ├── Mesh
| │   │       │   └── DogBone.py
| │   │       └── Sim
| │   │           └── Tensile.comm
| │   ├── Install
| │   └── Methods
| ├── bin
| ├── docs
| └── tests
|
|

1.5. Task 2: Running Multiple Simulations#

The next step is to run multiple simulations. This is achieved using Parameters_Var in conjunction with Parameters_Master.

The Parameters_Var file Input/Tensile/Tutorials/Parametric_1.py will be used to create two different meshes which are used for simulations. Firstly, you will see value ranges for Mesh.Rad_a and Mesh.Rad_b along with the Name for each mesh:

Mesh.Name = ['Notch2','Notch3']
Mesh.Rad_a = [0.001,0.002]
Mesh.Rad_b = [0.001,0.0005]

Any attributes of Mesh which are not included in the Parameters_Var file will instead use the values from Parameters_Master. For example, ‘Notch2’ will have the attributes:

Mesh.Name = 'Notch2'
Mesh.File = 'DogBone'

Mesh.Thickness = 0.003
Mesh.HandleWidth = 0.024
Mesh.HandleLength = 0.024
Mesh.GaugeWidth = 0.012
Mesh.GaugeLength = 0.04
Mesh.TransRad = 0.012
Mesh.HoleCentre = (0.0,0.0)
Mesh.Rad_a = 0.001
Mesh.Rad_b = 0.001

Mesh.Length1D = 0.001
Mesh.Length2D = 0.001
Mesh.Length3D = 0.001
Mesh.HoleSegmentN = 30

Simulations will then be performed for each of these samples:

Sim.Name = ['ParametricSim1', 'ParametricSim2']
Sim.Mesh = ['Notch2', 'Notch3']

In this instance, only the simulation geometry (hole radii) will differ between ‘ParametricSim1’ and ‘ParametricSim2’.

The results for both simulations will be opened in ParaVis. The results will be prefixed with the simulation name for clarity, see Fig. 1.5.

Action

Change Parameters_Var in the RunFile:

Parameters_Var='Parametric_1'

Launch VirtualLab:

VirtualLab -f RunFiles/RunTutorials.py
https://gitlab.com/ibsim/media/-/raw/master/images/docs/screenshots/ParaVis_03.png

Fig. 1.5 ParaVis visualisation of parametric analysis of sample where the dimensions of the void in its centre were varied.#

Compare Notch2.py and Notch3.py in the Meshes directory. You should see that only the values for Rad_a and Rad_b differ. Similarly, only Mesh will be different between ParametricSim1/Parameters.py and ParametricSim2/Parameters.py in the project directory.

Warning

The number of entries for attributes of Mesh and Sim must be consistent.

For example, if Mesh.Name has 3 entries then every attribute of Mesh in Parameters_Var must also have 3 entries.

1.6. Task 3: Running Multiple Simulations Concurrently#

The last task introduced you to running multiple simulations, however both the meshing and simulations were run sequentially. For more complex meshes and simulations this would be very time consuming. VirtualLab has the capability of running meshes and simulations concurrently, enabling a substantial speed up when running multiple simulations.

In VirtualLab.Settings you will see the kwarg NbJobs which specify how many tasks VirtualLab is to run concurrently.

Note

The number you specify for NbJobs will depend on a number of factors, including the number of CPUs available and the RAM.

For example, the fineness of the mesh is an important consideration since this can require a substantial amount of RAM.

Action

In the RunFile change NbJobs to 2:

VirtualLab.Settings(
           Mode='Interactive',
           Launcher='Process',
           NbJobs=2
           )

Launch VirtualLab.

You should now see that ‘Notch2’ and ‘Notch3’ are created simultaneously, followed by one xterm window opening, with the Name of each simulation written on top left. You can switch between simulations and compare them. Additionally, it is possible to open two simulations side by side.

1.7. Task 4: Simulation Without Meshing#

After running the simulation, you realise that the wrong material was used - you wanted to run analysis on a tungsten sample. You are happy with the meshes you already have and only want to re-run the simulations.

This can be accomplished by using the RunMesh kwarg in VirtualLab.Parameters. By setting this flag to False VirtualLab will skip the meshing routine.

Action

Change the material in Parameters_Master to ‘Tungsten’:

Sim.Materials = 'Tungsten'

Change the name of the simulations in Parameters_Var also:

Sim.Name = ['ParametricSim1_Tungsten', 'ParametricSim2_Tungsten']

In the RunFile ensure that RunMesh is set to False:

VirtualLab.Parameters(
           Parameters_Master,
           Parameters_Var,
           RunMesh=False,
           RunSim=True,
           RunDA=True
           )

Launch VirtualLab.

You should notice the difference in stress and displacement for the tungsten sample compared with that of the copper sample.

Tip

If you have interest in developing your own scripts then it would be worthwhile looking at the scripts DogBone.py and Tensile.comm which have been used by SALOME and Code_Aster respectively for this analysis.