launch several simulations within one script

Asked by ceguo

Hi Yade developers/users,

I want to conduct several simulations simultaneously and have to coordinate them under the framework of multiscale modeling. So each packing plays as a representative volume element, the boundary condition of which is imposed by a macro-calculation. How to launch this multi-simulation? Can I have multiple scenes and use O[0], O[1], O[2] ...?

Ning

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
Jan Stránský (honzik) said :
#1

Hi Ning,

one solution would be to use completely separate simulations for each RVE,
so to run several independent Yade sessions..

Jan

2011/10/31 ceguo <email address hidden>

> New question #176993 on Yade:
> https://answers.launchpad.net/yade/+question/176993
>
> Hi Yade developers/users,
>
> I want to conduct several simulations simultaneously and have to
> coordinate them under the framework of multiscale modeling. So each packing
> plays as a representative volume element, the boundary condition of which
> is imposed by a macro-calculation. How to launch this multi-simulation? Can
> I have multiple scenes and use O[0], O[1], O[2] ...?
>
> Ning
>
> --
> You received this question notification because you are a member of
> yade-users, which 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
>

Revision history for this message
ceguo (hhh-guo) said :
#2

Thanks Jan,

Yes each independent Yade simulation accounts for one RVE. Then how to coordinate these sessions, I mean assigning boundary conditions to them from the MASTER session? These boundary conditions are different for each RVE and are changing during the simulation.

Ning

Revision history for this message
Bruno Chareyre (bruno-chareyre) said :
#3

You could also use the saveTmp function to keep many scenes in memory.
https://yade-dem.org/doc/yade.wrapper.html?highlight=savetmp#yade.wrapper.Omega.saveTmp
Not sure what is the most convenient in your problem.

Revision history for this message
ceguo (hhh-guo) said :
#4

Hi Chareyre,

In my simulation, I have several simultaneously ongoing tests which pass responses to the master (a FEM code actually). And the master will determine the next loading on each test (imposing different boundary conditions). So I have to launch several tests. I don't know how to do this within one script (or write each test in each script and make all the tests callable by one script).

For saveTmp, I think it can save scenes at different stages for one test. Actually I need this capability because my loading on each test is in a trial-and-error way. I've to adjust the loading according to the equilibrium condition determined by the master. Anyway this is another question.

Ning

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

Hi Ning,

you can use only one script and launch it several time by several Yade
sessions, this should not be a problem. As I understand it, the problem is
how to pass boundary conditions from external (FEM) computation into
specific Yade session, right? I dont know the answer, but if you work it
out, let us know (or at least me, because I will face this problem durin
gmy phd thesis :-).

Is there a way to control python script externally, e.g. from another
python script? something like pipes?

Thanks
Jan

2011/11/1 ceguo <email address hidden>

> Question #176993 on Yade changed:
> https://answers.launchpad.net/yade/+question/176993
>
> Status: Answered => Open
>
> ceguo is still having a problem:
> Hi Chareyre,
>
> In my simulation, I have several simultaneously ongoing tests which pass
> responses to the master (a FEM code actually). And the master will
> determine the next loading on each test (imposing different boundary
> conditions). So I have to launch several tests. I don't know how to do
> this within one script (or write each test in each script and make all
> the tests callable by one script).
>
> For saveTmp, I think it can save scenes at different stages for one
> test. Actually I need this capability because my loading on each test is
> in a trial-and-error way. I've to adjust the loading according to the
> equilibrium condition determined by the master. Anyway this is another
> question.
>
> Ning
>
> --
> You received this question notification because you are a member of
> yade-users, which 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
>

Revision history for this message
Anton Gladky (gladky-anton) said :
#6

Just a guess.

You can read a file with data from the script.
This file can be written (created) by external program, where can be
your values.
Then you can apply those values.

Anton

Revision history for this message
ceguo (hhh-guo) said :
#7

Well now I can pass info between YADE and another FEM code using Python script. But I can only handle one DEM packing now while I need a lot more (100 maybe). Since the simulation is highly computationally consuming, it is not affordable to communicate through hard disk writing-and-reading. I think through python by calling functions is OK. The question is just how to add more DEM simulations within one script. (Although these DEM simulations are independent, they contribute to ONE simulation overall.)

