From 57b790e3bf014355e42cf17aaec00eecc5ae0dc9 Mon Sep 17 00:00:00 2001 From: Sarah Williamson Date: Mon, 13 May 2024 12:40:02 -0500 Subject: [PATCH 1/4] Adding a new function that runs the setup of structure S --- src/run_model.jl | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) diff --git a/src/run_model.jl b/src/run_model.jl index 396edf7..ee398de 100644 --- a/src/run_model.jl +++ b/src/run_model.jl @@ -39,4 +39,35 @@ function run_model(::Type{T},P::Parameter) where {T<:AbstractFloat} return Prog +end + +function run_setup(::Type{T}=Float32; # number format + kwargs... # all additional parameters + ) where {T<:AbstractFloat} + + P = ShallowWaters.Parameter(T=T;kwargs...) + return run_setup(T,P) +end + +function run_setup(P::ShallowWaters.Parameter) + @unpack T = P + return run_setup(T,P) +end + +function run_setup(::Type{T},P::ShallowWaters.Parameter) where {T<:AbstractFloat} + + @unpack Tprog = P + + G = ShallowWaters.Grid{T,Tprog}(P) + C = ShallowWaters.Constants{T,Tprog}(P,G) + F = ShallowWaters.Forcing{T}(P,G) + + Prog = ShallowWaters.initial_conditions(Tprog,G,P,C) + Diag = ShallowWaters.preallocate(T,Tprog,G) + + # one structure with everything inside + S = ShallowWaters.ModelSetup{T,Tprog}(P,G,C,F,Prog,Diag,0) + + return S + end \ No newline at end of file From 42e781772604dc2d515f40f538e8634e6596f69e Mon Sep 17 00:00:00 2001 From: Sarah Williamson Date: Tue, 14 May 2024 13:04:22 -0500 Subject: [PATCH 2/4] Modifying function name --- src/run_model.jl | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/run_model.jl b/src/run_model.jl index ee398de..01707a8 100644 --- a/src/run_model.jl +++ b/src/run_model.jl @@ -41,20 +41,20 @@ function run_model(::Type{T},P::Parameter) where {T<:AbstractFloat} end -function run_setup(::Type{T}=Float32; # number format +function model_setup(::Type{T}=Float32; # number format kwargs... # all additional parameters ) where {T<:AbstractFloat} P = ShallowWaters.Parameter(T=T;kwargs...) - return run_setup(T,P) + return model_setup(T,P) end -function run_setup(P::ShallowWaters.Parameter) +function model_setup(P::ShallowWaters.Parameter) @unpack T = P - return run_setup(T,P) + return model_setup(T,P) end -function run_setup(::Type{T},P::ShallowWaters.Parameter) where {T<:AbstractFloat} +function model_setup(::Type{T},P::ShallowWaters.Parameter) where {T<:AbstractFloat} @unpack Tprog = P From b69bdbfc9911b21acc3f3aeb342cec4acf5de9c0 Mon Sep 17 00:00:00 2001 From: Sarah Williamson Date: Tue, 14 May 2024 13:09:50 -0500 Subject: [PATCH 3/4] Also making it so model_setup is exported in ShallowWaters.jl --- src/ShallowWaters.jl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/ShallowWaters.jl b/src/ShallowWaters.jl index fda5303..de2b84b 100644 --- a/src/ShallowWaters.jl +++ b/src/ShallowWaters.jl @@ -1,6 +1,6 @@ module ShallowWaters - export run_model, Parameter, ∂x, ∂y, Ix, Iy, ∇² + export run_model, model_setup, Parameter, ∂x, ∂y, Ix, Iy, ∇² using NetCDF, Parameters, Printf, Dates, Interpolations From 91ad016060ccf048959a78b4115f4ca9a06e5548 Mon Sep 17 00:00:00 2001 From: Sarah Williamson Date: Tue, 14 May 2024 13:17:08 -0500 Subject: [PATCH 4/4] Removing ShallowWaters. everywhere it was used --- src/run_model.jl | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/run_model.jl b/src/run_model.jl index 01707a8..a3bac94 100644 --- a/src/run_model.jl +++ b/src/run_model.jl @@ -42,31 +42,30 @@ function run_model(::Type{T},P::Parameter) where {T<:AbstractFloat} end function model_setup(::Type{T}=Float32; # number format - kwargs... # all additional parameters + kwargs... # all additional parameters ) where {T<:AbstractFloat} - P = ShallowWaters.Parameter(T=T;kwargs...) + P = Parameter(T=T;kwargs...) return model_setup(T,P) end -function model_setup(P::ShallowWaters.Parameter) +function model_setup(P::Parameter) @unpack T = P return model_setup(T,P) end -function model_setup(::Type{T},P::ShallowWaters.Parameter) where {T<:AbstractFloat} +function model_setup(::Type{T},P::Parameter) where {T<:AbstractFloat} @unpack Tprog = P - G = ShallowWaters.Grid{T,Tprog}(P) - C = ShallowWaters.Constants{T,Tprog}(P,G) - F = ShallowWaters.Forcing{T}(P,G) + G = Grid{T,Tprog}(P) + C = Constants{T,Tprog}(P,G) + F = Forcing{T}(P,G) - Prog = ShallowWaters.initial_conditions(Tprog,G,P,C) - Diag = ShallowWaters.preallocate(T,Tprog,G) + Prog = initial_conditions(Tprog,G,P,C) + Diag = preallocate(T,Tprog,G) - # one structure with everything inside - S = ShallowWaters.ModelSetup{T,Tprog}(P,G,C,F,Prog,Diag,0) + S = ModelSetup{T,Tprog}(P,G,C,F,Prog,Diag,0) return S