diff --git a/test/runtests.jl b/test/runtests.jl index 7f3802f..7ca42f9 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -1,42 +1,7 @@ using DJUICE using Test -function searchdir(path,key) - filter(x->occursin(key,x), readdir(path)) -end - -function compareArchive(tf::String, procedure::Symbol) - # run test - @inline include(tf) - id = match(r"test(\d+).jl", tf).captures[1] - archive_name = "Archive"*string(id) - archive_path = issmdir()*"/test/Archives/"*archive_name*".arch" - if procedure===:update - # update Archive - else - # check Archive - if isfile(archive_path) - for k=1:length(field_names) - # Get field and tolerance - field=field_values[k]; - fieldname=field_names[k]; - tolerance=field_tolerances[k]; - - # Compare to archive - if !isnan(tolerance) - # Our output is in the correct order (n,1) or (1,1), so we do not need to transpose again - archive = archread(archive_path, archive_name*"_field"*string(k)) - error_diff = (maximum(abs.(archive-field))/(maximum(abs.(archive))+eps(Float64))) - - @test isnan(error_diff) == false - @test error_diff < tolerance skip = isnan(tolerance) - end - end - else - @warn "$archive_name does not exist! Skip the comparison of the results" - end - end -end +include("utils.jl") @time @testset "DJUICE" begin @time @testset "Model Struct Tests" begin include("modelstructtests.jl") end @@ -46,10 +11,7 @@ end for tf in testsolutions @time @testset "Model Solution Tests: $tf" begin # check the results vs. saved archive - compareArchive(tf, :test) + include(tf) end end - - # GPU test - #@time include("testGPU.jl") end diff --git a/test/test101.jl b/test/test101.jl index e64bdac..a12bd0b 100755 --- a/test/test101.jl +++ b/test/test101.jl @@ -1,4 +1,5 @@ using DJUICE +include("utils.jl") md = model() md = triangle(md,issmdir()*"/test/Exp/Square.exp",50000.) @@ -50,3 +51,4 @@ field_tolerances=[4e-13,4e-13,4e-13] field_values= [(md.results["StressbalanceSolution"]["Vx"]), (md.results["StressbalanceSolution"]["Vy"]), (md.results["StressbalanceSolution"]["Vel"]) ] +compareArchive(@__FILE__, field_names, field_tolerances, field_values, :test) diff --git a/test/test201.jl b/test/test201.jl index 5f82821..52987dd 100755 --- a/test/test201.jl +++ b/test/test201.jl @@ -1,4 +1,5 @@ using DJUICE +include("utils.jl") md = model() md = triangle(md,issmdir()*"/test/Exp/Square.exp", 150000.) @@ -55,3 +56,4 @@ field_tolerances=[2e-10,2e-10,2e-10] field_values= [(md.results["StressbalanceSolution"]["Vx"]), (md.results["StressbalanceSolution"]["Vy"]), (md.results["StressbalanceSolution"]["Vel"]) ] +compareArchive(@__FILE__, field_names, field_tolerances, field_values, :test) diff --git a/test/test208.jl b/test/test208.jl index bfc4a05..ecaaebe 100755 --- a/test/test208.jl +++ b/test/test208.jl @@ -1,4 +1,5 @@ using DJUICE +include("utils.jl") md = model() md = triangle(md,issmdir()*"/test/Exp/Square.exp", 150000.) @@ -65,10 +66,11 @@ field_tolerances=[2e-10,2e-10,2e-10,NaN,2e-10,2e-10,2e-10,NaN,NaN] field_values= [(md.results["TransientSolution"][1]["Vx"]), (md.results["TransientSolution"][1]["Vy"]), (md.results["TransientSolution"][1]["Vel"]), - (NaN), + ([NaN]), (md.results["TransientSolution"][1]["Base"]), (md.results["TransientSolution"][1]["Surface"]), (md.results["TransientSolution"][1]["Thickness"]), - (NaN), - (NaN), + ([NaN]), + ([NaN]), ] +compareArchive(@__FILE__, field_names, field_tolerances, field_values, :test) diff --git a/test/test301.jl b/test/test301.jl index 5210325..e836ac2 100755 --- a/test/test301.jl +++ b/test/test301.jl @@ -1,4 +1,5 @@ using DJUICE +include("utils.jl") md = model() md = triangle(md,issmdir()*"/test/Exp/Square.exp",150000.) @@ -17,13 +18,13 @@ md.geometry.surface = md.geometry.base+md.geometry.thickness md.geometry.bed = md.geometry.base #Initial velocity -#x = archread(issmdir()*"/test/Data/SquareShelfConstrained.arch","x") -#y = archread(issmdir()*"/test/Data/SquareShelfConstrained.arch","y") -#vx = archread(issmdir()*"/test/Data/SquareShelfConstrained.arch","vx") -#vy = archread(issmdir()*"/test/Data/SquareShelfConstrained.arch","vy") -#index = archread(issmdir()*"/test/Data/SquareShelfConstrained.arch","index") -md.initialization.vx=zeros(md.mesh.numberofvertices)#InterpFromMeshToMesh2d(index,x,y,vx,md.mesh.x,md.mesh.y) -md.initialization.vy=zeros(md.mesh.numberofvertices)#InterpFromMeshToMesh2d(index,x,y,vy,md.mesh.x,md.mesh.y) +x = archread(issmdir()*"/test/Data/SquareSheetConstrained.arch","x") +y = archread(issmdir()*"/test/Data/SquareSheetConstrained.arch","y") +vx = archread(issmdir()*"/test/Data/SquareSheetConstrained.arch","vx") +vy = archread(issmdir()*"/test/Data/SquareSheetConstrained.arch","vy") +index = Int.(archread(issmdir()*"/test/Data/SquareSheetConstrained.arch","index")) +md.initialization.vx=InterpFromMeshToMesh2d(index,x,y,vx,md.mesh.x,md.mesh.y,0.0) +md.initialization.vy=InterpFromMeshToMesh2d(index,x,y,vy,md.mesh.x,md.mesh.y,0.0) md.materials.rheology_B=1.815730284801701e+08*ones(md.mesh.numberofvertices) md.materials.rheology_n=3*ones(md.mesh.numberofelements) @@ -45,7 +46,8 @@ md.stressbalance.spcvy[pos] .= 0.0 md=solve(md,:Stressbalance) field_names =["Vx","Vy","Vel"] -field_tolerances=[NaN,NaN,NaN] +field_tolerances=[2e-10,1e-10,1e-10] field_values= [(md.results["StressbalanceSolution"]["Vx"]), (md.results["StressbalanceSolution"]["Vy"]), (md.results["StressbalanceSolution"]["Vel"]) ] +compareArchive(@__FILE__, field_names, field_tolerances, field_values, :test) diff --git a/test/test501.jl b/test/test501.jl index 197effc..cdfb4bb 100755 --- a/test/test501.jl +++ b/test/test501.jl @@ -1,4 +1,5 @@ using DJUICE +include("utils.jl") md = model() md = triangle(md,issmdir()*"/test/Exp/Pig.exp",20000.) @@ -54,3 +55,4 @@ field_tolerances=[NaN,NaN,NaN] field_values= [(md.results["StressbalanceSolution"]["Vx"]), (md.results["StressbalanceSolution"]["Vy"]), (md.results["StressbalanceSolution"]["Vel"]) ] +compareArchive(@__FILE__, field_names, field_tolerances, field_values, :test) diff --git a/test/test807.jl b/test/test807.jl index aad1ed0..c0192e1 100755 --- a/test/test807.jl +++ b/test/test807.jl @@ -1,4 +1,5 @@ using DJUICE +include("utils.jl") md = model() md = triangle(md,issmdir()*"/test/Exp/Square.exp",200000.) @@ -72,3 +73,5 @@ md.levelset.spclevelset=NaN*ones(md.mesh.numberofvertices) md.levelset.spclevelset[pos] = md.mask.ice_levelset[pos] md=solve(md,:Transient) +compareArchive(@__FILE__, field_names, field_tolerances, field_values, :test) + diff --git a/test/utils.jl b/test/utils.jl new file mode 100644 index 0000000..70eeb20 --- /dev/null +++ b/test/utils.jl @@ -0,0 +1,37 @@ +using DJUICE +using Test + +function searchdir(path,key) + filter(x->occursin(key,x), readdir(path)) +end + +function compareArchive(tf::String, field_names::Vector{String}, field_tolerances::Vector{Float64}, field_values::Vector{Vector{Float64}}, procedure::Symbol) + # make the test + id = match(r"test(\d+).jl", tf).captures[1] + archive_name = "Archive"*string(id) + archive_path = issmdir()*"/test/Archives/"*archive_name*".arch" + if procedure===:update + # TODO: update Archive + else + # check Archive + if isfile(archive_path) + @time @testset " Compare with $archive_name" begin + for k=1:length(field_names) + # Compare to archive + if !isnan(field_tolerances[k]) + @time @testset " $(field_names[k]): " begin + # Our output is in the correct order (n,1) or (1,1), so we do not need to transpose again + archive = archread(archive_path, archive_name*"_field"*string(k)) + error_diff = (maximum(abs.(archive-field_values[k]))/(maximum(abs.(archive))+eps(Float64))) + + @test isnan(error_diff) == false + @test error_diff < field_tolerances[k] skip = isnan(field_tolerances[k]) + end + end + end + end + else + @warn "$archive_name does not exist! Skip the comparison of the results" + end + end +end