Skip to content

Commit

Permalink
Fix presolver 1D not handling saturation parameter
Browse files Browse the repository at this point in the history
  • Loading branch information
bgroenks96 committed Aug 7, 2024
1 parent a847efc commit 3695e16
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "FreezeCurves"
uuid = "71e4ad71-e4f2-45a3-aa0a-91ffaa9676be"
authors = ["Brian Groenke <brian.groenke@awi.de> and contributors"]
version = "0.9.1"
version = "0.9.2"

[deps]
Flatten = "4c728ea3-d9ee-5c9a-9642-b6f7d7dc04fa"
Expand Down
11 changes: 8 additions & 3 deletions src/sfccsolvers/presolver.jl
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,14 @@ Note that this presolver implementation is **only valid when all other freeze cu
"""
mutable struct SFCCPreSolverCache1D{TF} <: AbstractPreSolverCache
f_H::TF # θw(H) interpolant
ΔH_min::Float64
initialized::Bool
function SFCCPreSolverCache1D()
function SFCCPreSolverCache1D(ΔH_min=1e-3)
# initialize with dummy functions to get type information;
# this is just to make sure that the compiler can still infer all of the types.
x = -3e8:1e6:3e8
dummy_f = _build_interpolant1D(x, zeros(length(x)))
return new{typeof(dummy_f)}(dummy_f, false)
return new{typeof(dummy_f)}(dummy_f, ΔH_min, false)
end
end
function _build_interpolant1D(H, θw)
Expand Down Expand Up @@ -67,7 +68,7 @@ function initialize!(solver::SFCCPreSolver{<:SFCCPreSolverCache1D}, fc::SFCC, hc
ρw = SoilWaterVolume(fc).ρw,
L = ρw*Lsl,
f_kwargs = (; θsat, fc_kwargs...),
f(T) = fc(T; f_kwargs...),
f(T) = fc(T, sat; f_kwargs...),
Hmin = FreezeCurves.enthalpy(Tmin, hc(f(Tmin), sat*θsat, θsat), L, f(Tmin)),
Hmax = FreezeCurves.enthalpy(Tmax, hc(f(Tmax), sat*θsat, θsat), L, f(Tmax));
# residual as a function of T and H
Expand Down Expand Up @@ -107,6 +108,10 @@ function initialize!(solver::SFCCPreSolver{<:SFCCPreSolverCache1D}, fc::SFCC, hc
ϵ = step(ΔH, H[end], θw[end], ∂θw∂H[end], T[end])
# iteratively halve the step size until error tolerance is satisfied
ΔH *= 0.5
if ΔH < solver.cache.ΔH_min
@warn "ΔH ($ΔH) < ΔH_min ($(solver.cache.ΔH_min))! SFCC approximation tolerance not guaranteed (ϵ = )"
break
end
end
Hnew = H[end] + ΔH
@assert isfinite(Hnew) "isfinite(ΔH) failed; H=$(H[end]), T=$(T[end]), ΔH=$ΔH"
Expand Down

2 comments on commit 3695e16

@bgroenks96
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/112577

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.9.2 -m "<description of version>" 3695e1665bc9f062431a1925b09f746194bfcf1e
git push origin v0.9.2

Please sign in to comment.