Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

format SciML Style #55

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style = "sciml"
42 changes: 42 additions & 0 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
name: format-check

on:
push:
branches:
- 'master'
- 'release-'
tags: '*'
pull_request:

jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
julia-version: [1]
julia-arch: [x86]
os: [ubuntu-latest]
steps:
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.julia-version }}

- uses: actions/checkout@v1
- name: Install JuliaFormatter and format
# This will use the latest version by default but you can set the version like so:
#
# julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter", version="0.13.0"))'
run: |
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
julia -e 'using JuliaFormatter; format(".", verbose=true)'
- name: Format check
run: |
julia -e '
out = Cmd(`git diff --name-only`) |> read |> String
if out == ""
exit(0)
else
@error "Some files have not been formatted !!!"
write(stdout, out)
exit(1)
end'
24 changes: 10 additions & 14 deletions docs/make.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,14 @@ using Documenter, NBodySimulator

include("pages.jl")

makedocs(
sitename="NbodySimulator.jl",
authors="Chris Rackauckas",
modules=[NBodySimulator],
clean=true,doctest=false,
format = Documenter.HTML(analytics = "UA-90474609-3",
assets = ["assets/favicon.ico"],
canonical="https://nbodysimulator.sciml.ai/stable/"),
pages=pages
)
makedocs(sitename = "NbodySimulator.jl",
authors = "Chris Rackauckas",
modules = [NBodySimulator],
clean = true, doctest = false,
format = Documenter.HTML(analytics = "UA-90474609-3",
assets = ["assets/favicon.ico"],
canonical = "https://nbodysimulator.sciml.ai/stable/"),
pages = pages)

deploydocs(
repo = "github.com/SciML/NBodySimulator.jl.git";
push_preview = true
)
deploydocs(repo = "github.com/SciML/NBodySimulator.jl.git";
push_preview = true)
4 changes: 2 additions & 2 deletions docs/pages.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Put in a separate page so it can be used by SciMLDocs.jl

