# Simulation speed

137 views
A few weeks ago, I ran a simulation (Case 1) which contains 95808 spheres(radius =0.025). I tried to simulate 100 seconds. So I set up:"

if Scene.time >100

Scenen.stop()

" in my script. The simulation was very slow, it is still running now. It takes around 15 hours run time to finish 1 second.

Then I tried to speed up the simulation by ruducing the number of shpheres, and enlarging the radius of spheres. Then I tried to run a simulaton(Case 2) with 20092 spheres(radius =0.05). I found this Case 2 is much slower than Case 1(Case 2 is 5-times slower than Case 1).

The time step for simulaiton is calculated by detT= radius* sqrt( density/E). Is that right? In case 2, I gave a larger radius, so the simulaiton should be faster in my expectation. But why it is much slower. Did I misunderstand something? Thanks!
commented Jun 14, 2017 by (49,030 points)

I will try to look within next few days, I was away now. Please be patient. v

answered Jun 19, 2017 by (49,030 points)

Hi, I tried to run the simulations you sent by e-mail to me. I had to comment out a lof of engines I was not sure what their purpose was (restartAssist and others) and the output is the following for case1:

Number of particles 106400
Name                                                  Count            Time [ms]        Rel. time [%]
-----------------------------------------------------------------------------------------------------
"leapfrog"                                       1001              13614.1                20.98
"collider"                                   (2) 1001              15329.6                23.62
"contactLoop"                                    1001              14111.6                21.75
"dynDt"                                            11                983.3                 1.52
VtkExport                                           0                  0.0                 0.00
HalfspaceBuoyancy                                1001              20093.3                30.97
"equilibrizer"                                      0                  0.0                 0.00
PyRunner                                            1                757.8                 1.17
PyRunner                                            0                  0.0                 0.00
TOTAL                                                              64889.7               100.00


and this is case2:

Number of particles 30684
Name                                                  Count            Time [ms]        Rel. time [%]
-----------------------------------------------------------------------------------------------------
"leapfrog"                                       1001               4241.1                17.48
"collider"                                   (1) 1001               4200.6                17.31
"contactLoop"                                    1001               9638.4                39.72
"dynDt"                                            11                797.2                 3.29
VtkExport                                           0                  0.0                 0.00
HalfspaceBuoyancy                                1001               4832.7                19.92
"equilibrizer"                                      0                  0.0                 0.00
PyRunner                                            1                555.0                 2.29
PyRunner                                            0                  0.0                 0.00
TOTAL                                                              24264.8               100.00



S.engines+=[PyRunner(1000,'import woo.timing; woo.timing.stats(); S.stop()',initRun=False)]

before starting with S.run()), and I added woo.master.timingEnabled=True in the script as well.

So what I see is the opposite, smaller number of spheres leads to smaller simulation time as expected (65s total time for 106k spheres, 24s for 31k spheres).

I think you should run your scripts with woo.timing and you will find out what is consuming disproportionate amount of time.

In the scripts, there are many unnecessary commands, like collectNodes (which you don't need), then you run createMastersAndTree, which was only used in the python implementation of buoyancy which you don't use anymore.

The function writeSeabedForces is unnecessarily complicated; first, python has formatting functions like '%20d'%i will print, with i=123, '                 123' padded to 20 chars, so you don't have to do som complicated. Second, if you use S.plot.addData(...) and then S.plot.saveDataTxt(...) which is there exactly for this purpose, plus you can see live plot of evolution during simulation.

You could also simplify the wall control a lot; one can impose a time-series of desired velocities (which are interpolated in-between the points) via VariableVelocity3d; for imposing constant force, there is ConstantForce.

Cheers, Vaclav

commented Jun 19, 2017 by (220 points)

Hi Vaclav,

Thank you for your so detailed reply. I will check my input script again based on your comments. Will let you know the result.

Best regards,
Lei