Skip to content

Commit

Permalink
draft fill box with periodic
Browse files Browse the repository at this point in the history
  • Loading branch information
arturgower committed Sep 20, 2023
1 parent 8b08866 commit 5b03e5d
Show file tree
Hide file tree
Showing 2 changed files with 90 additions and 24 deletions.
43 changes: 22 additions & 21 deletions src/pair-correlation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -89,36 +89,37 @@ struct DiscretePairCorrelation{Dim} <: PairCorrelation
end

# Predict the number density from the restriction that is due to the link with a probability distribution, and assuming homogeneous distribution of particles.
if !isempty(r)
σs = trapezoidal_scheme(r)

σs = trapezoidal_scheme(r)
sumg = sum(g .* r .^ (Dim - 1) .* σs)

sumg = sum(g .* r .^ (Dim - 1) .* σs)
number_density_predict = 1 / (2*(Dim - 1) * π * (r[end] ^ Dim / Dim - sumg))

number_density_predict = 1 / (2*(Dim - 1) * π * (r[end] ^ Dim / Dim - sumg))
if number_density == -1.0
number_density = number_density_predict
end

if number_density == -1.0
number_density = number_density_predict
end

number_density_error = abs(number_density / number_density_predict - 1)
number_density_error = abs(number_density / number_density_predict - 1)

# This formula seems to sensitive to numerical errors.
# if number_density_error > tol
# println("The number density that was specified was $(number_density), whereas the calculated number density was $(number_density_predict), a reltive error of $(number_density_error)")
# end
# This formula seems to sensitive to numerical errors.
# if number_density_error > tol
# println("The number density that was specified was $(number_density), whereas the calculated number density was $(number_density_predict), a reltive error of $(number_density_error)")
# end

if rescale
println("rescaling this pair correlation according to the number density provided.")
# this rescaling is due to a restriction imposed by the connection to probability distributions
if rescale
println("rescaling this pair correlation according to the number density provided.")
# this rescaling is due to a restriction imposed by the connection to probability distributions

b = r[end] ^ Dim / Dim - 1 / (2*(Dim - 1) * π * number_density)
α = b / sumg
b = r[end] ^ Dim / Dim - 1 / (2*(Dim - 1) * π * number_density)
α = b / sumg

if α < 0
@error "rescaling has failed and has given a negative scale for the pair-correlation"
end
if α < 0
@error "rescaling has failed and has given a negative scale for the pair-correlation"
end

g = α .* g
g = α .* g
end
end

new{Dim}(r,g,minimal_distance,number_density)
Expand Down
71 changes: 68 additions & 3 deletions test/particulate-from-structure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,77 @@
using ParticleCorrelations
using Test, Statistics

using Optim
using Plots

# let us first aim to recover a MonteCarlo pair-correlation from a crystalline arrangement

# 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

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 species, which represents a collection of one type of particle
radius = 0.5

s = Specie(
medium,
Sphere(dim, radius),
volume_fraction = 0.15,
separation_ratio = 1.0 # minimal distance from this particle = r * (separation_ratio - 1.0)
);

rs = 0.2:0.4:8.0
pair = pair_correlation(s, pairtype, rs)


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

ks = 1.0:0.5:20.0
sfactor = structure_factor(pair, ks)

plot(sfactor.k, sfactor.S)


# Define two regions R1 and R2 to place the particles
reg1 = Box([[-40.0, -40.0],[40.0, 40.0]]);
reg2 = Box([[-42.0, -42.0],[42.0, 42.0]]);

Dim = 2

# box = reg2
function periodic_particles(box::Box{T,Dim}, specie::Specie{Dim}) where {T, Dim}

Id = Matrix(I, Dim, Dim)
vs = [Id[:,i] for i = 1:Dim]

n = number_density(specie)

cell_length = (1 / n)^(1/Dim) / 2

d1 = origin(box) - box.dimensions ./ (2)
d2 = origin(box) + box.dimensions ./ (2)

end

using Optim

a = 1.0
rs = 0.0:0.01:8.0
function g!(G, S)
G[1] = -2.0 * (1.0 - S[1])
end

g = 1.0 .+ exp.(-(rs .- 4a).^2)

Expand Down

0 comments on commit 5b03e5d

Please sign in to comment.