Skip to content

Commit

Permalink
Merge pull request #324 from jbisits/add-gridpoints(OneDGrid)
Browse files Browse the repository at this point in the history
Add `gridpoints(::OneDGrid)` and tests
  • Loading branch information
navidcy committed Jun 14, 2022
2 parents cd2d3b8 + f276017 commit feb6a3f
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 2 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ coverage/
# MacOS stuff
*.DS_Store

# vs code
*.vscode
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ authors = ["Gregory L. Wagner <[email protected]>", "Navid C. Constantinou <
description = "Tools for building fast, hackable, pseudospectral partial differential equation solvers on periodic domains."
documentation = "https://fourierflows.github.io/FourierFlowsDocumentation/stable/"
repository = "https://github.com/FourierFlows/FourierFlows.jl"
version = "0.9.1"
version = "0.9.2"

[deps]
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
Expand Down
9 changes: 8 additions & 1 deletion src/domains.jl
Original file line number Diff line number Diff line change
Expand Up @@ -359,11 +359,18 @@ TwoDGrid(dev::CPU, args...; kwargs...) = TwoDGrid(args...; ArrayType=Array, kwar
ThreeDGrid(dev::CPU, args...; kwargs...) = ThreeDGrid(args...; ArrayType=Array, kwargs...)

"""
gridpoints(grid::OneDDGrid)
gridpoints(grid::TwoDGrid)
gridpoints(grid::ThreeDGrid)
Returns the collocation points of the `grid` in 2D or 3D arrays `X, Y` (and `Z`).
Returns the collocation points of the `grid` in 1D (`X`), 2D (`X, Y`) or 3D arrays (`X, Y, Z`).
"""
function gridpoints(grid::OneDGrid{T, A}) where {T, A}
X = [ grid.x[i] for i=1:grid.nx ]

return A(X)
end

function gridpoints(grid::TwoDGrid{T, A}) where {T, A}
X = [ grid.x[i₁] for i₁=1:grid.nx, i₂=1:grid.ny ]
Y = [ grid.y[i₂] for i₁=1:grid.nx, i₂=1:grid.ny ]
Expand Down
1 change: 1 addition & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ for dev in devices
@test testx(g₁)
@test testk(g₁)
@test testkr(g₁)
@test testgridpoints(dev, g₁)
@test testdealias(g₁)
@test testmakefilter(dev, g₁)

Expand Down
8 changes: 8 additions & 0 deletions test/test_grid.jl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ testl(g::Union{TwoDGrid, ThreeDGrid}) = testwavenumberalignment(g.l, g.ny)
testm(g::ThreeDGrid) = testwavenumberalignment(g.m, g.nz)
testkr(g) = CUDA.@allowscalar isapprox(cat(g.k[1:g.nkr-1], abs(g.k[g.nkr]), dims=1), g.kr)

function testgridpoints(dev::Device, g::OneDGrid{T}) where T
X = gridpoints(g)
dXgrid = @. X[2:end, :] - X[1:end-1, :]
dXones = ArrayType(dev)(g.dx*ones(T, size(dXgrid)))

return isapprox(dXgrid, dXones)
end

function testgridpoints(dev::Device, g::TwoDGrid{T}) where T
X, Y = gridpoints(g)
dXgrid = @. X[2:end, :] - X[1:end-1, :]
Expand Down

2 comments on commit feb6a3f

@navidcy
Copy link
Member Author

Choose a reason for hiding this comment

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

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

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

Registration pull request created: JuliaRegistries/General/62364

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.9.2 -m "<description of version>" feb6a3ff3152cda97e00ec0c636ab495cad30b2c
git push origin v0.9.2

Please sign in to comment.