diff --git a/examples/hybrid/hybrid3dcs_dss.jl b/examples/hybrid/hybrid3dcs_dss.jl index 7cf1605444..ecffa77ada 100644 --- a/examples/hybrid/hybrid3dcs_dss.jl +++ b/examples/hybrid/hybrid3dcs_dss.jl @@ -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!( diff --git a/examples/hybrid/sphere/hadley_circulation.jl b/examples/hybrid/sphere/hadley_circulation.jl index 441bcb326c..2b1db316e9 100644 --- a/examples/hybrid/sphere/hadley_circulation.jl +++ b/examples/hybrid/sphere/hadley_circulation.jl @@ -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 diff --git a/examples/hybrid/sphere/remap_pipeline.jl b/examples/hybrid/sphere/remap_pipeline.jl index d08db291cb..1fffecc833 100644 --- a/examples/hybrid/sphere/remap_pipeline.jl +++ b/examples/hybrid/sphere/remap_pipeline.jl @@ -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) diff --git a/examples/sphere/limiters_advection.jl b/examples/sphere/limiters_advection.jl index db0e5bb23b..49e7e0ea98 100644 --- a/examples/sphere/limiters_advection.jl +++ b/examples/sphere/limiters_advection.jl @@ -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) diff --git a/examples/sphere/shallow_water_cuda.jl b/examples/sphere/shallow_water_cuda.jl index 329e1782cb..407402e6d7 100644 --- a/examples/sphere/shallow_water_cuda.jl +++ b/examples/sphere/shallow_water_cuda.jl @@ -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 @@ -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 diff --git a/lib/ClimaCorePlots/src/ClimaCorePlots.jl b/lib/ClimaCorePlots/src/ClimaCorePlots.jl index 226f218548..5181862303 100644 --- a/lib/ClimaCorePlots/src/ClimaCorePlots.jl +++ b/lib/ClimaCorePlots/src/ClimaCorePlots.jl @@ -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 @@ -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) @@ -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)) diff --git a/lib/ClimaCoreTempestRemap/src/netcdf.jl b/lib/ClimaCoreTempestRemap/src/netcdf.jl index 13c07d87ef..c6c514aa19 100644 --- a/lib/ClimaCoreTempestRemap/src/netcdf.jl +++ b/lib/ClimaCoreTempestRemap/src/netcdf.jl @@ -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 @@ -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" diff --git a/lib/ClimaCoreTempestRemap/src/onlineremap.jl b/lib/ClimaCoreTempestRemap/src/onlineremap.jl index 9ea2cb988e..14cb831b00 100644 --- a/lib/ClimaCoreTempestRemap/src/onlineremap.jl +++ b/lib/ClimaCoreTempestRemap/src/onlineremap.jl @@ -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 @@ -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 diff --git a/lib/ClimaCoreTempestRemap/test/online_remap.jl b/lib/ClimaCoreTempestRemap/test/online_remap.jl index 3d6233378c..d1aa95303d 100644 --- a/lib/ClimaCoreTempestRemap/test/online_remap.jl +++ b/lib/ClimaCoreTempestRemap/test/online_remap.jl @@ -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 diff --git a/src/Fields/indices.jl b/src/Fields/indices.jl index 3491a99962..89cac213b7 100644 --- a/src/Fields/indices.jl +++ b/src/Fields/indices.jl @@ -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)) diff --git a/src/Grids/Grids.jl b/src/Grids/Grids.jl index 915cdcdacf..7d594d0d8d 100644 --- a/src/Grids/Grids.jl +++ b/src/Grids/Grids.jl @@ -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") diff --git a/src/InputOutput/writers.jl b/src/InputOutput/writers.jl index 3a3645ba16..7b19b1e30e 100644 --- a/src/InputOutput/writers.jl +++ b/src/InputOutput/writers.jl @@ -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 @@ -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 @@ -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 diff --git a/src/Operators/numericalflux.jl b/src/Operators/numericalflux.jl index 4137e03122..d767c4cedc 100644 --- a/src/Operators/numericalflux.jl +++ b/src/Operators/numericalflux.jl @@ -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)) @@ -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)) diff --git a/src/Spaces/extruded.jl b/src/Spaces/extruded.jl index 68eba562a6..3892989ca4 100644 --- a/src/Spaces/extruded.jl +++ b/src/Spaces/extruded.jl @@ -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)) @@ -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) diff --git a/src/Spaces/finitedifference.jl b/src/Spaces/finitedifference.jl index e3e21c5fb8..9b18b1ae3d 100644 --- a/src/Spaces/finitedifference.jl +++ b/src/Spaces/finitedifference.jl @@ -1,7 +1,12 @@ abstract type AbstractFiniteDifferenceSpace <: AbstractSpace end """ - FiniteDifferenceSpace(staggering::Staggering, grid::Grids.FiniteDifferenceGrid) + FiniteDifferenceSpace( + grid::Grids.FiniteDifferenceGrid, + staggering::Staggering, + ) + + """ struct FiniteDifferenceSpace{ @@ -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} diff --git a/src/Spaces/spectralelement.jl b/src/Spaces/spectralelement.jl index fb23dabee1..817b52f9b1 100644 --- a/src/Spaces/spectralelement.jl +++ b/src/Spaces/spectralelement.jl @@ -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 diff --git a/test/Spaces/ddss1.jl b/test/Spaces/ddss1.jl index 908fe35d3e..05b63e678d 100644 --- a/test/Spaces/ddss1.jl +++ b/test/Spaces/ddss1.jl @@ -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)) diff --git a/test/Spaces/distributed/ddss2.jl b/test/Spaces/distributed/ddss2.jl index f2ce3d7dbe..594b7c5f5a 100644 --- a/test/Spaces/distributed/ddss2.jl +++ b/test/Spaces/distributed/ddss2.jl @@ -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)) diff --git a/test/Spaces/distributed/ddss3.jl b/test/Spaces/distributed/ddss3.jl index acdbf994b9..9981a03ab6 100644 --- a/test/Spaces/distributed/ddss3.jl +++ b/test/Spaces/distributed/ddss3.jl @@ -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 diff --git a/test/Spaces/distributed_cuda/ddss2.jl b/test/Spaces/distributed_cuda/ddss2.jl index 8b26bad751..c7e5748c10 100644 --- a/test/Spaces/distributed_cuda/ddss2.jl +++ b/test/Spaces/distributed_cuda/ddss2.jl @@ -59,11 +59,15 @@ pid, nprocs = ClimaComms.init(context) @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)) diff --git a/test/Spaces/distributed_cuda/ddss3.jl b/test/Spaces/distributed_cuda/ddss3.jl index fcf39a16f1..1bca8d268b 100644 --- a/test/Spaces/distributed_cuda/ddss3.jl +++ b/test/Spaces/distributed_cuda/ddss3.jl @@ -80,22 +80,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