Skip to content

Commit

Permalink
Merge pull request #20 from DJ4Earth/add_ISSM_test_Archive
Browse files Browse the repository at this point in the history
add Archives from ISSM. Compare DJUICE solutions directly with ISSM solutions
  • Loading branch information
MathieuMorlighem authored Jul 5, 2024
2 parents 41be0cb + 5a05581 commit 29d9e8f
Show file tree
Hide file tree
Showing 10 changed files with 68 additions and 33 deletions.
Binary file added test/Archives/Archive201.arch
Binary file not shown.
Binary file added test/Archives/Archive208.arch
Binary file not shown.
Binary file added test/Archives/Archive301.arch
Binary file not shown.
Binary file added test/Archives/Archive501.arch
Binary file not shown.
28 changes: 15 additions & 13 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@ function searchdir(path,key)
filter(x->occursin(key,x), readdir(path))
end

function compareArchive(id, procedure::Symbol)
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
Expand All @@ -20,31 +23,30 @@ function compareArchive(id, procedure::Symbol)
tolerance=field_tolerances[k];

# Compare to archive
# 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)))
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
@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

@time begin
@time @testset "DJUICE" begin
@time @testset "Model Struct Tests" begin include("modelstructtests.jl") end

# test each individual cases, name with test[0-9]*.jl
testsolutions = searchdir("./", r"test\d+.jl")
@time @testset "Model Solution Tests" begin
for tf in testsolutions
# run the test
include(tf)
for tf in testsolutions
@time @testset "Model Solution Tests: $tf" begin
# check the results vs. saved archive
testid = match(r"test(\d+).jl", tf).captures[1]
compareArchive(testid, :test)
compareArchive(tf, :test)
end
end

Expand Down
26 changes: 16 additions & 10 deletions test/test201.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using DJUICE

md = model()
md = triangle(md,issmdir()*"/test/Exp/Square.exp", 50000.)
md = triangle(md,issmdir()*"/test/Exp/Square.exp", 150000.)
md = setmask(md, "all", "")

#Geometry
Expand All @@ -14,20 +14,20 @@ xmax=maximum(md.mesh.x)
md.geometry.thickness = hmax .+ (hmin-hmax)*(md.mesh.y .- ymin)./(ymax-ymin) .+ 0.1*(hmin-hmax)*(md.mesh.x .- xmin)./(xmax-xmin)
md.geometry.base = -md.materials.rho_ice/md.materials.rho_water*md.geometry.thickness
md.geometry.surface = md.geometry.base+md.geometry.thickness
md.geometry.bed = md.geometry.base .-10
md.geometry.bed = md.geometry.base .-500

