Skip to content

Commit bc75cda

Browse files
authored
Merge pull request #2292 from CliMA/gb/mask_error_remapper
Prevent mask from being incorrectly used when Remapping on a non-supported space
2 parents 4d7246e + 5f69b01 commit bc75cda

File tree

2 files changed

+30
-2
lines changed

2 files changed

+30
-2
lines changed

src/Remapping/distributed_remapping.jl

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -308,6 +308,19 @@ function _Remapper(
308308
ArrayType = ClimaComms.array_type(space)
309309
horizontal_topology = Spaces.topology(space)
310310
horizontal_mesh = horizontal_topology.mesh
311+
quad = Spaces.quadrature_style(space)
312+
313+
space_has_mask = !(Spaces.get_mask(space) isa DataLayouts.NoMask)
314+
element_has_more_than_one_node = Quadratures.degrees_of_freedom(quad) > 1
315+
316+
# Spectral remapping with a mask makes sense only if there is only one node
317+
# in the element (the code will go through, but the results will be
318+
# incorrect)
319+
if space_has_mask && element_has_more_than_one_node
320+
error(
321+
"Remapping does not support masks, unless each element contains exactly one nodal point",
322+
)
323+
end
311324

312325
is_1d = typeof(horizontal_topology) <: Topologies.IntervalTopology
313326

@@ -339,7 +352,6 @@ function _Remapper(
339352
ξs_split = Tuple([ξ[i] for ξ in ξs_combined] for i in 1:num_hdims)
340353

341354
# Compute the interpolation matrices
342-
quad = Spaces.quadrature_style(space)
343355
quad_points, _ = Quadratures.quadrature_points(FT, quad)
344356
Nq = Quadratures.degrees_of_freedom(quad)
345357

test/Remapping/distributed_remapping.jl

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@ import ClimaCore:
1616
Quadratures,
1717
Topologies,
1818
Remapping,
19-
Hypsography
19+
Hypsography,
20+
CommonSpaces
2021
using ClimaComms
2122
ClimaComms.@import_required_backends
2223
const context = ClimaComms.context()
@@ -925,3 +926,18 @@ end
925926
[Geometry.XPoint(x) for x in range(-500.0, 500.0, length = 180)],
926927
)
927928
end
929+
930+
@testset "Mask" begin
931+
@test_throws ErrorException Remapping.Remapper(
932+
CommonSpaces.ExtrudedCubedSphereSpace(;
933+
z_elem = 10,
934+
z_min = 0,
935+
z_max = 1,
936+
radius = 10,
937+
h_elem = 10,
938+
n_quad_points = 4,
939+
staggering = CommonSpaces.CellCenter(),
940+
enable_mask = true,
941+
),
942+
)
943+
end

0 commit comments

Comments
 (0)