Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add convenience constructors for grids #1567

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
64 changes: 64 additions & 0 deletions src/Domains/Domains.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -79,6 +83,49 @@ The domain minimum along the z-direction.
"""
z_min(domain::IntervalDomain) = domain.coord_min.z

function XIntervalDomain(;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Sbozzolo what do you think about adding doc strings to all of these convenience constructors, so that users know what the kwargs are? I think just copying the code itself into the doc string should be pretty self explanatory, and it'll be easy to keep up-to-date.

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)

Expand Down Expand Up @@ -108,6 +155,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)

Expand Down Expand Up @@ -144,6 +194,20 @@ 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)), ": ")
Expand Down
15 changes: 8 additions & 7 deletions src/Grids/column.jl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -40,14 +40,15 @@ 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)
133 changes: 130 additions & 3 deletions src/Grids/extruded.jl
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,134 @@ const ExtrudedSpectralElementGrid2D =
ExtrudedFiniteDifferenceGrid{<:SpectralElementGrid1D}
const ExtrudedSpectralElementGrid3D =
ExtrudedFiniteDifferenceGrid{<:SpectralElementGrid2D}
const ExtrudedRectilinearSpectralElementGrid3D =
ExtrudedFiniteDifferenceGrid{<:RectilinearSpectralElementGrid2D}
const ExtrudedCubedSphereSpectralElementGrid3D =



const SliceGrid = ExtrudedFiniteDifferenceGrid{<:LineSpectralElementGrid}
function SliceGrid(;
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}

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 = ExtrudedCubedSphereGrid
const ExtrudedRectilinearSpectralElementGrid3D = BoxGrid
31 changes: 31 additions & 0 deletions src/Grids/finitedifference.jl
Original file line number Diff line number Diff line change
Expand Up @@ -206,3 +206,34 @@ 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
Loading
Loading