Skip to content

Commit 799fb93

Browse files
Merge pull request #3798 from CliMA/ck/single_line_calls
Inline functions that return broadcasted objects
2 parents 426eb31 + 3c5b552 commit 799fb93

9 files changed

+16
-33
lines changed

src/cache/diagnostic_edmf_precomputed_quantities.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -979,8 +979,7 @@ NVTX.@annotate function set_diagnostic_edmf_precomputed_quantities_env_closures!
979979
ᶠu⁰ = p.scratch.ᶠtemp_C123
980980
@. ᶠu⁰ = C123(ᶠinterp(Y.c.uₕ)) + C123(ᶠu³⁰)
981981
ᶜstrain_rate = p.scratch.ᶜtemp_UVWxUVW
982-
bc_strain_rate = compute_strain_rate_center(ᶠu⁰)
983-
@. ᶜstrain_rate = bc_strain_rate
982+
ᶜstrain_rate .= compute_strain_rate_center(ᶠu⁰)
984983
@. ᶜstrain_rate_norm = norm_sqr(ᶜstrain_rate)
985984

986985
ᶜprandtl_nvec = p.scratch.ᶜtemp_scalar

src/cache/precomputed_quantities.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -270,8 +270,7 @@ the `turbconv_model` is EDMFX, the `Y.f.sgsʲs` are also modified so that each
270270
"""
271271
function set_velocity_at_surface!(Y, ᶠuₕ³, turbconv_model)
272272
sfc_u₃ = Fields.level(Y.f.u₃.components.data.:1, half)
273-
bc_sfc_u₃ = surface_velocity(Y.f.u₃, ᶠuₕ³)
274-
@. sfc_u₃ = bc_sfc_u₃
273+
sfc_u₃ .= surface_velocity(Y.f.u₃, ᶠuₕ³)
275274
if turbconv_model isa PrognosticEDMFX
276275
for j in 1:n_mass_flux_subdomains(turbconv_model)
277276
sfc_u₃ʲ = Fields.level(Y.f.sgsʲs.:($j).u₃.components.data.:1, half)
@@ -316,8 +315,7 @@ end
316315
function set_velocity_quantities!(ᶜu, ᶠu³, ᶜK, ᶠu₃, ᶜuₕ, ᶠuₕ³)
317316
@. ᶜu = C123(ᶜuₕ) + ᶜinterp(C123(ᶠu₃))
318317
@. ᶠu³ = ᶠuₕ³ + CT3(ᶠu₃)
319-
bc_kinetic = compute_kinetic(ᶜuₕ, ᶠu₃)
320-
@. ᶜK = bc_kinetic
318+
ᶜK .= compute_kinetic(ᶜuₕ, ᶠu₃)
321319
return nothing
322320
end
323321

src/cache/prognostic_edmf_precomputed_quantities.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -497,8 +497,7 @@ NVTX.@annotate function set_prognostic_edmf_precomputed_quantities_explicit_clos
497497
ᶠu⁰ = p.scratch.ᶠtemp_C123
498498
@. ᶠu⁰ = C123(ᶠinterp(Y.c.uₕ)) + C123(ᶠu³⁰)
499499
ᶜstrain_rate = p.scratch.ᶜtemp_UVWxUVW
500-
bc_strain_rate = compute_strain_rate_center(ᶠu⁰)
501-
@. ᶜstrain_rate = bc_strain_rate
500+
ᶜstrain_rate .= compute_strain_rate_center(ᶠu⁰)
502501
@. ᶜstrain_rate_norm = norm_sqr(ᶜstrain_rate)
503502

504503
ᶜprandtl_nvec = p.scratch.ᶜtemp_scalar

src/initial_conditions/initial_conditions.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -407,8 +407,7 @@ function overwrite_initial_conditions!(
407407
Y.c.uₕ .= C12.(Geometry.UVVector.(vel))
408408
Y.f.u₃ .= ᶠinterp.(C3.(Geometry.WVector.(vel)))
409409
e_kin = similar(ᶜT)
410-
bc_kinetic = compute_kinetic(Y.c.uₕ, Y.f.u₃)
411-
@. e_kin = bc_kinetic
410+
e_kin .= compute_kinetic(Y.c.uₕ, Y.f.u₃)
412411
e_pot = Fields.coordinate_field(Y.c).z .* thermo_params.grav
413412
Y.c.ρe_tot .= TD.total_energy.(thermo_params, ᶜts, e_kin, e_pot) .* Y.c.ρ
414413
if hasproperty(Y.c, :ρq_tot)

src/prognostic_equations/edmfx_sgs_flux.jl

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -356,8 +356,7 @@ function edmfx_sgs_diffusive_flux_tendency!(
356356

357357
# momentum
358358
ᶠstrain_rate = p.scratch.ᶠtemp_UVWxUVW
359-
bc_strain_rate = compute_strain_rate_face(ᶜu⁰)
360-
@. ᶠstrain_rate = bc_strain_rate
359+
ᶠstrain_rate .= compute_strain_rate_face(ᶜu⁰)
361360
@. Yₜ.c.uₕ -= C12(ᶜdivᵥ(-(2 * ᶠρaK_u * ᶠstrain_rate)) / Y.c.ρ)
362361
end
363362
return nothing
@@ -419,8 +418,7 @@ function edmfx_sgs_diffusive_flux_tendency!(
419418

420419
# momentum
421420
ᶠstrain_rate = p.scratch.ᶠtemp_UVWxUVW
422-
bc_strain_rate = compute_strain_rate_face(ᶜu)
423-
@. ᶠstrain_rate = bc_strain_rate
421+
ᶠstrain_rate .= compute_strain_rate_face(ᶜu)
424422
@. Yₜ.c.uₕ -= C12(ᶜdivᵥ(-(2 * ᶠρaK_u * ᶠstrain_rate)) / Y.c.ρ)
425423
end
426424

src/prognostic_equations/gm_sgs_closures.jl

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,7 @@ NVTX.@annotate function compute_gm_mixing_length!(ᶜmixing_length, Y, p)
4747
ᶠu = p.scratch.ᶠtemp_C123
4848
@. ᶠu = C123(ᶠinterp(Y.c.uₕ)) + C123(ᶠu³)
4949
ᶜstrain_rate = p.scratch.ᶜtemp_UVWxUVW
50-
bc_strain_rate = compute_strain_rate_center(ᶠu)
51-
@. ᶜstrain_rate = bc_strain_rate
50+
ᶜstrain_rate .= compute_strain_rate_center(ᶠu)
5251
@. ᶜstrain_rate_norm = norm_sqr(ᶜstrain_rate)
5352

5453
ᶜprandtl_nvec = p.scratch.ᶜtemp_scalar_2
@@ -64,6 +63,6 @@ NVTX.@annotate function compute_gm_mixing_length!(ᶜmixing_length, Y, p)
6463
sqrt(max(ᶜlinear_buoygrad, 0)), #N_eff
6564
ᶜdz,
6665
ᶜprandtl_nvec,
67-
norm_sqr(ᶜstrain_rate),
66+
ᶜstrain_rate_norm,
6867
)
6968
end

src/prognostic_equations/vertical_diffusion_boundary_layer.jl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,7 @@ function vertical_diffusion_boundary_layer_tendency!(
2424

2525
if !disable_momentum_vertical_diffusion(p.atmos.vert_diff)
2626
ᶠstrain_rate = p.scratch.ᶠtemp_UVWxUVW
27-
bc_strain_rate = compute_strain_rate_face(ᶜu)
28-
@. ᶠstrain_rate = bc_strain_rate
27+
ᶠstrain_rate .= compute_strain_rate_face(ᶜu)
2928
@. Yₜ.c.uₕ -= C12(
3029
ᶜdivᵥ(-2 * ᶠinterp(Y.c.ρ) * ᶠinterp(ᶜK_u) * ᶠstrain_rate) / Y.c.ρ,
3130
)

src/utils/utilities.jl

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ sort_files_by_time(files) =
4848
permute!(files, sortperm(time_from_filename.(files)))
4949

5050
"""
51-
bc_kinetic = compute_kinetic(uₕ::Field, uᵥ::Field)
52-
@. κ = bc_kinetic
51+
κ .= compute_kinetic(uₕ::Field, uᵥ::Field)
5352
5453
Compute the specific kinetic energy at cell centers, resulting in `κ` from
5554
individual velocity components:
@@ -80,8 +79,7 @@ state.
8079
compute_kinetic(Y::Fields.FieldVector) = compute_kinetic(Y.c.uₕ, Y.f.u₃)
8180

