Skip to content

Commit 2c9869d

Browse files
Merge pull request #2148 from CliMA/ck/fix_994
Fix getidx for GradientC2F with SetValue bcs
2 parents 1c7bc03 + 36d3563 commit 2c9869d

File tree

2 files changed

+61
-2
lines changed

2 files changed

+61
-2
lines changed

src/Operators/finitedifference.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2845,7 +2845,7 @@ Base.@propagate_inbounds function stencil_right_boundary(
28452845
)
28462846
@assert idx == right_face_boundary_idx(space)
28472847
Geometry.Covariant3Vector(2) (
2848-
getidx(space, bc.val, loc, nothing, idx)
2848+
getidx(space, bc.val, loc, nothing, hidx)
28492849
getidx(space, arg, loc, idx - half, hidx)
28502850
)
28512851
end

test/Operators/finitedifference/unit_column.jl

Lines changed: 60 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
using Test
22
using StaticArrays, IntervalSets, LinearAlgebra
3-
3+
using ClimaCore
44
using ClimaComms
55
ClimaComms.@import_required_backends
66
import ClimaCore: slab, Domains, Meshes, Topologies, Spaces, Fields, Operators
@@ -298,3 +298,62 @@ end
298298
cy_ref = [i == length(cyp) ? FT(10) : fyp[i + 1] for i in 1:length(cyp)]
299299
@test all(cy_ref .== cyp)
300300
end
301+
302+
# https://github.com/CliMA/ClimaCore.jl/issues/994
303+
# TODO: make this test more low-level / granular (test `getidx`).
304+
@testset "Spatially varying BC with Grad" begin
305+
FT = Float64
306+
zmin = FT(1.0)
307+
zmax = FT(2.0)
308+
xlim = FT.((0.0, 10.0))
309+
ylim = FT.((0.0, 1.0))
310+
zlim = FT.((zmin, zmax))
311+
nelements = (1, 1, 5)
312+
npolynomial = 3
313+
domain_x = Domains.IntervalDomain(
314+
Geometry.XPoint(xlim[1]),
315+
Geometry.XPoint(xlim[2]);
316+
periodic = true,
317+
)
318+
domain_y = Domains.IntervalDomain(
319+
Geometry.YPoint(ylim[1]),
320+
Geometry.YPoint(ylim[2]);
321+
periodic = true,
322+
)
323+
plane = Domains.RectangleDomain(domain_x, domain_y)
324+
context = ClimaComms.context()
325+
mesh = Meshes.RectilinearMesh(plane, nelements[1], nelements[2])
326+
grid_topology = Topologies.Topology2D(context, mesh)
327+
quad = Spaces.Quadratures.GLL{npolynomial + 1}()
328+
horzspace = Spaces.SpectralElementSpace2D(grid_topology, quad)
329+
330+
331+
vertdomain = Domains.IntervalDomain(
332+
Geometry.ZPoint(zlim[1]),
333+
Geometry.ZPoint(zlim[2]);
334+
boundary_names = (:bottom, :top),
335+
)
336+
vertmesh = Meshes.IntervalMesh(vertdomain, nelems = nelements[3])
337+
vert_center_space = Spaces.CenterFiniteDifferenceSpace(vertmesh)
338+
339+
hv_center_space =
340+
Spaces.ExtrudedFiniteDifferenceSpace(horzspace, vert_center_space)
341+
342+
surface_field = Fields.zeros(horzspace)
343+
344+
ψ = Fields.ones(hv_center_space)
345+
value = surface_field # same type/instance of underlying space as horizontal space of \psi
346+
347+
gradc2f_no_bc = Operators.GradientC2F()
348+
divf2c = Operators.DivergenceF2C(
349+
top = Operators.SetValue(Geometry.WVector.(value)),
350+
bottom = Operators.SetValue(Geometry.WVector(FT(0.0))),
351+
)
352+
@. divf2c(gradc2f_no_bc(ψ)) # runs
353+
354+
gradc2f = Operators.GradientC2F(;
355+
top = Operators.SetValue(value),
356+
bottom = Operators.SetValue{FT}(0.0),
357+
)
358+
gradc2f.(ψ) # fails
359+
end

0 commit comments

Comments
 (0)