PLAXIS 2D + Python Scripting Tutorial 2

Embankment stability (drained vs undrained), mesh, phases, safety analysis, and result extraction via Remote Scripting.

⬇️ PDF

1️⃣ Introduction

This tutorial continues the same Remote Scripting workflow as Tutorial 1, but for an embankment stability example. You’ll build the model, define materials, mesh it, create phases for drained/undrained cases, then run a Phi–c reduction safety analysis.

Key scripting objects:

  • s_i – Input server object (commands sent to PLAXIS Input).
  • g_i – Global Input object (project data: geometry, materials, mesh, stages).
  • s_o, g_o – Output equivalents for post-processing and extraction.

Treat each section like a Jupyter cell: run top-to-bottom and save often.

2️⃣ Connect to PLAXIS Remote Scripting Servers

Make sure PLAXIS Input and Output are running with Remote Scripting enabled on ports 10000 and 10001.

from plxscripting.easy import *

# Replace with your own password
user_password = "your-password-here"

# Connect to PLAXIS Input (10000) and Output (10001)
s_i, g_i = new_server('localhost', 10000, password=user_password)
s_o, g_o = new_server('localhost', 10001, password=user_password)

If connection fails, verify: Remote Scripting is enabled, ports are correct, and password matches.

3️⃣ Start a New Project & Save

Reset the model and save a new project path (save early, save often).

# Choose a project path (folder or base path depending on your PLAXIS version)
filepath = r"C:\Users\<you>\Plaxis_playground\tutorial_2"

# Start new project and save
s_i.new()
g_i.save(filepath)

4️⃣ Project Properties & Computational Domain

Configure project metadata, model type, and define the soil contour (domain extents).

# Project info
g_i.Project.Title.set("Lesson 2")
g_i.Project.Comments.set("Drained and undrained stability of an embankment")
g_i.Project.ModelType.set("plane strain")

# Element type (if supported in your PLAXIS build)
g_i.Project.ElementType = "15-Noded"

# Soil contour rectangle: (x_min, y_min, x_max, y_max)
g_i.SoilContour.initializerectangular(0, -6, 50, 4)

Choose a domain large enough so boundaries don’t influence the failure mechanism.

5️⃣ Boreholes & Soil Layers

Create a borehole, define a layer boundary, and set groundwater head.

# Borehole at x = 0
borehole_g = g_i.borehole(0)

# Define a soil layer boundary (example)
boreholepolygon_g = g_i.soillayer(6)
print(boreholepolygon_g.y.echo())

# Groundwater head
borehole_g.Head = 0
print(borehole_g.Head.echo())

Boreholes control the soil profile and groundwater distribution across the soil contour.

6️⃣ Define Soil Materials (Hardening Soil)

Create embankment and subgrade materials, then set properties using setproperties().

# Create materials
embankment_sand = g_i.soilmat("Identification","embankment sand", "SoilModel","hardening soil")
subgrade_clay = g_i.soilmat("Identification","subgrade clay", "SoilModel","hardening soil")
subgrade_clay_undrained = g_i.soilmat("Identification","subgrade clay undrained", "SoilModel","hardening soil")

# Property sets
sand_properties = [
    ("DrainageType","drained"), ("gammaUnsat",16), ("gammaSat",16),
    ("E50Ref",15000), ("EOedRef",15000), ("EURRef",45000),
    ("PowerM",0.5), ("cRef",3), ("phi",30), ("K0Determination","automatic"), ("OCR",1),
]
clay_properties = [
    ("DrainageType","drained"), ("gammaUnsat",13), ("gammaSat",13),
    ("E50Ref",5600), ("EOedRef",5000), ("EURRef",20000),
    ("PowerM",1), ("cRef",10), ("phi",25), ("K0Determination","automatic"), ("OCR",1.2),
]

# Apply properties
embankment_sand.setproperties(*sand_properties)
subgrade_clay.setproperties(*clay_properties)
subgrade_clay_undrained.setproperties(*clay_properties)

