Code Monkey home page Code Monkey logo

particlecorrelations.jl's Introduction

ParticleCorrelations.jl

Build Status

A package to calculate typical pair correlations (or structure factor) for disordered particulates, such as Percus-Yevick, and to calculate specific particle configurations from given pair correlation.

Pair correlations are used in many fields in physical chemistry, statistical physics, condensed matter physics, material science, and many more. This package aims to be useful and easy to understand for many of these communities.

Pair correlation and Structure factor

The definition of the pair-correlation $g$, for a finite number of multi-species particles, is [1]

$$ g(\mathbf r_1, \lambda_1; \mathbf r_2, \lambda_2) = \frac{p(\mathbf r_1, \lambda_1; \mathbf r_2, \lambda_2)}{p(\mathbf r_1, \lambda_1)p(\mathbf r_2, \lambda_2)}\frac{J -1}{J} $$

where $\mathbf r_j$ is the vector position of the centre of particle - $j$, $\lambda_j$ represents the size or other distinguishing properties of the type of particle, $p$ is the probability density function, and $J$ is the total number of particles. Due to the definition of the pair-correlation, when the particles become uncorrelated in the limit $|\mathbf r_1 - \mathbf r_2| \to \infty$ we have that

$\lim_{|\mathbf r_1 - \mathbf r_2| \to \infty} g(\mathbf r_1, \lambda_1; \mathbf r_2, \lambda_2) = 1$.

So far this package focuses on isotropic and statisticall homogeneous materials. Both these assumptions together imply that

$$ g(\mathbf r_1, \lambda_1; \mathbf r_2, \lambda_2) = g(|\mathbf r_1 - \mathbf r_2|; \lambda_1, \lambda_2), $$

where $|\mathbf r_1 - \mathbf r_2|$ is the distance between the particle centres.

Adding definitions and formulas for the structure factors...

Particle configurations

formulas for discrete particles...

Pair correlation from particles

We can calculate the pair-correlation from a configuration of particles.

using ParticleCorrelations

# choose the spatial dimension
dim = 2

# choose the medium for the particles. Currently only one type
medium = HardMedium{dim}()

# choose the shapes of the particles
radius = 0.5
particle_shapes = [Sphere(dim,radius)]

# choose a region to place the particles within
dimensions = [80.0,60.0];
region_shape = Box([0.0,0.0],dimensions)

# create a uniform random arrangement of particles using Sequential Addition 
particles = random_particles(medium, particle_shapes;
    num_particles = 600, 
    volume_fraction = 0.15,
    region_shape = region_shape
)

If you have the Plots package installed you can plot these particles by using

using Plots

plot(region_shape)
plot!(particles)
plot!(axis = false, xlab = "", ylab = "")

../particles.png

rs = 0.2:0.4:8.0
pair = pair_correlation(particles, rs)

# If you have the Plots package
plot(pair.r, pair.g)

../example_random_particles.png

Monte-Carlo methods

Here is a more convienient syntax to calculate pair-correlation from specific particle configurations.

dim = 2;

pairtype = MonteCarloPairCorrelation(dim; 
    rtol = 1e-3, 
    maxlength = 100, 
    iterations = 10, 
    numberofparticles = 3000
)

# choose the medium for the particles. Currently only one type
medium = HardMedium{dim}()

# choose the particle radius
radius = 0.5

# Choose the species, which represents a collection of one type of particle
s = Specie(
    medium,
    Sphere(dim, radius),
    volume_fraction = 0.15,
    separation_ratio = 1.0 # minimal distance from this particle = r * (separation_ratio - 1.0) 
);

pair = pair_correlation(s, pairtype, rs)

# If you have the Plots package
plot(pair.r, pair.g)

../monte-carlo-pair.png

From the pair-correlation we can easily calculate the structure factor by using:

rs = pair.r

ks = 0.2:0.2:20.0
sfactor = structure_factor(pair, ks)

plot(sfactor.k, sfactor.S,
    xlab = "k", lab = "struc. factor")

../monte-carlo-pair.png

Percus-Yevick

Let us consider a material filled with only one type of particle and use the Percus-Yevick approximation to calculate the pair-correlation for 3D hard spheres. That is, sphere which do not attract of repel each other. For details see Notes on Percus-Yevick [2].

# choose the type of pair correlation
pairtype = PercusYevick(3; rtol = 1e-3, maxlength = 200)

# Percus-Yevick is currently implemented only for 3D. So we need to change the type of particle

# choose the particle radius
radius = 0.5

s = Specie(
    HardMedium{3}(),
    Sphere(3, radius),
    volume_fraction = 0.3
);

# by ommiting the distances argument it will be calculated from the parameters provided by pairtype
pair = pair_correlation(s, pairtype)

We can plot the result of the Percus-Yevick approximation with the package Plots:

using Plots

plot(pair.r, pair.g,
    xlab = "distance", lab = "P-Y",
    xlims = (0.0, 5.0)
)

../PY-30-pair.png

which we can compare with Figure 8.3.1 from [1] below.

../TKD-PY-30.jpg

Note that for $x < 1$ the two particles of radius 0.5 would overlap, so the pair correlation should be zero.

We can now calculate the structure factor:

ks = 0.2:0.2:20.0
sfactor = structure_factor(pair, ks)

plot(sfactor.k, sfactor.S,
    xlab = "ks", lab = "struct. factor")

../PY-30-struct.png

Bespoke pair-correlation

Here is an example of choosing your own pair-correlation for a material filled with only one type of particle

using ParticleCorrelations

# particle radius 
r = 0.5

# mesh for the pair-correlation
rs = (2r):0.1:10.0

my_pair_correlation = 1.0 .+ 0.2 .* sin.(rs) ./ rs.^3


# spatial dimension. Needed for Monte Carlo or Structure factor
dim = 3

pair = pair_correlation(dim, rs, my_pair_correlation)

Note that when specifying a pair-correlation, the minimal distance between particles will be taken to be pair.r[1]. This is stored in pair.minimal_distance.

References

[1] Kong, Jin Au, Leung Tsang, Kung-Hau Ding, and Chi On Ao. Scattering of electromagnetic waves: numerical simulations. John Wiley & Sons, 2004.

[2] Gerhard Kristensson. "The Percus-Yevick approximation". github.com/JuliaWaveScattering/EffectiveWaves.jl (2022).

particlecorrelations.jl's People

Contributors

arturgower avatar

Stargazers

 avatar  avatar  avatar  avatar

Watchers

 avatar

particlecorrelations.jl's Issues

TagBot trigger issue

This issue is used to trigger TagBot; feel free to unsubscribe.

If you haven't already, you should update your TagBot.yml to include issue comment triggers.
Please see this post on Discourse for instructions and more details.

If you'd like for me to do this for you, comment TagBot fix on this issue.
I'll open a PR within a few hours, please be patient!

monte carlo radial mesh

The radial mesh distance for the monte-carlo method is treated as the centre of a bin, in which the number of particles are counted.

However, if the user provides a mesh with the smallest element too close to zero, then the bin has to change size. At the moment, this line creates an error if the smallest element distance[1] is too close to zero, then the centre of the bin with be negative, and this will lead to mistakes.

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.