Field Stress Script Examples#
Download the blankModel.rs3v3 for this example.
from rs3.RS3Modeler import RS3Modeler
from rs3.loadings.LoadingEnums import *
from rs3.CommonEnums 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 = 60105
RS3Modeler.startApplication(port)
2026-03-13 16:49:57,182 - Rocscience.RS3 - INFO - Attempting to start the application at C:\Program Files\Rocscience\RS3\RS3 and binding server to port 60105...
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. Constant Field Stress#
Field stress type needs to be set to CONSTANT. Otherwise, script cannot make changes to constant field stress properties.
model.Loadings.FieldStress.setType(FieldStressType.CONSTANT)
constantFieldStress = model.Loadings.FieldStress.Constant
Check current constant field stress properties.
constantFieldStress.getProperties()
{'Sigma1': 10.0, 'Sigma2': 10.0, 'Sigma3': 10.0}
constantFieldStress.setProperties(Sigma1=15.1, Sigma2=10.2, Sigma3=5.3)
constantFieldStress.getProperties()
{'Sigma1': 15.1, 'Sigma2': 10.2, 'Sigma3': 5.3}
Set orientation of field stress by normal vectors.
constantFieldStress.setOrientationType(LinearDirectionType.NORMAL_VECTOR)
constantFieldStress.setVectorOrientation((1.0, 3.0, 2.0), (1.0, 3.0, -5.0))
constantFieldStress.getVectorOrientation()
[(1.0, 3.0, 2.0), (1.0, 3.0, -5.0)]
Set orientation of field stress by trend and plunge.
constantFieldStress.setOrientationType(LinearDirectionType.TREND_PLUNGE)
constantFieldStress.setTrendPlungeOrientation(18.4349, -32.3115, 108.435, 0)
constantFieldStress.getTrendPlungeOrientation()
(18.4349, -32.3115, 108.435, 0.0)
2. Gravity Field Stress#
Field stress type needs to be set to GRAVITY. Otherwise, script cannot make changes to gravity field stress properties.
model.Loadings.FieldStress.setType(FieldStressType.GRAVITY)
gravityFieldStress = model.Loadings.FieldStress.Gravity
Check current gravity field stress properties.
gravityFieldStress.getProperties()
{'UseActualGroundSurface': True,
'GroundSurfaceElevation': 0.0,
'OverburdenUnitWeight': 20.0,
'UseEffectiveStressRatio': True,
'UseNonlinearVariableStressRatio': False,
'K0Condition': True,
'SigmaH1K1': 1.0,
'SigmaH1K1a': 1.0,
'SigmaH1K1b': 0.0,
'SigmaH1K1c': 0.0,
'SigmaH1LockedIn': 0.0,
'SigmaH2K2': 2.0,
'SigmaH2K2a': 1.0,
'SigmaH2K2b': 0.0,
'SigmaH2K2c': 0.0,
'SigmaH2LockedIn': 0.0}
gravityFieldStress.setProperties(UseActualGroundSurface=False, GroundSurfaceElevation=10.5, OverburdenUnitWeight=19.02)
gravityFieldStress.setSigmaH1K1(1.5)
gravityFieldStress.getProperties()
{'UseActualGroundSurface': False,
'GroundSurfaceElevation': 10.5,
'OverburdenUnitWeight': 19.02,
'UseEffectiveStressRatio': True,
'UseNonlinearVariableStressRatio': False,
'K0Condition': True,
'SigmaH1K1': 1.5,
'SigmaH1K1a': 1.0,
'SigmaH1K1b': 0.0,
'SigmaH1K1c': 0.0,
'SigmaH1LockedIn': 0.0,
'SigmaH2K2': 2.0,
'SigmaH2K2a': 1.0,
'SigmaH2K2b': 0.0,
'SigmaH2K2c': 0.0,
'SigmaH2LockedIn': 0.0}
Set orientation of field stress by normal vectors.
gravityFieldStress.setOrientationType(LinearDirectionType.NORMAL_VECTOR)
gravityFieldStress.setVectorOrientation((1.0, 3.0, 2.0), (1.0, 3.0, -5.0))
gravityFieldStress.getVectorOrientation()
[(1.0, 3.0, 2.0), (1.0, 3.0, -5.0)]
Set orientation of field stress by trend and plunge.
gravityFieldStress.setOrientationType(LinearDirectionType.TREND_PLUNGE)
gravityFieldStress.setTrendPlungeOrientation(18.4349, 13.2, 78.435)
gravityFieldStress.getTrendPlungeOrientation()
(18.4349, 13.2, 78.435)
3. Advanced Constant Field Stress#
Field stress type needs to be set to CONSTANT. Otherwise, script cannot make changes to constant field stress properties.
model.Loadings.FieldStress.setType(FieldStressType.CONSTANT)
advancedConstantFieldStress = model.Loadings.FieldStress.AdvancedConstant
material1Name = model.getAllMaterialProperties()[0].getMaterialName()
advancedConstantFieldStress.setApplyCustomFieldStress(material1Name, True)
advancedConstantFieldStress.setSigma1(material1Name, 246.289)
advancedConstantFieldStress.getSigma1(material1Name)
246.289
Set the vector orientation of the material.
advancedConstantFieldStress.setVectorOrientation(material1Name, (1.0, 3.0, 2.0), (1.0, 3.0, -5.0))
advancedConstantFieldStress.getVectorOrientation(material1Name)
[(1.0, 3.0, 2.0), (1.0, 3.0, -5.0)]
Trend and plunge orientation are updated accordingly.
advancedConstantFieldStress.getTrendPlungeOrientation(material1Name)
(18.43494882292201, -32.31153323742385, 18.43494882292201, 57.688466762576155)
Set the trend and plunge orientation of the material.
advancedConstantFieldStress.setTrendPlungeOrientation(material1Name, 18.4349, -32.3115, 108.435, 0)
advancedConstantFieldStress.getTrendPlungeOrientation(material1Name)
(18.4349, -32.3115, 108.435, 0.0)
The vector orientation is updated accordingly.
advancedConstantFieldStress.getVectorOrientation(material1Name)
[(0.2672606567507064, 0.8017842476414259, 0.5345219935486788),
(0.9486830155928029, -0.31622861338870933, 0.0)]
4. Advanced Gravity Field Stress#
Field stress type needs to be set to GRAVITY. Otherwise, script cannot make changes to gravity field stress properties.
model.Loadings.FieldStress.setType(FieldStressType.GRAVITY)
advancedGravityFieldStress = model.Loadings.FieldStress.AdvancedGravity
material2Name = model.getAllMaterialProperties()[1].getMaterialName()
advancedGravityFieldStress.setApplyCustomFieldStress(material2Name, True)
advancedGravityFieldStress.setSigmaH1K1(material2Name, 101.2)
advancedGravityFieldStress.getSigmaH1K1(material2Name)
101.2
Set trend and plunge orientation.
advancedGravityFieldStress.setTrendPlungeOrientation(material2Name, 18.4349, 13.2, 78.435)
advancedGravityFieldStress.getTrendPlungeOrientation(material2Name)
(18.4349, 13.2, 78.435)
advancedGravityFieldStress.getVectorOrientation(material2Name)
[(0.416069423439195, 0.08514194847222456, 0.9053381045163894),
(0.3078718944625007, 0.9236183068344723, -0.22835087011065575)]
Save and close the model.
model.close(True)
Close the program.
modeler.closeProgram()
Full Script#
# Field Stress 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.loadings.LoadingEnums import *
from rs3.CommonEnums 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 = 60105
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\copiedModel.rs3v3"
_ = shutil.copy(blankModelPath, copiedModelPath)
# Open the copied model file.
model = modeler.openFile(copiedModelPath)
# 1. Constant Field Stress
# Field stress type needs to be set to CONSTANT. Otherwise, script cannot make changes to constant field stress properties.
model.Loadings.FieldStress.setType(FieldStressType.CONSTANT)
# Create a short alias to avoid repeatedly typing model.Mesh.Uniform
constantFieldStress = model.Loadings.FieldStress.Constant
# Check current constant field stress properties.
constantFieldStress.setProperties(Sigma1=15.1, Sigma2=10.2, Sigma3=5.3)
# Set orientation of field stress by normal vectors.
constantFieldStress.setOrientationType(LinearDirectionType.NORMAL_VECTOR)
constantFieldStress.setVectorOrientation((1.0, 3.0, 2.0), (1.0, 3.0, -5.0))
# Set orientation of field stress by trend and plunge.
constantFieldStress.setOrientationType(LinearDirectionType.TREND_PLUNGE)
constantFieldStress.setTrendPlungeOrientation(18.4349, -32.3115, 108.435, 0)
# 2. Gravity Field Stress
# Field stress type needs to be set to GRAVITY. Otherwise, script cannot make changes to gravity field stress properties.
model.Loadings.FieldStress.setType(FieldStressType.GRAVITY)
gravityFieldStress = model.Loadings.FieldStress.Gravity
gravityFieldStress.setProperties(UseActualGroundSurface=False, GroundSurfaceElevation=10.5, OverburdenUnitWeight=19.02)
gravityFieldStress.setSigmaH1K1(1.5)
# Set orientation of field stress by normal vectors.
gravityFieldStress.setOrientationType(LinearDirectionType.NORMAL_VECTOR)
gravityFieldStress.setVectorOrientation((1.0, 3.0, 2.0), (1.0, 3.0, -5.0))
# Set orientation of field stress by trend and plunge.
gravityFieldStress.setOrientationType(LinearDirectionType.TREND_PLUNGE)
gravityFieldStress.setTrendPlungeOrientation(18.4349, 13.2, 78.435)
# 3. Advanced Constant Field Stress
# Field stress type needs to be set to CONSTANT. Otherwise, script cannot make changes to constant field stress properties.
model.Loadings.FieldStress.setType(FieldStressType.CONSTANT)
advancedConstantFieldStress = model.Loadings.FieldStress.AdvancedConstant
material1Name = model.getAllMaterialProperties()[0].getMaterialName()
advancedConstantFieldStress.setApplyCustomFieldStress(material1Name, True)
advancedConstantFieldStress.setSigma1(material1Name, 246.289)
# Set the vector orientation of the material.
advancedConstantFieldStress.setVectorOrientation(material1Name, (1.0, 3.0, 2.0), (1.0, 3.0, -5.0))
# Set the trend and plunge orientation of the material.
advancedConstantFieldStress.setTrendPlungeOrientation(material1Name, 18.4349, -32.3115, 108.435, 0)
# 4. Advanced Gravity Field Stress
# Field stress type needs to be set to GRAVITY. Otherwise, script cannot make changes to gravity field stress properties.
model.Loadings.FieldStress.setType(FieldStressType.GRAVITY)
advancedGravityFieldStress = model.Loadings.FieldStress.AdvancedGravity
material2Name = model.getAllMaterialProperties()[1].getMaterialName()
advancedGravityFieldStress.setApplyCustomFieldStress(material2Name, True)
advancedGravityFieldStress.setSigmaH1K1(material2Name, 101.2)
# Set trend and plunge orientation.
advancedGravityFieldStress.setTrendPlungeOrientation(material2Name, 18.4349, 13.2, 78.435)
# Save and close the model.
model.close(True)
2026-03-13 16:51:02,568 - Rocscience.RS3 - INFO - Attempting to start the application at C:\Program Files\Rocscience\RS3\RS3 and binding server to port 60105...