Skip to content

Do not reconstruct FD grid #117

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 3, 2025
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
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "ClimaDiagnostics"
uuid = "1ecacbb8-0713-4841-9a07-eb5aa8a2d53f"
authors = ["Gabriele Bozzola <gbozzola@caltech.edu>"]
version = "0.2.14"
version = "0.2.15"

[deps]
Accessors = "7d9f7c33-5ae7-4f3b-8dc6-eff91059b697"
Expand Down
53 changes: 21 additions & 32 deletions src/netcdf_writer_coordinates.jl
Original file line number Diff line number Diff line change
Expand Up @@ -503,7 +503,7 @@ function add_space_coordinates_maybe!(
add_space_coordinates_maybe!(nc, horizontal_space, num_points_horiz)

vertical_space = Spaces.FiniteDifferenceSpace(
Spaces.vertical_topology(space),
Spaces.grid(space).vertical_grid,
Spaces.staggering(space),
)

Expand Down Expand Up @@ -611,7 +611,7 @@ function target_coordinates(
target_coordinates(Spaces.horizontal_space(space), num_points_horiz)

vertical_space = Spaces.FiniteDifferenceSpace(
Spaces.vertical_topology(space),
Spaces.grid(space).vertical_grid,
Spaces.staggering(space),
)
vcoords =
Expand Down Expand Up @@ -681,79 +681,68 @@ Return a tuple with number of points that are optimally suited to interpolate th
"Optimally suited" here means approximately the same as the number of points as the given
`space`.
"""
function default_num_points(
space::ClimaCore.Spaces.ExtrudedFiniteDifferenceSpace,
)
horizontal_space = ClimaCore.Spaces.horizontal_space(space)
function default_num_points(space::Spaces.ExtrudedFiniteDifferenceSpace)
horizontal_space = Spaces.horizontal_space(space)
num_horz = default_num_points(horizontal_space)

vertical_space = ClimaCore.Spaces.FiniteDifferenceSpace(
Spaces.vertical_topology(space),
vertical_space = Spaces.FiniteDifferenceSpace(
Spaces.grid(space).vertical_grid,
Spaces.staggering(space),
)
num_vert = default_num_points(vertical_space)
return (num_horz..., num_vert...)
end

# 2D sphere
function default_num_points(
space::ClimaCore.Spaces.CubedSphereSpectralElementSpace2D,
)
function default_num_points(space::Spaces.CubedSphereSpectralElementSpace2D)
# A cubed sphere has 4 panels to cover the range of longitudes, each panel has
# `num_elements_per_panel` elements, each with `unique_degrees_of_freedom` points. Same
# for latitudes, except that we need 2 panels to cover from 0 to 180.

unique_degrees_of_freedom = ClimaCore.Quadratures.unique_degrees_of_freedom(
ClimaCore.Grids.quadrature_style(space),
Grids.quadrature_style(space),
)
num_elements_per_panel = ClimaCore.Meshes.n_elements_per_panel_direction(
ClimaCore.Spaces.topology(space).mesh,
Spaces.topology(space).mesh,
)
num_lat = 2 * num_elements_per_panel * unique_degrees_of_freedom
num_lon = 2num_lat
return (num_lon, num_lat)
end

# TODO: Maybe move to ClimaCore?
const RectilinearSpectralElementSpace1D =
ClimaCore.Spaces.SpectralElementSpace1D{
<:ClimaCore.Grids.SpectralElementGrid1D{
<:ClimaCore.Topologies.IntervalTopology,
},
}
const RectilinearSpectralElementSpace1D = Spaces.SpectralElementSpace1D{
<:Grids.SpectralElementGrid1D{<:ClimaCore.Topologies.IntervalTopology},
}

# 1D box
function default_num_points(space::RectilinearSpectralElementSpace1D)
unique_degrees_of_freedom = ClimaCore.Quadratures.unique_degrees_of_freedom(
ClimaCore.Grids.quadrature_style(space),
Grids.quadrature_style(space),
)
return (
unique_degrees_of_freedom *
ClimaCore.Meshes.nelements(ClimaCore.Spaces.topology(space).mesh),
ClimaCore.Meshes.nelements(Spaces.topology(space).mesh),
)
end

# 2D box
function default_num_points(
space::ClimaCore.Spaces.RectilinearSpectralElementSpace2D,
)
function default_num_points(space::Spaces.RectilinearSpectralElementSpace2D)
unique_degrees_of_freedom = ClimaCore.Quadratures.unique_degrees_of_freedom(
ClimaCore.Grids.quadrature_style(space),
Grids.quadrature_style(space),
)

return (
unique_degrees_of_freedom * ClimaCore.Meshes.nelements(
ClimaCore.Spaces.topology(space).mesh.intervalmesh1,
),
unique_degrees_of_freedom * ClimaCore.Meshes.nelements(
ClimaCore.Spaces.topology(space).mesh.intervalmesh2,
),
unique_degrees_of_freedom *
ClimaCore.Meshes.nelements(Spaces.topology(space).mesh.intervalmesh1),
unique_degrees_of_freedom *
ClimaCore.Meshes.nelements(Spaces.topology(space).mesh.intervalmesh2),
)
end

# Column
function default_num_points(space::Spaces.FiniteDifferenceSpace)
# We always want the center space for interpolation
cspace = Spaces.center_space(space)
return (ClimaCore.Spaces.nlevels(cspace),)
return (Spaces.nlevels(cspace),)
end
Loading