Skip to content

Commit

Permalink
more fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
simonbyrne committed Oct 24, 2023
1 parent 4efb0a6 commit 1973dac
Show file tree
Hide file tree
Showing 21 changed files with 114 additions and 73 deletions.
2 changes: 1 addition & 1 deletion examples/hybrid/hybrid3dcs_dss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ function hybrid3dcubedsphere_dss_profiler(

# precompile relevant functions
space = axes(Y.c)
horizontal_topology = space.horizontal_space.topology
horizontal_topology = Spaces.topology(space)
Spaces.weighted_dss_internal!(Y.c, ghost_buffer.c)
weighted_dss_full!(Y.c, ghost_buffer.c)
Spaces.fill_send_buffer!(
Expand Down
2 changes: 1 addition & 1 deletion examples/hybrid/sphere/hadley_circulation.jl
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ end

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

# write out RLL mesh
nlat = 90
Expand Down
2 changes: 1 addition & 1 deletion examples/hybrid/sphere/remap_pipeline.jl
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ function remap2latlon(filein, nc_dir, nlat, nlon)

# write out our cubed sphere mesh
meshfile_cc = remap_tmpdir * "mesh_cubedsphere.g"
write_exodus(meshfile_cc, hspace.topology)
write_exodus(meshfile_cc, Spaces.topology(hspace))

meshfile_rll = remap_tmpdir * "mesh_rll.g"
rll_mesh(meshfile_rll; nlat = nlat, nlon = nlon)
Expand Down
2 changes: 1 addition & 1 deletion examples/sphere/limiters_advection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ for (k, ne) in enumerate(ne_seq)
Spaces.SpectralElementSpace2D(grid_topology, quad; enable_bubble = true)

# Initialize variables needed for limiters
n_elems = Topologies.nlocalelems(space.topology)
n_elems = Topologies.nlocalelems(Spaces.topology(space))
min_q = zeros(n_elems)
max_q = zeros(n_elems)

Expand Down
4 changes: 2 additions & 2 deletions examples/sphere/shallow_water_cuda.jl
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ function rhs!(dYdt_fv, y_fv, parameters, t)
wcurl(Geometry.Covariant3Vector(curl(y.u))),
)

NVTX.@range "dss" Spaces.weighted_dss2!(dYdt, ghost_buffer)
NVTX.@range "dss" Spaces.weighted_dss!(dYdt, ghost_buffer)
end

NVTX.@range "tendency" begin
Expand All @@ -489,7 +489,7 @@ function rhs!(dYdt_fv, y_fv, parameters, t)
dYdt.u += -grad(g * (y.h + h_s) + norm(y.u)^2 / 2) #+
dYdt.u += y.u × (f + curl(y.u))
end
NVTX.@range "dss" Spaces.weighted_dss2!(dYdt, ghost_buffer)
NVTX.@range "dss" Spaces.weighted_dss!(dYdt, ghost_buffer)
end
end
return dYdt_fv
Expand Down
6 changes: 3 additions & 3 deletions lib/ClimaCorePlots/src/ClimaCorePlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ RecipesBase.@recipe function f(space::Spaces.ExtrudedFiniteDifferenceSpace)
#TODO: assumes VIFH layout
@assert Nj == 1 "plotting only defined for 1D extruded fields"

hspace = space.horizontal_space
hspace = Spaces.horizontal_space(space)

quad = Spaces.quadrature_style(hspace)
quad_name = Base.typename(typeof(quad)).name
Expand Down Expand Up @@ -196,7 +196,7 @@ function _slice_triplot(field, hinterpolate, ncolors)
Ni, Nj, _, Nv, Nh = size(data)

space = axes(field)
htopology = Spaces.topology(space.horizontal_space)
htopology = Spaces.topology(space)
hdomain = Topologies.domain(htopology)
vdomain = Topologies.domain(space.vertical_topology)

Expand Down Expand Up @@ -278,7 +278,7 @@ function _slice_along(field, coord)
)
end
space = axes(field)
hspace = space.horizontal_space
hspace = Spaces.horizontal_space(space)
htopo = ClimaCore.Spaces.topology(hspace)
hmesh = htopo.mesh
linear_idx = LinearIndices(ClimaCore.Meshes.elements(hmesh))
Expand Down
14 changes: 9 additions & 5 deletions lib/ClimaCoreTempestRemap/src/netcdf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,17 @@ end

