diff --git a/Project.toml b/Project.toml index 18666bbd..1fe3cfb7 100644 --- a/Project.toml +++ b/Project.toml @@ -31,8 +31,8 @@ WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192" [extensions] WaterLilyAMDGPUExt = "AMDGPU" WaterLilyCUDAExt = "CUDA" -WaterLilyMakieExt = "Makie" WaterLilyJLD2Ext = "JLD2" +WaterLilyMakieExt = "Makie" WaterLilyMeshingExt = ["Makie", "Meshing"] WaterLilyPlotsExt = "Plots" WaterLilyReadVTKExt = "ReadVTK" @@ -55,7 +55,10 @@ julia = "1.10" AMDGPU = "21141c5a-9bdb-4563-92ae-f87d6854732e" BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf" CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba" +FileIO = "5789e2e9-d7fb-5bc7-8068-2c6fae9b9549" GPUArrays = "0c68f7d7-f131-5f86-a1c3-88cf8149b2d7" +ImageCore = "a09fc81d-aa75-5fe9-8630-4744c3626534" +ImageMagick = "6218d12a-5da1-5696-b52f-db25d2ecc6d1" JLD2 = "033835bb-8acc-5ee8-8aae-3f567f8a3819" LaTeXStrings = "b964fa9f-0449-5b57-a5c2-d3ea65f4040f" Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a" @@ -68,4 +71,17 @@ UnicodePlots = "b8865327-cd53-5732-bb35-84acbb429228" WriteVTK = "64499a7a-5c06-52f2-abe2-ccb03c286192" [targets] -test = ["Test", "BenchmarkTools", "CUDA", "AMDGPU", "GPUArrays", "WriteVTK", "ReadVTK", "JLD2"] +test = [ + "AMDGPU", + "BenchmarkTools", + "CUDA", + "FileIO", + "GPUArrays", + "ImageMagick", + "ImageCore", + "JLD2", + "Plots", + "ReadVTK", + "Test", + "WriteVTK", +] diff --git a/test/compdata/compLogPlot.png b/test/compdata/compLogPlot.png new file mode 100644 index 00000000..88b5f96b Binary files /dev/null and b/test/compdata/compLogPlot.png differ diff --git a/test/compdata/compbody.png b/test/compdata/compbody.png new file mode 100644 index 00000000..88272fec Binary files /dev/null and b/test/compdata/compbody.png differ diff --git a/test/compdata/compgif.gif b/test/compdata/compgif.gif new file mode 100644 index 00000000..574a6446 Binary files /dev/null and b/test/compdata/compgif.gif differ diff --git a/test/compdata/floodTestNoLims.png b/test/compdata/floodTestNoLims.png new file mode 100644 index 00000000..6fda19f0 Binary files /dev/null and b/test/compdata/floodTestNoLims.png differ diff --git a/test/compdata/floodTestWithLims.png b/test/compdata/floodTestWithLims.png new file mode 100644 index 00000000..6346be1c Binary files /dev/null and b/test/compdata/floodTestWithLims.png differ diff --git a/test/maintests.jl b/test/maintests.jl index 7f185e4c..ea9f5640 100644 --- a/test/maintests.jl +++ b/test/maintests.jl @@ -1,7 +1,8 @@ using GPUArrays -using ReadVTK, WriteVTK, JLD2 +using ReadVTK, WriteVTK, JLD2, Plots +using FileIO, ImageMagick, ImageCore -backend != "KernelAbstractions" && throw(ArgumentError("SIMD backend not allowed to run main tests, use KernelAbstractions backend")) +WaterLily.backend != "KernelAbstractions" && throw(ArgumentError("SIMD backend not allowed to run main tests, use KernelAbstractions backend")) @info "Test backends: $(join(arrays,", "))" @testset "util.jl" begin I = CartesianIndex(1,2,3,4) @@ -605,6 +606,7 @@ end end @test_nowarn rm(test_dir, recursive=true) end + @testset "RigidMap.jl" begin for T ∈ (Float32,Float64) # initialize a rigid body @@ -658,4 +660,82 @@ end rmap = RigidMap(SA[0.,0.],π/4) body = AutoBody((x,t)->√(x'x)-1,rmap)-AutoBody((x,t)->√(x'x)-0.5,rmap) # annulus @test all(measure(setmap(body,ω=1.),SA[0.25,0.],0) .≈ (0.25,SA[-1,0],SA[0,0.25])) +end + +make_egg_noarray(ra=40,rb=20, U=1) = Simulation((5*ra,5*rb),(U,0), rb; + body=AutoBody((x,t)->√sum((x[1]-8)^2/ra+(x[2]-8)^2/rb)-1)) + +@testset "WaterLilyPlotsExt.jl" begin + Plots.plot(); # reset the plot + + # make a simulation + sim = make_egg_noarray(); + + # make a body plot of the simulation setup + test = body_plot!(sim) + Plots.savefig(test, "temp.png") + test = load("temp.png") + + # compare output and do cleanup + comp = load("compdata/compbody.png") + @test abs(maximum(channelview(test)-channelview(comp))) < 1 + rm("temp.png") + + Plots.plot(); # reset the plot + + # make a simulation + sim = make_egg_noarray(); + + # make a gif of the simulation + testgif = sim_gif!(sim,duration=0.5, clims=(-5,5),plotbody=true) + fn = testgif.filename + testgif = load(fn) + + # compare output and do cleanup + compgif = load("compdata/compgif.gif") + @test abs(maximum(channelview(testgif)-channelview(compgif))) < 1 + rm(fn) + + Plots.plot(); # reset the plot + + # make a 2d plot with flood + xr = -1:0.01:1 + yr = -1:0.01:1 + g(x,y) = x^2/2 + y^2/3 + flood(g.(xr,yr')) + + # compare output and do cleanup + Plots.savefig("temp.png") + comp = load("compdata/floodTestNoLims.png") + test = load("temp.png") + @test abs(maximum(channelview(test)-channelview(comp))) < 1 + rm("temp.png") + + Plots.plot(); # reset the plot + + flood(g.(xr,yr'), clims = (0.00,0.01)) + Plots.savefig("temp.png") + + # compare output and do cleanup + comp = load("compdata/floodTestWithLims.png") + test = load("temp.png") + @test abs(maximum(channelview(test)-channelview(comp))) < 1 + rm("temp.png") + + Plots.plot(); # reset the plot + + # make a simulation + sim = make_egg_noarray(); + + # make a plot of the simulation log + WaterLily.logger("testLog") # Log the residual of pressure solver + sim_step!(sim, 0.5) # Run the simulation + plot_logger("testLog.log") + Plots.savefig("testLogPlot.png") + + # compare output and do cleanup + comp = load("compdata/compLogPlot.png") + test = load("testLogPlot.png") + @test abs(maximum(channelview(test)-channelview(comp))) < 1 + rm("testLogPlot.png") end \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index 4d322347..60290dc5 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -15,4 +15,4 @@ function setup_backends() end arrays = setup_backends() -Threads.nthreads() > 1 ? include("maintests.jl") : include("alloctest.jl") +Threads.nthreads() > 1 ? include("maintests.jl") : include("alloctest.jl") \ No newline at end of file