From 3f4f2be86ffe38fbb4cfdfffdbd53b9b61f57b60 Mon Sep 17 00:00:00 2001 From: Simon Byrne Date: Thu, 30 Nov 2023 17:01:54 -0800 Subject: [PATCH 1/6] add convenience constructors for grids --- src/Domains/Domains.jl | 28 +++++++++++++++++ src/Grids/extruded.jl | 2 +- src/Grids/finitedifference.jl | 9 ++++++ src/Grids/spectralelement.jl | 57 ++++++++++++++++++++++++++++++++--- src/Meshes/interval.jl | 11 +++++++ src/Meshes/rectangle.jl | 13 ++++++++ 6 files changed, 114 insertions(+), 6 deletions(-) diff --git a/src/Domains/Domains.jl b/src/Domains/Domains.jl index 5336f30a2c..4cc2c9c2bc 100644 --- a/src/Domains/Domains.jl +++ b/src/Domains/Domains.jl @@ -35,6 +35,10 @@ struct IntervalDomain{CT, B} <: AbstractDomain where { boundary_names::B end +const XIntervalDomain{FT, B} = IntervalDomain{Geometry.XPoint{FT}, B} +const YIntervalDomain{FT, B} = IntervalDomain{Geometry.YPoint{FT}, B} +const ZIntervalDomain{FT, B} = IntervalDomain{Geometry.ZPoint{FT}, B} + isperiodic(domain::IntervalDomain) = isnothing(domain.boundary_names) boundary_names(domain::IntervalDomain) = isperiodic(domain) ? () : unique(domain.boundary_names) @@ -79,6 +83,19 @@ The domain minimum along the z-direction. """ z_min(domain::IntervalDomain) = domain.coord_min.z +function XIntervalDomain(; x_min::Real, x_max::Real, x_periodic::Bool=false, x_boundary_names=(:west, :east)) + x_min, x_max = promote(x_min, x_max) + IntervalDomain(Geometry.XPoint(x_min), Geometry.XPoint(x_max); periodic = x_periodic, boundary_names = x_boundary_names) +end +function YIntervalDomain(; y_min::Real, y_max::Real, y_periodic::Bool=false, y_boundary_names=(:south, :north)) + y_min, y_max = promote(y_min, y_max) + IntervalDomain(Geometry.YPoint(y_min), Geometry.YPoint(y_max); periodic = y_periodic, boundary_names = y_boundary_names) +end +function ZIntervalDomain(; z_min::Real, z_max::Real, z_periodic::Bool=false, z_boundary_names=(:bottom, :top)) + z_min, z_max = promote(z_min, z_max) + IntervalDomain(Geometry.ZPoint(z_min), Geometry.ZPoint(z_max); periodic = z_periodic, boundary_names = z_boundary_names) +end + coordinate_type(::IntervalDomain{CT}) where {CT} = CT Base.eltype(domain::IntervalDomain) = coordinate_type(domain) @@ -108,6 +125,9 @@ struct RectangleDomain{I1 <: IntervalDomain, I2 <: IntervalDomain} <: interval1::I1 interval2::I2 end + +const XYRectangleDomain = RectangleDomain{<:XIntervalDomain, <:YIntervalDomain} + Base.:*(interval1::IntervalDomain, interval2::IntervalDomain) = RectangleDomain(interval1, interval2) @@ -144,6 +164,14 @@ function RectangleDomain( return interval1 * interval2 end +function XYRectangleDomain(; + x_min::Real, x_max::Real, x_periodic::Bool=false, x_boundary_names=(:west, :east), + y_min::Real, y_max::Real, y_periodic::Bool=false, y_boundary_names=(:south, :north), +) + x_domain = XIntervalDomain(; x_min, x_max, x_periodic, x_boundary_names) + y_domain = YIntervalDomain(; y_min, y_max, y_periodic, y_boundary_names) + RectangleDomain(x_domain, y_domain) +end function Base.show(io::IO, domain::RectangleDomain) print(io, nameof(typeof(domain)), ": ") diff --git a/src/Grids/extruded.jl b/src/Grids/extruded.jl index 15b68c9423..9e2130b714 100644 --- a/src/Grids/extruded.jl +++ b/src/Grids/extruded.jl @@ -176,6 +176,6 @@ const ExtrudedSpectralElementGrid2D = const ExtrudedSpectralElementGrid3D = ExtrudedFiniteDifferenceGrid{<:SpectralElementGrid2D} const ExtrudedRectilinearSpectralElementGrid3D = - ExtrudedFiniteDifferenceGrid{<:RectilinearSpectralElementGrid2D} + ExtrudedFiniteDifferenceGrid{<:RectilinearSpectralElementGrid} const ExtrudedCubedSphereSpectralElementGrid3D = ExtrudedFiniteDifferenceGrid{<:CubedSphereSpectralElementGrid2D} diff --git a/src/Grids/finitedifference.jl b/src/Grids/finitedifference.jl index 8f594ec417..d0c6601942 100644 --- a/src/Grids/finitedifference.jl +++ b/src/Grids/finitedifference.jl @@ -163,6 +163,15 @@ FiniteDifferenceGrid( mesh::Meshes.IntervalMesh, ) = FiniteDifferenceGrid(Topologies.IntervalTopology(device, mesh)) +function FiniteDifferenceGrid(; + z_min::Real, z_max::Real, z_periodic::Bool=false, z_boundary_names=(:bottom, :top), + z_elem::Integer, z_stretch=Meshes.Uniform(), +) + mesh = Meshes.ZIntervalMesh(; z_min, z_max, z_periodic, z_boundary_names, z_elem, z_stretch) + topology = Topologies.IntervalTopology(mesh) + FiniteDifferenceGrid(topology) +end + # accessors topology(grid::FiniteDifferenceGrid) = grid.topology vertical_topology(grid::FiniteDifferenceGrid) = grid.topology diff --git a/src/Grids/spectralelement.jl b/src/Grids/spectralelement.jl index e49fe84b9b..85d63d0b02 100644 --- a/src/Grids/spectralelement.jl +++ b/src/Grids/spectralelement.jl @@ -148,7 +148,7 @@ local_geometry_type( SpectralElementSpace2D(topology, quadrature_style; enable_bubble, horizontal_layout_type = DataLayouts.IJFH) Construct a `SpectralElementSpace2D` instance given a `topology` and `quadrature`. The -flag `enable_bubble` enables the `bubble correction` for more accurate element areas. +flag `bubble` enables the "bubble correction" for more accurate element areas. # Input arguments: - topology: Topology2D @@ -156,7 +156,7 @@ flag `enable_bubble` enables the `bubble correction` for more accurate element a - enable_bubble: Bool - horizontal_layout_type: Type{<:AbstractData} -The idea behind the so-called `bubble_correction` is that the numerical area +The idea behind the so-called "bubble correction" is that the numerical area of the domain (e.g., the sphere) is given by the sum of nodal integration weights times their corresponding Jacobians. However, this discrete sum is not exactly equal to the exact geometric area (4pi*radius^2 for the sphere). To make these equal, @@ -322,7 +322,7 @@ function _SpectralElementGrid2D( end # If enabled, apply bubble correction - if enable_bubble + if bubble if abs(elem_area - high_order_elem_area) ≤ eps(FT) for i in 1:Nq, j in 1:Nq ξ = SVector(quad_points[i], quad_points[j]) @@ -605,7 +605,54 @@ Adapt.adapt_structure(to, grid::SpectralElementGrid2D) = ) ## aliases -const RectilinearSpectralElementGrid2D = +# +const RectilinearSpectralElementGrid = SpectralElementGrid2D{<:Topologies.RectilinearTopology2D} -const CubedSphereSpectralElementGrid2D = + +""" + Grids.RectilinearSpectralElementGrid(; + x_min, x_max, x_elem, x_periodic=false, x_boundary_names = (:west, :east), + y_min, y_max, y_elem, y_periodic=false, y_boundary_names = (:south, :north), + context = ClimaComms.context(), + poly_degree = 3, + ) + +Constructor for a `SpectralElementGrid2D` on a `RectangleDomain`. +""" +function RectilinearSpectralElementGrid(; + x_min::Real, x_max::Real, x_elem, x_periodic::Bool=false, x_boundary_names = (:west, :east), + y_min::Real, y_max::Real, y_elem, y_periodic::Bool=false, y_boundary_names = (:south, :north), + context = ClimaComms.context(), + poly_degree=3, + float_type = float(typeof(first(promote(x_min,x_max, y_min, y_max)))), +) + mesh = Meshes.RectilinearMesh(; + x_min, x_max, y_min, y_max, x_periodic, x_boundary_names, x_elem, + y_min, y_max, y_min, y_max, y_periodic, y_boundary_names, y_elem, + ) + topology = Topologies.Topology2D(context, mesh) + quadrature_style = Quadratures.GLL{poly_degree+1}() + SpectralElementGrid2D(topology, quadrature_style) +end + +const CubedSphereSpectralElementGrid = SpectralElementGrid2D{<:Topologies.CubedSphereTopology2D} + +function CubedSphereSpectralElementGrid(; + radius::Real, panel_elem::Integer, cubed_sphere_type = Meshes.EquiangularCubedSphere, + context = ClimaComms.context(), + poly_degree = 3, + float_type = float(typeof(radius)), + bubble = true, +) + domain = Domains.SphereDomain(radius) + mesh = cubed_sphere_type(domain, panel_elem) + topology = Topologies.Topology2D(context, mesh) + quadrature_style = Quadratures.GLL{poly_degree+1}() + SpectralElementGrid2D(topology, quadrature_style; bubble) +end + + +## to be deprecated +const RectilinearSpectralElementGrid2D = RectilinearSpectralElementGrid +const CubedSphereSpectralElementGrid2D = CubedSphereSpectralElementGrid diff --git a/src/Meshes/interval.jl b/src/Meshes/interval.jl index 7a2ea8d755..725438daa8 100644 --- a/src/Meshes/interval.jl +++ b/src/Meshes/interval.jl @@ -454,3 +454,14 @@ function truncate_mesh( ) return IntervalMesh(new_domain, new_stretch; nelems = new_nelems) end + + +const ZIntervalMesh = IntervalMesh{<:Domains.ZIntervalDomain} + +function ZIntervalMesh(; + z_min::Real, z_max::Real, z_periodic::Bool=false, z_boundary_names=(:bottom, :top), + z_elem::Integer, z_stretch=Uniform(), +) + domain = Domains.ZIntervalDomain(; z_min, z_max, z_periodic, z_boundary_names) + mesh = IntervalMesh(domain, z_stretch; nelem=z_elem) +end diff --git a/src/Meshes/rectangle.jl b/src/Meshes/rectangle.jl index a9b0393682..6918516f8b 100644 --- a/src/Meshes/rectangle.jl +++ b/src/Meshes/rectangle.jl @@ -32,6 +32,19 @@ function Base.hash(mesh::RectilinearMesh, h::UInt) end +function RectilinearMesh(; + x_min::Real, x_max::Real, x_elem::Integer, x_periodic::Bool=false, x_boundary_names=(:west, :east), + y_min::Real, y_max::Real, y_elem::Integer, y_periodic::Bool=false, y_boundary_names=(:south, :north), +) + x_domain = XIntervalDomain(; x_min, x_max, x_periodic, x_boundary_names) + y_domain = YIntervalDomain(; y_min, y_max, y_periodic, y_boundary_names) + + RectilinearMesh( + IntervalMesh(x_domain, x_elem), + IntervalMesh(y_domain, y_elem), + ) +end + function Base.summary(io::IO, mesh::RectilinearMesh) n1 = nelements(mesh.intervalmesh1) n2 = nelements(mesh.intervalmesh2) From cf3bc72c5943a4e9d2619cb26eacee7df85578ef Mon Sep 17 00:00:00 2001 From: Simon Byrne Date: Fri, 1 Dec 2023 15:58:30 -0800 Subject: [PATCH 2/6] more naming --- src/Grids/extruded.jl | 5 ++++- src/Grids/finitedifference.jl | 29 ++++++++++++++++++++--------- src/Grids/spectralelement.jl | 2 +- src/Topologies/interval.jl | 8 ++++++++ 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/Grids/extruded.jl b/src/Grids/extruded.jl index 9e2130b714..ad2cf971b8 100644 --- a/src/Grids/extruded.jl +++ b/src/Grids/extruded.jl @@ -177,5 +177,8 @@ const ExtrudedSpectralElementGrid3D = ExtrudedFiniteDifferenceGrid{<:SpectralElementGrid2D} const ExtrudedRectilinearSpectralElementGrid3D = ExtrudedFiniteDifferenceGrid{<:RectilinearSpectralElementGrid} -const ExtrudedCubedSphereSpectralElementGrid3D = +const ExtrudedCubedSphereSpectralElementGrid = ExtrudedFiniteDifferenceGrid{<:CubedSphereSpectralElementGrid2D} + +## to be deprecated +const ExtrudedCubedSphereSpectralElementGrid3D = ExtrudedCubedSphereSpectralElementGrid \ No newline at end of file diff --git a/src/Grids/finitedifference.jl b/src/Grids/finitedifference.jl index d0c6601942..d6a8545c55 100644 --- a/src/Grids/finitedifference.jl +++ b/src/Grids/finitedifference.jl @@ -163,15 +163,6 @@ FiniteDifferenceGrid( mesh::Meshes.IntervalMesh, ) = FiniteDifferenceGrid(Topologies.IntervalTopology(device, mesh)) -function FiniteDifferenceGrid(; - z_min::Real, z_max::Real, z_periodic::Bool=false, z_boundary_names=(:bottom, :top), - z_elem::Integer, z_stretch=Meshes.Uniform(), -) - mesh = Meshes.ZIntervalMesh(; z_min, z_max, z_periodic, z_boundary_names, z_elem, z_stretch) - topology = Topologies.IntervalTopology(mesh) - FiniteDifferenceGrid(topology) -end - # accessors topology(grid::FiniteDifferenceGrid) = grid.topology vertical_topology(grid::FiniteDifferenceGrid) = grid.topology @@ -215,3 +206,23 @@ local_geometry_data(grid::DeviceFiniteDifferenceGrid, ::CellCenter) = local_geometry_data(grid::DeviceFiniteDifferenceGrid, ::CellFace) = grid.face_local_geometry global_geometry(grid::DeviceFiniteDifferenceGrid) = grid.global_geometry + + +## aliases +const ColumnGrid = FiniteDifferenceGrid{<:Topologies.ColumnTopology1D} + +""" + Grids.ColumnGrid(; + z_min, z_max, + context = ClimaComms.SingletonCommsContext() + ) +""" +function ColumnGrid(; + z_min::Real, z_max::Real, z_periodic::Bool=false, z_boundary_names=(:bottom, :top), + z_elem::Integer, z_stretch=Meshes.Uniform(), + context = ClimaComms.SingletonCommsContext(), +) + mesh = Meshes.ZIntervalMesh(; z_min, z_max, z_periodic, z_boundary_names, z_elem, z_stretch) + topology = Topologies.IntervalTopology(mesh) + FiniteDifferenceGrid(topology) +end diff --git a/src/Grids/spectralelement.jl b/src/Grids/spectralelement.jl index 85d63d0b02..06856b2b92 100644 --- a/src/Grids/spectralelement.jl +++ b/src/Grids/spectralelement.jl @@ -617,7 +617,7 @@ const RectilinearSpectralElementGrid = poly_degree = 3, ) -Constructor for a `SpectralElementGrid2D` on a `RectangleDomain`. +Constructor for a `SpectralElementGrid2D` on a `RectangleDomain`, with `XYPoint` coordinates. """ function RectilinearSpectralElementGrid(; x_min::Real, x_max::Real, x_elem, x_periodic::Bool=false, x_boundary_names = (:west, :east), diff --git a/src/Topologies/interval.jl b/src/Topologies/interval.jl index f205a79e74..86f07b112d 100644 --- a/src/Topologies/interval.jl +++ b/src/Topologies/interval.jl @@ -165,3 +165,11 @@ function local_neighboring_elements(topology::AbstractIntervalTopology, elem) end end ghost_neighboring_elements(topology::AbstractIntervalTopology, elem) = () + + +## aliases +const LineTopology1D = + IntervalTopology{<:ClimaComms.AbstractCommsContext, <:Meshes.XIntervalMesh} + +const ColumnTopology1D = + IntervalTopology{<:ClimaComms.AbstractCommsContext, <:Meshes.ZIntervalMesh} From 408df241a1c2b156f8ae5233ddc2e7df1bb2497f Mon Sep 17 00:00:00 2001 From: Simon Byrne Date: Fri, 1 Dec 2023 16:28:15 -0800 Subject: [PATCH 3/6] simpler names --- src/Grids/column.jl | 14 ++++----- src/Grids/extruded.jl | 60 ++++++++++++++++++++++++++++++++++-- src/Grids/spectralelement.jl | 23 ++++++++++---- src/Meshes/interval.jl | 11 ++++++- 4 files changed, 91 insertions(+), 17 deletions(-) diff --git a/src/Grids/column.jl b/src/Grids/column.jl index d31825f6cb..4ff071ab91 100644 --- a/src/Grids/column.jl +++ b/src/Grids/column.jl @@ -21,14 +21,14 @@ end """ - ColumnGrid( + ColumnViewGrid( full_grid :: ExtrudedFiniteDifferenceGrid, colidx :: ColumnIndex, ) A view into a column of a `ExtrudedFiniteDifferenceGrid`. This can be used as an """ -struct ColumnGrid{ +struct ColumnViewGrid{ G <: AbstractExtrudedFiniteDifferenceGrid, C <: ColumnIndex, } <: AbstractFiniteDifferenceGrid @@ -40,14 +40,14 @@ local_geometry_type(::Type{ColumnGrid{G, C}}) where {G, C} = local_geometry_type(G) column(grid::AbstractExtrudedFiniteDifferenceGrid, colidx::ColumnIndex) = - ColumnGrid(grid, colidx) + ColumnViewGrid(grid, colidx) -topology(colgrid::ColumnGrid) = vertical_topology(colgrid.full_grid) -vertical_topology(colgrid::ColumnGrid) = vertical_topology(colgrid.full_grid) +topology(colgrid::ColumnViewGrid) = vertical_topology(colgrid.full_grid) +vertical_topology(colgrid::ColumnViewGrid) = vertical_topology(colgrid.full_grid) -local_geometry_data(colgrid::ColumnGrid, staggering::Staggering) = column( +local_geometry_data(colgrid::ColumnViewGrid, staggering::Staggering) = column( local_geometry_data(colgrid.full_grid, staggering::Staggering), colgrid.colidx.ij..., colgrid.colidx.h, ) -global_geometry(colgrid::ColumnGrid) = global_geometry(colgrid.full_grid) +global_geometry(colgrid::ColumnViewGrid) = global_geometry(colgrid.full_grid) diff --git a/src/Grids/extruded.jl b/src/Grids/extruded.jl index ad2cf971b8..58951d9ff1 100644 --- a/src/Grids/extruded.jl +++ b/src/Grids/extruded.jl @@ -175,10 +175,64 @@ const ExtrudedSpectralElementGrid2D = ExtrudedFiniteDifferenceGrid{<:SpectralElementGrid1D} const ExtrudedSpectralElementGrid3D = ExtrudedFiniteDifferenceGrid{<:SpectralElementGrid2D} -const ExtrudedRectilinearSpectralElementGrid3D = + + + +const PlaneGrid = + ExtrudedFiniteDifferenceGrid{<:LineSpectralElementGrid} +function PlaneGrid(; + x_min::Real, x_max::Real, x_elem, x_periodic::Bool=false, x_boundary_names = (:west, :east), + poly_degree = 3, + z_min::Real, z_max::Real, z_periodic::Bool=false, z_boundary_names=(:bottom, :top), + z_elem::Integer, z_stretch=Meshes.Uniform(), + context = ClimaComms.context(), + ) + h_grid = LineSpectralElementGrid(; + x_min, x_max, x_elem, x_periodic, x_boundary_names, + poly_degree, + context) + v_grid = ColumnGrid(; z_min, z_max, z_periodic, z_boundary_names, z_elem, z_stretch, context=ClimaComms.SingletonCommsContext(ClimaComms.device(context))) + ExtrudedFiniteDifferenceGrid(h_grid, v_grid) +end + + + +const BoxGrid = ExtrudedFiniteDifferenceGrid{<:RectilinearSpectralElementGrid} -const ExtrudedCubedSphereSpectralElementGrid = + +function BoxGrid(; + x_min::Real, x_max::Real, x_elem, x_periodic::Bool=false, x_boundary_names = (:west, :east), + y_min::Real, y_max::Real, y_elem, y_periodic::Bool=false, y_boundary_names = (:south, :north), + poly_degree = 3, + z_min::Real, z_max::Real, z_periodic::Bool=false, z_boundary_names=(:bottom, :top), + z_elem::Integer, z_stretch=Meshes.Uniform(), + context = ClimaComms.context(), + ) + h_grid = RectilinearSpectralElementGrid2D(; + x_min, x_max, x_elem, x_periodic, x_boundary_names, + y_min, y_max, y_elem, y_periodic, y_boundary_names, + poly_degree, + context) + v_grid = ColumnGrid(; z_min, z_max, z_periodic, z_boundary_names, z_elem, z_stretch, context=ClimaComms.SingletonCommsContext(ClimaComms.device(context))) + ExtrudedFiniteDifferenceGrid(h_grid, v_grid) +end + + +const ExtrudedCubedSphereGrid = ExtrudedFiniteDifferenceGrid{<:CubedSphereSpectralElementGrid2D} +function ExtrudedCubedSphereGrid(; + radius::Real, panel_elem::Integer, cubed_sphere_type = Meshes.EquiangularCubedSphere, + poly_degree = 3, bubble = true, + z_min::Real, z_max::Real, z_periodic::Bool=false, z_boundary_names=(:bottom, :top), + z_elem::Integer, z_stretch=Meshes.Uniform(), + context = ClimaComms.context(), +) + h_grid = CubedSphereGrid(;radius, panel_elem, cubed_sphere_type, poly_degree, bubble, context) + v_grid = ColumnGrid(; z_min, z_max, z_periodic, z_boundary_names, z_elem, z_stretch, context=ClimaComms.SingletonCommsContext(ClimaComms.device(context))) + ExtrudedFiniteDifferenceGrid(h_grid, v_grid) +end + ## to be deprecated -const ExtrudedCubedSphereSpectralElementGrid3D = ExtrudedCubedSphereSpectralElementGrid \ No newline at end of file +const ExtrudedCubedSphereSpectralElementGrid3D = ExtrudedCubedSphereGrid +const ExtrudedRectilinearSpectralElementGrid3D = BoxGrid \ No newline at end of file diff --git a/src/Grids/spectralelement.jl b/src/Grids/spectralelement.jl index 06856b2b92..7dde7712d2 100644 --- a/src/Grids/spectralelement.jl +++ b/src/Grids/spectralelement.jl @@ -605,7 +605,20 @@ Adapt.adapt_structure(to, grid::SpectralElementGrid2D) = ) ## aliases -# + +const LineSpectralElementGrid = SpectralElementGrid1D{<:Topologies.LineTopology1D} + +function LineSpectralElementGrid(; + x_min::Real, x_max::Real, x_periodic::Bool=false, x_boundary_names=(:west, :east), + x_elem::Integer, x_stretch=Uniform(), + poly_degree=3, + context=ClimaComms.SingletonCommsContext() +) + mesh = XIntervalMesh(; x_min, x_max, x_periodic, x_boundary_names, x_elem, x_stretch) + topology = IntervalTopology(context, mesh) + quadrature_style = Quadratures.GLL{poly_degree+1}() + SpectralElementGrid1D(topology, quadrature_style) +end const RectilinearSpectralElementGrid = SpectralElementGrid2D{<:Topologies.RectilinearTopology2D} @@ -624,7 +637,6 @@ function RectilinearSpectralElementGrid(; y_min::Real, y_max::Real, y_elem, y_periodic::Bool=false, y_boundary_names = (:south, :north), context = ClimaComms.context(), poly_degree=3, - float_type = float(typeof(first(promote(x_min,x_max, y_min, y_max)))), ) mesh = Meshes.RectilinearMesh(; x_min, x_max, y_min, y_max, x_periodic, x_boundary_names, x_elem, @@ -635,14 +647,13 @@ function RectilinearSpectralElementGrid(; SpectralElementGrid2D(topology, quadrature_style) end -const CubedSphereSpectralElementGrid = +const CubedSphereGrid = SpectralElementGrid2D{<:Topologies.CubedSphereTopology2D} -function CubedSphereSpectralElementGrid(; +function CubedSphereGrid(; radius::Real, panel_elem::Integer, cubed_sphere_type = Meshes.EquiangularCubedSphere, context = ClimaComms.context(), poly_degree = 3, - float_type = float(typeof(radius)), bubble = true, ) domain = Domains.SphereDomain(radius) @@ -655,4 +666,4 @@ end ## to be deprecated const RectilinearSpectralElementGrid2D = RectilinearSpectralElementGrid -const CubedSphereSpectralElementGrid2D = CubedSphereSpectralElementGrid +const CubedSphereSpectralElementGrid2D = CubedSphereGrid diff --git a/src/Meshes/interval.jl b/src/Meshes/interval.jl index 725438daa8..a9eaa61291 100644 --- a/src/Meshes/interval.jl +++ b/src/Meshes/interval.jl @@ -455,9 +455,18 @@ function truncate_mesh( return IntervalMesh(new_domain, new_stretch; nelems = new_nelems) end +## aliases -const ZIntervalMesh = IntervalMesh{<:Domains.ZIntervalDomain} +const XIntervalMesh = IntervalMesh{<:Domains.XIntervalDomain} +function XIntervalMesh(; + x_min::Real, x_max::Real, x_periodic::Bool=false, x_boundary_names=(:west, :east), + x_elem::Integer, x_stretch=Uniform(), +) + domain = Domains.XIntervalDomain(; x_min, x_max, x_periodic, x_boundary_names) + mesh = IntervalMesh(domain, x_stretch; nelem=x_elem) +end +const ZIntervalMesh = IntervalMesh{<:Domains.ZIntervalDomain} function ZIntervalMesh(; z_min::Real, z_max::Real, z_periodic::Bool=false, z_boundary_names=(:bottom, :top), z_elem::Integer, z_stretch=Uniform(), From 068e6aea31cd1eaea9d458da2b553d7dfd2ffd67 Mon Sep 17 00:00:00 2001 From: Simon Byrne Date: Wed, 10 Jan 2024 09:38:12 -0800 Subject: [PATCH 4/6] format --- src/Domains/Domains.jl | 54 ++++++++++++--- src/Grids/column.jl | 3 +- src/Grids/extruded.jl | 124 ++++++++++++++++++++++++++-------- src/Grids/finitedifference.jl | 17 ++++- src/Grids/spectralelement.jl | 66 +++++++++++++----- src/Meshes/interval.jl | 26 ++++--- src/Meshes/rectangle.jl | 12 +++- 7 files changed, 236 insertions(+), 66 deletions(-) diff --git a/src/Domains/Domains.jl b/src/Domains/Domains.jl index 4cc2c9c2bc..4838c7ca95 100644 --- a/src/Domains/Domains.jl +++ b/src/Domains/Domains.jl @@ -83,17 +83,47 @@ The domain minimum along the z-direction. """ z_min(domain::IntervalDomain) = domain.coord_min.z -function XIntervalDomain(; x_min::Real, x_max::Real, x_periodic::Bool=false, x_boundary_names=(:west, :east)) +function XIntervalDomain(; + x_min::Real, + x_max::Real, + x_periodic::Bool = false, + x_boundary_names = (:west, :east), +) x_min, x_max = promote(x_min, x_max) - IntervalDomain(Geometry.XPoint(x_min), Geometry.XPoint(x_max); periodic = x_periodic, boundary_names = x_boundary_names) + IntervalDomain( + Geometry.XPoint(x_min), + Geometry.XPoint(x_max); + periodic = x_periodic, + boundary_names = x_boundary_names, + ) end -function YIntervalDomain(; y_min::Real, y_max::Real, y_periodic::Bool=false, y_boundary_names=(:south, :north)) +function YIntervalDomain(; + y_min::Real, + y_max::Real, + y_periodic::Bool = false, + y_boundary_names = (:south, :north), +) y_min, y_max = promote(y_min, y_max) - IntervalDomain(Geometry.YPoint(y_min), Geometry.YPoint(y_max); periodic = y_periodic, boundary_names = y_boundary_names) + IntervalDomain( + Geometry.YPoint(y_min), + Geometry.YPoint(y_max); + periodic = y_periodic, + boundary_names = y_boundary_names, + ) end -function ZIntervalDomain(; z_min::Real, z_max::Real, z_periodic::Bool=false, z_boundary_names=(:bottom, :top)) +function ZIntervalDomain(; + z_min::Real, + z_max::Real, + z_periodic::Bool = false, + z_boundary_names = (:bottom, :top), +) z_min, z_max = promote(z_min, z_max) - IntervalDomain(Geometry.ZPoint(z_min), Geometry.ZPoint(z_max); periodic = z_periodic, boundary_names = z_boundary_names) + IntervalDomain( + Geometry.ZPoint(z_min), + Geometry.ZPoint(z_max); + periodic = z_periodic, + boundary_names = z_boundary_names, + ) end coordinate_type(::IntervalDomain{CT}) where {CT} = CT @@ -165,9 +195,15 @@ function RectangleDomain( end function XYRectangleDomain(; - x_min::Real, x_max::Real, x_periodic::Bool=false, x_boundary_names=(:west, :east), - y_min::Real, y_max::Real, y_periodic::Bool=false, y_boundary_names=(:south, :north), -) + x_min::Real, + x_max::Real, + x_periodic::Bool = false, + x_boundary_names = (:west, :east), + y_min::Real, + y_max::Real, + y_periodic::Bool = false, + y_boundary_names = (:south, :north), +) x_domain = XIntervalDomain(; x_min, x_max, x_periodic, x_boundary_names) y_domain = YIntervalDomain(; y_min, y_max, y_periodic, y_boundary_names) RectangleDomain(x_domain, y_domain) diff --git a/src/Grids/column.jl b/src/Grids/column.jl index 4ff071ab91..5c30d9a9c0 100644 --- a/src/Grids/column.jl +++ b/src/Grids/column.jl @@ -43,7 +43,8 @@ column(grid::AbstractExtrudedFiniteDifferenceGrid, colidx::ColumnIndex) = ColumnViewGrid(grid, colidx) topology(colgrid::ColumnViewGrid) = vertical_topology(colgrid.full_grid) -vertical_topology(colgrid::ColumnViewGrid) = vertical_topology(colgrid.full_grid) +vertical_topology(colgrid::ColumnViewGrid) = + vertical_topology(colgrid.full_grid) local_geometry_data(colgrid::ColumnViewGrid, staggering::Staggering) = column( local_geometry_data(colgrid.full_grid, staggering::Staggering), diff --git a/src/Grids/extruded.jl b/src/Grids/extruded.jl index 58951d9ff1..ff9fbbfe81 100644 --- a/src/Grids/extruded.jl +++ b/src/Grids/extruded.jl @@ -178,42 +178,90 @@ const ExtrudedSpectralElementGrid3D = -const PlaneGrid = - ExtrudedFiniteDifferenceGrid{<:LineSpectralElementGrid} +const PlaneGrid = ExtrudedFiniteDifferenceGrid{<:LineSpectralElementGrid} function PlaneGrid(; - x_min::Real, x_max::Real, x_elem, x_periodic::Bool=false, x_boundary_names = (:west, :east), + x_min::Real, + x_max::Real, + x_elem, + x_periodic::Bool = false, + x_boundary_names = (:west, :east), poly_degree = 3, - z_min::Real, z_max::Real, z_periodic::Bool=false, z_boundary_names=(:bottom, :top), - z_elem::Integer, z_stretch=Meshes.Uniform(), + z_min::Real, + z_max::Real, + z_periodic::Bool = false, + z_boundary_names = (:bottom, :top), + z_elem::Integer, + z_stretch = Meshes.Uniform(), context = ClimaComms.context(), - ) +) h_grid = LineSpectralElementGrid(; - x_min, x_max, x_elem, x_periodic, x_boundary_names, + x_min, + x_max, + x_elem, + x_periodic, + x_boundary_names, poly_degree, - context) - v_grid = ColumnGrid(; z_min, z_max, z_periodic, z_boundary_names, z_elem, z_stretch, context=ClimaComms.SingletonCommsContext(ClimaComms.device(context))) + context, + ) + v_grid = ColumnGrid(; + z_min, + z_max, + z_periodic, + z_boundary_names, + z_elem, + z_stretch, + context = ClimaComms.SingletonCommsContext(ClimaComms.device(context)), + ) ExtrudedFiniteDifferenceGrid(h_grid, v_grid) end -const BoxGrid = - ExtrudedFiniteDifferenceGrid{<:RectilinearSpectralElementGrid} +const BoxGrid = ExtrudedFiniteDifferenceGrid{<:RectilinearSpectralElementGrid} function BoxGrid(; - x_min::Real, x_max::Real, x_elem, x_periodic::Bool=false, x_boundary_names = (:west, :east), - y_min::Real, y_max::Real, y_elem, y_periodic::Bool=false, y_boundary_names = (:south, :north), + x_min::Real, + x_max::Real, + x_elem, + x_periodic::Bool = false, + x_boundary_names = (:west, :east), + y_min::Real, + y_max::Real, + y_elem, + y_periodic::Bool = false, + y_boundary_names = (:south, :north), poly_degree = 3, - z_min::Real, z_max::Real, z_periodic::Bool=false, z_boundary_names=(:bottom, :top), - z_elem::Integer, z_stretch=Meshes.Uniform(), + z_min::Real, + z_max::Real, + z_periodic::Bool = false, + z_boundary_names = (:bottom, :top), + z_elem::Integer, + z_stretch = Meshes.Uniform(), context = ClimaComms.context(), - ) +) h_grid = RectilinearSpectralElementGrid2D(; - x_min, x_max, x_elem, x_periodic, x_boundary_names, - y_min, y_max, y_elem, y_periodic, y_boundary_names, + x_min, + x_max, + x_elem, + x_periodic, + x_boundary_names, + y_min, + y_max, + y_elem, + y_periodic, + y_boundary_names, poly_degree, - context) - v_grid = ColumnGrid(; z_min, z_max, z_periodic, z_boundary_names, z_elem, z_stretch, context=ClimaComms.SingletonCommsContext(ClimaComms.device(context))) + context, + ) + v_grid = ColumnGrid(; + z_min, + z_max, + z_periodic, + z_boundary_names, + z_elem, + z_stretch, + context = ClimaComms.SingletonCommsContext(ClimaComms.device(context)), + ) ExtrudedFiniteDifferenceGrid(h_grid, v_grid) end @@ -222,17 +270,39 @@ const ExtrudedCubedSphereGrid = ExtrudedFiniteDifferenceGrid{<:CubedSphereSpectralElementGrid2D} function ExtrudedCubedSphereGrid(; - radius::Real, panel_elem::Integer, cubed_sphere_type = Meshes.EquiangularCubedSphere, - poly_degree = 3, bubble = true, - z_min::Real, z_max::Real, z_periodic::Bool=false, z_boundary_names=(:bottom, :top), - z_elem::Integer, z_stretch=Meshes.Uniform(), + radius::Real, + panel_elem::Integer, + cubed_sphere_type = Meshes.EquiangularCubedSphere, + poly_degree = 3, + bubble = true, + z_min::Real, + z_max::Real, + z_periodic::Bool = false, + z_boundary_names = (:bottom, :top), + z_elem::Integer, + z_stretch = Meshes.Uniform(), context = ClimaComms.context(), ) - h_grid = CubedSphereGrid(;radius, panel_elem, cubed_sphere_type, poly_degree, bubble, context) - v_grid = ColumnGrid(; z_min, z_max, z_periodic, z_boundary_names, z_elem, z_stretch, context=ClimaComms.SingletonCommsContext(ClimaComms.device(context))) + h_grid = CubedSphereGrid(; + radius, + panel_elem, + cubed_sphere_type, + poly_degree, + bubble, + context, + ) + v_grid = ColumnGrid(; + z_min, + z_max, + z_periodic, + z_boundary_names, + z_elem, + z_stretch, + context = ClimaComms.SingletonCommsContext(ClimaComms.device(context)), + ) ExtrudedFiniteDifferenceGrid(h_grid, v_grid) end ## to be deprecated const ExtrudedCubedSphereSpectralElementGrid3D = ExtrudedCubedSphereGrid -const ExtrudedRectilinearSpectralElementGrid3D = BoxGrid \ No newline at end of file +const ExtrudedRectilinearSpectralElementGrid3D = BoxGrid diff --git a/src/Grids/finitedifference.jl b/src/Grids/finitedifference.jl index d6a8545c55..a39189412b 100644 --- a/src/Grids/finitedifference.jl +++ b/src/Grids/finitedifference.jl @@ -218,11 +218,22 @@ const ColumnGrid = FiniteDifferenceGrid{<:Topologies.ColumnTopology1D} ) """ function ColumnGrid(; - z_min::Real, z_max::Real, z_periodic::Bool=false, z_boundary_names=(:bottom, :top), - z_elem::Integer, z_stretch=Meshes.Uniform(), + z_min::Real, + z_max::Real, + z_periodic::Bool = false, + z_boundary_names = (:bottom, :top), + z_elem::Integer, + z_stretch = Meshes.Uniform(), context = ClimaComms.SingletonCommsContext(), ) - mesh = Meshes.ZIntervalMesh(; z_min, z_max, z_periodic, z_boundary_names, z_elem, z_stretch) + mesh = Meshes.ZIntervalMesh(; + z_min, + z_max, + z_periodic, + z_boundary_names, + z_elem, + z_stretch, + ) topology = Topologies.IntervalTopology(mesh) FiniteDifferenceGrid(topology) end diff --git a/src/Grids/spectralelement.jl b/src/Grids/spectralelement.jl index 7dde7712d2..d9676e9d28 100644 --- a/src/Grids/spectralelement.jl +++ b/src/Grids/spectralelement.jl @@ -606,17 +606,29 @@ Adapt.adapt_structure(to, grid::SpectralElementGrid2D) = ## aliases -const LineSpectralElementGrid = SpectralElementGrid1D{<:Topologies.LineTopology1D} +const LineSpectralElementGrid = + SpectralElementGrid1D{<:Topologies.LineTopology1D} function LineSpectralElementGrid(; - x_min::Real, x_max::Real, x_periodic::Bool=false, x_boundary_names=(:west, :east), - x_elem::Integer, x_stretch=Uniform(), - poly_degree=3, - context=ClimaComms.SingletonCommsContext() + x_min::Real, + x_max::Real, + x_periodic::Bool = false, + x_boundary_names = (:west, :east), + x_elem::Integer, + x_stretch = Uniform(), + poly_degree = 3, + context = ClimaComms.SingletonCommsContext(), ) - mesh = XIntervalMesh(; x_min, x_max, x_periodic, x_boundary_names, x_elem, x_stretch) + mesh = XIntervalMesh(; + x_min, + x_max, + x_periodic, + x_boundary_names, + x_elem, + x_stretch, + ) topology = IntervalTopology(context, mesh) - quadrature_style = Quadratures.GLL{poly_degree+1}() + quadrature_style = Quadratures.GLL{poly_degree + 1}() SpectralElementGrid1D(topology, quadrature_style) end const RectilinearSpectralElementGrid = @@ -633,17 +645,37 @@ const RectilinearSpectralElementGrid = Constructor for a `SpectralElementGrid2D` on a `RectangleDomain`, with `XYPoint` coordinates. """ function RectilinearSpectralElementGrid(; - x_min::Real, x_max::Real, x_elem, x_periodic::Bool=false, x_boundary_names = (:west, :east), - y_min::Real, y_max::Real, y_elem, y_periodic::Bool=false, y_boundary_names = (:south, :north), + x_min::Real, + x_max::Real, + x_elem, + x_periodic::Bool = false, + x_boundary_names = (:west, :east), + y_min::Real, + y_max::Real, + y_elem, + y_periodic::Bool = false, + y_boundary_names = (:south, :north), context = ClimaComms.context(), - poly_degree=3, + poly_degree = 3, ) mesh = Meshes.RectilinearMesh(; - x_min, x_max, y_min, y_max, x_periodic, x_boundary_names, x_elem, - y_min, y_max, y_min, y_max, y_periodic, y_boundary_names, y_elem, - ) + x_min, + x_max, + y_min, + y_max, + x_periodic, + x_boundary_names, + x_elem, + y_min, + y_max, + y_min, + y_max, + y_periodic, + y_boundary_names, + y_elem, + ) topology = Topologies.Topology2D(context, mesh) - quadrature_style = Quadratures.GLL{poly_degree+1}() + quadrature_style = Quadratures.GLL{poly_degree + 1}() SpectralElementGrid2D(topology, quadrature_style) end @@ -651,7 +683,9 @@ const CubedSphereGrid = SpectralElementGrid2D{<:Topologies.CubedSphereTopology2D} function CubedSphereGrid(; - radius::Real, panel_elem::Integer, cubed_sphere_type = Meshes.EquiangularCubedSphere, + radius::Real, + panel_elem::Integer, + cubed_sphere_type = Meshes.EquiangularCubedSphere, context = ClimaComms.context(), poly_degree = 3, bubble = true, @@ -659,7 +693,7 @@ function CubedSphereGrid(; domain = Domains.SphereDomain(radius) mesh = cubed_sphere_type(domain, panel_elem) topology = Topologies.Topology2D(context, mesh) - quadrature_style = Quadratures.GLL{poly_degree+1}() + quadrature_style = Quadratures.GLL{poly_degree + 1}() SpectralElementGrid2D(topology, quadrature_style; bubble) end diff --git a/src/Meshes/interval.jl b/src/Meshes/interval.jl index a9eaa61291..4e02807eb6 100644 --- a/src/Meshes/interval.jl +++ b/src/Meshes/interval.jl @@ -459,18 +459,28 @@ end const XIntervalMesh = IntervalMesh{<:Domains.XIntervalDomain} function XIntervalMesh(; - x_min::Real, x_max::Real, x_periodic::Bool=false, x_boundary_names=(:west, :east), - x_elem::Integer, x_stretch=Uniform(), + x_min::Real, + x_max::Real, + x_periodic::Bool = false, + x_boundary_names = (:west, :east), + x_elem::Integer, + x_stretch = Uniform(), ) - domain = Domains.XIntervalDomain(; x_min, x_max, x_periodic, x_boundary_names) - mesh = IntervalMesh(domain, x_stretch; nelem=x_elem) + domain = + Domains.XIntervalDomain(; x_min, x_max, x_periodic, x_boundary_names) + mesh = IntervalMesh(domain, x_stretch; nelem = x_elem) end const ZIntervalMesh = IntervalMesh{<:Domains.ZIntervalDomain} function ZIntervalMesh(; - z_min::Real, z_max::Real, z_periodic::Bool=false, z_boundary_names=(:bottom, :top), - z_elem::Integer, z_stretch=Uniform(), + z_min::Real, + z_max::Real, + z_periodic::Bool = false, + z_boundary_names = (:bottom, :top), + z_elem::Integer, + z_stretch = Uniform(), ) - domain = Domains.ZIntervalDomain(; z_min, z_max, z_periodic, z_boundary_names) - mesh = IntervalMesh(domain, z_stretch; nelem=z_elem) + domain = + Domains.ZIntervalDomain(; z_min, z_max, z_periodic, z_boundary_names) + mesh = IntervalMesh(domain, z_stretch; nelem = z_elem) end diff --git a/src/Meshes/rectangle.jl b/src/Meshes/rectangle.jl index 6918516f8b..9f050c156e 100644 --- a/src/Meshes/rectangle.jl +++ b/src/Meshes/rectangle.jl @@ -33,8 +33,16 @@ end function RectilinearMesh(; - x_min::Real, x_max::Real, x_elem::Integer, x_periodic::Bool=false, x_boundary_names=(:west, :east), - y_min::Real, y_max::Real, y_elem::Integer, y_periodic::Bool=false, y_boundary_names=(:south, :north), + x_min::Real, + x_max::Real, + x_elem::Integer, + x_periodic::Bool = false, + x_boundary_names = (:west, :east), + y_min::Real, + y_max::Real, + y_elem::Integer, + y_periodic::Bool = false, + y_boundary_names = (:south, :north), ) x_domain = XIntervalDomain(; x_min, x_max, x_periodic, x_boundary_names) y_domain = YIntervalDomain(; y_min, y_max, y_periodic, y_boundary_names) From 9ba6f5b4dab4ac6b1da3536efe560781b96cc937 Mon Sep 17 00:00:00 2001 From: Simon Byrne Date: Wed, 10 Jan 2024 09:47:51 -0800 Subject: [PATCH 5/6] remove duplicate args --- src/Grids/spectralelement.jl | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/Grids/spectralelement.jl b/src/Grids/spectralelement.jl index d9676e9d28..fbd454ccc8 100644 --- a/src/Grids/spectralelement.jl +++ b/src/Grids/spectralelement.jl @@ -661,15 +661,11 @@ function RectilinearSpectralElementGrid(; mesh = Meshes.RectilinearMesh(; x_min, x_max, - y_min, - y_max, x_periodic, x_boundary_names, x_elem, y_min, y_max, - y_min, - y_max, y_periodic, y_boundary_names, y_elem, From af0a8fe90f551ce8f2a161cebe704728df690b63 Mon Sep 17 00:00:00 2001 From: Simon Byrne Date: Wed, 10 Jan 2024 11:00:41 -0800 Subject: [PATCH 6/6] PlaneGrid => SliceGrid --- src/Grids/extruded.jl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Grids/extruded.jl b/src/Grids/extruded.jl index ff9fbbfe81..f8c90d41b4 100644 --- a/src/Grids/extruded.jl +++ b/src/Grids/extruded.jl @@ -178,8 +178,8 @@ const ExtrudedSpectralElementGrid3D = -const PlaneGrid = ExtrudedFiniteDifferenceGrid{<:LineSpectralElementGrid} -function PlaneGrid(; +const SliceGrid = ExtrudedFiniteDifferenceGrid{<:LineSpectralElementGrid} +function SliceGrid(; x_min::Real, x_max::Real, x_elem,