Export wall for Paraview

Asked by Amrisha Khandelwal

i ran the oedometer tutorial in yade. I want to visualise it in paraview so i use VTKRecorder to export all the parameters. but there is no vtk/vtp file generated for wall element (plate is used as a wall). Please help me how to export wall to visulaise in paraview. Here the script i modified:

readParamsFromTable(rMean=.05, rRelFuzz=.3, maxLoad=1e6, minLoad=1e4)
# make rMean, rRelFuzz, maxLoad accessible directly as variables later
from yade.params.table import *

# create box with free top, and ceate loose packing inside the box
from yade import pack, plot, qtv
O.bodies.append(geom.facetBox((.5, .5, .5), (.5, .5, .5), wallMask=31))
sp = pack.SpherePack()
sp.makeCloud((0, 0, 0), (1, 1, 1), rMean=rMean, rRelFuzz=rRelFuzz)
sp.toSimulation()

O.engines = [
        ForceResetter(),
        # sphere, facet, wall
        InsertionSortCollider([Bo1_Sphere_Aabb(), Bo1_Facet_Aabb(), Bo1_Wall_Aabb()]),
        InteractionLoop(
                # the loading plate is a wall, we need to handle sphere+sphere, sphere+facet, sphere+wall
                [Ig2_Sphere_Sphere_ScGeom(), Ig2_Facet_Sphere_ScGeom(), Ig2_Wall_Sphere_ScGeom()],
                [Ip2_FrictMat_FrictMat_FrictPhys()],
                [Law2_ScGeom_FrictPhys_CundallStrack()]
        ),
        NewtonIntegrator(gravity=(0, 0, -9.81), damping=0.5),
        # the label creates an automatic variable referring to this engine
        # we use it below to change its attributes from the functions called
        PyRunner(command='checkUnbalanced()', realPeriod=2, label='checker'),
        # save data for Paraview
        VTKRecorder(fileName='3d-vtk-', recorders=['all'], iterPeriod=1000),
]
O.dt = .5 * PWaveTimeStep()
qt.View()
# the following checkUnbalanced, unloadPlate and stopUnloading functions are all called by the 'checker'
# (the last engine) one after another; this sequence defines progression of different stages of the
# simulation, as each of the functions, when the condition is satisfied, updates 'checker' to call
# the next function when it is run from within the simulation next time

# check whether the gravity deposition has already finished
# if so, add wall on the top of the packing and start the oedometric test
def checkUnbalanced():
 # at the very start, unbalanced force can be low as there is only few contacts, but it does not mean the packing is stable
 if O.iter < 5000:
  return
 # the rest will be run only if unbalanced is < .1 (stabilized packing)
 if unbalancedForce() > .1:
  return
 # add plate at the position on the top of the packing
 # the maximum finds the z-coordinate of the top of the topmost particle
 O.bodies.append(wall(max([b.state.pos[2] + b.shape.radius for b in O.bodies if isinstance(b.shape, Sphere)]), axis=2, sense=-1))
 global plate # without this line, the plate variable would only exist inside this function
 plate = O.bodies[-1] # the last particles is the plate
 # Wall objects are "fixed" by default, i.e. not subject to forces
 # prescribing a velocity will therefore make it move at constant velocity (downwards)
 plate.state.vel = (0, 0, -.1)
 # start plotting the data now, it was not interesting before
 O.engines = O.engines + [PyRunner(command='addPlotData()', iterPeriod=200)]
 # next time, do not call this function anymore, but the next one (unloadPlate) instead
 checker.command = 'unloadPlate()'

def unloadPlate():
 # if the force on plate exceeds maximum load, start unloading
 if abs(O.forces.f(plate.id)[2]) > maxLoad:
  plate.state.vel *= -1
  # next time, do not call this function anymore, but the next one (stopUnloading) instead
  checker.command = 'stopUnloading()'

def stopUnloading():
 if abs(O.forces.f(plate.id)[2]) < minLoad:
  # O.tags can be used to retrieve unique identifiers of the simulation
  # if running in batch, subsequent simulation would overwrite each other's output files otherwise
  # d (or description) is simulation description (composed of parameter values)
  # while the id is composed of time and process number
  plot.saveDataTxt(O.tags['d.id'] + '.txt')
  O.pause()

def addPlotData():
 if not isinstance(O.bodies[-1].shape, Wall):
  plot.addData()
  return
 Fz = O.forces.f(plate.id)[2]
 plot.addData(Fz=Fz, w=plate.state.pos[2] - plate.state.refPos[2], unbalanced=unbalancedForce(), i=O.iter)

# besides unbalanced force evolution, also plot the displacement-force diagram
plot.plots = {'i': ('unbalanced',), 'w': ('Fz',)}
plot.plot()

O.saveTmp()
Thanks in advance

Question information

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

Hello,

the problem is visualization of the infinite object :-) and its automation (what should be the shape? what size? ...?).
For every situation the proper visualization may be different.

As a workaround, you can export wall data to a CSV file, load it in paraview, "filter" it a bit and get whatever you want.
For example circles:

### yade scriptw1,w2,w3 = [wall((0,0,0),axis=i) for i in (0,1,2)]
walls = [w1,w2,w3]
O.bodies.append(walls)
w1.state.vel = (1,0,0)
w2.state.vel = (0,2,0)
w3.state.vel = (0,0,3)

O.engines = [
    PyRunner(iterPeriod=1,initRun=True,command="exportWalls()"),
    NewtonIntegrator(),
]

def exportWalls():
    with open(f"wall-{O.iter:06d}.csv","w") as f:
        f.write("x,y,z,nx,ny,nz\n")
        for w in walls:
            x,y,z = w.state.pos
            n = [0,0,0]
            n[w.shape.axis] = 1
            nx,ny,nz = n
            f.write(f"{x},{y},{z},{nx},{ny},{nz}\n")

O.dt = 1
O.run(5,True)
###

And then in Paraview for example:
- open the wall-....csv files, use CSV Reader if you have to choose, Apply
- Filters -> Table To Points, select x,y,z as X, Y, Z columns, Apply
- Calculator (make nz,ny,nz to one vector):
    - Result: normal
    - formula: iHat*nx+jHat*ny+kHat*nz
    - Apply
- Glyph -> Box:
    - Z Length: 0
    - Scale Factor: what you need, e.g. 5
    - Glyph Mode: All Points
    - Apply

Cheers
Jan

Can you help with this problem?

Provide an answer of your own, or ask Amrisha Khandelwal for more information if necessary.

To post a message you must log in.