# Make the undrained version undrained (example)
subgrade_clay_undrained.DrainageType = "undrained a"

# Assign to the soil domain represented by the borehole polygon
boreholepolygon_g.Soil.Material = subgrade_clay

Using a drained and an undrained material lets you create two scenarios without duplicating geometry.

7️⃣ Create Embankment Geometry

Switch to Structures, define the embankment polygon, and assign embankment sand.

# Go to Structures mode
g_i.gotostructures()

# Embankment polygon and material assignment
embankment_polygon = g_i.polygon((14,0), (22,4), (24,4), (36,0))[0]
embankment_polygon.Soil.setproperties("Material", embankment_sand)

8️⃣ Generate Mesh & Add Monitoring Point

Mesh the model, then add a curve point in Output for tracking displacement (e.g., near the toe).

# Mesh
g_i.gotomesh()
g_i.mesh(0.04)  # target element size

# Monitoring point in Output
g_i.selectmeshpoints()
g_o.addcurvepoint('node', g_o.Soil_1_1, (18, 0))
g_o.update()

Pick monitoring points that make engineering sense (toe, crest, potential slip surface region).

9️⃣ Create Phases & Run Calculation

Create staged construction phases for drained and undrained cases, then calculate.

# Staged Construction
g_i.gotostages()
phase0_s = g_i.InitialPhase

# Create two phases based on initial (drained and undrained)
phase1_s = g_i.phase(phase0_s)
phase2_s = g_i.phase(phase0_s)

# Re-acquire the polygon handle in Stages (example: first polygon)
embankment_g = g_i.Polygons[0]
embankment_g.activate(phase1_s, phase2_s)

# Switch subgrade to undrained for phase 2 (example approach)
g_i.Soils[1].Material.set(phase2_s, subgrade_clay_undrained)

# Run calculation and save
g_i.calculate()
g_i.save(filepath)

If your project indexing differs (e.g., which soil cluster is Soils[1]), inspect g_i.Soils and confirm material assignment before calculating.

🔟 Factor of Safety (Phi–c Reduction)

Clone the drained/undrained phases and set DeformCalcType to safety.

# Create FoS phases
phase3_s = g_i.phase(phase1_s)  # drained base
phase4_s = g_i.phase(phase2_s)  # undrained base

# Identify and set to Safety
phase3_s.Identification = "FoS of drained case"
phase3_s.DeformCalcType = "safety"

phase4_s.Identification = "FoS of undrained case"
phase4_s.DeformCalcType = "safety"

# Calculate safety phases
g_i.calculate()

Safety calculation performs strength reduction until failure; check Output for the computed FoS and mechanism.

1️⃣1️⃣ Extract Results in Output

Map an Input phase to Output and extract results at the curve point.

# Link a Stages phase to Output
g_i.view(phase2_s)
phase2_o = get_equivalent(phase2_s, g_o)

# Last curve point (added earlier)
curvepoint_o = g_o.CurvePoints.Nodes[-1]

# Vertical displacement at the point
uy_o = g_o.getcurveresults(curvepoint_o, phase2_o, g_o.ResultTypes.Soil.Uy)
print(uy_o)

# Explore other result types
# dir(g_o.ResultTypes.Soil)

For plotting, use Output GUI; for automation/reporting, extract arrays via the API and export CSV.

1️⃣2️⃣ Summary

This tutorial demonstrated how to:

  • Connect to PLAXIS Input/Output via Remote Scripting.
  • Set up project domain, borehole/layers, and groundwater head.
  • Define Hardening Soil materials for drained and undrained cases.
  • Create an embankment polygon and assign materials.
  • Generate mesh and add a curve point for monitoring.
  • Create phases and run calculations.
  • Run safety analysis (Phi–c reduction) and extract Output results.
Next-step idea
# Example: list curve points in Output
for cp in g_o.CurvePoints:
    print(cp.Name)