Skip to content

Commit 7e9d030

Browse files
Merge pull request #2330 from CliMA/dy/missing_methods
Add missing methods for column spaces and FieldVectors
2 parents f880322 + 1e18ec6 commit 7e9d030

4 files changed

Lines changed: 15 additions & 1 deletion

File tree

src/Fields/Fields.jl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ import ..Utilities: PlusHalf, half
3030
using ..RecursiveApply
3131
using ClimaComms
3232
import Adapt
33-
import UnrolledUtilities: unrolled_map
33+
import UnrolledUtilities: unrolled_map, unrolled_findfirst
3434

3535
import StaticArrays, LinearAlgebra, Statistics, InteractiveUtils
3636

src/Fields/fieldvector.jl

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -459,6 +459,17 @@ import ClimaComms
459459
ClimaComms.array_type(x::FieldVector) =
460460
promote_type(unrolled_map(ClimaComms.array_type, _values(x))...)
461461

462+
ClimaComms.device(x::FieldVector) = ClimaComms.device(ClimaComms.context(x))
463+
function ClimaComms.context(x::FieldVector)
464+
isempty(_values(x)) && error("Empty FieldVector has no device or context")
465+
# We don't have promotion for devices or contexts, so we use the first value
466+
# that isn't a PointField (a PointField's data can be stored on a different
467+
# device from other Fields to avoid scalar indexing on GPUs). If there is no
468+
# such value, fall back to using the first PointField.
469+
index = unrolled_findfirst(Base.Fix1(!isa, PointField), _values(x))
470+
return ClimaComms.context(_values(x)[isnothing(index) ? 1 : index])
471+
end
472+
462473
function __rprint_diff(
463474
io::IO,
464475
x::T,

src/Grids/column.jl

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ struct ColumnGrid{
3636
colidx::C
3737
end
3838

39+
Adapt.@adapt_structure ColumnGrid
40+
3941
local_geometry_type(::Type{ColumnGrid{G, C}}) where {G, C} =
4042
local_geometry_type(G)
4143

src/Spaces/finitedifference.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,6 +103,7 @@ function center_space(space::FiniteDifferenceSpace)
103103
return FiniteDifferenceSpace(grid(space), CellCenter())
104104
end
105105

106+
ncolumns(::FiniteDifferenceSpace) = 1
106107
nlevels(space::FiniteDifferenceSpace) = length(space)
107108
# TODO: deprecate?
108109
Base.length(space::FiniteDifferenceSpace) = length(coordinates_data(space))

0 commit comments

Comments
 (0)