Skip to content

Commit feb6a3f

Browse files
authored
Merge pull request #324 from jbisits/add-gridpoints(OneDGrid)
Add `gridpoints(::OneDGrid)` and tests
2 parents cd2d3b8 + f276017 commit feb6a3f

File tree

5 files changed

+20
-2
lines changed

5 files changed

+20
-2
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,5 @@ coverage/
2222
# MacOS stuff
2323
*.DS_Store
2424

25+
# vs code
26+
*.vscode

Project.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ authors = ["Gregory L. Wagner <wagner.greg@gmail.com>", "Navid C. Constantinou <
66
description = "Tools for building fast, hackable, pseudospectral partial differential equation solvers on periodic domains."
77
documentation = "https://fourierflows.github.io/FourierFlowsDocumentation/stable/"
88
repository = "https://github.com/FourierFlows/FourierFlows.jl"
9-
version = "0.9.1"
9+
version = "0.9.2"
1010

1111
[deps]
1212
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"

src/domains.jl

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,18 @@ TwoDGrid(dev::CPU, args...; kwargs...) = TwoDGrid(args...; ArrayType=Array, kwar
359359
ThreeDGrid(dev::CPU, args...; kwargs...) = ThreeDGrid(args...; ArrayType=Array, kwargs...)
360360

361361
"""
362+
gridpoints(grid::OneDDGrid)
362363
gridpoints(grid::TwoDGrid)
363364
gridpoints(grid::ThreeDGrid)
364365
365-
Returns the collocation points of the `grid` in 2D or 3D arrays `X, Y` (and `Z`).
366+
Returns the collocation points of the `grid` in 1D (`X`), 2D (`X, Y`) or 3D arrays (`X, Y, Z`).
366367
"""
368+
function gridpoints(grid::OneDGrid{T, A}) where {T, A}
369+
X = [ grid.x[i] for i=1:grid.nx ]
370+
371+
return A(X)
372+
end
373+
367374
function gridpoints(grid::TwoDGrid{T, A}) where {T, A}
368375
X = [ grid.x[i₁] for i₁=1:grid.nx, i₂=1:grid.ny ]
369376
Y = [ grid.y[i₂] for i₁=1:grid.nx, i₂=1:grid.ny ]

test/runtests.jl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ for dev in devices
5656
@test testx(g₁)
5757
@test testk(g₁)
5858
@test testkr(g₁)
59+
@test testgridpoints(dev, g₁)
5960
@test testdealias(g₁)
6061
@test testmakefilter(dev, g₁)
6162

test/test_grid.jl

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,14 @@ testl(g::Union{TwoDGrid, ThreeDGrid}) = testwavenumberalignment(g.l, g.ny)
4747
testm(g::ThreeDGrid) = testwavenumberalignment(g.m, g.nz)
4848
testkr(g) = CUDA.@allowscalar isapprox(cat(g.k[1:g.nkr-1], abs(g.k[g.nkr]), dims=1), g.kr)
4949

50+
function testgridpoints(dev::Device, g::OneDGrid{T}) where T
51+
X = gridpoints(g)
52+
dXgrid = @. X[2:end, :] - X[1:end-1, :]
53+
dXones = ArrayType(dev)(g.dx*ones(T, size(dXgrid)))
54+
55+
return isapprox(dXgrid, dXones)
56+
end
57+
5058
function testgridpoints(dev::Device, g::TwoDGrid{T}) where T
5159
X, Y = gridpoints(g)
5260
dXgrid = @. X[2:end, :] - X[1:end-1, :]

0 commit comments

Comments
 (0)