Ning

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

Very nice and very simple solution indeed :-)

just out of curiosity, is there a way of combining different python scripts
directly in memory, i.e. without time spent on writing and reading files?

Jan

2011/11/1 Anton Gladky <email address hidden>

> Question #176993 on Yade changed:
> https://answers.launchpad.net/yade/+question/176993
>
> Anton Gladky proposed the following answer:
> Just a guess.
>
> You can read a file with data from the script.
> This file can be written (created) by external program, where can be
> your values.
> Then you can apply those values.
>
> Anton
>
> --
> You received this question notification because you are a member of
> yade-users, which 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
>

Revision history for this message
ceguo (hhh-guo) said :
#9

Hi Jan,

You can directly pass info in memory between two codes through python as long as they are both wrapped with python. Now I found two such FEM codes are compatible with YADE: GetFEM++ and Escript/Finley.

Ning

Revision history for this message
Anton Gladky (gladky-anton) said :
#10
Revision history for this message
Václav Šmilauer (eudoxos) said :
#11

Have a look at O.switchScene(), that's what you need.

Revision history for this message
ceguo (hhh-guo) said :
#12

Hi,

I still need an answer in this question. I've wrapped a class for simulation as below:

import `everything`

class simDEM(object):
   def __init__(self,sd=1):
      self.__id='thread'+str(sd)
      self.__O=Omega()
      self.__O.materials.append(FrictMat(young=1.e8,poisson=.3,frictionAngle=.5,density=1000))
      self.__sp=pack.SpherePack()
      self.__sp.makeCloud(minCorner=(0,0,0),maxCorner=(3,3,0),rMean=.03,rRelFuzz=.25,periodic=True,seed=sd)
      self.__sp.toSimulation()
      self.__O.cell.hSize=Matrix3(3,0,0, 0,3,0, 0,0,1)
      for p in self.__O.bodies:
         p.state.blockedDOFs='zXY'
      self.__O.dt=.5*utils.PWaveTimeStep()

   def countParticle(self):
      return len(self.__O.bodies)

   def getThreadID(self):
      return self.__id

   def consolidate(self, stress=(-5.e4,-5.e4,0,0,0,0)):
      self.__O.engines=[
         ForceResetter(),
         InsertionSortCollider([Bo1_Sphere_Aabb()]),
         InteractionLoop(
            [Ig2_Sphere_Sphere_Dem3DofGeom()],
            [Ip2_FrictMat_FrictMat_FrictPhys()],
            [Law2_Dem3DofGeom_FrictPhys_CundallStrack()]
         ),
         Peri3dController(
            goal=stress,
            stressMask=3,
            nSteps=20000,
            maxStrain=.5,
            label='cons'
         ),
         NewtonIntegrator()
      ]
      self.__O.run()
      self.__O.wait()

   def shear(self, strain=(1.e-2,-1.e-2,0,0,0,0)):
      import __builtin__
      __builtin__.__dict__['saveAddData']=self.saveAddData
      self.__O.engines=[
         ForceResetter(),
         InsertionSortCollider([Bo1_Sphere_Aabb()]),
         InteractionLoop(
            [Ig2_Sphere_Sphere_Dem3DofGeom()],
            [Ip2_FrictMat_FrictMat_FrictPhys()],
            [Law2_Dem3DofGeom_FrictPhys_CundallStrack()]
         ),
         Peri3dController(
            goal=strain,
            stressMask=0,
            nSteps=10000,
            maxStrain=.5,
            label='biax'
         ),
         NewtonIntegrator(),
         PyRunner(command='saveAddData()',iterPeriod=100)
      ]
      self.__O.run()
      self.__O.wait()

   def getStress(self):
      return biax.stress

   def finalization(self):
      self.__O.exitNoBacktrace()

I want to run 2 simulations (more than 2 in real case, maybe tens) within one script like this:

a = simDEM(sd=1)
b = simDEM(sd=2)
a.anyfunc()
b.anyfunc()

