Skip to content

Commit

Permalink
Merge pull request #1783 from CliMA/js/cctr-spacefilling
Browse files Browse the repository at this point in the history
add CCTR spacefillingcurve tests
  • Loading branch information
juliasloan25 authored Jun 6, 2024
2 parents e7ee513 + 9d8a23f commit a57c937
Show file tree
Hide file tree
Showing 2 changed files with 118 additions and 26 deletions.
101 changes: 86 additions & 15 deletions lib/ClimaCoreTempestRemap/test/netcdf.jl
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,28 @@ using ClimaCoreTempestRemap

OUTPUT_DIR = mkpath(get(ENV, "CI_OUTPUT_DIR", tempname()))

@testset "write remap sphere data $node_type" for node_type in ["cgll", "dgll"]
@testset "write remap sphere data $node_type; use spacefillingcurve $use_spacefillingcurve" for node_type in
[
"cgll",
"dgll",
],
use_spacefillingcurve in [true, false]
# generate CC mesh
ne = 4
R = 5.0
Nq = 5
domain = Domains.SphereDomain(R)
mesh = Meshes.EquiangularCubedSphere(domain, ne)
topology = Topologies.Topology2D(ClimaComms.SingletonCommsContext(), mesh)
if use_spacefillingcurve
topology = Topologies.Topology2D(
ClimaComms.SingletonCommsContext(),
mesh,
Topologies.spacefillingcurve(mesh),
)
else
topology =
Topologies.Topology2D(ClimaComms.SingletonCommsContext(), mesh)
end
quad = Quadratures.GLL{Nq}()
space = Spaces.SpectralElementSpace2D(topology, quad)
coords = Fields.coordinate_field(space)
Expand All @@ -49,6 +63,7 @@ OUTPUT_DIR = mkpath(get(ENV, "CI_OUTPUT_DIR", tempname()))
nothing
end

# construct regular latitude-longitude (RLL) mesh
nlat = 90
nlon = 180
meshfile_rll = joinpath(OUTPUT_DIR, "mesh_rll.g")
Expand All @@ -67,6 +82,7 @@ OUTPUT_DIR = mkpath(get(ENV, "CI_OUTPUT_DIR", tempname()))
in_np = Nq,
)

# remap to RLL (lat-lon)
datafile_rll = joinpath(OUTPUT_DIR, "data_rll.nc")
apply_remap(datafile_rll, datafile_cc, weightfile, ["xlat", "sinlong"])

Expand All @@ -82,16 +98,29 @@ OUTPUT_DIR = mkpath(get(ENV, "CI_OUTPUT_DIR", tempname()))
end
end

@testset "write remap 3d sphere data $node_type" for node_type in
["cgll", "dgll"]
@testset "write remap 3d sphere data $node_type; use spacefillingcurve $use_spacefillingcurve" for node_type in
[
"cgll",
"dgll",
],
use_spacefillingcurve in [true, false]
# generate CC mesh
ne = 4
R = 1000.0
nlevels = 10
Nq = 5
hdomain = Domains.SphereDomain(R)
hmesh = Meshes.EquiangularCubedSphere(hdomain, ne)
htopology = Topologies.Topology2D(ClimaComms.SingletonCommsContext(), hmesh)
if use_spacefillingcurve
htopology = Topologies.Topology2D(
ClimaComms.SingletonCommsContext(),
hmesh,
Topologies.spacefillingcurve(hmesh),
)
else
htopology =
Topologies.Topology2D(ClimaComms.SingletonCommsContext(), hmesh)
end
quad = Quadratures.GLL{Nq}()
hspace = Spaces.SpectralElementSpace2D(htopology, quad)

Expand Down Expand Up @@ -126,6 +155,7 @@ end
nothing
end

# construct regular latitude-longitude (RLL) mesh
nlat = 90
nlon = 180
meshfile_rll = joinpath(OUTPUT_DIR, "mesh_rll.g")
Expand All @@ -144,6 +174,7 @@ end
in_np = Nq,
)

# remap to RLL (lat-lon)
datafile_rll = joinpath(OUTPUT_DIR, "data_rll_3d.nc")
apply_remap(datafile_rll, datafile_cc, weightfile, ["xlat", "xz"])

Expand All @@ -162,19 +193,29 @@ end
end
end

@testset "write remap 3d sphere data $node_type to rll and back with Nq = $Nq" for node_type in
[
@testset "write remap 3d sphere data $node_type to rll and back with Nq = $Nq; use spacefillingcurve $use_spacefillingcurve" for node_type in
[
"cgll",
"dgll",
],
Nq in [4, 5]
Nq in [4, 5],
use_spacefillingcurve in [true, false]
# generate CC mesh
ne = 4
R = 1000.0
nlevels = 10
hdomain = Domains.SphereDomain(R)
hmesh = Meshes.EquiangularCubedSphere(hdomain, ne)
htopology = Topologies.Topology2D(ClimaComms.SingletonCommsContext(), hmesh)
if use_spacefillingcurve
htopology = Topologies.Topology2D(
ClimaComms.SingletonCommsContext(),
hmesh,
Topologies.spacefillingcurve(hmesh),
)
else
htopology =
Topologies.Topology2D(ClimaComms.SingletonCommsContext(), hmesh)
end
quad = Quadratures.GLL{Nq}()
hspace = Spaces.SpectralElementSpace2D(htopology, quad)

Expand Down Expand Up @@ -209,6 +250,7 @@ end
nothing
end

# construct regular latitude-longitude (RLL) mesh
nlat = 90
nlon = 180
meshfile_rll = joinpath(OUTPUT_DIR, "mesh_rll.g")
Expand All @@ -228,6 +270,7 @@ end
mono = true,
)

