seeking help in VTKRecorder

Asked by Yuri Bezmenov

Hi folks!
I am trying to run a simulation with Geogrid and Balls. It is running fine but I want to visualize Geogrid and Balls separately.
How can I achieve this?
I am using Ubuntu 22.04.2 LTS and Yade 2022.01a.

my code is attached:

from builtins import range
from yade import pack, geom, plot, export
from yade.gridpfacet import *
rate=-0.5 #1.66e-4
compFricDegree=30
finalFricDegree = 40
stabilityThreshold = 0.1
young = 5e6
mn, mx = Vector3(0, 0, 0), Vector3(0.9, 0.6, 0.6)
O.engines = [
        ForceResetter(),
        InsertionSortCollider([
                Bo1_Sphere_Aabb(),
                Bo1_GridConnection_Aabb(),
  Bo1_Facet_Aabb(), Bo1_Wall_Aabb()
        ]),
        InteractionLoop(
                [ Ig2_Sphere_Sphere_ScGeom(),
   Ig2_Facet_Sphere_ScGeom(), Ig2_Wall_Sphere_ScGeom(),
                        Ig2_Sphere_GridConnection_ScGridCoGeom(),
                        Ig2_GridNode_GridNode_GridNodeGeom6D(),
                        Ig2_GridConnection_GridConnection_GridCoGridCoGeom()],
  [Ip2_CohFrictMat_CohFrictMat_CohFrictPhys(setCohesionNow=True, setCohesionOnNewContacts=True), Ip2_FrictMat_FrictMat_FrictPhys()],
  [Law2_ScGeom_FrictPhys_CundallStrack(), Law2_ScGridCoGeom_FrictPhys_CundallStrack(), Law2_GridCoGridCoGeom_FrictPhys_CundallStrack(),
  Law2_ScGeom6D_CohFrictPhys_CohesionMoment(),]
        ),
        GlobalStiffnessTimeStepper(timestepSafetyCoefficient=0.1, label='ts'),
        NewtonIntegrator(gravity=(0,-10,0), damping=.5, label='newton'),
 PyRunner(command='addPlotData()', iterPeriod=500),
 # VTKRecorder(fileName='/files/Geogrid/paraview/pullout', recorders=['all'], iterPeriod=500),
]
def addPlotData():
 plot.addData(
  unbalanced=unbalancedForce(),
  i=O.iter
 )
plot.plots = {
        'i':('unbalanced'),
}
plot.plot()
O.materials.append(FrictMat(young=young, poisson=0.5, frictionAngle=radians(compFricDegree), density=2600, label='spheres'))
O.materials.append(FrictMat(young=young, poisson=0.5, frictionAngle=0, density=0, label='walls'))
O.materials.append(CohFrictMat(young=1.325e8, poisson=0.40, density=900, frictionAngle=radians(10), normalCohesion=1.1e8, shearCohesion=1.1e8, momentRotationLaw=True, label='spheremat'))
L = 0.608 #length [m]
l = 0.304 #width [m]
nbL = 16+1 #number of nodes for the length [#]
nbl = 8+1 #number of nodes for the width [#]
r = 0.008/2 # L / 100. #radius
color = [255. / 255., 102. / 255., 0. / 255.]
nodesIds = []
for i in range(0, nbL):
 for j in range(0, nbl):
  nodesIds.append(O.bodies.append(gridNode([i*L/nbL, 0.3, 0.15+j*l/nbl], r, wire=False, fixed=False, material='spheremat', color=color)))

#Create connection between the nodes
for i in range(0, len(nodesIds)):
 for j in range(i + 1, len(nodesIds)):
  dist = (O.bodies[i].state.pos-O.bodies[j].state.pos).norm()
  if (dist <= (L/nbL)*1.05):
   O.bodies.append(gridConnection(i, j, r, color=color))
O.bodies.append(geom.facetBox((.45, .5, .3), (.45, .5, .3), wallMask=55, material='walls'))
sp = pack.SpherePack()
sp.makeCloud((0, 0, 0), (0.9, 0.2, 0.6), rMean=.05, rRelFuzz=.3)
sp.makeCloud((0, 0.4, 0), (0.9, 0.6, 0.6), rMean=.05, rRelFuzz=.3)
O.bodies.append([sphere(center, rad, material='spheres') for center, rad in sp])
O.run()

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 :
#2

Hello,

> ... a simulation with Geogrid and Balls.

what are "Geogrid" and "Balls"?
Why capital letters?

