Skip to content

Commit ba58b2a

Browse files
eliascarvgithub-actions[bot]juliohm
authored
Generalize dispatch to OrthoRegularGrid (#1079)
* Update definition of grid methods * Apply suggestions * Apply suggestions * Apply suggestions from code review Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Update src/domains/meshes/cartesiangrid.jl * Apply suggestions * Format Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> * Apply suggestions * Format Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> --------- Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Júlio Hoffimann <[email protected]>
1 parent 10b15de commit ba58b2a

File tree

7 files changed

+16
-13
lines changed

7 files changed

+16
-13
lines changed

src/boundingboxes.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ end
6969

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

72-
boundingbox(g::CartesianGrid) = Box(extrema(g)...)
72+
boundingbox(g::OrthoRegularGrid) = Box(extrema(g)...)
7373

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

src/centroid.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ centroid(d::Domain, ind::Int) = centroid(d[ind])
6565

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

68-
function centroid(g::RegularGrid{<:𝔼,<:CartesianOrProjected}, ind::Int)
68+
function centroid(g::OrthoRegularGrid, ind::Int)
6969
ijk = elem2cart(topology(g), ind)
7070
vertex(g, ijk) + Vec(spacing(g) ./ 2)
7171
end

src/coarsening/regular.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ end
2020

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

23-
function coarsen(grid::CartesianGrid, method::RegularCoarsening)
23+
function coarsen(grid::OrthoRegularGrid, method::RegularCoarsening)
2424
factors = fitdims(method.factors, paramdim(grid))
25-
CartesianGrid(minimum(grid), maximum(grid), dims=size(grid) factors)
25+
RegularGrid(minimum(grid), maximum(grid), dims=size(grid) factors)
2626
end
2727

2828
function coarsen(grid::RectilinearGrid, method::RegularCoarsening)

src/domains/meshes.jl

+3
Original file line numberDiff line numberDiff line change
@@ -246,3 +246,6 @@ include("meshes/rectilineargrid.jl")
246246
include("meshes/structuredgrid.jl")
247247
include("meshes/simplemesh.jl")
248248
include("meshes/transformedmesh.jl")
249+
250+
# alias for dispatch purposes
251+
const OrthoRegularGrid{M<:𝔼,C<:Union{Cartesian,Projected}} = RegularGrid{M,C}

src/indices.jl

+6-6
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ Return the indices of the elements of the `domain` that intersect with the `geom
1313
"""
1414
indices(domain::Domain, geometry::Geometry) = findall(intersects(geometry), domain)
1515

16-
function indices(grid::CartesianGrid, point::Point)
16+
function indices(grid::OrthoRegularGrid, point::Point)
1717
point grid && return Int[]
1818

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

34-
function indices(grid::CartesianGrid, chain::Chain)
34+
function indices(grid::OrthoRegularGrid, chain::Chain)
3535
dims = size(grid)
3636
mask = falses(dims)
3737

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

46-
function indices(grid::CartesianGrid, poly::Polygon)
46+
function indices(grid::OrthoRegularGrid, poly::Polygon)
4747
dims = size(grid)
4848
mask = zeros(Int, dims)
4949
cpoly = poly boundingbox(grid)
@@ -56,15 +56,15 @@ function indices(grid::CartesianGrid, poly::Polygon)
5656
LinearIndices(dims)[mask .> 0]
5757
end
5858

59-
function indices(grid::CartesianGrid, box::Box)
59+
function indices(grid::OrthoRegularGrid, box::Box)
6060
# cartesian range
6161
range = cartesianrange(grid, box)
6262

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

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

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

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

92-
function _euclideanrange(grid::CartesianGrid, box::Box)
92+
function _euclideanrange(grid::OrthoRegularGrid, box::Box)
9393
# grid properties
9494
or = minimum(grid)
9595
sp = spacing(grid)

src/refinement/regular.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ end
2020

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

23-
function refine(grid::CartesianGrid, method::RegularRefinement)
23+
function refine(grid::OrthoRegularGrid, method::RegularRefinement)
2424
factors = fitdims(method.factors, paramdim(grid))
25-
CartesianGrid(minimum(grid), maximum(grid), dims=size(grid) .* factors)
25+
RegularGrid(minimum(grid), maximum(grid), dims=size(grid) .* factors)
2626
end
2727

2828
function refine(grid::RectilinearGrid, method::RegularRefinement)

src/sampling/regular.jl

+1-1
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,6 @@ extrapoints(c::FrustumSurface, sz) = (bottom(c)(0, 0), top(c)(0, 0))
8787
# SPECIAL CASES
8888
# --------------
8989

90-
function sample(rng::AbstractRNG, grid::CartesianGrid, method::RegularSampling)
90+
function sample(rng::AbstractRNG, grid::OrthoRegularGrid, method::RegularSampling)
9191
sample(rng, boundingbox(grid), method)
9292
end

0 commit comments

Comments
 (0)