Results 1 to 16 of 16

Thread: [VB6] Simple SPH (smoothed particles hydrodynamics)

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2010
    Location
    Italy
    Posts
    678

    [VB6] Simple SPH (smoothed particles hydrodynamics)

    Simple SPH

    SPH is a technique for simulating fluids.

    I think this is the simplest 2D implementation of SPH

    It uses a slightly modified Spatial grid to detect the pairs of particles to be processed.

    It's very simple, based on 3 main "rules":
    • Attraction
    • Density & Pressure
    • Viscosity



    ATTRACTION:
    When the particles are close together they attract each other with a force proportional to the square of the inverse of the distance.
    If r is the distance between them (normalized in the range 0-1)
    Their attraction strength is equal to (1-r) ^ 2



    Density and PRESSURE:
    The density of each particle is calculated by adding up the weight of neighboring cells. (within the radius h)
    The weight of neighboring cells is given by the Density Kernel:
    Code:
    Private Function SmoothKernel_3(ByVal r As Single) As Single
        r = r * 2!
        If r <= 1! Then
            SmoothKernel_3 = 1! - 1.5! * r * r + 0.75! * r * r * r
        Else
            r = 2! - r
            SmoothKernel_3 = 0.25! * r * r * r
        End If
    End Function
    The pressure of each particle is given by
    Pressure (I) = (Density (I) - RestDensity) / RestDensity

    The replusion force due to pressure is given by the average pressure of the pair of particles multiplied by the Density Kernel * (1 - r)



    VISCOSITY

    The force due to the viscosity between two particles is given by
    This smoothing kernel: -0.5 * r ^ 3 + r ^ 2 + 1 / (2 * r) - 1
    It is applied when the particles are approaching each other.
    When they are moving away, however, only a small part of this force is applied.

    vbRichClient is needed
    Have fun

    look at smoothing kernel graph here:
    https://www.desmos.com/calculator/vz0kydxch7


    2D




    EDIT

    Here is the 3D version!

    • cSpatialGrid3D To quick detect pairs of points at a fixed minumun distance in a 3D space
    • m3DEasyCam To manage a virtual camera and convert 3D world coordinates to the screen ones
    • mQuickSort To draw points from farthest to nearest to camera


    move clicked-mouse on picture to rotate camera.

    EDIT 2

    Update to 3D v4
    Basically:
    -new simplified camera model
    -Fake particels at boundaries

    EDIT 3
    Latest 3D Version on GitHub
    From 3D version V.5 , camera has been improved, now it can manage lines which have one of its points that goes behind the camera by using "near-clipping-plane" technique.



    Attached Files Attached Files

  2. #2
    PowerPoster
    Join Date
    Aug 2010
    Location
    Canada
    Posts
    2,412

    Re: [VB6] Simple SPH (smoothed particles hydrodynamics)

    Wow that's beautiful work! Mesmerizing

  3. #3
    Addicted Member
    Join Date
    Feb 2014
    Location
    USA
    Posts
    128

    Re: [VB6] Simple SPH (smoothed particles hydrodynamics)

    Quote Originally Posted by jpbro View Post
    Wow that's beautiful work! Mesmerizing
    Tell me about it, and with SO little code. Yes I examined it some. There are *very* few in the world who can pull this off, no matter how much code is used.

  4. #4

  5. #5
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: [VB6] Simple SPH (smoothed particles hydrodynamics)

    Well, that would require 3D calculations, so off hand, a fair amount of extra calculation compared to a 2D fluid calculation.
    Have to wonder whether the planet calculation has to take into consideration the various layers and type of material the planets are made of and account for those in the particle calculations.

  6. #6
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: [VB6] Simple SPH (smoothed particles hydrodynamics)

    Very interesting code, thank you reexre.

    In addition, the math function expressions in desmos are equally interesting. Is there a way to implement similar functionalities with vbRichClient5?
    Attached Images Attached Images  

  7. #7
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: [VB6] Simple SPH (smoothed particles hydrodynamics)

    I'm not sure what you're asking.
    The equations you posted are pretty much the same as what reexre posted that he is using in the first post.
    Since he is using the same or similar equations and using vbrichclient to illustrate the implementation on a large number of particles, it you wanted to modify the equations slightly, then there shouldn't be any issue with using vbrichclient since that is what is already being done.

  8. #8
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: [VB6] Simple SPH (smoothed particles hydrodynamics)

    Quote Originally Posted by passel View Post
    I'm not sure what you're asking.
    The equations you posted are pretty much the same as what reexre posted that he is using in the first post.
    Since he is using the same or similar equations and using vbrichclient to illustrate the implementation on a large number of particles, it you wanted to modify the equations slightly, then there shouldn't be any issue with using vbrichclient since that is what is already being done.
    I mean how to draw math-equations with vbRichClient5 or pure VB6.

  9. #9
    Sinecure devotee
    Join Date
    Aug 2013
    Location
    Southern Tier NY
    Posts
    6,582

    Re: [VB6] Simple SPH (smoothed particles hydrodynamics)

    Ok, to replicate the graphs shown?
    That should be easy enough with pure VB6, and I'm sure also vbRichClient5, although I haven't used vbRichClient.
    I guess you can't see the whole equation for the Density Smooth.

    With "pure VB6", you could just create a picturebox to use as the graph area, set the ScaleWidth and ScaleHeight to the size you want for your plot area and set the ScaleLeft and ScaleTop appropriately.

    I guess looking at the web page, perhaps it is a little more complicated than that since you can click on the graph, and drag to scroll the graph vertically and horizontally to see more of the graph, so the plot's virtual size can be much larger than what can fit on the screen at any given time. And you can zoom in and out so the scale is modifiable. If you want to replicate the functionality of the desmos graphing interface, then that would be quite a bit of work, i.e. the display of point values along the curve with tooltip type windows, etc...

    I'm sure it can be done in pure VB6 or other graphic library. The question is how much of the functionality are you looking to implement.

  10. #10
    PowerPoster
    Join Date
    Sep 2012
    Posts
    2,083

    Re: [VB6] Simple SPH (smoothed particles hydrodynamics)

    Yes, the workload of developing a general math equation editor is large.

  11. #11

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2010
    Location
    Italy
    Posts
    678

    Re: [VB6] Simple SPH (smoothed particles hydrodynamics)

    SPH 3D
    I added the third dimension.
    soon I will publish it.
    after some refining.

  12. #12
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,121

    Re: [VB6] Simple SPH (smoothed particles hydrodynamics)

    Wow! Can you impl gravity centering to a point like a planet and possibly a moon?

    I see that the liquid already has some volume so in this case this volume will fill up a (rotating) sphere.

    cheers,
    </wqw>

  13. #13

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2010
    Location
    Italy
    Posts
    678

    Re: [VB6] Simple SPH (smoothed particles hydrodynamics)

    @wqweto

    This is my new test.
    I added an Attraction to Global Center of Mass
    Thanks for the suggestion.
    Quite near your Planets demo... but I don't think I'll go more further


  14. #14
    PowerPoster wqweto's Avatar
    Join Date
    May 2011
    Location
    Sofia, Bulgaria
    Posts
    5,121

    Re: [VB6] Simple SPH (smoothed particles hydrodynamics)

    This is extremely cool interactive demo! Both liquids don't mix like water and oil :-))

    cheers,
    </wqw>

  15. #15

  16. #16

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2010
    Location
    Italy
    Posts
    678

    Re: [VB6] Simple SPH (smoothed particles hydrodynamics)

    3D Version on GitHub since today.

    now 3D version (V.5) has an improved camera that can manage lines which have one of its points that goes behind the camera by using "near-clipping-plane" technique.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width