I expected a and b are separate simulations while they are not due to global defined Omega. How can I run several simulations simultaneously? Vaclav suggested using switchscene(), while it works for 2 scenes as I see it, but I need more than that. How to modify yade to expand its capacity in containing more scenes? Or is there a way to import yade locally to get a local Omega?

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

Hi Ning,

I was looking on the Omega class, and it should be no problem to modify
it to contain several scenes and the possibility to switch arbitrarily
between them, I try and test it and inform you about the progress :-)

Jan

ceguo píše v Po 06. 02. 2012 v 09:30 +0000:
> Question #176993 on Yade changed:
> https://answers.launchpad.net/yade/+question/176993
>
> Status: Answered => Open
>
> ceguo is still having a problem:
> Hi,
>
> I still need an answer in this question. I've wrapped a class for
> simulation as below:
>
>
> import `everything`
>
> class simDEM(object):
> def __init__(self,sd=1):
> self.__id='thread'+str(sd)
> self.__O=Omega()
> self.__O.materials.append(FrictMat(young=1.e8,poisson=.3,frictionAngle=.5,density=1000))
> self.__sp=pack.SpherePack()
> self.__sp.makeCloud(minCorner=(0,0,0),maxCorner=(3,3,0),rMean=.03,rRelFuzz=.25,periodic=True,seed=sd)
> self.__sp.toSimulation()
> self.__O.cell.hSize=Matrix3(3,0,0, 0,3,0, 0,0,1)
> for p in self.__O.bodies:
> p.state.blockedDOFs='zXY'
> self.__O.dt=.5*utils.PWaveTimeStep()
>
> def countParticle(self):
> return len(self.__O.bodies)
>
> def getThreadID(self):
> return self.__id
>
> def consolidate(self, stress=(-5.e4,-5.e4,0,0,0,0)):
> self.__O.engines=[
> ForceResetter(),
> InsertionSortCollider([Bo1_Sphere_Aabb()]),
> InteractionLoop(
> [Ig2_Sphere_Sphere_Dem3DofGeom()],
> [Ip2_FrictMat_FrictMat_FrictPhys()],
> [Law2_Dem3DofGeom_FrictPhys_CundallStrack()]
> ),
> Peri3dController(
> goal=stress,
> stressMask=3,
> nSteps=20000,
> maxStrain=.5,
> label='cons'
> ),
> NewtonIntegrator()
> ]
> self.__O.run()
> self.__O.wait()
>
> def shear(self, strain=(1.e-2,-1.e-2,0,0,0,0)):
> import __builtin__
> __builtin__.__dict__['saveAddData']=self.saveAddData
> self.__O.engines=[
> ForceResetter(),
> InsertionSortCollider([Bo1_Sphere_Aabb()]),
> InteractionLoop(
> [Ig2_Sphere_Sphere_Dem3DofGeom()],
> [Ip2_FrictMat_FrictMat_FrictPhys()],
> [Law2_Dem3DofGeom_FrictPhys_CundallStrack()]
> ),
> Peri3dController(
> goal=strain,
> stressMask=0,
> nSteps=10000,
> maxStrain=.5,
> label='biax'
> ),
> NewtonIntegrator(),
> PyRunner(command='saveAddData()',iterPeriod=100)
> ]
> self.__O.run()
> self.__O.wait()
>
> def getStress(self):
> return biax.stress
>
> def finalization(self):
> self.__O.exitNoBacktrace()
>
> I want to run 2 simulations (more than 2 in real case, maybe tens)
> within one script like this:
>
> a = simDEM(sd=1)
> b = simDEM(sd=2)
> a.anyfunc()
> b.anyfunc()
>
> I expected a and b are separate simulations while they are not due to
> global defined Omega. How can I run several simulations simultaneously?
> Vaclav suggested using switchscene(), while it works for 2 scenes as I
> see it, but I need more than that. How to modify yade to expand its
> capacity in containing more scenes? Or is there a way to import yade
> locally to get a local Omega?
>

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

Hi Ning,

in r3023 it is possible to create and switch between more than one
simulations. Use something like this

sNum = O.addScene()
O.switchToScene(sNum)

note that all attributes genrated with O (O.bodies, O.interactions,
O.time etc.) called after O.switchToScene will refer to current scene
only. Perhaps you will need some (I hope not so much :-) time for
testing and getting used to it.