> I want to visualize Geogrid and Balls separately. How can I achieve this?

What does "to visualize" mean? In Yade? In an external program (Paraview)? In export data? ...?
What does "separately" mean in this context?

Cheers
Jan

Revision history for this message
Yuri Bezmenov (yuribezmenov) said :
#3

Hi Jan,
1. By 'Geogrid' and 'Balls', I mean grid and sphere, respectively. I used capital letter just because of my habit, please ignore it.
2. When I use VTKRecorder, it exports all objects in the simulation, e.g. when I import spheres in Paraview they have spheres representing both spheres (soil in this case) and grid (geogrid in this case). Now I want to export spheres representing soil as different group and and balls representing gridpoint as different group so I can visualize the grid alone.
Hope this clarify my question.
Thanks

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

There are more options, mainly:
1) do real separate export e.g. using export.VTKExporter
2) do standard one-file export and do the separation in Paraview, e.g. using material if suitable. You always have mask attribute which can be used for this purpose, too

Cheers
Jan

Revision history for this message
Yuri Bezmenov (yuribezmenov) said :
#5

Hi Jan,
I modify the code to use VTKExporter but cannot visualize the force at each grid element. For interaction, I created two matrices, one has the ids of balls and the other with grid-connection to the ball id. In first case that is the matrix b, I an able to export interaction but they have constant value over the simulation. In second case, it shows an error "interaction does not exist".
Could you please help me out.
Thank You

MWE:
from builtins import range
from yade import pack, geom, plot, export
from yade.gridpfacet import *
rate=-0.5 #1.66e-4
compFricDegree=30
finalFricDegree = 40
stabilityThreshold = 0.1
young = 5e6
mn, mx = Vector3(0, 0, 0), Vector3(0.9, 0.6, 0.6)
O.engines = [
        ForceResetter(),
        InsertionSortCollider([
                Bo1_Sphere_Aabb(),
                Bo1_GridConnection_Aabb(),
  Bo1_Facet_Aabb(), Bo1_Wall_Aabb()
        ]),
        InteractionLoop(
                [ Ig2_Sphere_Sphere_ScGeom(),
   Ig2_Facet_Sphere_ScGeom(), Ig2_Wall_Sphere_ScGeom(),
                        Ig2_Sphere_GridConnection_ScGridCoGeom(),
                        Ig2_GridNode_GridNode_GridNodeGeom6D(),
                        Ig2_GridConnection_GridConnection_GridCoGridCoGeom()],
  [Ip2_CohFrictMat_CohFrictMat_CohFrictPhys(setCohesionNow=True, setCohesionOnNewContacts=True), Ip2_FrictMat_FrictMat_FrictPhys()],
  [Law2_ScGeom_FrictPhys_CundallStrack(), Law2_ScGridCoGeom_FrictPhys_CundallStrack(), Law2_GridCoGridCoGeom_FrictPhys_CundallStrack(),
  Law2_ScGeom6D_CohFrictPhys_CohesionMoment(),]
        ),
        GlobalStiffnessTimeStepper(timestepSafetyCoefficient=0.1, label='ts'),
        NewtonIntegrator(gravity=(0,-10,0), damping=.5, label='newton'),
 PyRunner(command='addPlotData()', iterPeriod=500),
 PyRunner(command='expo()', iterPeriod=500),
 VTKRecorder(fileName='/files/Geogrid/paraview/pullout', recorders=['all'], iterPeriod=500),
]
def addPlotData():
 plot.addData(
  unbalanced=unbalancedForce(),
  i=O.iter
 )
plot.plots = {
        'i':('unbalanced'),
}
plot.plot()
O.materials.append(FrictMat(young=young, poisson=0.5, frictionAngle=radians(compFricDegree), density=2600, label='spheres'))
O.materials.append(FrictMat(young=young, poisson=0.5, frictionAngle=0, density=0, label='walls'))
O.materials.append(CohFrictMat(young=1.325e8, poisson=0.40, density=900, frictionAngle=radians(10), normalCohesion=1.1e8, shearCohesion=1.1e8, momentRotationLaw=True, label='spheremat'))
L = 0.608 #length [m]
l = 0.304 #width [m]
nbL = 16+1 #number of nodes for the length [#]
nbl = 8+1 #number of nodes for the width [#]
r = 0.008/2 # L / 100. #radius
color = [255. / 255., 102. / 255., 0. / 255.]
nodesIds = []
for i in range(0, nbL):
 for j in range(0, nbl):
  nodesIds.append(O.bodies.append(gridNode([i*L/nbL, 0.3, 0.15+j*l/nbl], r, wire=False, fixed=False, material='spheremat', color=color)))
