Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .buildkite/Manifest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

julia_version = "1.10.8"
manifest_format = "2.0"
project_hash = "f124967e8a7148176db47cb208ec29c14f382b0f"
project_hash = "1df235e0c8e5246d3a9cdc32ad82313e2fd7f343"

[[deps.ADTypes]]
git-tree-sha1 = "f7304359109c768cf32dc5fa2d371565bb63b68a"
Expand Down Expand Up @@ -376,7 +376,7 @@ weakdeps = ["CUDA", "MPI"]
deps = ["Adapt", "BandedMatrices", "BlockArrays", "ClimaComms", "ClimaInterpolations", "CubedSphere", "DataStructures", "ForwardDiff", "GaussQuadrature", "GilbertCurves", "HDF5", "InteractiveUtils", "IntervalSets", "KrylovKit", "LazyBroadcast", "LinearAlgebra", "MultiBroadcastFusion", "NVTX", "PkgVersion", "RecursiveArrayTools", "RootSolvers", "SparseArrays", "StaticArrays", "Statistics", "UnrolledUtilities"]
path = ".."
uuid = "d414da3d-4745-48bb-8d80-42e94e092884"
version = "0.14.48"
version = "0.14.49"
weakdeps = ["CUDA", "GPUCompiler", "Krylov"]

[deps.ClimaCore.extensions]
Expand Down
2 changes: 2 additions & 0 deletions .buildkite/Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,6 @@ Thermodynamics = "b60c26fb-14c3-4610-9d3e-2d17fe7ff00c"
ThreadsX = "ac1d9e8a-700a-412c-b207-f0111f4b6c0d"

[compat]
JET = "0.9.18"
PrettyTables = "2"
SnoopCompileCore = "3"
8 changes: 8 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,17 @@ ClimaCore.jl Release Notes

main
-------

