How to excute the VTKRecorder at virtual time

Asked by mikexue

Hello,
I see there is "realPeriod" that I can use to define the real time period calling the VTKRecorder.
However, I want to start to call the VTKRecorder at a specific virtual time in the simulation instead of "firstIterRun" and deactivated it after several virtual time Period. How can I manage to do that?
Besides, am I getting it right that If I want to call the VTKRecorder at a specific virutal time , I should set the initRun =true?

I appreciate your help.

Best.
Mikexue

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
mikexue (mikexue) said :
#1

Going through the documentation, I understand I can set the "virtPeriod” and the “nDo” to achieve control of the period and the exact number of times.
But I can't find a way to set the specific virtual time to call the vtkrecorder.
Did I miss something?

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

Hello,

> realPeriod
> virtPeriod

the third is iterPeriod, just to make it complete

> If I want to call the VTKRecorder at a specific virutal time , I should set the initRun =true?

no.
initRun determines what to do if time=0, call the engine or not?

> How can I manage to do that?

See MWE below. Replace "thatEngine" by your VTKRecorder.
###
O.engines = [
    PyRunner(virtPeriod=20,command="startThatEngine()",label="thisEngine"),
    PyRunner(dead=True,virtPeriod=3,nDo=5,command="print(O.time)",label="thatEngine"),
]

def startThatEngine():
    thisEngine.dead = True
    thatEngine.dead = False

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

Cheers
Jan

Revision history for this message
mikexue (mikexue) said (last edit ):
#3

Hi,Jan
Thanks! Your code works just fine!
I am just curious why my code didn't work although it's poorly written. I get nothing from the following code with no mistake reported either.
###
O.engines = [
    PyRunner(command='record_vrk()',virtPeriod=1,nDo = 2),#call "record_vtk"at O.time=20 for only once
]

def record_vrk():
    VTKRecorder(fileName='3d-vtk-',recorders=['all','bstresses'],virtPeriod = 3,nDo = 5)

Best,
Mikexue

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

> VTKRecorder(fileName='3d-vtk-',recorders=['all','bstresses'],virtPeriod = 3,nDo = 5)

this creates VTKRecorder engine.
Just create, it does not any output:
- it is not called
- it is not included in O.engines

Below are two possible approaches (rewritten to iterPeriod, but it would be same with virtPeriod or realPeriod)

##################################
# MWE1, VTKRecorder inside O.engines
b = sphere((0,0,0),1)
b.state.vel = (1,0,0)
O.bodies.append(b)

O.engines += [
    PyRunner(iterPeriod=20,command="enableVtk()",label="enabler"),
    VTKRecorder(dead=True,fileName="test2",iterPeriod=3,nDo=5,label="vtk"),
]

def enableVtk():
    enabler.dead = True
    vtk.dead = False

O.run(100,True)
##################################

##################################
# MWE2, VTKRecorder called
b = sphere((0,0,0),1)
b.state.vel = (1,0,0)
O.bodies.append(b)

vtk = VTKRecorder(fileName="test1")
# vtk() , calling the instance, does the export, not just creating VTKRecorder(...)

O.engines += [
    PyRunner(iterPeriod=20,command="enableVtk()",label="enabler"),
    PyRunner(dead=True,iterPeriod=3,nDo=5,command="vtk()",label="vtkCaller"),
]

def enableVtk():
    enabler.dead = True
    vtkCaller.dead = False

O.run(100,True)
##################################

Cheers
Jan

Revision history for this message
mikexue (mikexue) said :
#5

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