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

Fix type stabilities for FVMSystems #48

Merged
merged 67 commits into from
Sep 15, 2023
Merged

Fix type stabilities for FVMSystems #48

merged 67 commits into from
Sep 15, 2023

Conversation

DanielVandH
Copy link
Member

This was slowing things down significantly.

@codecov
Copy link

codecov bot commented Sep 15, 2023

Codecov Report

Patch coverage: 98.44% and project coverage change: +0.76% 🎉

Comparison is base (df43599) 92.98% compared to head (71ffbc3) 93.75%.
Report is 2 commits behind head on main.

❗ Current head 71ffbc3 differs from pull request most recent head 6cf7a45. Consider uploading reports for the commit 6cf7a45 to get more accurate results

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     
Files Changed Coverage Δ
src/problem.jl 94.76% <96.82%> (+4.32%) ⬆️
src/conditions.jl 99.13% <100.00%> (-0.04%) ⬇️
src/equations/boundary_edge_contributions.jl 98.48% <100.00%> (+0.12%) ⬆️
src/equations/individual_flux_contributions.jl 100.00% <100.00%> (ø)
src/utils.jl 83.78% <100.00%> (+15.36%) ⬆️

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

@DanielVandH
Copy link
Member Author

DanielVandH commented Sep 15, 2023

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 :)

@DanielVandH DanielVandH merged commit 9412ce0 into main Sep 15, 2023
0 of 3 checks passed
@DanielVandH DanielVandH deleted the syseff branch September 15, 2023 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant