Calculate and plot the stress ratio for 2D element

Post Reply
yuweihwang
Posts: 34
Joined: Wed Apr 29, 2020 4:54 am

Calculate and plot the stress ratio for 2D element

Post by yuweihwang » Wed Dec 01, 2021 10:04 pm

Hi all,

I have tried to calculate and plot the stress ratio for 2D elements.
Here is my code.

Code: Select all

from PyMpc import *
from PyMpc import MpcOdbVirtualResult as vr

doc = App.postDocument()
db = doc.getDatabase(1)
# get stress at initial stage
initial_stage = 1
S22= db.getElementalResult('stress (Volumes; Components {σ22',match = MpcOdb.Contains, time = vr.stageEnd(initial_stage))
S12= db.getElementalResult('stress (Volumes; Components {σ23',match = MpcOdb.Contains, time = vr.stageEnd(initial_stage))
S22 += (S22 == 0.0)*1.0e-12
S12 += (S12 == 0.0)*1.0e-12
Sratio = S12/(S22)
Sratio.setDisplayName('Stress Ratio')
Sratio.setComponentLabels(['stress_ratio'])
db.addVirtualResult(Sratio)
However, it looks like I cannot get S22 and S12 correctly.
I got the following error messages.

Code: Select all

Cannot add the virtual results due to the following errors:
MpcOdbElementalResultWithField: Result is NULL
MpcOdbElementalResultWithField: Result is NULL
Do you have any suggestions?
Many thanks for your help.

STKO Team
Posts: 893
Joined: Tue Oct 29, 2019 8:45 am

Re: Calculate and plot the stress ratio for 2D element

Post by STKO Team » Thu Dec 02, 2021 8:46 am

That's because there is no result which contains this string "stress (Volumes; Components {σ22'".

I think I understood what you were trying to do, but it is not correct. You thought that placing the component name in the first string gives you that component.
This is wrong.

The first string is the name of the result you want, or a part of it in case Match = Contains. But note that the piece of the string must be contained completely and contiguously.

Once you do that correctly, you obtain the result. Once you evaluate it, you obtain the result field. for a 2D stress tensor, it should be a 3-column dataset, whose columns refer to the following components: S11, S22, S12.

If you send us your mpco output I will show you how to do it.

yuweihwang
Posts: 34
Joined: Wed Apr 29, 2020 4:54 am

Re: Calculate and plot the stress ratio for 2D element

Post by yuweihwang » Thu Dec 02, 2021 4:24 pm

Hello STKO team,

I am not sure why I cannot attach my model.
Here is the dropbox folder for my model.
https://www.dropbox.com/sh/7ceg96cb17j3 ... Y18Qa?dl=0
Many thanks for your help.

Best,
Yu-Wei

STKO Team
Posts: 893
Joined: Tue Oct 29, 2019 8:45 am

Re: Calculate and plot the stress ratio for 2D element

Post by STKO Team » Fri Dec 03, 2021 10:02 am

Oops, unfortunately, what you want to do cannot be done now.
Because you are trying to perform a ratio operation between different components.
You can still do it using the evaluate function and compute values in the script, but not using a virtual result for plots.

To do it, in the next version, I need to create another function that allows you to extract a single column from a multi-component result.

Post Reply