Skip to content

Commit e4591c2

Browse files
committed
address comments
1 parent db8d15f commit e4591c2

8 files changed

Lines changed: 40 additions & 52 deletions

File tree

src/CommonGrids/CommonGrids.jl

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -441,19 +441,6 @@ function Box3DGrid(
441441
periodic_x,
442442
periodic_y,
443443
),
444-
Topologies.spacefillingcurve(
445-
DefaultRectangleXYMesh(
446-
FT;
447-
x_min,
448-
x_max,
449-
y_min,
450-
y_max,
451-
x_elem,
452-
y_elem,
453-
periodic_x,
454-
periodic_y,
455-
),
456-
),
457444
),
458445
z_mesh::Meshes.IntervalMesh = DefaultZMesh(
459446
FT;

src/Geometry/axistensors.jl

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,8 @@ const AxisVector{T, A1, S} = AxisTensor{T, 1, Tuple{A1}, S}
234234
AxisVector(ax::A1, v::SVector{N, T}) where {A1 <: AbstractAxis, N, T} =
235235
AxisVector{T, A1, SVector{N, T}}((ax,), v)
236236

237+
(AxisVector{T, A, SVector{0, T}} where {T})() where {A} =
238+
AxisVector(A.instance, SVector{0, T}())
237239
(AxisVector{T, A, SVector{1, T}} where {T})(arg1::Real) where {A} =
238240
AxisVector(A.instance, SVector(arg1))
239241
(AxisVector{T, A, SVector{2, T}} where {T})(arg1::Real, arg2::Real) where {A} =
@@ -244,8 +246,6 @@ AxisVector(ax::A1, v::SVector{N, T}) where {A1 <: AbstractAxis, N, T} =
244246
arg3::Real,
245247
) where {A} = AxisVector(A.instance, SVector(arg1, arg2, arg3))
246248

247-
(AxisVector{T, A, SVector{0, T}})() where {A, T} =
248-
AxisVector(A.instance, SVector{0, T}())
249249

250250
const CovariantVector{T, I, S} = AxisVector{T, CovariantAxis{I}, S}
251251
const ContravariantVector{T, I, S} = AxisVector{T, ContravariantAxis{I}, S}
@@ -331,6 +331,10 @@ const Cartesian2Tensor{T, A, S} =
331331
const Local2Tensor{T, A, S} =
332332
Axis2Tensor{T, A, S} where {T, A <: Tuple{LocalAxis, AbstractAxis}, S}
333333

334+
const CovariantTensor = Union{CovariantVector, Covariant2Tensor}
335+
const ContravariantTensor = Union{ContravariantVector, Contravariant2Tensor}
336+
const CartesianTensor = Union{CartesianVector, Cartesian2Tensor}
337+
const LocalTensor = Union{LocalVector, Local2Tensor}
334338
for I in [(), (1,), (2,), (3,), (1, 2), (1, 3), (2, 3), (1, 2, 3)]
335339

336340
strI = isempty(I) ? "Null" : join(I)
@@ -355,12 +359,6 @@ for I in [(), (1,), (2,), (3,), (1, 2), (1, 3), (2, 3), (1, 2, 3)]
355359
end
356360
end
357361

358-
const CovariantTensor = Union{CovariantVector, Covariant2Tensor}
359-
const ContravariantTensor =
360-
Union{ContravariantVector, Contravariant2Tensor}
361-
const CartesianTensor = Union{CartesianVector, Cartesian2Tensor}
362-
const LocalTensor = Union{LocalVector, Local2Tensor}
363-
364362
# LinearAlgebra
365363

366364
check_axes(::A, ::A) where {A} = nothing

src/Geometry/conversions.jl

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -550,10 +550,6 @@ The return type when taking the divergence of a field of `V`.
550550
Required for statically infering the result type of the divergence operation for `AxisVector` subtypes.
551551
"""
552552
@inline divergence_result_type(::Type{V}) where {V <: AxisVector} = eltype(V)
553-
@inline divergence_result_type(::Type{V}) where {V <: CovariantNullVector} =
554-
eltype(V)
555-
@inline divergence_result_type(::Type{V}) where {V <: ContravariantNullVector} =
556-
eltype(V)
557553

558554
# this isn't quite right: it only is true when the Christoffel symbols are zero
559555
@inline divergence_result_type(
@@ -575,9 +571,6 @@ Required for statically infering the result type of the gradient operation for `
575571
N = length(I)
576572
AxisVector{V, CovariantAxis{I}, SVector{N, V}}
577573
end
578-
@inline function gradient_result_type(::Val{()}, ::Type{V}) where {V <: Number}
579-
CovariantNullVector{V}
580-
end
581574
@inline function gradient_result_type(
582575
::Val{I},
583576
::Type{V},
@@ -625,7 +618,8 @@ Curl is only defined for `CovariantVector`` field input types.
625618
) where {FT} = ContravariantNullVector{FT}
626619
@inline curl_result_type(::Val{()}, ::Type{<:CovariantVector{FT}}) where {FT} =
627620
ContravariantNullVector{FT}
628-
621+
@inline curl_result_type(_, ::Type{CovariantNullVector{FT}}) where {FT} =
622+
ContravariantNullVector{FT}
629623

630624
@inline curl_result_type(::Val{(1,)}, ::Type{Covariant1Vector{FT}}) where {FT} =
631625
Contravariant1Vector{FT} # not strictly correct: should be a zero Vector

src/Operators/spectralelement.jl

Lines changed: 16 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -188,27 +188,13 @@ Copy the slab indexed by `slabidx` from `bc` to `out`.
188188
"""
189189
Base.@propagate_inbounds function copyto_slab!(out, bc, slabidx)
190190
space = axes(out)
191-
QS = Spaces.quadrature_style(space)
192-
Nq = Quadratures.degrees_of_freedom(QS)
193191
rbc = resolve_operator(bc, slabidx)
194192
@inbounds for ij in node_indices(axes(out))
195193
set_node!(space, out, ij, slabidx, get_node(space, rbc, ij, slabidx))
196194
end
197195
return nothing
198196
end
199197

