Skip to content

Commit

Permalink
Print an error if non-positive dt is detected
Browse files Browse the repository at this point in the history
  • Loading branch information
kbarros committed Nov 15, 2023
1 parent 72b35a6 commit c79bd51
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 6 deletions.
10 changes: 8 additions & 2 deletions src/Integrators.jl
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ mutable struct Langevin
kT :: Float64
end

Langevin(Δt; λ, kT) = Langevin(Δt, λ, kT)
function Langevin(Δt; λ, kT)
Δt <= 0 && error("Select positive Δt")
return Langevin(Δt, λ, kT)
end

Base.copy(dyn::Langevin) = Langevin(dyn.Δt, dyn.λ, dyn.kT)

Expand All @@ -41,7 +44,10 @@ mutable struct ImplicitMidpoint
atol :: Float64
end

ImplicitMidpoint(Δt; atol=1e-12) = ImplicitMidpoint(Δt, atol)
function ImplicitMidpoint(Δt; atol=1e-12)
Δt <= 0 && error("Select positive Δt")
return ImplicitMidpoint(Δt, atol)
end



Expand Down
4 changes: 2 additions & 2 deletions test/test_jet.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
sampler = LocalSampler(kT=0.2; propose)
@test_opt step!(sys, sampler)

langevin = Langevin(0.01, kT=0.2, λ=0.1)
langevin = Langevin(0.01; kT=0.2, λ=0.1)
@test_opt step!(sys, langevin)

integrator = ImplicitMidpoint(0.01)
Expand Down Expand Up @@ -48,7 +48,7 @@ end
step!(sys, sampler)
@test 0 == @allocated step!(sys, sampler)

langevin = Langevin(0.01, kT=0.2, λ=0.1)
langevin = Langevin(0.01; kT=0.2, λ=0.1)
step!(sys, langevin)
@test 0 == @allocated step!(sys, langevin)

Expand Down
4 changes: 2 additions & 2 deletions test/test_samplers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@
collect_dur = 100.0

sys = su3_anisotropy_model(; D, L, seed=0)
langevin = Langevin(Δt; kT=0.0, λ)
langevin = Langevin(Δt; kT=0, λ)

for kT in kTs
langevin.kT = kT
Expand All @@ -96,7 +96,7 @@
collect_dur = 200.0

sys = su5_anisotropy_model(; D, L, seed=0)
langevin = Langevin(Δt; kT=0.0, λ)
langevin = Langevin(Δt; kT=0, λ)

for kT kTs
langevin.kT = kT
Expand Down

0 comments on commit c79bd51

Please sign in to comment.