Tutorial 1#

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:

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

VirtualLab=VLSetup(
               Simulation,
               Project)

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

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

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

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

VirtualLab.DA()

VirtualLab.Cleanup()

The setup above means that the path to the Parameters_Master file used is Inputs/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.

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/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.

https://gitlab.com/ibsim/media/-/raw/master/images/VirtualLab/DogBone.png?inline=false

Fig. 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.

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 acse is Scripts/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 a force controlled and displacement controlled simulation are run. If, for example, only a constant force simulation you wish to run, 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.

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 mangitude 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.

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

Running this simulation will create the following outputs:

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

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

  • 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

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 hot it was alunched. 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.

As 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:

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.

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 Inputs/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.

Action

Change Parameters_Var in the RunFile:

Parameters_Var='Parametric_1'

Launch VirtualLab:

VirtualLab -f RunFiles/RunTutorials.py

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.

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 two xterm windows opening, with the Name of each simulation written on top.

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.