Skip to content
Snippets Groups Projects
Commit 0c266586 authored by Brian Groenke's avatar Brian Groenke
Browse files

Optimize freeW freeze curve and related functions

parent f3b4caf9
No related branches found
No related tags found
1 merge request!63Fixes recent regressions in heat initialization and refactors soil state variables
...@@ -11,6 +11,7 @@ using CryoGrid.Numerics: nonlineardiffusion!, harmonicmean!, harmonicmean, heavi ...@@ -11,6 +11,7 @@ using CryoGrid.Numerics: nonlineardiffusion!, harmonicmean!, harmonicmean, heavi
using CryoGrid.Layers: Soil, porosity using CryoGrid.Layers: Soil, porosity
using CryoGrid.Utils using CryoGrid.Utils
using Base: @propagate_inbounds
using DimensionalData using DimensionalData
using IfElse using IfElse
using Interpolations: Linear, Flat using Interpolations: Linear, Flat
......
...@@ -201,8 +201,14 @@ total water content (θw), and liquid water content (θl). ...@@ -201,8 +201,14 @@ total water content (θw), and liquid water content (θl).
I_c*(H/) + I_t I_c*(H/) + I_t
end end
end end
@inbounds @. state.θl = freezethaw(state.H, heat.L, state.θw)*state.θw @inbounds for i in 1:length(state.H)
heatcapacity!(layer, heat, state) # update heat capacity, C let θw = state.θw[i],
@inbounds @. state.T = enthalpyinv(state.H, state.C, heat.L, state.θw) H = state.H[i],
L = heat.L;
state.θl[i] = θw*freezethaw(H, L, θw)
state.C[i] = heatcapacity(layer, heat, state, i) # update heat capacity, C
state.T[i] = enthalpyinv(H, state.C[i], L, θw)
end
end
return nothing return nothing
end end
...@@ -12,7 +12,7 @@ struct TemperatureGradient{E,F} <: BoundaryProcess ...@@ -12,7 +12,7 @@ struct TemperatureGradient{E,F} <: BoundaryProcess
end end
BoundaryStyle(::Type{<:TemperatureGradient}) = Dirichlet() BoundaryStyle(::Type{<:TemperatureGradient}) = Dirichlet()
BoundaryStyle(::Type{<:TemperatureGradient{<:Damping}}) = Neumann() BoundaryStyle(::Type{<:TemperatureGradient{<:Damping}}) = Neumann()
@inline boundaryvalue(bc::TemperatureGradient, l1, p2, l2, s1, s2) where {F} = bc.T(s1.t) @inline boundaryvalue(bc::TemperatureGradient, l1, p2, l2, s1, s2) = bc.T(s1.t)
@with_kw struct NFactor{W,S} <: BoundaryEffect @with_kw struct NFactor{W,S} <: BoundaryEffect
winterfactor::W = Param(1.0, bounds=(0.0,1.0)) # applied when Tair <= 0 winterfactor::W = Param(1.0, bounds=(0.0,1.0)) # applied when Tair <= 0
......
# Thermal properties
@inline function heatcapacity(soil::Soil, totalwater, liquidwater, mineral, organic) @inline function heatcapacity(soil::Soil, totalwater, liquidwater, mineral, organic)
@unpack cw,co,cm,ca,ci = soil.hc @unpack cw,co,cm,ca,ci = soil.hc
let air = 1.0 - totalwater - mineral - organic, let air = 1.0 - totalwater - mineral - organic,
...@@ -14,13 +15,16 @@ end ...@@ -14,13 +15,16 @@ end
(liq*kw^0.5 + ice*ki^0.5 + mineral*km^0.5 + organic*ko^0.5 + air*ka^0.5)^2 (liq*kw^0.5 + ice*ki^0.5 + mineral*km^0.5 + organic*ko^0.5 + air*ka^0.5)^2
end end
end end
@inline function heatcapacity!(soil::Soil, ::Heat, state) @inline @propagate_inbounds heatcapacity(soil::Soil, ::Heat, state, i) = heatcapacity(soil, state.θw[i], state.θl[i], state.θm[i], state.θo[i])
@inbounds @. state.C = heatcapacity(soil, state.θw, state.θl, state.θm, state.θo) @inline @propagate_inbounds function heatcapacity!(soil::Soil, ::Heat, state)
@. state.C = heatcapacity(soil, state.θw, state.θl, state.θm, state.θo)
end end
@inline function thermalconductivity!(soil::Soil, ::Heat, state) @inline @propagate_inbounds thermalconductivity(soil::Soil, ::Heat, state, i) = thermalconductivity(soil, state.θw[i], state.θl[i], state.θm[i], state.θo[i])
@inbounds @. state.kc = thermalconductivity(soil, state.θw, state.θl, state.θm, state.θo) @inline @propagate_inbounds function thermalconductivity!(soil::Soil, ::Heat, state)
@. state.kc = thermalconductivity(soil, state.θw, state.θl, state.θm, state.θo)
end end
# SFCC
include("sfcc.jl") include("sfcc.jl")
""" """
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment