Closing PLAXIS after your calculation is finished


ApplicationPLAXIS 2D
PLAXIS 3D
VersionPLAXIS 2D CONNECT Edition V20
PLAXIS 3D CONNECT Edition V20
Date created11 November 2020
Date modified11 November 2020

After a PLAXIS calculation is finished, the PLAXIS program will stay open and active. PLAXIS will also not automatically save the calculation results: this save action is something the user must explicitly do to confirm changes in order to avoid accidental loss of work or save the file under a new name.

When running your calculation overnight, or over the weekend, it would be nice if the calculation was automatically saved and the PLAXIS program closed. This has benefits, as it can release software license usage, or you might even want to shut down the computer to save energy.

For this purpose, you can make use of the PLAXIS Calculation manager, where you can queue up PLAXIS 2D and PLAXIS 3D calculations, or use manual control to run calculations, save them and move to the next one using the command line, or Python scripting.

Calculation manager

The PLAXIS Calculation manager allows you to queue several PLAXIS 2D and PLAXIS 3D models to be calculated.

For full details and instruction video, please see the page: Calculation manager for PLAXIS 2D and PLAXIS 3D.

Manual controlling calculation and saving

Sometimes you want manual control or additional functionality. There are two commands in PLAXIS 2D and PLAXIS 3D that can help with closing PLAXIS:

* note the double underscore at the start of both commands. These are added on purpose to prevent accidental usage.

In order to make use of these commands automatically after a calculation is finished, you will need to run all the commands, including the calculate command via the Commands Runner, via a macro, or you can take advantage of the Remote Scripting facility to control PLAXIS.

Note: these options only control the PLAXIS Input application. If you have other PLAXIS programs running (e.g. PLAXIS, SoilTest, PLAXIS Output, Sensitivity Analysis & Parameter variation), these will not be closed via the __kill command, and consequently, this will keep your license in active usage.

Calculate and close PLAXIS

In order to tell PLAXIS to run the calculation, store results and shut down, we will need three commands:

calculate  # this will calculate all phases marked for calculation 
save       # explicitly save the newly calculated data 
__kill     # this will shut down PLAXIS 

We can write these commands in the Commands Runner (Expert menu) and execute them in our project:

When using this solution more often, creating a macro will make this efficient. You can create a commands macro easily via the Expert > Macro menu item. Here you can specify a name for the macro and the commands it will use:

After storing, it can be accessed easily via the Macro menu item:

Select Macro from Expert menu

This approach can also be used in combination with Batch files, see Practical use of the commands runner: Using a batch file to run commands.

Shut down the computer when PLAXIS is finished

PLAXIS offers the option to also close and shutdown windows using the __gogreen command.

With the __gogreen command, you have the options to either hibernate the computer or completely shut down your computer.

Do not forget to add the SAVE command before calling the shutdown command, otherwise, all calculation results will be lost!

For more details and options please see the Commands Reference, available via the Help menu in the PLAXIS Input program or this related wiki page: Energy saving while running multiple calculations.

Note that shutting down the computer with this command will force the computer to shut down. If you have unsaved data in other applications, this could be lost, so make sure all data is safely stored.

Remote scripting solution 1: standalone script

When using Python scripting, a possible strategy running it as a standalone script consists of starting PLAXIS as a subprocess and terminate it after having performed all intended operations.

A simple standalone Python script example illustrating the required steps for opening a file, calculating the phases, saving the file and closing PLAXIS is provided below:

# import subprocess module
import subprocess

# start PLAXIS as a subprocess
plxpath = r"C:\Program Files\Bentley\Geotechnical\PLAXIS 2D CONNECT Edition V20\Plaxis2DXInput.exe"
plx = subprocess.Popen([plxpath, "--AppServerPort=XXXXX", "--Password=yourpassword"])

# Notes:
# (1) the path locating PLAXIS executable (plxpath) may need to be modified (e.g. when using PLAXIS 3D)
# (2) XXXXX refers to the active server port and yourpassword to remote scripting server password
# (3) yourpassword should be written, in this case, without quotes

# import PLAXIS scripting module and connect to PLAXIS application
from plxscripting.easy import *
s_i, g_i = new_server('localhost', XXXXX, password='yourpassword')

# open a PLAXIS project
plaxisfile = r'C:\projectpath\projectname.p2dx'
s_i.open(plaxisfile)

# perform all intended operations
# (…)

# calculate the project
g_i.calculate()

# save the project
g_i.save(plaxisfile)

# terminate PLAXIS application
plx.terminate()

Remote scripting solution 2: script used in PLAXIS Input

Another solution is to use a Python script to run an analysis of the current open PLAXIS file while working in PLAXIS Input.

In this example, we run the file, take the same name and append the _[calculated] to the filename to make a distinction what the calculated file is. Of course, other options could be added to change the filename, like adding a timestamp or other information, or you can even change the save location to a shared location.

# get current file name if available
currentfilename = g_i.Project.Filename.value
while currentfilename == '':
    # empty filename
    response = input("\nYou did not save the PLAXIS file yet.\nPlease manually save it in PLAXIS and hit [Enter] to continue.")
    currentfilename = g_i.Project.Filename.value

# make sure we only calculate when we have a filename
if currentfilename != '':
    # get the current name and determine new save name
    # here we add _calculated if it is not added yet
    postfix = "_[calculated]"
    folder, filename = os.path.split(currentfilename)
    savename, ext = os.path.splitext(filename)
    if postfix not in savename:
        savename = savename + postfix
    newfilename = os.path.join(folder, savename + ext)

    # ensure we are in staged construction / calculation mode
    g_i.gotostages()

    # running the calculation
    print("Starting calculation")
    print("When finished, it will be saved as:")
    print(newfilename)
    force_all_phases  = True # Boolean to force all phases to be calculated
    g_i.calculate(force_all_phases)
    print("\nCalculation done")

    # optional: run post-processing
    # ...

    # save the file
    g_i.save(newfilename)
    print("Saved as: {}".format(newfilename))

    # optional: close PLAXIS
    g_i.kill()

In order to use this script from within PLAXIS Input:

When you do not have access rights to add the script in the mentioned folder, alternatively, you can choose to use Expert menu > Python > Run script > Open... to manually open and run the file.

Tips

The calculate command

The calculate command can take additional parameters to control what you want to calculate.

Saving under a different name

When running automated commands, using macros or Python scripts that will just save the current PLAXIS model (so only the save command without a location), it will use the current file name to save it. And if you did not save the file under a specific name after starting a new PLAXIS project, the save command will not work and responds with First save command must specify a location.
For those cases, make sure to manually save the file using the desired name and location.

Note: in order to release all PLAXIS software usage for the CONNECTION Client, all PLAXIS instances should be closed. This includes PLAXIS Input, PLAXIS Output and PLAXIS SoilTest. The above-mentioned examples only close PLAXIS Input via the Commands runner or Python scripting. In order to free your PLAXIS software usage, make sure to close all other PLAXIS applications.

See also