# remap to RLL (lat-lon)
datafile_rll = joinpath(OUTPUT_DIR, "data_rll_3d.nc")
apply_remap(datafile_rll, datafile_cc, weightfile, ["xlat", "xz"])

Expand Down Expand Up @@ -300,16 +343,29 @@ function test_warp(coords)
return zₛ
end

@testset "write remap warped 3d sphere data $node_type" for node_type in
["cgll", "dgll"]
@testset "write remap warped 3d sphere data $node_type; use spacefillingcurve $use_spacefillingcurve" for node_type in
[
"cgll",
"dgll",
],
use_spacefillingcurve in [true, false]
# generate CC mesh
ne = 4
R = 1000.0
nlevels = 10
Nq = 5
hdomain = Domains.SphereDomain(R)
hmesh = Meshes.EquiangularCubedSphere(hdomain, ne)
htopology = Topologies.Topology2D(ClimaComms.SingletonCommsContext(), hmesh)
if use_spacefillingcurve
htopology = Topologies.Topology2D(
ClimaComms.SingletonCommsContext(),
hmesh,
Topologies.spacefillingcurve(hmesh),
)
else
htopology =
Topologies.Topology2D(ClimaComms.SingletonCommsContext(), hmesh)
end
quad = Quadratures.GLL{Nq}()
hspace = Spaces.SpectralElementSpace2D(htopology, quad)

Expand Down Expand Up @@ -348,6 +404,7 @@ end
nothing
end

# construct regular latitude-longitude (RLL) mesh
nlat = 90
nlon = 180
meshfile_rll = joinpath(OUTPUT_DIR, "mesh_rll.g")
Expand All @@ -366,6 +423,7 @@ end
in_np = Nq,
)

# remap to RLL (lat-lon)
datafile_rll = joinpath(OUTPUT_DIR, "data_rll_3d.nc")
apply_remap(
datafile_rll,
Expand Down Expand Up @@ -394,8 +452,12 @@ end
end
end

@testset "write nc data for column with $node_type" for node_type in
["cgll", "dgll"]
@testset "write nc data for column with $node_type; use spacefillingcurve $use_spacefillingcurve" for node_type in
[
"cgll",
"dgll",
],
use_spacefillingcurve in [true, false]

node_type = "cgll"
FT = Float64
Expand All @@ -419,7 +481,16 @@ end
hmesh = Meshes.RectilinearMesh(domain, x_elem, y_elem)

quad = Quadratures.GL{1}()
htopology = Topologies.Topology2D(ClimaComms.SingletonCommsContext(), hmesh)
if use_spacefillingcurve
htopology = Topologies.Topology2D(
ClimaComms.SingletonCommsContext(),
hmesh,
Topologies.spacefillingcurve(hmesh),
)
else
htopology =
Topologies.Topology2D(ClimaComms.SingletonCommsContext(), hmesh)
end
hspace = Spaces.SpectralElementSpace2D(htopology, quad)

vdomain = Domains.IntervalDomain(
Expand Down
43 changes: 32 additions & 11 deletions lib/ClimaCoreTempestRemap/test/online_remap.jl
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,12 @@ function reshape_sparse_to_field!(field::Fields.Field, in_array::Array, R)
end


@testset "online remap 2D sphere data" begin
@testset "online remap 2D sphere data; source spacefillingcurve $spacefillingcurve_i; target spacefillingcurve $spacefillingcurve_o" for spacefillingcurve_i in
[
true,
false,
],
spacefillingcurve_o in [true, false]

# domain
R = 1.0 # unit sphere
Expand All @@ -54,21 +59,37 @@ end
ne_o = 5
nq_o = 3

# construct source mesh
# construct source mesh and space, using `spacefillingcurve`` if requested
mesh_i = ClimaCore.Meshes.EquiangularCubedSphere(domain, ne_i)
topology_i = ClimaCore.Topologies.Topology2D(
ClimaComms.SingletonCommsContext(),
mesh_i,
)
if spacefillingcurve_i
topology_i = ClimaCore.Topologies.Topology2D(
ClimaComms.SingletonCommsContext(),
mesh_i,
ClimaCore.Topologies.spacefillingcurve(mesh_i),
)
else
topology_i = ClimaCore.Topologies.Topology2D(
ClimaComms.SingletonCommsContext(),
mesh_i,
)
end
space_i = Spaces.SpectralElementSpace2D(topology_i, Quadratures.GLL{nq_i}())
coords_i = Fields.coordinate_field(space_i)

# construct target mesh
# construct target mesh and space, using `spacefillingcurve`` if requested
mesh_o = ClimaCore.Meshes.EquiangularCubedSphere(domain, ne_o)
topology_o = ClimaCore.Topologies.Topology2D(
ClimaComms.SingletonCommsContext(),
mesh_o,
)
if spacefillingcurve_o
topology_o = ClimaCore.Topologies.Topology2D(
ClimaComms.SingletonCommsContext(),
mesh_o,
ClimaCore.Topologies.spacefillingcurve(mesh_o),
)
else
topology_o = ClimaCore.Topologies.Topology2D(
ClimaComms.SingletonCommsContext(),
mesh_o,
)
end
space_o = Spaces.SpectralElementSpace2D(topology_o, Quadratures.GLL{nq_o}())
coords_o = Fields.coordinate_field(space_o)

Expand Down

0 comments on commit a57c937

Please sign in to comment.