From 3c0a2d76f1acea9af5a6a9c9cbc1df73d8ae2766 Mon Sep 17 00:00:00 2001 From: Skylar Gering Date: Mon, 1 Jul 2024 15:50:33 -0400 Subject: [PATCH] Clarify float types for simulations and consts --- examples/many_floes.jl | 15 ++++++++------- src/simulation_components/floe.jl | 25 ++++++++++++++++++------- src/simulation_components/simulation.jl | 6 +++--- 3 files changed, 29 insertions(+), 17 deletions(-) diff --git a/examples/many_floes.jl b/examples/many_floes.jl index 4ca5eb1..c6236d0 100644 --- a/examples/many_floes.jl +++ b/examples/many_floes.jl @@ -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) @@ -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) diff --git a/src/simulation_components/floe.jl b/src/simulation_components/floe.jl index 46e62b2..003b1b1 100644 --- a/src/simulation_components/floe.jl +++ b/src/simulation_components/floe.jl @@ -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, @@ -352,7 +363,7 @@ Output: floe_arr list of floes created from given polygon coordinates """ -function initialize_floe_field( +function _initialize_floe_field( ::Type{FT}, coords::V, domain, @@ -502,7 +513,7 @@ function generate_voronoi_coords( end """ - initialize_floe_field( + _initialize_floe_field( ::Type{FT}, nfloes, concentrations, @@ -543,7 +554,7 @@ Output: floe_arr 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, diff --git a/src/simulation_components/simulation.jl b/src/simulation_components/simulation.jl index e036c74..2396432 100644 --- a/src/simulation_components/simulation.jl +++ b/src/simulation_components/simulation.jl @@ -25,8 +25,8 @@ 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...) @@ -34,7 +34,7 @@ Constants(::Type{FT}, args...) where {FT <: AbstractFloat} = 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}}