{ "cells": [ { "cell_type": "markdown", "id": "3953d19e", "metadata": { "papermill": { "duration": 0.010875, "end_time": "2026-03-13T21:08:03.366119", "exception": false, "start_time": "2026-03-13T21:08:03.355244", "status": "completed" }, "tags": [] }, "source": [ "(composite_liner_result_example)=\n", "# Composite Liner Result Script Example" ] }, { "cell_type": "markdown", "id": "8e19a99c", "metadata": { "papermill": { "duration": 0.004483, "end_time": "2026-03-13T21:08:03.380809", "exception": false, "start_time": "2026-03-13T21:08:03.376326", "status": "completed" }, "tags": [] }, "source": [ "Download the [RS3_Result_Scripting_Example folder](https://github.com/Rocscience/rs3-scripting/tree/main/docs/example_code/example_models/RS3_Result_Scripting_Example) for this example." ] }, { "cell_type": "code", "execution_count": 1, "id": "0d48abd5", "metadata": { "execution": { "iopub.execute_input": "2026-03-13T21:08:03.400304Z", "iopub.status.busy": "2026-03-13T21:08:03.399416Z", "iopub.status.idle": "2026-03-13T21:08:03.819913Z", "shell.execute_reply": "2026-03-13T21:08:03.818313Z" }, "papermill": { "duration": 0.433508, "end_time": "2026-03-13T21:08:03.821658", "exception": false, "start_time": "2026-03-13T21:08:03.388150", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "from rs3.RS3Modeler import RS3Modeler\n", "from rs3.results.ResultEnums import LinerResultTypes\n", "from rs3.Geometry import Point, Cube\n", "import os" ] }, { "cell_type": "markdown", "id": "6375a745", "metadata": { "papermill": { "duration": 0.006076, "end_time": "2026-03-13T21:08:03.835058", "exception": false, "start_time": "2026-03-13T21:08:03.828982", "status": "completed" }, "tags": [] }, "source": [ "Get the current folder directory." ] }, { "cell_type": "code", "execution_count": 2, "id": "01397a19", "metadata": { "execution": { "iopub.execute_input": "2026-03-13T21:08:03.855331Z", "iopub.status.busy": "2026-03-13T21:08:03.854747Z", "iopub.status.idle": "2026-03-13T21:08:03.862906Z", "shell.execute_reply": "2026-03-13T21:08:03.859631Z" }, "papermill": { "duration": 0.02169, "end_time": "2026-03-13T21:08:03.865040", "exception": false, "start_time": "2026-03-13T21:08:03.843350", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "current_dir = os.path.dirname(os.path.abspath(\"\"))" ] }, { "cell_type": "markdown", "id": "2810d692", "metadata": { "papermill": { "duration": 0.006714, "end_time": "2026-03-13T21:08:03.878350", "exception": false, "start_time": "2026-03-13T21:08:03.871636", "status": "completed" }, "tags": [] }, "source": [ "Specify a port number that is not in use and start the RS3 program." ] }, { "cell_type": "code", "execution_count": 3, "id": "e5faed9b", "metadata": { "execution": { "iopub.execute_input": "2026-03-13T21:08:03.894432Z", "iopub.status.busy": "2026-03-13T21:08:03.893704Z", "iopub.status.idle": "2026-03-13T21:08:33.534887Z", "shell.execute_reply": "2026-03-13T21:08:33.533032Z" }, "papermill": { "duration": 29.65175, "end_time": "2026-03-13T21:08:33.536461", "exception": false, "start_time": "2026-03-13T21:08:03.884711", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2026-03-13 17:08:03,903 - Rocscience.RS3 - INFO - Attempting to start the application at C:\\Program Files\\Rocscience\\RS3\\RS3 and binding server to port 60506...\n" ] } ], "source": [ "port = 60506\n", "RS3Modeler.startApplication(port)" ] }, { "cell_type": "markdown", "id": "378160b4", "metadata": { "papermill": { "duration": 0.006101, "end_time": "2026-03-13T21:08:33.548956", "exception": false, "start_time": "2026-03-13T21:08:33.542855", "status": "completed" }, "tags": [] }, "source": [ "Connect with the RS3 Modeler." ] }, { "cell_type": "code", "execution_count": 4, "id": "5ee8eb3b", "metadata": { "execution": { "iopub.execute_input": "2026-03-13T21:08:33.567016Z", "iopub.status.busy": "2026-03-13T21:08:33.566251Z", "iopub.status.idle": "2026-03-13T21:08:33.575874Z", "shell.execute_reply": "2026-03-13T21:08:33.574100Z" }, "papermill": { "duration": 0.021458, "end_time": "2026-03-13T21:08:33.577342", "exception": false, "start_time": "2026-03-13T21:08:33.555884", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "modeler = RS3Modeler(port)" ] }, { "cell_type": "markdown", "id": "fa1ba63d", "metadata": { "papermill": { "duration": 0.004986, "end_time": "2026-03-13T21:08:33.587474", "exception": false, "start_time": "2026-03-13T21:08:33.582488", "status": "completed" }, "tags": [] }, "source": [ "For the demonstration purposes only, the model is copied for reuse. You may change the model path to your own model path." ] }, { "cell_type": "code", "execution_count": 5, "id": "68a779ea", "metadata": { "execution": { "iopub.execute_input": "2026-03-13T21:08:33.598187Z", "iopub.status.busy": "2026-03-13T21:08:33.597822Z", "iopub.status.idle": "2026-03-13T21:08:44.926528Z", "shell.execute_reply": "2026-03-13T21:08:44.925075Z" }, "papermill": { "duration": 11.336325, "end_time": "2026-03-13T21:08:44.927838", "exception": false, "start_time": "2026-03-13T21:08:33.591513", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "model = modeler.openFile(rf\"{current_dir}\\example_models\\RS3_Result_Scripting_Example\\RS3_Result_Scripting_Example.rs3v3\")" ] }, { "cell_type": "markdown", "id": "77e01601", "metadata": { "papermill": { "duration": 0.004817, "end_time": "2026-03-13T21:08:44.937309", "exception": false, "start_time": "2026-03-13T21:08:44.932492", "status": "completed" }, "tags": [] }, "source": [ "## 1. Get Node Results" ] }, { "cell_type": "markdown", "id": "3dfa67c3", "metadata": { "papermill": { "duration": 0.00468, "end_time": "2026-03-13T21:08:44.946877", "exception": false, "start_time": "2026-03-13T21:08:44.942197", "status": "completed" }, "tags": [] }, "source": [ "### 1.1 Define a box region to filter liner elements (optional)\n", "\n", "A cube region is defined by two corners. Only mesh nodes inside or intersecting the box will be returned. If you omit the region in the next step, all nodes in the model would be returned.\n", "\n", "In this example, the middle part of the tunnel will be queried." ] }, { "cell_type": "code", "execution_count": 6, "id": "c3a02dcd", "metadata": { "execution": { "iopub.execute_input": "2026-03-13T21:08:44.958396Z", "iopub.status.busy": "2026-03-13T21:08:44.957975Z", "iopub.status.idle": "2026-03-13T21:08:44.964034Z", "shell.execute_reply": "2026-03-13T21:08:44.962232Z" }, "papermill": { "duration": 0.014534, "end_time": "2026-03-13T21:08:44.965623", "exception": false, "start_time": "2026-03-13T21:08:44.951089", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "liner_query_region = Cube(\n", " corner1=Point(x=8.5, y=14.5, z=-8.5),\n", " corner2=Point(x=11.5, y=15.5, z=-11.5),\n", ")" ] }, { "cell_type": "markdown", "id": "0c52ef31", "metadata": { "papermill": { "duration": 0.004586, "end_time": "2026-03-13T21:08:44.976349", "exception": false, "start_time": "2026-03-13T21:08:44.971763", "status": "completed" }, "tags": [] }, "source": [ "### 1.2 Get the liner results object for the desired stage(s)\n", "\n", "getCompositeLinerResults returns a list: one entry per stage requested. Here we request only stage 3, so the list has one element at index 0." ] }, { "cell_type": "code", "execution_count": 7, "id": "e1bf1c47", "metadata": { "execution": { "iopub.execute_input": "2026-03-13T21:08:44.988919Z", "iopub.status.busy": "2026-03-13T21:08:44.988540Z", "iopub.status.idle": "2026-03-13T21:08:45.865940Z", "shell.execute_reply": "2026-03-13T21:08:45.863393Z" }, "papermill": { "duration": 0.886149, "end_time": "2026-03-13T21:08:45.867722", "exception": false, "start_time": "2026-03-13T21:08:44.981573", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "liner_results_list = model.Results.getCompositeLinerResults(stageNumber=[3])\n", "liner_results_stage_3 = liner_results_list[0]" ] }, { "cell_type": "markdown", "id": "90d686fd", "metadata": { "papermill": { "duration": 0.007619, "end_time": "2026-03-13T21:08:45.881248", "exception": false, "start_time": "2026-03-13T21:08:45.873629", "status": "completed" }, "tags": [] }, "source": [ "### 1.3 Get all liner node results for this stage\n", "\n", "No region is passed, so we get nodes for the all liner in this stage." ] }, { "cell_type": "code", "execution_count": 8, "id": "992d3346", "metadata": { "execution": { "iopub.execute_input": "2026-03-13T21:08:45.900349Z", "iopub.status.busy": "2026-03-13T21:08:45.899721Z", "iopub.status.idle": "2026-03-13T21:08:46.026944Z", "shell.execute_reply": "2026-03-13T21:08:46.025225Z" }, "papermill": { "duration": 0.138909, "end_time": "2026-03-13T21:08:46.028439", "exception": false, "start_time": "2026-03-13T21:08:45.889530", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "liner_node_results_list = liner_results_stage_3.getLinerNodeResults()" ] }, { "cell_type": "markdown", "id": "f1385d63", "metadata": { "papermill": { "duration": 0.004986, "end_time": "2026-03-13T21:08:46.039161", "exception": false, "start_time": "2026-03-13T21:08:46.034175", "status": "completed" }, "tags": [] }, "source": [ "Build a lookup: NodeID -> nodal result object. This is used later to get coordinates for each node attached to an element." ] }, { "cell_type": "code", "execution_count": 9, "id": "68a91513", "metadata": { "execution": { "iopub.execute_input": "2026-03-13T21:08:46.053390Z", "iopub.status.busy": "2026-03-13T21:08:46.052952Z", "iopub.status.idle": "2026-03-13T21:08:46.059700Z", "shell.execute_reply": "2026-03-13T21:08:46.058182Z" }, "papermill": { "duration": 0.016904, "end_time": "2026-03-13T21:08:46.060888", "exception": false, "start_time": "2026-03-13T21:08:46.043984", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "liner_node_by_id = {nr.NodeID: nr for nr in liner_node_results_list}" ] }, { "cell_type": "markdown", "id": "2ada3fc8", "metadata": { "papermill": { "duration": 0.00543, "end_time": "2026-03-13T21:08:46.072707", "exception": false, "start_time": "2026-03-13T21:08:46.067277", "status": "completed" }, "tags": [] }, "source": [ "### 1.4 Get liner element results within the region" ] }, { "cell_type": "code", "execution_count": 10, "id": "3e5170a9", "metadata": { "execution": { "iopub.execute_input": "2026-03-13T21:08:46.084983Z", "iopub.status.busy": "2026-03-13T21:08:46.084602Z", "iopub.status.idle": "2026-03-13T21:08:46.172884Z", "shell.execute_reply": "2026-03-13T21:08:46.171154Z" }, "papermill": { "duration": 0.096675, "end_time": "2026-03-13T21:08:46.174171", "exception": false, "start_time": "2026-03-13T21:08:46.077496", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "liner_element_results_list = liner_results_stage_3.getLinerElementResults(region=liner_query_region)" ] }, { "cell_type": "markdown", "id": "e8f00176", "metadata": { "papermill": { "duration": 0.005284, "end_time": "2026-03-13T21:08:46.185801", "exception": false, "start_time": "2026-03-13T21:08:46.180517", "status": "completed" }, "tags": [] }, "source": [ "### 1.5 Take one element and read its per-node result values\n", "\n", "Each element has attached nodes. getResults(...) returns a list of values, one per node of the element (in the same order as AttachedNodeIDs)." ] }, { "cell_type": "code", "execution_count": 11, "id": "1aac0004", "metadata": { "execution": { "iopub.execute_input": "2026-03-13T21:08:46.199559Z", "iopub.status.busy": "2026-03-13T21:08:46.198952Z", "iopub.status.idle": "2026-03-13T21:08:46.207441Z", "shell.execute_reply": "2026-03-13T21:08:46.205755Z" }, "papermill": { "duration": 0.017902, "end_time": "2026-03-13T21:08:46.208790", "exception": false, "start_time": "2026-03-13T21:08:46.190888", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Liner element ID 81643, nodal results:\n", " Node 2375: (x, y, z, Total Displacement, Moment YY) = (10.368124552684677, 15.559329226663175, -9.070223514111749, 0.017510250963789133, 0.3562554391291303)\n", " Node 2622: (x, y, z, Total Displacement, Moment YY) = (10.587785252292472, 15.559329226663177, -9.190983005625052, 0.01659801477075613, 0.3562554391291307)\n", " Node 2621: (x, y, z, Total Displacement, Moment YY) = (10.587785252292472, 15.27928756138166, -9.190983005625052, 0.016808917305162055, 0.3562554391291303)\n" ] } ], "source": [ "element_index = 0\n", "selected_liner_element = liner_element_results_list[element_index]\n", "attached_node_ids = selected_liner_element.AttachedNodeIDs\n", "total_disp_per_node = selected_liner_element.getResults(LinerResultTypes.TOTAL_DISPLACEMENT)\n", "moment_y_per_node = selected_liner_element.getResults(LinerResultTypes.MOMENT_YY)\n", "\n", "print(f\"Liner element ID {selected_liner_element.ElementID}, nodal results:\")\n", "for i in range(len(attached_node_ids)):\n", " node_id = attached_node_ids[i]\n", " nodal_result = liner_node_by_id[node_id]\n", " print(\n", " f\" Node {node_id}: (x, y, z, Total Displacement, Moment YY) = \"\n", " f\"({nodal_result.XCoordinate}, {nodal_result.YCoordinate}, {nodal_result.ZCoordinate}, \"\n", " f\"{total_disp_per_node[i]}, {moment_y_per_node[i]})\"\n", " )" ] }, { "cell_type": "markdown", "id": "649242e3", "metadata": { "papermill": { "duration": 0.006753, "end_time": "2026-03-13T21:08:46.221586", "exception": false, "start_time": "2026-03-13T21:08:46.214833", "status": "completed" }, "tags": [] }, "source": [ "Since accessing results doesn't change the model, close the model without saving." ] }, { "cell_type": "code", "execution_count": 12, "id": "358e8f69", "metadata": { "execution": { "iopub.execute_input": "2026-03-13T21:08:46.236003Z", "iopub.status.busy": "2026-03-13T21:08:46.235605Z", "iopub.status.idle": "2026-03-13T21:08:48.386637Z", "shell.execute_reply": "2026-03-13T21:08:48.384192Z" }, "papermill": { "duration": 2.161377, "end_time": "2026-03-13T21:08:48.388436", "exception": false, "start_time": "2026-03-13T21:08:46.227059", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "model.close(False)" ] }, { "cell_type": "markdown", "id": "fb7a7218", "metadata": { "papermill": { "duration": 0.010504, "end_time": "2026-03-13T21:08:48.406064", "exception": false, "start_time": "2026-03-13T21:08:48.395560", "status": "completed" }, "tags": [] }, "source": [ "Close the program." ] }, { "cell_type": "code", "execution_count": 13, "id": "7f01d161", "metadata": { "execution": { "iopub.execute_input": "2026-03-13T21:08:48.427465Z", "iopub.status.busy": "2026-03-13T21:08:48.426977Z", "iopub.status.idle": "2026-03-13T21:08:53.335463Z", "shell.execute_reply": "2026-03-13T21:08:53.330165Z" }, "papermill": { "duration": 4.920926, "end_time": "2026-03-13T21:08:53.337970", "exception": false, "start_time": "2026-03-13T21:08:48.417044", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "modeler.closeProgram()" ] }, { "cell_type": "markdown", "id": "a6507f96", "metadata": { "papermill": { "duration": 0.013977, "end_time": "2026-03-13T21:08:53.361509", "exception": false, "start_time": "2026-03-13T21:08:53.347532", "status": "completed" }, "tags": [] }, "source": [ "## Full Script" ] }, { "cell_type": "code", "execution_count": 14, "id": "c7f8838a", "metadata": { "execution": { "iopub.execute_input": "2026-03-13T21:08:53.382090Z", "iopub.status.busy": "2026-03-13T21:08:53.381573Z", "iopub.status.idle": "2026-03-13T21:09:38.844799Z", "shell.execute_reply": "2026-03-13T21:09:38.843458Z" }, "papermill": { "duration": 45.474718, "end_time": "2026-03-13T21:09:38.846333", "exception": false, "start_time": "2026-03-13T21:08:53.371615", "status": "completed" }, "tags": [] }, "outputs": [ { "name": "stderr", "output_type": "stream", "text": [ "2026-03-13 17:08:53,394 - Rocscience.RS3 - INFO - Attempting to start the application at C:\\Program Files\\Rocscience\\RS3\\RS3 and binding server to port 60506...\n" ] }, { "name": "stdout", "output_type": "stream", "text": [ "Liner element ID 81643, nodal results:\n", " Node 2375: (x, y, z, Total Displacement, Moment YY) = (10.368124552684677, 15.559329226663175, -9.070223514111749, 0.017510250963789133, 0.3562554391291303)\n", " Node 2622: (x, y, z, Total Displacement, Moment YY) = (10.587785252292472, 15.559329226663177, -9.190983005625052, 0.01659801477075613, 0.3562554391291307)\n", " Node 2621: (x, y, z, Total Displacement, Moment YY) = (10.587785252292472, 15.27928756138166, -9.190983005625052, 0.016808917305162055, 0.3562554391291303)\n" ] } ], "source": [ "# Composite Liner Result Script Example\n", "# Download the [RS3_Result_Scripting_Example folder](https://github.com/Rocscience/rs3-scripting/tree/main/docs/example_code/example_models/RS3_Result_Scripting_Example) for this example.\n", "from rs3.RS3Modeler import RS3Modeler\n", "from rs3.results.ResultEnums import LinerResultTypes\n", "from rs3.Geometry import Point, Cube\n", "import os\n", "# Get the current folder directory.\n", "current_dir = os.path.dirname(os.path.abspath(\"\"))\n", "# Specify a port number that is not in use and start the RS3 program.\n", "port = 60506\n", "RS3Modeler.startApplication(port)\n", "# Connect with the RS3 Modeler.\n", "modeler = RS3Modeler(port)\n", "# For the demonstration purposes only, the model is copied for reuse. \n", "# You may change the model path to your own model path.\n", "model = modeler.openFile(rf\"{current_dir}\\example_models\\RS3_Result_Scripting_Example\\RS3_Result_Scripting_Example.rs3v3\")\n", "\n", "# 1. Get Node Results\n", "# 1.1 Define a box region to filter liner elements (optional)\n", "# A cube region is defined by two corners. Only mesh nodes inside or \n", "# intersecting the box will be returned. If you omit the region in the next \n", "# step, all nodes in the model would be returned.\n", "# In this example, the middle part of the tunnel will be queried.\n", "liner_query_region = Cube(\n", " corner1=Point(x=8.5, y=14.5, z=-8.5),\n", " corner2=Point(x=11.5, y=15.5, z=-11.5),\n", ")\n", "\n", "# 1.2 Get the liner results object for the desired stage(s)\n", "# getCompositeLinerResults returns a list: one entry per stage requested. \n", "# Here we request only stage 3, so the list has one element at index 0.\n", "liner_results_list = model.Results.getCompositeLinerResults(stageNumber=[3])\n", "liner_results_stage_3 = liner_results_list[0]\n", "\n", "# 1.3 Get all liner node results for this stage\n", "# No region is passed, so we get nodes for the all liner in this stage.\n", "liner_node_results_list = liner_results_stage_3.getLinerNodeResults()\n", "# Build a lookup: NodeID -> nodal result object. This is used later to get \n", "# coordinates for each node attached to an element.\n", "liner_node_by_id = {nr.NodeID: nr for nr in liner_node_results_list}\n", "\n", "# 1.4 Get liner element results within the region\n", "liner_element_results_list = liner_results_stage_3.getLinerElementResults(region=liner_query_region)\n", "\n", "# 1.5 Take one element and read its per-node result values\n", "# Each element has attached nodes. getResults(...) returns a list of values, \n", "# one per node of the element (in the same order as AttachedNodeIDs).\n", "element_index = 0\n", "selected_liner_element = liner_element_results_list[element_index]\n", "attached_node_ids = selected_liner_element.AttachedNodeIDs\n", "total_disp_per_node = selected_liner_element.getResults(LinerResultTypes.TOTAL_DISPLACEMENT)\n", "moment_y_per_node = selected_liner_element.getResults(LinerResultTypes.MOMENT_YY)\n", "print(f\"Liner element ID {selected_liner_element.ElementID}, nodal results:\")\n", "for i in range(len(attached_node_ids)):\n", " node_id = attached_node_ids[i]\n", " nodal_result = liner_node_by_id[node_id]\n", " print(\n", " f\" Node {node_id}: (x, y, z, Total Displacement, Moment YY) = \"\n", " f\"({nodal_result.XCoordinate}, {nodal_result.YCoordinate}, {nodal_result.ZCoordinate}, \"\n", " f\"{total_disp_per_node[i]}, {moment_y_per_node[i]})\"\n", " )\n", " \n", "# Since accessing results doesn't change the model, close the model without saving.\n", "model.close(False)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "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.13.0" }, "papermill": { "default_parameters": {}, "duration": 99.05918, "end_time": "2026-03-13T21:09:40.581540", "environment_variables": {}, "exception": null, "input_path": "C:\\Users\\GraceHu\\source\\repos\\RS3Scripting_Compute\\docs\\example_code\\results\\composite_liner_result_example.ipynb", "output_path": "C:\\Users\\GraceHu\\source\\repos\\RS3Scripting_Compute\\docs\\example_code\\results\\composite_liner_result_example.ipynb", "parameters": {}, "start_time": "2026-03-13T21:08:01.522360", "version": "2.6.0" } }, "nbformat": 4, "nbformat_minor": 5 }