Retrieve stresses on GaussPoint

Post Reply
Posts: 7
Joined: Sat Sep 10, 2022 2:28 pm

Retrieve stresses on GaussPoint

Post by gaetano_cmr » Tue Dec 06, 2022 1:44 pm

Dear STKO support,

I'm facing a problem retreaving stresses on specific gausspoint in my STKO model.
I load the postprocessor results and I tryed to retrieve "σ22" using this script:

Code: Select all

from PyMpc import *
from PyMpc import MpcOdbVirtualResult as vr
from time import sleep
import traceback
import numpy as np
from time import sleep
import traceback
from PySide2.QtCore import (
from PySide2.QtWidgets import (


# clear terminal

# get document
doc = App.postDocument()

# get first database
if len(doc.databases) == 0:
	raise Exception("You need a database with ID = 1 for this test")
db = doc.getDatabase(1)

# create evaluation options
# here we want to extract data for all steps of the last stage
all_stages = db.getStageIDs()
last_stage = all_stages[-1]
all_steps = db.getStepIDs(last_stage)
opt = MpcOdbVirtualResultEvaluationOptions()
opt.stage = last_stage

# signals
finished = Signal()

# gauss result
result_x = db.getElementalResult("material.stress (Volume; 3 Components {σ11,σ22,σ12};S)", match = MpcOdb.Contains)
row = MpcOdbResultField.gauss(1130, 1) # the gauss field object is the row identifier in the result field
num_steps = len(all_steps)

x = []
for i in range(num_steps):
	opt.step = all_steps[i]
	field_x = result_x.evaluate(opt)
	x.append(field_x[row, 0])

but I got this message:

Code: Select all

Cannot evaluate the virtual results due to the following errors:
MpcOdbElementalResultWithField: Result is NULL
I'm following one of your webinars ( but without success.
Where the error could be?

Posts: 2309
Joined: Tue Oct 29, 2019 8:45 am

Re: Retrieve stresses on GaussPoint

Post by STKO Team » Wed Dec 07, 2022 10:37 am

The error is saying that the result you requested is null, i.e. it does not exist in your MPCO database.
Did you record it?

Posts: 7
Joined: Sat Sep 10, 2022 2:28 pm

Re: Retrieve stresses on GaussPoint

Post by gaetano_cmr » Thu Dec 08, 2022 9:39 am

Yes I did, I’m able to plot it using “data chart” or displaying it in the post-processor GUI.
Don’t know what I’m doing wrong in the script :/

Posts: 2309
Joined: Tue Oct 29, 2019 8:45 am

Re: Retrieve stresses on GaussPoint

Post by STKO Team » Wed Dec 14, 2022 11:45 am

Could you please make a screenshot of your element results?:
ele_res.png (45.28 KiB) Viewed 4613 times
Do you have a result that starts with this "material.stress (Volume; 3 Components {σ11,σ22,σ12};S)"?

Posts: 7
Joined: Sat Sep 10, 2022 2:28 pm

Re: Retrieve stresses on GaussPoint

Post by gaetano_cmr » Fri Dec 16, 2022 9:08 am

Yes, I have it in my model as result; here the screenshot of my elements recorders:
immagine_2022-12-16_100838598.png (15.95 KiB) Viewed 4593 times

Posts: 2309
Joined: Tue Oct 29, 2019 8:45 am

Re: Retrieve stresses on GaussPoint

Post by STKO Team » Fri Dec 16, 2022 2:46 pm

There is a missing white-space at the end ";<missing_here>S"

Posts: 3
Joined: Thu Jul 06, 2023 9:19 am

Re: Retrieve stresses on GaussPoint

Post by Nolaraj » Sat Sep 16, 2023 5:12 am

I want to derive shear stress vs strain plot from SSPbrick element with PIMY material property assigned for soil. I had used the code below but couldnot get the stress strain for PIMY material but it had efficiently extracted for elasticISotrophic material assigned to foundation which similarly been modelled with SSPbrick element. How could I solve this ?
Note: I had used custom result with stress and strain entity for complete model region in MPCOrecorder.
(2.07 KiB) Downloaded 189 times

Posts: 2309
Joined: Tue Oct 29, 2019 8:45 am

Re: Retrieve stresses on GaussPoint

Post by STKO Team » Mon Sep 18, 2023 7:50 am

It's because the PIMY material gives you a 7-components stress vector (the first 6 are stress components, the last one is an internal variable).

Therefore this line is not working as the result has a different name (7 instead of 6). Change this string

Code: Select all

stress = db.getElementalResult('stress (Volumes; 6', match=MpcOdb.Contains)

Posts: 3
Joined: Thu Jul 06, 2023 9:19 am

Re: Retrieve stresses on GaussPoint

Post by Nolaraj » Tue Mar 05, 2024 1:18 pm

Now, I have extracted the required outputs and complete documentation for them is as follows:

Chapter 1
Stress Strain parameters from Solid Element (Source code: ...
1. Initialization of STKO system and its components
2. User input for data customization
• Database ID
db_id = 1

• Stress and strain component
component = 5 # from 0 to 6 (example 2 = Szz)

• Stage-id for mesh evaluation: Generally, first stage is occupied by gravity analysis and second stage is assigned for seismic analysis. The index here follows with start with 1.
stage_for_mesh = 2

• Reference CoOrdinates in X, Y and Z format: The values here provided are the reference from which nearby first scanned node (ie. Midpoint of solid element) inside the sphere defined by the tolerance is used for data extraction.
refcoOrd = [12.5,12.5,-7] # [X, Y , Z] Units of co ordinates are according to the model dimensions

• Tolerance: Values provided here iterates from start to end with specified increment (multiplying factor) until first node of solid element inside the sphere of influence specified by reference Co ordinate (as center) above is found. Here the tolerance value on each iterations acts to behave as radius for sphere of influence.
Tolerances = [1e-7, 1.5, 5] #Toleraces: Starting tolerance for check, tolerance increment, and maximum tolerance

Getting solid element of interest (based on reference CoOrdinates)
Elements = []
for ele_id, ele in mesh.elements.items():
if CheckValue(ele):
1. First all the elements from mesh are iterated.
2. The elements are checked whether they lie inside the boundary demarcated by reference coordinates and tolerance.
3. First scanned element is taken for further process.

Extracting all available volume-based stress and strains
strain = db.getElementalResult('strain (Volumes; 6', match=MpcOdb.Contains)
stress = db.getElementalResult('stress (Volumes; 6', match=MpcOdb.Contains)

• To get elements results for stress and strains as displayed above, custom recorders each with value “stress” and “strain” needs to be kept in analysis step of preprocessor.
• Strain and stress variable in the code above extracts all stress and strains values of index [3] and [4] of figure above.

Parsing all the available steps for particular stage and writing
# X-Y data for each element
XY_lists = [([], []) for i in range(len(elements))]

# parse all stages and all steps
for stage_id in db.getStageIDs():
all_steps = db.getStepIDs(stage_id)
for step_id in all_steps:
opt.stage = stage_id
opt.step = step_id
# evaluate the field
stress_field = stress.evaluate(opt)
strain_field = strain.evaluate(opt)
# process each element
for i in range(len(elements)):
ele_id = elements
x, y = XY_lists
row = MpcOdbResultField.gauss(ele_id, 0)
ix = strain_field[row, component]
iy = stress_field[row, component]
print(ele_id, ix, iy)
• XY_lists creates the space for accommodation of ([stressstep 1, stressstep 2 …], [strain step 1, strain step 2 ...]), ([], [])…. for each elements.
• Then stress and strains fields are found out through .evaluate(opt) command. After that for each steps, stress and strain are determined as ix and iy based upon row and component variable.
o row primarily defines for the index of element’s gauss point on MPCO Result field.
o component is as defined in initialization process.
• Note: Here in this case only one element is considered so i variable loop runs for single time. In case of multiple variable, the outputs will be as directed above.

By using of the data above chart is now developed using the code below
# make charts for each selected element
for i in range(len(elements)):
# element data
ele_id = elements
x, y = XY_lists

# create a new chart data
cdata = MpcChartData() = doc.genNextIdForChartData() = "Element {} - Compoenent {}".format(ele_id, component)
cdata.xLabel = strain.componentLabels()[component]
cdata.yLabel = stress.componentLabels()[component]
cdata.x = x
cdata.y = y

# create a chart data item to put in the chart
cdata_item = MpcChartDataGraphicItem(cdata)
cdata_item.color = MpcQColor(255, 150, 0, 255)
cdata_item.thickness = 1.5
cdata_item.penStyle = MpcQPenStyle.SolidLine

# create a new chart
chart = MpcChart() = doc.genNextIdForChart() = "Element {} - Compoenent {}".format(ele_id, component)

Sample of plot for single gauss point result

Chapter 2
Bulk processing of multiple model database (Source code: ...
Summary of complete process
1. First the user provides root directory from which data extraction needs to be proceed.
2. The system then extracts for all available .mpco files inside all the sub directory of root folder.
3. Each .mpco cluster is determined and separated for preventing mixing of multiple database from same cluster.
4. The system then extracts stress and strain as mentioned in previous heading.
Note: In this code stress strains are extracted from .mpco using h5py python module without involvement of STKO platform.
5. The stress and strain are then saved inside Excel workbook with worksheet for each cluster as shown in sample figure below. Strain are saved under column A and stress under column B.

6. Further data processing can be attained through custom python code.
(239.22 KiB) Downloaded 138 times

Posts: 348
Joined: Sat Mar 28, 2020 2:25 pm

Re: Retrieve stresses on GaussPoint

Post by kesavapraba » Wed Mar 06, 2024 3:50 pm

Thank you
:: With best wishes ::
Prabakaran Kesavan

Post Reply