Skip to content

Commit

Permalink
Merge pull request #1821 from CliMA/ck/topo_device
Browse files Browse the repository at this point in the history
Remove `IntervalTopology(::Mesh)` method
  • Loading branch information
charleskawczynski committed Jun 18, 2024
2 parents 4136909 + 213e8da commit 3170a88
Show file tree
Hide file tree
Showing 65 changed files with 319 additions and 159 deletions.
5 changes: 5 additions & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,11 @@ ClimaCore.jl Release Notes
main
-------

v0.15.0
-------

- ![][badge-💥breaking] support for `IntervalTopology(::Mesh)` has been dropped in favor of using `IntervalTopology(::ClimaComms.AbstractDevice, ::Mesh)`. PR [#1821](https://github.com/CliMA/ClimaCore.jl/pull/1821).

v0.14.9
-------

Expand Down
7 changes: 4 additions & 3 deletions docs/tutorials/introduction.jl
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,9 @@ rectangle_mesh = ClimaCore.Meshes.RectilinearMesh(rectangle_domain, 16, 16)
#
# A _topology_ determines the ordering and connections between elements of a mesh
# - At the moment, this is only required for 2D meshes

device = ClimaComms.device()
rectangle_topology = ClimaCore.Topologies.Topology2D(
ClimaComms.SingletonCommsContext(),
ClimaComms.SingletonCommsContext(device),
rectangle_mesh,
)
#----------------------------------------------------------------------------
Expand All @@ -71,7 +71,8 @@ rectangle_topology = ClimaCore.Topologies.Topology2D(
#
# You can construct either the center or face space from the mesh, then construct the opposite space from the original one (this is to avoid allocating additional memory).

column_center_space = ClimaCore.Spaces.CenterFiniteDifferenceSpace(column_mesh)
column_center_space =
ClimaCore.Spaces.CenterFiniteDifferenceSpace(device, column_mesh)
## construct the face space from the center one
column_face_space =
ClimaCore.Spaces.FaceFiniteDifferenceSpace(column_center_space)
Expand Down
6 changes: 4 additions & 2 deletions examples/column/advect.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ClimaComms
ClimaComms.@import_required_backends
import ClimaCore:
Fields,
Domains,
Expand Down Expand Up @@ -26,8 +28,8 @@ domain = Domains.IntervalDomain(
boundary_names = (:left, :right),
)
mesh = Meshes.IntervalMesh(domain, nelems = n)

cs = Spaces.CenterFiniteDifferenceSpace(mesh)
device = ClimaComms.device()
cs = Spaces.CenterFiniteDifferenceSpace(device, mesh)
fs = Spaces.FaceFiniteDifferenceSpace(cs)

V = Geometry.WVector.(ones(FT, fs))
Expand Down
6 changes: 4 additions & 2 deletions examples/column/advect_diffusion.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ClimaComms
ClimaComms.@import_required_backends
import ClimaCore:
Fields,
Domains,
Expand Down Expand Up @@ -32,8 +34,8 @@ domain = Domains.IntervalDomain(
boundary_names = (:bottom, :top),
)
mesh = Meshes.IntervalMesh(domain, nelems = n)

cs = Spaces.CenterFiniteDifferenceSpace(mesh)
device = ClimaComms.device()
cs = Spaces.CenterFiniteDifferenceSpace(device, mesh)
fs = Spaces.FaceFiniteDifferenceSpace(cs)
zc = Fields.coordinate_field(cs)
zp = (z₀ + z₁ / n / 2):(z₁ / n):(z₁ - z₁ / n / 2)
Expand Down
6 changes: 4 additions & 2 deletions examples/column/bb_fct_advection.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ClimaComms
ClimaComms.@import_required_backends
using Test
using LinearAlgebra
using OrdinaryDiffEq: ODEProblem, solve
Expand Down Expand Up @@ -86,10 +88,10 @@ domain = Domains.IntervalDomain(

stretch_fns = (Meshes.Uniform(), Meshes.ExponentialStretching(FT(7.0)))
plot_string = ["uniform", "stretched"]

device = ClimaComms.device()
for (i, stretch_fn) in enumerate(stretch_fns)
mesh = Meshes.IntervalMesh(domain, stretch_fn; nelems = n)
cent_space = Spaces.CenterFiniteDifferenceSpace(mesh)
cent_space = Spaces.CenterFiniteDifferenceSpace(device, mesh)
face_space = Spaces.FaceFiniteDifferenceSpace(cent_space)
z = Fields.coordinate_field(cent_space).z
O = ones(FT, face_space)
Expand Down
6 changes: 4 additions & 2 deletions examples/column/ekman.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ClimaComms
ClimaComms.@import_required_backends
using LinearAlgebra
import ClimaCore:
Fields,
Expand Down Expand Up @@ -41,8 +43,8 @@ domain = Domains.IntervalDomain(
)
#mesh = Meshes.IntervalMesh(domain, Meshes.ExponentialStretching(7.5e3); nelems = 30)
mesh = Meshes.IntervalMesh(domain; nelems = nelems)

cspace = Spaces.CenterFiniteDifferenceSpace(mesh)
device = ClimaComms.device()
cspace = Spaces.CenterFiniteDifferenceSpace(device, mesh)
fspace = Spaces.FaceFiniteDifferenceSpace(cspace)


Expand Down
6 changes: 4 additions & 2 deletions examples/column/fct_advection.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ClimaComms
ClimaComms.@import_required_backends
using Test
using LinearAlgebra
using OrdinaryDiffEq: ODEProblem, solve, SSPRK33
Expand Down Expand Up @@ -87,11 +89,11 @@ initial_mass = zeros(FT, length(stretch_fns))
mass = zeros(FT, length(stretch_fns))
rel_mass_err = zeros(FT, length(stretch_fns))
plot_string = ["uniform", "stretched"]

device = ClimaComms.device()
for (i, stretch_fn) in enumerate(stretch_fns)

mesh = Meshes.IntervalMesh(domain, stretch_fn; nelems = n)
cs = Spaces.CenterFiniteDifferenceSpace(mesh)
cs = Spaces.CenterFiniteDifferenceSpace(device, mesh)
fs = Spaces.FaceFiniteDifferenceSpace(cs)
zc = Fields.coordinate_field(cs)
O = ones(FT, fs)
Expand Down
6 changes: 4 additions & 2 deletions examples/column/heat.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ClimaComms
ClimaComms.@import_required_backends
import ClimaCore:
Fields,
Domains,
Expand Down Expand Up @@ -28,8 +30,8 @@ domain = Domains.IntervalDomain(
boundary_names = (:bottom, :top),
)
mesh = Meshes.IntervalMesh(domain, nelems = n)

cs = Spaces.CenterFiniteDifferenceSpace(mesh)
device = ClimaComms.device()
cs = Spaces.CenterFiniteDifferenceSpace(device, mesh)
T = Fields.zeros(FT, cs)

# Solve Heat Equation: ∂_t T = α ∇²T
Expand Down
6 changes: 4 additions & 2 deletions examples/column/hydrostatic.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ClimaComms
ClimaComms.@import_required_backends
import ClimaCore:
Fields,
Domains,
Expand Down Expand Up @@ -32,8 +34,8 @@ domain = Domains.IntervalDomain(
)
#mesh = Meshes.IntervalMesh(domain, Meshes.ExponentialStretching(7.5e3); nelems = 30)
mesh = Meshes.IntervalMesh(domain; nelems = 30)

cspace = Spaces.CenterFiniteDifferenceSpace(mesh)
device = ClimaComms.device()
cspace = Spaces.CenterFiniteDifferenceSpace(device, mesh)
fspace = Spaces.FaceFiniteDifferenceSpace(cspace)

# https://github.com/CliMA/Thermodynamics.jl/blob/main/src/TemperatureProfiles.jl#L115-L155
Expand Down
6 changes: 4 additions & 2 deletions examples/column/hydrostatic_discrete.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ClimaComms
ClimaComms.@import_required_backends
import ClimaCore:
Fields,
Domains,
Expand Down Expand Up @@ -34,8 +36,8 @@ domain = Domains.IntervalDomain(
)
#mesh = Meshes.IntervalMesh(domain, Meshes.ExponentialStretching(7.5e3); nelems = 30)
mesh = Meshes.IntervalMesh(domain; nelems = n_vert)

cspace = Spaces.CenterFiniteDifferenceSpace(mesh)
device = ClimaComms.device()
cspace = Spaces.CenterFiniteDifferenceSpace(device, mesh)
fspace = Spaces.FaceFiniteDifferenceSpace(cspace)

# https://github.com/CliMA/Thermodynamics.jl/blob/main/src/TemperatureProfiles.jl#L115-L155
Expand Down
6 changes: 4 additions & 2 deletions examples/column/hydrostatic_ekman.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ClimaComms
ClimaComms.@import_required_backends
using LinearAlgebra

import ClimaCore:
Expand Down Expand Up @@ -45,8 +47,8 @@ domain = Domains.IntervalDomain(
)
#mesh = Meshes.IntervalMesh(domain, Meshes.ExponentialStretching(7.5e3); nelems = 30)
mesh = Meshes.IntervalMesh(domain; nelems = nelems)

cspace = Spaces.CenterFiniteDifferenceSpace(mesh)
device = ClimaComms.device()
cspace = Spaces.CenterFiniteDifferenceSpace(device, mesh)
fspace = Spaces.FaceFiniteDifferenceSpace(cspace)


Expand Down
6 changes: 4 additions & 2 deletions examples/column/step.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ClimaComms
ClimaComms.@import_required_backends
using LinearAlgebra
import ClimaCore:
Fields,
Expand Down Expand Up @@ -28,8 +30,8 @@ end

domain = Domains.IntervalDomain(a, b, boundary_names = (:left, :right))
mesh = Meshes.IntervalMesh(domain, nelems = n)

cs = Spaces.CenterFiniteDifferenceSpace(mesh)
device = ClimaComms.device()
cs = Spaces.CenterFiniteDifferenceSpace(device, mesh)
fs = Spaces.FaceFiniteDifferenceSpace(cs)

V = Geometry.WVector.(ones(FT, fs))
Expand Down
6 changes: 4 additions & 2 deletions examples/column/wave.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ClimaComms
ClimaComms.@import_required_backends
import ClimaCore.Geometry, LinearAlgebra
import ClimaCore:
Fields,
Expand All @@ -22,8 +24,8 @@ domain = Domains.IntervalDomain(
boundary_names = (:left, :right),
)
mesh = Meshes.IntervalMesh(domain; nelems = 30)

cspace = Spaces.CenterFiniteDifferenceSpace(mesh)
device = ClimaComms.device()
cspace = Spaces.CenterFiniteDifferenceSpace(device, mesh)
fspace = Spaces.FaceFiniteDifferenceSpace(cspace)

zc = Fields.coordinate_field(cspace)
Expand Down
6 changes: 4 additions & 2 deletions examples/column/zalesak_fct_advection.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import ClimaComms
ClimaComms.@import_required_backends
using Test
using LinearAlgebra
using OrdinaryDiffEq: ODEProblem, solve
Expand Down Expand Up @@ -87,10 +89,10 @@ domain = Domains.IntervalDomain(

stretch_fns = (Meshes.Uniform(), Meshes.ExponentialStretching(FT(7.0)))
plot_string = ["uniform", "stretched"]

device = ClimaComms.device()
for (i, stretch_fn) in enumerate(stretch_fns)
mesh = Meshes.IntervalMesh(domain, stretch_fn; nelems = n)
cent_space = Spaces.CenterFiniteDifferenceSpace(mesh)
cent_space = Spaces.CenterFiniteDifferenceSpace(device, mesh)
face_space = Spaces.FaceFiniteDifferenceSpace(cent_space)
z = Fields.coordinate_field(cent_space).z
O = ones(FT, face_space)
Expand Down
5 changes: 3 additions & 2 deletions examples/common_spaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ function make_horizontal_space(
)
quad = Quadratures.GLL{npoly + 1}()
if mesh isa Meshes.AbstractMesh1D
topology = Topologies.IntervalTopology(mesh)
topology = Topologies.IntervalTopology(ClimaComms.device(context), mesh)
space = Spaces.SpectralElementSpace1D(topology, quad)
elseif mesh isa Meshes.AbstractMesh2D
topology = Topologies.Topology2D(context, mesh)
Expand Down Expand Up @@ -68,8 +68,9 @@ function make_hybrid_spaces(h_space, z_max, z_elem; z_stretch)
Geometry.ZPoint(z_max);
boundary_names = (:bottom, :top),
)
context = ClimaComms.context(h_space)
z_mesh = Meshes.IntervalMesh(z_domain, z_stretch; nelems = z_elem)
z_topology = Topologies.IntervalTopology(z_mesh)
z_topology = Topologies.IntervalTopology(ClimaComms.device(context), z_mesh)
z_space = Spaces.CenterFiniteDifferenceSpace(z_topology)
center_space = Spaces.ExtrudedFiniteDifferenceSpace(h_space, z_space)
face_space = Spaces.FaceExtrudedFiniteDifferenceSpace(center_space)
Expand Down
6 changes: 5 additions & 1 deletion examples/hybrid/box/bubble_3d_invariant_rhotheta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ using Test
using ClimaComms
using LinearAlgebra

import ClimaComms
ClimaComms.@import_required_backends

import ClimaCore:
ClimaCore,
slab,
Expand Down Expand Up @@ -47,14 +50,15 @@ function hvspace_3D(
horzmesh = Meshes.RectilinearMesh(horzdomain, xelem, yelem)
horztopology = Topologies.Topology2D(context, horzmesh)
#horztopology = Topologies.Topology2D(horzmesh)
device = ClimaComms.device(context)

zdomain = Domains.IntervalDomain(
Geometry.ZPoint{FT}(zlim[1]),
Geometry.ZPoint{FT}(zlim[2]);
boundary_names = (:bottom, :top),
)
vertmesh = Meshes.IntervalMesh(zdomain, nelems = zelem)
vert_center_space = Spaces.CenterFiniteDifferenceSpace(vertmesh)
vert_center_space = Spaces.CenterFiniteDifferenceSpace(device, vertmesh)

quad = Quadratures.GLL{npoly + 1}()
horzspace = Spaces.SpectralElementSpace2D(horztopology, quad)
Expand Down
6 changes: 5 additions & 1 deletion examples/hybrid/box/bubble_3d_rhotheta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ using Test
using ClimaComms
using LinearAlgebra, StaticArrays

import ClimaComms
ClimaComms.@import_required_backends

import ClimaCore:
ClimaCore,
slab,
Expand Down Expand Up @@ -42,6 +45,7 @@ function hvspace_3D(
Geometry.YPoint{FT}(ylim[2]),
periodic = true,
)
device = ClimaComms.device(context)

horzdomain = Domains.RectangleDomain(xdomain, ydomain)
horzmesh = Meshes.RectilinearMesh(horzdomain, xelem, yelem)
Expand All @@ -53,7 +57,7 @@ function hvspace_3D(
boundary_names = (:bottom, :top),
)
vertmesh = Meshes.IntervalMesh(zdomain, nelems = zelem)
vert_center_space = Spaces.CenterFiniteDifferenceSpace(vertmesh)
vert_center_space = Spaces.CenterFiniteDifferenceSpace(device, vertmesh)

quad = Quadratures.GLL{npoly + 1}()
horzspace = Spaces.SpectralElementSpace2D(horztopology, quad)
Expand Down
3 changes: 3 additions & 0 deletions examples/hybrid/hybrid3dcs_dss.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ using JLD2

include("../nvtx.jl")

import ClimaComms
ClimaComms.@import_required_backends

import ClimaCore:
Domains,
Fields,
Expand Down
9 changes: 7 additions & 2 deletions examples/hybrid/plane/bubble_2d_invariant_rhoe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@ push!(LOAD_PATH, joinpath(@__DIR__, "..", ".."))
using Test
using StaticArrays, IntervalSets, LinearAlgebra

import ClimaComms
ClimaComms.@import_required_backends

import ClimaCore:
ClimaCore,
slab,
Expand Down Expand Up @@ -35,15 +38,17 @@ function hvspace_2D(
boundary_names = (:bottom, :top),
)
vertmesh = Meshes.IntervalMesh(vertdomain, nelems = zelem)
vert_center_space = Spaces.CenterFiniteDifferenceSpace(vertmesh)
context = ClimaComms.context()
device = ClimaComms.device(context)
vert_center_space = Spaces.CenterFiniteDifferenceSpace(device, vertmesh)

horzdomain = Domains.IntervalDomain(
Geometry.XPoint{FT}(xlim[1]),
Geometry.XPoint{FT}(xlim[2]);
periodic = true,
)
horzmesh = Meshes.IntervalMesh(horzdomain, nelems = xelem)
horztopology = Topologies.IntervalTopology(horzmesh)
horztopology = Topologies.IntervalTopology(device, horzmesh)

quad = Quadratures.GLL{npoly + 1}()
horzspace = Spaces.SpectralElementSpace1D(horztopology, quad)
Expand Down
9 changes: 7 additions & 2 deletions examples/hybrid/plane/density_current_2d_flux_form.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
using Test
using LinearAlgebra, StaticArrays

import ClimaComms
ClimaComms.@import_required_backends

import ClimaCore:
ClimaCore,
slab,
Expand Down Expand Up @@ -33,15 +36,17 @@ function hvspace_2D(
boundary_names = (:bottom, :top),
)
vertmesh = Meshes.IntervalMesh(vertdomain, nelems = velem)
vert_center_space = Spaces.CenterFiniteDifferenceSpace(vertmesh)
context = ClimaComms.context()
device = ClimaComms.device(context)
vert_center_space = Spaces.CenterFiniteDifferenceSpace(device, vertmesh)

horzdomain = Domains.IntervalDomain(
Geometry.XPoint{FT}(xlim[1]),
Geometry.XPoint{FT}(xlim[2]),
periodic = true,
)
horzmesh = Meshes.IntervalMesh(horzdomain; nelems = helem)
horztopology = Topologies.IntervalTopology(horzmesh)
horztopology = Topologies.IntervalTopology(device, horzmesh)

quad = Quadratures.GLL{npoly + 1}()
horzspace = Spaces.SpectralElementSpace1D(horztopology, quad)
Expand Down
Loading

0 comments on commit 3170a88

Please sign in to comment.