← Back to team overview

yade-users team mailing list archive

Re: [Question #707137]: Resetting and starting simulations from the beginning

 

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

    Status: Open => Answered

Jan Stránský proposed the following answer:
Hello,

> run simulations like batch mode but without using the actual batch
mode

Batch mode is exactly for this purposes.
If you know the values in advance, it should be the preferred method.
If you need to change the values dynamically, then some custom solution is maybe better (also a "glue" python script could be created, creating tables, running yade-batch and evaluating results).

> My problem is that the simulation won't reload and won't start
automatically again

See [1] for some information.
You cannot do "simply" these kind of operations from within O.engines

> I have tried O.loadTmp() instead of O.reload() but had no success.

Please be specific, what / how you have tried.


If you want to change some parameters, depending on actual use case, probably O.saveTmp / O.loadTmp is not the way to go, as the original value is probably already saved and it is better to create the simulation from the scratch.

A few possible approaches:

1)
### using O.saveTmp, O.loadTml and thread as in [1]
O.bodies.append(sphere(center=(0,0,0),radius=1))
O.engines = [
        ForceResetter(),
        InsertionSortCollider([Bo1_Sphere_Aabb()]),
        InteractionLoop(
                [Ig2_Sphere_Sphere_ScGeom()],
                [Ip2_FrictMat_FrictMat_FrictPhys()],
                [Law2_ScGeom_FrictPhys_CundallStrack()]
        ),
        NewtonIntegrator(),
        PyRunner(command='stop()',virtPeriod=10)
]
O.saveTmp()

def restart(dt=1):
    O.loadTmp()
    O.dt = dt
    O.run()
    
index=0
def stop():
   global index
   index = index + 1
   print(f"{index}. run, dt={O.dt}")
   O.pause()
   if index > 10:
       return
   import _thread
   _thread.start_new_thread(restart, (O.dt+1,))

restart()
###


2)
### "from scratch" each time
index=0
params = {
    "dt": 1,
}

def stop():
   global index
   index = index + 1
   O.pause()
   print(f"{index}. run, dt={O.dt}")
   params["dt"] = index + 1

def simulation():
    O.bodies.append(sphere(center=(0,0,0),radius=1))
    O.engines = [
            ForceResetter(),
            InsertionSortCollider([Bo1_Sphere_Aabb()]),
            InteractionLoop(
                    [Ig2_Sphere_Sphere_ScGeom()],
                    [Ip2_FrictMat_FrictMat_FrictPhys()],
                    [Law2_ScGeom_FrictPhys_CundallStrack()]
            ),
            NewtonIntegrator(),
            PyRunner(command='stop()',virtPeriod=10)
    ]
    O.saveTmp()
    O.dt = params["dt"]
    O.run()
    O.wait()

while index < 10:
    dt = index + 1
    simulation()
###

Surely there are more options and/or combinations of them

Cheers
Jan

[1] https://yade-dem.org/doc/user.html#checkpoints

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