a=[]
b=[]
#Create connection between the nodes
for i in range(0, len(nodesIds)):
 for j in range(i + 1, len(nodesIds)):
  dist = (O.bodies[i].state.pos-O.bodies[j].state.pos).norm()
  if (dist <= (L/nbL)*1.05):
   O.bodies.append(gridConnection(i, j, r, color=color))
   a=a+[(i,O.bodies[-1].id), (O.bodies[-1].id,j)]
   b=b+[(i,j)]
O.bodies.append(geom.facetBox((.45, .5, .3), (.45, .5, .3), wallMask=55, material='walls'))
sp = pack.SpherePack()
sp.makeCloud((0, 0, 0), (0.9, 0.2, 0.6), rMean=.05, rRelFuzz=.3)
sp.makeCloud((0, 0.4, 0), (0.9, 0.6, 0.6), rMean=.05, rRelFuzz=.3)
O.bodies.append([sphere(center, rad, material='spheres') for center, rad in sp])
vtkExporter = export.VTKExporter('/files/Geogrid/paraview1/geogrid')
def expo():
 vtkExporter.exportSpheres(what=dict(dist='b.state.pos.norm()',pos='b.state.pos'), ids=range(0,433))
 vtkExporter.exportInteractions(what=dict(kn='i.phys.kn', kr='i.phys.kr', ks='i.phys.ks'), ids=b) ###Here I replace a and b
 # vtkExporter.exportContactPoints(what={'nn': 'i.geom.normal'})
 # vtkExporter.exportPolyhedra(what=dict(n='b.state.pos.norm()'), ids=plate.id)
O.run(10000,True)
for i in range (0,nbl):
 O.bodies[i].state.blockedDOFs='x'
 O.bodies[i].state.vel = (rate,0,0)
O.run(15000,True)

Revision history for this message
Yuri Bezmenov (yuribezmenov) said :
#6

Further I tried with mask option but it export all the bodies in simulation

MWE:

from builtins import range
from yade import pack, geom, plot, export
from yade.gridpfacet import *
rate=-0.5 #1.66e-4
compFricDegree=30
finalFricDegree = 40
stabilityThreshold = 0.1
young = 5e6
mn, mx = Vector3(0, 0, 0), Vector3(0.9, 0.6, 0.6)
O.engines = [
        ForceResetter(),
        InsertionSortCollider([
                Bo1_Sphere_Aabb(),
                Bo1_GridConnection_Aabb(),
  Bo1_Facet_Aabb(), Bo1_Wall_Aabb()
        ]),
        InteractionLoop(
                [ Ig2_Sphere_Sphere_ScGeom(),
   Ig2_Facet_Sphere_ScGeom(), Ig2_Wall_Sphere_ScGeom(),
                        Ig2_Sphere_GridConnection_ScGridCoGeom(),
                        Ig2_GridNode_GridNode_GridNodeGeom6D(),
                        Ig2_GridConnection_GridConnection_GridCoGridCoGeom()],
  [Ip2_CohFrictMat_CohFrictMat_CohFrictPhys(setCohesionNow=True, setCohesionOnNewContacts=True), Ip2_FrictMat_FrictMat_FrictPhys()],
  [Law2_ScGeom_FrictPhys_CundallStrack(), Law2_ScGridCoGeom_FrictPhys_CundallStrack(), Law2_GridCoGridCoGeom_FrictPhys_CundallStrack(),
  Law2_ScGeom6D_CohFrictPhys_CohesionMoment(),]
        ),
        GlobalStiffnessTimeStepper(timestepSafetyCoefficient=0.1, label='ts'),
        NewtonIntegrator(gravity=(0,-10,0), damping=.5, label='newton'),
 PyRunner(command='addPlotData()', iterPeriod=500),
 #PyRunner(command='expo()', iterPeriod=500),
 VTKRecorder(fileName='/files/Geogrid/paraview/pullout', recorders=['all'], iterPeriod=500, mask=10),
 VTKRecorder(fileName='/files/Geogrid/paraview1/pullout', recorders=['all'], iterPeriod=500, mask=11),

]
def addPlotData():
 plot.addData(
  unbalanced=unbalancedForce(),
  i=O.iter
 )
