Skip to content

Commit

Permalink
Remove IntervalTopology(::Mesh) method
Browse files Browse the repository at this point in the history
  • Loading branch information
charleskawczynski committed Jun 17, 2024
1 parent 6d03f1d commit 775f2b5
Show file tree
Hide file tree
Showing 50 changed files with 198 additions and 121 deletions.
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
4 changes: 2 additions & 2 deletions examples/column/advect.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,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
4 changes: 2 additions & 2 deletions examples/column/advect_diffusion.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,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
4 changes: 2 additions & 2 deletions examples/column/bb_fct_advection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -86,10 +86,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
4 changes: 2 additions & 2 deletions examples/column/ekman.jl
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,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
4 changes: 2 additions & 2 deletions examples/column/fct_advection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,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
4 changes: 2 additions & 2 deletions examples/column/heat.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,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
4 changes: 2 additions & 2 deletions examples/column/hydrostatic.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,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
4 changes: 2 additions & 2 deletions examples/column/hydrostatic_discrete.jl
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,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
4 changes: 2 additions & 2 deletions examples/column/hydrostatic_ekman.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,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
4 changes: 2 additions & 2 deletions examples/column/step.jl
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,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
4 changes: 2 additions & 2 deletions examples/column/wave.jl
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,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
4 changes: 2 additions & 2 deletions examples/column/zalesak_fct_advection.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,10 +87,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
3 changes: 2 additions & 1 deletion examples/hybrid/box/bubble_3d_invariant_rhotheta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,14 +47,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
3 changes: 2 additions & 1 deletion examples/hybrid/box/bubble_3d_rhotheta.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,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 +54,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
6 changes: 4 additions & 2 deletions examples/hybrid/plane/bubble_2d_invariant_rhoe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -35,15 +35,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
6 changes: 4 additions & 2 deletions examples/hybrid/plane/density_current_2d_flux_form.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,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
4 changes: 3 additions & 1 deletion examples/hybrid/plane/density_current_2dinvariant_rhoe.jl
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@ function hvspace_2D(
periodic = true,
)
horzmesh = Meshes.IntervalMesh(horzdomain, nelems = xelem)
horztopology = Topologies.IntervalTopology(horzmesh)
context = ClimaComms.context()
device = ClimaComms.device(context)
horztopology = Topologies.IntervalTopology(device, horzmesh)

quad = Quadratures.GLL{npoly + 1}()
horzspace = Spaces.SpectralElementSpace1D(horztopology, quad)
Expand Down
4 changes: 3 additions & 1 deletion examples/hybrid/plane/isothermal_channel.jl
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,9 @@ function hvspace_2D(
periodic = true,
)
horzmesh = Meshes.IntervalMesh(horzdomain, nelems = xelem)
horztopology = Topologies.IntervalTopology(horzmesh)
context = ClimaComms.context()
device = ClimaComms.device(context)
horztopology = Topologies.IntervalTopology(device, horzmesh)
quad = Quadratures.GLL{npoly + 1}()
horzspace = Spaces.SpectralElementSpace1D(horztopology, quad)
z_surface = Geometry.ZPoint.(warp_fn.(Fields.coordinate_field(horzspace)))
Expand Down
4 changes: 3 additions & 1 deletion examples/hybrid/plane/topo_agnesi_nh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,9 @@ function hvspace_2D(
periodic = true,
)
horzmesh = Meshes.IntervalMesh(horzdomain, nelems = xelem)
horztopology = Topologies.IntervalTopology(horzmesh)
context = ClimaComms.context()
device = ClimaComms.device(context)
horztopology = Topologies.IntervalTopology(device, horzmesh)
quad = Quadratures.GLL{npoly + 1}()
horzspace = Spaces.SpectralElementSpace1D(horztopology, quad)

Expand Down
4 changes: 3 additions & 1 deletion examples/hybrid/plane/topo_schar_nh.jl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,9 @@ function hvspace_2D(
periodic = true,
)
horzmesh = Meshes.IntervalMesh(horzdomain, nelems = xelem)
horztopology = Topologies.IntervalTopology(horzmesh)
context = ClimaComms.context()
device = ClimaComms.device(context)
horztopology = Topologies.IntervalTopology(device, horzmesh)
quad = Quadratures.GLL{npoly + 1}()
horzspace = Spaces.SpectralElementSpace1D(horztopology, quad)

Expand Down
2 changes: 1 addition & 1 deletion lib/ClimaCoreMakie/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ end
periodic = true,
)
mesh = Meshes.IntervalMesh(domain, nelems = 32)
topology = Topologies.IntervalTopology(mesh)
topology = Topologies.IntervalTopology(ClimaComms.device(context), mesh)
quad = Quadratures.GLL{5}()
horz_space = Spaces.SpectralElementSpace1D(topology, quad)
horz_coords = Fields.coordinate_field(horz_space)
Expand Down
6 changes: 5 additions & 1 deletion lib/ClimaCorePlots/src/ClimaCorePlots.jl
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,11 @@ function _slice_along(field, coord)
end

# construct the slice field space
htopo_ortho = ClimaCore.Topologies.IntervalTopology(hmesh_ortho)
context = ClimaComms.context(field)
htopo_ortho = ClimaCore.Topologies.IntervalTopology(
ClimaComms.device(context),
hmesh_ortho,
)
hspace_ortho = ClimaCore.Spaces.SpectralElementSpace1D(
htopo_ortho,
ClimaCore.Spaces.quadrature_style(hspace),
Expand Down
12 changes: 8 additions & 4 deletions lib/ClimaCorePlots/test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ OUTPUT_DIR = mkpath(get(ENV, "CI_OUTPUT_DIR", tempname()))
boundary_names = (:left, :right),
)
mesh = ClimaCore.Meshes.IntervalMesh(domain; nelems = 5)
grid_topology = ClimaCore.Topologies.IntervalTopology(mesh)
context = ClimaComms.context()
grid_topology =
ClimaCore.Topologies.IntervalTopology(ClimaComms.device(context), mesh)
quad = ClimaCore.Quadratures.GLL{5}()
space = ClimaCore.Spaces.SpectralElementSpace1D(grid_topology, quad)
coords = ClimaCore.Fields.coordinate_field(space)
Expand Down Expand Up @@ -199,16 +201,18 @@ end
ClimaCore.Geometry.ZPoint{FT}(1000);
boundary_names = (:bottom, :top),
)
vertmesh = ClimaCore.Meshes.IntervalMesh(vertdomain, nelems = velem)
context = ClimaComms.context()
device = ClimaComms.device(context)
vertmesh = ClimaCore.Meshes.IntervalMesh(device, vertdomain, nelems = velem)
vert_center_space = ClimaCore.Spaces.CenterFiniteDifferenceSpace(vertmesh)

horzdomain = ClimaCore.Domains.IntervalDomain(
ClimaCore.Geometry.XPoint{FT}(-500) ..
ClimaCore.Geometry.XPoint{FT}(500),
periodic = true,
)
horzmesh = ClimaCore.Meshes.IntervalMesh(horzdomain; nelems = helem)
horztopology = ClimaCore.Topologies.IntervalTopology(horzmesh)
horzmesh = ClimaCore.Meshes.IntervalMesh(device, horzdomain; nelems = helem)
horztopology = ClimaCore.Topologies.IntervalTopology(device, horzmesh)

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

0 comments on commit 775f2b5

Please sign in to comment.