manipulate the spheres during running

Asked by gaoxuesong on 2018-12-27

I want to get the information of some specific spheres during the calculation when it meets some condition, like the time larger than some point. i have used two run mode of yade, one is just normal mode, the other is batch mode.

The flowchart of my code is that,

### to invode getDemandbody to get what i want
def getDandBody():

    # input a box
        vboxMin = (2.1,0.1,0.72)
        vboxMax = (2.9,0.9,0.98)
        vPorosity = utils.voxelPorosity(resolution=400, start=vboxMin, end=vboxMax)

    # use the box the select the spheres and erase outside spheres
        for eb in O.bodies:
            if not isinstance(eb.shape, Sphere):
                continue
            if not (vboxMin[0]<= eb.state.pos[0]<= vboxMax[0] and vboxMin[1]<= eb.state.pos[1] <= vboxMax[1] and vboxMin[2] <=
            eb.state.pos[2] <= vboxMax[2]):
                O.bodies.erase(eb.id)

    # output the information
       with open('rel.txt', 'w') as fd:
            fd.write('%e %e\n' % (sthrd, lthrd))
            fd.write('%.4f, %d, %d, %.2f\n' % (1-vPorosity, snum, inum, inum*1.0/snum))
           O.pause()

#define the new thread to load saved file
def newThread():
    if O.time > 3.6:
        import thread
        thread.start_new_thread(newRun,())

def newRun():
    O.pause();O.wait()

    ### import saved state
    O.load('./svdir/t3-3.5')

    ### new engines and new run
   ### the function of getDemandBody is what i need to run to get sphere information
    O.engines = [
            PyRunner(iterPeriod=1,command='getDemandBody()'),
            ]
    O.run(1)

### the save file function
def svfun():
    some expressions

#define engines:
O.engines=[
 ForceResetter(),
 InsertionSortCollider([Bo1_Sphere_Aabb(),Bo1_Facet_Aabb()]),
 InteractionLoop(
       # handle sphere+sphere and facet+sphere collisions
         [Ig2_Sphere_Sphere_ScGeom6D(),Ig2_Facet_Sphere_ScGeom6D()],
         [Ip2_CohFrictMat_CohFrictMat_CohFrictPhys()],
          [Law2_ScGeom6D_CohFrictPhys_CohesionMoment()]
    ),
       PyRunner(iterPeriod=100,command='svfun()'),
       PyRunner(iterPeriod=100,command='newThread()'),
       NewtonIntegrator(damping=0.75, exactAsphericalRot=True, gravity=(0,0,-9810*gcof)),

]

O.run()

### script finished #####

I have two problems,
1. when i use the normal mode, like the command, yade myscript.py, it works. I can get the information of the selected spheres. But i want to ask, using a new thread is a must? In fact, i don't want to load saved file, just the current state is also ok.
2. when i use the yade-batch mode, it doesn't work. There is no output file. So i doubt there is a problem when create a new thread in batch mode.

So any suggestions?

Thanks,
Xuesong

Question information

Language:
English Edit question
Status:
Answered
For:
Yade Edit question
Assignee:
No assignee Edit question
Last query:
2018-12-27
Last reply:
2018-12-28
gaoxuesong (260582472-9) said : #1

I have just found that just put the functional code into a function runned by pyRunner, it works well in yade-batch mode. So my question becomes that if it is not allowed to create a new thread to load yade saved state in batch mode?

Chareyre (bruno-chareyre-9) said : #2

Hi, if I read correctly you have two threads trying to run the same
simulation. I would expect this to fail always although i can imagine that
in some cases the problem remains unnoticed.
What are you trying to achieve? There could be simpler ways.
Bruno

Le 27 déc. 2018 18:13, "gaoxuesong" <email address hidden>
a écrit :

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

gaoxuesong gave more information on the question:
I have just found that just put the functional code into a function
runned by pyRunner, it works well in yade-batch mode. So my question
becomes that if it is not allowed to create a new thread to load yade
saved state in batch mode?

--
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 address hidden>
Unsubscribe : https://launchpad.net/~yade-users
More help : https://help.launchpad.net/ListHelp

gaoxuesong (260582472-9) said : #3

Hi. The thing i want is with the yade-batch mode, when i finish 5000 iters, i want to reload some previous state which has been saved before. So the procedure should be like this,
    create a new thread, invoke a new function, and execute the O.load() demand.

def newThread():
    if O.time > 3.6:
        import thread
        thread.start_new_thread(newRun,())

def newRun():
    O.pause();O.wait()
    O.load('./svdir/t3-3.5')

I find this method is ok in usual mode of yade, but failed in batch mode.

Chareyre (bruno-chareyre-9) said : #4

Batch is already multithread, by definition. It thus seems you are nesting
threads into threads.
Still unclear what you are trying to achieve. It should be enough to load()
then run(). No need for python's threading module.

As for why it seems to work in normal mode... it's just puzzling me.
Bruno

Le ven. 28 déc. 2018 00:27, gaoxuesong <email address hidden>
a écrit :

> Question #677084 on Yade changed:
> https://answers.launchpad.net/yade/+question/677084
>
> Status: Answered => Open
>
> gaoxuesong is still having a problem:
> Hi. The thing i want is with the yade-batch mode, when i finish 5000
> iters, i want to reload some previous state which has been saved before. So
> the procedure should be like this,
> create a new thread, invoke a new function, and execute the O.load()
> demand.
>
> def newThread():
> if O.time > 3.6:
> import thread
> thread.start_new_thread(newRun,())
>
> def newRun():
> O.pause();O.wait()
> O.load('./svdir/t3-3.5')
>
> I find this method is ok in usual mode of yade, but failed in batch
> mode.
>
> --
> 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 address hidden>
> Unsubscribe : https://launchpad.net/~yade-users
> More help : https://help.launchpad.net/ListHelp
> e.

Can you help with this problem?

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

To post a message you must log in.