Skip to content

Commit

Permalink
save to float32
Browse files Browse the repository at this point in the history
  • Loading branch information
Iddingsite committed Jan 17, 2024
1 parent be74ac5 commit 6a194cc
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 45 deletions.
48 changes: 24 additions & 24 deletions src/callbacks/output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,10 @@ function hdf5_initial_conditions(IC::InitialConditions1D, Domain::Domain1D, path
attributes(grp)["Center"] = "Node"
end

t0["Mg"]["Mg"] = IC.CMg0
t0["Fe"]["Fe"] = IC.CFe0
t0["Mn"]["Mn"] = IC.CMn0
t0["Ca"]["Ca"] = 1 .- IC.CMg0 .- IC.CFe0 .- IC.CMn0
t0["Mg"]["Mg"] = convert(Array{Float32}, IC.CMg0)
t0["Fe"]["Fe"] = convert(Array{Float32}, IC.CFe0)
t0["Mn"]["Mn"] = convert(Array{Float32}, IC.CMn0)
t0["Ca"]["Ca"] = convert(Array{Float32}, replace!((1 .- IC.CMg0 .- IC.CFe0 .- IC.CMn0), 1=>0))
end
end

Expand Down Expand Up @@ -66,10 +66,10 @@ function hdf5_initial_conditions(IC::InitialConditionsSpherical, Domain::DomainS
attributes(grp)["Center"] = "Node"
end

t0["Mg"]["Mg"] = IC.CMg0
t0["Fe"]["Fe"] = IC.CFe0
t0["Mn"]["Mn"] = IC.CMn0
t0["Ca"]["Ca"] = 1 .- IC.CMg0 .- IC.CFe0 .- IC.CMn0
t0["Mg"]["Mg"] = convert(Array{Float32}, IC.CMg0)
t0["Fe"]["Fe"] = convert(Array{Float32}, IC.CFe0)
t0["Mn"]["Mn"] = convert(Array{Float32}, IC.CMn0)
t0["Ca"]["Ca"] = convert(Array{Float32}, replace!((1 .- IC.CMg0 .- IC.CFe0 .- IC.CMn0), 1=>0))
end
end

Expand Down Expand Up @@ -110,12 +110,12 @@ function hdf5_initial_conditions(IC::InitialConditions2D, Domain::Domain2D, path
attributes(grp)["Center"] = "Node"
end

t0["Mg"]["Mg"] = IC.CMg0
t0["Fe"]["Fe"] = IC.CFe0
t0["Mn"]["Mn"] = IC.CMn0
t0["Ca"]["Ca"] = replace!((1 .- IC.CMg0 .- IC.CFe0 .- IC.CMn0), 1=>0)
t0["GrtPosition"]["GrtPosition"] = IC.grt_position
t0["GrtBoundary"]["GrtBoundary"] = IC.grt_boundary
t0["Mg"]["Mg"] = convert(Array{Float32}, IC.CMg0)
t0["Fe"]["Fe"] = convert(Array{Float32}, IC.CFe0)
t0["Mn"]["Mn"] = convert(Array{Float32}, IC.CMn0)
t0["Ca"]["Ca"] = convert(Array{Float32}, replace!((1 .- IC.CMg0 .- IC.CFe0 .- IC.CMn0), 1=>0))
t0["GrtPosition"]["GrtPosition"] = convert(Array{Int32},IC.grt_position)
t0["GrtBoundary"]["GrtBoundary"] = convert(Array{Int32},IC.grt_boundary)
end
end

Expand Down Expand Up @@ -158,12 +158,12 @@ function hdf5_initial_conditions(IC::InitialConditions3D, Domain::Domain3D, path
attributes(grp)["Center"] = "Node"
end

t0["Mg"]["Mg"] = IC.CMg0
t0["Fe"]["Fe"] = IC.CFe0
t0["Mn"]["Mn"] = IC.CMn0
t0["Ca"]["Ca"] = replace!((1 .- IC.CMg0 .- IC.CFe0 .- IC.CMn0), 1=>0)
t0["GrtPosition"]["GrtPosition"] = IC.grt_position
t0["GrtBoundary"]["GrtBoundary"] = IC.grt_boundary
t0["Mg"]["Mg"] = convert(Array{Float32}, IC.CMg0)
t0["Fe"]["Fe"] = convert(Array{Float32}, IC.CFe0)
t0["Mn"]["Mn"] = convert(Array{Float32}, IC.CMn0)
t0["Ca"]["Ca"] = convert(Array{Float32}, replace!((1 .- IC.CMg0 .- IC.CFe0 .- IC.CMn0), 1=>0))
t0["GrtPosition"]["GrtPosition"] = convert(Array{Int32},IC.grt_position)
t0["GrtBoundary"]["GrtBoundary"] = convert(Array{Int32},IC.grt_boundary)
end
end

Expand Down Expand Up @@ -201,10 +201,10 @@ function hdf5_timestep(u, dt, tcurrent, path_hdf5)
attributes(grp)["Center"] = "Node"
end

t["Mg"]["Mg"] = CMg
t["Fe"]["Fe"] = CFe
t["Mn"]["Mn"] = CMn
t["Ca"]["Ca"] = replace!((1 .- CMg .- CFe .- CMn), 1=>0)
t["Mg"]["Mg"] = convert(Array{Float32}, CMg)
t["Fe"]["Fe"] = convert(Array{Float32}, CFe)
t["Mn"]["Mn"] = convert(Array{Float32}, CMn)
t["Ca"]["Ca"] = convert(Array{Float32}, replace!((1 .- CMg .- CFe .- CMn), 1=>0))
end
end

Expand Down
42 changes: 21 additions & 21 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -285,33 +285,33 @@ end
sol_2D = simulate(domain2D; callback=save_data_callback, path_save=(@__DIR__) * "/Grt_2D.h5", progress=false, save_everystep=false)

h5open("./Grt_1D.h5", "r") do file
@test read(file["Diffusion_Grt"]["t0000"]["Mg"]["Mg"]) == IC1D.CMg0
@test read(file["Diffusion_Grt"]["t0000"]["Fe"]["Fe"]) == IC1D.CFe0
@test read(file["Diffusion_Grt"]["t0000"]["Mn"]["Mn"]) == IC1D.CMn0
@test read(file["Diffusion_Grt"]["t0000"]["Ca"]["Ca"]) == replace!((1 .- IC1D.CMg0 .- IC1D.CFe0 .- IC1D.CMn0), 1=>0)
@test read(file["Diffusion_Grt"]["t0003"]["Mg"]["Mg"]) == sol_1D.u[end][:,1]
@test read(file["Diffusion_Grt"]["t0003"]["Fe"]["Fe"]) == sol_1D.u[end][:,2]
@test read(file["Diffusion_Grt"]["t0003"]["Mn"]["Mn"]) == sol_1D.u[end][:,3]
@test read(file["Diffusion_Grt"]["t0000"]["Mg"]["Mg"]) == convert(Array{Float32}, IC1D.CMg0)
@test read(file["Diffusion_Grt"]["t0000"]["Fe"]["Fe"]) == convert(Array{Float32}, IC1D.CFe0)
@test read(file["Diffusion_Grt"]["t0000"]["Mn"]["Mn"]) == convert(Array{Float32}, IC1D.CMn0)
@test read(file["Diffusion_Grt"]["t0000"]["Ca"]["Ca"]) == convert(Array{Float32}, replace!((1 .- IC1D.CMg0 .- IC1D.CFe0 .- IC1D.CMn0), 1=>0))
@test read(file["Diffusion_Grt"]["t0003"]["Mg"]["Mg"]) == convert(Array{Float32}, sol_1D.u[end][:,1])
@test read(file["Diffusion_Grt"]["t0003"]["Fe"]["Fe"]) == convert(Array{Float32}, sol_1D.u[end][:,2])
@test read(file["Diffusion_Grt"]["t0003"]["Mn"]["Mn"]) == convert(Array{Float32}, sol_1D.u[end][:,3])
end

h5open("./Grt_Sph.h5", "r") do file
@test read(file["Diffusion_Grt"]["t0000"]["Mg"]["Mg"]) == ICSph.CMg0
@test read(file["Diffusion_Grt"]["t0000"]["Fe"]["Fe"]) == ICSph.CFe0
@test read(file["Diffusion_Grt"]["t0000"]["Mn"]["Mn"]) == ICSph.CMn0
@test read(file["Diffusion_Grt"]["t0000"]["Ca"]["Ca"]) == replace!((1 .- ICSph.CMg0 .- ICSph.CFe0 .- ICSph.CMn0), 1=>0)
@test read(file["Diffusion_Grt"]["t0003"]["Mg"]["Mg"]) == sol_sph.u[end][:,1]
@test read(file["Diffusion_Grt"]["t0003"]["Fe"]["Fe"]) == sol_sph.u[end][:,2]
@test read(file["Diffusion_Grt"]["t0003"]["Mn"]["Mn"]) == sol_sph.u[end][:,3]
@test read(file["Diffusion_Grt"]["t0000"]["Mg"]["Mg"]) == convert(Array{Float32}, ICSph.CMg0)
@test read(file["Diffusion_Grt"]["t0000"]["Fe"]["Fe"]) == convert(Array{Float32}, ICSph.CFe0)
@test read(file["Diffusion_Grt"]["t0000"]["Mn"]["Mn"]) == convert(Array{Float32}, ICSph.CMn0)
@test read(file["Diffusion_Grt"]["t0000"]["Ca"]["Ca"]) == convert(Array{Float32}, replace!((1 .- ICSph.CMg0 .- ICSph.CFe0 .- ICSph.CMn0), 1=>0))
@test read(file["Diffusion_Grt"]["t0003"]["Mg"]["Mg"]) == convert(Array{Float32}, sol_sph.u[end][:,1])
@test read(file["Diffusion_Grt"]["t0003"]["Fe"]["Fe"]) == convert(Array{Float32}, sol_sph.u[end][:,2])
@test read(file["Diffusion_Grt"]["t0003"]["Mn"]["Mn"]) == convert(Array{Float32}, sol_sph.u[end][:,3])
end

h5open("./Grt_2D.h5", "r") do file
@test read(file["Diffusion_Grt"]["t0000"]["Mg"]["Mg"]) == IC2D.CMg0
@test read(file["Diffusion_Grt"]["t0000"]["Fe"]["Fe"]) == IC2D.CFe0
@test read(file["Diffusion_Grt"]["t0000"]["Mn"]["Mn"]) == IC2D.CMn0
@test read(file["Diffusion_Grt"]["t0000"]["Ca"]["Ca"]) == replace!((1 .- IC2D.CMg0 .- IC2D.CFe0 .- IC2D.CMn0), 1=>0)
@test read(file["Diffusion_Grt"]["t0003"]["Mg"]["Mg"]) == sol_2D.u[end][:,:,1]
@test read(file["Diffusion_Grt"]["t0003"]["Fe"]["Fe"]) == sol_2D.u[end][:,:,2]
@test read(file["Diffusion_Grt"]["t0003"]["Mn"]["Mn"]) == sol_2D.u[end][:,:,3]
@test read(file["Diffusion_Grt"]["t0000"]["Mg"]["Mg"]) == convert(Array{Float32}, IC2D.CMg0)
@test read(file["Diffusion_Grt"]["t0000"]["Fe"]["Fe"]) == convert(Array{Float32}, IC2D.CFe0)
@test read(file["Diffusion_Grt"]["t0000"]["Mn"]["Mn"]) == convert(Array{Float32}, IC2D.CMn0)
@test read(file["Diffusion_Grt"]["t0000"]["Ca"]["Ca"]) == convert(Array{Float32}, replace!((1 .- IC2D.CMg0 .- IC2D.CFe0 .- IC2D.CMn0), 1=>0))
@test read(file["Diffusion_Grt"]["t0003"]["Mg"]["Mg"]) == convert(Array{Float32}, sol_2D.u[end][:,:,1])
@test read(file["Diffusion_Grt"]["t0003"]["Fe"]["Fe"]) == convert(Array{Float32}, sol_2D.u[end][:,:,2])
@test read(file["Diffusion_Grt"]["t0003"]["Mn"]["Mn"]) == convert(Array{Float32}, sol_2D.u[end][:,:,3])
end

# delete files "Grt_1D.h5" and "Grt_Sph.h5" if it exists
Expand Down

0 comments on commit 6a194cc

Please sign in to comment.