Skip to content

Generalize dispatch to OrthoRegularGrid #1079

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

Merged
merged 9 commits into from
Sep 20, 2024
Merged
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
2 changes: 1 addition & 1 deletion src/boundingboxes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ end

boundingbox(t::Torus) = _pboxes(pointify(t))

boundingbox(g::CartesianGrid) = Box(extrema(g)...)
boundingbox(g::OrthoRegularGrid) = Box(extrema(g)...)

boundingbox(g::RectilinearGrid) = Box(extrema(g)...)

Expand Down
2 changes: 1 addition & 1 deletion src/centroid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ centroid(d::Domain, ind::Int) = centroid(d[ind])

centroid(d::SubDomain, ind::Int) = centroid(parent(d), parentindices(d)[ind])

function centroid(g::RegularGrid{<:𝔼,<:CartesianOrProjected}, ind::Int)
function centroid(g::OrthoRegularGrid, ind::Int)
ijk = elem2cart(topology(g), ind)
vertex(g, ijk) + Vec(spacing(g) ./ 2)
end
Expand Down
4 changes: 2 additions & 2 deletions src/coarsening/regular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ end

RegularCoarsening(factors::Vararg{Int,N}) where {N} = RegularCoarsening(factors)

function coarsen(grid::CartesianGrid, method::RegularCoarsening)
function coarsen(grid::OrthoRegularGrid, method::RegularCoarsening)
factors = fitdims(method.factors, paramdim(grid))
CartesianGrid(minimum(grid), maximum(grid), dims=size(grid) .÷ factors)
RegularGrid(minimum(grid), maximum(grid), dims=size(grid) .÷ factors)
end

function coarsen(grid::RectilinearGrid, method::RegularCoarsening)
Expand Down
3 changes: 3 additions & 0 deletions src/domains/meshes.jl
Original file line number Diff line number Diff line change
Expand Up @@ -246,3 +246,6 @@ include("meshes/rectilineargrid.jl")
include("meshes/structuredgrid.jl")
include("meshes/simplemesh.jl")
include("meshes/transformedmesh.jl")

# alias for dispatch purposes
const OrthoRegularGrid{M<:𝔼,C<:Union{Cartesian,Projected}} = RegularGrid{M,C}
12 changes: 6 additions & 6 deletions src/indices.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ Return the indices of the elements of the `domain` that intersect with the `geom
"""
indices(domain::Domain, geometry::Geometry) = findall(intersects(geometry), domain)

function indices(grid::CartesianGrid, point::Point)
function indices(grid::OrthoRegularGrid, point::Point)
point ∉ grid && return Int[]

# grid properties
Expand All @@ -31,7 +31,7 @@ function indices(grid::CartesianGrid, point::Point)
[LinearIndices(dims)[coords...]]
end

function indices(grid::CartesianGrid, chain::Chain)
function indices(grid::OrthoRegularGrid, chain::Chain)
dims = size(grid)
mask = falses(dims)

Expand All @@ -43,7 +43,7 @@ function indices(grid::CartesianGrid, chain::Chain)
LinearIndices(dims)[mask]
end

function indices(grid::CartesianGrid, poly::Polygon)
function indices(grid::OrthoRegularGrid, poly::Polygon)
dims = size(grid)
mask = zeros(Int, dims)
cpoly = poly ∩ boundingbox(grid)
Expand All @@ -56,15 +56,15 @@ function indices(grid::CartesianGrid, poly::Polygon)
LinearIndices(dims)[mask .> 0]
end

function indices(grid::CartesianGrid, box::Box)
function indices(grid::OrthoRegularGrid, box::Box)
# cartesian range
range = cartesianrange(grid, box)

# convert to linear indices
LinearIndices(size(grid))[range] |> vec
end

indices(grid::CartesianGrid, multi::Multi) = mapreduce(geom -> indices(grid, geom), vcat, parent(multi)) |> unique
indices(grid::OrthoRegularGrid, multi::Multi) = mapreduce(geom -> indices(grid, geom), vcat, parent(multi)) |> unique

function indices(grid::RectilinearGrid, box::Box)
# cartesian range
Expand All @@ -89,7 +89,7 @@ _manifoldrange(::Type{<:𝔼}, grid::Grid, box::Box) = _euclideanrange(grid, box

_manifoldrange(::Type{<:🌐}, grid::Grid, box::Box) = _geodesicrange(grid, box)

function _euclideanrange(grid::CartesianGrid, box::Box)
function _euclideanrange(grid::OrthoRegularGrid, box::Box)
# grid properties
or = minimum(grid)
sp = spacing(grid)
Expand Down
4 changes: 2 additions & 2 deletions src/refinement/regular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,9 @@ end

RegularRefinement(factors::Vararg{Int,N}) where {N} = RegularRefinement(factors)

function refine(grid::CartesianGrid, method::RegularRefinement)
function refine(grid::OrthoRegularGrid, method::RegularRefinement)
factors = fitdims(method.factors, paramdim(grid))
CartesianGrid(minimum(grid), maximum(grid), dims=size(grid) .* factors)
RegularGrid(minimum(grid), maximum(grid), dims=size(grid) .* factors)
end

function refine(grid::RectilinearGrid, method::RegularRefinement)
Expand Down
2 changes: 1 addition & 1 deletion src/sampling/regular.jl
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,6 @@ extrapoints(c::FrustumSurface, sz) = (bottom(c)(0, 0), top(c)(0, 0))
# SPECIAL CASES
# --------------

function sample(rng::AbstractRNG, grid::CartesianGrid, method::RegularSampling)
function sample(rng::AbstractRNG, grid::OrthoRegularGrid, method::RegularSampling)
sample(rng, boundingbox(grid), method)
end
Loading