Application | PLAXIS 2D PLAXIS 3D |
Version | PLAXIS 2D 2024.1 and later PLAXIS 3D 2024.1 and later |
Date created | 09 September 2024 |
Date modified | 09 September 2024 |
Original author | Stefanos Papavasileiou - Technical Support Group |
Keywords | PLAXIS, SoilTest, soil, test, lab test, virtual lab, Python, API, py, cookbook |
The SoilTest option is a quick and convenient procedure to simulate basic soil lab tests on the basis of a single-point algorithm, i.e., without the need to create a complete finite element model.
Using Python, the SoilTest facility can be utilized to run most of the types of laboratory tests and allow the retrieval of results, which can be post-processed by any script used for automation.
In this article you will learn:
For SoilTest to run a virtual laboratory test, a material needs to be provided. In this case, PLAXIS Input should provide the material.
To create a material in PLAXIS via Python scripting, the Remote Scripting Server needs to be initialised for the PLAXIS Input program.
See also: Using PLAXIS Remote scripting with the Python wrapper in order to correctly set up the reference to Plaxis Input (s_i, g_i) using the boilerplate code.
In the code below, the following happens:
# 1. PLAXIS boilerplate from plxscripting.easy import * s_i, g_i = new_server('localhost', 10000, password="your_password") # 2. Start a new PLAXIS project s_i.new() # 3. Define Sand material as Hardening Soil sand_properties = ["Identification", "Sand", "SoilModel", "Hardening Soil", "gammaUnsat", 17, "gammaSat", 20, "E50Ref", 40000, "EOedRef", 40000, "cRef", 5, "phi", 32, "PermHorizontalPrimary", 1, "PermVertical", 1, "InterfaceStrengthDetermination", "Manual", "Rinter", 0.67] # 4. Create the material object g_i.soilmat(*sand_properties) # 5. Start SoilTest from Input localhostport_t = g_i.soiltest(g_i.Sand) s_t, g_t = new_server('localhost', localhostport_t, password=s_i.connection._password)
In the code below, the configuration of a triaxial test is set:
# 1. Define the laboratory test lab_test = g_t.Triaxial # 2. Configure the Triaxial test lab_test.CellPressure = 100 lab_test.MaximumStrain = 10 lab_test.Steps = 500 # 3. Calculate the test g_t.calculate(lab_test)
In the code provided, various calculation results are retrieved and printed to the Python console:
# Various results from Triaxial test # 1a. Retrieve the Deviatoric Stresses deviatoric_stresses = lab_test.Results.DeviatoricStressT.value # 1b. Retrieve the Cartesian Y-direction Strains epsyys = lab_test.Results.Epsyy.value # 1c. Retrieve the Total Volumetric Strains vol_strains = lab_test.Results.TotalVolumetricStrain.value # 2. Print maximum and minimum values for some results print(f"Maximum value for {deviatoric_stresses.Name} is: {max(deviatoric_stresses)}") print(f"Minimum value for {vol_strains.Name} is: {(min(vol_strains)):.2%}") # 3. Print some results in console for dev_stress in deviatoric_stresses: print(dev_stress)
In the last part of the code, the matplotlib module is used to create a plot:
# 1. Import a Python module for the script import matplotlib.pyplot as plt # 2. Create a plot with Deviatoric Stresses and Cartesian Y-direction Strains results print("Plot created. Click the X on Figure 1 to close it.") plt.plot(epsyys, deviatoric_stresses) plt.xlabel(r'$\varepsilon_{yy}$') plt.ylabel(r'$|\sigma_1 - \sigma_2|$ [kN/m$^2$]') plt.gca().invert_xaxis() # Invert the x-axis plt.show()
For further information on commands and objects in SoilTest, go to Help > Command reference menu option.
This script has been tested with PLAXIS 2024.1 and Python 3.8.18, and with PLAXIS 2024.2 and Python 3.12.3.