Python and lambda property of Modified Cam-Clay model


ApplicationPLAXIS 2D
PLAXIS 3D
VersionPLAXIS 2D 2016 and later
PLAXIS 3D 2016 and later
Date created12 April 2024
Date modified12 April 2024
Original authorStefanos Papavasileiou - Bentley Technical Support Group

Description

PLAXIS automations with Python very frequently consider defining and/or editing the available material models and other parameters, which will be used in the Finite Element calculations.

In the specific case of the Modified Cam-Clay model, one of the material parameters is "λ", which is the Cam-Clay compression index. In the command line and the object structure of SoilMat, this material parameter is named: lambda

In Python programming, you may already know that the same name is already used for the Lambda Functions, which are also known as anonymous functions that are used for simple operations and are subject to a more restrictive syntax. Due to that, lambda is a Python-reserved keyword.

For example, the basic syntax of a lambda function to produce the double of "x" (e.g., integer) in this case is:

double_lambda = lambda x: x * 2
result_value = double_lambda(3)  # Output: 6

In the Modified Cam Clay model in PLAXIS, the compression index parameter is called "lambda" and as such it will conflict with the reserved keyword when using the PLAXIS Python wrapper. This implies that we cannot use the term .lambda in the Python environment to define the Modified Cam Clay parameter “λ” inside PLAXIS.

This means that accessing the .lambda property will either result in an error in Python as shown below or the value of the material will not be updated (skipped):

Workaround

Provided the reserved state of the "lambda" term, the following options can help to overcome the issue when defining/editing a Modified Cam-Clay material dataset. Assuming a material dataset defined with the name MCC, these are:

Setting the value

A. PLAXIS command

g_i.MCC.setproperties('lambda', 0.35)

This command, setproperties, is offered by the PLAXIS native command line. For more information, you can check our Command reference under the Help menu.

B. PLAXIS Python function

s_i.call_and_handle_command("set MCC. lambda 0.3")   

 This uses the plxscripting function s_i.call_and_handle_command which can have any string as a parameter. In this case, it takes the exact native PLAXIS command and passes it via the API.

C. Python function

setattr(g_i. ModifiedCamClay_mat, "lambda", 0.3)   

 This is the Python setattr function, which requires the parameters to be the material object, the property name as a string (no spaces allowed) and the value of the property.

 

 Note that for versions prior to PLAXIS CONNECT Edition V22, the required definition of "lambda" was only using the "lambda modified" property. In such cases, you can define a local variable to assist in computing the "lambda modified" property, and use it in the definition of the new material as such:

lambda_ = 0.3
e0 = 0.75
lambda_mod = lambda_ / (1 + e0)
soil_material = g_i.soilmat()
g_i.setproperties(soil_material, "MaterialName", " ModifiedCamClay_mat_V21", "SoilModel", 8, "DrainageType", 1, "gammaUnsat", 18, "gammaSat", 18, "ninit", e0/(1+e0), "kappamodified", 0.05, "lambdaModified", lambda_mod, "cref", 0.001, "M", 1.11, "POP", 200)  

 

Retrieving the value

To retrieve the value, you can use the following options:

A. PLAXIS Python function

echo = s_i.call_and_handle_command("echo MCC.lambda")
value = float(echo.split(':')[-1].strip())

Here you can use the s_i.call_and_handle_command as explained before and via string-processing convert it to a float (number) to use it directly.

B. Python function

value = getattr(g_i.MCC, 'lambda')

This is the Python getattr function, which requires the parameters to be the material object and the property name as a string (no spaces allowed).

See also