Skip to content

Commit 784c0b5

Browse files
Merge pull request #18 from ChrisRackauckas-Claude/runic-formatting
Switch from JuliaFormatter to Runic.jl for code formatting
2 parents 676858a + 81a3298 commit 784c0b5

16 files changed

Lines changed: 122 additions & 74 deletions

.JuliaFormatter.toml

Lines changed: 0 additions & 3 deletions
This file was deleted.

.github/workflows/FormatCheck.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
name: format-check
2+
3+
on:
4+
push:
5+
branches:
6+
- 'master'
7+
- 'main'
8+
- 'release-'
9+
tags: '*'
10+
pull_request:
11+
12+
jobs:
13+
runic:
14+
runs-on: ubuntu-latest
15+
steps:
16+
- uses: actions/checkout@v4
17+
- uses: fredrikekre/runic-action@v1
18+
with:
19+
version: '1'

docs/make.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ makedocs(;
1717
pages = [
1818
"Home" => "index.md",
1919
"Examples" => "examples.md",
20-
"Mathematical Details" => "math.md"
20+
"Mathematical Details" => "math.md",
2121
]
2222
)
2323

src/FiniteVolumeMethod1D.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,4 +25,4 @@ include("solve.jl")
2525
(obj::Returns)(@nospecialize(args...); @nospecialize(kw...)) = obj.value
2626
end
2727

28-
end # module
28+
end # module

src/boundary_conditions.jl

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ Base.@kwdef struct Dirichlet{F, P} <: AbstractBoundaryCondition{F, P}
2929
end
3030
Dirichlet(f::Function) = Dirichlet(f, nothing)
3131
Dirichlet(v::Number) =
32-
let v = v
33-
Dirichlet((u, t, p) -> oftype(u, v))
34-
end
32+
let v = v
33+
Dirichlet((u, t, p) -> oftype(u, v))
34+
end
3535

