Skip to content

Commit

Permalink
add tests, release v0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
islent committed Mar 22, 2024
1 parent bc95c4a commit 7697b95
Show file tree
Hide file tree
Showing 4 changed files with 191 additions and 0 deletions.
35 changes: 35 additions & 0 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
name: CI

on: [push, pull_request, workflow_dispatch]

# 64-bit Julia only
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
if: "!contains(github.event.head_commit.message, '[skip ci]') && !contains(github.event.head_commit.message, 'CompatHelper')"
strategy:
matrix:
version:
- '1.10.2'
os:
- ubuntu-latest
- macOS-latest
- windows-latest
arch:
- x64
steps:
- run: echo ACTIONS_RUNNER_DEBUG true
- uses: actions/[email protected]
- name: "Set up Julia"
uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
#- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest
#env:
# ACTIONS_RUNNER_DEBUG: true
- uses: julia-actions/julia-uploadcodecov@latest
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
15 changes: 15 additions & 0 deletions .github/workflows/TagBot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
name: TagBot
on:
issue_comment:
types:
- created
workflow_dispatch:
jobs:
TagBot:
if: github.event_name == 'workflow_dispatch' || github.actor == 'JuliaTagBot'
runs-on: ubuntu-latest
steps:
- uses: JuliaRegistries/TagBot@v1
with:
token: ${{ secrets.GITHUB_TOKEN }}
ssh: ${{ secrets.DOCUMENTER_KEY }}
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# PhysicalFFT.jl

[![codecov](https://codecov.io/gh/JuliaAstroSim/PhysicalFFT.jl/graph/badge.svg?token=AtZqmsUQEj)](https://codecov.io/gh/JuliaAstroSim/PhysicalFFT.jl)

FFT solvers in Julia language

WARNING: *This package is under development!!!*
Expand Down Expand Up @@ -35,6 +37,33 @@ This package is extracted from [AstroNbodySim.jl](https://github.com/JuliaAstroS

```julia
using PhysicalFFT
using PhysicalMeshes

sol(p::PVector) = sin(2*pi*p.x) * sin(2*pi*p.y) * sin(2*pi*p.z) + sin(32*pi*p.x) * sin(32*pi*p.y) * sin(2*pi*p.z) / 256
init_rho(p::PVector) = -12 * pi * pi * sin(2*pi*p.x) * sin(2*pi*p.y) * sin(2*pi*p.z) - 12 * pi * pi * sin(32*pi*p.x) * sin(32*pi*p.y) * sin(32*pi*p.z)

function test_fft3D(Nx, boundary=Periodic())
m = MeshCartesianStatic(;
xMin = 0.0,
yMin = 0.0,
zMin = 0.0,
xMax = 1.0,
yMax = 1.0,
zMax = 1.0,
Nx = Nx - 1,
Ny = Nx - 1,
Nz = Nx - 1,
NG = 0,
dim = 3,
boundary,
)
m.rho .= init_rho.(m.pos)
fft_poisson!(m, m.rho, m.config.boundary)
s = sol.(m.pos)
r = m.phi .- s

return L2norm(r)
end

test_fft3D(8, Periodic())
```
112 changes: 112 additions & 0 deletions test/runtests.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,112 @@
using Test
using AstroSimBase
using PhysicalMeshes
using PhysicalMeshes.PhysicalParticles
using PhysicalFFT

sol(x::Real) = sin(2*pi*x) + sin(32*pi*x) / 256
init_rho(x::Real) = -4*pi*pi*sin(2*pi*x) - 4*pi*pi*sin(32*pi*x)

sol(p::PVector2D) = sin(2*pi*p.x) * sin(2*pi*p.y) + sin(32*pi*p.x) * sin(32*pi*p.y) / 256
init_rho(p::PVector2D) = -8 * pi * pi * sin(2*pi*p.x) * sin(2*pi*p.y) - 8 * pi * pi * sin(32*pi*p.x) * sin(32*pi*p.y)

sol(p::PVector) = sin(2*pi*p.x) * sin(2*pi*p.y) * sin(2*pi*p.z) + sin(32*pi*p.x) * sin(32*pi*p.y) * sin(2*pi*p.z) / 256
init_rho(p::PVector) = -12 * pi * pi * sin(2*pi*p.x) * sin(2*pi*p.y) * sin(2*pi*p.z) - 12 * pi * pi * sin(32*pi*p.x) * sin(32*pi*p.y) * sin(32*pi*p.z)

L2norm(r) = sqrt(sum((r.^2)/prod(size(r))))

@testset "1D" begin
function test_fft1D(Nx, boundary=Periodic())
m = MeshCartesianStatic(;
xMin = 0.0,
xMax = 1.0,
Nx = Nx - 1,
NG = 0,
dim = 1,
boundary,
)
m.rho .= init_rho.(m.pos)
fft_poisson!(m, m.rho, m.config.boundary)
s = sol.(m.pos)
r = m.phi .- s

return L2norm(r)
end

@testset "Periodic" begin
@test test_fft1D(8, Periodic()) < 0.5
@test test_fft1D(128, Periodic()) < 0.016
end

@testset "Dirichlet" begin
@test test_fft1D(8, Dirichlet()) < 0.7
@test test_fft1D(128, Dirichlet()) < 0.031
end
end

@testset "2D" begin
function test_fft2D(Nx, boundary=Periodic())
m = MeshCartesianStatic(;
xMin = 0.0,
yMin = 0.0,
xMax = 1.0,
yMax = 1.0,
Nx = Nx - 1,
Ny = Nx - 1,
NG = 0,
dim = 2,
boundary,
)
m.rho .= init_rho.(m.pos)
fft_poisson!(m, m.rho, m.config.boundary)
s = sol.(m.pos)
r = m.phi .- s

return L2norm(r)
end

@testset "Periodic" begin
@test test_fft2D(8, Periodic()) < 0.3
@test test_fft2D(128, Periodic()) < 0.012
end

@testset "Dirichlet" begin
@test test_fft2D(8, Dirichlet()) < 0.3
@test test_fft2D(128, Dirichlet()) < 0.02
end
end

@testset "3D" begin
function test_fft3D(Nx, boundary=Periodic())
m = MeshCartesianStatic(;
xMin = 0.0,
yMin = 0.0,
zMin = 0.0,
xMax = 1.0,
yMax = 1.0,
zMax = 1.0,
Nx = Nx - 1,
Ny = Nx - 1,
Nz = Nx - 1,
NG = 0,
dim = 3,
boundary,
)
m.rho .= init_rho.(m.pos)
fft_poisson!(m, m.rho, m.config.boundary)
s = sol.(m.pos)
r = m.phi .- s

return L2norm(r)
end

@testset "Periodic" begin
@test test_fft3D(8, Periodic()) < 0.15
@test test_fft3D(16, Periodic()) < 0.41
end

@testset "Dirichlet" begin
@test test_fft3D(8, Dirichlet()) < 0.14
@test test_fft3D(16, Dirichlet()) < 0.40
end
end

0 comments on commit 7697b95

Please sign in to comment.