Page 1 of 1

Retrieve stresses on GaussPoint

Posted: Tue Dec 06, 2022 1:44 pm
by gaetano_cmr
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 (
	QObject,
	Signal,
	Slot,
	QCoreApplication,
	QTimer,
	QThread,
	QEventLoop,
	)
from PySide2.QtWidgets import (
	QWidget,
	QDialog,
	QSizePolicy,
	QVBoxLayout,
	)

################################################################################

# clear terminal
App.clearTerminal()

# 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 (https://www.youtube.com/watch?v=TrHhvJ8L9ao) but without success.
Where the error could be?

Re: Retrieve stresses on GaussPoint

Posted: Wed Dec 07, 2022 10:37 am
by STKO Team
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?

Re: Retrieve stresses on GaussPoint

Posted: Thu Dec 08, 2022 9:39 am
by gaetano_cmr
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 :/

Re: Retrieve stresses on GaussPoint

Posted: Wed Dec 14, 2022 11:45 am
by STKO Team
Could you please make a screenshot of your element results?:
ele_res.png
ele_res.png (45.28 KiB) Viewed 8453 times
Do you have a result that starts with this "material.stress (Volume; 3 Components {σ11,σ22,σ12};S)"?

Re: Retrieve stresses on GaussPoint

Posted: Fri Dec 16, 2022 9:08 am
by gaetano_cmr
Yes, I have it in my model as result; here the screenshot of my elements recorders:

Re: Retrieve stresses on GaussPoint

Posted: Fri Dec 16, 2022 2:46 pm
by STKO Team
There is a missing white-space at the end ";<missing_here>S"

Re: Retrieve stresses on GaussPoint

Posted: Sat Sep 16, 2023 5:12 am
by Nolaraj
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.

Re: Retrieve stresses on GaussPoint

Posted: Mon Sep 18, 2023 7:50 am
by STKO Team
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)

Re: Retrieve stresses on GaussPoint

Posted: Tue Mar 05, 2024 1:18 pm
by Nolaraj
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: https://github.com/Nolaraj/STKO_Opensee ... Element.py)
Initialization
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):
Elements.append(ele_id)
break
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)
x.append(ix)
y.append(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()
cdata.id = doc.genNextIdForChartData()
cdata.name = "Element {} - Compoenent {}".format(ele_id, component)
cdata.xLabel = strain.componentLabels()[component]
cdata.yLabel = stress.componentLabels()[component]
cdata.x = x
cdata.y = y
doc.addChartData(cdata)

# 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()
chart.id = doc.genNextIdForChart()
chart.name = "Element {} - Compoenent {}".format(ele_id, component)
chart.addItem(cdata_item)
doc.addChart(chart)

Sample of plot for single gauss point result


Chapter 2
Bulk processing of multiple model database (Source code: https://github.com/Nolaraj/STKO_Opensee ... _python.py)
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.

Re: Retrieve stresses on GaussPoint

Posted: Wed Mar 06, 2024 3:50 pm
by kesavapraba
Thank you