#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/SquareShelf.arch","x")
y = archread(issmdir()*"/test/Data/SquareShelf.arch","y")
vx = archread(issmdir()*"/test/Data/SquareShelf.arch","vx")
vy = archread(issmdir()*"/test/Data/SquareShelf.arch","vy")
index = round.(Int64, archread(issmdir()*"/test/Data/SquareShelf.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)
md.friction.coefficient=20*ones(md.mesh.numberofvertices)
md.friction.coefficient=0*ones(md.mesh.numberofvertices)
md.friction.p=ones(md.mesh.numberofvertices)
md.friction.q=ones(md.mesh.numberofvertices)

Expand All @@ -49,3 +49,9 @@ md.stressbalance.spcvx[pos] .= 0.0
md.stressbalance.spcvy[pos] .= 0.0

md=solve(md,:Stressbalance)
# Fields and tolerances to track changes
field_names =["Vx","Vy","Vel"]
field_tolerances=[2e-10,2e-10,2e-10]
field_values= [(md.results["StressbalanceSolution"]["Vx"]),
(md.results["StressbalanceSolution"]["Vy"]),
(md.results["StressbalanceSolution"]["Vel"]) ]
31 changes: 23 additions & 8 deletions test/test208.jl
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,21 @@ xmax=maximum(md.mesh.x)
md.geometry.thickness = hmax .+ (hmin-hmax)*(md.mesh.y .- ymin)./(ymax-ymin) .+ 0.1*(hmin-hmax)*(md.mesh.x .- xmin)./(xmax-xmin)
md.geometry.base = -md.materials.rho_ice/md.materials.rho_water*md.geometry.thickness
md.geometry.surface = md.geometry.base+md.geometry.thickness
md.geometry.bed = md.geometry.base .-10
md.geometry.bed = md.geometry.base .- 500

#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/SquareShelf.arch","x")
y = archread(issmdir()*"/test/Data/SquareShelf.arch","y")
vx = archread(issmdir()*"/test/Data/SquareShelf.arch","vx")
vy = archread(issmdir()*"/test/Data/SquareShelf.arch","vy")
index = round.(Int64, archread(issmdir()*"/test/Data/SquareShelf.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)
md.friction.coefficient=20*ones(md.mesh.numberofvertices)
md.friction.coefficient[md.mask.ocean_levelset.<0.] .= 0.0
md.friction.p=ones(md.mesh.numberofvertices)
md.friction.q=ones(md.mesh.numberofvertices)

Expand Down Expand Up @@ -57,3 +58,17 @@ md.basalforcings.floatingice_melting_rate = ones(md.mesh.numberofvertices)
md.masstransport.spcthickness = NaN*ones(md.mesh.numberofvertices)

md=solve(md,:Transient)

# Fields and tolerances to track changes
field_names =["Vx1","Vy1","Vel1","Presure1", "Bed1","Surface1","Thickness1", "TotalGroundedBmb1", "TotalFloatingBmb1"]
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),
(md.results["TransientSolution"][1]["Base"]),
(md.results["TransientSolution"][1]["Surface"]),
(md.results["TransientSolution"][1]["Thickness"]),
(NaN),
(NaN),
]
6 changes: 6 additions & 0 deletions test/test301.jl
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,9 @@ md.stressbalance.spcvx[pos] .= 0.0
md.stressbalance.spcvy[pos] .= 0.0

md=solve(md,:Stressbalance)

field_names =["Vx","Vy","Vel"]
field_tolerances=[NaN,NaN,NaN]
field_values= [(md.results["StressbalanceSolution"]["Vx"]),
(md.results["StressbalanceSolution"]["Vy"]),
(md.results["StressbalanceSolution"]["Vel"]) ]
8 changes: 7 additions & 1 deletion test/test501.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using DJUICE

md = model()
md = triangle(md,issmdir()*"/test/Exp/Pig.exp",10000.)
md = triangle(md,issmdir()*"/test/Exp/Pig.exp",20000.)
md = setmask( md,issmdir()*"/test/Exp/PigShelves.exp",issmdir()*"/test/Exp/PigIslands.exp")

#Initial velocity and geometry
Expand Down Expand Up @@ -48,3 +48,9 @@ md.stressbalance.spcvx[pos] .= 0.0
md.stressbalance.spcvy[pos] .= 0.0

md=solve(md, :Stressbalance)

field_names =["Vx","Vy","Vel"]
field_tolerances=[NaN,NaN,NaN]
field_values= [(md.results["StressbalanceSolution"]["Vx"]),
(md.results["StressbalanceSolution"]["Vy"]),
(md.results["StressbalanceSolution"]["Vel"]) ]
2 changes: 1 addition & 1 deletion test/test807.jl
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ md.timestepping.final_time = 30;
md.transient.isstressbalance=1;
md.transient.ismasstransport=1;
md.transient.issmb=1;
md.transient.ismovingfront=1;
md.transient.ismovingfront=0;

md.calving.calvingrate=0*ones(md.mesh.numberofvertices)
md.frontalforcings.meltingrate=10000*ones(md.mesh.numberofvertices)
Expand Down

0 comments on commit 29d9e8f

Please sign in to comment.