Automatic line cross-section chart generation using Python


ApplicationPLAXIS 2D
PLAXIS 3D
VersionPLAXIS 2D 2017
PLAXIS 3D 2016
Date created05 December 2017
Date modified05 December 2017

Versions: 3D 2016 and later, 2D 2017 and later

Description

In this article, a simple example is provided on how to create a line cross-section by using the Remote Scripting feature in the Plaxis Output program. In addition, the matplotlib module is used to create a chart from the results of the line cross-section. This Python script retrieves the results for total displacements of soil elements.

Python solution

By using the Remote Scripting Server in the Plaxis Output program, we can create a Python script to automatically retrieve the results for a specified line cross-section. The attached script requires the user to define the following variables:

The Python script will then:

Boilerplate code

In order to use the Python script, you must make sure that your Python script can communicate with the PLAXIS application. For more information on the boilerplate code please check the following article on Using PLAXIS Remote scripting with the Python wrapper.

Note that the Python script uses the g_o variable. This variable is bound to the global object of the current open Plaxis model in Output.

Modules used

The Python script requires the following modules:

All modules are part of the standard PLAXIS 3D 2016 (and later) installation that includes a full Python 3.4.x distribution.

Python code

from matplotlib import pyplot

sample_count = 16
start = (2.0, 4.0, 0.0)
end = (2.0, 0.0, 0.0)
# assumes that start and end contain floats


def gather_results():
    step = [(e - s) / (sample_count - 1) for e, s in zip(end, start)]
    results = []
    for i in range(sample_count):
        position = (start[0] + i * step[0],
                    start[1] + i * step[1],
                    start[2] + i * step[2])
        result_string = g_o.getsingleresult(g_o.Phases[-1],
                                            g_o.ResultTypes.Soil.Utot,
                                            position)
        # check if position lies outside the mesh
        if result_string == "not found":
            raise Exception("Used getsingleresult for point outside mesh.")

        results.append(float(result_string))
    return results

results = gather_results()


def output_results():
    pyplot.plot(range(len(results)), results, 'r')
    pyplot.grid(True)
    pyplot.show()

output_results()

Version

This script has been made for PLAXIS 3D 2016.02 using Python 3.4.x

Notes

The current Python script can be also used for making a 2D line cross-section. The 2D version of the Python script requires the following changes:

Disclaimer

This Python script is made available as a service to PLAXIS users and can only be used in combination with a Bentley Geotechnical SELECT Entitlement [GSE] (former PLAXIS-VIP) license.
You use this Python script at your own responsibility and you are solely responsible for its results and the use thereof. Plaxis does not accept any responsibility nor liability for the use of this Python script nor do we provide support on its use.

 

See also