3636
@doc raw"""
3737
Neumann{F,P} <: AbstractBoundaryCondition{F,P}
@@ -60,9 +60,9 @@ Base.@kwdef struct Neumann{F, P} <: AbstractBoundaryCondition{F, P}
6060
Neumann(f::F, p::P = nothing) where {F, P} = new{F, P}(f, p)
6161
end
6262
Neumann(v::Number) =
63-
let v = v
64-
Neumann((u, t, p) -> oftype(u, v))
65-
end
63+
let v = v
64+
Neumann((u, t, p) -> oftype(u, v))
65+
end
6666

6767
is_dirichlet(::AbstractBoundaryCondition) = false
6868
is_dirichlet(::Dirichlet) = true

src/equations.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,12 @@ function pde_odes!(dudt, u, prob::P, t) where {P}
3737
hᵢ = h[i]
3838
hᵢ₋₁ = h[i - 1]
3939
Rᵢ = R(u[i], xᵢ, t, Rp)
40-
dudt[i] = inv(Vᵢ) * (D̄ᵢᵢ₊₁ * ((u[i + 1] - u[i]) / hᵢ) -
41-
D̄ᵢ₋₁ᵢ * ((u[i] - u[i - 1]) / hᵢ₋₁)) + Rᵢ
40+
dudt[i] = inv(Vᵢ) * (
41+
D̄ᵢᵢ₊₁ * ((u[i + 1] - u[i]) / hᵢ) -
42+
D̄ᵢ₋₁ᵢ * ((u[i] - u[i - 1]) / hᵢ₋₁)
43+
) + Rᵢ
4244
end
43-
if !is_dirichlet(rhs)
45+
return if !is_dirichlet(rhs)
4446
b = mesh_points[end]
4547
xₙ₋₁ = mesh_points[end - 1]
4648
Vₙ = V[end]
@@ -58,16 +60,16 @@ end
5860

5961
jacobian_sparsity(prob::FVMProblem) = jacobian_sparsity(prob.geometry.mesh_points)
6062
function jacobian_sparsity(pts)
61-
num_nnz = 3(length(pts) - 2) + 4 # 3 neighbours for each interior node, 2 from each boundary node
63+
num_nnz = 3(length(pts) - 2) + 4 # 3 neighbours for each interior node, 2 from each boundary node
6264
I = zeros(Int64, num_nnz)
6365
J = zeros(Int64, num_nnz)
6466
V = ones(num_nnz)
65-
# The left boundary node
67+
# The left boundary node
6668
I[1] = firstindex(pts)
6769
J[1] = firstindex(pts)
6870
I[2] = firstindex(pts)
6971
J[2] = firstindex(pts) + 1
70-
# The interior nodes
72+
# The interior nodes
7173
ctr = 3
7274
for i in (firstindex(pts) + 1):(lastindex(pts) - 1)
7375
I[ctr] = i
@@ -80,7 +82,7 @@ function jacobian_sparsity(pts)
8082
J[ctr] = i - 1
8183
ctr += 1
8284
end
83-
# The right boundary node
85+
# The right boundary node
8486
I[ctr] = lastindex(pts)
8587
J[ctr] = lastindex(pts)
8688
ctr += 1

src/problem.jl

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,9 @@ Base.@kwdef struct FVMProblem{T, DF, DP, RF, RP, L, R, IC, FT}
5656
final_time::FT
5757
end
5858
function FVMProblem(mesh_points, lhs, rhs; kwargs...)
59-
FVMProblem(;
59+
return FVMProblem(;
6060
geometry = FVMGeometry(mesh_points),
6161
boundary_conditions = BoundaryConditions(lhs, rhs),
62-
kwargs...)
62+
kwargs...
63+
)
6364
end

src/solve.jl

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
1-
function SciMLBase.ODEProblem(prob::FVMProblem;
1+
function SciMLBase.ODEProblem(
2+
prob::FVMProblem;
23
specialization::Type{S} = SciMLBase.AutoSpecialize,
34
jac_prototype = jacobian_sparsity(prob),
4-
kwargs...) where {S}
5+
kwargs...
6+
) where {S}
57
initial_time = prob.initial_time
68
final_time = prob.final_time
79
time_span = (initial_time, final_time)
@@ -12,7 +14,8 @@ function SciMLBase.ODEProblem(prob::FVMProblem;
1214
cb = CallbackSet(lhs_cb, rhs_cb)
1315
f = ODEFunction{true, S}(pde_odes!; jac_prototype = jac_prototype)
1416
ode_problem = ODEProblem{true, S}(
15-
f, initial_condition, time_span, prob; callback = cb, kwargs...)
17+
f, initial_condition, time_span, prob; callback = cb, kwargs...
18+
)
1619
return ode_problem
1720
end
1821

@@ -60,5 +63,5 @@ function update_rhs!(integrator)
6063
end
6164

6265
function CommonSolve.init(prob::FVMProblem, alg; kwargs...)
63-
CommonSolve.init(ODEProblem(prob; kwargs...), alg; kwargs...)
66+
return CommonSolve.init(ODEProblem(prob; kwargs...), alg; kwargs...)
6467
end

test/dirichlet_source.jl

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ using OrdinaryDiffEq
55
using CairoMakie
66
using ReferenceTests
77

8-
# p. 145 Constanda
9-
# uₜ = uₓₓ + π²exp[-24π²t]sin(5πx), 0 < x < 1
8+
# p. 145 Constanda
9+
# uₜ = uₓₓ + π²exp[-24π²t]sin(5πx), 0 < x < 1
1010
# u(0, t) = 0
1111
# u(1, t) = 0
1212
# u(x, 0) = 3sin(4πx)
1313

1414
function exact_u(x, t)
15-
return 3exp(-16π^2*t)*sin(4π*x) + exp(-25π^2*t)*(exp^2*t)-1)*sin(5π*x)
15+
return 3exp(-16π^2 * t) * sin(4π * x) + exp(-25π^2 * t) * (exp^2 * t) - 1) * sin(5π * x)
1616
end
1717

1818
reaction_function = (u, x, t, p) -> p[1] * exp(-p[2] * t) * sin(p[3] * x)
@@ -21,18 +21,20 @@ diffusion_function = (u, x, t, p) -> one(u)
2121
lhs = Dirichlet(0.0)
2222
rhs = Dirichlet(0.0)
2323
mesh_points = LinRange(0, 1, 500)
24-
ic_ff = x -> 3sin(4π*x)
24+
ic_ff = x -> 3sin(4π * x)
2525
initial_condition = ic_ff.(mesh_points)
2626
final_time = 0.05
27-
prob = FVMProblem(mesh_points, lhs, rhs;
27+
prob = FVMProblem(
28+
mesh_points, lhs, rhs;
2829
diffusion_function,
2930
reaction_function,
3031
reaction_parameters,
3132
initial_condition,
32-
final_time)
33+
final_time
34+
)
3335
sol = solve(prob, TRBDF2(linsolve = KLUFactorization()), saveat = 0.001)
3436
exact_sol = [exact_u.(mesh_points, sol.t[i]) for i in eachindex(sol)]
35-
@test reduce(hcat, sol.u) reduce(hcat, exact_sol) rtol = 1e-1
37+
@test reduce(hcat, sol.u) reduce(hcat, exact_sol) rtol = 1.0e-1
3638

3739
let t_range = LinRange(0.0, final_time, 250)
3840
fig = Figure(fontsize = 33)

test/fisher.jl

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,23 @@ ic_f(x) = x < 0 ? 1.0 : 1 / 2
2323
Dt = Differential(t)
2424
Dx = Differential(x)
2525
Dxx = Differential(x)^2
26-
eqs = [Dt(u(t, x)) ~
27-
Dx(
28-
(inv(θ₁ * u(t, x)) + θ₂ * inv(u(t, x)^2) + θ₃ * inv(u(t, x)^3)) *
29-
Dx(u(t, x))
30-
) +
31-
β * K * u(t, x) * (1 - u(t, x) / K)]
32-
bcs = [Dx(u(t, 2π)) ~ 0.0,
26+
eqs = [
27+
Dt(u(t, x)) ~
28+
Dx(
29+
(inv(θ₁ * u(t, x)) + θ₂ * inv(u(t, x)^2) + θ₃ * inv(u(t, x)^3)) *
30+
Dx(u(t, x))
31+
) +
32+
β * K * u(t, x) * (1 - u(t, x) / K),
33+
]
34+
bcs = [
35+
Dx(u(t, 2π)) ~ 0.0,
3336
Dx(u(t, -2π)) ~ 0.0,
34-
u(0, x) ~ ic_f(x)]
35-
domains = [t Interval(0.0, 1.0),
36-
x Interval(-2π, 2π)]
37+
u(0, x) ~ ic_f(x),
38+
]
39+
domains = [
40+
t Interval(0.0, 1.0),
41+
x Interval(-2π, 2π),
42+
]
3743
@named pdesys = PDESystem(
3844
eqs,
3945
bcs,
@@ -44,8 +50,8 @@ domains = [t ∈ Interval(0.0, 1.0),
4450
θ₁ => 1.0,
4551
θ₂ => 50.0,
4652
θ₃ => 3.0,
47-
β => 1e-3,
48-
K => 2.0
53+
β => 1.0e-3,
54+
K => 2.0,
4955
]
5056
)
5157
discretisation = MOLFiniteDifference([x => 0.1], t)
@@ -59,7 +65,7 @@ solu = sol[u(t, x)]
5965
diffusion_function = (u, x, t, p) -> inv(p[1] * u) + p[2] * inv(u^2) + p[3] * inv(u^3)
6066
reaction_function = (u, x, t, p) -> p[1] * p[2] * u * (1 - u / p[2])
6167
diffusion_parameters = [1.0, 50.0, 3.0]
62-
reaction_parameters = [1e-3, 2.0]
68+
reaction_parameters = [1.0e-3, 2.0]
6369
mesh_points = solx
6470
initial_condition = ic_f.(mesh_points)
6571
final_time = 1.0
@@ -78,7 +84,7 @@ fvm_prob = FVMProblem(
7884
)
7985
fvm_sol = solve(fvm_prob, TRBDF2(), saveat = solt)
8086
fvm_solu = reduce(hcat, fvm_sol.u)'
81-
@test solu fvm_solu rtol = 1e-2
87+
@test solu fvm_solu rtol = 1.0e-2
8288

8389
let sol = fvm_sol, t_range = LinRange(0.0, final_time, 250)
8490
fig = Figure(fontsize = 33)

0 commit comments

Comments
 (0)