8281
"""
83-
bc_ϵ = compute_strain_rate_center(u::Field)
84-
@. ϵ = bc_ϵ
82+
ϵ .= compute_strain_rate_center(u::Field)
8583
8684
Compute the strain_rate at cell centers from velocity at cell faces.
8785
"""
@@ -97,8 +95,7 @@ function compute_strain_rate_center(u::Fields.Field)
9795
end
9896

9997
"""
100-
bc_ϵ = compute_strain_rate_face(u::Field)
101-
@. ϵ = bc_ϵ
98+
ϵ .= compute_strain_rate_face(u::Field)
10299
103100
Compute the strain_rate at cell faces from velocity at cell centers.
104101
"""

test/utilities.jl

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,7 @@ end
4848
CT123 = Geometry.Contravariant123Vector
4949
# Exercise function
5050
κ = zeros(cent_space)
51-
bc_kinetic = CA.compute_kinetic(uₕ, uᵥ)
52-
@. κ = bc_kinetic
51+
κ .= CA.compute_kinetic(uₕ, uᵥ)
5352
ᶜκ_exact = @. 1 // 2 *
5453
cos(z)^2 *
5554
((sin(x)^2) * (cos(y)^2) + (cos(x)^2) * (sin(y)^2))
@@ -87,12 +86,8 @@ end
8786
ᶠu = @. UVW(Geometry.UVector(ᶠu)) +
8887
UVW(Geometry.VVector(ᶠv)) +
8988
UVW(Geometry.WVector(ᶠw))
90-
bc_strain_rate =
91-
CA.compute_strain_rate_center(Geometry.Covariant123Vector.(ᶠu))
92-
@. ᶜϵ = bc_strain_rate
93-
bc_strain_rate =
94-
CA.compute_strain_rate_face(Geometry.Covariant123Vector.(ᶜu))
95-
@. ᶠϵ = bc_strain_rate
89+
ᶜϵ .= CA.compute_strain_rate_center(Geometry.Covariant123Vector.(ᶠu))
90+
ᶠϵ .= CA.compute_strain_rate_face(Geometry.Covariant123Vector.(ᶜu))
9691

9792
# Center valued strain rate
9893
@test ᶜϵ.components.data.:1 == ᶜϵ.components.data.:1 .* FT(0)

0 commit comments

Comments
 (0)