Skip to content

Commit

Permalink
Merge pull request #158 from milankl/scale
Browse files Browse the repository at this point in the history
scale_sst_inv removed to avoid subnormal
  • Loading branch information
milankl authored Apr 29, 2021
2 parents b2f6f58 + 113b93e commit e671d7a
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
5 changes: 1 addition & 4 deletions src/constants.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,6 @@ struct Constants{T<:AbstractFloat,Tprog<:AbstractFloat}
scale::T # multiplicative constant for low-precision arithmetics
scale_inv::T # and its inverse
scale_sst::T # scale for sst
scale_sst_inv::T # and its inverse
end

"""Generator function for the mutable struct Constants."""
Expand Down Expand Up @@ -118,12 +117,10 @@ function Constants{T,Tprog}(P::Parameter,G::Grid) where {T<:AbstractFloat,Tprog<
scale = convert(T,P.scale)
scale_inv = convert(T,1/P.scale)
scale_sst = convert(T,P.scale_sst)
scale_sst_inv = convert(T,1/P.scale_sst)

return Constants{T,Tprog}( RKaΔt,RKbΔt,Δt_Δs,Δt_Δ,Δt_Δ_half,
SSPRK3c,one_minus_α,
g,cD,rD,γ,cSmag,νB,τSST,jSST,
ωFη,ωFx,ωFy,
scale,scale_inv,
scale_sst,scale_sst_inv)
scale,scale_inv,scale_sst)
end
10 changes: 5 additions & 5 deletions src/ghost_points.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ function remove_halo( u::Array{T,2},
S::ModelSetup) where {T<:AbstractFloat}

@unpack halo,haloη,halosstx,halossty = S.grid
@unpack scale_inv,scale_sst_inv = S.constants
@unpack scale_inv,scale_sst = S.constants

# undo scaling as well
ucut = scale_inv*u[halo+1:end-halo,halo+1:end-halo]
vcut = scale_inv*v[halo+1:end-halo,halo+1:end-halo]
ηcut = η[haloη+1:end-haloη,haloη+1:end-haloη]
sstcut = scale_sst_inv*sst[halosstx+1:end-halosstx,halossty+1:end-halossty]
@views ucut = scale_inv*u[halo+1:end-halo,halo+1:end-halo]
@views vcut = scale_inv*v[halo+1:end-halo,halo+1:end-halo]
@views ηcut = η[haloη+1:end-haloη,haloη+1:end-haloη]
@views sstcut = sst[halosstx+1:end-halosstx,halossty+1:end-halossty]/scale_sst

return ucut,vcut,ηcut,sstcut
end
Expand Down
4 changes: 2 additions & 2 deletions src/output.jl
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ function output_nc!(i::Int,

@unpack halo,haloη,halosstx,halossty = S.grid
@unpack f_q,ep,dtint = S.grid
@unpack scale,scale_inv,scale_sst_inv = S.constants
@unpack scale,scale_inv,scale_sst = S.constants

# CUT OFF HALOS
# As output is before copyto!(u,u0), take u0,v0,η0
Expand All @@ -109,7 +109,7 @@ function output_nc!(i::Int,
NetCDF.putvar(ncs.η,"eta",η,start=[1,1,iout],count=[-1,-1,1])
end
if ncs.sst != nothing
@views sst = Float32.(scale_sst_inv*Prog.sst[halosstx+1:end-halosstx,halossty+1:end-halossty])
@views sst = Float32.(Prog.sst[halosstx+1:end-halosstx,halossty+1:end-halossty]/scale_sst)
NetCDF.putvar(ncs.sst,"sst",sst,start=[1,1,iout],count=[-1,-1,1])
end
if ncs.q != nothing
Expand Down

0 comments on commit e671d7a

Please sign in to comment.