Why VTKExporter does not work?

Asked by Mahdeyeh

I load a saved file of simulation and after loading it, I import every function in original script. every thing is good but it does n`t export VTK.

When I run main script (not saved file) , all things are ok and data export to VTK . Here is its code:

"
from yade import export,polyhedra_utils
import os
from yade import plot
import math
from yade import utils
import pylab
import matplotlib; matplotlib.rc('axes',grid=True)
from matplotlib import pyplot
from yade import qt
import numpy as np
from numpy import *
from yade import export as expt
.
.
.

os.mkdir(O.tags['id'])

ClumpVtkData = expt.VTKExporter(O.tags['id']+'/'+'clumpData')
def VTKview():
    for b in O.bodies:
        ClumpVtkData.exportSpheres(ids='all', what={('color','b.shape.color')})
        ClumpVtkData.exportFacets(ids='all', what={('color','b.shape.color')})

O.engines=O.engines+[PyRunner(iterPeriod=70000,command='VTKview()',label="VTKview")]
"

But now in saved file, I could n`t export any vtk file. (I import all codes above in terminal after loading saved file, but something is wrong .)
When I type VTKview() in terminal (when saved file of simulation is running), it says:

"global name 'ClumpVtkData' is not defined"

Please help me.

Best regards,

ubuntu : 18.04
yade 2018.02b

Question information

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

Hello,

> I load a saved file of simulation

What does "load" mean?
What does "saved" mean?
What does "file" mean?

> I import every function in original script

Please provide the code.
in original script? from original script?

> But now in saved file, I could n`t export any vtk file.

what does "in saved file mean"?

> I import every function
> I import all codes above in terminal

every function? all code?
Please be consistent

> "global name 'ClumpVtkData' is not defined"

should be self-explanatory. Did you import ClumpVtkData?

The description is a bit vague and ambiguous.
Please provide a complete MWE [1] with detailed info how you execute the code (e.g. this I run with 'yade script.py', this I copy-paste line-by-line in the Yade terminal, ...).

Cheers
Jan

[1] https://www.yade-dem.org/wiki/Howtoask

Revision history for this message
Mahdeyeh (mahdiye.sky) said :
#2

Hi Jan
I apologize for always explaining badly!

> What does "saved" mean?
 I ran a script with 'yade test.py', (in this script, VTK exported and everything was ok). I have saved simulation in iteration 2591000 with command = O.save('iter2591000.bz2')
Then for some reason first simulation stopped.

so :
> What does "load" mean?
I used saved file (iter2591000.bz2) and load it with command = O.load('iter2591000.bz2')
to continue the simulation.

> What does "file" mean?
'iter2591000.bz2'

> in original script? from original script?
from original script.

> what does "in saved file mean"?
When I load the scene ('iter2591000.bz2') later and resume the simulation.

 > Please be consistent
 After resume simulation with ( O.load), I import again lines below in terminal:

from yade import export,polyhedra_utils
import os
from yade import plot
import math
from yade import utils
import pylab
import matplotlib; matplotlib.rc('axes',grid=True)
from matplotlib import pyplot
from yade import qt
import numpy as np
from numpy import *
from yade import export as expt

os.mkdir(O.tags['id'])

ClumpVtkData = expt.VTKExporter(O.tags['id']+'/'+'clumpData')
def VTKview():
    for b in O.bodies:
        ClumpVtkData.exportSpheres(ids='all', what={('color','b.shape.color')})
        ClumpVtkData.exportFacets(ids='all', what={('color','b.shape.color')})

O.engines=O.engines+[PyRunner(iterPeriod=70000,command='VTKview()',label="VTKview")]

> should be self-explanatory. Did you import ClumpVtkData?
yes, as I wrote above with :
ClumpVtkData = expt.VTKExporter(O.tags['id']+'/'+'clumpData')

> The description is a bit vague and ambiguous.
I really sorry.

Best regards,
Mahdeyeh

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

Thanks for clarification

> in terminal

why not in a script? Terminal itself has its own "gotchas"..

a complete example is still missing, please provide actual code (MWE).
Before, please make it minimal (M=minimal in MWE). E.g. most of the imports is unrelated to the problem.

Also a note:
> for b in O.bodies:
> ClumpVtkData.exportSpheres(ids='all', what={('color','b.shape.color')})
does not make sense, you do not want to export all spheres for b in O.bodies, do it just once (otherwise you export the same file again and again for all bodies)
The result is OK, just the export is executed not-necessarily

Cheers
Jan

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

I just have tried what you described (both with script and terminal) and could not reproduce the problem..

### script 1
from yade import export
O.bodies.append(sphere((0,0,0),1))
vtk = yade.export.VTKExporter("test")
def doVtk():
    vtk.exportSpheres()
O.engines = [PyRunner(iterPeriod=1,command="doVtk()")]
O.step()
print(len(O.bodies))
O.save("test.bz2")
###

### script 2
O.load("test.bz2")
print(O.iter)
print(len(O.bodies))
from yade import export
vtk = yade.export.VTKExporter("test")
def doVtk():
    vtk.exportSpheres()
O.engines = [PyRunner(iterPeriod=1,command="doVtk()")]
O.step()
###

Cheers
Jan

Revision history for this message
Karol Brzezinski (kbrzezinski) said :
#5

Hi All,

I think that the problem occurs because Mahdeyeh defines the function in the 'live' Yade console. The best way to restore simulation is by script as Jan did. 'Copy-paste' approach may work but one line needs to be added at the end of the pasted code:
globals().update(locals())

Best wishes,
Karol

Revision history for this message
Mahdeyeh (mahdiye.sky) said :
#6

Thank you Jan and Karol, both of you said true!
My mistake was defining the function in the 'live' Yade console.
When I use 'Copy-paste' approach to restore simulation, everything goes normal and ok.

You guys are the best.

Best regards,
Mahdeyeh

Revision history for this message
Mahdeyeh (mahdiye.sky) said :
#7