From 1857358a9e66a04a63f524025e34c16ec88c6073 Mon Sep 17 00:00:00 2001 From: "Navid C. Constantinou" Date: Wed, 6 Mar 2024 23:25:15 +0200 Subject: [PATCH 1/2] some code alignment + delete unnecessary spaces --- src/dynamics/time_integration.jl | 2 +- src/models/barotropic.jl | 2 +- src/output/callbacks.jl | 4 ++-- src/output/output.jl | 13 +++++++------ test/utility_functions.jl | 2 +- 5 files changed, 12 insertions(+), 11 deletions(-) diff --git a/src/dynamics/time_integration.jl b/src/dynamics/time_integration.jl index a61ac6a70..7ad72e20f 100644 --- a/src/dynamics/time_integration.jl +++ b/src/dynamics/time_integration.jl @@ -154,7 +154,7 @@ function leapfrog!( A_old::LowerTriangularMatrix{Complex{NF}}, # prognostic end # variables that are leapfrogged in the respective models that are on layers (so excl surface pressure) -leapfrog_layer_vars(::Barotropic) = (:vor, ) +leapfrog_layer_vars(::Barotropic) = (:vor,) leapfrog_layer_vars(::ShallowWater) = (:vor, :div) leapfrog_layer_vars(::PrimitiveDry) = (:vor, :div, :temp) leapfrog_layer_vars(::PrimitiveWet) = (:vor, :div, :temp, :humid) diff --git a/src/models/barotropic.jl b/src/models/barotropic.jl index 9e08f7d63..6719418b3 100644 --- a/src/models/barotropic.jl +++ b/src/models/barotropic.jl @@ -53,7 +53,7 @@ Base.@kwdef mutable struct BarotropicModel{ feedback::FB = Feedback() end -has(::Type{<:Barotropic}, var_name::Symbol) = var_name in (:vor, ) +has(::Type{<:Barotropic}, var_name::Symbol) = var_name in (:vor,) default_concrete_model(::Type{Barotropic}) = BarotropicModel """ diff --git a/src/output/callbacks.jl b/src/output/callbacks.jl index 7f48615fa..9bdddada4 100644 --- a/src/output/callbacks.jl +++ b/src/output/callbacks.jl @@ -109,8 +109,8 @@ function initialize!( model::ModelSetup, ) where NF callback.temp = Vector{NF}(undef, progn.clock.n_timesteps+1) # replace with vector of correct length - callback.temp[1] = diagn.layers[diagn.nlev].temp_average[] # set initial conditions - callback.timestep_counter = 1 # (re)set counter to 1 + callback.temp[1] = diagn.layers[diagn.nlev].temp_average[] # set initial conditions + callback.timestep_counter = 1 # (re)set counter to 1 end """ diff --git a/src/output/output.jl b/src/output/output.jl index 52d008281..6094feacd 100644 --- a/src/output/output.jl +++ b/src/output/output.jl @@ -193,8 +193,9 @@ function initialize!( (;startdate) = output time_string = "hours since $(Dates.format(startdate, "yyyy-mm-dd HH:MM:0.0"))" defDim(dataset, "time", Inf) # unlimited time dimension - defVar(dataset, "time", Float64, ("time", ), attrib=Dict("units"=>time_string, "long_name"=>"time", - "standard_name"=>"time", "calendar"=>"proleptic_gregorian")) + defVar(dataset, "time", Float64, ("time",), + attrib=Dict("units"=>time_string, "long_name"=>"time", + "standard_name"=>"time", "calendar"=>"proleptic_gregorian")) # DEFINE NETCDF DIMENSIONS SPACE (;input_Grid, output_Grid, nlat_half) = output @@ -209,7 +210,7 @@ function initialize!( else # output grid directly into a matrix (resort grid points, no interpolation) (;nlat_half) = diagn # don't use output.nlat_half as not supported for output_matrix - nlon, nlat = RingGrids.matrix_size(input_Grid, nlat_half) # size of the matrix output + nlon, nlat = RingGrids.matrix_size(input_Grid, nlat_half) # size of the matrix output lond = collect(1:nlon) # just enumerate grid points for lond, latd latd = collect(1:nlat) lon_name, lon_units, lon_longname = "i", "1", "horizontal index i" @@ -221,9 +222,9 @@ function initialize!( output.as_matrix || RingGrids.update_locator!(output.interpolator, latds, londs) σ = output_NF.(model.geometry.σ_levels_full) - defVar(dataset, lon_name, lond, (lon_name, ), attrib=Dict("units"=>lon_units, "long_name"=>lon_longname)) - defVar(dataset, lat_name, latd, (lat_name, ), attrib=Dict("units"=>lat_units, "long_name"=>lat_longname)) - defVar(dataset, "lev", σ, ("lev", ), attrib=Dict("units"=>"1", "long_name"=>"sigma levels")) + defVar(dataset, lon_name, lond, (lon_name,), attrib=Dict("units"=>lon_units, "long_name"=>lon_longname)) + defVar(dataset, lat_name, latd, (lat_name,), attrib=Dict("units"=>lat_units, "long_name"=>lat_longname)) + defVar(dataset, "lev", σ, ("lev",), attrib=Dict("units"=>"1", "long_name"=>"sigma levels")) # VARIABLES, define every variable here that could be output (;compression_level) = output diff --git a/test/utility_functions.jl b/test/utility_functions.jl index 68a183dcc..5ea821330 100644 --- a/test/utility_functions.jl +++ b/test/utility_functions.jl @@ -48,7 +48,7 @@ end end @testset "nans" begin - for s in ((3, ), (3, 4), (3, 4, 5)) + for s in ((3,), (3, 4), (3, 4, 5)) for T in (Float16, Float32, Float64) A = SpeedyWeather.nans(T, s...) for a in A From 1be34cfc7ed5dae99d20c11b002ca7380debf8f6 Mon Sep 17 00:00:00 2001 From: "Navid C. Constantinou" Date: Wed, 6 Mar 2024 23:43:14 +0200 Subject: [PATCH 2/2] space after ; --- README.md | 2 +- docs/src/callbacks.md | 6 +- docs/src/forcing_drag.md | 16 ++--- docs/src/grids.md | 2 +- docs/src/how_to_run_speedy.md | 8 +-- docs/src/output.md | 10 +-- docs/src/setups.md | 16 ++--- docs/src/spectral_transform.md | 2 +- docs/src/speedytransforms.md | 2 +- src/LowerTriangularMatrices/plot.jl | 2 +- src/RingGrids/grids_general.jl | 2 +- src/RingGrids/interpolation.jl | 4 +- src/RingGrids/octahealpix.jl | 6 +- src/RingGrids/octahedral.jl | 6 +- src/RingGrids/scaling.jl | 2 +- src/RingGrids/show.jl | 8 +-- src/SpeedyTransforms/aliasing.jl | 2 +- src/SpeedyTransforms/show.jl | 2 +- src/SpeedyTransforms/spectral_gradients.jl | 6 +- src/SpeedyTransforms/spectral_transform.jl | 24 +++---- src/SpeedyTransforms/spectral_truncation.jl | 8 +-- src/dynamics/adiabatic_conversion.jl | 6 +- src/dynamics/atmosphere.jl | 2 +- src/dynamics/coriolis.jl | 8 +-- src/dynamics/diagnostic_variables.jl | 22 +++--- src/dynamics/drag.jl | 2 +- src/dynamics/forcing.jl | 12 ++-- src/dynamics/geometry.jl | 2 +- src/dynamics/geopotential.jl | 18 ++--- src/dynamics/horizontal_diffusion.jl | 28 ++++---- src/dynamics/implicit.jl | 56 +++++++-------- src/dynamics/initial_conditions.jl | 50 +++++++------- src/dynamics/orography.jl | 24 +++---- src/dynamics/planet.jl | 2 +- src/dynamics/prognostic_variables.jl | 14 ++-- src/dynamics/spectral_grid.jl | 14 ++-- src/dynamics/tendencies.jl | 76 ++++++++++----------- src/dynamics/time_integration.jl | 42 ++++++------ src/dynamics/vertical_coordinates.jl | 2 +- src/dynamics/virtual_temperature.jl | 16 ++--- src/models/barotropic.jl | 4 +- src/models/primitive_dry.jl | 4 +- src/models/primitive_wet.jl | 6 +- src/models/shallow_water.jl | 4 +- src/models/simulation.jl | 4 +- src/output/feedback.jl | 6 +- src/output/output.jl | 20 +++--- src/output/plot.jl | 6 +- src/physics/boundary_layer.jl | 24 +++---- src/physics/column_variables.jl | 4 +- src/physics/convection.jl | 22 +++--- src/physics/land.jl | 30 ++++---- src/physics/land_sea_mask.jl | 8 +-- src/physics/large_scale_condensation.jl | 12 ++-- src/physics/longwave_radiation.jl | 6 +- src/physics/ocean.jl | 10 +-- src/physics/shortwave_radiation.jl | 4 +- src/physics/surface_fluxes.jl | 26 +++---- src/physics/temperature_relaxation.jl | 40 +++++------ src/physics/tendencies.jl | 8 +-- src/physics/thermodynamics.jl | 24 +++---- src/physics/vertical_diffusion.jl | 16 ++--- src/physics/zenith.jl | 28 ++++---- test/callbacks.jl | 6 +- test/column_variables.jl | 6 +- test/diffusion.jl | 10 +-- test/extending.jl | 34 ++++----- test/geopotential.jl | 12 ++-- test/interpolation.jl | 2 +- test/land_sea_mask.jl | 2 +- test/lower_triangular_matrix.jl | 2 +- test/netcdf_output.jl | 70 +++++++++---------- test/orography.jl | 2 +- test/run_speedy.jl | 8 +-- test/set_vars.jl | 4 +- test/spectral_gradients.jl | 20 +++--- test/spectral_transform.jl | 10 +-- 77 files changed, 519 insertions(+), 517 deletions(-) diff --git a/README.md b/README.md index 17f9fc8f6..26d957df3 100644 --- a/README.md +++ b/README.md @@ -31,7 +31,7 @@ With v0.6 the interface to SpeedyWeather.jl consist of 4 steps: define the grid, ```julia spectral_grid = SpectralGrid(trunc=31, Grid=OctahedralGaussianGrid, nlev=8) -model = PrimitiveDryModel(;spectral_grid, orography = EarthOrography(spectral_grid)) +model = PrimitiveDryModel(; spectral_grid, orography = EarthOrography(spectral_grid)) simulation = initialize!(model) run!(simulation, period=Day(10), output=true) ``` diff --git a/docs/src/callbacks.md b/docs/src/callbacks.md index 2f3dc83bf..5e384595f 100644 --- a/docs/src/callbacks.md +++ b/docs/src/callbacks.md @@ -74,7 +74,7 @@ function SpeedyWeather.initialize!( callback.maximum_surface_wind_speed = zeros(progn.clock.n_timesteps + 1) # where surface (=lowermost model layer) u, v on the grid are stored - (;u_grid, v_grid) = diagn.layers[diagn.nlev].grid_variables + (; u_grid, v_grid) = diagn.layers[diagn.nlev].grid_variables # maximum wind speed of initial conditions callback.maximum_surface_wind_speed[1] = max_2norm(u_grid, v_grid) @@ -124,7 +124,7 @@ function SpeedyWeather.callback!( i = callback.timestep_counter # where surface (=lowermost model layer) u, v on the grid are stored - (;u_grid, v_grid) = diagn.layers[diagn.nlev].grid_variables + (; u_grid, v_grid) = diagn.layers[diagn.nlev].grid_variables # maximum wind speed at current time step callback.maximum_surface_wind_speed[i] = max_2norm(u_grid, v_grid) @@ -188,7 +188,7 @@ Meaning that callbacks can be added before and after model construction ```@example callbacks spectral_grid = SpectralGrid() callbacks = CallbackDict(:callback_added_before => NoCallback()) -model = PrimitiveWetModel(;spectral_grid, callbacks) +model = PrimitiveWetModel(; spectral_grid, callbacks) add!(model.callbacks, :callback_added_afterwards => NoCallback()) ``` Let us add two more meaningful callbacks diff --git a/docs/src/forcing_drag.md b/docs/src/forcing_drag.md index 345943f8e..3bfebdaee 100644 --- a/docs/src/forcing_drag.md +++ b/docs/src/forcing_drag.md @@ -251,9 +251,9 @@ be used throughout model integration. But in SpeedyWeather we typically use the [SpectralGrid](@ref) object to pass on the information of the resolution (and number format) so we want a generator function like ```@example extend -function StochasticStirring(SG::SpectralGrid;kwargs...) - (;trunc, nlat) = SG - return StochasticStirring{SG.NF}(;trunc, nlat, kwargs...) +function StochasticStirring(SG::SpectralGrid; kwargs...) + (; trunc, nlat) = SG + return StochasticStirring{SG.NF}(; trunc, nlat, kwargs...) end ``` Which allows us to do @@ -275,7 +275,7 @@ function SpeedyWeather.initialize!( forcing::StochasticStirring, model::ModelSetup) # precompute forcing strength, scale with radius^2 as is the vorticity equation - (;radius) = model.spectral_grid + (; radius) = model.spectral_grid A = radius^2 * forcing.strength # precompute noise and auto-regressive factor, packed in RefValue for mutability @@ -285,7 +285,7 @@ function SpeedyWeather.initialize!( forcing::StochasticStirring, forcing.b[] = exp(-dt/τ) # precompute the latitudinal mask - (;Grid, nlat_half) = model.spectral_grid + (; Grid, nlat_half) = model.spectral_grid latd = RingGrids.get_latd(Grid, nlat_half) for j in eachindex(forcing.lat_mask) @@ -366,7 +366,7 @@ function forcing!( diagn::DiagnosticVariablesLayer, a = forcing.a[] # = sqrt(1 - exp(-2dt/τ)) b = forcing.b[] # = exp(-dt/τ) - (;S) = forcing + (; S) = forcing for lm in eachindex(S) # Barnes and Hartmann, 2011 Eq. 2 Qi = 2rand(Complex{NF}) - (1 + im) # ~ [-1, 1] in complex @@ -381,7 +381,7 @@ function forcing!( diagn::DiagnosticVariablesLayer, RingGrids._scale_lat!(S_grid, forcing.lat_mask) # back to spectral space - (;vor_tend) = diagn.tendencies + (; vor_tend) = diagn.tendencies SpeedyTransforms.spectral!(vor_tend, S_grid, spectral_transform) return nothing @@ -443,7 +443,7 @@ and just put them together as you like, and as long as you follow some rules. spectral_grid = SpectralGrid(trunc=42, nlev=1) stochastic_stirring = StochasticStirring(spectral_grid, latitude=-45) initial_conditions = StartFromRest() -model = BarotropicModel(;spectral_grid, initial_conditions, forcing=stochastic_stirring) +model = BarotropicModel(; spectral_grid, initial_conditions, forcing=stochastic_stirring) simulation = initialize!(model) run!(simulation) ``` diff --git a/docs/src/grids.md b/docs/src/grids.md index 3820b4919..71a7e7b55 100644 --- a/docs/src/grids.md +++ b/docs/src/grids.md @@ -130,7 +130,7 @@ changes when `dealiasing` is passed onto `SpectralGrid` on the `FullGaussianGrid | 42 | 3 | 192x96 | | ... | ... | ... | -You will obtain this information every time you create a `SpectralGrid(;Grid, trunc, dealiasing)`. +You will obtain this information every time you create a `SpectralGrid(; Grid, trunc, dealiasing)`. ## [Full Gaussian grid](@id FullGaussianGrid) diff --git a/docs/src/how_to_run_speedy.md b/docs/src/how_to_run_speedy.md index 24104c1a0..fc6984a5f 100644 --- a/docs/src/how_to_run_speedy.md +++ b/docs/src/how_to_run_speedy.md @@ -119,11 +119,11 @@ also `Δt` which is a scaled time step used internally, because SpeedyWeather.jl [scales the equations](@ref scaled_swm) with the radius of the Earth, but this is largely hidden (except here) from the user. With this new `Leapfrog` time stepper constructed we can create a model by passing -on the components (they are keyword arguments so either use `;time_stepping` +on the components (they are keyword arguments so either use `; time_stepping` for which the naming must match, or `time_stepping=my_time_stepping` with any name) ```@example howto -model = ShallowWaterModel(;spectral_grid, time_stepping) +model = ShallowWaterModel(; spectral_grid, time_stepping) ``` This logic continues for all model components. See the [Model setups](@ref) for examples. All model components are also subtype (i.e. `<:`) of @@ -156,9 +156,9 @@ parameterizations. Conceptually you construct these different models with spectral_grid = SpectralGrid(trunc=..., ...) component1 = SomeComponent(spectral_grid, parameter1=..., ...) component2 = SomeOtherComponent(spectral_grid, parameter2=..., ...) -model = BarotropicModel(;spectral_grid, all_other_components..., ...) +model = BarotropicModel(; spectral_grid, all_other_components..., ...) ``` -or `model = ShallowWaterModel(;spectral_grid, ...)`, etc. +or `model = ShallowWaterModel(; spectral_grid, ...)`, etc. ## [Model initialization](@id initialize) diff --git a/docs/src/output.md b/docs/src/output.md index 27d93bf5c..91e2798c3 100644 --- a/docs/src/output.md +++ b/docs/src/output.md @@ -12,7 +12,7 @@ The output writer is a component of every Model, i.e. `BarotropicModel`, `Shallo using SpeedyWeather spectral_grid = SpectralGrid() output = OutputWriter(spectral_grid, ShallowWater) -model = ShallowWaterModel(;spectral_grid, output=output) +model = ShallowWaterModel(; spectral_grid, output=output) nothing # hide ``` @@ -28,7 +28,7 @@ Then we can also pass on further keyword arguments. So let's start with an examp If we want to increase the frequency of the output we can choose `output_dt` (default `=Hour(6)`) like so ```@example netcdf output = OutputWriter(spectral_grid, ShallowWater, output_dt=Hour(1)) -model = ShallowWaterModel(;spectral_grid, output=output) +model = ShallowWaterModel(; spectral_grid, output=output) nothing # hide ``` which will now output every hour. It is important to pass on the new output writer `output` to the @@ -45,7 +45,7 @@ seconds. Depending on the output frequency (we chose `output_dt = Hour(1)` above this will be slightly adjusted during model initialization: ```@example netcdf output = OutputWriter(spectral_grid, ShallowWater, output_dt=Hour(1)) -model = ShallowWaterModel(;spectral_grid, time_stepping, output) +model = ShallowWaterModel(; spectral_grid, time_stepping, output) simulation = initialize!(model) model.time_stepping.Δt_sec ``` @@ -60,7 +60,7 @@ time_stepping.Δt_sec and a little info will be printed to explain that even though you wanted `output_dt = Hour(1)` you will not actually get this upon initialization: ```@example netcdf -model = ShallowWaterModel(;spectral_grid, time_stepping, output) +model = ShallowWaterModel(; spectral_grid, time_stepping, output) simulation = initialize!(model) ``` @@ -77,7 +77,7 @@ which is a bit ugly, that's why `adjust_with_output=true` is the default. In tha ```@example netcdf time_stepping = Leapfrog(spectral_grid, adjust_with_output=true) output = OutputWriter(spectral_grid, ShallowWater, output_dt=Hour(1)) -model = ShallowWaterModel(;spectral_grid, time_stepping, output) +model = ShallowWaterModel(; spectral_grid, time_stepping, output) simulation = initialize!(model) run!(simulation, period=Day(1), output=true) id = model.output.id diff --git a/docs/src/setups.md b/docs/src/setups.md index d520aed59..743742480 100644 --- a/docs/src/setups.md +++ b/docs/src/setups.md @@ -12,7 +12,7 @@ complicated setups. spectral_grid = SpectralGrid(trunc=63, nlev=1) still_earth = Earth(spectral_grid, rotation=0) initial_conditions = StartWithRandomVorticity() - model = BarotropicModel(;spectral_grid, initial_conditions, planet=still_earth) + model = BarotropicModel(; spectral_grid, initial_conditions, planet=still_earth) simulation = initialize!(model) run!(simulation, period=Day(20)) ``` @@ -46,7 +46,7 @@ horizontal wavenumber, and the amplitude is ``10^{-5}\text{s}^{-1}``. Now we want to construct a `BarotropicModel` with these ```@example barotropic_setup -model = BarotropicModel(;spectral_grid, initial_conditions, planet=still_earth) +model = BarotropicModel(; spectral_grid, initial_conditions, planet=still_earth) nothing # hide ``` The `model` contains all the parameters, but isn't initialized yet, which we can do @@ -71,7 +71,7 @@ with default settings. More options on output in [NetCDF output](@ref). spectral_grid = SpectralGrid(trunc=63, nlev=1) orography = NoOrography(spectral_grid) initial_conditions = ZonalJet() - model = ShallowWaterModel(;spectral_grid, orography, initial_conditions) + model = ShallowWaterModel(; spectral_grid, orography, initial_conditions) simulation = initialize!(model) run!(simulation, period=Day(6)) ``` @@ -97,7 +97,7 @@ initial_conditions = ZonalJet() The jet sits at 45˚N with a maximum velocity of 80m/s and a perturbation as described in their paper. Now we construct a model, but this time a `ShallowWaterModel` ```@example galewsky_setup -model = ShallowWaterModel(;spectral_grid, orography, initial_conditions) +model = ShallowWaterModel(; spectral_grid, orography, initial_conditions) simulation = initialize!(model) run!(simulation, period=Day(6)) ``` @@ -164,7 +164,7 @@ Same as before, create a model, initialize into a simulation, run. This time dir compare with the last plot ```@example galewsky_setup -model = ShallowWaterModel(;spectral_grid, orography, initial_conditions) +model = ShallowWaterModel(; spectral_grid, orography, initial_conditions) simulation = initialize!(model) run!(simulation, period=Day(12), output=true) ``` @@ -206,7 +206,7 @@ spectral_grid = SpectralGrid(trunc=63, nlev=1) forcing = JetStreamForcing(spectral_grid, latitude=60) drag = QuadraticDrag(spectral_grid) output = OutputWriter(spectral_grid, ShallowWater, output_dt=Hour(6), output_vars=[:u, :v, :pres, :orography]) -model = ShallowWaterModel(;spectral_grid, output, drag, forcing) +model = ShallowWaterModel(; spectral_grid, output, drag, forcing) simulation = initialize!(model) model.feedback.verbose = false # hide run!(simulation, period=Day(20)) # discard first 20 days @@ -259,7 +259,7 @@ implicit = SpeedyWeather.ImplicitShallowWater(spectral_grid, α=0.5) orography = EarthOrography(spectral_grid, smoothing=false) initial_conditions = SpeedyWeather.RandomWaves() output = OutputWriter(spectral_grid, ShallowWater, output_dt=Hour(12), output_vars=[:u, :pres, :div, :orography]) -model = ShallowWaterModel(;spectral_grid, orography, output, initial_conditions, implicit, time_stepping) +model = ShallowWaterModel(; spectral_grid, orography, output, initial_conditions, implicit, time_stepping) simulation = initialize!(model) model.feedback.verbose = false # hide run!(simulation, period=Day(2), output=true) @@ -323,7 +323,7 @@ using SpeedyWeather spectral_grid = SpectralGrid(trunc=31, nlev=8, Grid=FullGaussianGrid, dealiasing=3) orography = ZonalRidge(spectral_grid) initial_conditions = ZonalWind() -model = PrimitiveDryModel(;spectral_grid, orography, initial_conditions, physics=false) +model = PrimitiveDryModel(; spectral_grid, orography, initial_conditions, physics=false) simulation = initialize!(model) model.feedback.verbose = false # hide run!(simulation, period=Day(9), output=true) diff --git a/docs/src/spectral_transform.md b/docs/src/spectral_transform.md index 8bb0fa992..09cb5bc07 100644 --- a/docs/src/spectral_transform.md +++ b/docs/src/spectral_transform.md @@ -455,7 +455,7 @@ as further described in [Radius scaling](@ref scaling). ## References -[^Malardel2016]: Malardel S, Wedi N, Deconinck W, Diamantakis M, Kühnlein C, Mozdzynski G, Hamrud M, Smolarkiewicz P. A new grid for the IFS. ECMWF newsletter. 2016;146(23-28):321. doi: [10.21957/zwdu9u5i](https://doi.org/10.21957/zwdu9u5i) +[^Malardel2016]: Malardel S, Wedi N, Deconinck W, Diamantakis M, Kühnlein C, Mozdzynski G, Hamrud M, Smolarkiewicz P. A new grid for the IFS. ECMWF newsletter. 2016; 146(23-28):321. doi: [10.21957/zwdu9u5i](https://doi.org/10.21957/zwdu9u5i) [^Gorski2004]: Górski, Hivon, Banday, Wandelt, Hansen, Reinecke, Bartelmann, 2004. _HEALPix: A FRAMEWORK FOR HIGH-RESOLUTION DISCRETIZATION AND FAST ANALYSIS OF DATA DISTRIBUTED ON THE SPHERE_, The Astrophysical Journal. doi:[10.1086/427976](https://doi.org/10.1086/427976) [^Willmert2020]: Justin Willmert, 2020. [justinwillmert.com](https://justinwillmert.com/) - [Introduction to Associated Legendre Polynomials (Legendre.jl Series, Part I)](https://justinwillmert.com/articles/2020/introduction-to-associated-legendre-polynomials/) diff --git a/docs/src/speedytransforms.md b/docs/src/speedytransforms.md index 80a2512bc..393e9d850 100644 --- a/docs/src/speedytransforms.md +++ b/docs/src/speedytransforms.md @@ -321,7 +321,7 @@ using SpeedyWeather spectral_grid = SpectralGrid(trunc=31, nlev=1) forcing = SpeedyWeather.JetStreamForcing(spectral_grid) drag = QuadraticDrag(spectral_grid) -model = ShallowWaterModel(;spectral_grid, forcing, drag) +model = ShallowWaterModel(; spectral_grid, forcing, drag) model.feedback.verbose = false # hide simulation = initialize!(model); run!(simulation, period=Day(30)) diff --git a/src/LowerTriangularMatrices/plot.jl b/src/LowerTriangularMatrices/plot.jl index 8fa471252..fa140a76d 100644 --- a/src/LowerTriangularMatrices/plot.jl +++ b/src/LowerTriangularMatrices/plot.jl @@ -25,5 +25,5 @@ function plot(L::LowerTriangularMatrix{T}; mode::Function=abs) where T width=width, height=height)) - return UnicodePlots.heatmap(Lplot;plot_kwargs...) + return UnicodePlots.heatmap(Lplot; plot_kwargs...) end \ No newline at end of file diff --git a/src/RingGrids/grids_general.jl b/src/RingGrids/grids_general.jl index 105f155d1..71bf4edb6 100644 --- a/src/RingGrids/grids_general.jl +++ b/src/RingGrids/grids_general.jl @@ -224,7 +224,7 @@ $(TYPEDSIGNATURES) Returns a vector `nlons` for the number of longitude points per latitude ring, north to south. Provide grid `Grid` and its resolution parameter `nlat_half`. For both_hemisphere==false only the northern hemisphere (incl Equator) is returned.""" -function get_nlons(Grid::Type{<:AbstractGrid}, nlat_half::Integer;both_hemispheres::Bool=false) +function get_nlons(Grid::Type{<:AbstractGrid}, nlat_half::Integer; both_hemispheres::Bool=false) n = both_hemispheres ? get_nlat(Grid, nlat_half) : nlat_half return [get_nlon_per_ring(Grid, nlat_half, j) for j in 1:n] end diff --git a/src/RingGrids/interpolation.jl b/src/RingGrids/interpolation.jl index dd3885282..05f1b9154 100644 --- a/src/RingGrids/interpolation.jl +++ b/src/RingGrids/interpolation.jl @@ -290,8 +290,8 @@ function update_locator!( I::AbstractInterpolator{NF, Grid}, # GridGeometry # find latitude ring indices corresponding to interpolation points (; latd ) = I.geometry # latitudes of rings including north and south pole - (; js, Δys ) = I.locator # to be updated: ring indices js, and meridional weights Δys - find_rings!(js, Δys, θs, latd;unsafe) # next ring at or north of θ + (; js, Δys ) = I.locator # to be updated: ring indices js, and meridional weights Δys + find_rings!(js, Δys, θs, latd; unsafe) # next ring at or north of θ # find grid incides ij for top, bottom and left, right grid points around (θ, λ) find_grid_indices!(I, λs) # next points left and right of λ on rings north and south diff --git a/src/RingGrids/octahealpix.jl b/src/RingGrids/octahealpix.jl index 6d41d77f6..f6910aec1 100644 --- a/src/RingGrids/octahealpix.jl +++ b/src/RingGrids/octahealpix.jl @@ -119,7 +119,7 @@ full_grid(::Type{<:OctaHEALPixGrid}) = FullOctaHEALPixGrid # the full grid wi matrix_size(grid::OctaHEALPixGrid) = (2grid.nlat_half, 2grid.nlat_half) matrix_size(::Type{OctaHEALPixGrid}, nlat_half::Integer) = (2nlat_half, 2nlat_half) -Base.Matrix(G::OctaHEALPixGrid{T};kwargs...) where T = Matrix!(zeros(T, matrix_size(G)...), G;kwargs...) +Base.Matrix(G::OctaHEALPixGrid{T}; kwargs...) where T = Matrix!(zeros(T, matrix_size(G)...), G; kwargs...) """ Matrix!(M::AbstractMatrix, @@ -134,10 +134,10 @@ Every quadrant of the grid `G` is rotated as specified in `quadrant_rotation`, eastward starting from 0˚E. The grid quadrants are moved into the matrix quadrant (i, j) as specified. Defaults are equivalent to centered at 0˚E and a rotation such that the North Pole is at M's midpoint.""" -Matrix!(M::AbstractMatrix, G::OctaHEALPixGrid;kwargs...) = Matrix!((M, G);kwargs...) +Matrix!(M::AbstractMatrix, G::OctaHEALPixGrid; kwargs...) = Matrix!((M, G); kwargs...) """ - Matrix!(MGs::Tuple{AbstractMatrix{T}, OctaHEALPixGrid}...;kwargs...) + Matrix!(MGs::Tuple{AbstractMatrix{T}, OctaHEALPixGrid}...; kwargs...) Like `Matrix!(::AbstractMatrix, ::OctaHEALPixGrid)` but for simultaneous processing of tuples `((M1, G1), (M2, G2), ...)` with matrices `Mi` and grids `Gi`. diff --git a/src/RingGrids/octahedral.jl b/src/RingGrids/octahedral.jl index f428d1505..ba028b37c 100644 --- a/src/RingGrids/octahedral.jl +++ b/src/RingGrids/octahedral.jl @@ -149,7 +149,7 @@ full_grid(::Type{<:OctahedralClenshawGrid}) = FullClenshawGrid # the full gri matrix_size(G::OctahedralClenshawGrid) = (2*(4+G.nlat_half), 2*(4+G.nlat_half)) matrix_size(::Type{OctahedralClenshawGrid}, nlat_half::Integer) = (2*(4+nlat_half), 2*(4+nlat_half)) -Base.Matrix(G::OctahedralClenshawGrid{T};kwargs...) where T = Matrix!(zeros(T, matrix_size(G)...), G;kwargs...) +Base.Matrix(G::OctahedralClenshawGrid{T}; kwargs...) where T = Matrix!(zeros(T, matrix_size(G)...), G; kwargs...) """ Matrix!(M::AbstractMatrix, @@ -164,10 +164,10 @@ Every quadrant of the grid `G` is rotated as specified in `quadrant_rotation`, eastward starting from 0˚E. The grid quadrants are moved into the matrix quadrant (i, j) as specified. Defaults are equivalent to centered at 0˚E and a rotation such that the North Pole is at M's midpoint.""" -Matrix!(M::AbstractMatrix, G::OctahedralClenshawGrid;kwargs...) = Matrix!((M, G);kwargs...) +Matrix!(M::AbstractMatrix, G::OctahedralClenshawGrid; kwargs...) = Matrix!((M, G); kwargs...) """ - Matrix!(MGs::Tuple{AbstractMatrix{T}, OctahedralClenshawGrid}...;kwargs...) + Matrix!(MGs::Tuple{AbstractMatrix{T}, OctahedralClenshawGrid}...; kwargs...) Like `Matrix!(::AbstractMatrix, ::OctahedralClenshawGrid)` but for simultaneous processing of tuples `((M1, G1), (M2, G2), ...)` with matrices `Mi` and grids `Gi`. diff --git a/src/RingGrids/scaling.jl b/src/RingGrids/scaling.jl index 28a863661..36e4cc1cb 100644 --- a/src/RingGrids/scaling.jl +++ b/src/RingGrids/scaling.jl @@ -4,7 +4,7 @@ scale_coslat²!( A::AbstractGrid) = _scale_coslat!(A, power=2) scale_coslat⁻¹!(A::AbstractGrid) = _scale_coslat!(A, power=-1) scale_coslat⁻²!(A::AbstractGrid) = _scale_coslat!(A, power=-2) -function _scale_coslat!(A::Grid;power=1) where {Grid<:AbstractGrid} +function _scale_coslat!(A::Grid; power=1) where {Grid<:AbstractGrid} coslat = sin.(get_colat(Grid, A.nlat_half)) # sin(colat) = cos(lat) coslat .^= power return _scale_lat!(A, coslat) diff --git a/src/RingGrids/show.jl b/src/RingGrids/show.jl index 3849d2a2a..17c1e6bab 100644 --- a/src/RingGrids/show.jl +++ b/src/RingGrids/show.jl @@ -6,12 +6,12 @@ function Base.array_summary(io::IO, grid::AbstractGrid, inds::Tuple{Vararg{Base. Base.showarg(io, grid, true) end -function plot(A::AbstractGrid;title::String="$(get_nlat(A))-ring $(typeof(A))") +function plot(A::AbstractGrid; title::String="$(get_nlat(A))-ring $(typeof(A))") A_full = interpolate(full_grid(typeof(A)), A.nlat_half, A) - plot(A_full;title) + plot(A_full; title) end -function plot(A::AbstractFullGrid;title::String="$(get_nlat(A))-ring $(typeof(A))") +function plot(A::AbstractFullGrid; title::String="$(get_nlat(A))-ring $(typeof(A))") A_matrix = Matrix(A) nlon, nlat = size(A_matrix) @@ -33,5 +33,5 @@ function plot(A::AbstractFullGrid;title::String="$(get_nlat(A))-ring $(typeof(A) colorbar=true, width=width, height=height)) - return UnicodePlots.heatmap(A_view';plot_kwargs...) + return UnicodePlots.heatmap(A_view'; plot_kwargs...) end \ No newline at end of file diff --git a/src/SpeedyTransforms/aliasing.jl b/src/SpeedyTransforms/aliasing.jl index 118b5cc61..7281a3a79 100644 --- a/src/SpeedyTransforms/aliasing.jl +++ b/src/SpeedyTransforms/aliasing.jl @@ -38,7 +38,7 @@ Returns an integer `m >= n` with only small prime factors 2, 3 (default, others with the keyword argument `small_primes`) to obtain an efficiently fourier-transformable number of longitudes, m = 2^i * 3^j * 5^k >= n, with i, j, k >=0. """ -function roundup_fft(n::Integer;small_primes::Vector{T}=[2, 3, 5]) where {T<:Integer} +function roundup_fft(n::Integer; small_primes::Vector{T}=[2, 3, 5]) where {T<:Integer} factors_not_in_small_primes = true # starting condition for while loop n += isodd(n) ? 1 : 0 # start with an even n while factors_not_in_small_primes diff --git a/src/SpeedyTransforms/show.jl b/src/SpeedyTransforms/show.jl index 33088b424..19281357f 100644 --- a/src/SpeedyTransforms/show.jl +++ b/src/SpeedyTransforms/show.jl @@ -13,7 +13,7 @@ function prettymemory(b) end function Base.show(io::IO, S::SpectralTransform{NF}) where NF - (;lmax, mmax, Grid, nlat_half) = S + (; lmax, mmax, Grid, nlat_half) = S # add information about size of Legendre polynomials s = S.recompute_legendre ? Base.summarysize(S.Λ) : Base.summarysize(S.Λs) diff --git a/src/SpeedyTransforms/spectral_gradients.jl b/src/SpeedyTransforms/spectral_gradients.jl index 40f402918..200924e6e 100644 --- a/src/SpeedyTransforms/spectral_gradients.jl +++ b/src/SpeedyTransforms/spectral_gradients.jl @@ -362,8 +362,8 @@ function ∇²!( ∇²alms::LowerTriangularMatrix{Complex{NF}}, # Output: (inv eigenvalues = inverse ? S.eigenvalues⁻¹ : S.eigenvalues @boundscheck length(eigenvalues) >= lmax+1 || throw(BoundsError) - @inline kernel(o, a) = flipsign ? (add ? (o-a) : -a) : - (add ? (o+a) : a) + @inline kernel(o, a) = flipsign ? (add ? (o-a) : -a) : + (add ? (o+a) : a) lm = 0 @inbounds for m in 1:mmax+1 # order m = 0:mmax but 1-based @@ -432,7 +432,7 @@ function ∇⁻²!( ∇⁻²alms::LowerTriangularMatrix{Complex{NF}}, # Output: ) where {NF<:AbstractFloat} inverse = true - return ∇²!(∇⁻²alms, alms, S;add, flipsign, inverse) + return ∇²!(∇⁻²alms, alms, S; add, flipsign, inverse) end """ diff --git a/src/SpeedyTransforms/spectral_transform.jl b/src/SpeedyTransforms/spectral_transform.jl index 2cacc5b9c..69a27bc87 100644 --- a/src/SpeedyTransforms/spectral_transform.jl +++ b/src/SpeedyTransforms/spectral_transform.jl @@ -222,7 +222,7 @@ function SpectralTransform( alms::AbstractMatrix{Complex{NF}}; # spectral coeff ) where NF # number format NF lmax, mmax = size(alms) .- 1 # -1 for 0-based degree l, order m - return SpectralTransform(NF, Grid, lmax, mmax;recompute_legendre) + return SpectralTransform(NF, Grid, lmax, mmax; recompute_legendre) end """ @@ -238,7 +238,7 @@ function SpectralTransform( map::AbstractGrid{NF}; # gridded field Grid = typeof(map) trunc = get_truncation(map) - return SpectralTransform(NF, Grid, trunc+one_more_degree, trunc;recompute_legendre) + return SpectralTransform(NF, Grid, trunc+one_more_degree, trunc; recompute_legendre) end """ @@ -506,8 +506,8 @@ function gridded( alms::AbstractMatrix{T}; # spectral coefficients ) where {NF, T<:Complex{NF}} # number format NF lmax, mmax = size(alms) .- 1 # -1 for 0-based degree l, order m - S = SpectralTransform(NF, Grid, lmax, mmax;recompute_legendre) - return gridded(alms, S;kwargs...) + S = SpectralTransform(NF, Grid, lmax, mmax; recompute_legendre) + return gridded(alms, S; kwargs...) end """ @@ -520,26 +520,26 @@ function gridded( alms::AbstractMatrix, # spectral coefficients kwargs... ) where NF # number format NF - map = zeros(S.Grid{NF}, S.nlat_half) # preallocate output + map = zeros(S.Grid{NF}, S.nlat_half) # preallocate output almsᴸ = zeros(LowerTriangularMatrix{Complex{NF}}, S.lmax+1, S.mmax+1) - copyto!(almsᴸ, alms) # drop the upper triangle and convert to NF - gridded!(map, almsᴸ, S;kwargs...) # now execute the in-place version + copyto!(almsᴸ, alms) # drop the upper triangle and convert to NF + gridded!(map, almsᴸ, S; kwargs...) # now execute the in-place version return map end """ $(TYPEDSIGNATURES) -Converts `map` to `grid(map)` to execute `spectral(map::AbstractGrid;kwargs...)`.""" +Converts `map` to `grid(map)` to execute `spectral(map::AbstractGrid; kwargs...)`.""" function spectral( map::AbstractMatrix; # gridded field Grid::Type{<:AbstractGrid}=DEFAULT_GRID, kwargs...) - return spectral(Grid(map);kwargs...) + return spectral(Grid(map); kwargs...) end """ $(TYPEDSIGNATURES) -Converts `map` to `Grid(map)` to execute `spectral(map::AbstractGrid;kwargs...)`.""" +Converts `map` to `Grid(map)` to execute `spectral(map::AbstractGrid; kwargs...)`.""" function spectral( map::AbstractGrid{NF}; # gridded field recompute_legendre::Bool = true, # saves memory one_more_degree::Bool = false, # for lmax+2 x mmax+1 output size @@ -547,13 +547,13 @@ function spectral( map::AbstractGrid{NF}; # gridded field Grid = typeof(map) trunc = get_truncation(map.nlat_half) - S = SpectralTransform(NF, Grid, trunc+one_more_degree, trunc;recompute_legendre) + S = SpectralTransform(NF, Grid, trunc+one_more_degree, trunc; recompute_legendre) return spectral(map, S) end """ $(TYPEDSIGNATURES) -Spectral transform (grid to spectral) `map` to `grid(map)` to execute `spectral(map::AbstractGrid;kwargs...)`.""" +Spectral transform (grid to spectral) `map` to `grid(map)` to execute `spectral(map::AbstractGrid; kwargs...)`.""" function spectral( map::AbstractGrid, # gridded field S::SpectralTransform{NF}, # spectral transform struct ) where NF # number format NF diff --git a/src/SpeedyTransforms/spectral_truncation.jl b/src/SpeedyTransforms/spectral_truncation.jl index 2b97446a2..2430478f5 100644 --- a/src/SpeedyTransforms/spectral_truncation.jl +++ b/src/SpeedyTransforms/spectral_truncation.jl @@ -142,18 +142,18 @@ spectral_interpolation(alms::AbstractMatrix{NF}, ltrunc::Integer, mtrunc::Intege spectral_interpolation(alms::AbstractMatrix, trunc::Int) = spectral_interpolation(alms, trunc, trunc) """ - A_smooth = spectral_smoothing(A::LowerTriangularMatrix, c;power=1) + A_smooth = spectral_smoothing(A::LowerTriangularMatrix, c; power=1) Smooth the spectral field `A` following A_smooth = (1-c*∇²ⁿ)A with power n of a normalised Laplacian so that the highest degree lmax is dampened by multiplication with c. Anti-diffusion for c<0.""" -function spectral_smoothing(A::LowerTriangularMatrix, c::Real;power::Real=1) +function spectral_smoothing(A::LowerTriangularMatrix, c::Real; power::Real=1) A_smooth = copy(A) - spectral_smoothing!(A_smooth, c;power) + spectral_smoothing!(A_smooth, c; power) return A_smooth end """ - spectral_smoothing!(A::LowerTriangularMatrix, c;power=1) + spectral_smoothing!(A::LowerTriangularMatrix, c; power=1) Smooth the spectral field `A` following A *= (1-(1-c)*∇²ⁿ) with power n of a normalised Laplacian so that the highest degree lmax is dampened by multiplication with c. Anti-diffusion for c>1.""" diff --git a/src/dynamics/adiabatic_conversion.jl b/src/dynamics/adiabatic_conversion.jl index 9951102e4..dc5950e78 100644 --- a/src/dynamics/adiabatic_conversion.jl +++ b/src/dynamics/adiabatic_conversion.jl @@ -11,16 +11,16 @@ Base.@kwdef struct AdiabaticConversion{NF} <: AbstractAdiabaticConversion σ_lnp_B::Vector{NF} = zeros(NF, nlev) end -AdiabaticConversion(SG::SpectralGrid;kwargs...) = AdiabaticConversion{SG.NF}(;nlev=SG.nlev, kwargs...) +AdiabaticConversion(SG::SpectralGrid; kwargs...) = AdiabaticConversion{SG.NF}(; nlev=SG.nlev, kwargs...) function initialize!( adiabatic::AdiabaticConversion, model::PrimitiveEquation, ) - (;σ_lnp_A, σ_lnp_B) = adiabatic + (; σ_lnp_A, σ_lnp_B) = adiabatic # ADIABATIC TERM, Simmons and Burridge, 1981, eq. 3.12 - (;σ_levels_half, σ_levels_full, σ_levels_thick) = model.geometry + (; σ_levels_half, σ_levels_full, σ_levels_thick) = model.geometry # precompute ln(σ_k+1/2) - ln(σ_k-1/2) but swap sign, include 1/Δσₖ σ_lnp_A .= log.(σ_levels_half[1:end-1]./σ_levels_half[2:end]) ./ σ_levels_thick σ_lnp_A[1] = 0 # the corresponding sum is 1:k-1 so 0 to replace log(0) from above diff --git a/src/dynamics/atmosphere.jl b/src/dynamics/atmosphere.jl index 1598148e0..f487a53fb 100644 --- a/src/dynamics/atmosphere.jl +++ b/src/dynamics/atmosphere.jl @@ -59,4 +59,4 @@ Base.@kwdef mutable struct EarthAtmosphere{NF<:AbstractFloat} <: AbstractAtmosph layer_thickness::NF = 8500 end -EarthAtmosphere(SG::SpectralGrid;kwargs...) = EarthAtmosphere{SG.NF}(;kwargs...) \ No newline at end of file +EarthAtmosphere(SG::SpectralGrid; kwargs...) = EarthAtmosphere{SG.NF}(; kwargs...) \ No newline at end of file diff --git a/src/dynamics/coriolis.jl b/src/dynamics/coriolis.jl index 2e1b78a7b..7edbd6913 100644 --- a/src/dynamics/coriolis.jl +++ b/src/dynamics/coriolis.jl @@ -9,11 +9,11 @@ Base.@kwdef struct Coriolis{NF} <: AbstractCoriolis f::Vector{NF} = zeros(NF, nlat) end -Coriolis(SG::SpectralGrid;kwargs...) = Coriolis{SG.NF}(nlat=SG.nlat;kwargs...) +Coriolis(SG::SpectralGrid; kwargs...) = Coriolis{SG.NF}(nlat=SG.nlat; kwargs...) function initialize!(coriolis::Coriolis, model::ModelSetup) - (;rotation) = model.planet - (;sinlat, radius) = model.geometry + (; rotation) = model.planet + (; sinlat, radius) = model.geometry # =2Ωsin(lat) but scaled with radius as are the equations coriolis.f .= 2rotation * sinlat * radius @@ -50,5 +50,5 @@ function coriolis( grid::Grid; rotation=DEFAULT_ROTATION ) where {Grid<:AbstractGrid} - return coriolis(Grid, grid.nlat_half;rotation) + return coriolis(Grid, grid.nlat_half; rotation) end \ No newline at end of file diff --git a/src/dynamics/diagnostic_variables.jl b/src/dynamics/diagnostic_variables.jl index 4f9898b44..234d6bbe2 100644 --- a/src/dynamics/diagnostic_variables.jl +++ b/src/dynamics/diagnostic_variables.jl @@ -21,8 +21,8 @@ end # generator function based on a SpectralGrid function Base.zeros(::Type{Tendencies}, SG::SpectralGrid) - (;NF, trunc, Grid, nlat_half) = SG - return Tendencies{NF, Grid{NF}}(;nlat_half, trunc) + (; NF, trunc, Grid, nlat_half) = SG + return Tendencies{NF, Grid{NF}}(; nlat_half, trunc) end """ @@ -44,8 +44,8 @@ end # generator function based on a SpectralGrid function Base.zeros(::Type{GridVariables}, SG::SpectralGrid) - (;NF, Grid, nlat_half) = SG - return GridVariables{NF, Grid{NF}}(;nlat_half) + (; NF, Grid, nlat_half) = SG + return GridVariables{NF, Grid{NF}}(; nlat_half) end """ @@ -83,8 +83,8 @@ end # generator function based on a SpectralGrid function Base.zeros(::Type{DynamicsVariables}, SG::SpectralGrid) - (;NF, trunc, Grid, nlat_half) = SG - return DynamicsVariables{NF, Grid{NF}}(;nlat_half, trunc) + (; NF, trunc, Grid, nlat_half) = SG + return DynamicsVariables{NF, Grid{NF}}(; nlat_half, trunc) end export DiagnosticVariablesLayer @@ -107,7 +107,7 @@ end function Base.zeros(::Type{DiagnosticVariablesLayer}, SG::SpectralGrid, k::Integer=0) # use k=0 (i.e. unspecified) as default - (;npoints) = SG + (; npoints) = SG tendencies = zeros(Tendencies, SG) grid_variables = zeros(GridVariables, SG) dynamics_variables = zeros(DynamicsVariables, SG) @@ -147,8 +147,8 @@ end function Base.zeros(::Type{SurfaceVariables}, SG::SpectralGrid) - (;NF, trunc, Grid, nlat_half, npoints) = SG - return SurfaceVariables{NF, Grid{NF}}(;nlat_half, trunc, npoints) + (; NF, trunc, Grid, nlat_half, npoints) = SG + return SurfaceVariables{NF, Grid{NF}}(; nlat_half, trunc, npoints) end export DiagnosticVariables @@ -175,13 +175,13 @@ function Base.zeros( Model::Type{<:ModelSetup} ) - (;NF, Grid, nlat_half, nlev, npoints) = SG + (; NF, Grid, nlat_half, nlev, npoints) = SG layers = [zeros(DiagnosticVariablesLayer, SG, k) for k in 1:nlev] surface = zeros(SurfaceVariables, SG) # create one column variable per thread to avoid race conditions nthreads = Threads.nthreads() - columns = [ColumnVariables{NF}(;nlev) for _ in 1:nthreads] + columns = [ColumnVariables{NF}(; nlev) for _ in 1:nthreads] scale = Ref(convert(SG.NF, SG.radius)) diff --git a/src/dynamics/drag.jl b/src/dynamics/drag.jl index 8fb54bc9c..14d9304de 100644 --- a/src/dynamics/drag.jl +++ b/src/dynamics/drag.jl @@ -24,7 +24,7 @@ Base.@kwdef mutable struct QuadraticDrag{NF} <: AbstractDrag c::Base.RefValue{NF} = Ref(zero(NF)) end -QuadraticDrag(SG::SpectralGrid;kwargs...) = QuadraticDrag{SG.NF}(;kwargs...) +QuadraticDrag(SG::SpectralGrid; kwargs...) = QuadraticDrag{SG.NF}(; kwargs...) function initialize!( drag::QuadraticDrag, model::ModelSetup) diff --git a/src/dynamics/forcing.jl b/src/dynamics/forcing.jl index cc92496f9..8550105b4 100644 --- a/src/dynamics/forcing.jl +++ b/src/dynamics/forcing.jl @@ -44,14 +44,14 @@ Base.@kwdef mutable struct JetStreamForcing{NF} <: AbstractForcing amplitude::Vector{NF} = zeros(NF, nlat) end -JetStreamForcing(SG::SpectralGrid;kwargs...) = JetStreamForcing{SG.NF}( - ;nlat=SG.nlat, kwargs...) +JetStreamForcing(SG::SpectralGrid; kwargs...) = JetStreamForcing{SG.NF}( + ; nlat=SG.nlat, kwargs...) function initialize!( forcing::JetStreamForcing, model::ModelSetup) - (;latitude, width, speed, time_scale, amplitude) = forcing - (;radius) = model.spectral_grid + (; latitude, width, speed, time_scale, amplitude) = forcing + (; radius) = model.spectral_grid # Some constants similar to Galewsky 2004 θ₀ = (latitude-width)/360*2π # southern boundary of jet [radians] @@ -60,7 +60,7 @@ function initialize!( forcing::JetStreamForcing, A₀ = speed/eₙ/time_scale.value # amplitude [m/s²] without lat dependency A₀ *= radius # scale by radius as are the momentum equations - (;nlat, colat) = model.geometry + (; nlat, colat) = model.geometry for j in 1:nlat # latitude in radians, abs for north/south symmetry @@ -94,7 +94,7 @@ The forcing is precomputed in `initialize!(::JetStreamForcing, ::ModelSetup)`."" function forcing!( diagn::DiagnosticVariablesLayer, forcing::JetStreamForcing) Fu = diagn.tendencies.u_tend_grid - (;amplitude) = forcing + (; amplitude) = forcing @inbounds for (j, ring) in enumerate(eachring(Fu)) F = amplitude[j] diff --git a/src/dynamics/geometry.jl b/src/dynamics/geometry.jl index 158ec78bf..2d75475f7 100644 --- a/src/dynamics/geometry.jl +++ b/src/dynamics/geometry.jl @@ -100,7 +100,7 @@ end $(TYPEDSIGNATURES) Generator function for `Geometry` struct based on `spectral_grid`.""" function Geometry(spectral_grid::SpectralGrid) - return Geometry{spectral_grid.NF}(;spectral_grid) + return Geometry{spectral_grid.NF}(; spectral_grid) end function Base.show(io::IO, G::Geometry) diff --git a/src/dynamics/geopotential.jl b/src/dynamics/geopotential.jl index 3db367cf4..ed964a317 100644 --- a/src/dynamics/geopotential.jl +++ b/src/dynamics/geopotential.jl @@ -7,7 +7,7 @@ Base.@kwdef struct Geopotential{NF} <: AbstractGeopotential Δp_geopot_full::Vector{NF} = zeros(NF, nlev) end -Geopotential(SG::SpectralGrid) = Geopotential{SG.NF}(;nlev=SG.nlev) +Geopotential(SG::SpectralGrid) = Geopotential{SG.NF}(; nlev=SG.nlev) """ $(TYPEDSIGNATURES) @@ -21,9 +21,9 @@ function initialize!( geopotential::Geopotential, model::PrimitiveEquation ) - (;Δp_geopot_half, Δp_geopot_full, nlev) = geopotential - (;R_dry) = model.atmosphere - (;σ_levels_full, σ_levels_half) = model.geometry + (; Δp_geopot_half, Δp_geopot_full, nlev) = geopotential + (; R_dry) = model.atmosphere + (; σ_levels_full, σ_levels_half) = model.geometry # 1. integration onto half levels for k in 1:nlev-1 # k is full level index, 1=top, nlev=bottom @@ -48,9 +48,9 @@ function geopotential!( orography::AbstractOrography, ) - (;geopot_surf) = orography # = orography*gravity - (;Δp_geopot_half, Δp_geopot_full) = geopotential # = R*Δlnp either on half or full levels - (;nlev) = diagn # number of vertical levels + (; geopot_surf) = orography # = orography*gravity + (; Δp_geopot_half, Δp_geopot_full) = geopotential # = R*Δlnp either on half or full levels + (; nlev) = diagn # number of vertical levels @boundscheck nlev == length(Δp_geopot_full) || throw(BoundsError) @@ -92,7 +92,7 @@ function geopotential!( ) nlev = length(geopot) - (;Δp_geopot_half, Δp_geopot_full) = G # = R*Δlnp either on half or full levels + (; Δp_geopot_half, Δp_geopot_full) = G # = R*Δlnp either on half or full levels @boundscheck length(temp) >= nlev || throw(BoundsError) @boundscheck length(Δp_geopot_full) >= nlev || throw(BoundsError) @@ -121,6 +121,6 @@ i.e. gravity times the interface displacement (field `pres`)""" function geopotential!( diagn::DiagnosticVariablesLayer, pres::LowerTriangularMatrix, planet::AbstractPlanet) - (;geopot) = diagn.dynamics_variables + (; geopot) = diagn.dynamics_variables geopot .= pres * planet.gravity end \ No newline at end of file diff --git a/src/dynamics/horizontal_diffusion.jl b/src/dynamics/horizontal_diffusion.jl index c0d2857b2..79b5889b5 100644 --- a/src/dynamics/horizontal_diffusion.jl +++ b/src/dynamics/horizontal_diffusion.jl @@ -60,9 +60,9 @@ end """$(TYPEDSIGNATURES) Generator function based on the resolutin in `spectral_grid`. Passes on keyword arguments.""" -function HyperDiffusion(spectral_grid::SpectralGrid;kwargs...) - (;NF, trunc, nlev) = spectral_grid # take resolution parameters from spectral_grid - return HyperDiffusion{NF}(;trunc, nlev, kwargs...) +function HyperDiffusion(spectral_grid::SpectralGrid; kwargs...) + (; NF, trunc, nlev) = spectral_grid # take resolution parameters from spectral_grid + return HyperDiffusion{NF}(; trunc, nlev, kwargs...) end """$(TYPEDSIGNATURES) @@ -87,8 +87,8 @@ model time step.""" function initialize!( scheme::HyperDiffusion, L::AbstractTimeStepper) - (;trunc, ∇²ⁿ_2D, ∇²ⁿ_2D_implicit, power) = scheme - (;Δt, radius) = L + (; trunc, ∇²ⁿ_2D, ∇²ⁿ_2D_implicit, power) = scheme + (; Δt, radius) = L # time scale times 1/radius because time step Δt is scaled with 1/radius time_scale = scheme.time_scale.value/radius @@ -122,9 +122,9 @@ function initialize!( L::AbstractTimeStepper, vor_max::Real = 0, ) - (;trunc, resolution_scaling, ∇²ⁿ, ∇²ⁿ_implicit) = scheme - (;power, power_stratosphere, tapering_σ) = scheme - (;Δt, radius) = L + (; trunc, resolution_scaling, ∇²ⁿ, ∇²ⁿ_implicit) = scheme + (; power, power_stratosphere, tapering_σ) = scheme + (; Δt, radius) = L σ = G.σ_levels_full[k] # Reduce diffusion time scale (=increase diffusion) with resolution @@ -213,8 +213,8 @@ function horizontal_diffusion!( diagn::DiagnosticVariablesLayer, ∇²ⁿ_implicit = HD.∇²ⁿ_2D_implicit # Barotropic model diffuses vorticity (only variable) - (;vor) = progn.timesteps[lf] - (;vor_tend) = diagn.tendencies + (; vor) = progn.timesteps[lf] + (; vor_tend) = diagn.tendencies horizontal_diffusion!(vor_tend, vor, ∇²ⁿ, ∇²ⁿ_implicit) end @@ -230,8 +230,8 @@ function horizontal_diffusion!( progn::PrognosticLayerTimesteps, ∇²ⁿ_implicit = HD.∇²ⁿ_2D_implicit # ShallowWater model diffuses vorticity and divergence - (;vor, div) = progn.timesteps[lf] - (;vor_tend, div_tend) = diagn.tendencies + (; vor, div) = progn.timesteps[lf] + (; vor_tend, div_tend) = diagn.tendencies horizontal_diffusion!(vor_tend, vor, ∇²ⁿ, ∇²ⁿ_implicit) horizontal_diffusion!(div_tend, div, ∇²ⁿ, ∇²ⁿ_implicit) end @@ -252,8 +252,8 @@ function horizontal_diffusion!( progn::PrognosticLayerTimesteps, ∇²ⁿ_implicit = HD.∇²ⁿ_implicit[k] # Primitive equation models diffuse vor and divergence more selective/adaptive - (;vor, div, temp, humid) = progn.timesteps[lf] - (;vor_tend, div_tend, temp_tend, humid_tend) = diagn.tendencies + (; vor, div, temp, humid) = progn.timesteps[lf] + (; vor_tend, div_tend, temp_tend, humid_tend) = diagn.tendencies horizontal_diffusion!(vor_tend, vor, ∇²ⁿ, ∇²ⁿ_implicit) horizontal_diffusion!(div_tend, div, ∇²ⁿ, ∇²ⁿ_implicit) diff --git a/src/dynamics/implicit.jl b/src/dynamics/implicit.jl index 71a0b1216..bff7b64b1 100644 --- a/src/dynamics/implicit.jl +++ b/src/dynamics/implicit.jl @@ -33,9 +33,9 @@ end """ $(TYPEDSIGNATURES) Generator using the resolution from `spectral_grid`.""" -function ImplicitShallowWater(spectral_grid::SpectralGrid;kwargs...) - (;NF, trunc) = spectral_grid - return ImplicitShallowWater{NF}(;trunc, kwargs...) +function ImplicitShallowWater(spectral_grid::SpectralGrid; kwargs...) + (; NF, trunc) = spectral_grid + return ImplicitShallowWater{NF}(; trunc, kwargs...) end # function barrier to unpack the constants struct for shallow water @@ -53,9 +53,9 @@ function initialize!( atmosphere::AbstractAtmosphere, ) - (;α, H, ξH, g∇², ξg∇², S⁻¹) = implicit # precomputed arrays to be updated - (;gravity) = planet # gravitational acceleration [m/s²] - (;layer_thickness) = atmosphere # shallow water layer thickness [m] + (; α, H, ξH, g∇², ξg∇², S⁻¹) = implicit # precomputed arrays to be updated + (; gravity) = planet # gravitational acceleration [m/s²] + (; layer_thickness) = atmosphere # shallow water layer thickness [m] # implicit time step between i-1 and i+1 # α = 0 means the gravity wave terms are evaluated at i-1 (forward) @@ -65,7 +65,7 @@ function initialize!( # α = 0.5 slows gravity waves and prevents them from amplifying # α > 0.5 will dampen the gravity waves within days to a few timesteps (α=1) - ξ = α*dt # new implicit timestep ξ = α*dt = 2αΔt (for leapfrog) from input dt + ξ = α*dt # new implicit timestep ξ = α*dt = 2αΔt (for leapfrog) from input dt H[] = layer_thickness # update H the undisturbed layer thickness without mountains ξH[] = ξ*layer_thickness # update ξ*H with new ξ, in RefValue for mutability @@ -89,14 +89,14 @@ function implicit_correction!( diagn::DiagnosticVariablesLayer{NF}, progn_surface::PrognosticSurfaceTimesteps{NF}, implicit::ImplicitShallowWater) where NF - (;div_tend) = diagn.tendencies # divergence tendency + (; div_tend) = diagn.tendencies # divergence tendency div_old = progn.timesteps[1].div # divergence at t div_new = progn.timesteps[2].div # divergence at t+dt pres_old = progn_surface.timesteps[1].pres # pressure/η at t pres_new = progn_surface.timesteps[2].pres # pressure/η at t+dt - (;pres_tend) = diagn_surface # tendency of pressure/η + (; pres_tend) = diagn_surface # tendency of pressure/η - (;g∇², ξg∇², S⁻¹) = implicit + (; g∇², ξg∇², S⁻¹) = implicit H = implicit.H[] # unpack as it's stored in a RefValue for mutation ξH = implicit.ξH[] # unpack as it's stored in a RefValue for mutation @@ -188,8 +188,8 @@ end """$(TYPEDSIGNATURES) Generator using the resolution from SpectralGrid.""" function ImplicitPrimitiveEquation(spectral_grid::SpectralGrid, kwargs...) - (;NF, trunc, nlev) = spectral_grid - return ImplicitPrimitiveEquation{NF}(;trunc, nlev, kwargs...) + (; NF, trunc, nlev) = spectral_grid + return ImplicitPrimitiveEquation{NF}(; trunc, nlev, kwargs...) end # function barrier to unpack the constants struct for primitive eq models @@ -215,11 +215,11 @@ function initialize!( adiabatic_conversion::AbstractAdiabaticConversion, ) - (;trunc, nlev, α, temp_profile, S, S⁻¹, L, R, U, W, L0, L1, L2, L3, L4) = implicit - (;σ_levels_full, σ_levels_thick) = geometry - (;R_dry, κ) = atmosphere - (;Δp_geopot_half, Δp_geopot_full) = geopotential - (;σ_lnp_A, σ_lnp_B) = adiabatic_conversion + (; trunc, nlev, α, temp_profile, S, S⁻¹, L, R, U, W, L0, L1, L2, L3, L4) = implicit + (; σ_levels_full, σ_levels_thick) = geometry + (; R_dry, κ) = atmosphere + (; Δp_geopot_half, Δp_geopot_full) = geopotential + (; σ_lnp_A, σ_lnp_B) = adiabatic_conversion for k in 1:nlev # use current vertical temperature profile @@ -312,15 +312,15 @@ function implicit_correction!( # escape immediately if explicit implicit.α == 0 && return nothing - # (;Δp_geopot_half, Δp_geopot_full) = model.geometry # = R*Δlnp on half or full levels - (;nlev, trunc, S⁻¹, R, U, L, W) = implicit + # (; Δp_geopot_half, Δp_geopot_full) = model.geometry # = R*Δlnp on half or full levels + (; nlev, trunc, S⁻¹, R, U, L, W) = implicit ξ = implicit.ξ[] # MOVE THE IMPLICIT TERMS OF THE TEMPERATURE EQUATION FROM TIME STEP i TO i-1 # geopotential and linear pressure gradient (divergence equation) are already evaluated at i-1 # so is the -D̄ term for surface pressure in tendencies! @floop for k in 1:nlev - (;temp_tend) = diagn.layers[k].tendencies # unpack temp_tend + (; temp_tend) = diagn.layers[k].tendencies # unpack temp_tend for r in 1:nlev div_old = progn.layers[r].timesteps[1].div # divergence at i-1 div_new = progn.layers[r].timesteps[2].div # divergence at i @@ -333,17 +333,17 @@ function implicit_correction!( end # SEMI IMPLICIT CORRECTIONS FOR DIVERGENCE - (;pres_tend) = diagn.surface + (; pres_tend) = diagn.surface @floop for k in 1:nlev # loop from bottom layer to top for geopotential calculation # calculate the combined tendency G = G_D + ξRG_T + ξUG_lnps to solve for divergence δD G = diagn.layers[k].dynamics_variables.a # reuse work arrays, used for combined tendency G geopot = diagn.layers[k].dynamics_variables.b # used for geopotential - (;div_tend) = diagn.layers[k].tendencies # unpack div_tend + (; div_tend) = diagn.layers[k].tendencies # unpack div_tend # 1. the ξ*R*G_T term, vertical integration of geopotential (excl ξ, this is done in 2.) @inbounds for r in k:nlev # skip 1:k-1 as integration is surface to k - (;temp_tend) = diagn.layers[r].tendencies # unpack temp_tend + (; temp_tend) = diagn.layers[r].tendencies # unpack temp_tend @. geopot += R[k, r]*temp_tend end @@ -379,7 +379,7 @@ function implicit_correction!( # NOW SOLVE THE δD = S⁻¹G to correct divergence tendency @floop for k in 1:nlev - (;div_tend) = diagn.layers[k].tendencies # unpack div_tend + (; div_tend) = diagn.layers[k].tendencies # unpack div_tend @inbounds for r in 1:nlev G = diagn.layers[r].dynamics_variables.a # reuse work arrays @@ -397,15 +397,15 @@ function implicit_correction!( # SEMI IMPLICIT CORRECTIONS FOR PRESSURE AND TEMPERATURE, insert δD to get δT, δlnpₛ @floop for k in 1:nlev - (;temp_tend) = diagn.layers[k].tendencies # unpack temp_tend + (; temp_tend) = diagn.layers[k].tendencies # unpack temp_tend @inbounds for r in 1:nlev - (;div_tend) = diagn.layers[r].tendencies # unpack div_tend + (; div_tend) = diagn.layers[r].tendencies # unpack div_tend @. temp_tend += ξ*L[k, r]*div_tend # δT = G_T + ξLδD end end for k in 1:nlev # not thread safe - (;div_tend) = diagn.layers[k].tendencies # unpack div_tend - @. pres_tend += ξ*W[k]*div_tend # δlnpₛ = G_lnpₛ + ξWδD + (; div_tend) = diagn.layers[k].tendencies # unpack div_tend + @. pres_tend += ξ*W[k]*div_tend # δlnpₛ = G_lnpₛ + ξWδD end end \ No newline at end of file diff --git a/src/dynamics/initial_conditions.jl b/src/dynamics/initial_conditions.jl index e46de5a56..4e30edde1 100644 --- a/src/dynamics/initial_conditions.jl +++ b/src/dynamics/initial_conditions.jl @@ -101,8 +101,8 @@ function initialize!( progn::PrognosticVariables, initial_conditions::ZonalJet, model::ShallowWater) - (;latitude, width, umax) = initial_conditions # for jet - (;perturb_lat, perturb_lon, perturb_xwidth, # for perturbation + (; latitude, width, umax) = initial_conditions # for jet + (; perturb_lat, perturb_lon, perturb_xwidth, # for perturbation perturb_ywidth, perturb_height) = initial_conditions θ₀ = (latitude-width)/360*2π # southern boundary of jet [radians] @@ -114,8 +114,8 @@ function initialize!( progn::PrognosticVariables, β = perturb_ywidth*2π/360 # meridional extent of interface perturbation [radians] λ = perturb_lon*2π/360 # perturbation longitude [radians] - (;rotation, gravity) = model.planet - (;radius) = model.spectral_grid + (; rotation, gravity) = model.planet + (; radius) = model.spectral_grid # always create on F64 grid then convert to spectral and interpolate there Grid = FullGaussianGrid @@ -160,17 +160,17 @@ function initialize!( progn::PrognosticVariables, η = spectral(η_grid) # interpolate in spectral space to desired resolution - (;lmax, mmax) = model.spectral_transform - (;NF) = model.spectral_grid + (; lmax, mmax) = model.spectral_transform + (; NF) = model.spectral_grid u = spectral_truncation(complex(NF), u, lmax, mmax) # get vorticity initial conditions from curl of u, v v = zero(u) # meridional velocity zero for these initial conditions - (;vor) = progn.layers[end].timesteps[1] + (; vor) = progn.layers[end].timesteps[1] curl!(vor, u, v, model.spectral_transform) # transform interface height η (use pres as prognostic variable) in spectral - (;pres) = progn.surface.timesteps[1] + (; pres) = progn.surface.timesteps[1] copyto!(pres, η) spectral_truncation!(pres) end @@ -225,14 +225,14 @@ function initialize!( progn::PrognosticVariables{NF}, initial_conditions::ZonalWind, model::PrimitiveEquation) where NF - (;u₀, η₀, ΔT, Tmin, pressure_on_orography) = initial_conditions - (;perturb_lat, perturb_lon, perturb_uₚ, perturb_radius) = initial_conditions - (;lapse_rate, σ_tropopause) = initial_conditions - (;temp_ref, R_dry, pres_ref) = model.atmosphere - (;radius, Grid, nlat_half, nlev) = model.spectral_grid - (;rotation, gravity) = model.planet - (;σ_levels_full) = model.geometry - (;norm_sphere) = model.spectral_transform + (; u₀, η₀, ΔT, Tmin, pressure_on_orography) = initial_conditions + (; perturb_lat, perturb_lon, perturb_uₚ, perturb_radius) = initial_conditions + (; lapse_rate, σ_tropopause) = initial_conditions + (; temp_ref, R_dry, pres_ref) = model.atmosphere + (; radius, Grid, nlat_half, nlev) = model.spectral_grid + (; rotation, gravity) = model.planet + (; σ_levels_full) = model.geometry + (; norm_sphere) = model.spectral_transform φ, λ = model.geometry.latds, model.geometry.londs S = model.spectral_transform @@ -277,7 +277,7 @@ function initialize!( progn::PrognosticVariables{NF}, D[ij] = -2perturb_uₚ*radius/R^2 * exp_decay * acos(X) * X_norm * cosφc*sind(λij-λc) end - (;vor, div) = layer.timesteps[1] + (; vor, div) = layer.timesteps[1] spectral!(vor, ζ, S) spectral!(div, D, S) spectral_truncation!(vor) @@ -319,7 +319,7 @@ function initialize!( progn::PrognosticVariables{NF}, T[ij] = Tη[k] + A1*((-2sinφ^6*(cosφ^2 + 1/3) + 10/63)*A2 + (8/5*cosφ^3*(sinφ^2 + 2/3) - π/4)*aΩ) end - (;temp) = layer.timesteps[1] + (; temp) = layer.timesteps[1] spectral!(temp, T, S) spectral_truncation!(temp) end @@ -373,10 +373,10 @@ function homogeneous_temperature!( progn::PrognosticVariables, # lapse_rate: Reference temperature lapse rate -dT/dz [K/km] # gravity: Gravitational acceleration [m/s^2] # R_dry: Specific gas constant for dry air [J/kg/K] - (;temp_ref, lapse_rate, R_dry) = model.atmosphere - (;gravity) = model.planet - (;nlev, σ_levels_full) = model.geometry - (;norm_sphere) = model.spectral_transform # normalization of the l=m=0 spherical harmonic + (; temp_ref, lapse_rate, R_dry) = model.atmosphere + (; gravity) = model.planet + (; nlev, σ_levels_full) = model.geometry + (; norm_sphere) = model.spectral_transform # normalization of the l=m=0 spherical harmonic # Lapse rate scaled by gravity [K/m / (m²/s²)] Γg⁻¹ = lapse_rate/gravity @@ -450,7 +450,7 @@ function initialize_humidity!( scale_height::NF = 7.5 # scale height for pressure [km] scale_height_ratio = scale_height/scale_height_humid - (;nlev, σ_levels_full) = model.geometry + (; nlev, σ_levels_full) = model.geometry # Specific humidity at the surface (grid space) temp_grid = gridded(progn.layers[end].timesteps[1].temp, model.spectral_transform) @@ -490,8 +490,8 @@ function initialize!( progn::PrognosticVariables{NF}, initial_conditions::RandomWaves, model::ShallowWater) where NF - (;A, lmin, lmax) = initial_conditions - (;trunc) = progn + (; A, lmin, lmax) = initial_conditions + (; trunc) = progn η = progn.surface.timesteps[1].pres η .= randn(LowerTriangularMatrix{Complex{NF}}, trunc+2, trunc+1) diff --git a/src/dynamics/orography.jl b/src/dynamics/orography.jl index a1b518861..7eaa0d67e 100644 --- a/src/dynamics/orography.jl +++ b/src/dynamics/orography.jl @@ -15,7 +15,7 @@ end $(TYPEDSIGNATURES) Generator function pulling the resolution information from `spectral_grid`.""" function NoOrography(spectral_grid::SpectralGrid) - (;NF, Grid, nlat_half, trunc) = spectral_grid + (; NF, Grid, nlat_half, trunc) = spectral_grid orography = zeros(Grid{NF}, nlat_half) geopot_surf = zeros(LowerTriangularMatrix{Complex{NF}}, trunc+2, trunc+1) return NoOrography{NF, Grid{NF}}(orography, geopot_surf) @@ -47,11 +47,11 @@ end """ $(TYPEDSIGNATURES) Generator function pulling the resolution information from `spectral_grid`.""" -function ZonalRidge(spectral_grid::SpectralGrid;kwargs...) - (;NF, Grid, nlat_half, trunc) = spectral_grid +function ZonalRidge(spectral_grid::SpectralGrid; kwargs...) + (; NF, Grid, nlat_half, trunc) = spectral_grid orography = zeros(Grid{NF}, nlat_half) geopot_surf = zeros(LowerTriangularMatrix{Complex{NF}}, trunc+2, trunc+1) - return ZonalRidge{NF, Grid{NF}}(;orography, geopot_surf, kwargs...) + return ZonalRidge{NF, Grid{NF}}(; orography, geopot_surf, kwargs...) end # function barrier @@ -70,11 +70,11 @@ function initialize!( orog::ZonalRidge, S::SpectralTransform, G::Geometry) - (;gravity, rotation) = P - (;radius) = G + (; gravity, rotation) = P + (; radius) = G φ = G.latds # latitude for each grid point [˚N] - (;orography, geopot_surf, η₀, u₀) = orog + (; orography, geopot_surf, η₀, u₀) = orog ηᵥ = (1-η₀)*π/2 # ηᵥ-coordinate of the surface [1] A = u₀*cos(ηᵥ)^(3/2) # amplitude [m/s] @@ -136,11 +136,11 @@ end """ $(TYPEDSIGNATURES) Generator function pulling the resolution information from `spectral_grid`.""" -function EarthOrography(spectral_grid::SpectralGrid;kwargs...) - (;NF, Grid, nlat_half, trunc) = spectral_grid +function EarthOrography(spectral_grid::SpectralGrid; kwargs...) + (; NF, Grid, nlat_half, trunc) = spectral_grid orography = zeros(Grid{NF}, nlat_half) geopot_surf = zeros(LowerTriangularMatrix{Complex{NF}}, trunc+2, trunc+1) - return EarthOrography{NF, Grid{NF}}(;orography, geopot_surf, kwargs...) + return EarthOrography{NF, Grid{NF}}(; orography, geopot_surf, kwargs...) end # function barrier @@ -158,8 +158,8 @@ function initialize!( orog::EarthOrography, P::AbstractPlanet, S::SpectralTransform) - (;orography, geopot_surf) = orog - (;gravity) = P + (; orography, geopot_surf) = orog + (; gravity) = P # LOAD NETCDF FILE if orog.path == "SpeedyWeather.jl/input_data" diff --git a/src/dynamics/planet.jl b/src/dynamics/planet.jl index aef9d90fc..e40927efe 100644 --- a/src/dynamics/planet.jl +++ b/src/dynamics/planet.jl @@ -42,4 +42,4 @@ Base.@kwdef mutable struct Earth{NF<:AbstractFloat} <: AbstractPlanet solar_constant::NF = 1365 end -Earth(SG::SpectralGrid;kwargs...) = Earth{SG.NF}(;kwargs...) \ No newline at end of file +Earth(SG::SpectralGrid; kwargs...) = Earth{SG.NF}(; kwargs...) \ No newline at end of file diff --git a/src/dynamics/prognostic_variables.jl b/src/dynamics/prognostic_variables.jl index 11e19623e..3e5bbe51e 100644 --- a/src/dynamics/prognostic_variables.jl +++ b/src/dynamics/prognostic_variables.jl @@ -50,8 +50,8 @@ end """ $(TYPEDSIGNATURES) Create and initialize a clock from `time_stepping`""" -function Clock(time_stepping::AbstractTimeStepper;kwargs...) - clock = Clock(;kwargs...) +function Clock(time_stepping::AbstractTimeStepper; kwargs...) + clock = Clock(; kwargs...) initialize!(clock, time_stepping) end @@ -133,8 +133,8 @@ end # generator function based on a SpectralGrid function PrognosticVariablesOcean(SG::SpectralGrid) - (;nlat_half, Grid, NF) = SG - return PrognosticVariablesOcean{NF, Grid{NF}}(;nlat_half) + (; nlat_half, Grid, NF) = SG + return PrognosticVariablesOcean{NF, Grid{NF}}(; nlat_half) end Base.@kwdef mutable struct PrognosticVariablesLand{NF<:AbstractFloat, Grid<:AbstractGrid{NF}} <: AbstractVariables @@ -161,8 +161,8 @@ end # generator function based on a SpectralGrid function PrognosticVariablesLand(SG::SpectralGrid) - (;nlat_half, Grid, NF) = SG - return PrognosticVariablesLand{NF, Grid{NF}}(;nlat_half) + (; nlat_half, Grid, NF) = SG + return PrognosticVariablesLand{NF, Grid{NF}}(; nlat_half) end """Collect the n time steps of PrognosticVariablesSurface @@ -199,7 +199,7 @@ end function PrognosticVariables(SG::SpectralGrid, model::ModelSetup) - (;trunc, nlat_half, nlev, Grid, NF) = SG + (; trunc, nlat_half, nlev, Grid, NF) = SG # data structs layers = [PrognosticLayerTimesteps(SG) for _ in 1:nlev] # vector of nlev layers diff --git a/src/dynamics/spectral_grid.jl b/src/dynamics/spectral_grid.jl index eee07f386..3ea9c9f9d 100644 --- a/src/dynamics/spectral_grid.jl +++ b/src/dynamics/spectral_grid.jl @@ -49,7 +49,7 @@ Base.@kwdef struct SpectralGrid <: AbstractSpectralGrid nlev::Int = DEFAULT_NLEV "[OPTION] coordinates used to discretize the vertical" - vertical_coordinates::VerticalCoordinates = SigmaCoordinates(;nlev) + vertical_coordinates::VerticalCoordinates = SigmaCoordinates(; nlev) # make sure nlev and vertical_coordinates.nlev match function SpectralGrid(NF, trunc, Grid, dealiasing, radius, nlat_half, nlat, npoints, nlev, vertical_coordinates) @@ -64,12 +64,12 @@ Base.@kwdef struct SpectralGrid <: AbstractSpectralGrid end # generator functions -SpectralGrid(NF::Type{<:AbstractFloat};kwargs...) = SpectralGrid(;NF, kwargs...) -SpectralGrid(Grid::Type{<:AbstractGrid};kwargs...) = SpectralGrid(;Grid, kwargs...) -SpectralGrid(NF::Type{<:AbstractFloat}, Grid::Type{<:AbstractGrid};kwargs...) = SpectralGrid(;NF, Grid, kwargs...) +SpectralGrid(NF::Type{<:AbstractFloat}; kwargs...) = SpectralGrid(; NF, kwargs...) +SpectralGrid(Grid::Type{<:AbstractGrid}; kwargs...) = SpectralGrid(; Grid, kwargs...) +SpectralGrid(NF::Type{<:AbstractFloat}, Grid::Type{<:AbstractGrid}; kwargs...) = SpectralGrid(; NF, Grid, kwargs...) function Base.show(io::IO, SG::SpectralGrid) - (;NF, trunc, Grid, radius, nlat, npoints, nlev, vertical_coordinates) = SG + (; NF, trunc, Grid, radius, nlat, npoints, nlev, vertical_coordinates) = SG # resolution information res_ave = sqrt(4π*radius^2/npoints)/1000 # in [km] @@ -89,7 +89,7 @@ function SpeedyTransforms.SpectralTransform(spectral_grid::SpectralGrid; recompute_legendre::Bool = false, one_more_degree::Bool = true, kwargs...) - (;NF, Grid, trunc, dealiasing) = spectral_grid - return SpectralTransform(NF, Grid, trunc+one_more_degree, trunc;recompute_legendre, dealiasing, kwargs...) + (; NF, Grid, trunc, dealiasing) = spectral_grid + return SpectralTransform(NF, Grid, trunc+one_more_degree, trunc; recompute_legendre, dealiasing, kwargs...) end diff --git a/src/dynamics/tendencies.jl b/src/dynamics/tendencies.jl index e977616aa..47438b88a 100644 --- a/src/dynamics/tendencies.jl +++ b/src/dynamics/tendencies.jl @@ -21,8 +21,8 @@ function dynamics_tendencies!( time::DateTime, # time to evaluate the tendencies at model::ShallowWater, ) - (;forcing, drag, planet, atmosphere, orography) = model - (;spectral_transform, geometry) = model + (; forcing, drag, planet, atmosphere, orography) = model + (; spectral_transform, geometry) = model # for compatibility with other ModelSetups pressure pres = interface displacement η here forcing!(diagn, progn, forcing, time, model) # = (Fᵤ, Fᵥ, Fₙ) forcing for u, v, η @@ -148,13 +148,13 @@ end function pressure_gradient!(diagn::DiagnosticVariables, progn::PrognosticVariables, - lf::Integer, # leapfrog index + lf::Integer, # leapfrog index S::SpectralTransform) - (;pres) = progn.surface.timesteps[lf] # log of surface pressure - ∇lnp_x_spec = diagn.layers[1].dynamics_variables.a # reuse work arrays for gradients - ∇lnp_y_spec = diagn.layers[1].dynamics_variables.b # in spectral space - (;∇lnp_x, ∇lnp_y) = diagn.surface # but store in grid space + (; pres) = progn.surface.timesteps[lf] # log of surface pressure + ∇lnp_x_spec = diagn.layers[1].dynamics_variables.a # reuse work arrays for gradients + ∇lnp_y_spec = diagn.layers[1].dynamics_variables.b # in spectral space + (; ∇lnp_x, ∇lnp_y) = diagn.surface # but store in grid space ∇!(∇lnp_x_spec, ∇lnp_y_spec, pres, S) # CALCULATE ∇ln(pₛ) gridded!(∇lnp_x, ∇lnp_x_spec, S, unscale_coslat=true) # transform to grid: zonal gradient @@ -168,7 +168,7 @@ function pressure_flux!(diagn::DiagnosticVariablesLayer, (; u_grid, v_grid ) = diagn.grid_variables (; uv∇lnp ) = diagn.dynamics_variables - @. uv∇lnp = u_grid*∇lnp_x + v_grid*∇lnp_y # the (u, v)⋅∇lnpₛ term + @. uv∇lnp = u_grid*∇lnp_x + v_grid*∇lnp_y # the (u, v)⋅∇lnpₛ term end """Convert absolute and virtual temperature to anomalies wrt to the reference profile""" @@ -287,14 +287,14 @@ function vertical_velocity!( surf::SurfaceVariables, G::Geometry, ) - (;k) = diagn # vertical level + (; k) = diagn # vertical level Δσₖ = G.σ_levels_thick[k] # σ level thickness at k σk_half = G.σ_levels_half[k+1] # σ at k+1/2 σ̇ = diagn.dynamics_variables.σ_tend # vertical mass flux M = pₛσ̇ at k+1/2 # sum of Δσ-weighted div, uv∇lnp from 1:k-1 - (;div_sum_above, uv∇lnp, uv∇lnp_sum_above) = diagn.dynamics_variables - (;div_grid) = diagn.grid_variables + (; div_sum_above, uv∇lnp, uv∇lnp_sum_above) = diagn.dynamics_variables + (; div_grid) = diagn.grid_variables ūv̄∇lnp = surf.pres_tend_grid # calc'd in surface_pressure_tendency! (excl -D̄) D̄ = surf.div_mean_grid # vertical avrgd div to be added to ūv̄∇lnp @@ -317,7 +317,7 @@ function vordiv_tendencies!( surf::SurfaceVariables, model::PrimitiveEquation, ) - (;coriolis, atmosphere, geometry, spectral_transform) = model + (; coriolis, atmosphere, geometry, spectral_transform) = model vordiv_tendencies!(diagn, surf, coriolis, atmosphere, geometry, spectral_transform) end @@ -347,11 +347,11 @@ function vordiv_tendencies!( geometry::AbstractGeometry, S::SpectralTransform, ) - (;R_dry) = atmosphere # gas constant for dry air - (;f) = coriolis # coriolis parameter - (;coslat⁻¹) = geometry + (; R_dry) = atmosphere # gas constant for dry air + (; f) = coriolis # coriolis parameter + (; coslat⁻¹) = geometry - (;u_tend_grid, v_tend_grid) = diagn.tendencies # already contains vertical advection + (; u_tend_grid, v_tend_grid) = diagn.tendencies # already contains vertical advection u = diagn.grid_variables.u_grid # velocity v = diagn.grid_variables.v_grid # velocity vor = diagn.grid_variables.vor_grid # relative vorticity @@ -404,10 +404,10 @@ function tendencies_physics_only!( S::SpectralTransform, wet_core::Bool = true ) - (;coslat⁻¹) = G + (; coslat⁻¹) = G # already contain parameterizations - (;u_tend_grid, v_tend_grid, temp_tend_grid, humid_tend_grid) = diagn.tendencies + (; u_tend_grid, v_tend_grid, temp_tend_grid, humid_tend_grid) = diagn.tendencies # precompute ring indices and boundscheck rings = eachring(u_tend_grid, v_tend_grid) @@ -440,7 +440,7 @@ function temperature_tendency!( diagn::DiagnosticVariablesLayer, model::PrimitiveEquation, ) - (;adiabatic_conversion, atmosphere, geometry, spectral_transform, implicit) = model + (; adiabatic_conversion, atmosphere, geometry, spectral_transform, implicit) = model temperature_tendency!(diagn, adiabatic_conversion, atmosphere, geometry, spectral_transform, implicit) end @@ -462,11 +462,11 @@ function temperature_tendency!( S::SpectralTransform, I::ImplicitPrimitiveEquation, ) - (;temp_tend, temp_tend_grid) = diagn.tendencies - (;div_grid, temp_grid) = diagn.grid_variables - (;uv∇lnp, uv∇lnp_sum_above, div_sum_above) = diagn.dynamics_variables + (; temp_tend, temp_tend_grid) = diagn.tendencies + (; div_grid, temp_grid) = diagn.grid_variables + (; uv∇lnp, uv∇lnp_sum_above, div_sum_above) = diagn.dynamics_variables - (;κ) = atmosphere # thermodynamic kappa = R_Dry/heat_capacity + (; κ) = atmosphere # thermodynamic kappa = R_Dry/heat_capacity Tᵥ = diagn.grid_variables.temp_virt_grid # anomaly wrt to Tₖ Tₖ = I.temp_profile[diagn.k] # average layer temperature from reference profile @@ -519,7 +519,7 @@ function horizontal_advection!( add::Bool=true # add/overwrite A_tend_grid? ) where NF - (;div_grid) = diagn.grid_variables + (; div_grid) = diagn.grid_variables @inline kernel(a, b, c) = add ? a+b*c : b*c @@ -553,8 +553,8 @@ function flux_divergence!( A_tend::LowerTriangularMatrix{Complex{NF}}, # Ouput: add::Bool=true, # add result to A_tend or overwrite for false flipsign::Bool=true) where NF # compute -∇⋅((u, v)*A) (true) or ∇⋅((u, v)*A)? - (;u_grid, v_grid) = diagn.grid_variables - (;coslat⁻¹) = G + (; u_grid, v_grid) = diagn.grid_variables + (; coslat⁻¹) = G # reuse general work arrays a, b, a_grid, b_grid uA = diagn.dynamics_variables.a # = u*A in spectral @@ -576,7 +576,7 @@ function flux_divergence!( A_tend::LowerTriangularMatrix{Complex{NF}}, # Ouput: spectral!(uA, uA_grid, S) spectral!(vA, vA_grid, S) - divergence!(A_tend, uA, vA, S;add, flipsign) + divergence!(A_tend, uA, vA, S; add, flipsign) return nothing end @@ -602,10 +602,10 @@ function vorticity_flux_curldiv!( diagn::DiagnosticVariablesLayer, div::Bool=true, # also calculate div of vor flux? add::Bool=false) # accumulate in vor/div tendencies? - (;f) = coriolis - (;coslat⁻¹) = geometry + (; f) = coriolis + (; coslat⁻¹) = geometry - (;u_tend_grid, v_tend_grid) = diagn.tendencies # already contains forcing + (; u_tend_grid, v_tend_grid) = diagn.tendencies # already contains forcing u = diagn.grid_variables.u_grid # velocity v = diagn.grid_variables.v_grid # velocity vor = diagn.grid_variables.vor_grid # relative vorticity @@ -631,8 +631,8 @@ function vorticity_flux_curldiv!( diagn::DiagnosticVariablesLayer, spectral!(u_tend, u_tend_grid, S) spectral!(v_tend, v_tend_grid, S) - curl!(vor_tend, u_tend, v_tend, S;add) # ∂ζ/∂t = ∇×(u_tend, v_tend) - div && divergence!(div_tend, u_tend, v_tend, S;add) # ∂D/∂t = ∇⋅(u_tend, v_tend) + curl!(vor_tend, u_tend, v_tend, S; add) # ∂ζ/∂t = ∇×(u_tend, v_tend) + div && divergence!(div_tend, u_tend, v_tend, S; add) # ∂D/∂t = ∇⋅(u_tend, v_tend) return nothing end @@ -721,10 +721,10 @@ function linear_pressure_gradient!( atmosphere::AbstractAtmosphere, I::ImplicitPrimitiveEquation, ) - (;R_dry) = atmosphere # dry gas constant - Tₖ = I.temp_profile[diagn.k] # reference profile at layer k - (;pres) = surface.timesteps[lf] # logarithm of surface pressure - (;geopot) = diagn.dynamics_variables + (; R_dry) = atmosphere # dry gas constant + Tₖ = I.temp_profile[diagn.k] # reference profile at layer k + (; pres) = surface.timesteps[lf] # logarithm of surface pressure + (; geopot) = diagn.dynamics_variables # -R_dry*Tₖ*∇²lnpₛ, linear part of the ∇⋅RTᵥ∇lnpₛ pressure gradient term # Tₖ being the reference temperature profile, the anomaly term T' = Tᵥ - Tₖ is calculated @@ -776,8 +776,8 @@ function SpeedyTransforms.gridded!( # surface only for ShallowWaterModel or PrimitiveEquation S = model.spectral_transform - (;pres_grid) = diagn.surface - (;pres) = progn.surface.timesteps[lf] + (; pres_grid) = diagn.surface + (; pres) = progn.surface.timesteps[lf] model isa Barotropic || gridded!(pres_grid, pres, S) return nothing diff --git a/src/dynamics/time_integration.jl b/src/dynamics/time_integration.jl index 7ad72e20f..2be10d1c9 100644 --- a/src/dynamics/time_integration.jl +++ b/src/dynamics/time_integration.jl @@ -89,9 +89,9 @@ end $(TYPEDSIGNATURES) Generator function for a Leapfrog struct using `spectral_grid` for the resolution information.""" -function Leapfrog(spectral_grid::SpectralGrid;kwargs...) - (;NF, trunc, radius) = spectral_grid - return Leapfrog{NF}(;trunc, radius, kwargs...) +function Leapfrog(spectral_grid::SpectralGrid; kwargs...) + (; NF, trunc, radius) = spectral_grid + return Leapfrog{NF}(; trunc, radius, kwargs...) end """ @@ -101,7 +101,7 @@ Initialize leapfrogging `L` by recalculating the timestep given the output time be a divisor such that an integer number of time steps matches exactly with the output time step.""" function initialize!(L::Leapfrog, model::ModelSetup) - (;output_dt) = model.output + (; output_dt) = model.output if L.adjust_with_output # take actual output dt from model.output and recalculate timestep @@ -133,8 +133,8 @@ function leapfrog!( A_old::LowerTriangularMatrix{Complex{NF}}, # prognostic @boundscheck lf == 1 || lf == 2 || throw(BoundsError()) # index lf picks leapfrog dim A_lf = lf == 1 ? A_old : A_new # view on either t or t+dt to dis/enable Williams filter - (;robert_filter, williams_filter) = L # coefficients for the Robert and Williams filter - dt_NF = convert(NF, dt) # time step dt in number format NF + (; robert_filter, williams_filter) = L # coefficients for the Robert and Williams filter + dt_NF = convert(NF, dt) # time step dt in number format NF # LEAP FROG time step with or without Robert+Williams filter # Robert time filter to compress computational mode, Williams filter for 3rd order accuracy @@ -180,7 +180,7 @@ function leapfrog!( progn::PrognosticSurfaceTimesteps, lf::Int, # leapfrog index to dis/enable Williams filter model::ModelSetup) - (;pres_tend) = diagn + (; pres_tend) = diagn pres_old = progn.timesteps[1].pres pres_new = progn.timesteps[2].pres spectral_truncation!(pres_tend) # set lmax+1 mode to zero @@ -198,11 +198,11 @@ function first_timesteps!( output::AbstractOutputWriter, ) - (;clock) = progn + (; clock) = progn clock.n_timesteps == 0 && return nothing # exit immediately for no time steps - (;implicit) = model - (;Δt, Δt_millisec) = model.time_stepping + (; implicit) = model + (; Δt, Δt_millisec) = model.time_stepping Δt_millisec_half = Dates.Millisecond(Δt_millisec.value÷2) # this might be 1ms off # FIRST TIME STEP (EULER FORWARD with dt=Δt/2) @@ -247,7 +247,7 @@ function timestep!( lf2::Int=2, # leapfrog index 2 (time step used for tendencies) ) model.feedback.nars_detected && return nothing # exit immediately if NaRs already present - (;time) = progn.clock # current time + (; time) = progn.clock # current time # set the tendencies back to zero for accumulation zero_tendencies!(diagn) @@ -274,7 +274,7 @@ function timestep!( progn::PrognosticVariables{NF}, # all prognostic variables ) where {NF<:AbstractFloat} model.feedback.nars_detected && return nothing # exit immediately if NaRs already present - (;time) = progn.clock # current time + (; time) = progn.clock # current time # set the tendencies back to zero for accumulation zero_tendencies!(diagn) @@ -283,8 +283,8 @@ function timestep!( progn::PrognosticVariables{NF}, # all prognostic variables diagn_layer = diagn.layers[1] # multi-layer shallow water not supported progn_lf = progn_layer.timesteps[lf2] # pick the leapfrog time step lf2 for tendencies - (;pres) = progn.surface.timesteps[lf2] - (;implicit, spectral_transform) = model + (; pres) = progn.surface.timesteps[lf2] + (; implicit, spectral_transform) = model # GET TENDENCIES, CORRECT THEM FOR SEMI-IMPLICIT INTEGRATION dynamics_tendencies!(diagn_layer, progn_lf, diagn.surface, pres, time, model) @@ -296,7 +296,7 @@ function timestep!( progn::PrognosticVariables{NF}, # all prognostic variables gridded!(diagn_layer, progn_lf, model) # SURFACE LAYER (pressure), no diffusion though - (;pres_grid) = diagn.surface + (; pres_grid) = diagn.surface leapfrog!(progn.surface, diagn.surface, dt, lf1, model) gridded!(pres_grid, pres, spectral_transform) end @@ -313,7 +313,7 @@ function timestep!( progn::PrognosticVariables{NF}, # all prognostic variables ) where {NF<:AbstractFloat} model.feedback.nars_detected && return nothing # exit immediately if NaRs already present - (;time) = progn.clock # current time + (; time) = progn.clock # current time # set the tendencies back to zero for accumulation zero_tendencies!(diagn) @@ -351,7 +351,7 @@ function timestep!( progn::PrognosticVariables{NF}, # all prognostic variables gridded!(diagn_layer, progn_layer_lf, model) # propagate spectral state to grid else # surface level, time step for pressure leapfrog!(progn.surface, diagn.surface, dt, lf1, model) - (;pres_grid) = diagn.surface + (; pres_grid) = diagn.surface pres_lf = progn.surface.timesteps[lf2].pres gridded!(pres_grid, pres_lf, model.spectral_transform) end @@ -368,16 +368,16 @@ function time_stepping!( model::ModelSetup, # all model components ) - (;clock) = progn - (;Δt, Δt_millisec) = model.time_stepping - (;time_stepping) = model + (; clock) = progn + (; Δt, Δt_millisec) = model.time_stepping + (; time_stepping) = model # SCALING: we use vorticity*radius, divergence*radius in the dynamical core scale!(progn, model.spectral_grid.radius) # OUTPUT INITIALISATION AND STORING INITIAL CONDITIONS + FEEDBACK # propagate spectral state to grid variables for initial condition output - (;output, feedback) = model + (; output, feedback) = model lf = 1 # use first leapfrog index gridded!(diagn, progn, lf, model) initialize!(output, feedback, time_stepping, clock, diagn, model) diff --git a/src/dynamics/vertical_coordinates.jl b/src/dynamics/vertical_coordinates.jl index 71d1c2f7a..c6996b2ba 100644 --- a/src/dynamics/vertical_coordinates.jl +++ b/src/dynamics/vertical_coordinates.jl @@ -14,7 +14,7 @@ Base.@kwdef struct SigmaCoordinates <: VerticalCoordinates end # obtain nlev from length of predefined σ_half levels -SigmaCoordinates(σ_half::AbstractVector) = SigmaCoordinates(nlev=length(σ_half)-1;σ_half) +SigmaCoordinates(σ_half::AbstractVector) = SigmaCoordinates(nlev=length(σ_half)-1; σ_half) SigmaCoordinates(σ_half::AbstractRange) = SigmaCoordinates(collect(σ_half)) function Base.show(io::IO, σ::SigmaCoordinates) diff --git a/src/dynamics/virtual_temperature.jl b/src/dynamics/virtual_temperature.jl index 2223358e9..5b7768893 100644 --- a/src/dynamics/virtual_temperature.jl +++ b/src/dynamics/virtual_temperature.jl @@ -22,8 +22,8 @@ function virtual_temperature!( atmosphere::AbstractAtmosphere, ) - (;temp_grid, humid_grid, temp_virt_grid) = diagn.grid_variables - (;temp_virt) = diagn.dynamics_variables + (; temp_grid, humid_grid, temp_virt_grid) = diagn.grid_variables + (; temp_virt) = diagn.dynamics_variables μ = atmosphere.μ_virt_temp @inbounds for ij in eachgridpoint(temp_virt_grid, temp_grid, humid_grid) @@ -44,8 +44,8 @@ function virtual_temperature!( diagn::DiagnosticVariablesLayer, temp::LowerTriangularMatrix, model::PrimitiveDry) - (;temp_grid, temp_virt_grid) = diagn.grid_variables - (;temp_virt) = diagn.dynamics_variables + (; temp_grid, temp_virt_grid) = diagn.grid_variables + (; temp_virt) = diagn.dynamics_variables copyto!(temp_virt_grid, temp_grid) end @@ -61,8 +61,8 @@ function linear_virtual_temperature!( model::PrimitiveDry, lf::Integer, ) - (;temp_virt) = diagn.dynamics_variables - (;temp) = progn.timesteps[lf] + (; temp_virt) = diagn.dynamics_variables + (; temp) = progn.timesteps[lf] copyto!(temp_virt, temp) end @@ -93,10 +93,10 @@ function linear_virtual_temperature!( diagn::DiagnosticVariablesLayer, atmosphere::AbstractAtmosphere, lf::Int) - (;temp_virt) = diagn.dynamics_variables + (; temp_virt) = diagn.dynamics_variables μ = atmosphere.μ_virt_temp Tₖ = diagn.temp_average[] - (;temp, humid) = progn.timesteps[lf] + (; temp, humid) = progn.timesteps[lf] @. temp_virt = temp + (Tₖ*μ)*humid end \ No newline at end of file diff --git a/src/models/barotropic.jl b/src/models/barotropic.jl index 6719418b3..4767c4e61 100644 --- a/src/models/barotropic.jl +++ b/src/models/barotropic.jl @@ -4,7 +4,7 @@ export BarotropicModel, initialize! The BarotropicModel contains all model components needed for the simulation of the barotropic vorticity equations. To be constructed like - model = BarotropicModel(;spectral_grid, kwargs...) + model = BarotropicModel(; spectral_grid, kwargs...) with `spectral_grid::SpectralGrid` used to initalize all non-default components passed on as keyword arguments, e.g. `planet=Earth(spectral_grid)`. Fields, representing @@ -62,7 +62,7 @@ Calls all `initialize!` functions for most fields, representing components, of ` except for `model.output` and `model.feedback` which are always called at in `time_stepping!`.""" function initialize!(model::Barotropic; time::DateTime = DEFAULT_DATE) - (;spectral_grid) = model + (; spectral_grid) = model spectral_grid.nlev > 1 && @warn "Only nlev=1 supported for BarotropicModel, \ SpectralGrid with nlev=$(spectral_grid.nlev) provided." diff --git a/src/models/primitive_dry.jl b/src/models/primitive_dry.jl index fcc768664..5e6ae8938 100644 --- a/src/models/primitive_dry.jl +++ b/src/models/primitive_dry.jl @@ -92,7 +92,7 @@ Calls all `initialize!` functions for components of `model`, except for `model.output` and `model.feedback` which are always called at in `time_stepping!` and `model.implicit` which is done in `first_timesteps!`.""" function initialize!(model::PrimitiveDry; time::DateTime = DEFAULT_DATE) - (;spectral_grid) = model + (; spectral_grid) = model # NUMERICS (implicit is initialized later) initialize!(model.time_stepping, model) @@ -120,7 +120,7 @@ function initialize!(model::PrimitiveDry; time::DateTime = DEFAULT_DATE) # initial conditions prognostic_variables = PrognosticVariables(spectral_grid, model) initialize!(prognostic_variables, model.initial_conditions, model) - (;clock) = prognostic_variables + (; clock) = prognostic_variables clock.time = time # set the time # initialize ocean and land and synchronize clocks diff --git a/src/models/primitive_wet.jl b/src/models/primitive_wet.jl index aa8af32d8..3d13304c5 100644 --- a/src/models/primitive_wet.jl +++ b/src/models/primitive_wet.jl @@ -105,8 +105,8 @@ $(TYPEDSIGNATURES) Calls all `initialize!` functions for components of `model`, except for `model.output` and `model.feedback` which are always called at in `time_stepping!` and `model.implicit` which is done in `first_timesteps!`.""" -function initialize!(model::PrimitiveWet;time::DateTime = DEFAULT_DATE) - (;spectral_grid) = model +function initialize!(model::PrimitiveWet; time::DateTime = DEFAULT_DATE) + (; spectral_grid) = model # NUMERICS (implicit is initialized later) initialize!(model.time_stepping, model) @@ -139,7 +139,7 @@ function initialize!(model::PrimitiveWet;time::DateTime = DEFAULT_DATE) # initial conditions prognostic_variables = PrognosticVariables(spectral_grid, model) initialize!(prognostic_variables, model.initial_conditions, model) - (;clock) = prognostic_variables + (; clock) = prognostic_variables clock.time = time # set the time # initialize ocean and land and synchronize clocks diff --git a/src/models/shallow_water.jl b/src/models/shallow_water.jl index 8360023c6..e97503916 100644 --- a/src/models/shallow_water.jl +++ b/src/models/shallow_water.jl @@ -4,7 +4,7 @@ export ShallowWaterModel The ShallowWaterModel contains all model components needed for the simulation of the shallow water equations. To be constructed like - model = ShallowWaterModel(;spectral_grid, kwargs...) + model = ShallowWaterModel(; spectral_grid, kwargs...) with `spectral_grid::SpectralGrid` used to initalize all non-default components passed on as keyword arguments, e.g. `planet=Earth(spectral_grid)`. Fields, representing @@ -63,7 +63,7 @@ Calls all `initialize!` functions for most components (=fields) of `model`, except for `model.output` and `model.feedback` which are always initialized in `time_stepping!` and `model.implicit` which is done in `first_timesteps!`.""" function initialize!(model::ShallowWater; time::DateTime = DEFAULT_DATE) - (;spectral_grid) = model + (; spectral_grid) = model spectral_grid.nlev > 1 && @warn "Only nlev=1 supported for ShallowWaterModel, \ SpectralGrid with nlev=$(spectral_grid.nlev) provided." diff --git a/src/models/simulation.jl b/src/models/simulation.jl index 2c4dd5bbc..338442333 100644 --- a/src/models/simulation.jl +++ b/src/models/simulation.jl @@ -38,8 +38,8 @@ function run!( simulation::AbstractSimulation; period = Day(n_days) end - (;prognostic_variables, diagnostic_variables, model) = simulation - (;clock) = prognostic_variables + (; prognostic_variables, diagnostic_variables, model) = simulation + (; clock) = prognostic_variables # set the clock's enddate set_period!(clock, period) diff --git a/src/output/feedback.jl b/src/output/feedback.jl index f8038da1d..a2489ee7d 100644 --- a/src/output/feedback.jl +++ b/src/output/feedback.jl @@ -73,9 +73,9 @@ Initializes the a `Feedback` struct.""" function initialize!(feedback::Feedback, clock::Clock, model::ModelSetup) # reinitalize progress meter, minus one to exclude first_timesteps! which contain compilation - (;showspeed, desc) = feedback.progress_meter - (;verbose) = feedback - feedback.progress_meter = ProgressMeter.Progress(clock.n_timesteps-1;enabled=verbose, showspeed, desc) + (; showspeed, desc) = feedback.progress_meter + (; verbose) = feedback + feedback.progress_meter = ProgressMeter.Progress(clock.n_timesteps-1; enabled=verbose, showspeed, desc) # set to false to recheck for NaRs feedback.nars_detected = false diff --git a/src/output/output.jl b/src/output/output.jl index 6094feacd..98cce3266 100644 --- a/src/output/output.jl +++ b/src/output/output.jl @@ -130,7 +130,7 @@ function OutputWriter( NF::Type{<:Union{Float32, Float64}} = DEFAULT_OUTPUT_NF, kwargs... ) where {Model<:ModelSetup} - return OutputWriter{NF, Model}(;spectral_grid, kwargs...) + return OutputWriter{NF, Model}(; spectral_grid, kwargs...) end # default variables to output by model @@ -190,7 +190,7 @@ function initialize!( output.netcdf_file = dataset # DEFINE NETCDF DIMENSIONS TIME - (;startdate) = output + (; startdate) = output time_string = "hours since $(Dates.format(startdate, "yyyy-mm-dd HH:MM:0.0"))" defDim(dataset, "time", Inf) # unlimited time dimension defVar(dataset, "time", Float64, ("time",), @@ -198,7 +198,7 @@ function initialize!( "standard_name"=>"time", "calendar"=>"proleptic_gregorian")) # DEFINE NETCDF DIMENSIONS SPACE - (;input_Grid, output_Grid, nlat_half) = output + (; input_Grid, output_Grid, nlat_half) = output if output.as_matrix == false # interpolate onto (possibly different) output grid lond = get_lond(output_Grid, nlat_half) @@ -209,7 +209,7 @@ function initialize!( lat_name, lat_units, lat_longname = "lat", "degrees_north", "latitude" else # output grid directly into a matrix (resort grid points, no interpolation) - (;nlat_half) = diagn # don't use output.nlat_half as not supported for output_matrix + (; nlat_half) = diagn # don't use output.nlat_half as not supported for output_matrix nlon, nlat = RingGrids.matrix_size(input_Grid, nlat_half) # size of the matrix output lond = collect(1:nlon) # just enumerate grid points for lond, latd latd = collect(1:nlat) @@ -227,7 +227,7 @@ function initialize!( defVar(dataset, "lev", σ, ("lev",), attrib=Dict("units"=>"1", "long_name"=>"sigma levels")) # VARIABLES, define every variable here that could be output - (;compression_level) = output + (; compression_level) = output missing_value = convert(output_NF, output.missing_value) # given pres the right name, depending on ShallowWaterModel or PrimitiveEquationModel @@ -401,13 +401,13 @@ function write_netcdf_variables!( output::OutputWriter, diagn::DiagnosticVariables{NF, Grid, Model}) where {NF, Grid, Model} output.output_counter += 1 # increase output step counter - (;output_vars) = output # Vector{Symbol} of variables to output + (; output_vars) = output # Vector{Symbol} of variables to output i = output.output_counter - (;u, v, vor, div, pres, temp, humid, precip_cond, precip_conv, cloud) = output - (;output_Grid, interpolator) = output - (;quadrant_rotation, matrix_quadrant) = output - (;netcdf_file, keepbits) = output + (; u, v, vor, div, pres, temp, humid, precip_cond, precip_conv, cloud) = output + (; output_Grid, interpolator) = output + (; quadrant_rotation, matrix_quadrant) = output + (; netcdf_file, keepbits) = output for (k, diagn_layer) in enumerate(diagn.layers) diff --git a/src/output/plot.jl b/src/output/plot.jl index d0132f426..f6dd8e289 100644 --- a/src/output/plot.jl +++ b/src/output/plot.jl @@ -1,3 +1,5 @@ # to avoid ambiguity with exporting plot -plot(L::LowerTriangularMatrix{T}; kwargs...) where T = LowerTriangularMatrices.plot(L;kwargs...) -plot(G::AbstractGrid{T}; kwargs...) where T = RingGrids.plot(G;kwargs...) \ No newline at end of file +plot(L::LowerTriangularMatrix{T}; kwargs...) where T = LowerTriangularMatrices.plot(L; kwargs...) +plot(G::AbstractGrid{T}; kwargs...) where T = RingGrids.plot(G; kwargs...) + +; diff --git a/src/physics/boundary_layer.jl b/src/physics/boundary_layer.jl index ed1edad42..bcc32756f 100644 --- a/src/physics/boundary_layer.jl +++ b/src/physics/boundary_layer.jl @@ -33,7 +33,7 @@ end """ $(TYPEDSIGNATURES) Generator function using `nlev` from `SG::SpectralGrid`""" -LinearDrag(SG::SpectralGrid;kwargs...) = LinearDrag{SG.NF}(nlev=SG.nlev;kwargs...) +LinearDrag(SG::SpectralGrid; kwargs...) = LinearDrag{SG.NF}(nlev=SG.nlev; kwargs...) """ $(TYPEDSIGNATURES) @@ -41,8 +41,8 @@ Precomputes the drag coefficients for this `BoundaryLayerDrag` scheme.""" function initialize!( scheme::LinearDrag, model::PrimitiveEquation) - (;σ_levels_full) = model.geometry - (;σb, time_scale, drag_coefs) = scheme + (; σ_levels_full) = model.geometry + (; σb, time_scale, drag_coefs) = scheme kf = 1/time_scale.value @@ -64,8 +64,8 @@ Compute tendency for boundary layer drag of a `column` and add to its tendencies function boundary_layer_drag!( column::ColumnVariables, scheme::LinearDrag) - (;u, v, u_tend, v_tend) = column - (;drag_coefs) = scheme + (; u, v, u_tend, v_tend) = column + (; drag_coefs) = scheme @inbounds for k in eachlayer(column) kᵥ = drag_coefs[k] @@ -81,7 +81,7 @@ Base.@kwdef struct ConstantDrag{NF} <: AbstractBoundaryLayer drag::NF = 1e-3 end -ConstantDrag(SG::SpectralGrid;kwargs...) = ConstantDrag{SG.NF}(;kwargs...) +ConstantDrag(SG::SpectralGrid; kwargs...) = ConstantDrag{SG.NF}(; kwargs...) initialize!(::ConstantDrag, ::PrimitiveEquation) = nothing function boundary_layer_drag!( column::ColumnVariables, scheme::ConstantDrag, @@ -108,20 +108,20 @@ Base.@kwdef struct BulkRichardsonDrag{NF} <: AbstractBoundaryLayer drag_max::Base.RefValue{NF} = Ref(zero(NF)) end -BulkRichardsonDrag(SG::SpectralGrid, kwargs...) = BulkRichardsonDrag{SG.NF}(;kwargs...) +BulkRichardsonDrag(SG::SpectralGrid, kwargs...) = BulkRichardsonDrag{SG.NF}(; kwargs...) function initialize!(scheme::BulkRichardsonDrag, model::PrimitiveEquation) # Typical height Z of lowermost layer from geopotential of reference surface temperature # minus surface geopotential (orography * gravity) - (;temp_ref) = model.atmosphere - (;gravity) = model.planet - (;Δp_geopot_full) = model.geopotential + (; temp_ref) = model.atmosphere + (; gravity) = model.planet + (; Δp_geopot_full) = model.geopotential Z = temp_ref * Δp_geopot_full[end] / gravity # maximum drag Cmax from that height, stable conditions would decrease Cmax towards 0 # Frierson 2006, eq (12) - (;κ, z₀) = scheme + (; κ, z₀) = scheme scheme.drag_max[] = (κ/log(Z/z₀))^2 end @@ -136,7 +136,7 @@ function boundary_layer_drag!( scheme::BulkRichardsonDrag, ) - (;Ri_c) = scheme + (; Ri_c) = scheme drag_max = scheme.drag_max[] # bulk Richardson number at lowermost layer from Frierson, 2006, eq. (15) diff --git a/src/physics/column_variables.jl b/src/physics/column_variables.jl index 08500332a..c2b580831 100644 --- a/src/physics/column_variables.jl +++ b/src/physics/column_variables.jl @@ -24,7 +24,7 @@ function get_column!( C::ColumnVariables, orography::AbstractOrography, land_sea_mask::AbstractLandSeaMask) - (;σ_levels_full, ln_σ_levels_full) = geometry + (; σ_levels_full, ln_σ_levels_full) = geometry @boundscheck C.nlev == D.nlev || throw(BoundsError) @@ -73,7 +73,7 @@ end function get_column( S::AbstractSimulation, ij::Integer, verbose::Bool = true) - (;prognostic_variables, diagnostic_variables, model) = S + (; prognostic_variables, diagnostic_variables, model) = S column = deepcopy(S.diagnostic_variables.columns[1]) reset_column!(column) diff --git a/src/physics/convection.jl b/src/physics/convection.jl index 870e49a1b..c3b994ab3 100644 --- a/src/physics/convection.jl +++ b/src/physics/convection.jl @@ -29,7 +29,7 @@ Base.@kwdef struct SimplifiedBettsMiller{NF} <: AbstractConvection humid_ref_profile::Vector{NF} = zeros(NF, nlev) end -SimplifiedBettsMiller(SG::SpectralGrid;kwargs...) = SimplifiedBettsMiller{SG.NF}(nlev=SG.nlev;kwargs...) +SimplifiedBettsMiller(SG::SpectralGrid; kwargs...) = SimplifiedBettsMiller{SG.NF}(nlev=SG.nlev; kwargs...) initialize!(::SimplifiedBettsMiller, ::PrimitiveWet) = nothing # function barrier for all AbstractConvection @@ -70,10 +70,10 @@ function convection!( σ = geometry.σ_levels_full σ_half = geometry.σ_levels_half Δσ = geometry.σ_levels_thick - (;temp_ref_profile, humid_ref_profile) = SBM - (;geopot, nlev, temp, temp_virt, humid, temp_tend, humid_tend) = column + (; temp_ref_profile, humid_ref_profile) = SBM + (; geopot, nlev, temp, temp_virt, humid, temp_tend, humid_tend) = column pₛ = column.pres[end] - (;Lᵥ, cₚ) = clausius_clapeyron + (; Lᵥ, cₚ) = clausius_clapeyron # CONVECTIVE CRITERIA AND FIRST GUESS RELAXATION temp_parcel = temp[nlev] @@ -154,9 +154,9 @@ function convection!( column.precip_convection += δq * Δσ[k] end - (;gravity) = planet - (;water_density) = atmosphere - (;Δt_sec) = time_stepping + (; gravity) = planet + (; water_density) = atmosphere + (; Δt_sec) = time_stepping pₛΔt_gρ = (pₛ * Δt_sec / gravity / water_density) * deep_convection # enfore no precip for shallow conv column.precip_convection *= pₛΔt_gρ # convert to [m] of rain during Δt column.cloud_top = min(column.cloud_top, level_zero_buoyancy) # clouds reach to top of convection @@ -179,7 +179,7 @@ function pseudo_adiabat!( clausius_clapeyron::AbstractClausiusClapeyron, ) where NF - (;Lᵥ, R_dry, R_vapour, cₚ) = clausius_clapeyron + (; Lᵥ, R_dry, R_vapour, cₚ) = clausius_clapeyron R_cₚ = R_dry/cₚ ε = clausius_clapeyron.mol_ratio μ = (1-ε)/ε # for virtual temperature @@ -261,7 +261,7 @@ Base.@kwdef struct DryBettsMiller{NF} <: AbstractConvection temp_ref_profile::Vector{NF} = zeros(NF, nlev) end -DryBettsMiller(SG::SpectralGrid;kwargs...) = DryBettsMiller{SG.NF}(nlev=SG.nlev;kwargs...) +DryBettsMiller(SG::SpectralGrid; kwargs...) = DryBettsMiller{SG.NF}(nlev=SG.nlev; kwargs...) initialize!(::DryBettsMiller, ::PrimitiveWet) = nothing # function barrier to unpack model @@ -291,8 +291,8 @@ function convection!( σ = geometry.σ_levels_full σ_half = geometry.σ_levels_half Δσ = geometry.σ_levels_thick - (;temp_ref_profile) = DBM - (;nlev, temp, temp_tend) = column + (; temp_ref_profile) = DBM + (; nlev, temp, temp_tend) = column # CONVECTIVE CRITERIA AND FIRST GUESS RELAXATION level_zero_buoyancy = dry_adiabat!(temp_ref_profile, diff --git a/src/physics/land.jl b/src/physics/land.jl index 7aa240de8..b979c85c4 100644 --- a/src/physics/land.jl +++ b/src/physics/land.jl @@ -38,9 +38,9 @@ Base.@kwdef struct SeasonalLandTemperature{NF, Grid<:AbstractGrid{NF}} <: Abstra end # generator function -function SeasonalLandTemperature(SG::SpectralGrid;kwargs...) - (;NF, Grid, nlat_half) = SG - return SeasonalLandTemperature{NF, Grid{NF}}(;nlat_half, kwargs...) +function SeasonalLandTemperature(SG::SpectralGrid; kwargs...) + (; NF, Grid, nlat_half) = SG + return SeasonalLandTemperature{NF, Grid{NF}}(; nlat_half, kwargs...) end function initialize!(land::SeasonalLandTemperature, model::PrimitiveEquation) @@ -60,7 +60,7 @@ function land_timestep!(land::PrognosticVariablesLand, model::PrimitiveEquation; initialize::Bool = false) # the time step is dictated by the land "model" - executed = land_timestep!(land, time, model.land;initialize) + executed = land_timestep!(land, time, model.land; initialize) executed && model isa PrimitiveWet && soil_timestep!(land, time, model.soil) end @@ -82,7 +82,7 @@ function land_timestep!(land::PrognosticVariablesLand{NF}, # TODO check whether this shifts the climatology by 1/2 a month weight = convert(NF, Dates.days(time-Dates.firstdayofmonth(time))/Dates.daysinmonth(time)) - (;monthly_temperature) = land_model + (; monthly_temperature) = land_model @. land.land_surface_temperature = (1-weight) * monthly_temperature[this_month] + weight * monthly_temperature[next_month] @@ -143,9 +143,9 @@ Base.@kwdef struct SeasonalSoilMoisture{NF, Grid<:AbstractGrid{NF}} <: AbstractS end # generator function -function SeasonalSoilMoisture(SG::SpectralGrid;kwargs...) - (;NF, Grid, nlat_half) = SG - return SeasonalSoilMoisture{NF, Grid{NF}}(;nlat_half, kwargs...) +function SeasonalSoilMoisture(SG::SpectralGrid; kwargs...) + (; NF, Grid, nlat_half) = SG + return SeasonalSoilMoisture{NF, Grid{NF}}(; nlat_half, kwargs...) end function initialize!(soil::SeasonalSoilMoisture, model::PrimitiveWet) @@ -164,7 +164,7 @@ function soil_timestep!(land::PrognosticVariablesLand{NF}, # TODO check whether this shifts the climatology by 1/2 a month weight = convert(NF, Dates.days(time-Dates.firstdayofmonth(time))/Dates.daysinmonth(time)) - (;monthly_soil_moisture_layer1, monthly_soil_moisture_layer2) = soil_model + (; monthly_soil_moisture_layer1, monthly_soil_moisture_layer2) = soil_model @. land.soil_moisture_layer1 = (1-weight) * monthly_soil_moisture_layer1[this_month] + weight * monthly_soil_moisture_layer1[next_month] @. land.soil_moisture_layer2 = (1-weight) * monthly_soil_moisture_layer2[this_month] + @@ -211,9 +211,9 @@ Base.@kwdef struct VegetationClimatology{NF, Grid<:AbstractGrid{NF}} <: Abstract end # generator function -function VegetationClimatology(SG::SpectralGrid;kwargs...) - (;NF, Grid, nlat_half) = SG - return VegetationClimatology{NF, Grid{NF}}(;nlat_half, kwargs...) +function VegetationClimatology(SG::SpectralGrid; kwargs...) + (; NF, Grid, nlat_half) = SG + return VegetationClimatology{NF, Grid{NF}}(; nlat_half, kwargs...) end function initialize!(vegetation::VegetationClimatology, model::PrimitiveEquation) @@ -259,9 +259,9 @@ function soil_moisture_availability!( soil::AbstractSoil, vegetation::AbstractVegetation) where NF - (;soil_moisture_availability) = diagn - (;soil_moisture_layer1, soil_moisture_layer2) = land - (;high_cover, low_cover) = vegetation + (; soil_moisture_availability) = diagn + (; soil_moisture_layer1, soil_moisture_layer2) = land + (; high_cover, low_cover) = vegetation D_top = convert(NF, soil.D_top) D_root = convert(NF, soil.D_root) diff --git a/src/physics/land_sea_mask.jl b/src/physics/land_sea_mask.jl index e8e63ec5e..42e728b08 100644 --- a/src/physics/land_sea_mask.jl +++ b/src/physics/land_sea_mask.jl @@ -57,10 +57,10 @@ end """ $(TYPEDSIGNATURES) Generator function pulling the resolution information from `spectral_grid`.""" -function (L::Type{<:AbstractLandSeaMask})(spectral_grid::SpectralGrid;kwargs...) - (;NF, Grid, nlat_half) = spectral_grid +function (L::Type{<:AbstractLandSeaMask})(spectral_grid::SpectralGrid; kwargs...) + (; NF, Grid, nlat_half) = spectral_grid land_sea_mask = zeros(Grid{NF}, nlat_half) - return L{NF, Grid{NF}}(;land_sea_mask, kwargs...) + return L{NF, Grid{NF}}(; land_sea_mask, kwargs...) end """ @@ -69,7 +69,7 @@ Reads a high-resolution land-sea mask from file and interpolates (grid-call aver onto the model grid for a fractional sea mask.""" function initialize!(land_sea_mask::LandSeaMask, model::PrimitiveEquation) - (;file_Grid) = land_sea_mask + (; file_Grid) = land_sea_mask # LOAD NETCDF FILE if land_sea_mask.path == "SpeedyWeather.jl/input_data" diff --git a/src/physics/large_scale_condensation.jl b/src/physics/large_scale_condensation.jl index 2fbba2032..13b903513 100644 --- a/src/physics/large_scale_condensation.jl +++ b/src/physics/large_scale_condensation.jl @@ -18,7 +18,7 @@ Base.@kwdef struct ImplicitCondensation{NF<:AbstractFloat} <: AbstractCondensati time_scale::NF = 9 end -ImplicitCondensation(SG::SpectralGrid;kwargs...) = ImplicitCondensation{SG.NF}(;kwargs...) +ImplicitCondensation(SG::SpectralGrid; kwargs...) = ImplicitCondensation{SG.NF}(; kwargs...) # nothing to initialize with this scheme initialize!(scheme::ImplicitCondensation, model::PrimitiveEquation) = nothing @@ -67,17 +67,17 @@ function large_scale_condensation!( time_stepping::AbstractTimeStepper, ) where NF - (;temp, humid, pres) = column # prognostic vars: specific humidity, pressure - (;temp_tend, humid_tend) = column # tendencies to write into - (;sat_humid) = column # intermediate variable, calculated in thermodynamics! + (; temp, humid, pres) = column # prognostic vars: specific humidity, pressure + (; temp_tend, humid_tend) = column # tendencies to write into + (; sat_humid) = column # intermediate variable, calculated in thermodynamics! # precompute scaling constant for precipitation output pₛ = pres[end] # surface pressure - (;Δt_sec) = time_stepping + (; Δt_sec) = time_stepping Δσ = geometry.σ_levels_thick pₛΔt_gρ = pₛ*Δt_sec/(planet.gravity * atmosphere.water_density) - (;Lᵥ, cₚ, Lᵥ_Rᵥ) = clausius_clapeyron + (; Lᵥ, cₚ, Lᵥ_Rᵥ) = clausius_clapeyron Lᵥ_cₚ = Lᵥ/cₚ # latent heat of vaporization over heat capacity max_heating = scheme.max_heating/Δt_sec time_scale = scheme.time_scale diff --git a/src/physics/longwave_radiation.jl b/src/physics/longwave_radiation.jl index d79ab5b0b..a91452243 100644 --- a/src/physics/longwave_radiation.jl +++ b/src/physics/longwave_radiation.jl @@ -20,7 +20,7 @@ Base.@kwdef struct UniformCooling{NF} <: AbstractLongwave time_scale_stratosphere::Second = Day(5) end -UniformCooling(SG::SpectralGrid;kwargs...) = UniformCooling{SG.NF}(;kwargs...) +UniformCooling(SG::SpectralGrid; kwargs...) = UniformCooling{SG.NF}(; kwargs...) initialize!(scheme::UniformCooling, model::PrimitiveEquation) = nothing function longwave_radiation!( @@ -35,8 +35,8 @@ function longwave_radiation!( column::ColumnVariables{NF}, scheme::UniformCooling, ) where NF - (;temp, temp_tend) = column - (;temp_min, temp_stratosphere) = scheme + (; temp, temp_tend) = column + (; temp_min, temp_stratosphere) = scheme cooling = -inv(convert(NF, scheme.time_scale.value)) τ⁻¹ = inv(scheme.time_scale_stratosphere.value) diff --git a/src/physics/ocean.jl b/src/physics/ocean.jl index a8b5b6ffa..c7432cca9 100644 --- a/src/physics/ocean.jl +++ b/src/physics/ocean.jl @@ -37,9 +37,9 @@ Base.@kwdef struct SeasonalOceanClimatology{NF, Grid<:AbstractGrid{NF}} <: Abstr end # generator function -function SeasonalOceanClimatology(SG::SpectralGrid;kwargs...) - (;NF, Grid, nlat_half) = SG - return SeasonalOceanClimatology{NF, Grid{NF}}(;nlat_half, kwargs...) +function SeasonalOceanClimatology(SG::SpectralGrid; kwargs...) + (; NF, Grid, nlat_half) = SG + return SeasonalOceanClimatology{NF, Grid{NF}}(; nlat_half, kwargs...) end function initialize!(ocean::SeasonalOceanClimatology, model::PrimitiveEquation) @@ -94,7 +94,7 @@ function ocean_timestep!( ocean::PrognosticVariablesOcean, time::DateTime, model::PrimitiveEquation; initialize::Bool = false) - ocean_timestep!(ocean, time, model.ocean;initialize) + ocean_timestep!(ocean, time, model.ocean; initialize) end function ocean_timestep!( ocean::PrognosticVariablesOcean{NF}, @@ -115,7 +115,7 @@ function ocean_timestep!( ocean::PrognosticVariablesOcean{NF}, # TODO check whether this shifts the climatology by 1/2 a month weight = convert(NF, Dates.days(time-Dates.firstdayofmonth(time))/Dates.daysinmonth(time)) - (;monthly_temperature) = ocean_model + (; monthly_temperature) = ocean_model @. ocean.sea_surface_temperature = (1-weight) * monthly_temperature[this_month] + weight * monthly_temperature[next_month] diff --git a/src/physics/shortwave_radiation.jl b/src/physics/shortwave_radiation.jl index 1dc442ba9..61ac38696 100644 --- a/src/physics/shortwave_radiation.jl +++ b/src/physics/shortwave_radiation.jl @@ -22,8 +22,8 @@ end TransparentShortwave(SG::SpectralGrid) = TransparentShortwave{SG.NF}() function initialize!(scheme::TransparentShortwave, model::PrimitiveEquation) - (;solar_constant, gravity) = model.planet - (;pres_ref) = model.atmosphere + (; solar_constant, gravity) = model.planet + (; pres_ref) = model.atmosphere cₚ = model.atmosphere.heat_capacity Δσ = model.geometry.σ_levels_thick scheme.S[] = (1 - scheme.albedo) * solar_constant * gravity / (Δσ[end] * pres_ref * cₚ) diff --git a/src/physics/surface_fluxes.jl b/src/physics/surface_fluxes.jl index da90beb97..92da45deb 100644 --- a/src/physics/surface_fluxes.jl +++ b/src/physics/surface_fluxes.jl @@ -30,7 +30,7 @@ function surface_thermodynamics!( column::ColumnVariables, column.surface_humid = column.humid[end] # humidity at surface is the same as # surface air density via virtual temperature - (;R_dry) = atmosphere + (; R_dry) = atmosphere Tᵥ = column.temp_virt[column.nlev] column.surface_air_density = column.pres[end]/(R_dry*Tᵥ) end @@ -39,7 +39,7 @@ function surface_thermodynamics!( column::ColumnVariables, ::SurfaceThermodynamicsConstant, atmosphere::AbstractAtmosphere, model::PrimitiveDry) - (;R_dry) = atmosphere + (; R_dry) = atmosphere # surface value is same as lowest model level column.surface_temp = column.temp[end] # todo use constant POTENTIAL temperature column.surface_air_density = column.pres[end]/(R_dry*column.surface_temp) @@ -66,19 +66,19 @@ Base.@kwdef struct SurfaceWind{NF<:AbstractFloat} <: AbstractSurfaceWind max_flux::NF = 0.1 end -SurfaceWind(SG::SpectralGrid;kwargs...) = SurfaceWind{SG.NF}(;kwargs...) +SurfaceWind(SG::SpectralGrid; kwargs...) = SurfaceWind{SG.NF}(; kwargs...) function surface_wind_stress!( column::ColumnVariables{NF}, surface_wind::SurfaceWind) where NF - (;land_fraction) = column - (;f_wind, V_gust, drag_land, drag_sea) = surface_wind - (;max_flux) = surface_wind + (; land_fraction) = column + (; f_wind, V_gust, drag_land, drag_sea) = surface_wind + (; max_flux) = surface_wind # SPEEDY documentation eq. 49 column.surface_u = f_wind*column.u[end] column.surface_v = f_wind*column.v[end] - (;surface_u, surface_v) = column + (; surface_u, surface_v) = column # SPEEDY documentation eq. 50 column.surface_wind_speed = sqrt(surface_u^2 + surface_v^2 + V_gust^2) @@ -122,7 +122,7 @@ Base.@kwdef struct SurfaceSensibleHeat{NF<:AbstractFloat} <: AbstractSurfaceHeat max_flux::NF = 100 end -SurfaceSensibleHeat(SG::SpectralGrid;kwargs...) = SurfaceSensibleHeat{SG.NF}(;kwargs...) +SurfaceSensibleHeat(SG::SpectralGrid; kwargs...) = SurfaceSensibleHeat{SG.NF}(; kwargs...) function sensible_heat_flux!( column::ColumnVariables, @@ -130,7 +130,7 @@ function sensible_heat_flux!( atmosphere::AbstractAtmosphere ) cₚ = atmosphere.heat_capacity - (;heat_exchange_land, heat_exchange_sea, max_flux) = heat_flux + (; heat_exchange_land, heat_exchange_sea, max_flux) = heat_flux ρ = column.surface_air_density V₀ = column.surface_wind_speed @@ -190,7 +190,7 @@ Base.@kwdef struct SurfaceEvaporation{NF<:AbstractFloat} <: AbstractEvaporation moisture_exchange_sea::NF = 0.9e-3 end -SurfaceEvaporation(SG::SpectralGrid;kwargs...) = SurfaceEvaporation{SG.NF}(;kwargs...) +SurfaceEvaporation(SG::SpectralGrid; kwargs...) = SurfaceEvaporation{SG.NF}(; kwargs...) # don't do anything for dry core function evaporation!( column::ColumnVariables, @@ -208,8 +208,8 @@ function evaporation!( column::ColumnVariables{NF}, evaporation::SurfaceEvaporation, clausius_clapeyron::AbstractClausiusClapeyron) where NF - (;skin_temperature_sea, skin_temperature_land, pres) = column - (;moisture_exchange_land, moisture_exchange_sea) = evaporation + (; skin_temperature_sea, skin_temperature_land, pres) = column + (; moisture_exchange_land, moisture_exchange_sea) = evaporation α = column.soil_moisture_availability # SATURATION HUMIDITY OVER LAND AND OCEAN @@ -220,7 +220,7 @@ function evaporation!( column::ColumnVariables{NF}, ρ = column.surface_air_density V₀ = column.surface_wind_speed land_fraction = column.land_fraction - (;surface_humid) = column + (; surface_humid) = column # drag coefficient either from SurfaceEvaporation or from a central drag coefficient drag_sea, drag_land = evaporation.use_boundary_layer_drag ? diff --git a/src/physics/temperature_relaxation.jl b/src/physics/temperature_relaxation.jl index 4c9e6acab..f9f37df33 100644 --- a/src/physics/temperature_relaxation.jl +++ b/src/physics/temperature_relaxation.jl @@ -58,9 +58,9 @@ end """ $(TYPEDSIGNATURES) create a HeldSuarez temperature relaxation with arrays allocated given `spectral_grid`""" -function HeldSuarez(SG::SpectralGrid;kwargs...) - (;NF, nlat, nlev) = SG - return HeldSuarez{NF}(;nlev, nlat, kwargs...) +function HeldSuarez(SG::SpectralGrid; kwargs...) + (; NF, nlat, nlev) = SG + return HeldSuarez{NF}(; nlev, nlat, kwargs...) end """$(TYPEDSIGNATURES) @@ -69,11 +69,11 @@ equilibrium temperature Teq.""" function initialize!( scheme::HeldSuarez, model::PrimitiveEquation) - (;σ_levels_full, coslat, sinlat) = model.geometry - (;σb, ΔTy, Δθz, relax_time_slow, relax_time_fast, Tmax) = scheme - (;temp_relax_freq, temp_equil_a, temp_equil_b) = scheme + (; σ_levels_full, coslat, sinlat) = model.geometry + (; σb, ΔTy, Δθz, relax_time_slow, relax_time_fast, Tmax) = scheme + (; temp_relax_freq, temp_equil_a, temp_equil_b) = scheme - (;pres_ref) = model.atmosphere + (; pres_ref) = model.atmosphere scheme.p₀[] = pres_ref # surface reference pressure [Pa] scheme.κ[] = model.atmosphere.κ # thermodynamic kappa R_dry/cₚ @@ -110,12 +110,12 @@ function temperature_relaxation!( scheme::HeldSuarez, atmosphere::AbstractAtmosphere, ) - (;temp, temp_tend, pres, ln_pres) = column + (; temp, temp_tend, pres, ln_pres) = column j = column.jring[] # latitude ring index j - (;Tmin, temp_relax_freq, temp_equil_a, temp_equil_b) = scheme + (; Tmin, temp_relax_freq, temp_equil_a, temp_equil_b) = scheme # surface reference pressure [Pa] and thermodynamic kappa R_dry/cₚ - (;pres_ref, κ) = atmosphere + (; pres_ref, κ) = atmosphere @inbounds for k in eachlayer(column) lnp = ln_pres[k] # logarithm of pressure at level k @@ -171,9 +171,9 @@ end """ $(TYPEDSIGNATURES) create a JablonowskiRelaxation temperature relaxation with arrays allocated given `spectral_grid`""" -function JablonowskiRelaxation(SG::SpectralGrid;kwargs...) - (;NF, nlat, nlev) = SG - return JablonowskiRelaxation{NF}(;nlev, nlat, kwargs...) +function JablonowskiRelaxation(SG::SpectralGrid; kwargs...) + (; NF, nlat, nlev) = SG + return JablonowskiRelaxation{NF}(; nlev, nlat, kwargs...) end """$(TYPEDSIGNATURES) @@ -182,11 +182,11 @@ equilibrium temperature Teq and the frequency (strength of relaxation).""" function initialize!( scheme::JablonowskiRelaxation, model::PrimitiveEquation) - (;σ_levels_full, coslat, sinlat) = model.geometry - (;σb, relax_time_slow, relax_time_fast, η₀, u₀, ΔT) = scheme - (;temp_relax_freq, temp_equil, σ_tropopause, lapse_rate) = scheme - (;gravity) = model.planet - (;R_dry, temp_ref) = model.atmosphere + (; σ_levels_full, coslat, sinlat) = model.geometry + (; σb, relax_time_slow, relax_time_fast, η₀, u₀, ΔT) = scheme + (; temp_relax_freq, temp_equil, σ_tropopause, lapse_rate) = scheme + (; gravity) = model.planet + (; R_dry, temp_ref) = model.atmosphere Ω = model.planet.rotation # slow relaxation [1/s] everywhere, fast in the tropics @@ -235,9 +235,9 @@ vertical profile.""" function temperature_relaxation!( column::ColumnVariables, scheme::JablonowskiRelaxation) - (;temp, temp_tend) = column + (; temp, temp_tend) = column j = column.jring[] # latitude ring index j - (;temp_relax_freq, temp_equil) = scheme + (; temp_relax_freq, temp_equil) = scheme @inbounds for k in eachlayer(column) kₜ = temp_relax_freq[k, j] # (inverse) relaxation time scale diff --git a/src/physics/tendencies.jl b/src/physics/tendencies.jl index 58889c2ab..22ca82148 100644 --- a/src/physics/tendencies.jl +++ b/src/physics/tendencies.jl @@ -75,14 +75,14 @@ function fluxes_to_tendencies!( atmosphere::AbstractAtmosphere, ) - (;nlev, u_tend, flux_u_upward, flux_u_downward) = column + (; nlev, u_tend, flux_u_upward, flux_u_downward) = column (; v_tend, flux_v_upward, flux_v_downward) = column - (;humid_tend, flux_humid_upward, flux_humid_downward) = column - (;temp_tend, flux_temp_upward, flux_temp_downward) = column + (; humid_tend, flux_humid_upward, flux_humid_downward) = column + (; temp_tend, flux_temp_upward, flux_temp_downward) = column Δσ = geometry.σ_levels_thick pₛ = column.pres[end] # surface pressure - (;radius) = geometry # used for scaling + (; radius) = geometry # used for scaling # for g/Δp and g/(Δp*cₚ), see Fortran SPEEDY documentation eq. (3, 5) g_pₛ = planet.gravity/pₛ diff --git a/src/physics/thermodynamics.jl b/src/physics/thermodynamics.jl index 6404d4662..440b1f3ed 100644 --- a/src/physics/thermodynamics.jl +++ b/src/physics/thermodynamics.jl @@ -40,8 +40,8 @@ end # generator function function ClausiusClapeyron(SG::SpectralGrid, atm::AbstractAtmosphere; kwargs...) - (;R_dry, R_vapour, latent_heat_condensation, heat_capacity) = atm - return ClausiusClapeyron{SG.NF}(;Lᵥ=latent_heat_condensation, R_dry, R_vapour, cₚ=heat_capacity, kwargs...) + (; R_dry, R_vapour, latent_heat_condensation, heat_capacity) = atm + return ClausiusClapeyron{SG.NF}(; Lᵥ=latent_heat_condensation, R_dry, R_vapour, cₚ=heat_capacity, kwargs...) end """ @@ -54,7 +54,7 @@ Clausius-Clapeyron equation, where T is in Kelvin, Lᵥ the the latent heat of vaporization and Rᵥ the gas constant of water vapour, T₀ is 0˚C in Kelvin.""" function (CC::ClausiusClapeyron{NF})(temp_kelvin::NF) where NF - (;e₀, T₀⁻¹, Lᵥ_Rᵥ) = CC + (; e₀, T₀⁻¹, Lᵥ_Rᵥ) = CC return e₀ * exp(Lᵥ_Rᵥ*(T₀⁻¹ - inv(temp_kelvin))) end @@ -104,7 +104,7 @@ function saturation_humidity( clausius_clapeyron::AbstractClausiusClapeyron, ) where NF sat_vap_pres = clausius_clapeyron(temp_kelvin) - return saturation_humidity(sat_vap_pres, pres;mol_ratio=clausius_clapeyron.mol_ratio) + return saturation_humidity(sat_vap_pres, pres; mol_ratio=clausius_clapeyron.mol_ratio) end """ @@ -132,7 +132,7 @@ function dry_static_energy!( atmosphere::AbstractAtmosphere ) cₚ = atmosphere.heat_capacity - (;dry_static_energy, geopot, temp) = column + (; dry_static_energy, geopot, temp) = column @inbounds for k in eachlayer(column) dry_static_energy[k] = cₚ * temp[k] + geopot[k] @@ -146,7 +146,7 @@ function bulk_richardson!( atmosphere::AbstractAtmosphere, ) cₚ = atmosphere.heat_capacity - (;u, v, geopot, temp_virt, nlev, bulk_richardson) = column + (; u, v, geopot, temp_virt, nlev, bulk_richardson) = column V² = u[nlev]^2 + v[nlev]^2 Θ₀ = cₚ*temp_virt[nlev] @@ -169,7 +169,7 @@ function saturation_humidity!( column::ColumnVariables, clausius_clapeyron::AbstractClausiusClapeyron, ) - (;sat_humid, pres, temp) = column + (; sat_humid, pres, temp) = column for k in eachlayer(column) sat_humid[k] = saturation_humidity(temp[k], pres[k], clausius_clapeyron) @@ -188,9 +188,9 @@ function moist_static_energy!( column::ColumnVariables, clausius_clapeyron::AbstractClausiusClapeyron ) - (;Lᵥ) = clausius_clapeyron # latent heat of vaporization - (;sat_moist_static_energy, moist_static_energy, dry_static_energy) = column - (;humid, sat_humid) = column + (; Lᵥ) = clausius_clapeyron # latent heat of vaporization + (; sat_moist_static_energy, moist_static_energy, dry_static_energy) = column + (; humid, sat_humid) = column for k in eachlayer(column) moist_static_energy[k] = dry_static_energy[k] + Lᵥ * humid[k] @@ -238,7 +238,7 @@ Tetens equation, where T is in Kelvin and i = 1, 2 for saturation above and below freezing, respectively.""" function (TetensCoefficients::TetensEquation{NF})(temp_kelvin::NF) where NF - (;e₀, T₀, C₁, C₂, T₁, T₂) = TetensCoefficients + (; e₀, T₀, C₁, C₂, T₁, T₂) = TetensCoefficients C, T = temp_kelvin > T₀ ? (C₁, T₁) : (C₂, T₂) # change coefficients above/below freezing temp_celsius = temp_kelvin - T₀ return e₀ * exp(C * temp_celsius / (temp_celsius + T)) @@ -248,7 +248,7 @@ end $(TYPEDSIGNATURES) Gradient of the Tetens equation wrt to temperature, evaluated at `temp_kelvin`.""" function grad(TetensCoefficients::TetensEquation{NF}, temp_kelvin::NF) where NF - (;T₀, C₁, C₂, T₁, T₂) = TetensCoefficients + (; T₀, C₁, C₂, T₁, T₂) = TetensCoefficients e = TetensCoefficients(temp_kelvin) # saturation vapour pressure C, T = temp_kelvin > T₀ ? (C₁, T₁) : (C₂, T₂) # change coefficients above/below freezing return e*C*T/(temp_kelvin - T₀ - T)^2 # chain rule: times derivative of inner function diff --git a/src/physics/vertical_diffusion.jl b/src/physics/vertical_diffusion.jl index e0c095f5e..793dcca1a 100644 --- a/src/physics/vertical_diffusion.jl +++ b/src/physics/vertical_diffusion.jl @@ -37,15 +37,15 @@ Base.@kwdef struct StaticEnergyDiffusion{NF<:AbstractFloat} <: AbstractVerticalD Fstar::Base.RefValue{NF} = Ref(zero(NF)) # excluding the surface pressure pₛ end -StaticEnergyDiffusion(SG::SpectralGrid;kwargs...) = StaticEnergyDiffusion{SG.NF}(;kwargs...) +StaticEnergyDiffusion(SG::SpectralGrid; kwargs...) = StaticEnergyDiffusion{SG.NF}(; kwargs...) """$(TYPEDSIGNATURES) Initialize dry static energy diffusion.""" function initialize!( scheme::StaticEnergyDiffusion, model::PrimitiveEquation) - (;nlev) = model.spectral_grid - (;gravity) = model.planet + (; nlev) = model.spectral_grid + (; gravity) = model.planet C₀ = 1/nlev # average Δσ # Fortran SPEEDY documentation equation (70), excluding the surface pressure pₛ @@ -57,7 +57,7 @@ Apply dry static energy diffusion.""" function static_energy_diffusion!( column::ColumnVariables, scheme::StaticEnergyDiffusion) - (;nlev, dry_static_energy, flux_temp_upward, geopot) = column + (; nlev, dry_static_energy, flux_temp_upward, geopot) = column pₛ = column.pres[end] # surface pressure Fstar = scheme.Fstar[]*pₛ Γˢᵉ = scheme.static_energy_lapse_rate @@ -97,15 +97,15 @@ Base.@kwdef struct HumidityDiffusion{NF<:AbstractFloat} <: AbstractVerticalDiffu Fstar::Base.RefValue{NF} = Ref(zero(NF)) # excluding the surface pressure pₛ end -HumidityDiffusion(SG::SpectralGrid;kwargs...) = HumidityDiffusion{SG.NF}(;kwargs...) +HumidityDiffusion(SG::SpectralGrid; kwargs...) = HumidityDiffusion{SG.NF}(; kwargs...) """$(TYPEDSIGNATURES) Initialize dry static energy diffusion.""" function initialize!( scheme::HumidityDiffusion, model::PrimitiveEquation) - (;nlev) = model.spectral_grid - (;gravity) = model.planet + (; nlev) = model.spectral_grid + (; gravity) = model.planet C₀ = 1/nlev # average Δσ # Fortran SPEEDY documentation equation (70), excluding the surface pressure pₛ @@ -147,7 +147,7 @@ function humidity_diffusion!( column::ColumnVariables, scheme::HumidityDiffusion, geometry::Geometry) - (;nlev, sat_humid, rel_humid, flux_humid_upward) = column + (; nlev, sat_humid, rel_humid, flux_humid_upward) = column pₛ = column.pres[end] # surface pressure Fstar = scheme.Fstar[]*pₛ # Fstar = scheme.Fstar[] # SPEEDY code version diff --git a/src/physics/zenith.jl b/src/physics/zenith.jl index e621cb33d..1f7102624 100644 --- a/src/physics/zenith.jl +++ b/src/physics/zenith.jl @@ -13,13 +13,13 @@ Base.@kwdef struct SinSolarDeclination{NF} <: AbstractSolarDeclination end """Generator function pulling the number format NF from a SpectralGrid.""" -SinSolarDeclination(SG::SpectralGrid;kwargs...) = SinSolarDeclination{SG.NF}(;kwargs...) +SinSolarDeclination(SG::SpectralGrid; kwargs...) = SinSolarDeclination{SG.NF}(; kwargs...) """Generator function using the planet's orbital parameters to adapt the solar declination calculation.""" function SinSolarDeclination(SG::SpectralGrid, P::AbstractPlanet) - (;axial_tilt, equinox, length_of_year, length_of_day) = P - SinSolarDeclination{SG.NF}(;axial_tilt, equinox, length_of_year, length_of_day) + (; axial_tilt, equinox, length_of_year, length_of_day) = P + SinSolarDeclination{SG.NF}(; axial_tilt, equinox, length_of_year, length_of_day) end """ @@ -53,7 +53,7 @@ Base.@kwdef struct SolarDeclination{NF<:AbstractFloat} <: AbstractSolarDeclinati end """Generator function pulling the number format NF from a SpectralGrid.""" -SolarDeclination(SG::SpectralGrid;kwargs...) = SolarDeclination{SG.NF}(;kwargs...) +SolarDeclination(SG::SpectralGrid; kwargs...) = SolarDeclination{SG.NF}(; kwargs...) """ $(TYPEDSIGNATURES) @@ -61,7 +61,7 @@ SolarDeclination functor, computing the solar declination angle of angular fraction of year g [radians] using the coefficients of the SolarDeclination struct.""" function (SD::SolarDeclination)(g) - (;a, s1, s2, s3, c1, c2, c3) = SD + (; a, s1, s2, s3, c1, c2, c3) = SD sin1g, cos1g = sincos(g) sin2g, cos2g = sincos(2g) sin3g, cos3g = sincos(3g) @@ -90,7 +90,7 @@ $(TYPEDSIGNATURES) Functor that returns the time correction for a angular fraction of the year g [radians], so that g=0 for Jan-01 and g=2π for Dec-31.""" function (STC::SolarTimeCorrection)(g) - (;a, s1, s2, c1, c2) = STC + (; a, s1, s2, c1, c2) = STC sin1g, cos1g = sincos(g) sin2g, cos2g = sincos(2g) return deg2rad(a + s1*sin1g + c1*cos1g + s2*sin2g + c2*cos2g) @@ -108,9 +108,9 @@ Chooses from SolarZenith (daily and seasonal cycle) or SolarZenithSeason given the parameters in model.planet. In both cases the seasonal cycle can be disabled, calculating the solar declination from the initial time instead of current time.""" -function WhichZenith(SG::SpectralGrid, P::AbstractPlanet;kwargs...) - (;NF, Grid, nlat_half) = SG - (;daily_cycle, seasonal_cycle, length_of_day, length_of_year) = P +function WhichZenith(SG::SpectralGrid, P::AbstractPlanet; kwargs...) + (; NF, Grid, nlat_half) = SG + (; daily_cycle, seasonal_cycle, length_of_day, length_of_year) = P solar_declination = SinSolarDeclination(SG, P) if daily_cycle @@ -125,7 +125,7 @@ end # function barrier function cos_zenith!(time::DateTime, model::PrimitiveEquation) - (;solar_zenith, geometry) = model + (; solar_zenith, geometry) = model cos_zenith!(solar_zenith, time, geometry) end @@ -206,8 +206,8 @@ function cos_zenith!( geometry::AbstractGeometry, ) where NF - (;sinlat, coslat, lons) = geometry - (;cos_zenith, length_of_day, length_of_year) = S + (; sinlat, coslat, lons) = geometry + (; cos_zenith, length_of_day, length_of_year) = S @boundscheck geometry.nlat_half == S.nlat_half || throw(BoundsError) # g: angular fraction of year [0...2π] for Jan-01 to Dec-31 @@ -270,8 +270,8 @@ function cos_zenith!( geometry::AbstractGeometry, ) where NF - (;sinlat, coslat, lat) = geometry - (;cos_zenith, length_of_day, length_of_year) = S + (; sinlat, coslat, lat) = geometry + (; cos_zenith, length_of_day, length_of_year) = S @boundscheck geometry.nlat_half == S.nlat_half || throw(BoundsError) # g: angular fraction of year [0...2π] for Jan-01 to Dec-31 diff --git a/test/callbacks.jl b/test/callbacks.jl index 7dc5e039e..b6420c60e 100644 --- a/test/callbacks.jl +++ b/test/callbacks.jl @@ -39,7 +39,7 @@ end callback.maximum_surface_wind_speed = zeros(progn.clock.n_timesteps + 1) # where surface (=lowermost model layer) u, v on the grid are stored - (;u_grid, v_grid) = diagn.layers[diagn.nlev].grid_variables + (; u_grid, v_grid) = diagn.layers[diagn.nlev].grid_variables # maximum wind speed of initial conditions callback.maximum_surface_wind_speed[1] = max_2norm(u_grid, v_grid) @@ -69,7 +69,7 @@ end i = callback.timestep_counter # where surface (=lowermost model layer) u, v on the grid are stored - (;u_grid, v_grid) = diagn.layers[diagn.nlev].grid_variables + (; u_grid, v_grid) = diagn.layers[diagn.nlev].grid_variables # maximum wind speed at current time step callback.maximum_surface_wind_speed[i] = max_2norm(u_grid, v_grid) @@ -79,7 +79,7 @@ end spectral_grid = SpectralGrid() callbacks = CallbackDict(NoCallback()) - model = PrimitiveWetModel(;spectral_grid, callbacks) + model = PrimitiveWetModel(; spectral_grid, callbacks) storm_chaser = StormChaser(spectral_grid) key = :storm_chaser diff --git a/test/column_variables.jl b/test/column_variables.jl index 97a46bc5a..8d657e9c7 100644 --- a/test/column_variables.jl +++ b/test/column_variables.jl @@ -23,13 +23,13 @@ end @testset for NF in (Float32, Float64) nlev = 8 - spectral_grid = SpectralGrid(NF;nlev) - model = PrimitiveDryModel(;spectral_grid) + spectral_grid = SpectralGrid(NF; nlev) + model = PrimitiveDryModel(; spectral_grid) simulation = initialize!(model) diagn = simulation.diagnostic_variables progn = simulation.prognostic_variables - column = ColumnVariables{NF}(;nlev) + column = ColumnVariables{NF}(; nlev) SpeedyWeather.reset_column!(column) SpeedyWeather.get_column!(column, diagn, progn, 1, model) diff --git a/test/diffusion.jl b/test/diffusion.jl index f27bacf60..07ca999b1 100644 --- a/test/diffusion.jl +++ b/test/diffusion.jl @@ -2,14 +2,14 @@ for NF in (Float32, Float64) spectral_grid = SpectralGrid(NF) - m = PrimitiveDryModel(;spectral_grid) + m = PrimitiveDryModel(; spectral_grid) simulation = initialize!(m) p = simulation.prognostic_variables d = simulation.diagnostic_variables - (;vor) = p.layers[1].timesteps[1] - (;vor_tend) = d.layers[1].tendencies - (;∇²ⁿ, ∇²ⁿ_implicit) = m.horizontal_diffusion + (; vor) = p.layers[1].timesteps[1] + (; vor_tend) = d.layers[1].tendencies + (; ∇²ⁿ, ∇²ⁿ_implicit) = m.horizontal_diffusion vor = randn(typeof(vor), size(vor)...) @@ -18,7 +18,7 @@ # diffusion tendency has opposite sign (real/imag respectively) # than prognostic variable to act as a dissipation - (;lmax, mmax) = m.spectral_transform + (; lmax, mmax) = m.spectral_transform for m in 1:mmax+1 for l in max(2, m):lmax @test -sign(real(vor[l, m])) == sign(real(vor_tend[l, m])) diff --git a/test/extending.jl b/test/extending.jl index 6d46861ba..624794d92 100644 --- a/test/extending.jl +++ b/test/extending.jl @@ -23,15 +23,15 @@ ζ₀::LowerTriangularMatrix{Complex{NF}} = zeros(LowerTriangularMatrix{Complex{NF}}, trunc+2, trunc+1) end - function JetDrag(SG::SpectralGrid;kwargs...) - return JetDrag{SG.NF}(;SG.trunc, kwargs...) + function JetDrag(SG::SpectralGrid; kwargs...) + return JetDrag{SG.NF}(; SG.trunc, kwargs...) end function SpeedyWeather.initialize!( drag::JetDrag, model::ModelSetup) - (;spectral_grid, geometry) = model - (;Grid, NF, nlat_half) = spectral_grid + (; spectral_grid, geometry) = model + (; Grid, NF, nlat_half) = spectral_grid u = zeros(Grid{NF}, nlat_half) lat = geometry.latds @@ -52,11 +52,11 @@ time::DateTime, model::ModelSetup) - (;vor) = progn - (;vor_tend) = diagn.tendencies - (;ζ₀) = drag + (; vor) = progn + (; vor_tend) = diagn.tendencies + (; ζ₀) = drag - (;radius) = model.spectral_grid + (; radius) = model.spectral_grid r = radius/drag.time_scale.value for lm in eachindex(vor, vor_tend, ζ₀) vor_tend[lm] -= r*(vor[lm] - ζ₀[lm]) @@ -112,16 +112,16 @@ lat_mask::Vector{NF} = zeros(NF, nlat) end - function StochasticStirring(SG::SpectralGrid;kwargs...) - (;trunc, nlat) = SG - return StochasticStirring{SG.NF}(;trunc, nlat, kwargs...) + function StochasticStirring(SG::SpectralGrid; kwargs...) + (; trunc, nlat) = SG + return StochasticStirring{SG.NF}(; trunc, nlat, kwargs...) end function SpeedyWeather.initialize!( forcing::StochasticStirring, model::ModelSetup) # precompute forcing strength, scale with radius^2 as is the vorticity equation - (;radius) = model.spectral_grid + (; radius) = model.spectral_grid A = radius^2 * forcing.strength # precompute noise and auto-regressive factor, packed in RefValue for mutability @@ -131,7 +131,7 @@ forcing.b[] = exp(-dt/τ) # precompute the latitudinal mask - (;Grid, nlat_half) = model.spectral_grid + (; Grid, nlat_half) = model.spectral_grid latd = RingGrids.get_latd(Grid, nlat_half) for j in eachindex(forcing.lat_mask) @@ -158,7 +158,7 @@ a = forcing.a[] # = sqrt(1 - exp(-2dt/τ)) b = forcing.b[] # = exp(-dt/τ) - (;S) = forcing + (; S) = forcing lmax, mmax = size(S) @inbounds for m in 1:mmax for l in m:lmax @@ -179,7 +179,7 @@ RingGrids._scale_lat!(S_grid, forcing.lat_mask) # back to spectral space - (;vor_tend) = diagn.tendencies + (; vor_tend) = diagn.tendencies SpeedyTransforms.spectral!(vor_tend, S_grid, spectral_transform) SpeedyTransforms.spectral_truncation!(vor_tend) # set lmax+1 to zero @@ -193,14 +193,14 @@ initial_conditions = StartFromRest() # with barotropic model - model = BarotropicModel(;spectral_grid, initial_conditions, forcing, drag) + model = BarotropicModel(; spectral_grid, initial_conditions, forcing, drag) simulation = initialize!(model) run!(simulation, period=Day(5)) @test simulation.model.feedback.nars_detected == false # with shallow water model - model = ShallowWaterModel(;spectral_grid, initial_conditions, forcing, drag) + model = ShallowWaterModel(; spectral_grid, initial_conditions, forcing, drag) simulation = initialize!(model) run!(simulation, period=Day(5)) diff --git a/test/geopotential.jl b/test/geopotential.jl index c7676a438..b2b429ade 100644 --- a/test/geopotential.jl +++ b/test/geopotential.jl @@ -1,8 +1,8 @@ @testset "Geopotential reasonable" begin for NF in (Float32, Float64) nlev = 8 - spectral_grid = SpectralGrid(;NF, nlev, Grid=FullGaussianGrid) - model = PrimitiveWetModel(;spectral_grid) + spectral_grid = SpectralGrid(; NF, nlev, Grid=FullGaussianGrid) + model = PrimitiveWetModel(; spectral_grid) simulation = initialize!(model) p = simulation.prognostic_variables d = simulation.diagnostic_variables @@ -34,8 +34,8 @@ end @testset "Add geopotential and kinetic energy, compute -∇²B term, no errors" begin for NF in (Float32, Float64) nlev = 8 - spectral_grid = SpectralGrid(;NF, nlev, Grid=FullGaussianGrid) - m = PrimitiveWetModel(;spectral_grid) + spectral_grid = SpectralGrid(; NF, nlev, Grid=FullGaussianGrid) + m = PrimitiveWetModel(; spectral_grid) simulation = initialize!(m) p = simulation.prognostic_variables d = simulation.diagnostic_variables @@ -60,8 +60,8 @@ end @testset "Virtual temperature calculation" begin for NF in (Float32, Float64) nlev = 8 - spectral_grid = SpectralGrid(;NF, nlev, Grid=FullGaussianGrid) - m = PrimitiveWetModel(;spectral_grid) + spectral_grid = SpectralGrid(; NF, nlev, Grid=FullGaussianGrid) + m = PrimitiveWetModel(; spectral_grid) simulation = initialize!(m) p = simulation.prognostic_variables d = simulation.diagnostic_variables diff --git a/test/interpolation.jl b/test/interpolation.jl index c42472fe1..fb31a24c7 100644 --- a/test/interpolation.jl +++ b/test/interpolation.jl @@ -167,7 +167,7 @@ end trunc = 10 alms = randn(LowerTriangularMatrix{Complex{NF}}, 5, 5) alms = spectral_truncation(alms, trunc+2, trunc+1) - A = gridded(alms;Grid) + A = gridded(alms; Grid) # interpolate to FullGaussianGrid and back and compare nlat_half = 32 diff --git a/test/land_sea_mask.jl b/test/land_sea_mask.jl index 999d7dae5..62a135a4e 100644 --- a/test/land_sea_mask.jl +++ b/test/land_sea_mask.jl @@ -2,7 +2,7 @@ @testset for Mask in (LandSeaMask, AquaPlanetMask) spectral_grid = SpectralGrid(trunc=31, nlev=8) mask = Mask(spectral_grid) - model = PrimitiveWetModel(;spectral_grid, land_sea_mask=mask) + model = PrimitiveWetModel(; spectral_grid, land_sea_mask=mask) simulation = initialize!(model) run!(simulation, period=Day(5)) @test simulation.model.feedback.nars_detected == false diff --git a/test/lower_triangular_matrix.jl b/test/lower_triangular_matrix.jl index 1642aee03..2680c7e36 100644 --- a/test/lower_triangular_matrix.jl +++ b/test/lower_triangular_matrix.jl @@ -48,7 +48,7 @@ end @test_throws BoundsError A[34, 32] = 1 @test_throws BoundsError A[561] = 1 - # this can create a segfault so don't test regularly (but it worked ;) + # this can create a segfault so don't test regularly, but it worked ;) # g(A, i) = @inbounds A[i] = 1 # g(A, i, j) = @inbounds A[i, j] = 1 # g(A, 34, 32) diff --git a/test/netcdf_output.jl b/test/netcdf_output.jl index 82d5e8e86..ab841f9a3 100644 --- a/test/netcdf_output.jl +++ b/test/netcdf_output.jl @@ -5,77 +5,77 @@ using NCDatasets, Dates period = Day(1) # default grid, Float64, ShallowWater - spectral_grid = SpectralGrid(;NF=Float64, nlev=1) + spectral_grid = SpectralGrid(; NF=Float64, nlev=1) output = OutputWriter(spectral_grid, ShallowWater, path=tmp_output_path) - model = ShallowWaterModel(;spectral_grid, output) + model = ShallowWaterModel(; spectral_grid, output) simulation = initialize!(model) - run!(simulation, output=true;period) + run!(simulation, output=true; period) @test simulation.model.feedback.nars_detected == false # default grid, Float32, ShallowWater - spectral_grid = SpectralGrid(;NF=Float32, nlev=1) + spectral_grid = SpectralGrid(; NF=Float32, nlev=1) output = OutputWriter(spectral_grid, ShallowWater, path=tmp_output_path) - model = ShallowWaterModel(;spectral_grid, output) + model = ShallowWaterModel(; spectral_grid, output) simulation = initialize!(model) - run!(simulation, output=true;period) + run!(simulation, output=true; period) @test simulation.model.feedback.nars_detected == false # FullClenshawGrid, Float32, ShallowWater - spectral_grid = SpectralGrid(;NF=Float32, Grid=FullClenshawGrid, nlev=1) + spectral_grid = SpectralGrid(; NF=Float32, Grid=FullClenshawGrid, nlev=1) output = OutputWriter(spectral_grid, ShallowWater, path=tmp_output_path) - model = ShallowWaterModel(;spectral_grid, output) + model = ShallowWaterModel(; spectral_grid, output) simulation = initialize!(model) - run!(simulation, output=true;period) + run!(simulation, output=true; period) @test simulation.model.feedback.nars_detected == false # OctahedralClenshawGrid, Float32, ShallowWater - spectral_grid = SpectralGrid(;NF=Float32, Grid=OctahedralClenshawGrid, nlev=1) + spectral_grid = SpectralGrid(; NF=Float32, Grid=OctahedralClenshawGrid, nlev=1) output = OutputWriter(spectral_grid, ShallowWater, path=tmp_output_path) - model = ShallowWaterModel(;spectral_grid, output) + model = ShallowWaterModel(; spectral_grid, output) simulation = initialize!(model) - run!(simulation, output=true;period) + run!(simulation, output=true; period) @test simulation.model.feedback.nars_detected == false # HEALPixGrid, Float32, ShallowWater - spectral_grid = SpectralGrid(;NF=Float32, Grid=HEALPixGrid, nlev=1) + spectral_grid = SpectralGrid(; NF=Float32, Grid=HEALPixGrid, nlev=1) output = OutputWriter(spectral_grid, ShallowWater, path=tmp_output_path) - model = ShallowWaterModel(;spectral_grid, output) + model = ShallowWaterModel(; spectral_grid, output) simulation = initialize!(model) - run!(simulation, output=true;period) + run!(simulation, output=true; period) @test simulation.model.feedback.nars_detected == false # OctaHEALPixGrid, Float32, ShallowWater - spectral_grid = SpectralGrid(;NF=Float32, Grid=OctaHEALPixGrid, nlev=1) + spectral_grid = SpectralGrid(; NF=Float32, Grid=OctaHEALPixGrid, nlev=1) output = OutputWriter(spectral_grid, ShallowWater, path=tmp_output_path) - model = ShallowWaterModel(;spectral_grid, output) + model = ShallowWaterModel(; spectral_grid, output) simulation = initialize!(model) - run!(simulation, output=true;period) + run!(simulation, output=true; period) @test simulation.model.feedback.nars_detected == false # OctahedralClenshawGrid, as matrix, Float32, ShallowWater - spectral_grid = SpectralGrid(;NF=Float32, Grid=OctahedralClenshawGrid, nlev=1) + spectral_grid = SpectralGrid(; NF=Float32, Grid=OctahedralClenshawGrid, nlev=1) output = OutputWriter(spectral_grid, ShallowWater, path=tmp_output_path, as_matrix=true) - model = ShallowWaterModel(;spectral_grid, output) + model = ShallowWaterModel(; spectral_grid, output) simulation = initialize!(model) - run!(simulation, output=true;period) + run!(simulation, output=true; period) @test simulation.model.feedback.nars_detected == false # OctaHEALPixGrid, as matrix, Float32, PrimitiveDry # using T42 as T31 has stability issues in the first day - spectral_grid = SpectralGrid(;NF=Float32, trunc=42, Grid=OctaHEALPixGrid) + spectral_grid = SpectralGrid(; NF=Float32, trunc=42, Grid=OctaHEALPixGrid) output = OutputWriter(spectral_grid, PrimitiveDry, path=tmp_output_path, as_matrix=true) - model = PrimitiveDryModel(;spectral_grid, output) + model = PrimitiveDryModel(; spectral_grid, output) simulation = initialize!(model) - run!(simulation, output=true;period) + run!(simulation, output=true; period) @test simulation.model.feedback.nars_detected == false # OctaHEALPixGrid, as matrix, Float32, but output Float64 PrimitiveDry # using T42 as T31 has stability issues in the first day - spectral_grid = SpectralGrid(;NF=Float32, trunc=42, Grid=OctaHEALPixGrid) + spectral_grid = SpectralGrid(; NF=Float32, trunc=42, Grid=OctaHEALPixGrid) output = OutputWriter(spectral_grid, PrimitiveDry, path=tmp_output_path, as_matrix=true, NF=Float64) - model = PrimitiveDryModel(;spectral_grid, output) + model = PrimitiveDryModel(; spectral_grid, output) simulation = initialize!(model) - run!(simulation, output=true;period) + run!(simulation, output=true; period) @test simulation.model.feedback.nars_detected == false end @@ -84,12 +84,12 @@ end spectral_grid = SpectralGrid() output = OutputWriter(spectral_grid, PrimitiveDry, path=tmp_output_path, id="restart-test") - model = PrimitiveDryModel(;spectral_grid, output) + model = PrimitiveDryModel(; spectral_grid, output) simulation = initialize!(model) - run!(simulation, output=true;period=Day(1)) + run!(simulation, output=true; period=Day(1)) initial_conditions = StartFromFile(path=tmp_output_path, id="restart-test") - model2 = PrimitiveDryModel(;spectral_grid, initial_conditions) + model2 = PrimitiveDryModel(; spectral_grid, initial_conditions) simulation2 = initialize!(model2) p1 = simulation.prognostic_variables @@ -119,9 +119,9 @@ end spectral_grid = SpectralGrid() output = OutputWriter(spectral_grid, PrimitiveDry, path=tmp_output_path, id="dense-output-test", output_dt=Hour(0)) - model = PrimitiveDryModel(;spectral_grid, output) + model = PrimitiveDryModel(; spectral_grid, output) simulation = initialize!(model) - run!(simulation, output=true;period=Day(1)) + run!(simulation, output=true; period=Day(1)) progn = simulation.prognostic_variables tmp_read_path = joinpath(model.output.run_path, model.output.filename) @@ -131,9 +131,9 @@ end # do a simulation with the adjust_Δt_with_output turned on output = OutputWriter(spectral_grid, PrimitiveDry, path=tmp_output_path, id="adjust_dt_with_output-test", output_dt=Minute(70)) time_stepping = Leapfrog(spectral_grid, adjust_with_output=true) - model = PrimitiveDryModel(;spectral_grid, output, time_stepping) + model = PrimitiveDryModel(; spectral_grid, output, time_stepping) simulation = initialize!(model) - run!(simulation, output=true;period=Day(1)) + run!(simulation, output=true; period=Day(1)) t = SpeedyWeather.load_trajectory("time", model) @test all(y->y==diff(t)[1], diff(t)) # all elements equal @test diff(t)[1] == Minute(70) @@ -145,7 +145,7 @@ end spectral_grid = SpectralGrid() time_stepping = Leapfrog(spectral_grid, Δt_at_T31=Day(3650)) output = OutputWriter(spectral_grid, PrimitiveDry, path=tmp_output_path, id="long-output-test", output_dt=Day(3650)) - model = PrimitiveDryModel(;spectral_grid, output, time_stepping) + model = PrimitiveDryModel(; spectral_grid, output, time_stepping) simulation = initialize!(model) run!(simulation, output=true, period=Day(365000)) diff --git a/test/orography.jl b/test/orography.jl index 8fbb6b93b..d1ff6127a 100644 --- a/test/orography.jl +++ b/test/orography.jl @@ -2,7 +2,7 @@ @testset for Orography in (EarthOrography, ZonalRidge) spectral_grid = SpectralGrid(trunc=31, nlev=8) orography = Orography(spectral_grid) - model = PrimitiveWetModel(;spectral_grid, orography) + model = PrimitiveWetModel(; spectral_grid, orography) simulation = initialize!(model) run!(simulation, period=Day(5)) @test simulation.model.feedback.nars_detected == false diff --git a/test/run_speedy.jl b/test/run_speedy.jl index b2eed9170..590d4f461 100644 --- a/test/run_speedy.jl +++ b/test/run_speedy.jl @@ -1,28 +1,28 @@ @testset "run_speedy no errors, no blowup" begin # Barotropic spectral_grid = SpectralGrid(nlev=1) - model = BarotropicModel(;spectral_grid) + model = BarotropicModel(; spectral_grid) simulation = initialize!(model) run!(simulation, period=Day(10)) @test simulation.model.feedback.nars_detected == false # ShallowWater spectral_grid = SpectralGrid(nlev=1) - model = ShallowWaterModel(;spectral_grid) + model = ShallowWaterModel(; spectral_grid) simulation = initialize!(model) run!(simulation, period=Day(10)) @test simulation.model.feedback.nars_detected == false # PrimitiveDry spectral_grid = SpectralGrid() - model = PrimitiveDryModel(;spectral_grid) + model = PrimitiveDryModel(; spectral_grid) simulation = initialize!(model) run!(simulation, period=Day(10)) @test simulation.model.feedback.nars_detected == false # PrimitiveWet spectral_grid = SpectralGrid() - model = PrimitiveWetModel(;spectral_grid) + model = PrimitiveWetModel(; spectral_grid) simulation = initialize!(model) run!(simulation, period=Day(10)) @test simulation.model.feedback.nars_detected == false diff --git a/test/set_vars.jl b/test/set_vars.jl index 3db6ae38f..2a1638cc9 100644 --- a/test/set_vars.jl +++ b/test/set_vars.jl @@ -3,7 +3,7 @@ # test setting LowerTriangularMatrices spectral_grid = SpectralGrid() initial_conditions = StartFromRest() - M = PrimitiveWetModel(;spectral_grid, initial_conditions) + M = PrimitiveWetModel(; spectral_grid, initial_conditions) simulation = initialize!(M) P = simulation.prognostic_variables @@ -74,7 +74,7 @@ # test setting matrices spectral_grid = SpectralGrid(Grid=FullGaussianGrid) initial_conditions = StartFromRest() - M = PrimitiveWetModel(;spectral_grid, initial_conditions) + M = PrimitiveWetModel(; spectral_grid, initial_conditions) simulation = initialize!(M) P = simulation.prognostic_variables diff --git a/test/spectral_gradients.jl b/test/spectral_gradients.jl index a0165e721..77d8a2835 100644 --- a/test/spectral_gradients.jl +++ b/test/spectral_gradients.jl @@ -1,8 +1,8 @@ @testset "Divergence of a non-divergent flow zero?" begin @testset for NF in (Float32, Float64) - spectral_grid = SpectralGrid(;NF, nlev=1) - m = ShallowWaterModel(;spectral_grid) + spectral_grid = SpectralGrid(; NF, nlev=1) + m = ShallowWaterModel(; spectral_grid) simulation = initialize!(m) p = simulation.prognostic_variables d = simulation.diagnostic_variables @@ -48,8 +48,8 @@ end @testset "Curl of an irrotational flow zero?" begin @testset for NF in (Float32, Float64) - spectral_grid = SpectralGrid(;NF, nlev=1) - m = ShallowWaterModel(;spectral_grid) + spectral_grid = SpectralGrid(; NF, nlev=1) + m = ShallowWaterModel(; spectral_grid) simulation = initialize!(m) p = simulation.prognostic_variables d = simulation.diagnostic_variables @@ -97,7 +97,7 @@ end OctahedralClenshawGrid, HEALPixGrid) - SG = SpectralGrid(NF;Grid, nlev=1) + SG = SpectralGrid(NF; Grid, nlev=1) G = Geometry(SG) A = Grid(randn(NF, SG.npoints)) @@ -173,8 +173,8 @@ end @testset "D, ζ -> u, v -> D, ζ" begin @testset for NF in (Float32, Float64) - spectral_grid = SpectralGrid(;NF, nlev=1) - m = ShallowWaterModel(;spectral_grid) + spectral_grid = SpectralGrid(; NF, nlev=1) + m = ShallowWaterModel(; spectral_grid) simulation = initialize!(m) p = simulation.prognostic_variables d = simulation.diagnostic_variables @@ -188,7 +188,7 @@ end fill!(d.layers[1].tendencies.div_tend, 0) # create initial conditions - (;lmax, mmax) = m.spectral_transform + (; lmax, mmax) = m.spectral_transform vor0 = rand(LowerTriangularMatrix{Complex{NF}}, lmax+1, mmax+1) div0 = rand(LowerTriangularMatrix{Complex{NF}}, lmax+1, mmax+1) @@ -294,8 +294,8 @@ end for NF in (Float32, Float64) trunc = 31 - spectral_grid = SpectralGrid(;NF, trunc, Grid=FullGaussianGrid, nlev=1) - m = ShallowWaterModel(;spectral_grid) + spectral_grid = SpectralGrid(; NF, trunc, Grid=FullGaussianGrid, nlev=1) + m = ShallowWaterModel(; spectral_grid) simulation = initialize!(m) p = simulation.prognostic_variables d = simulation.diagnostic_variables diff --git a/test/spectral_transform.jl b/test/spectral_transform.jl index 213d62110..63c929aa2 100644 --- a/test/spectral_transform.jl +++ b/test/spectral_transform.jl @@ -50,7 +50,7 @@ spectral_resolutions_inexact = (127, 255) FullHEALPixGrid, FullOctaHEALPixGrid) - SG = SpectralGrid(NF;trunc, Grid) + SG = SpectralGrid(NF; trunc, Grid) S = SpectralTransform(SG) alms = zeros(LowerTriangularMatrix{Complex{NF}}, trunc+2, trunc+1) @@ -71,7 +71,7 @@ end for trunc in spectral_resolutions for NF in (Float32, Float64) - SG = SpectralGrid(NF;trunc) + SG = SpectralGrid(NF; trunc) S1 = SpectralTransform(SG, recompute_legendre=true) S2 = SpectralTransform(SG, recompute_legendre=false) @@ -94,7 +94,7 @@ end OctahedralGaussianGrid, OctahedralClenshawGrid) - SG = SpectralGrid(NF;trunc, Grid) + SG = SpectralGrid(NF; trunc, Grid) S = SpectralTransform(SG, recompute_legendre=true) lmax = 3 @@ -124,7 +124,7 @@ end FullHEALPixGrid, FullOctaHEALPixGrid) - SG = SpectralGrid(NF;trunc, Grid) + SG = SpectralGrid(NF; trunc, Grid) S = SpectralTransform(SG, recompute_legendre=true) lmax = 3 @@ -159,7 +159,7 @@ end # clenshaw-curtis grids are only exact for cubic truncation dealiasing = Grid in (FullGaussianGrid, OctahedralGaussianGrid) ? 2 : 3 - SG = SpectralGrid(NF;trunc, Grid, dealiasing) + SG = SpectralGrid(NF; trunc, Grid, dealiasing) S = SpectralTransform(SG, recompute_legendre=false) O = EarthOrography(SG, smoothing=true, smoothing_truncation=31) E = Earth(SG)