Skip to content

Commit 745dbb0

Browse files
authored
Clean up treatment of floating point precision (#346)
1 parent a27e5f1 commit 745dbb0

10 files changed

+29
-27
lines changed

src/Bathymetry.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ function regrid_bathymetry(target_grid;
165165
Nyn = length(φ_data)
166166
Nzn = 1
167167

168-
native_grid = LatitudeLongitudeGrid(arch;
168+
native_grid = LatitudeLongitudeGrid(arch, Float32;
169169
size = (Nxn, Nyn, Nzn),
170170
latitude = (φ₁_data, φ₂_data),
171171
longitude = (λ₁_data, λ₂_data),
@@ -234,7 +234,7 @@ function interpolate_bathymetry_in_passes(native_z, target_grid;
234234

235235
@debug "Bathymetry interpolation pass $pass with size $new_size"
236236

237-
new_grid = LatitudeLongitudeGrid(architecture(target_grid),
237+
new_grid = LatitudeLongitudeGrid(architecture(target_grid), Float32,
238238
size = new_size,
239239
latitude = (latitude[1], latitude[2]),
240240
longitude = (longitude[1], longitude[2]),

src/DataWrangling/ECCO/ECCO.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,7 +115,7 @@ function empty_ECCO_field(metadata::ECCOMetadata;
115115
sz = (Nx, Ny)
116116
end
117117

118-
grid = LatitudeLongitudeGrid(architecture; halo, longitude, latitude, z,
118+
grid = LatitudeLongitudeGrid(architecture, Float32; halo, longitude, latitude, z,
119119
size = sz,
120120
topology = (TX, TY, TZ))
121121

src/OceanSeaIceModels/InterfaceComputations/coefficient_based_turbulent_fluxes.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ end
1212
convert_if_number(FT, a::Number) = convert(FT, a)
1313
convert_if_number(FT, a) = a
1414

15-
function CoefficientBasedFluxes(FT = Float64;
15+
function CoefficientBasedFluxes(FT = Oceananigans.defaults.FloatType;
1616
drag_coefficient = 1e-3,
1717
gravitational_acceleration = g_Earth,
1818
heat_transfer_coefficient = drag_coefficient,

src/OceanSeaIceModels/InterfaceComputations/interface_states.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ struct WaterMoleFraction{FT, C}
5959
salinity_constituents :: C
6060
end
6161

62-
function WaterMoleFraction(FT=Float64)
62+
function WaterMoleFraction(FT=Oceananigans.defaults.FloatType)
6363
water_molar_mass = convert(FT, 18.02)
6464

6565
# TODO: find reference for these

src/OceanSeaIceModels/InterfaceComputations/radiation.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ Keyword Arguments
3838
- `sea_ice_albedo`: The albedo of the sea ice surface. Default: `0.7`.
3939
- `stefan_boltzmann_constant`: The Stefan-Boltzmann constant. Default: `5.67e-8`.
4040
"""
41-
function Radiation(arch = CPU(), FT=Float64;
41+
function Radiation(arch = CPU(), FT=Oceananigans.defaults.FloatType;
4242
ocean_emissivity = 0.97,
4343
sea_ice_emissivity = 1.0,
4444
ocean_albedo = LatitudeDependentAlbedo(FT),

src/OceanSeaIceModels/InterfaceComputations/roughness_lengths.jl

+9-9
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ struct ScalarRoughnessLength{FT, V, R}
1313
end
1414

1515
"""
16-
ScalarRoughnessLength([FT=Float64];
16+
ScalarRoughnessLength(FT = Float64;
1717
air_kinematic_viscosity = temperature_dependent_viscosity,
1818
reynolds_number_scaling_function = empirical_scaling_function,
1919
maximum_roughness_length = 1.6e-4)
@@ -28,7 +28,7 @@ Keyword Arguments
2828
- `reynolds_number_scaling_function::Function`: The function to compute the Reynolds number scaling factor.
2929
- `maximum_roughness_length::Float`: The maximum roughness length value. Defaults to `1.6e-4`.
3030
"""
31-
function ScalarRoughnessLength(FT=Float64;
31+
function ScalarRoughnessLength(FT=Oceananigans.defaults.FloatType;
3232
air_kinematic_viscosity = TemperatureDependentAirViscosity(FT),
3333
reynolds_number_scaling_function = ReynoldsScalingFunction(FT),
3434
maximum_roughness_length = 1.6e-4) # Values from COARE3.6
@@ -39,7 +39,7 @@ function ScalarRoughnessLength(FT=Float64;
3939
end
4040

4141
"""
42-
MomentumRoughnessLength([FT=Float64];
42+
MomentumRoughnessLength(FT = Float64;
4343
gravitational_acceleration = default_gravitational_acceleration,
4444
maximum_roughness_length = 1.0,
4545
air_kinematic_viscosity = TemperatureDependentAirViscosity(FT),
@@ -58,7 +58,7 @@ Keyword Arguments
5858
- `gravity_wave_parameter`: The wave parameter. Default: 0.011.
5959
- `laminar_parameter`: The laminar parameter. Default: 0.11.
6060
"""
61-
function MomentumRoughnessLength(FT=Float64;
61+
function MomentumRoughnessLength(FT=Oceananigans.defaults.FloatType;
6262
gravitational_acceleration = default_gravitational_acceleration,
6363
maximum_roughness_length = 1.0, # An estimate?
6464
air_kinematic_viscosity = TemperatureDependentAirViscosity(FT),
@@ -72,7 +72,7 @@ function MomentumRoughnessLength(FT=Float64;
7272
convert(FT, maximum_roughness_length))
7373
end
7474

75-
function default_roughness_lengths(FT=Float64)
75+
function default_roughness_lengths(FT=Oceananigans.defaults.FloatType)
7676
momentum = MomentumRoughnessLength(FT)
7777
temperature = ScalarRoughnessLength(FT)
7878
water_vapor = ScalarRoughnessLength(FT)
@@ -88,7 +88,7 @@ struct TemperatureDependentAirViscosity{FT}
8888
end
8989

9090
"""
91-
TemperatureDependentAirViscosity([FT = Float64;
91+
TemperatureDependentAirViscosity([FT = Oceananigans.defaults.FloatType;
9292
C₀ = 1.326e-5,
9393
C₁ = C₀ * 6.542e-3,
9494
C₂ = C₀ * 8.301e-6,
@@ -100,7 +100,7 @@ viscosity of air as
100100
C₀ + C₁ T + C₂ T^2 + C₃ T^3.
101101
```
102102
"""
103-
function TemperatureDependentAirViscosity(FT = Float64;
103+
function TemperatureDependentAirViscosity(FT = Oceananigans.defaults.FloatType;
104104
C₀ = 1.326e-5,
105105
C₁ = C₀ * 6.542e-3,
106106
C₂ = C₀ * 8.301e-6,
@@ -148,15 +148,15 @@ struct ReynoldsScalingFunction{FT}
148148
end
149149

150150
"""
151-
ReynoldsScalingFunction(FT = Float64; A = 5.85e-5, b = 0.72)
151+
ReynoldsScalingFunction(FT=Float64; A=5.85e-5, b=0.72)
152152
153153
Empirical fit of the scalar roughness length with roughness Reynolds number `R★ = u★ ℓu / ν`.
154154
Edson et al. (2013), equation (28).
155155
```math
156156
ℓs = A / R★ ^ b
157157
```
158158
"""
159-
ReynoldsScalingFunction(FT = Float64; A = 5.85e-5, b = 0.72) =
159+
ReynoldsScalingFunction(FT = Oceananigans.defaults.FloatType; A = 5.85e-5, b = 0.72) =
160160
ReynoldsScalingFunction(convert(FT, A), convert(FT, b))
161161

162162
@inline (s::ReynoldsScalingFunction)(R★, args...) = ifelse(R★ == 0, convert(eltype(R★), 0), s.A / R★ ^ s.b)

src/OceanSeaIceModels/InterfaceComputations/similarity_theory_turbulent_fluxes.jl

+3-3
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ Keyword Arguments
106106
- `solver_tolerance`: The tolerance for convergence. Default: 1e-8.
107107
- `solver_maxiter`: The maximum number of iterations. Default: 100.
108108
"""
109-
function SimilarityTheoryFluxes(FT::DataType = Float64;
109+
function SimilarityTheoryFluxes(FT::DataType = Oceananigans.defaults.FloatType;
110110
gravitational_acceleration = g_Earth,
111111
von_karman_constant = 0.4,
112112
turbulent_prandtl_number = 1,
@@ -462,7 +462,7 @@ end
462462
end
463463

464464
# Edson et al. (2013)
465-
function edson_stability_functions(FT = Float64)
465+
function edson_stability_functions(FT=Oceananigans.defaults.FloatType)
466466
ψu = EdsonMomentumStabilityFunction{FT}()
467467
ψc = EdsonScalarStabilityFunction{FT}()
468468
return SimilarityScales(ψu, ψc, ψc)
@@ -559,7 +559,7 @@ end
559559
return ifelse(stable, Ψ_stable, Ψ_unstable)
560560
end
561561

562-
function atmosphere_sea_ice_stability_functions(FT=Float64)
562+
function atmosphere_sea_ice_stability_functions(FT=Oceananigans.defaults.FloatType)
563563
stable_momentum = PaulsonMomentumStabilityFunction{FT}()
564564
unstable_momentum = ShebaMomentumStabilityFunction{FT}()
565565
momentum = SplitStabilityFunction(stable_momentum, unstable_momentum)

src/OceanSeaIceModels/InterfaceComputations/tabulated_albedo.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ Keyword Arguments
7979
- `φ_values`: The latitude values for the table. Default: `(0:2:90) ./ 180 * π`.
8080
- `𝓉_values`: The transmissivity values for the table. Default: `0:0.05:1`.
8181
"""
82-
function TabulatedAlbedo(arch = CPU(), FT = Float64;
82+
function TabulatedAlbedo(arch = CPU(), FT = Oceananigans.defaults.FloatType;
8383
S₀ = convert(FT, 1365),
8484
α_table = α_payne,
8585
φ_values = (0:2:90) ./ 180 * π,

src/OceanSeaIceModels/PrescribedAtmospheres.jl

+8-7
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ end
6363
Base.show(io::IO, p::ConstitutiveParameters) = print(io, summary(p))
6464

6565
"""
66-
ConstitutiveParameters(FT; gas_constant = 8.3144598,
67-
dry_air_molar_mass = 0.02897,
68-
water_molar_mass = 0.018015)
66+
ConstitutiveParameters(FT = Float64;
67+
gas_constant = 8.3144598,
68+
dry_air_molar_mass = 0.02897,
69+
water_molar_mass = 0.018015)
6970
7071
Construct a set of parameters that define the density of moist air,
7172
@@ -85,7 +86,7 @@ where
8586
8687
For more information see [reference docs].
8788
"""
88-
function ConstitutiveParameters(FT = Float64;
89+
function ConstitutiveParameters(FT = Oceananigans.defaults.FloatType;
8990
gas_constant = 8.3144598,
9091
dry_air_molar_mass = 0.02897,
9192
water_molar_mass = 0.018015)
@@ -130,7 +131,7 @@ Base.show(io::IO, p::HeatCapacityParameters) = print(io, summary(p))
130131
131132
Isobaric heat capacities.
132133
"""
133-
function HeatCapacityParameters(FT = Float64;
134+
function HeatCapacityParameters(FT = Oceananigans.defaults.FloatType;
134135
dry_air_adiabatic_exponent = 2/7,
135136
water_vapor_heat_capacity = 1859,
136137
liquid_water_heat_capacity = 4181,
@@ -173,7 +174,7 @@ end
173174

174175
Base.show(io::IO, p::PhaseTransitionParameters) = print(io, summary(p))
175176

176-
function PhaseTransitionParameters(FT = Float64;
177+
function PhaseTransitionParameters(FT = Oceananigans.defaults.FloatType;
177178
reference_vaporization_enthalpy = 2500800,
178179
reference_sublimation_enthalpy = 2834400,
179180
reference_temperature = 273.16,
@@ -244,7 +245,7 @@ function Base.show(io::IO, p::PrescribedAtmosphereThermodynamicsParameters)
244245
" └── total_ice_nucleation_temperature (Tⁱ): ", prettysummary(pt.total_ice_nucleation_temperature))
245246
end
246247

247-
function PrescribedAtmosphereThermodynamicsParameters(FT=Float64;
248+
function PrescribedAtmosphereThermodynamicsParameters(FT = Oceananigans.defaults.FloatType;
248249
constitutive = ConstitutiveParameters(FT),
249250
phase_transitions = PhaseTransitionParameters(FT),
250251
heat_capacity = HeatCapacityParameters(FT))

src/OceanSeaIceModels/freezing_limited_ocean_temperature.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ the `T < Tₘ` except for heating to allow temperature to increase.
2323
2424
The melting temperature is a function of salinity and is controlled by the `liquidus`.
2525
"""
26-
FreezingLimitedOceanTemperature(FT::DataType=Float64) = FreezingLimitedOceanTemperature(LinearLiquidus(FT))
26+
FreezingLimitedOceanTemperature(FT::DataType=Oceananigans.defaults.FloatType) =
27+
FreezingLimitedOceanTemperature(LinearLiquidus(FT))
2728

2829
const FreezingLimitedCoupledModel = OceanSeaIceModel{<:FreezingLimitedOceanTemperature}
2930

0 commit comments

Comments
 (0)