diff --git a/.github/workflows/Downgrade.yml b/.github/workflows/Downgrade.yml index cc389dd..18b7ae4 100644 --- a/.github/workflows/Downgrade.yml +++ b/.github/workflows/Downgrade.yml @@ -17,4 +17,7 @@ jobs: uses: "SciML/.github/.github/workflows/downgrade.yml@v1" with: julia-version: "lts" + # SciMLTesting resolves test/Plotting's sub-env to latest versions in the same + # process that already loaded Core's floor SciMLBase, so only Core is floor-tested. + group: "Core" secrets: "inherit" diff --git a/src/equations.jl b/src/equations.jl index a78dfe2..ebdbbd0 100644 --- a/src/equations.jl +++ b/src/equations.jl @@ -61,8 +61,8 @@ end jacobian_sparsity(prob::FVMProblem) = jacobian_sparsity(prob.geometry.mesh_points) function jacobian_sparsity(pts) num_nnz = 3(length(pts) - 2) + 4 # 3 neighbours for each interior node, 2 from each boundary node - I = zeros(Int64, num_nnz) - J = zeros(Int64, num_nnz) + I = zeros(Int, num_nnz) + J = zeros(Int, num_nnz) V = ones(num_nnz) # The left boundary node I[1] = firstindex(pts) diff --git a/test/Plotting/Project.toml b/test/Plotting/Project.toml new file mode 100644 index 0000000..d97f1fe --- /dev/null +++ b/test/Plotting/Project.toml @@ -0,0 +1,32 @@ +[deps] +CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" +DomainSets = "5b8099bc-c8ec-5219-889f-1d9e522a28bf" +FiniteVolumeMethod1D = "cfdabe9e-7cc8-40e3-9725-d80209c3e763" +LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" +LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae" +MethodOfLines = "94925ecb-adb7-4558-8ed8-f975c56a0bf4" +ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" +NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec" +OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" +OrdinaryDiffEqSDIRK = "2d112036-d095-4a1e-ab9a-08536f3ecdbf" +ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf" +SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" +SciMLTesting = "09d9d899-5365-40a9-917a-5f67fddea283" +SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" +Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" + +[compat] +CairoMakie = "0.15.12" +DomainSets = "0.8.1" +LinearSolve = "3.87, 4.2.0, 5.1" +MethodOfLines = "0.11.13" +ModelingToolkit = "11.31.0" +NonlinearSolve = "4.17.1, 4.20.2" +OrdinaryDiffEq = "6.56, 7.1.1" +OrdinaryDiffEqSDIRK = "1.14, 2.7.1" +ReferenceTests = "0.10.6" +SafeTestsets = "0.0.1, 0.1" +SciMLTesting = "2.4" +SpecialFunctions = "2.8.0" +Test = "1" +julia = "1.10" diff --git a/test/Plotting/dirichlet_source.jl b/test/Plotting/dirichlet_source.jl new file mode 100644 index 0000000..0cc7032 --- /dev/null +++ b/test/Plotting/dirichlet_source.jl @@ -0,0 +1,13 @@ +using CairoMakie +using ReferenceTests +include(joinpath(@__DIR__, "..", "dirichlet_source.jl")) + +let t_range = LinRange(0.0, final_time, 250) + fig = Figure(fontsize = 33) + ax = Axis3(fig[1, 1], xlabel = L"x", ylabel = L"t", zlabel = L"z", azimuth = 0.8) + sol_u = [sol(t) for t in t_range] + surface!(ax, mesh_points, t_range, reduce(hcat, sol_u), colormap = :viridis) + fig_path = normpath(@__DIR__, "..", "..", "docs", "src", "figures") + @test_reference joinpath(fig_path, "dirichlet_source_surface.png") fig + fig +end diff --git a/test/Plotting/heat.jl b/test/Plotting/heat.jl new file mode 100644 index 0000000..279224c --- /dev/null +++ b/test/Plotting/heat.jl @@ -0,0 +1,13 @@ +using CairoMakie +using ReferenceTests +include(joinpath(@__DIR__, "..", "heat.jl")) + +let t_range = LinRange(0.0, final_time, 250) + fig = Figure(fontsize = 33) + ax = Axis(fig[1, 1], xlabel = L"x", ylabel = L"t") + sol_u = [sol(t) for t in t_range] + contourf!(ax, mesh_points, t_range, reduce(hcat, sol_u), colormap = :viridis) + fig_path = normpath(@__DIR__, "..", "..", "docs", "src", "figures") + @test_reference joinpath(fig_path, "heat_contour.png") fig + fig +end diff --git a/test/Plotting/porous_medium.jl b/test/Plotting/porous_medium.jl new file mode 100644 index 0000000..d517da7 --- /dev/null +++ b/test/Plotting/porous_medium.jl @@ -0,0 +1,46 @@ +using CairoMakie +using ReferenceTests +include(joinpath(@__DIR__, "..", "porous_medium.jl")) + +fig = Figure(size = (2150, 460), fontsize = 34) +ax = Axis( + fig[1, 1], xlabel = L"x", ylabel = L"u(x)", title = L"(a):$ $ Numerical solution", + titlealign = :left, width = 600, height = 300 +) +colors = [:red, :black, :blue, :darkgreen, :magenta, :orange] +[lines!(ax, mesh_points, sol.u[i], color = colors[i]) for i in eachindex(sol.t)] +ylims!(ax, -1.0e-6, 5) +xlims!(ax, -1, 1) +ax = Axis( + fig[1, 2], xlabel = L"x", ylabel = L"u(x)", title = L"(b):$ $ Exact solution", + titlealign = :left, width = 600, height = 300 +) +[lines!(ax, mesh_points, exact[i], color = colors[i]) for i in eachindex(sol.t)] +ylims!(ax, -1.0e-6, 5) +xlims!(ax, -1, 1) +ax = Axis( + fig[1, 3], xlabel = L"x", ylabel = L"u(x)", title = L"(c):$ $ Error", + titlealign = :left, width = 600, height = 300 +) +[ + lines!(ax, mesh_points, abs.(exact[i] .- sol.u[i]), color = colors[i]) + for i in eachindex(sol.t) +] +ylims!(ax, -1.0e-6, 0.5) +xlims!(ax, -1, 1) +fig_path = normpath(@__DIR__, "..", "figures") +@test_reference joinpath(fig_path, "porous_comparison.png") fig + +let t_range = LinRange(0.0, final_time, 250) + fig = Figure(fontsize = 33) + ax = Axis3(fig[1, 1], xlabel = L"x", ylabel = L"t", zlabel = L"z") + sol_u = [sol(t) for t in t_range] + in_int_range = findall(x -> abs(x) < 1, mesh_points) # Makie won't clip the plot to (-1, 1) + surface!( + ax, mesh_points[in_int_range], t_range, + reduce(hcat, sol_u)[in_int_range, :], colormap = :viridis + ) + xlims!(ax, -1, 1) + fig_path = normpath(@__DIR__, "..", "..", "docs", "src", "figures") + @test_reference joinpath(fig_path, "porous_surface.png") fig +end diff --git a/test/Plotting/robin_diffusion.jl b/test/Plotting/robin_diffusion.jl new file mode 100644 index 0000000..f355aec --- /dev/null +++ b/test/Plotting/robin_diffusion.jl @@ -0,0 +1,12 @@ +using CairoMakie +using ReferenceTests +include(joinpath(@__DIR__, "..", "robin_diffusion.jl")) + +let t_range = LinRange(0.0, final_time, 250) + fig = Figure(fontsize = 33) + ax = Axis3(fig[1, 1], xlabel = L"x", ylabel = L"t", zlabel = L"z", azimuth = 0.8) + sol_u = [sol(t) for t in t_range] + surface!(ax, mesh_points, t_range, reduce(hcat, sol_u), colormap = :viridis) + fig_path = normpath(@__DIR__, "..", "..", "docs", "src", "figures") + @test_reference joinpath(fig_path, "robin_diffusion_surface.png") fig +end diff --git a/test/Project.toml b/test/Project.toml index dc64bfe..c260ded 100644 --- a/test/Project.toml +++ b/test/Project.toml @@ -1,14 +1,9 @@ [deps] -CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0" -DomainSets = "5b8099bc-c8ec-5219-889f-1d9e522a28bf" LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e" LinearSolve = "7ed4a6bd-45f5-4d41-b270-4a48e9bafcae" -MethodOfLines = "94925ecb-adb7-4558-8ed8-f975c56a0bf4" -ModelingToolkit = "961ee093-0014-501f-94e3-6117800e7a78" NonlinearSolve = "8913a72c-1f9b-4ce2-8d82-65094dcecaec" OrdinaryDiffEq = "1dea7af3-3e70-54e6-95c3-0bf5283fa5ed" OrdinaryDiffEqSDIRK = "2d112036-d095-4a1e-ab9a-08536f3ecdbf" -ReferenceTests = "324d217c-45ce-50fc-942e-d289b448e8cf" SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f" SciMLBase = "0bca4576-84f4-4d90-8ffe-ffa030f20462" SciMLTesting = "09d9d899-5365-40a9-917a-5f67fddea283" @@ -17,15 +12,10 @@ SpecialFunctions = "276daf66-3868-5448-9aa4-cd146d93841b" Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40" [compat] -CairoMakie = "0.15.12" -DomainSets = "0.8.1" LinearSolve = "3.87, 4.2.0, 5.1" -MethodOfLines = "0.11.13" -ModelingToolkit = "11.31.0" NonlinearSolve = "4.17.1, 4.20.2" OrdinaryDiffEq = "6.56, 7.1.1" OrdinaryDiffEqSDIRK = "1.14, 2.7.1" -ReferenceTests = "0.10.6" SafeTestsets = "0.0.1, 0.1" SciMLBase = "3.18" SciMLTesting = "2.4" diff --git a/test/dirichlet_source.jl b/test/dirichlet_source.jl index d4e69fa..ef24277 100644 --- a/test/dirichlet_source.jl +++ b/test/dirichlet_source.jl @@ -3,8 +3,6 @@ using LinearAlgebra using LinearSolve using OrdinaryDiffEq using OrdinaryDiffEqSDIRK -using CairoMakie -using ReferenceTests # p. 145 Constanda # uₜ = uₓₓ + π²exp[-24π²t]sin(5πx), 0 < x < 1 @@ -39,13 +37,3 @@ sol = solve( ) exact_sol = [exact_u.(mesh_points, sol.t[i]) for i in eachindex(sol.t)] @test reduce(hcat, sol.u) ≈ reduce(hcat, exact_sol) rtol = 1.0e-1 - -let t_range = LinRange(0.0, final_time, 250) - fig = Figure(fontsize = 33) - ax = Axis3(fig[1, 1], xlabel = L"x", ylabel = L"t", zlabel = L"z", azimuth = 0.8) - sol_u = [sol(t) for t in t_range] - surface!(ax, mesh_points, t_range, reduce(hcat, sol_u), colormap = :viridis) - fig_path = normpath(@__DIR__, "..", "docs", "src", "figures") - @test_reference joinpath(fig_path, "dirichlet_source_surface.png") fig - fig -end diff --git a/test/heat.jl b/test/heat.jl index c682e93..a8f1269 100644 --- a/test/heat.jl +++ b/test/heat.jl @@ -1,8 +1,6 @@ using FiniteVolumeMethod1D using OrdinaryDiffEq using OrdinaryDiffEqSDIRK -using ReferenceTests -using CairoMakie using LinearSolve function exact2(x, t) @@ -30,13 +28,3 @@ prob = FVMProblem( sol = solve(prob, TRBDF2(linsolve = KLUFactorization())) exact_sol = [exact2.(mesh_points, sol.t[i]) for i in eachindex(sol.t)] @test reduce(hcat, sol.u) ≈ reduce(hcat, exact_sol) rtol = 1.0e-2 - -let t_range = LinRange(0.0, final_time, 250) - fig = Figure(fontsize = 33) - ax = Axis(fig[1, 1], xlabel = L"x", ylabel = L"t") - sol_u = [sol(t) for t in t_range] - contourf!(ax, mesh_points, t_range, reduce(hcat, sol_u), colormap = :viridis) - fig_path = normpath(@__DIR__, "..", "docs", "src", "figures") - @test_reference joinpath(fig_path, "heat_contour.png") fig - fig -end diff --git a/test/ode_problem.jl b/test/ode_problem.jl index ebb5f34..2ebd632 100644 --- a/test/ode_problem.jl +++ b/test/ode_problem.jl @@ -28,6 +28,7 @@ prob = FVMProblem(; ) J = FVM.jacobian_sparsity(prob) @test J == FVM.jacobian_sparsity(mesh_points) +@test J isa SparseMatrixCSC{Float64, Int} _J = zeros(length(mesh_points), length(mesh_points)) for i in eachindex(mesh_points) if i == 1 diff --git a/test/porous_medium.jl b/test/porous_medium.jl index 3fbf585..1868536 100644 --- a/test/porous_medium.jl +++ b/test/porous_medium.jl @@ -1,8 +1,6 @@ using FiniteVolumeMethod1D using OrdinaryDiffEq using OrdinaryDiffEqSDIRK -using CairoMakie -using ReferenceTests using SpecialFunctions FVM = FiniteVolumeMethod1D @@ -45,46 +43,3 @@ prob = FVMProblem( sol = solve(prob, TRBDF2(); saveat = saveat) exact = [exact_solution.(mesh_points, sol.t[i]) for i in eachindex(sol.t)] @test exact ≈ sol.u rtol = 1.0e-1 - -fig = Figure(size = (2150, 460), fontsize = 34) -ax = Axis( - fig[1, 1], xlabel = L"x", ylabel = L"u(x)", title = L"(a):$ $ Numerical solution", - titlealign = :left, width = 600, height = 300 -) -colors = [:red, :black, :blue, :darkgreen, :magenta, :orange] -[lines!(ax, mesh_points, sol.u[i], color = colors[i]) for i in eachindex(sol.t)] -ylims!(ax, -1.0e-6, 5) -xlims!(ax, -1, 1) -ax = Axis( - fig[1, 2], xlabel = L"x", ylabel = L"u(x)", title = L"(b):$ $ Exact solution", - titlealign = :left, width = 600, height = 300 -) -[lines!(ax, mesh_points, exact[i], color = colors[i]) for i in eachindex(sol.t)] -ylims!(ax, -1.0e-6, 5) -xlims!(ax, -1, 1) -ax = Axis( - fig[1, 3], xlabel = L"x", ylabel = L"u(x)", title = L"(c):$ $ Error", - titlealign = :left, width = 600, height = 300 -) -[ - lines!(ax, mesh_points, abs.(exact[i] .- sol.u[i]), color = colors[i]) - for i in eachindex(sol.t) -] -ylims!(ax, -1.0e-6, 0.5) -xlims!(ax, -1, 1) -fig_path = normpath(@__DIR__, "..", "test", "figures") -@test_reference joinpath(fig_path, "porous_comparison.png") fig - -let t_range = LinRange(0.0, final_time, 250) - fig = Figure(fontsize = 33) - ax = Axis3(fig[1, 1], xlabel = L"x", ylabel = L"t", zlabel = L"z") - sol_u = [sol(t) for t in t_range] - in_int_range = findall(x -> abs(x) < 1, mesh_points) # Makie won't clip the plot to (-1, 1) - surface!( - ax, mesh_points[in_int_range], t_range, - reduce(hcat, sol_u)[in_int_range, :], colormap = :viridis - ) - xlims!(ax, -1, 1) - fig_path = normpath(@__DIR__, "..", "docs", "src", "figures") - @test_reference joinpath(fig_path, "porous_surface.png") fig -end diff --git a/test/robin_diffusion.jl b/test/robin_diffusion.jl index a70e951..fa94a9b 100644 --- a/test/robin_diffusion.jl +++ b/test/robin_diffusion.jl @@ -4,8 +4,6 @@ using LinearSolve using OrdinaryDiffEq using OrdinaryDiffEqSDIRK using NonlinearSolve -using CairoMakie -using ReferenceTests # uₜ = (1/25)uₓₓ # u(0, t) = 0 @@ -52,12 +50,3 @@ sol = solve(prob, TRBDF2(linsolve = KLUFactorization()), saveat = 0.01) μ = compute_μₙ.(1:100) exact_sol = [exact_u.(mesh_points, sol.t[i], Ref(μ)) for i in eachindex(sol.t)] @test reduce(hcat, sol.u) ≈ reduce(hcat, exact_sol) rtol = 1.0e-2 - -let t_range = LinRange(0.0, final_time, 250) - fig = Figure(fontsize = 33) - ax = Axis3(fig[1, 1], xlabel = L"x", ylabel = L"t", zlabel = L"z", azimuth = 0.8) - sol_u = [sol(t) for t in t_range] - surface!(ax, mesh_points, t_range, reduce(hcat, sol_u), colormap = :viridis) - fig_path = normpath(@__DIR__, "..", "docs", "src", "figures") - @test_reference joinpath(fig_path, "robin_diffusion_surface.png") fig -end diff --git a/test/test_groups.toml b/test/test_groups.toml index 855811b..724a6db 100644 --- a/test/test_groups.toml +++ b/test/test_groups.toml @@ -7,5 +7,8 @@ versions = ["1"] os = ["ubuntu-latest"] arch = "x86" +[Plotting] +versions = ["lts", "1", "pre"] + [QA] versions = ["lts", "1"]