Skip to content

Commit 6f813c9

Browse files
Merge pull request #45 from SciML/repeat
Remove repeat times
2 parents 5c9d950 + a0103b5 commit 6f813c9

File tree

2 files changed

+17
-16
lines changed

2 files changed

+17
-16
lines changed

src/nbody_simulation_result.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -297,7 +297,7 @@ end
297297
# this should be a method for integrators designed for the SecondOrderODEProblem (It is worth somehow to sort them from other algorithms)
298298
function calculate_simulation(s::NBodySimulation, alg_type::Union{VelocityVerlet,DPRKN6,Yoshida6}, args...; kwargs...)
299299
cb = obtain_callbacks_for_so_ode_problem(s)
300-
solution = solve(SecondOrderODEProblem(s), alg_type, args...; callback=cb, kwargs...)
300+
solution = solve(SecondOrderODEProblem(s), alg_type, args...; callback=cb, save_everystep = isempty(cb), kwargs...)
301301
return SimulationResult(solution, s)
302302
end
303303

@@ -331,7 +331,7 @@ function get_andersen_thermostating_callback(s::NBodySimulation)
331331
end
332332
end
333333
end
334-
cb = DiscreteCallback(condition, affect!)
334+
cb = DiscreteCallback(condition, affect!, save_positions = (false,true))
335335
end
336336

337337
function apply_andersen_rescaling_velocity(integrator, i, kb, system::PotentialNBodySystem, p::AndersenThermostat)
@@ -382,11 +382,11 @@ end
382382
positions = get_position(sr, time)
383383
seriestype --> :scatter
384384
markersize --> 5
385-
385+
386386
for i in 1:n
387387
@series begin
388388
label --> "Body no. $i"
389-
389+
390390
if all(positions[3,:] .- positions[3,1] .< 1e-15)
391391
([positions[1,i]], [positions[2,i]])
392392
else

test/thermostat_test.jl

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@testset "Testing thermostats on liquid argon " begin
1+
@testset "Testing thermostats on liquid argon " begin
22
T = 120.0 # °K
33
T0 = 90 # °K
44
kb = 8.3144598e-3 # kJ/(K*mol)
@@ -8,9 +8,9 @@
88
m = 39.95# Da
99
N = 125
1010
L = (m * N / ρ)^(1 / 3)#10.229σ
11-
R = 0.5 * L
11+
R = 0.5 * L
1212
v_dev = sqrt(kb * T / m)
13-
@testset "Andersen thermostat" begin
13+
@testset "Andersen thermostat" begin
1414
bodies = generate_bodies_in_cell_nodes(N, m, v_dev, L)
1515

1616
τ = 0.5e-3 # ps or 1e-12 s
@@ -22,15 +22,16 @@
2222
thermostat = AndersenThermostat(T0, 0.1/τ)
2323
simulation = NBodySimulation(lj_system, (t1, t2), PeriodicBoundaryConditions(L), thermostat, kb);
2424
result = run_simulation(simulation, VelocityVerlet(), dt=τ)
25-
2625

27-
T1 = temperature(result, t1)
26+
27+
T1 = temperature(result, t1)
2828
T2 = temperature(result, t2)
2929
ε = 0.5
3030
@test abs(T2 - T0) / T0 0.0 atol = ε
31+
@test result.solution.t == unique(result.solution.t)
3132
end
3233

33-
@testset "Berendsen thermostat" begin
34+
@testset "Berendsen thermostat" begin
3435
bodies = generate_bodies_in_cell_nodes(N, m, v_dev, L)
3536

3637
τ = 0.5e-3
@@ -43,13 +44,13 @@
4344
pbc = CubicPeriodicBoundaryConditions(L)
4445
simulation = NBodySimulation(lj_system, (t1, t2), pbc, thermostat, kb);
4546
result = run_simulation(simulation, VelocityVerlet(), dt=τ)
46-
47+
4748
T2 = temperature(result, t2)
4849
ε = 0.1
4950
@test abs(T2 - T0) / T 0.0 atol = ε
5051
end
5152

52-
@testset "Nose-Hoover thermostat" begin
53+
@testset "Nose-Hoover thermostat" begin
5354
bodies = generate_bodies_in_cell_nodes(N, m, v_dev, L)
5455

5556
τ = 0.5e-3
@@ -62,13 +63,13 @@
6263
pbc = CubicPeriodicBoundaryConditions(L)
6364
simulation = NBodySimulation(lj_system, (t1, t2), pbc, thermostat, kb);
6465
result = run_simulation(simulation, VelocityVerlet(), dt=τ)
65-
66+
6667
T2 = temperature(result, t2)
6768
ε = 0.5
6869
@test abs(T2 - T0) / T0 0.0 atol = ε
6970
end
7071

71-
@testset "Langevin thermostat" begin
72+
@testset "Langevin thermostat" begin
7273
bodies = generate_bodies_in_cell_nodes(N, m, v_dev, L)
7374

7475
τ = 0.5e-3
@@ -81,9 +82,9 @@
8182
pbc = CubicPeriodicBoundaryConditions(L)
8283
simulation = NBodySimulation(lj_system, (t1, t2), pbc, thermostat, kb);
8384
result = run_simulation(simulation, EM(), dt=τ)
84-
85+
8586
T2 = temperature(result, t2)
8687
ε = 0.5
8788
@test abs(T2 - T0) / T0 0.0 atol = ε
8889
end
89-
end
90+
end

0 commit comments

Comments
 (0)