-
-
Notifications
You must be signed in to change notification settings - Fork 3
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
Fix type stabilities for FVMSystems #48
Conversation
Codecov ReportPatch coverage:
Additional details and impacted files@@ Coverage Diff @@
## main #48 +/- ##
==========================================
+ Coverage 92.98% 93.75% +0.76%
==========================================
Files 20 20
Lines 998 1057 +59
==========================================
+ Hits 928 991 +63
+ Misses 70 66 -4
☔ View full report in Codecov by Sentry. |
Just to show the difference: Consider this benchmark using FiniteVolumeMethod, OrdinaryDiffEq, LinearSolve, BenchmarkTools, DelaunayTriangulation
const FVM = FiniteVolumeMethod
tri = triangulate_rectangle(0, 1, 0, 1, 25, 25, single_boundary=false)
mesh = FVMGeometry(tri)
Φ_bot = (x, y, t, u, p) -> -1 / 4 * exp(-x - t / 2)
Φ_right = (x, y, t, u, p) -> 1 / 4 * exp(-1 - y - t / 2)
Φ_top = (x, y, t, u, p) -> exp(-1 - x - t / 2)
Φ_left = (x, y, t, u, p) -> -1 / 4 * exp(-y - t / 2)
Φ_bc_fncs = (Φ_bot, Φ_right, Φ_top, Φ_left)
Φ_bc_types = (Neumann, Neumann, Dirichlet, Neumann)
Φ_BCs = BoundaryConditions(mesh, Φ_bc_fncs, Φ_bc_types)
Ψ_bot = (x, y, t, u, p) -> exp(x + t / 2)
Ψ_right = (x, y, t, u, p) -> -1 / 4 * exp(1 + y + t / 2)
Ψ_top = (x, y, t, u, p) -> -1 / 4 * exp(1 + x + t / 2)
Ψ_left = (x, y, t, u, p) -> exp(y + t / 2)
Ψ_bc_fncs = (Ψ_bot, Ψ_right, Ψ_top, Ψ_left)
Ψ_bc_types = (Dirichlet, Neumann, Neumann, Dirichlet)
Ψ_BCs = BoundaryConditions(mesh, Ψ_bc_fncs, Ψ_bc_types)
Φ_q = (x, y, t, α, β, γ, p) -> (-α[1] / 4, -β[1] / 4)
Ψ_q = (x, y, t, α, β, γ, p) -> (-α[2] / 4, -β[2] / 4)
Φ_S = (x, y, t, (Φ, Ψ), p) -> Φ^2 * Ψ - 2Φ
Ψ_S = (x, y, t, (Φ, Ψ), p) -> -Φ^2 * Ψ + Φ
Φ_exact = (x, y, t) -> exp(-x - y - t / 2)
Ψ_exact = (x, y, t) -> exp(x + y + t / 2)
Φ₀ = [Φ_exact(x, y, 0) for (x, y) in each_point(tri)]
Ψ₀ = [Ψ_exact(x, y, 0) for (x, y) in each_point(tri)]
Φ_prob = FVMProblem(mesh, Φ_BCs; flux_function=Φ_q, source_function=Φ_S,
initial_condition=Φ₀, final_time=5.0)
Ψ_prob = FVMProblem(mesh, Ψ_BCs; flux_function=Ψ_q, source_function=Ψ_S,
initial_condition=Ψ₀, final_time=5.0)
prob = FVMSystem(Φ_prob, Ψ_prob)
alg = TRBDF2(linsolve=KLUFactorization())
parallel = Val(false)
saveat = 0.1
@benchmark solve($prob, $alg, ; parallel=$parallel, saveat=$saveat) On this branch: BenchmarkTools.Trial: 69 samples with 1 evaluation.
Range (min … max): 68.157 ms … 100.711 ms ┊ GC (min … max): 0.00% … 28.19%
Time (median): 72.281 ms ┊ GC (median): 0.00%
Time (mean ± σ): 72.922 ms ± 4.346 ms ┊ GC (mean ± σ): 0.56% ± 3.39%
▁▄▄▄▄ ▄▄▄ █▁▄▄█▁█▁ ▁ ▁ █ ▁
▆▁▆█████▆███▆████████▁▆█▁█▆▆█▆▆█▁▁▁▁▁▁▁▁▆▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▆ ▁
68.2 ms Histogram: frequency by time 84.1 ms <
Memory estimate: 13.16 MiB, allocs estimate: 58802. Without: BenchmarkTools.Trial: 2 samples with 1 evaluation.
Range (min … max): 2.646 s … 2.736 s ┊ GC (min … max): 19.30% … 20.46%
Time (median): 2.691 s ┊ GC (median): 19.89%
Time (mean ± σ): 2.691 s ± 63.664 ms ┊ GC (mean ± σ): 19.89% ± 0.82%
█ █
█▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁▁█ ▁
2.65 s Histogram: frequency by time 2.74 s <
Memory estimate: 6.96 GiB, allocs estimate: 14403237. Yikes :) |
This was slowing things down significantly.