pages=[
pages = [
"Home" => "index.md",
"examples.md",
"nbodysimulator.md"
"nbodysimulator.md",
]
26 changes: 15 additions & 11 deletions examples/liquid_argon.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,23 +3,27 @@ using NBodySimulator, StaticArrays
function generate_bodies_in_line(n::Int, m::Real, v_dev::Real, L::Real)
dL = L / (ceil(n^(1 / 3)))
n_line = floor(Int, L / dL)
rng = MersenneTwister(n);
rng = MersenneTwister(n)
velocities = v_dev * randn(rng, Float64, (3, n_line))
bodies = MassBody[]
x = y = L / 2
for i = 1:n_line
for i in 1:n_line
r = SVector(x, y, i * dL)
v = SVector{3}(velocities[:,i])
v = SVector{3}(velocities[:, i])
body = MassBody(r, v, m)
push!(bodies, body)
push!(bodies, body)
end
return bodies
end

function generate_random_directions(n::Int)
theta = acos.(1 - 2 * rand(n));
phi = 2 * pi * rand(n);
directions = [@SVector [sin(theta[i]) .* cos(phi[i]), sin(theta[i]) .* sin(phi[i]), cos(theta[i])] for i = 1:n]
theta = acos.(1 - 2 * rand(n))
phi = 2 * pi * rand(n)
directions = [@SVector [
sin(theta[i]) .* cos(phi[i]),
sin(theta[i]) .* sin(phi[i]),
cos(theta[i]),
] for i in 1:n]
end

units = :real
Expand All @@ -33,8 +37,8 @@ const σ = 3.4e-10 # m
const ρ = 1374 # kg/m^3
const m = 39.95 * 1.6747 * 1e-27 # kg
const N = 216#floor(Int, ρ * L^3 / m)
const L = (m*N/ρ)^(1/3)#10.229σ
const R = 0.5*L
const L = (m * N / ρ)^(1 / 3)#10.229σ
const R = 0.5 * L
const v_dev = sqrt(kb * T / m)
const τ = 0.5e-15 # σ/v
const t1 = 0τ
Expand All @@ -48,7 +52,7 @@ pbc = CubicPeriodicBoundaryConditions(L)
lj_system = PotentialNBodySystem(bodies, Dict(:lennard_jones => jl_parameters));
simulation = NBodySimulation(lj_system, (t1, t2), pbc, kb);
#result = run_simulation(simulation, Tsit5())
result = @time run_simulation(simulation, VelocityVerlet(), dt=τ)
result = @time run_simulation(simulation, VelocityVerlet(), dt = τ)

#=
using Plots
Expand Down Expand Up @@ -95,4 +99,4 @@ write(file, "ts", ts)
write(file, "grf", grf)
write(file, "dr2", dr2)
close(file)
=#
=#
15 changes: 6 additions & 9 deletions examples/liquid_argon_omm_units.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ const T0 = 90.0 # °K
const kb = 8.3144598e-3 # kJ/(K*mol)
const ϵ = T * kb
const σ = 0.34 # nm
const ρ = 1374/1.6747# Da/nm^3
const ρ = 1374 / 1.6747# Da/nm^3
const m = 39.95# Da
const N = 8
const L = (m*N/ρ)^(1/3)#10.229σ
const R = 0.5*L
const L = (m * N / ρ)^(1 / 3)#10.229σ
const R = 0.5 * L
const v_dev = sqrt(kb * T / m)
const bodies = generate_bodies_in_cell_nodes(N, m, v_dev, L)

Expand All @@ -28,23 +28,21 @@ const pbc = CubicPeriodicBoundaryConditions(L)
const simulation = NBodySimulation(lj_system, (t1, t2), pbc, thermostat, kb);
#result = @time run_simulation(simulation, VelocityVerlet(), dt=τ)
#result = @time run_simulation_sde(simulation, ISSEM(symplectic=true,theta=0.5))
result = @time run_simulation(simulation, EM(), dt=τ)
result = @time run_simulation(simulation, EM(), dt = τ)

#(rs, grf) = rdf(result)
#(ts, dr2) = msd(result)

t = t1:τ:result.solution.t[end-1]
t = t1:τ:result.solution.t[end - 1]
temper = @time temperature.(result, t)


#using Plots
#pl=plot(t, temper, ylim=[0,200], xlabel="t, ps", ylabel = "T, °K", label="Temperature, °K", linewidth=2)
#plot!(pl, t, T0*ones(length(t)), label = "90 °K", linewidth=2)
#plot!(pl, title="Andersen thermostat at dt*v=$(thermostat.ν*τ) ")
#plot!(pl, title="Berendsen thermostat at tau=$(thermostat.τ) ps")
#plot!(pl, title="Nose-Hoover thermostat at tau=$(thermostat.τ) ps")


time_now = Dates.format(now(), "yyyy_mm_dd_HH_MM_SS")
Nactual = length(bodies)
timesteps = round(length(result.solution.t))
Expand All @@ -54,7 +52,6 @@ timesteps = round(length(result.solution.t))
#using JLD
#save("d:/nosehoover thermostat for water liquid argon $T0 and $(thermostat.τ) _$time_now.jld", "t",t, "temper", temper, "T0", T0, "τ", thermostat.τ)


#=
using MAT

Expand All @@ -74,4 +71,4 @@ end
#write(file, "grf", grf)
#write(file, "dr2", dr2)
close(file)
=#
=#
12 changes: 6 additions & 6 deletions examples/liquid_argon_reduced.jl
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ const σ = 3.4e-10 # m
const ρ = 1374 # kg/m^3
const m = 39.95 * 1.6747 * 1e-27 # kg
const N = 216#floor(Int, ρ * L^3 / m)
const L = (m*N/ρ)^(1/3)#10.229σ
const R = 2.25σ
const L = (m * N / ρ)^(1 / 3)#10.229σ
const R = 2.25σ
const v_dev = sqrt(kb * T / m)
const τ = 0.5e-15 # σ/v, fs
const t1 = 0.0
Expand All @@ -26,9 +26,10 @@ const _t2 = t2 * sqrt(ϵ / m) / σ
bodies = generate_bodies_in_cell_nodes(N, _m, _v, _L)
parameters = LennardJonesParameters(_ϵ, _σ, _R)
lj_system = PotentialNBodySystem(bodies, Dict(:lennard_jones => parameters));
simulation = NBodySimulation(lj_system, (_t1, _t2), CubicPeriodicBoundaryConditions(_L), _ϵ/T);
simulation = NBodySimulation(lj_system, (_t1, _t2), CubicPeriodicBoundaryConditions(_L),
_ϵ / T);
#result = run_simulation(simulation, Tsit5())
result = @time run_simulation(simulation, VelocityVerlet(), dt=_τ)
result = @time run_simulation(simulation, VelocityVerlet(), dt = _τ)

#(rs, grf) = rdf(result)
#(ts, dr2) = msd(result)
Expand All @@ -37,9 +38,8 @@ result = @time run_simulation(simulation, VelocityVerlet(), dt=_τ)
#plot(rs, grf, xlim=[0, 0.4999_L], label=["Radial distribution function"],ylabel="g(r)", xlabel="r")
#plot(rs/_σ, grf, xlim=[0, 0.4999_L/_σ], label=["Radial distribution function"],ylabel="g(r)", xlabel="r/sigma")


#time_now = Dates.format(now(), "yyyy_mm_dd_HH_MM_SS")
#Nactual = length(bodies)
#timesteps = round(length(result.solution.t))

#@time save_to_pdb(result, "D:/liquid argon simulation $Nactual molecules and $timesteps steps $time_now.pdb" )
#@time save_to_pdb(result, "D:/liquid argon simulation $Nactual molecules and $timesteps steps $time_now.pdb" )
12 changes: 5 additions & 7 deletions examples/liquid_argon_sde.jl
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@ T0 = 90
kb = 8.3144598e-3 # kJ/(K*mol)
ϵ = T * kb
σ = 0.34 # nm
ρ = 1374/1.6747# Da/nm^3
ρ = 1374 / 1.6747# Da/nm^3
m = 39.95# Da
N = 216
L = (m*N/ρ)^(1/3)#10.229σ
R = 0.5*L
L = (m * N / ρ)^(1 / 3)#10.229σ
R = 0.5 * L
v_dev = sqrt(kb * T / m)
bodies = generate_bodies_in_cell_nodes(N, m, v_dev, L)

Expand All @@ -26,22 +26,20 @@ thermostat = LangevinThermostat(T0, 10.0)
pbc = CubicPeriodicBoundaryConditions(L)
simulation = NBodySimulation(lj_system, (t1, t2), pbc, thermostat, kb);
#result = @time run_simulation(simulation, VelocityVerlet(), dt=τ)
result = @time run_simulation_sde(simulation, EM(), dt=τ)
result = @time run_simulation_sde(simulation, EM(), dt = τ)

#=
time_now = Dates.format(now(), "yyyy_mm_dd_HH_MM_SS")
Nactual = length(bodies)
timesteps = round(length(result.solution.t))


using Plots
t = t1:τ:result.solution.t[end-1]
temper = temperature.(result, t)
pl=plot(t, temper, ylim=[0,500], xlabel="t, ps", ylabel = "T, °K", label="Temperature, °K", linewidth=2)
plot!(pl, t, T0*ones(length(t)), label = "$T0 °K", linewidth=2)
plot!(pl, title="Langevin thermostat at gamma=$(thermostat.γ) 1/ps")


using JLD
save("d:/$(typeof(thermostat)) thermostat for water $T0 _$time_now.jld", "t",t, "temper", temper, "T0", T0, "thermostat", thermostat)
=#
=#