Skip to content

Commit

Permalink
Try #1477:
Browse files Browse the repository at this point in the history
  • Loading branch information
bors[bot] authored Sep 29, 2023
2 parents 28cc4a7 + aa78ca4 commit 3b979b2
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 50 deletions.
2 changes: 1 addition & 1 deletion docs/src/lib/ClimaCoreTempestRemap.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ end

# write out our cubed sphere mesh
meshfile_cc = "mesh_cubedsphere.g"
write_exodus(meshfile_cc, cspace.horizontal_space.topology)
write_exodus(meshfile_cc, Spaces.horizontal_space(cspace).topology)

# write out RLL mesh
nlat = 90
Expand Down
6 changes: 2 additions & 4 deletions examples/hybrid/sphere/remap_pipeline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,8 @@ function remap2latlon(filein, nc_dir, nlat, nlon)

# reconstruct space, obtain Nq from space
cspace = axes(Y.c)
hspace = cspace.horizontal_space
Nq = Spaces.Quadratures.degrees_of_freedom(
cspace.horizontal_space.quadrature_style,
)
hspace = Spaces.horizontal_space(cspace)
Nq = Spaces.Quadratures.degrees_of_freedom(hspace.quadrature_style)

# create a temporary dir for intermediate data
remap_tmpdir = nc_dir * "remaptmp/"
Expand Down
18 changes: 8 additions & 10 deletions lib/ClimaCoreVTK/src/space.jl
Original file line number Diff line number Diff line change
Expand Up @@ -125,10 +125,9 @@ function vtk_cells_linear(gridspace::Spaces.SpectralElementSpace2D)
end

