Skip to content

Commit

Permalink
Merge #1332
Browse files Browse the repository at this point in the history
1332: allow broadcasting over horizontal spaces r=simonbyrne a=simonbyrne

Fixes #1331.

- [x] Code follows the [style guidelines](https://clima.github.io/ClimateMachine.jl/latest/DevDocs/CodeStyle/) OR N/A.
- [x] Unit tests are included OR N/A.
- [x] Code is exercised in an integration test OR N/A.
- [x] Documentation has been added/updated OR N/A.


Co-authored-by: Simon Byrne <[email protected]>
  • Loading branch information
bors[bot] and simonbyrne committed Jun 20, 2023
2 parents eb6f155 + d1bb0c5 commit 7e6cb89
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 13 deletions.
7 changes: 7 additions & 0 deletions src/Fields/broadcast.jl
Original file line number Diff line number Diff line change
Expand Up @@ -192,6 +192,10 @@ end
parent(Spaces.local_geometry_data(space2))
)
warn_mismatched_spaces(typeof(space1), typeof(space2))
elseif Spaces.issubspace(space2, space1)
return space1
elseif Spaces.issubspace(space1, space2)
return space2
else
error_mismatched_spaces(typeof(space1), typeof(space2))
end
Expand Down Expand Up @@ -229,6 +233,9 @@ end
parent(Spaces.local_geometry_data(space2))
)
warn_mismatched_spaces(typeof(space1), typeof(space2))
elseif Spaces.issubspace(space2, space1) ||
Spaces.issubspace(space1, space2)
nothing
else
error_mismatched_spaces(typeof(space1), typeof(space2))
end
Expand Down
2 changes: 2 additions & 0 deletions src/Spaces/Spaces.jl
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ using StaticArrays, ForwardDiff, LinearAlgebra, UnPack, Adapt

abstract type AbstractSpace end

issubspace(::AbstractSpace, ::AbstractSpace) = false

undertype(space::AbstractSpace) =
Geometry.undertype(eltype(local_geometry_data(space)))

Expand Down
15 changes: 15 additions & 0 deletions src/Spaces/extruded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,21 @@ struct ExtrudedFiniteDifferenceSpace{
face_ghost_geometry::LGG
end

function issubspace(
hspace::AbstractSpectralElementSpace,
extruded_space::ExtrudedFiniteDifferenceSpace,
)
if hspace === extruded_space.horizontal_space
return true
end
# TODO: improve level handling
return Spaces.topology(hspace) ===
Spaces.topology(extruded_space.horizontal_space) &&
quadrature_style(hspace) ===
quadrature_style(extruded_space.horizontal_space)
end


Adapt.adapt_structure(to, space::ExtrudedFiniteDifferenceSpace) =
ExtrudedFiniteDifferenceSpace(
space.staggering,
Expand Down
18 changes: 5 additions & 13 deletions test/Fields/field.jl
Original file line number Diff line number Diff line change
Expand Up @@ -430,21 +430,13 @@ end
ᶜx_surf = Spaces.level(Y.x, TU.fc_index(1, space))

# Still need to define broadcast rules for surface planes with 3D domains
if nameof(typeof(space)) == :ExtrudedFiniteDifferenceSpace
@test_broken begin
try
domain_surface_bc!(Y.x, ᶜz_surf)
true
catch
false
end
end
else
domain_surface_bc!(Y.x, ᶜz_surf, ᶜx_surf)
end
domain_surface_bc!(Y.x, ᶜz_surf, ᶜx_surf)

# Skip spaces incompatible with Fields.bycolumn:
TU.bycolumnable(space) || continue
column_surface_bc!(Y.x, ᶜz_surf, ᶜx_surf)
Yc = TU.FieldFromNamedTuple(space, (; x = FT(1)))
column_surface_bc!(Yc.x, ᶜz_surf, ᶜx_surf)
@test Y.x == Yc.x
nothing
end
nothing
Expand Down

0 comments on commit 7e6cb89

Please sign in to comment.