Question #698152 on Yade changed:
https://answers.launchpad.net/yade/+question/698152

Olivier Gillia posted a new comment:
>>> Solution proposed by Jan Stránský <<<

Hello Olivier,
 
next time, please ask questions via launchpad interface [1].
 
By default, O.save only saves attributes of C++ core. It does not save 
python-defined stuff (functions, variables), nor custom O.anythingNotCPlusPlus.
However, see documentation of utils.saveVars [2] / utils.loadVars [3]. They 
allow you to save custom data in the .xml file and use it after O.load,. 
Something like:
 
###
resume = False # change to Ture for the "resume" run

someVar = 1 # default value, overwritten below

def incrementSomeVar():
    global someVar
    someVar += 1

O.engines += [
    PyRunner(iterPeriod=1,command="incrementSomeVar()"),
    PyRunner(iterPeriod=10,command="save()"),
]

def save():
    saveVars("mySavedVars",someVar=someVar)
    O.save("test.xml")

if resume:
    O.load("test.xml")
    loadVars("mySavedVars")
else:
    saveVars("mySavedVars",someVar=someVar)
from yade.params.mySavedVars import *

print("TEST 1:",O.iter,someVar)
O.run(25,True) # simulating interruption
print("TEST 2:",O.iter,someVar)
###
 
Cheers
Jan
 
[1] https://launchpad.nt/yade, "Ask a question" button
[2] https://yade-dem.org/doc/yade.utils.html#yade.utils.saveVars
[3] https://yade-dem.org/doc/yade.utils.html#yade.utils.loadVars

-- 
You received this question notification because your team yade-users is
an answer contact for Yade.

_______________________________________________
Mailing list: https://launchpad.net/~yade-users
Post to     : [email protected]
Unsubscribe : https://launchpad.net/~yade-users
More help   : https://help.launchpad.net/ListHelp

Reply via email to