Skip to content

Commit

Permalink
Merge pull request #141 from JuliaGeodynamics/adm/new_function
Browse files Browse the repository at this point in the history
Fuse center and vertex phase ratio functions
  • Loading branch information
albert-de-montserrat authored Sep 25, 2024
2 parents 5aef76d + bed9db2 commit 87fdb05
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 9 deletions.
12 changes: 12 additions & 0 deletions ext/JustPICAMDGPUExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,12 @@ module _2D

# Phase ratio kernels

function JustPIC._2D.update_phase_ratios!(phase_ratios::JustPIC.PhaseRatios{AMDGPUBackend}, particles, xci, xvi, phases)
phase_ratios_center!(phase_ratios, particles, xci, phases)
phase_ratios_vertex!(phase_ratios, particles, xvi, phases)
return nothing
end

function JustPIC._2D.PhaseRatios(
::Type{AMDGPUBackend}, nphases::Integer, ni::NTuple{N,Integer}
) where {N}
Expand Down Expand Up @@ -455,6 +461,12 @@ module _3D

# Phase ratio kernels

function JustPIC._3D.update_phase_ratios!(phase_ratios::JustPIC.PhaseRatios{AMDGPUBackend}, particles, xci, xvi, phases)
phase_ratios_center!(phase_ratios, particles, xci, phases)
phase_ratios_vertex!(phase_ratios, particles, xvi, phases)
return nothing
end

function JustPIC._3D.PhaseRatios(
::Type{AMDGPUBackend}, nphases::Integer, ni::NTuple{N,Integer}
) where {N}
Expand Down
12 changes: 12 additions & 0 deletions ext/JustPICCUDAExt.jl
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,12 @@ module _2D

# Phase ratio kernels

function JustPIC._2D.update_phase_ratios!(phase_ratios::JustPIC.PhaseRatios{CUDABackend}, particles, xci, xvi, phases)
phase_ratios_center!(phase_ratios, particles, xci, phases)
phase_ratios_vertex!(phase_ratios, particles, xvi, phases)
return nothing
end

function JustPIC._2D.PhaseRatios(
::Type{CUDABackend}, nphases::Integer, ni::NTuple{N,Integer}
) where {N}
Expand Down Expand Up @@ -450,6 +456,12 @@ module _3D

# Phase ratio kernels

function JustPIC._3D.update_phase_ratios!(phase_ratios::JustPIC.PhaseRatios{CUDABackend}, particles, xci, xvi, phases)
phase_ratios_center!(phase_ratios, particles, xci, phases)
phase_ratios_vertex!(phase_ratios, particles, xvi, phases)
return nothing
end

function JustPIC._3D.PhaseRatios(
::Type{CUDABackend}, nphases::Integer, ni::NTuple{N,Integer}
) where {N}
Expand Down
6 changes: 6 additions & 0 deletions src/PhaseRatios/kernels.jl
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
function update_phase_ratios!(phase_ratios::JustPIC.PhaseRatios, particles, xci, xvi, phases)
phase_ratios_center!(phase_ratios, particles, xci, phases)
phase_ratios_vertex!(phase_ratios, particles, xvi, phases)
return nothing
end

## Kernels to compute phase ratios at the centers

function phase_ratios_center!(phase_ratios::JustPIC.PhaseRatios, particles, xci, phases)
Expand Down
2 changes: 1 addition & 1 deletion src/common.jl
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ include("PhaseRatios/constructors.jl")
export PhaseRatios

include("PhaseRatios/kernels.jl")
export phase_ratios_center!, phase_ratios_vertex!
export update_phase_ratios!, phase_ratios_center!, phase_ratios_vertex!
16 changes: 8 additions & 8 deletions test/test_CellArrays.jl
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
using JustPIC, Test, StaticArrays

@testset "CellArrays - 2D" begin
x = 1e0
x = 1e0
ni = (2, 2)

## Test a 2x2 grid with 2x1 CellArrays per grid cell
Expand Down Expand Up @@ -48,13 +48,13 @@ end

nphases = 5
phases, = JustPIC._2D.init_cell_arrays(particles, Val(1));
phases.data .= rand(1:nphases, size(phases.data));
T = typeof(phases.data)
phases.data .= T(rand(1:nphases, size(phases.data)));

phase_ratios = JustPIC._2D.PhaseRatios(backend, nphases, ni);

JustPIC._2D.phase_ratios_vertex!(phase_ratios, particles, xvi, phases)
JustPIC._2D.phase_ratios_center!(phase_ratios, particles, xci, phases)

JustPIC._2D.update_phase_ratios!(phase_ratios, particles, xci, xvi, phases)

@test sum(phase_ratios.vertex.data) prod(ni.+1)
@test sum(phase_ratios.center.data) prod(ni)
end
Expand Down Expand Up @@ -108,12 +108,12 @@ end

nphases = 5
phases, = JustPIC._3D.init_cell_arrays(particles, Val(1));
phases.data .= rand(1:nphases, size(phases.data));
T = typeof(phases.data)
phases.data .= T(rand(1:nphases, size(phases.data)));

phase_ratios = JustPIC._3D.PhaseRatios(backend, nphases, ni);

JustPIC._3D.phase_ratios_vertex!(phase_ratios, particles, xvi, phases)
JustPIC._3D.phase_ratios_center!(phase_ratios, particles, xci, phases)
JustPIC._3D.update_phase_ratios!(phase_ratios, particles, xci, xvi, phases)

@test sum(phase_ratios.vertex.data) prod(ni.+1)
@test sum(phase_ratios.center.data) prod(ni)
Expand Down

0 comments on commit 87fdb05

Please sign in to comment.