Skip to content

Commit

Permalink
Try to fix FieldVector inference
Browse files Browse the repository at this point in the history
Skip calling Fields.wrap
  • Loading branch information
charleskawczynski committed Sep 8, 2023
1 parent 4205c01 commit b5543c2
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 30 deletions.
40 changes: 18 additions & 22 deletions src/TurbulenceConvection_deprecated/types.jl
Original file line number Diff line number Diff line change
Expand Up @@ -212,21 +212,23 @@ float_type(state::State) = eltype(state.prog)
# float_type(field::CC.Fields.Field) = CC.Spaces.undertype(axes(field))
float_type(field::CC.Fields.Field) = eltype(parent(field))

import ClimaCore.Fields as Fields
import ClimaCore.Spaces as Spaces


Base.@propagate_inbounds function field_vector_column(
fv::FieldVector{T},
colidx::Fields.ColumnIndex,
) where {T}
values = map(x -> x[colidx], Fields._values(fv))
return Fields.FieldVector{T, typeof(values)}(values)
end

function tc_column_state(prog, p, tendencies, colidx, t)
prog_cent_column = CC.column(prog.c, colidx)
prog_face_column = CC.column(prog.f, colidx)
aux_cent_column = CC.column(p.edmf_cache.aux.cent, colidx)
aux_face_column = CC.column(p.edmf_cache.aux.face, colidx)
tends_cent_column = CC.column(tendencies.c, colidx)
tends_face_column = CC.column(tendencies.f, colidx)
prog_column =
CC.Fields.FieldVector(cent = prog_cent_column, face = prog_face_column)
aux_column =
CC.Fields.FieldVector(cent = aux_cent_column, face = aux_face_column)
tends_column = CC.Fields.FieldVector(
cent = tends_cent_column,
face = tends_face_column,
)
FT = Spaces.undertype(axes(prog.c))
prog_column = field_vector_column(prog, colidx)
aux_column = field_vector_column(p.edmf_cache.aux, colidx)
tends_column = field_vector_column(tendencies, colidx)
surface_conditions = CC.column(p.sfc_conditions, colidx)[]
return State(
prog_column,
Expand All @@ -239,14 +241,8 @@ function tc_column_state(prog, p, tendencies, colidx, t)
end

function tc_column_state(prog, p, tendencies::Nothing, colidx, t)
prog_cent_column = CC.column(prog.c, colidx)
prog_face_column = CC.column(prog.f, colidx)
aux_cent_column = CC.column(p.edmf_cache.aux.cent, colidx)
aux_face_column = CC.column(p.edmf_cache.aux.face, colidx)
prog_column =
CC.Fields.FieldVector(cent = prog_cent_column, face = prog_face_column)
aux_column =
CC.Fields.FieldVector(cent = aux_cent_column, face = aux_face_column)
prog_column = field_vector_column(prog, colidx)
aux_column = field_vector_column(p.edmf_cache.aux, colidx)
tends_column = nothing
surface_conditions = CC.column(p.sfc_conditions, colidx)[]
return State(
Expand Down
11 changes: 3 additions & 8 deletions src/dycore_equations_deprecated/sgs_flux_tendencies.jl
Original file line number Diff line number Diff line change
Expand Up @@ -237,14 +237,9 @@ function explicit_sgs_flux_tendency!(Yₜ, Y, p, t, colidx, ::TC.EDMFModel)
# Note: This "filter relaxation tendency" can be scaled down if needed, but
# it must be present in order to prevent Y and Y_filtered from diverging
# during each timestep.
Yₜ_turbconv =
Fields.FieldVector(c = Yₜ.c.turbconv[colidx], f = Yₜ.f.turbconv[colidx])
Y_filtered_turbconv = Fields.FieldVector(
c = Y_filtered.c.turbconv[colidx],
f = Y_filtered.f.turbconv[colidx],
)
Y_turbconv =
Fields.FieldVector(c = Y.c.turbconv[colidx], f = Y.f.turbconv[colidx])
Yₜ_turbconv = field_vector_column(Yₜ, colidx)
Y_filtered_turbconv = field_vector_column(Y_filtered, colidx)
Y_turbconv = field_vector_column(Y, colidx)
Yₜ_turbconv .+= (Y_filtered_turbconv .- Y_turbconv) ./ Δt
return nothing
end

0 comments on commit b5543c2

Please sign in to comment.