Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

B Are there any SPH planet collision simulators?

  1. Oct 20, 2017 #1
    Hello, I've been searching for a collision simulator for planets that uses SPH. I haven't found any though. US2 doesn't use SPH collisions. But does anyone know any that are publically available? Example video below:

    And a channel with a few: https://www.youtube.com/user/joetaicoon/videos
     
  2. jcsd
  3. Oct 20, 2017 #2
    GADGET 2 - "GADGET computes gravitational forces with a hierarchical tree algorithm (optionally in combination with a particle-mesh scheme for long-range gravitational forces) and represents fluids by means of smoothed particle hydrodynamics (SPH)." - Free software, released in May 2005
     
  4. Oct 20, 2017 #3
    Sadly that doesn't do planetary collisions.
     
  5. Oct 20, 2017 #4
    Bump, don't know when i can bump but I haven't found a rule book thing
     
  6. Oct 20, 2017 #5

    Drakkith

    User Avatar

    Staff: Mentor

    The link to PF Terms and Rules can be found at the bottom right of every page on the site and under the "Info" tab at the top.

    Per the rules:

    Bumping
    Do not "bump" one of your threads to the top of a forum's thread list by posting a basically empty message to it, until at least 24 hours have passed since the latest post in the thread; and then do it only once per thread.
     
  7. Oct 20, 2017 #6
    Ah sorry. I didn't see that
     
  8. Oct 20, 2017 #7

    phyzguy

    User Avatar
    Science Advisor

    Why do you say it doesn't do planetary collisions? If you have gravity and fluid mechanics, what in your mind is missing? Why isn't it just a matter of setting up the initial conditions properly?
     
  9. Oct 20, 2017 #8
    afaik I don't know any way to create new conditions for it. The .param file is just for the loading and not the objects. a.k.a It doesn't say where the particles and motion it just says stuff like when the simulation should end & write the files for loading.
     
  10. Oct 21, 2017 #9
    Oh also it is for gas and dark matter simulations.
     
  11. Oct 21, 2017 #10

    phyzguy

    User Avatar
    Science Advisor

    You will need to write code to generate the particle initial conditions. If you don't know how to do this, then you won't know how to interpret the simulator output either, because it is just files with lists of particle positions and velocities. I think Gadget could do the job, but I won't argue the point. I know that Rosswog's group uses the SPH code MAGMA to simulate neutron star collisions, but as far as I know it is not publicly available.
     
  12. Oct 21, 2017 #11
    I mean, the data is .dat files and it's binary littleendian and bigendian so it's very very hard to interpret it!
     
  13. Nov 8, 2017 #12
    GADGET 2 is presumably open-source. That should make it possible to find out what it does by reading its source code. There ought to be some place in it for reading in initial conditions. From how it reads in, one can find the initial-conditions data format and work out how to generate initial conditions with one's own software. It's essentially a lot of particle positions and velocities with extra info on how they behave.
     
  14. Nov 8, 2017 #13

    phyzguy

    User Avatar
    Science Advisor

    @MrQuack It's not that hard to read and write the Gadget IC files. I've attached below some Python code to read a Gadget IC file and print out the position and velocity of one of the particles. It's not the cleanest code in the world, but it works. Maybe this will be of some use to you.

    Code (Python):
    #!/usr/bin/env python

    from pylab import *
    import array


    def ReadGadgetICFile(filename):# Reads an initial conditions file

        class ICfile:
            pass

        icfile = ICfile()
        file = open(filename,"rb")
        icfile.header = ReadGadgetHeader(file) # Header data
        icfile.data = ReadGadgetData(file, icfile.header,1)
        file.close()

        return icfile

    def ReadGadgetHeader(file): # Reads the header of the snapshot or IC file

        class HeadData:
            pass
        header=HeadData()

        header.blocksize = array.array("i")
        header.Npart = array.array("I")
        header.Massarr = array.array("d")
        header.Time = array.array("d")
        header.Redshift = array.array("d")
        header.FlagSfr = array.array("i")
        header.FlagFeedback = array.array("i")
        header.Nall = array.array("i")
        header.FlagCooling = array.array("i")
        header.NumFiles = array.array("i")
        header.BoxSize = array.array("d")
        header.Omega0 = array.array("d")
        header.OmegaLambda = array.array("d")
        header.HubbleParam = array.array("d")
        header.FlagAge = array.array("i")
        header.FlagMetals = array.array("i")
        header.NallHW = array.array("i")
        header.flag_entr_ics = array.array("i")
        header.unused = array.array("i")

        header.blocksize.fromfile(file,1)
        header.Npart.fromfile(file,6)
        header.Massarr.fromfile(file,6)
        header.Time.fromfile(file,1)
        header.Redshift.fromfile(file,1)
        header.FlagSfr.fromfile(file,1)
        header.FlagFeedback.fromfile(file,1)
        header.Nall.fromfile(file,6)
        header.FlagCooling.fromfile(file,1)
        header.NumFiles.fromfile(file,1)
        header.BoxSize.fromfile(file,1)
        header.Omega0.fromfile(file,1)
        header.OmegaLambda.fromfile(file,1)
        header.HubbleParam.fromfile(file,1)
        header.FlagAge.fromfile(file,1)
        header.FlagMetals.fromfile(file,1)
        header.NallHW.fromfile(file,6)
        header.flag_entr_ics.fromfile(file,1)
        header.unused.fromfile(file,15)
        header.blocksize.fromfile(file,1)

        return header

    def ReadGadgetData(file,header,filetype):
        # Reads the data (position, velocity, mass, ...)
        # filetype=0->snapshot file, filetype=1->IC file

        class Data:
            pass
        data=Data()

        Npart=header.Npart
        Massarr=header.Massarr
        Ngas=header.Npart[0]
        N=0
        for i in range(6):
            N = N+Npart[i]
        Nm=0
        for i in range(6):
            if Massarr[i]==0:
                Nm = Nm+Npart[i]

        data.blocksize = array.array("i")
        data.pos = array.array("f")
        data.vel = array.array("f")
        data.id = array.array("i")
        data.masses = array.array("f")
        data.u = array.array("f")
        data.rho = array.array("f")
        if header.FlagCooling[0]==1:
            data.ne = array.array("f")
            data.np = array.array("f")
        data.hsml = array.array("f")

        data.blocksize.fromfile(file,1)
        data.pos.fromfile(file,3*N)
        data.blocksize.fromfile(file,1)

        data.blocksize.fromfile(file,1)
        data.vel.fromfile(file,3*N)
        data.blocksize.fromfile(file,1)

        data.blocksize.fromfile(file,1)
        data.id.fromfile(file,N)
        data.blocksize.fromfile(file,1)

        if Nm!=0:
            data.blocksize.fromfile(file,1)
            data.masses.fromfile(file,Nm)
            data.blocksize.fromfile(file,1)
        if Ngas!=0:    
            data.blocksize.fromfile(file,1)
            data.u.fromfile(file,Ngas)
            data.blocksize.fromfile(file,1)

           if filetype==0:

                data.blocksize.fromfile(file,1)
                data.rho.fromfile(file,Ngas)
                data.blocksize.fromfile(file,1)

            if header.FlagCooling[0]==1:

                    data.blocksize.fromfile(file,1)
                    data.ne.fromfile(file,Ngas)
                    data.blocksize.fromfile(file,1)

                    data.blocksize.fromfile(file,1)
                    data.np.fromfile(file,Ngas)
                    data.blocksize.fromfile(file,1)

                data.blocksize.fromfile(file,1)
                data.hsml.fromfile(file,Ngas)
                data.blocksize.fromfile(file,1)

        return data

    icfile = ReadGadgetICFile('bullet.dat')

    id = 17

    print "Particle # %d has mass %f, position (%f,%f,%f), and velocity (%f,%f,%f)"%(icfile.data.id[id], icfile.data.masses[id], icfile.data.pos[id], icfile.data.pos[id+1], icfile.data.pos[id+2], icfile.data.vel[id], icfile.data.vel[id+1], icfile.data.vel[id+2])
     
     
  15. Nov 14, 2017 #14

    phyzguy

    User Avatar
    Science Advisor

    @MrQuack : If you look at this paper, they are in fact using Gadget for planetary collision simulations.
     
  16. Nov 29, 2017 #15
    @phyzguy Ah thanks! Sorry for very late reply, forgot about forums for a little bit
     
  17. Nov 29, 2017 #16
    Sadly I'm not that good at reading papers though and can't understand most of them
     
  18. Nov 29, 2017 #17

    phyzguy

    User Avatar
    Science Advisor

    These simulators are not simple pieces of code. Using them is not like running a program like Excel. You have to dig into how they work in order to create the initial conditions and interpret the output. Often you have to modify the code itself. If you can't understand the paper I linked, then you probably won't be able to run these complex simulations. Sorry to be blunt, but that's the way it is.
     
  19. Nov 29, 2017 #18
    oh i guess im not gonna use any of that stuff then
     
  20. Dec 9, 2017 at 12:25 PM #19
    A very fast and simple SPH algorithm is described extensively in this paper:
    http://www.ligum.umontreal.ca/Clavet-2005-PVFS/pvfs.pdf
    Not the state of the art, but very suited for real-time applications, eg. Games.

    That should take care of the velocity and position vectors.

    Then you just need to use N-Body calculations for the acceleration vectors.
     
  21. Dec 9, 2017 at 12:31 PM #20
    If you just want some neat effects and are not aiming for accuracy, you should ignore soft body physics and directly simulate the planet as thousands of frictionless rigid body spheres, as a fluid with zero viscosity and surface tension is basically many rigid body particles.
     
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Have something to add?
Draft saved Draft deleted