200-
Base.@propagate_inbounds function copyto_slab!(
201-
out::Field{T, <:Spaces.FiniteDifferenceSpace},
202-
bc,
203-
slabidx,
204-
) where {T}
205-
space = axes(out)
206-
rbc = resolve_operator(bc, slabidx)
207-
@inbounds for ij in node_indices(space)
208-
set_node!(space, out, ij, slabidx, get_node(space, rbc, ij, slabidx))
209-
end
210-
return nothing
211-
end
212198

213199
"""
214200
resolve_operator(bc, slabidx)
@@ -355,7 +341,7 @@ Base.@propagate_inbounds function get_node(
355341
slabidx,
356342
)
357343
space = reconstruct_placeholder_space(axes(field), parent_space)
358-
i, = space isa Spaces.FiniteDifferenceSpace ? (1,) : Tuple(ij)
344+
i, = Tuple(ij)
359345
if space isa Spaces.FaceExtrudedFiniteDifferenceSpace ||
360346
space isa Spaces.FaceFiniteDifferenceSpace
361347
_v = slabidx.v + half
@@ -1635,6 +1621,7 @@ matrix_interpolate(field::Field, Nu::Integer) =
16351621
matrix_interpolate(field, Quadratures.Uniform{Nu}())
16361622

16371623
import .DataLayouts: slab_index
1624+
import .Spaces: slab_type
16381625

16391626
"""
16401627
rmatmul1(W, S, i, j)
@@ -1670,6 +1657,7 @@ function rmatmul2(W, S, i, j)
16701657
end
16711658

16721659

1660+
16731661
function apply_operator(
16741662
op::Union{
16751663
Divergence{()},
@@ -1686,7 +1674,18 @@ function apply_operator(
16861674
FT = Spaces.undertype(space)
16871675
RT = operator_return_eltype(op, eltype(arg))
16881676
zero_value = zero(RT)
1689-
out = DataLayouts.IF{RT, 1}(MArray, FT)
1690-
out[slab_index(1)] = zero_value
1677+
slab_type = DataLayouts.slab_type(space)
1678+
QS = Spaces.quadrature_style(space)
1679+
Nq = Quadratures.degrees_of_freedom(QS)
1680+
1681+
if slab_type === DataLayouts.IJF
1682+
out = DataLayouts.IJF{RT, Nq}(MArray, FT)
1683+
fill!(parent(out), zero(FT))
1684+
out[slab_index(1, 1)] = zero_value
1685+
else
1686+
out = DataLayouts.IF{RT, 1}(MArray, FT)
1687+
out[slab_index(1)] = zero_value
1688+
end
1689+
16911690
return Field(SArray(out), space)
16921691
end

src/Spaces/Spaces.jl

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,4 +212,18 @@ set_mask!(fn, space::ExtrudedFiniteDifferenceSpace) =
212212
set_mask!(space::AbstractSpace, data::DataLayouts.AbstractData) =
213213
set_mask!(grid(space), data)
214214

215+
"""
216+
slab_type(space)
217+
218+
Determines the appropriate slab data layout type for a given space.
219+
220+
For spaces with 2 horizontal dimensions, returns IJF.
221+
For 1D spaces, returns IF.
222+
"""
223+
slab_type(space::SpectralElementSpace2D) = DataLayouts.IJF
224+
slab_type(space::SpectralElementSpace1D) = DataLayouts.IF
225+
slab_type(space::FiniteDifferenceSpace) = DataLayouts.IF
226+
slab_type(space::ExtrudedFiniteDifferenceSpace) =
227+
slab_type(horizontal_space(space))
228+
215229
end # module

src/Topologies/Topologies.jl

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,6 @@ end
6363

6464
function print_context(io::IO, context::ClimaComms.MPICommsContext)
6565
print(io, "MPICommsContext with ", ClimaComms.nprocs(context), " processes")
66-
6766
print(io, " using ")
6867
print_device(io, context.device)
6968
end

src/Topologies/topology2d.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ end
237237
function Topology2D(
238238
context::ClimaComms.AbstractCommsContext,
239239
mesh::Meshes.AbstractMesh{2},
240-
elemorder = Meshes.elements(mesh),
240+
elemorder = spacefillingcurve(mesh),
241241
elempid = nothing, # array of same size as elemorder, containing owning pid for each element (it should be sorted)
242242
orderindex = Meshes.linearindices(elemorder), # inverse mapping of elemorder (e.g. map CartesianIndex => Int)
243243
)

src/to_device.jl

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@ If the input is already defined on the target device, returns a copy.
1818
1919
This means that `out === x` will not in general be satisfied.
2020
"""
21-
function to_device(
22-
device::ClimaComms.AbstractDevice,
23-
x,
24-
)
21+
function to_device(device::ClimaComms.AbstractDevice, x)
2522
return Adapt.adapt(ClimaComms.array_type(device), x)
2623
end
2724

0 commit comments

Comments
 (0)