function vtk_cells_linear(gridspace::Spaces.FaceExtrudedFiniteDifferenceSpace2D)
Nq = Spaces.Quadratures.degrees_of_freedom(
gridspace.horizontal_space.quadrature_style,
)
Nh = Topologies.nlocalelems(gridspace.horizontal_space)
hspace = Spaces.horizontal_space(gridspace)
Nq = Spaces.Quadratures.degrees_of_freedom(hspace.quadrature_style)
Nh = Topologies.nlocalelems(hspace)
Nv = Spaces.nlevels(gridspace)
ind = LinearIndices((1:Nv, 1:Nq, 1:Nh)) # assume VIFH
cells = [
Expand All @@ -145,10 +144,9 @@ function vtk_cells_linear(gridspace::Spaces.FaceExtrudedFiniteDifferenceSpace2D)
return vec(cells)
end
function vtk_cells_linear(gridspace::Spaces.FaceExtrudedFiniteDifferenceSpace3D)
Nq = Spaces.Quadratures.degrees_of_freedom(
gridspace.horizontal_space.quadrature_style,
)
Nh = Topologies.nlocalelems(gridspace.horizontal_space)
hspace = Spaces.horizontal_space(gridspace)
Nq = Spaces.Quadratures.degrees_of_freedom(hspace.quadrature_style)
Nh = Topologies.nlocalelems(hspace)
Nv = Spaces.nlevels(gridspace)
ind = LinearIndices((1:Nv, 1:Nq, 1:Nq, 1:Nh)) # assumes VIJFH
cells = [
Expand Down Expand Up @@ -199,7 +197,7 @@ function vtk_grid_space(space::Spaces.SpectralElementSpace2D)
end
function vtk_grid_space(space::Spaces.FaceExtrudedFiniteDifferenceSpace)
# this will need to be updated for warped meshes
horizontal_space = vtk_grid_space(space.horizontal_space)
horizontal_space = vtk_grid_space(Spaces.horizontal_space(space))
vertical_space = Spaces.FaceFiniteDifferenceSpace(space.vertical_topology)
return Spaces.ExtrudedFiniteDifferenceSpace(
horizontal_space,
Expand Down Expand Up @@ -241,7 +239,7 @@ function vtk_cell_space(gridspace::Spaces.SpectralElementSpace2D)
end
function vtk_cell_space(gridspace::Spaces.FaceExtrudedFiniteDifferenceSpace)
# this will need to be updated for warped meshes
horizontal_space = vtk_cell_space(gridspace.horizontal_space)
horizontal_space = vtk_cell_space(Spaces.horizontal_space(gridspace))
vertical_space =
Spaces.CenterFiniteDifferenceSpace(gridspace.vertical_topology)
return Spaces.ExtrudedFiniteDifferenceSpace(
Expand Down
6 changes: 2 additions & 4 deletions src/Fields/Fields.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ Field(::Type{T}, space::S) where {T, S <: AbstractSpace} =
ClimaComms.context(field::Field) = ClimaComms.context(axes(field))

ClimaComms.context(space::Spaces.ExtrudedFiniteDifferenceSpace) =
ClimaComms.context(space.horizontal_space)
ClimaComms.context(Spaces.horizontal_space(space))
ClimaComms.context(space::Spaces.SpectralElementSpace2D) =
ClimaComms.context(space.topology)
ClimaComms.context(space::S) where {S <: Spaces.AbstractSpace} =
Expand Down Expand Up @@ -403,9 +403,7 @@ Create a buffer for communicating neighbour information of `field`.
"""
function Spaces.create_dss_buffer(field::Field)
space = axes(field)
hspace =
space isa Spaces.ExtrudedFiniteDifferenceSpace ?
space.horizontal_space : space
hspace = Spaces.horizontal_space(space)
Spaces.create_dss_buffer(field_values(field), hspace)
end
# Add definitions for backward compatibility
Expand Down
45 changes: 18 additions & 27 deletions src/Spaces/extruded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -36,21 +36,20 @@ function issubspace(
hspace::AbstractSpectralElementSpace,
extruded_space::ExtrudedFiniteDifferenceSpace,
)
if hspace === extruded_space.horizontal_space
ehspace = Spaces.horizontal_space(extruded_space)
if hspace === ehspace
return true
end
# TODO: improve level handling
return Spaces.topology(hspace) ===
Spaces.topology(extruded_space.horizontal_space) &&
quadrature_style(hspace) ===
quadrature_style(extruded_space.horizontal_space)
return Spaces.topology(hspace) === Spaces.topology(ehspace) &&
quadrature_style(hspace) === quadrature_style(ehspace)
end


Adapt.adapt_structure(to, space::ExtrudedFiniteDifferenceSpace) =
ExtrudedFiniteDifferenceSpace(
space.staggering,
Adapt.adapt(to, space.horizontal_space),
Adapt.adapt(to, Spaces.horizontal_space(space)),
Adapt.adapt(to, space.vertical_topology),
Adapt.adapt(to, space.hypsography),
Adapt.adapt(to, space.global_geometry),
Expand Down Expand Up @@ -82,7 +81,7 @@ function ExtrudedFiniteDifferenceSpace{S}(
) where {S <: Staggering}
ExtrudedFiniteDifferenceSpace(
S(),
space.horizontal_space,
Spaces.horizontal_space(space),
space.vertical_topology,
space.hypsography,
space.global_geometry,
Expand All @@ -103,21 +102,12 @@ function Base.show(io::IO, space::ExtrudedFiniteDifferenceSpace)
":",
)
print(iio, " "^(indent + 2), "context: ")
Topologies.print_context(iio, space.horizontal_space.topology.context)
hspace = Spaces.horizontal_space(space)
Topologies.print_context(iio, hspace.topology.context)
println(iio)
println(iio, " "^(indent + 2), "horizontal:")
println(
iio,
" "^(indent + 4),
"mesh: ",
space.horizontal_space.topology.mesh,
)
println(
iio,
" "^(indent + 4),
"quadrature: ",
space.horizontal_space.quadrature_style,
)
println(iio, " "^(indent + 4), "mesh: ", hspace.topology.mesh)
println(iio, " "^(indent + 4), "quadrature: ", hspace.quadrature_style)
println(iio, " "^(indent + 2), "vertical:")
print(iio, " "^(indent + 4), "mesh: ", space.vertical_topology.mesh)
end
Expand Down Expand Up @@ -180,9 +170,10 @@ function ExtrudedFiniteDifferenceSpace(
end

quadrature_style(space::ExtrudedFiniteDifferenceSpace) =
space.horizontal_space.quadrature_style
Spaces.horizontal_space(space).quadrature_style

topology(space::ExtrudedFiniteDifferenceSpace) = space.horizontal_space.topology
topology(space::ExtrudedFiniteDifferenceSpace) =
Spaces.horizontal_space(space).topology
ClimaComms.device(space::ExtrudedFiniteDifferenceSpace) =
ClimaComms.device(topology(space))
vertical_topology(space::ExtrudedFiniteDifferenceSpace) =
Expand All @@ -194,7 +185,7 @@ Base.@propagate_inbounds function slab(
h,
)
SpectralElementSpaceSlab(
space.horizontal_space.quadrature_style,
Spaces.horizontal_space(space).quadrature_style,
slab(local_geometry_data(space), v, h),
)
end
Expand Down Expand Up @@ -233,7 +224,7 @@ Base.@propagate_inbounds function level(
space::CenterExtrudedFiniteDifferenceSpace,
v::Integer,
)
horizontal_space = space.horizontal_space
horizontal_space = Spaces.horizontal_space(space)
if horizontal_space isa SpectralElementSpace1D
SpectralElementSpace1D(
horizontal_space.topology,
Expand Down Expand Up @@ -262,7 +253,7 @@ Base.@propagate_inbounds function level(
space::FaceExtrudedFiniteDifferenceSpace,
v::PlusHalf,
)
horizontal_space = space.horizontal_space
horizontal_space = Spaces.horizontal_space(space)
if horizontal_space isa SpectralElementSpace1D
@inbounds SpectralElementSpace1D(
horizontal_space.topology,
Expand Down Expand Up @@ -388,12 +379,12 @@ function product_geometry(
end

function eachslabindex(cspace::CenterExtrudedFiniteDifferenceSpace)
h_iter = eachslabindex(cspace.horizontal_space)
h_iter = eachslabindex(Spaces.horizontal_space(cspace))
Nv = size(cspace.center_local_geometry, 4)
return Iterators.product(1:Nv, h_iter)
end
function eachslabindex(fspace::FaceExtrudedFiniteDifferenceSpace)
h_iter = eachslabindex(fspace.horizontal_space)
h_iter = eachslabindex(Spaces.horizontal_space(fspace))
Nv = size(fspace.face_local_geometry, 4)
return Iterators.product(1:Nv, h_iter)
end
9 changes: 5 additions & 4 deletions test/Operators/hybrid/2d.jl
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,18 @@ end
ccoord = Fields.coordinate_field(hv_center_space)
@test parent(Fields.field_values(level(fcoord.x, half))) == parent(
Fields.field_values(
Fields.coordinate_field(hv_face_space.horizontal_space).x,
Fields.coordinate_field(Spaces.horizontal_space(hv_face_space)).x,
),
)
@test parent(Fields.field_values(level(ccoord.x, 1))) == parent(
Fields.field_values(
Fields.coordinate_field(hv_center_space.horizontal_space).x,
Fields.coordinate_field(Spaces.horizontal_space(hv_center_space)).x,
),
)
@test parent(Fields.field_values(level(fcoord.z, half))) ==
parent(
Fields.field_values(
Fields.coordinate_field(hv_face_space.horizontal_space).x,
Fields.coordinate_field(Spaces.horizontal_space(hv_face_space)).x,
),
) .* 0
end
Expand Down Expand Up @@ -308,7 +308,8 @@ end
hv_center_space, hv_face_space =
hvspace_2D(xlim = (-1, 1), zlim = (-1, 1), helem = n, velem = n)
ccoords = Fields.coordinate_field(hv_center_space)
bcoords = Fields.coordinate_field(hv_center_space.horizontal_space)
bcoords =
Fields.coordinate_field(Spaces.horizontal_space(hv_center_space))

Δh[k] = 1.0 / n

Expand Down

0 comments on commit 3b979b2

Please sign in to comment.