Skip to content

Commit 031a30b

Browse files
committed
Check if initial energy is infinite. Add isinf(e1) in perform_action
1 parent 73708c5 commit 031a30b

3 files changed

Lines changed: 14 additions & 11 deletions

File tree

src/atoms.jl

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
struct Atoms{D, Q, V<:AbstractVector, C<:NeighbourList, H, T<:AbstractFloat, SM<:AbstractArray} <: Particles
1+
struct Atoms{D, V<:AbstractVector, C<:NeighbourList, H, T<:AbstractFloat, SM<:AbstractArray} <: Particles
22
position::Vector{SVector{D,T}}
33
species::V
44
density::T
@@ -8,7 +8,6 @@ struct Atoms{D, Q, V<:AbstractVector, C<:NeighbourList, H, T<:AbstractFloat, SM<
88
N::Int
99
d::Int
1010
box::SVector{D,T}
11-
local_energy::MVector{Q, T}
1211
neighbour_list::C
1312
species_list::H
1413
end
@@ -20,15 +19,17 @@ function System(position, species, density::T, temperature::T, model_matrix; lis
2019
d = length(Array(position)[1])
2120
energy = Vector{T}(undef, 1)
2221
box = @SVector fill(T((N / density)^(1 / d)), d)
23-
local_energy = MVector{N, T}(zeros(T, N))
24-
indices = MVector{N, Bool}(falses(N))
2522
maxcut = maximum([model.rcut for model in model_matrix])
2623
neighbour_list = list_type(box, maxcut, N)
2724
species_list = isa(species[1], Integer) ? SpeciesList(species) : nothing
2825
system = Atoms(position, species, density, energy, temperature, model_matrix, N, d, box, neighbour_list, species_list)
2926
build_neighbour_list!(system)
30-
system.local_energy .= [compute_energy_particle(system, i) for i in eachindex(system)]
31-
system.energy[1] = sum(system.local_energy) / 2
27+
local_energy = [compute_energy_particle(system, i, neighbour_list) for i in eachindex(position)]
28+
energy = mean(local_energy) / 2
29+
if isinf(energy) || isnan(energy)
30+
error("Initial configuration has infinite or NaN energy.")
31+
end
32+
system.energy[1] = energy
3233
return system
3334
end
3435

src/molecules.jl

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ struct Molecules{D, VS<:AbstractVector, C<:NeighbourList, T<:AbstractFloat, SM<
1313
N::Int
1414
Nmol::Int
1515
box::SVector{D,T}
16-
local_energy::Vector{T}
1716
neighbour_list::C
1817
bonds::Vector{Vector{Int}}
1918
end
@@ -27,14 +26,17 @@ function System(position, species, molecule, density::T, temperature::T, model_m
2726
molecule_species = something(molecule_species, ones(Int, N))
2827
d = length(Array(position)[1])
2928
box = @SVector fill(T((N / density)^(1 / d)), d)
30-
local_energy = zeros(T, N)
3129
energy = zeros(T, 1)
3230
maxcut = maximum([model.rcut for model in model_matrix])
3331
neighbour_list = list_type(box, maxcut, N)
3432
system = Molecules(position, species, molecule, molecule_species, start_mol, length_mol, density, temperature, energy, model_matrix, d, N, Nmol,box, neighbour_list, bonds)
3533
build_neighbour_list!(system)
36-
system.local_energy .= [compute_energy_particle(system, i, neighbour_list) for i in eachindex(position)]
37-
system.energy[1] = sum(system.local_energy) / 2
34+
local_energy = [compute_energy_particle(system, i, neighbour_list) for i in eachindex(position)]
35+
energy = mean(local_energy) / 2
36+
if isinf(energy) || isnan(energy)
37+
error("Initial configuration has infinite or NaN energy.")
38+
end
39+
system.energy[1] = energy
3840
return system
3941
end
4042

src/moves.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ using ComponentArrays
22

33
function Arianna.perform_action!(system::Particles, action::Action)
44
e₁, e₂ = perform_action!(system, action)
5-
if isinf(e₂)
5+
if isinf(e₁) || isinf(e₂)
66
action.δe = zero(typeof(system.energy[1]))
77
else
88
action.δe = e₂ - e₁

0 commit comments

Comments
 (0)