From 7697b95e600828b0024e93f1266b9df4879aeb6d Mon Sep 17 00:00:00 2001 From: islent Date: Fri, 22 Mar 2024 22:19:40 +0800 Subject: [PATCH] add tests, release v0.1.0 --- .github/workflows/CI.yml | 35 +++++++++++ .github/workflows/TagBot.yml | 15 +++++ README.md | 29 +++++++++ test/runtests.jl | 112 +++++++++++++++++++++++++++++++++++ 4 files changed, 191 insertions(+) create mode 100644 .github/workflows/CI.yml create mode 100644 .github/workflows/TagBot.yml diff --git a/.github/workflows/CI.yml b/.github/workflows/CI.yml new file mode 100644 index 0000000..29d3d3e --- /dev/null +++ b/.github/workflows/CI.yml @@ -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/checkout@v1.0.0 + - 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 }} \ No newline at end of file diff --git a/.github/workflows/TagBot.yml b/.github/workflows/TagBot.yml new file mode 100644 index 0000000..623860f --- /dev/null +++ b/.github/workflows/TagBot.yml @@ -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 }} \ No newline at end of file diff --git a/README.md b/README.md index 062cb11..3f15e62 100644 --- a/README.md +++ b/README.md @@ -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!!!* @@ -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()) ``` \ No newline at end of file diff --git a/test/runtests.jl b/test/runtests.jl index e69de29..a4ac032 100644 --- a/test/runtests.jl +++ b/test/runtests.jl @@ -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 \ No newline at end of file