v0.14.49
-------
- Add `PressureInterpolator` [2422](https://github.com/CliMA/ClimaCore.jl/pull/2422)
- Add Buildkite pipeline to check flagship AMIP performance [2438](https://github.com/CliMA/ClimaCore.jl/pull/2438)
- Fix conservation of split divergence [2432](https://github.com/CliMA/ClimaCore.jl/pull/2432)

v0.14.48
-------
- Add `VerticalMassBorrowingLimiter` [2383](https://github.com/CliMA/ClimaCore.jl/pull/2383)

v0.14.47
-------
- Use space-filling curve for CubedSphereGrid and ExtrudedCubedSphereGrid
Expand Down
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ClimaCore"
uuid = "d414da3d-4745-48bb-8d80-42e94e092884"
authors = ["CliMA Contributors <clima-software@caltech.edu>"]
version = "0.14.48"
version = "0.14.49"

[deps]
Adapt = "79e6a3ab-5dfb-504d-930d-738a2a938a0e"
Expand Down
48 changes: 34 additions & 14 deletions src/Remapping/interpolate_pressure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ struct PressureInterpolator{
FACE <: Fields.Field,
SPACE <: Spaces.AbstractSpace,
LEVELS,
EXTRAPOLATE <: ClimaInterpolations.Interpolation1D.Extrapolate1D,
}
"""A ClimaCore.Field representing pressure on center space. This field is
defined on a space with height (z) as the vertical coordinate, not
Expand All @@ -51,6 +52,10 @@ struct PressureInterpolator{
"""A 1D vector of pressure coordinates to interpolate onto for every
column"""
pressure_levels::LEVELS

"""Extrapolation condition when interpolating outside of the pressure
range"""
extrapolate::EXTRAPOLATE
end

"""
Expand Down Expand Up @@ -130,15 +135,23 @@ function construct_pfull_grid(::Type{FT}, pressure_levels, device) where {FT}
end

"""
PressureInterpolator(pfull_field::Fields.Field, pressure_levels)
PressureInterpolator(
pfull_field::Fields.Field,
pressure_levels;
extrapolate = ClimaInterpolations.Interpolation1D.Flat(),
)

Construct a `PressureInterpolator` from `pfull_field`, a pressure field defined
on a center space and `pressure_levels`, a vector of pressure levels to
interpolate to.

The pressure levels must be in ascending or descending order.
"""
function PressureInterpolator(pfull_field::Fields.Field, pressure_levels)
function PressureInterpolator(
pfull_field::Fields.Field,
pressure_levels;
extrapolate = ClimaInterpolations.Interpolation1D.Flat(),
)
if issorted(pressure_levels, rev = true)
pressure_levels = sort(pressure_levels)
end
Expand All @@ -150,7 +163,8 @@ function PressureInterpolator(pfull_field::Fields.Field, pressure_levels)
pressure_space = construct_pressure_space(FT, space, pressure_levels)
return PressureInterpolator(
pfull_field,
pressure_space,
pressure_space;
extrapolate,
)
end

Expand All @@ -160,18 +174,22 @@ end
pressure_space::Union{
Spaces.AbstractFiniteDifferenceSpace,
Spaces.ExtrudedFiniteDifferenceSpace,
},
};
extrapolate = ClimaInterpolations.Interpolation1D.Flat()
)

Construct a `PressureInterpolator` from `pfull_field`, a pressure field, and
`pressure_space`, a space with pressure as the vertical coordinate.

The default extrapolation behavior is constant extrapolation.
"""
function PressureInterpolator(
pfull_field::Fields.Field,
pressure_space::Union{
Spaces.AbstractFiniteDifferenceSpace,
Spaces.ExtrudedFiniteDifferenceSpace,
},
};
extrapolate = ClimaInterpolations.Interpolation1D.Flat(),
)
axes(pfull_field).staggering isa Grids.CellCenter || error("The staggering of the
pressure field must be cell center")
Expand All @@ -197,6 +215,7 @@ function PressureInterpolator(
scratch_face_pressure_field,
pressure_space,
pressure_levels,
extrapolate,
)
end

Expand Down Expand Up @@ -258,21 +277,19 @@ end
"""
interpolate_pressure(
field::Fields.Field,
pfull_intp::PressureInterpolator;
extrapolate = ClimaInterpolations.Interpolation1D.Flat(),
pfull_intp::PressureInterpolator,
)

Vertically interpolate field onto a space identical to that of field, but with
pressure as the vertical coordinate and return the interpolated field.
"""
function interpolate_pressure(
field::Fields.Field,
pfull_intp::PressureInterpolator;
extrapolate = ClimaInterpolations.Interpolation1D.Flat(),
pfull_intp::PressureInterpolator,
)
(; pfull_field) = pfull_intp
dest = fill(one(eltype(pfull_field)), pfull_intp.pressure_space)
Remapping.interpolate_pressure!(dest, field, pfull_intp; extrapolate)
Remapping.interpolate_pressure!(dest, field, pfull_intp)
return dest
end

Expand All @@ -281,7 +298,6 @@ end
dest::Fields.Field,
field::Fields.Field,
pfull_intp::PressureInterpolator;
extrapolate = ClimaInterpolations.Interpolation1D.Flat(),
)

Vertically interpolate `field` onto `dest` and return `nothing`.
Expand All @@ -291,10 +307,14 @@ The vertical coordinate of the space of `dest` must be in pressure.
function interpolate_pressure!(
dest::Fields.Field,
field::Fields.Field,
pfull_intp::PressureInterpolator;
extrapolate = ClimaInterpolations.Interpolation1D.Flat(),
pfull_intp::PressureInterpolator,
)
(; scratch_center_pressure_field, scratch_face_pressure_field, pressure_levels) =
(;
scratch_center_pressure_field,
scratch_face_pressure_field,
pressure_levels,
extrapolate,
) =
pfull_intp
scratch_pfull_array = if axes(field).staggering isa Grids.CellCenter
Fields.field2array(scratch_center_pressure_field)
Expand Down
20 changes: 18 additions & 2 deletions test/Remapping/interpolate_pressure.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,12 @@ for FT in (Float32, Float64)
pfull_field = fill(FT(1.0), space)
pfull_field_array = Fields.field2array(pfull_field)
pfull_field_array .= collect(10:-1:1)
pfull_levels = [0.0, 1.0, 5.5, 10.0, 12.0]
pressure_levels = [0.0, 1.0, 5.5, 10.0, 12.0]

# Pressures should be in sorted order
@test_throws ErrorException PressureInterpolator(pfull_field, [5.5, 10.0, 1.0])

pfull_intp = PressureInterpolator(pfull_field, pfull_levels)
pfull_intp = PressureInterpolator(pfull_field, pressure_levels)
pfull_field_array = Fields.field2array(Remapping.pfull_field(pfull_intp))

# Check the pressures along each column is sorted in descending
Expand Down Expand Up @@ -106,6 +106,22 @@ for FT in (Float32, Float64)

interpolate_pressure!(dest2, dummy_field, pfull_intp)
@test dest2 == dest

# Test linear extrapolation
pressure_levels = [-100.0, 100.0]
extrapolate = ClimaInterpolations.Interpolation1D.LinearExtrapolation()
linear_pfull_intp =
PressureInterpolator(pfull_field, pressure_levels; extrapolate)
dummy_field = fill(FT(1.0), space)
dummy_field_array = Fields.field2array(dummy_field)
dummy_field_array .= collect(10:-1:1)
dest = interpolate_pressure(dummy_field, linear_pfull_intp)
dest_array = Fields.field2array(dest)
@test dest_array == repeat(
[-100.0, 100.0],
1,
size(pfull_field_array, 2),
)
end
end

Expand Down
Loading