Skip to content

Commit

Permalink
feat(#22): add method to get nodes per cut volume in Plaxis3DOutputCo…
Browse files Browse the repository at this point in the history
…ntroller.
  • Loading branch information
Pablo Vasconez committed Nov 14, 2023
1 parent aee0588 commit 931305a
Show file tree
Hide file tree
Showing 2 changed files with 171 additions and 0 deletions.
125 changes: 125 additions & 0 deletions notebooks/Plaxis3D_output_controller.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,125 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Plaxis 3D Output Controller\n",
"\n",
"______________________________________________________________________\n",
"\n",
"**Authors: Pablo Vasconez & Daan Vink**"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 1. Install additional requirements and import required modules"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"!pip install -r requirements.txt"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"from plxscripting.easy import new_server\n",
"from plxcontroller.plaxis_3d_output_controller import Plaxis3DOutputController"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 2. Activate scripting server in the PLAXIS 3D program (manually)\n",
"![image](image.png)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 3. Connect to the remote scripting server and create new Plaxis3DInputController instance"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Enter IP address of machine and port (integer) and password of the PLAXIS remote server\n",
"ip_address = \"localhost\" # can also be an IP address with format \"XXX.XXX.X.XX\"\n",
"port = 10000\n",
"password = \"<password in plaxis program>\""
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Connect to PLAXIS remote server\n",
"server, _ = new_server(ip_address, port, password=password)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"# Create a new Plaxis controller instance\n",
"co = Plaxis3DOutputController(server)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### 4. Start scripting"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"a = co.get_nodes_per_cut_volume()"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "env-notebook-local",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.16"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
46 changes: 46 additions & 0 deletions src/plxcontroller/plaxis_3d_output_controller.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
from __future__ import annotations

from typing import Dict, List

from plxscripting.plxproxy import PlxProxyGlobalObject
from plxscripting.server import Server

from plxcontroller.geometry_3d.point_3d import Point3D


class Plaxis3DOutputController:
def __init__(self, server: Server):
Expand All @@ -22,3 +26,45 @@ def s_o(self) -> Server:
def g_o(self) -> PlxProxyGlobalObject:
"""Returns the global project object. This is a typical alias for the global project object."""
return self.server.plx_global

def get_nodes_per_cut_volume(self) -> Dict[str, List[Point3D]]:
"""Get all the nodes per cut volume as points.
Note that cut volumes are the volumes produced by the intersection
of geometry in Plaxis (this takes place when the tab Mesh is clicked).
Returns
-------
Dict[str, List[Point3D]]
the dictionary with all the nodes per cut volume in the following
format {cut_volume_name: points}
"""
# Map all nodes per soil volume
nodes_per_cut_volume = {}
for volume in self.g_o.Volumes:
# Volumes deepest level (cutted in Mesh, present also in Stages)
for cut_volume in volume:
# Request x, y and z values
plaxis_xs = self.g_o.getresults(
cut_volume, self.g_o.ResultTypes.Soil.X, "node", False
)
plaxis_ys = self.g_o.getresults(
cut_volume, self.g_o.ResultTypes.Soil.Y, "node", False
)
plaxis_zs = self.g_o.getresults(
cut_volume, self.g_o.ResultTypes.Soil.Z, "node", False
)
# Map PlxValues to List[float] (this is time consuming)
xs = list(map(float, plaxis_xs))
ys = list(map(float, plaxis_ys))
zs = list(map(float, plaxis_zs))
# Make a set of the coordinates
coordinates_set = set()
for x, y, z in zip(xs, ys, zs):
coordinates_set.add((x, y, z))
# Store the coordinates as points
nodes_per_cut_volume[cut_volume.Name.value] = [
Point3D(x=c[0], y=c[1], z=c[2]) for c in list(coordinates_set)
]

return nodes_per_cut_volume

0 comments on commit 931305a

Please sign in to comment.