Output micro-stress vtk

Asked by Leonard

Hi,

I'd like to ask that how to output vtk file for micro-stress[1].

Referring to previous answer at #6 in [2], a working MWE provided by Jan is copied as below:
################### Working MWE
from yade import export
O.bodies.append((
   sphere((0,0,0),1),
   sphere((1,0,0),1),
))
O.step()
s = bodyStressTensors()
vtk = export.VTKExporter("stress-test")

TW=TesselationWrapper()
TW.setState()
TW.computeVolumes()
s=bodyStressTensors()

for b in O.bodies:
 b.mystress = s[b.id]*4.*pi/3.*b.shape.radius**3/TW.volume(b.id)
vtk.exportSpheres(what=[("stress","b.mystress")])
##########

However, when I tried to adapt this code to a packing of particles like what example code [3] has done. I got an error saying: "AttributeError: 'Body' object has no attribute 'mystress'"

############## Below is the not-working MWE
from yade import export
tt=TriaxialTest()
tt.generate("test.yade")
O.load("test.yade")
O.run(100,True)

particleIds=[]
for i in O.bodies:
 if isinstance(i.shape,Sphere):
  particleIds.append(i.id)

vtk = export.VTKExporter("microStress")

TW=TesselationWrapper()
TW.setState()
TW.computeVolumes()
s=bodyStressTensors()

for b in O.bodies:
 if isinstance(b.shape, Sphere):
  b.mystress = s[b.id]*4.*pi/3.*b.shape.radius**3/TW.volume(b.id)
vtk.exportSpheres(ids=[i for i in particleIds],what=[("stress","b.mystress")])
##########
Do you know why this error occurs for the second MWE?

Thanks
Leonard

[1]https://yade-dev.gitlab.io/trunk/user.html?highlight=paraview#micro-stress
[2]https://answers.launchpad.net/yade/+question/685223
[3]https://gitlab.com/yade-dev/trunk/-/blob/master/examples/tesselationwrapper/tesselationWrapper.py

Question information

Language:
English Edit question
Status:
Solved
For:
Yade Edit question
Assignee:
No assignee Edit question
Solved by:
Jan Stránský
Solved:
Last query:
Last reply:
Revision history for this message
Jan Stránský (honzik) said :
#1

Hello,

what is your Yade and OS version?
I have tried the second code, but it run without any error, producing some microStress-spheres-00000000.vtk successfully.
Ubuntu 18.04, yadedaily, 20220124-6294~406fb7a~bionic1

Cheers
Jan

Revision history for this message
Leonard (z2521899293) said :
#2

Hi Jan,

I use Ubuntu 18.04, Yade 2018.02b.

Does it mean that Yade 2018.02b could not output microstress in this way?

Thanks
Leonard

Revision history for this message
Best Jan Stránský (honzik) said :
#3

Not directly this way.
However, after following workaround, I could make it run on 2018.02b, too
Cheers
Jan

###
from yade import export
tt=TriaxialTest()
tt.generate("test.yade")
O.load("test.yade")
O.run(100,True)

particleIds=[]
for i in O.bodies:
 if isinstance(i.shape,Sphere):
  particleIds.append(i.id)

vtk = export.VTKExporter("microStress")

TW=TesselationWrapper()
TW.setState()
TW.computeVolumes()
s=bodyStressTensors()
mystresses = [None for _ in O.bodies] # "external" variable, accessed only by b.id
import __builtin__
__builtin__.mystresses = mystresses # make it "global"

for b in O.bodies:
 if isinstance(b.shape, Sphere):
  mystresses[b.id] = s[b.id]*4.*pi/3.*b.shape.radius**3/TW.volume(b.id) # fill mystresses with values
vtk.exportSpheres(ids=[i for i in particleIds],what=[("stress","mystresses[b.id]")]) # using mystresses "global" "external" variable
###

Revision history for this message
Leonard (z2521899293) said :
#4

Thanks Jan Stránský, that solved my question.