Skip to content

Commit

Permalink
Merge pull request #4 from jagoosw/jsw/adapts
Browse files Browse the repository at this point in the history
Add adapt methods for wind stress and heat exchange
  • Loading branch information
jagoosw committed Dec 27, 2023
2 parents 1620a94 + 788f921 commit 0e9ff4e
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 2 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "Walrus"
uuid = "bec5164f-1c7a-4c32-8768-be9354254d6a"
authors = ["Jago Stong-Wright <jagoosw@protonmail.com>"]
version = "0.4.1"
version = "0.4.2"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
6 changes: 6 additions & 0 deletions src/Walrus.jl
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@ export WindStress, WindStressBoundaryConditions, LogarithmicNeutralWind

export SurfaceHeatExchange, SurfaceHeatExchangeBoundaryCondition

using Adapt: adapt

import Adapt: adapt_structure

# This is how we will standarise function vs values, I will have to think of a way to deal with discrete vs continuous at some point
struct ReturnValue{FT}
value :: FT
end

adapt_structure(to, rv::ReturnValue) = ReturnValue(adapt(to, rv.value))

@inline (return_value::ReturnValue)(args...) = return_value.value

display_input(return_value::ReturnValue) = return_value.value
Expand Down
16 changes: 16 additions & 0 deletions src/surface_heating.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,17 @@ export SurfaceHeatExchange, SurfaceHeatExchangeBoundaryCondition

using Roots

using Adapt: adapt

using Oceananigans.BoundaryConditions: FluxBoundaryCondition

using Walrus: ReturnValue, display_input
using Walrus.WindStressModel: WindStress,
LogarithmicNeutralWind,
find_velocity_roughness_length

import Adapt: adapt_structure

struct SurfaceHeatExchange{WS, AT, LH, VP, FT} <: Function
wind_stress :: WS
air_temperature :: AT
Expand All @@ -24,6 +28,18 @@ struct SurfaceHeatExchange{WS, AT, LH, VP, FT} <: Function
stephan_boltzman_constant :: FT
end

adapt_structure(to, sh::SurfaceHeatExchange) =
SurfaceHeatExchange(adapt(to, sh.wind_stress),
adapt(to, sh.air_temperature),
adapt(to, sh.latent_heat_vaporisation),
adapt(to, sh.vapour_pressure),
sh.water_specific_heat_capacity,
sh.water_density,
sh.air_specific_heat_capacity,
sh.air_density,
sh.air_water_mixing_ratio,
sh.stephan_boltzman_constant)

"""
SurfaceHeatExchange(; wind_stress,
air_temperature = 18, # °C
Expand Down
13 changes: 12 additions & 1 deletion src/wind_stress.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,13 @@ module WindStressModel
export WindStress, WindStressBoundaryConditions, LogarithmicNeutralWind

using Roots
using Walrus: ReturnValue, display_input

using Adapt: adapt
using Oceananigans.BoundaryConditions: FluxBoundaryCondition
using Oceananigans.BuoyancyModels: g_Earth
using Walrus: ReturnValue, display_input

import Adapt: adapt_structure
import Base: summary, show

struct WindStress{WS, WD, DC, FT} <: Function
Expand All @@ -17,6 +20,12 @@ struct WindStress{WS, WD, DC, FT} <: Function
water_density :: FT
end

adapt_structure(to, ws::WindStress) = WindStress(adapt(to, ws.reference_wind_speed),
adapt(to, ws.reference_wind_direction),
adapt(to, ws.drag_coefficient),
ws.air_density,
ws.water_density)

"""
WindStress(; reference_wind_speed,
reference_wind_direction,
Expand Down Expand Up @@ -242,6 +251,8 @@ This parameterisaion is described in [smith1988](@citet)
gravity_acceleration :: FT = g_Earth
end

adapt_structure(to, dc::LogarithmicNeutralWind) = dc

@inline velocity_roughness_length_roots(z₀, params) =
log(params.reference_height/z₀)/(params.κ * params.wind_speed) *
(params.ν * params.b + params.aᶜ * (params.κ * params.wind_speed / log(params.reference_height/z₀))^3) - z₀
Expand Down

2 comments on commit 0e9ff4e

@jagoosw
Copy link
Owner Author

Choose a reason for hiding this comment

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

@JuliaRegistrator register

Release Note:

No breaking changes but quite a few bug fixes and edge case handling for wind stress solver (+should work on GPU now)

@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/97790

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.4.2 -m "<description of version>" 0e9ff4ebeac705e4aef3f2d86f95f61c12668f70
git push origin v0.4.2

Please sign in to comment.