function def_space_coord(
nc::NCDataset,
space::Spaces.ExtrudedFiniteDifferenceSpace{S};
space::Spaces.ExtrudedFiniteDifferenceSpace;
type = "dgll",
) where {S <: Spaces.Staggering}
hvar = def_space_coord(nc, space.horizontal_space; type = type)
)
staggering = Spaces.staggering(space)
hvar = def_space_coord(nc, Spaces.horizontal_space(space); type = type)
vvar = def_space_coord(
nc,
Spaces.FiniteDifferenceSpace{S}(space.vertical_topology),
Spaces.FiniteDifferenceSpace(
Spaces.vertical_topology(space),
staggering,
),
)
(hvar..., vvar...)
end
Expand Down Expand Up @@ -332,7 +336,7 @@ function Base.setindex!(
)
nc = NCDataset(var)
space = axes(field)
hspace = space.horizontal_space
hspace = Spaces.horizontal_space(space)
if nc.attrib["node_type"] == "cgll"
nodes = Spaces.unique_nodes(hspace)
elseif nc.attrib["node_type"] == "dgll"
Expand Down
12 changes: 2 additions & 10 deletions lib/ClimaCoreTempestRemap/src/onlineremap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,7 @@ function remap!(
# using out_type == "cgll"
if R.out_type == "cgll"
topology = Spaces.topology(R.target_space)
hspace = Spaces.horizontal_space(R.target_space)
quadrature_style = Spaces.quadrature_style(hspace)
Spaces.dss2!(target, topology, quadrature_style)
Topologies.dss!(target, topology)
end
return target
end
Expand Down Expand Up @@ -131,13 +129,7 @@ function remap!(target::Fields.Field, R::LinearMap, source::Fields.Field)
# using out_type == "cgll"
if R.out_type == "cgll"
topology = Spaces.topology(axes(target))
hspace = Spaces.horizontal_space(axes(target))
quadrature_style = Spaces.quadrature_style(hspace)
Spaces.dss2!(
Fields.field_values(target),
topology,
quadrature_style,
)
Topologies.dss!(Fields.field_values(target), topology)
end
return target
end
Expand Down
2 changes: 1 addition & 1 deletion lib/ClimaCoreTempestRemap/test/online_remap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ function reshape_sparse_to_field!(field::Fields.Field, in_array::Array, R)
topology = Spaces.topology(axes(field))
hspace = Spaces.horizontal_space(axes(field))
quadrature_style = Spaces.quadrature_style(hspace)
Spaces.dss2!(Fields.field_values(field), topology, quadrature_style)
Topologies.dss!(Fields.field_values(field), topology)
return field
end

Expand Down
2 changes: 1 addition & 1 deletion src/Fields/indices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -214,7 +214,7 @@ function byslab(
::ClimaComms.CPUMultiThreaded,
space::Spaces.AbstractSpectralElementSpace,
)
Nh = Topologies.nlocalelems(space.topology)::Int
Nh = Topologies.nlocalelems(Spaces.topology(space))::Int
@inbounds begin
Threads.@threads for h in 1:Nh
fn(SlabIndex(nothing, h))
Expand Down
2 changes: 1 addition & 1 deletion src/Grids/Grids.jl
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ function vertical_topology end
ClimaComms.context(grid::AbstractGrid) = ClimaComms.context(topology(grid))
ClimaComms.device(grid::AbstractGrid) = ClimaComms.device(topology(grid))

Meshes.domain(grid::AbstractGrid) = Meshes.domain(Topologies.topology(grid))
Meshes.domain(grid::AbstractGrid) = Meshes.domain(topology(grid))

include("finitedifference.jl")
include("spectralelement.jl")
Expand Down
6 changes: 3 additions & 3 deletions src/InputOutput/writers.jl
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ function write_new!(
"quadrature_num_points",
Quadratures.degrees_of_freedom(Spaces.quadrature_style(space)),
)
write_attribute(group, "topology", write!(writer, space.topology))
write_attribute(group, "topology", write!(writer, Spaces.topology(space)))
return name
end

Expand All @@ -347,7 +347,7 @@ function write_new!(
"quadrature_num_points",
Quadratures.degrees_of_freedom(Spaces.quadrature_style(space)),
)
write_attribute(group, "topology", write!(writer, space.topology))
write_attribute(group, "topology", write!(writer, Spaces.topology(space)))
return name
end

Expand All @@ -358,7 +358,7 @@ function write_new!(
)
group = create_group(writer.file, "grids/$name")
write_attribute(group, "type", "FiniteDifferenceGrid")
write_attribute(group, "topology", write!(writer, space.topology))
write_attribute(group, "topology", write!(writer, Spaces.topology(space)))
return name
end

Expand Down
4 changes: 2 additions & 2 deletions src/Operators/numericalflux.jl
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ See also:
function add_numerical_flux_internal!(fn, dydt, args...)
space = axes(dydt)
Nq = Spaces.Quadratures.degrees_of_freedom(Spaces.quadrature_style(space))
topology = space.topology
topology = Spaces.topology(space)

for (iface, (elem⁻, face⁻, elem⁺, face⁺, reversed)) in
enumerate(Topologies.interior_faces(topology))
Expand Down Expand Up @@ -101,7 +101,7 @@ end
function add_numerical_flux_boundary!(fn, dydt, args...)
space = axes(dydt)
Nq = Spaces.Quadratures.degrees_of_freedom(Spaces.quadrature_style(space))
topology = space.topology
topology = Spaces.topology(space)

for (iboundary, boundarytag) in
enumerate(Topologies.boundary_tags(topology))
Expand Down
9 changes: 7 additions & 2 deletions src/Spaces/extruded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,16 @@ function ExtrudedFiniteDifferenceSpace(
return ExtrudedFiniteDifferenceSpace(grid, vertical_space.staggering)
end

FaceExtrudedFiniteDifferenceSpace(grid::Grids.ExtrudedFiniteDifferenceGrid) =
ExtrudedFiniteDifferenceSpace(grid, CellFace())
CenterExtrudedFiniteDifferenceSpace(grid::Grids.ExtrudedFiniteDifferenceGrid) =
ExtrudedFiniteDifferenceSpace(grid, CellCenter())
FaceExtrudedFiniteDifferenceSpace(space::ExtrudedFiniteDifferenceSpace) =
ExtrudedFiniteDifferenceSpace(space.grid, CellFace())
CenterExtrudedFiniteDifferenceSpace(space::ExtrudedFiniteDifferenceSpace) =
ExtrudedFiniteDifferenceSpace(space.grid, CellCenter())


local_dss_weights(space::ExtrudedFiniteDifferenceSpace) =
local_dss_weights(grid(space))

Expand Down Expand Up @@ -115,10 +120,10 @@ function Base.show(io::IO, space::ExtrudedFiniteDifferenceSpace)
)
print(iio, " "^(indent + 2), "context: ")
hspace = Spaces.horizontal_space(space)
Topologies.print_context(iio, hspace.topology.context)
Topologies.print_context(iio, Spaces.topology(hspace).context)
println(iio)
println(iio, " "^(indent + 2), "horizontal:")
println(iio, " "^(indent + 4), "mesh: ", hspace.topology.mesh)
println(iio, " "^(indent + 4), "mesh: ", Spaces.topology(hspace).mesh)
println(iio, " "^(indent + 4), "quadrature: ", quadrature_style(hspace))
println(iio, " "^(indent + 2), "vertical:")
print(iio, " "^(indent + 4), "mesh: ", space.vertical_topology.mesh)
Expand Down
12 changes: 11 additions & 1 deletion src/Spaces/finitedifference.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
abstract type AbstractFiniteDifferenceSpace <: AbstractSpace end

"""
FiniteDifferenceSpace(staggering::Staggering, grid::Grids.FiniteDifferenceGrid)
FiniteDifferenceSpace(
grid::Grids.FiniteDifferenceGrid,
staggering::Staggering,
)
"""
struct FiniteDifferenceSpace{
Expand All @@ -11,6 +16,11 @@ struct FiniteDifferenceSpace{
grid::G
staggering::S
end
FiniteDifferenceSpace(
topology::Topologies.IntervalTopology,
staggering::Staggering,
) = FiniteDifferenceSpace(Grids.FiniteDifferenceGrid(topology), staggering)


const FaceFiniteDifferenceSpace{G} = FiniteDifferenceSpace{G, CellFace}
const CenterFiniteDifferenceSpace{G} = FiniteDifferenceSpace{G, CellCenter}
Expand Down
8 changes: 4 additions & 4 deletions src/Spaces/spectralelement.jl
Original file line number Diff line number Diff line change
Expand Up @@ -203,28 +203,28 @@ function Base.iterate(
# this also doesn't deal with the case where eo == e
if j == 1
# face 1
eo, _, _ = Topologies.opposing_face(space.topology, e, 1)
eo, _, _ = Topologies.opposing_face(Spaces.topology(space), e, 1)
if 0 < eo < e
continue
end
end
if i == Nq
# face 2
eo, _, _ = Topologies.opposing_face(space.topology, e, 2)
eo, _, _ = Topologies.opposing_face(Spaces.topology(space), e, 2)
if 0 < eo < e
continue
end
end
if j == Nq
# face 3
eo, _, _ = Topologies.opposing_face(space.topology, e, 3)
eo, _, _ = Topologies.opposing_face(Spaces.topology(space), e, 3)
if 0 < eo < e
continue
end
end
if i == 1
# face 4
eo, _, _ = Topologies.opposing_face(space.topology, e, 4)
eo, _, _ = Topologies.opposing_face(Spaces.topology(space), e, 4)
if 0 < eo < e
continue
end
Expand Down
12 changes: 8 additions & 4 deletions test/Spaces/ddss1.jl
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,14 @@ init_state_vector(local_geometry, p) = Geometry.Covariant12Vector(1.0, -1.0)

@test Topologies.nlocalelems(Spaces.topology(space)) == 4

@test Topologies.local_neighboring_elements(space.topology, 1) == [2, 4]
@test Topologies.local_neighboring_elements(space.topology, 2) == [1, 3]
@test Topologies.local_neighboring_elements(space.topology, 3) == [2, 4]
@test Topologies.local_neighboring_elements(space.topology, 4) == [1, 3]
@test Topologies.local_neighboring_elements(Spaces.topology(space), 1) ==
[2, 4]
@test Topologies.local_neighboring_elements(Spaces.topology(space), 2) ==
[1, 3]
@test Topologies.local_neighboring_elements(Spaces.topology(space), 3) ==
[2, 4]
@test Topologies.local_neighboring_elements(Spaces.topology(space), 4) ==
[1, 3]

y0 = init_state_scalar.(Fields.local_geometry_field(space), Ref(nothing))
nel = Topologies.nlocalelems(Spaces.topology(space))
Expand Down
12 changes: 8 additions & 4 deletions test/Spaces/distributed/ddss2.jl
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,15 @@ include("ddss_setup.jl")

@test Topologies.nlocalelems(Spaces.topology(space)) == 2

@test Topologies.local_neighboring_elements(space.topology, 1) == [2]
@test Topologies.local_neighboring_elements(space.topology, 2) == [1]
@test Topologies.local_neighboring_elements(Spaces.topology(space), 1) ==
[2]
@test Topologies.local_neighboring_elements(Spaces.topology(space), 2) ==
[1]

@test Topologies.ghost_neighboring_elements(space.topology, 1) == [2]
@test Topologies.ghost_neighboring_elements(space.topology, 2) == [1]
@test Topologies.ghost_neighboring_elements(Spaces.topology(space), 1) ==
[2]
@test Topologies.ghost_neighboring_elements(Spaces.topology(space), 2) ==
[1]

init_state(local_geometry, p) == 1.0)
y0 = init_state.(Fields.local_geometry_field(space), Ref(nothing))
Expand Down
31 changes: 20 additions & 11 deletions test/Spaces/distributed/ddss3.jl
Original file line number Diff line number Diff line change
Expand Up @@ -39,22 +39,31 @@ partition numbers
@test Topologies.nlocalelems(Spaces.topology(space)) == (pid == 1 ? 6 : 5)
if pid == 1
# gidx 1
@test Topologies.local_neighboring_elements(space.topology, 1) ==
[2, 5, 6]
@test Topologies.ghost_neighboring_elements(space.topology, 1) == []
@test Topologies.local_neighboring_elements(
Spaces.topology(space),
1,
) == [2, 5, 6]
@test Topologies.ghost_neighboring_elements(
Spaces.topology(space),
1,
) == []
# gidx 6
@test Topologies.local_neighboring_elements(space.topology, 6) ==
[1, 2, 3, 5]
@test space.topology.recv_elem_gidx[Topologies.ghost_neighboring_elements(
space.topology,
@test Topologies.local_neighboring_elements(
Spaces.topology(space),
6,
) == [1, 2, 3, 5]
@test Spaces.topology(space).recv_elem_gidx[Topologies.ghost_neighboring_elements(
Spaces.topology(space),
6,
)] == [7, 9, 10, 11]
elseif pid == 2
# gidx 7
@test Topologies.local_neighboring_elements(space.topology, 1) ==
[2, 4, 5]
@test space.topology.recv_elem_gidx[Topologies.ghost_neighboring_elements(
space.topology,
@test Topologies.local_neighboring_elements(
Spaces.topology(space),
1,
) == [2, 4, 5]
@test Spaces.topology(space).recv_elem_gidx[Topologies.ghost_neighboring_elements(
Spaces.topology(space),
1,
)] == [2, 3, 4, 6, 12]
end
Expand Down
Loading

0 comments on commit 1973dac

Please sign in to comment.