Compute Script Examples#

Download the blankModel.rs3v3 for this example.

from rs3.RS3Modeler import RS3Modeler
from rs3.properties.PropertyEnums import *
from rs3.projectSettings.ProjectSettingEnums import *
from rs3.ModelEnums import *
import os
import shutil

Get the current folder directory.

current_dir = os.path.dirname(os.path.abspath(""))

Specify a port number that is not in use and start the RS3 program.

port = 60108
RS3Modeler.startApplication(port)
2026-03-13 16:42:17,331 - Rocscience.RS3 - INFO - Attempting to start the application at C:\Program Files\Rocscience\RS3\RS3 and binding server to port 60108...

Connect with the RS3 Modeler.

modeler = RS3Modeler(port)

For the demonstration purposes only, the model is copied for reuse. You may change the model path to your own model path.

blankModelPath = rf"{current_dir}\example_models\blankModel.rs3v3"
copiedModelPath = rf"{current_dir}\example_models\copiedModel.rs3v3"
_ = shutil.copy(blankModelPath, copiedModelPath)

Open the copied model file.

model = modeler.openFile(copiedModelPath)

1. Compute#

If nothing specified, by default, model computes after the last computed stage and compute all compute types (i.e. solids and groudwater).

model.Compute.compute()
Recovery: True
Stages Convergence:
Stage    Status  
----------------
1        Yes     
2        Yes     
3        Yes     
4        Yes     
5        Yes     
(True, '')

2. Compute Groundwater Only#

Turn on groundwater mode in project settings.

model.ProjectSettings.Groundwater.setGroundwaterMethod(GroundwaterMethodType.GW_SURFACES)

Create a water surface.

groundwaterName = "Groundwater @ -5 m"
model.createNewWaterByLocationProperty(groundwaterName)
waterSurface = model.getWaterByLocationPropertyByName(groundwaterName)
waterSurface.setWaterSurfaceLocation([(0, 0, -5), (0, 30, -5), (30, 30, -5), (30, 0, -5)])

Assign the water surface to Material 1.

material1 = model.getMaterialPropertiesInUseByStage(1)[0]
material1.getMaterialName()
'Soil'
material1.Hydraulic.StaticGroundwater.setStaticWaterMode(StaticWaterModes.WATER_SURFACE, groundwaterName)
material1.Hydraulic.StaticGroundwater.getStaticWaterMode()
'Groundwater @ -5 m'

Compute groundwater only from the beginning.

model.Compute.compute(ComputeType.GROUNDWATER_ONLY, ComputeStart.FROM_BEGINNING)
Recovery: True
Stages Convergence:
Stage    Status  
----------------
1        Yes     
2        Yes     
3        Yes     
4        Yes     
5        Yes     
(True, '')

Save and close the model.

model.close(True)

Close the program.

modeler.closeProgram()

Full Script#

# Compute Script Examples
# Download the [blankModel.rs3v3](https://github.com/Rocscience/rs3-scripting/tree/main/docs/example_code/example_models/blankModel.rs3v3) for this example.
from rs3.RS3Modeler import RS3Modeler
from rs3.properties.PropertyEnums import *
from rs3.projectSettings.ProjectSettingEnums import *
from rs3.ModelEnums import *
import os
import shutil
# Get the current folder directory.
current_dir = os.path.dirname(os.path.abspath(""))
# Specify a port number that is not in use and start the RS3 program.
port = 60108
RS3Modeler.startApplication(port)
# Connect with the RS3 Modeler.
modeler = RS3Modeler(port)
# For the demonstration purposes only, the model is copied for reuse. 
# You may change the model path to your own model path.
blankModelPath = rf"{current_dir}\example_models\blankModel.rs3v3"
copiedModelPath = rf"{current_dir}\example_models\fullScriptCopiedModel.rs3v3"
_ = shutil.copy(blankModelPath, copiedModelPath)
# Open the copied model file.
model = modeler.openFile(copiedModelPath)

# 1. Compute
# If nothing specified, by default, model computes after the last computed stage and 
# compute all compute types (i.e. solids and groudwater).
model.Compute.compute()

# 2. Compute Groundwater Only
# Turn on groundwater mode in project settings.
model.ProjectSettings.Groundwater.setGroundwaterMethod(GroundwaterMethodType.GW_SURFACES)
# Create a water surface.
groundwaterName = "Groundwater @ -5 m"
model.createNewWaterByLocationProperty(groundwaterName)
waterSurface = model.getWaterByLocationPropertyByName(groundwaterName)
waterSurface.setWaterSurfaceLocation([(0, 0, -5), (0, 30, -5), (30, 30, -5), (30, 0, -5)])
# Assign the water surface to Material 1.
material1 = model.getMaterialPropertiesInUseByStage(1)[0]
material1.Hydraulic.StaticGroundwater.setStaticWaterMode(StaticWaterModes.WATER_SURFACE, groundwaterName)
# Compute groundwater only from the beginning.
model.Compute.compute(ComputeType.GROUNDWATER_ONLY, ComputeStart.FROM_BEGINNING)

# Save and close the model.
model.close(True)
2026-03-13 16:45:17,362 - Rocscience.RS3 - INFO - Attempting to start the application at C:\Program Files\Rocscience\RS3\RS3 and binding server to port 60108...
Recovery: True
Stages Convergence:
Stage    Status  
----------------
1        Yes     
2        Yes     
3        Yes     
4        Yes     
5        Yes     
Recovery: True
Stages Convergence:
Stage    Status  
----------------
1        Yes     
2        Yes     
3        Yes     
4        Yes     
5        Yes