good luck
Jan

Jan Stránský píše v Po 06. 02. 2012 v 10:43 +0100:
> Hi Ning,
>
> I was looking on the Omega class, and it should be no problem to modify
> it to contain several scenes and the possibility to switch arbitrarily
> between them, I try and test it and inform you about the progress :-)
>
> Jan
>
>
> ceguo píše v Po 06. 02. 2012 v 09:30 +0000:
> > Question #176993 on Yade changed:
> > https://answers.launchpad.net/yade/+question/176993
> >
> > Status: Answered => Open
> >
> > ceguo is still having a problem:
> > Hi,
> >
> > I still need an answer in this question. I've wrapped a class for
> > simulation as below:
> >
> >
> > import `everything`
> >
> > class simDEM(object):
> > def __init__(self,sd=1):
> > self.__id='thread'+str(sd)
> > self.__O=Omega()
> > self.__O.materials.append(FrictMat(young=1.e8,poisson=.3,frictionAngle=.5,density=1000))
> > self.__sp=pack.SpherePack()
> > self.__sp.makeCloud(minCorner=(0,0,0),maxCorner=(3,3,0),rMean=.03,rRelFuzz=.25,periodic=True,seed=sd)
> > self.__sp.toSimulation()
> > self.__O.cell.hSize=Matrix3(3,0,0, 0,3,0, 0,0,1)
> > for p in self.__O.bodies:
> > p.state.blockedDOFs='zXY'
> > self.__O.dt=.5*utils.PWaveTimeStep()
> >
> > def countParticle(self):
> > return len(self.__O.bodies)
> >
> > def getThreadID(self):
> > return self.__id
> >
> > def consolidate(self, stress=(-5.e4,-5.e4,0,0,0,0)):
> > self.__O.engines=[
> > ForceResetter(),
> > InsertionSortCollider([Bo1_Sphere_Aabb()]),
> > InteractionLoop(
> > [Ig2_Sphere_Sphere_Dem3DofGeom()],
> > [Ip2_FrictMat_FrictMat_FrictPhys()],
> > [Law2_Dem3DofGeom_FrictPhys_CundallStrack()]
> > ),
> > Peri3dController(
> > goal=stress,
> > stressMask=3,
> > nSteps=20000,
> > maxStrain=.5,
> > label='cons'
> > ),
> > NewtonIntegrator()
> > ]
> > self.__O.run()
> > self.__O.wait()
> >
> > def shear(self, strain=(1.e-2,-1.e-2,0,0,0,0)):
> > import __builtin__
> > __builtin__.__dict__['saveAddData']=self.saveAddData
> > self.__O.engines=[
> > ForceResetter(),
> > InsertionSortCollider([Bo1_Sphere_Aabb()]),
> > InteractionLoop(
> > [Ig2_Sphere_Sphere_Dem3DofGeom()],
> > [Ip2_FrictMat_FrictMat_FrictPhys()],
> > [Law2_Dem3DofGeom_FrictPhys_CundallStrack()]
> > ),
> > Peri3dController(
> > goal=strain,
> > stressMask=0,
> > nSteps=10000,
> > maxStrain=.5,
> > label='biax'
> > ),
> > NewtonIntegrator(),
> > PyRunner(command='saveAddData()',iterPeriod=100)
> > ]
> > self.__O.run()
> > self.__O.wait()
> >
> > def getStress(self):
> > return biax.stress
> >
> > def finalization(self):
> > self.__O.exitNoBacktrace()
> >
> > I want to run 2 simulations (more than 2 in real case, maybe tens)
> > within one script like this:
> >
> > a = simDEM(sd=1)
> > b = simDEM(sd=2)
> > a.anyfunc()
> > b.anyfunc()
> >
> > I expected a and b are separate simulations while they are not due to
> > global defined Omega. How can I run several simulations simultaneously?
> > Vaclav suggested using switchscene(), while it works for 2 scenes as I
> > see it, but I need more than that. How to modify yade to expand its
> > capacity in containing more scenes? Or is there a way to import yade
> > locally to get a local Omega?
> >
>
>

Revision history for this message
ceguo (hhh-guo) said :
#15

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