Skip to content

Commit 10b15de

Browse files
eliascarvjuliohm
andauthored
Update the method definition of centroid of grids (#1078)
* Update the method definition of 'centroid' of grids * Add more tests * Update src/utils.jl --------- Co-authored-by: Júlio Hoffimann <[email protected]>
1 parent fe93665 commit 10b15de

File tree

3 files changed

+8
-3
lines changed

3 files changed

+8
-3
lines changed

src/centroid.jl

+2-2
Original file line numberDiff line numberDiff line change
@@ -65,12 +65,12 @@ 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::CartesianGrid, ind::Int)
68+
function centroid(g::RegularGrid{<:𝔼,<:CartesianOrProjected}, ind::Int)
6969
ijk = elem2cart(topology(g), ind)
7070
vertex(g, ijk) + Vec(spacing(g) ./ 2)
7171
end
7272

73-
function centroid(g::RectilinearGrid, ind::Int)
73+
function centroid(g::RectilinearGrid{<:𝔼,<:CartesianOrProjected}, ind::Int)
7474
ijk = elem2cart(topology(g), ind)
7575
p1 = vertex(g, ijk)
7676
p2 = vertex(g, ijk .+ 1)

src/utils.jl

+2-1
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
# Licensed under the MIT License. See LICENSE in the project root.
33
# ------------------------------------------------------------------
44

5-
# auxiliary type for dispatch purposes
5+
# auxiliary types for dispatch purposes
66
const GeometryOrDomain = Union{Geometry,Domain}
7+
const CartesianOrProjected = Union{Cartesian,Projected}
78

89
include("utils/basic.jl")
910
include("utils/assert.jl")

test/meshes.jl

+4
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
@test eltype(grid) <: Quadrangle
1414
@test vertex(grid, 1) == vertex(grid, (1, 1))
1515
@test vertex(grid, nvertices(grid)) == vertex(grid, (11, 21))
16+
@test centroid(grid, 1) == centroid(grid[1])
1617
@test grid[1, 1] == grid[1]
1718
@test grid[10, 20] == grid[200]
1819

@@ -30,6 +31,7 @@
3031
@test eltype(grid) <: Quadrangle
3132
@test vertex(grid, 1) == vertex(grid, (1, 1))
3233
@test vertex(grid, nvertices(grid)) == vertex(grid, (11, 21))
34+
@test centroid(grid, 1) == centroid(grid[1])
3335
@test grid[1, 1] == grid[1]
3436
@test grid[10, 20] == grid[200]
3537

@@ -47,6 +49,7 @@
4749
@test eltype(grid) <: Quadrangle
4850
@test vertex(grid, 1) == vertex(grid, (1, 1))
4951
@test vertex(grid, nvertices(grid)) == vertex(grid, (11, 21))
52+
@test centroid(grid, 1) == centroid(grid[1])
5053
@test grid[1, 1] == grid[1]
5154
@test grid[10, 20] == grid[200]
5255

@@ -64,6 +67,7 @@
6467
@test eltype(grid) <: Hexahedron
6568
@test vertex(grid, 1) == vertex(grid, (1, 1, 1))
6669
@test vertex(grid, nvertices(grid)) == vertex(grid, (11, 21, 31))
70+
@test centroid(grid, 1) == centroid(grid[1])
6771
@test grid[1, 1, 1] == grid[1]
6872
@test grid[10, 20, 30] == grid[6000]
6973

0 commit comments

Comments
 (0)