-
Notifications
You must be signed in to change notification settings - Fork 0
/
types.jl
74 lines (63 loc) · 2.15 KB
/
types.jl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
"""
Potential
Supertype for all kinds of interaction potentials.
"""
abstract type Potential end
"""
System{V<:Real}
Holds all relevant information for the simulation system.
# Fields
- `xpos::VT`: stores the array for the positions of the particles.
- `density::T`: the density of the system.
- `temperature::T`: the temperature of the system.
- `box::CellListMap.Box{UnitCellType,N,T,M}`: simulation box that will get updated as the
simulation runs.
- `cutoff::T`: cutoff radius for the molecular interactions
- `rng::Random.AbstractRNG`: holds the RNG object for the system
- `npart::Int`: total number of particles in the system
"""
mutable struct System{UnitCellType,N,T,M,VT}
xpos::VT
density::T
temperature::T
box::CellListMap.Box{UnitCellType,N,T,M}
rng::Random.AbstractRNG
npart::Int
end
function System(
density::T, temp::T, particles::Int, cutoff::T; dims=3, random_init=true, lcell=2
) where {T<:Real}
box_size = cbrt(particles / density)
box = CellListMap.Box(fill(box_size, dims), cutoff; lcell=lcell)
rng = Xorshifts.Xoroshiro128Plus()
xpos = initialize_positions(
box_size, rng, particles; dims=dims, random_init=random_init
)
syst = System(xpos, density, temp, box, rng, particles)
return syst
end
function initialize_positions(box_size, rng, particles; dims=3, random_init=true)
if random_init
range = (zero(typeof(box_size)), box_size)
xpos = [random_vec(SVector{dims,Float64}, range; rng=rng) for _ in 1:particles]
else
xpos = [zeros(SVector{dims,Float64}) for _ in 1:particles]
square_lattice!(xpos, particles, box_size)
end
return xpos
end
"""
Simulation
A type to hold all relevant information for the simulation.
# Fields
- `system::S`: ideally, a `System` type that has all the information about the positions
and physical information on the system.
- `ensemble::E`: this is the _statistical ensemble_ used for doing the simulation, ideally
of type `Ensemble`.
- `potential::P`: the interaction potential between the particles, ideally an object of
"""
struct Simulation{S,E,P}
system::S
ensemble::E
potential::P
end