plot.plots = {
        'i':('unbalanced'),
}
plot.plot()
O.materials.append(FrictMat(young=young, poisson=0.5, frictionAngle=radians(compFricDegree), density=2600, label='spheres'))
O.materials.append(FrictMat(young=young, poisson=0.5, frictionAngle=0, density=0, label='walls'))
O.materials.append(CohFrictMat(young=1.325e8, poisson=0.40, density=900, frictionAngle=radians(10), normalCohesion=1.1e8, shearCohesion=1.1e8, momentRotationLaw=True, label='spheremat'))
L = 0.608 #length [m]
l = 0.304 #width [m]
nbL = 16+1 #number of nodes for the length [#]
nbl = 8+1 #number of nodes for the width [#]
r = 0.008/2 # L / 100. #radius
color = [255. / 255., 102. / 255., 0. / 255.]
nodesIds = []
for i in range(0, nbL):
 for j in range(0, nbl):
  nodesIds.append(O.bodies.append(gridNode([i*L/nbL, 0.3, 0.15+j*l/nbl], r, wire=False, fixed=False, material='spheremat', color=color)))
a=[]
b=[]
#Create connection between the nodes
for i in range(0, len(nodesIds)):
 for j in range(i + 1, len(nodesIds)):
  dist = (O.bodies[i].state.pos-O.bodies[j].state.pos).norm()
  if (dist <= (L/nbL)*1.05):
   O.bodies.append(gridConnection(i, j, r, color=color))
   a=a+[(i,O.bodies[-1].id), (O.bodies[-1].id,j)]
   b=b+[(i,j)]
O.bodies.append(geom.facetBox((.45, .5, .3), (.45, .5, .3), wallMask=55, material='walls'))
sp = pack.SpherePack()
sp.makeCloud((0, 0, 0), (0.9, 0.2, 0.6), rMean=.05, rRelFuzz=.3)
sp.makeCloud((0, 0.4, 0), (0.9, 0.6, 0.6), rMean=.05, rRelFuzz=.3)
O.bodies.append([sphere(center, rad, material='spheres') for center, rad in sp])
for b in O.bodies:
 if b.id<153:
  b.groupMask=10
 else:
  if b.id<433:
   b.groupMask=11
  else:
   b.groupMask=12

#vtkExporter = export.VTKExporter('/home/harshal/files/Geogrid/paraview1/geogrid')
#def expo():
 #vtkExporter.exportSpheres(what=dict(dist='b.state.pos.norm()',pos='b.state.pos'), ids=range(0,433))
 #vtkExporter.exportInteractions(what=dict(kn='i.phys.kn', kr='i.phys.kr', ks='i.phys.ks'), ids=b) ###Here I replace a and b
 # vtkExporter.exportContactPoints(what={'nn': 'i.geom.normal'})
 # vtkExporter.exportPolyhedra(what=dict(n='b.state.pos.norm()'), ids=plate.id)
O.run(10000,True)
for i in range (0,nbl):
 O.bodies[i].state.blockedDOFs='x'
 O.bodies[i].state.vel = (rate,0,0)
O.run(15000,True)

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

> cannot visualize the force
> I an able to export interaction but they have constant value over the simulation.

kn, kr and ks are supposed to be constant.
Did you mean i.phys.normalForce and/or similar?

> In second case, it shows an error "interaction does not exist".

I am not a user of grid stuff, so I cannot help much here..
instead of O.run(...,True), just run O.step(), investigate "a" list and try to determine what is the problem.

> Further I tried with mask option but it export all the bodies in simulation

Originally I meant to export a "mask" attribute and use some Paraview filter to only display particles with specific mask.

But it turns that you can use mask to split the export:
###
O.bodies.append([
    sphere((0,0,0),1,mask=-1), # 0b111
    sphere((2,0,0),1,mask=2), # 0b010
    sphere((0,2,0),1,mask=3), # 0b011
    sphere((2,2,0),1,mask=4), # 0b100
])
O.engines = [
    VTKRecorder(fileName="test1",iterPeriod=1,recorders=["spheres"],mask=0), # all particles
    VTKRecorder(fileName="test2",iterPeriod=1,recorders=["spheres"],mask=2), # 0b010, first 3 particles
]
O.step()
###

note that the condition for mask to be exported is not
bodyMask == vtkMask
but
bodyMask & vtkMask != 0
so you have to setup it more carefully (not randomly trying 10 (0b1010), 11 (0b1011), 12 (0b1100), which all have 0b1000 bit in common)

Cheers
Jan

Revision history for this message
Yuri Bezmenov (yuribezmenov) said :
#8

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