Skip to content

Commit

Permalink
Clarify float types for simulations and consts
Browse files Browse the repository at this point in the history
  • Loading branch information
skygering committed Jul 1, 2024
1 parent 1aee7db commit 3c0a2d7
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 17 deletions.
15 changes: 8 additions & 7 deletions examples/many_floes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,22 @@ const coarse_ny = 10

# Model instantiation
grid = RegRectilinearGrid(
FT,
(-Lx, Lx),
(-Ly, Ly),
Δgrid,
Δgrid,
)

ocean = Ocean(grid, -0.2, 0.0, -1.0)
ocean = Ocean(FT, grid, -0.2, 0.0, -1.0)

atmos = Atmos(grid, 0.0, 0.0, -3.0)
atmos = Atmos(FT, grid, 0.0, 0.0, -3.0)

# Domain creation - boundaries and topography
nboundary = OpenBoundary(North, grid)
sboundary = OpenBoundary(South, grid)
eboundary = OpenBoundary(East, grid)
wboundary = OpenBoundary(West, grid)
nboundary = OpenBoundary(FT, North, grid)
sboundary = OpenBoundary(FT, South, grid)
eboundary = OpenBoundary(FT, East, grid)
wboundary = OpenBoundary(FT, West, grid)

domain = Subzero.Domain(nboundary, sboundary, eboundary, wboundary)

Expand All @@ -46,7 +47,7 @@ model = Model(grid, ocean, atmos, domain, floe_arr)

# Simulation setup
modulus = 1.5e3*(mean(sqrt.(floe_arr.area)) + minimum(sqrt.(floe_arr.area)))
consts = Constants(E = modulus)
consts = Constants(FT; E = modulus)
#consts = Constants(E = modulus, Cd_io = 0.0, Cd_ia = 0.0, Cd_ao = 0.0, f = 0.0, μ = 0.0) # collisions without friction
simulation = Simulation(; model, consts, Δt, nΔt = 4000, verbose = true)

Expand Down
25 changes: 18 additions & 7 deletions src/simulation_components/floe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -313,17 +313,28 @@ function poly_to_floes!(
return 0
end


"""
initialize_floe_field(args...)
If a type isn't specified, the list of Floes will each be of type Float64 and
the correct constructor will be called with all other arguments.
A float type FT can be provided as the first argument of the initialize_floe_field
constructor. A field of floes of type FT will be created by passing all other
arguments to the correct method.
"""
initialize_floe_field(args...; kwargs...) =
initialize_floe_field(Float64, args...; kwargs...)
_initialize_floe_field(Float64, args...; kwargs...)

"""
initialize_floe_field(args...)
If a type isn't specified, the field of Floes will each be of type Float64 and
the correct constructor will be called with all other arguments.
"""
initialize_floe_field(::Type{FT}, args...; kwargs...) where FT =
_initialize_floe_field(FT, args...; kwargs...)

"""
initialize_floe_field(
_initialize_floe_field(
::Type{FT},
coords,
domain,
Expand Down Expand Up @@ -352,7 +363,7 @@ Output:
floe_arr <StructArray{Floe}> list of floes created from given polygon
coordinates
"""
function initialize_floe_field(
function _initialize_floe_field(
::Type{FT},
coords::V,
domain,
Expand Down Expand Up @@ -502,7 +513,7 @@ function generate_voronoi_coords(
end

"""
initialize_floe_field(
_initialize_floe_field(
::Type{FT},
nfloes,
concentrations,
Expand Down Expand Up @@ -543,7 +554,7 @@ Output:
floe_arr <StructArray> list of floes created using Voronoi Tesselation
of the domain with given concentrations.
"""
function initialize_floe_field(
function _initialize_floe_field(
::Type{FT},
nfloes::Int,
concentrations,
Expand Down
6 changes: 3 additions & 3 deletions src/simulation_components/simulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ A float type FT can be provided as the first argument of any Constants
constructor. A Constants of type FT will be created by passing all other
arguments to the correct constructor.
"""
Constants(::Type{FT}, args...) where {FT <: AbstractFloat} =
Constants{FT}(args...)
Constants(::Type{FT}, args...; kwargs...) where {FT <: AbstractFloat} =
Constants{FT}(args...; kwargs...)

"""
Constants(args...)
If a type isn't specified, Constants will be of type Float64 and the correct
constructor will be called with all other arguments.
"""
Constants(args...) = Constants{Float64}(args...)
Constants(args...; kwargs...) = Constants{Float64}(args...; kwargs...)

"""
Simulation{FT<:AbstractFloat, DT<:Domain{FT}}
Expand Down

0 comments on commit 3c0a2d7

Please sign in to comment.