Git Product home page Git Product logo

bubblebath.jl's Introduction

BubbleBath.jl

Build Status codecov

Generate loose packings of spheres in orthorhombic domains, in 2 and 3 dimensions.

Features

  • Fill a domain with spheres from a given distribution of radii to reach a target packing fraction, or from already-sampled radii.
  • Control minimum allowed distance between spheres.
  • Decide whether spheres can cross through domain boundaries or not.

BubbleBath.jl just employs the trivial brute-force method, with the only peculiarity that spheres are introduced in order of decreasing radius. Dense packings are obtained with reasonable performance, but spatial correlations between sphere sizes are introduced.

This is not an algorithm to generate tight, space-filling packings.

Example usage

The package exports a Sphere{D} type, which is just a wrapper around a position pos::NTuple{D,Float64} and a radius radius::Float64, and the bubblebath function, which creates a loose packing of spheres in a domain.

To generate a (2D) distribution of spheres with radii uniformly distributed within 1 and 5, in a rectangular domain of edges 100 and 50, with a packing fraction 0.4, we can do

using BubbleBath
using Distributions: Uniform

radius_pdf = Uniform(1,5)
extent = (100, 50)
ϕ_max = 0.4
bath = bubblebath(radius_pdf, ϕ_max, extent)

Bubblebath in 2D

If we want to impose a minimal distance between the surface of spheres, the min_distance keyword can be used

radius_pdf = Uniform(1,5)
extent = (100, 50)
ϕ_max = 0.4
min_distance = 2.0
bath = bubblebath(radius_pdf, ϕ_max, extent; min_distance)

Bubblebath in 2D with minimum separation

Again, the procedure in 3D is identical

radius_pdf = Uniform(10,25)
extent = (100, 100, 100)
ϕ_max = 0.3
min_distance = 10.0
bath = bubblebath(radius_pdf, ϕ_max, extent; min_distance)

Bubblebath in 3D with minimum separation

We can verify that the generated radii closely match the chosen distribution, even at relatively high packing fractions.

using Distributions: Exponential
θ = 3.0 # average radius
radius_pdf = Exponential(θ)
extent = ntuple(_->300, 3)
bath1 = bubblebath(radius_pdf, 0.3, extent)
# this can take a while
bath2 = bubblebath(radius_pdf, 0.6, extent)
r1 = map(s -> s.radius, bath1)
r2 = map(s -> s.radius, bath2)

Comparison of theoretical and generated radius distributions

Finally, bubblebath also has an in-place version bubblebath!, which can operate on pre-initialised vectors of Spheres. For example, to produce the BubbleBath.jl logo:

using Distributions: Exponential
# initialise vector with three spheres at desired locations
Lx = 400
Ly = 400
extent = (Lx,Ly)
R = 50
D = 60
spheres = [
    Sphere((Lx/2-D,Ly/2-D), R),
    Sphere((Lx/2+D,Ly/2-D), R),
    Sphere((Lx/2,Ly/2+3D/4), R)
]
# add new spheres with exponential distribution of radii
radius_pdf = Exponential(2.0)
ϕ_max = 0.25 - packing_fraction(spheres, extent)
min_distance = 2.0
bubblebath!(spheres, radius_pdf, ϕ_max, extent; min_distance)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.