diff --git a/.github/workflows/Format.yml b/.github/workflows/Format.yml index 1ef6159..c718b1e 100644 --- a/.github/workflows/Format.yml +++ b/.github/workflows/Format.yml @@ -7,11 +7,7 @@ on: permissions: contents: read - - # needed for julia-actions/cache to delete old caches actions: write - - # needed for googleapis/code-suggester pull-requests: write jobs: @@ -19,12 +15,18 @@ jobs: runs-on: ubuntu-latest if: github.event.pull_request.draft == false steps: - - uses: actions/checkout@v4 + - name: Check out repository + uses: actions/checkout@v4 with: ref: ${{github.event.pull_request.head.ref}} repository: ${{github.event.pull_request.head.repo.full_name}} fetch-depth: 0 + - name: Add upstream remote + run: | + git remote add upstream https://github.com/${{ github.repository }} + git fetch upstream + - name: Setup Julia uses: julia-actions/setup-julia@v2 with: @@ -42,19 +44,19 @@ jobs: - name: Run Runic id: runic run: | - set +e - MERGE_BASE=$(git merge-base upstream/${{ github.base_ref }} HEAD) || exit 1 - DIFF=$(git runic --diff $MERGE_BASE) - EXIT_CODE=$? - - echo "exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT - echo "diff<> $GITHUB_OUTPUT - echo "$DIFF" >> $GITHUB_OUTPUT - echo "EOF" >> $GITHUB_OUTPUT - - # if Runic failed, bail out - [ $EXIT_CODE -eq 2 ] && exit 1 || exit 0 - + set +e + MERGE_BASE=$(git merge-base upstream/${{ github.base_ref }} HEAD) || exit 1 + DIFF=$(git runic --diff $MERGE_BASE) + EXIT_CODE=$? + + echo "exit_code=$EXIT_CODE" >> $GITHUB_OUTPUT + echo "diff<> $GITHUB_OUTPUT + echo "$DIFF" >> $GITHUB_OUTPUT + echo "EOF" >> $GITHUB_OUTPUT + + # if Runic failed, bail out + [ $EXIT_CODE -eq 2 ] && exit 1 || exit 0 + - name: Find comment uses: peter-evans/find-comment@v3 id: find-comment @@ -62,7 +64,7 @@ jobs: issue-number: ${{ github.event.pull_request.number }} comment-author: 'github-actions[bot]' body-includes: '' - + - name: Comment formatting suggestions if: steps.runic.outputs.exit_code == 1 uses: peter-evans/create-or-update-comment@v4 @@ -81,10 +83,10 @@ jobs: ```diff ${{ steps.runic.outputs.diff }} ``` - - - edit-mode: replace - + + + edit-mode: replace + - name: Update stale comment if: steps.runic.outputs.exit_code == 0 && steps.find-comment.outputs.comment-id uses: peter-evans/create-or-update-comment@v4 @@ -96,3 +98,8 @@ jobs: Your PR no longer requires formatting changes. Thank you for your contribution! edit-mode: replace + + # XXX: if Github ever supports allow-failure (actions/runner#2347) + #- name: Propagate exit code + # run: | + # exit ${{ steps.runic.outputs.exit_code }} \ No newline at end of file diff --git a/ext/JustPICAMDGPUExt.jl b/ext/JustPICAMDGPUExt.jl index 01a8643..6f86cdb 100644 --- a/ext/JustPICAMDGPUExt.jl +++ b/ext/JustPICAMDGPUExt.jl @@ -304,6 +304,13 @@ module _2D return inject_particles!(particles, args, grid) end + function JustPIC._2D.force_injection!(particles::Particles{AMDGPUBackend}, p_new, fields::NTuple{N, Any}, values::NTuple{N, Any}) where {N} + force_injection!(particles, p_new, fields, values) + return nothing + end + + JustPIC._2D.force_injection!(particles::Particles{AMDGPUBackend}, p_new) = force_injection!(particles, p_new, (), ()) + function JustPIC._2D.inject_particles_phase!( particles::Particles{AMDGPUBackend}, particles_phases, args, fields, grid::NTuple{N} ) where {N} @@ -674,6 +681,13 @@ module _3D return inject_particles!(particles, args, grid) end + function JustPIC._3D.force_injection!(particles::Particles{AMDGPUBackend}, p_new, fields::NTuple{N, Any}, values::NTuple{N, Any}) where {N} + force_injection!(particles, p_new, fields, values) + return nothing + end + + JustPIC._3D.force_injection!(particles::Particles{AMDGPUBackend}, p_new) = force_injection!(particles, p_new, (), ()) + function JustPIC._3D.inject_particles_phase!( particles::Particles{AMDGPUBackend}, particles_phases, args, fields, grid::NTuple{N} ) where {N} diff --git a/ext/JustPICCUDAExt.jl b/ext/JustPICCUDAExt.jl index 943596a..d0097c3 100644 --- a/ext/JustPICCUDAExt.jl +++ b/ext/JustPICCUDAExt.jl @@ -274,6 +274,13 @@ module _2D return inject_particles!(particles, args, grid) end + function JustPIC._2D.force_injection!(particles::Particles{CUDABackend}, p_new, fields::NTuple{N, Any}, values::NTuple{N, Any}) where {N} + force_injection!(particles, p_new, fields, values) + return nothing + end + + JustPIC._2D.force_injection!(particles::Particles{CUDABackend}, p_new) = force_injection!(particles, p_new, (), ()) + function JustPIC._2D.inject_particles_phase!( particles::Particles{CUDABackend}, particles_phases, args, fields, grid::NTuple{N} ) where {N} @@ -644,6 +651,13 @@ module _3D return nothing end + function JustPIC._3D.force_injection!(particles::Particles{CUDABackend}, p_new, fields::NTuple{N, Any}, values::NTuple{N, Any}) where {N} + force_injection!(particles, p_new, fields, values) + return nothing + end + + JustPIC._3D.force_injection!(particles::Particles{CUDABackend}, p_new) = force_injection!(particles, p_new, (), ()) + function JustPIC._3D.move_particles!( particles::Particles{CUDABackend}, grid::NTuple{N}, args ) where {N} diff --git a/src/Particles/forced_injection.jl b/src/Particles/forced_injection.jl new file mode 100644 index 0000000..8657dc6 --- /dev/null +++ b/src/Particles/forced_injection.jl @@ -0,0 +1,58 @@ + +""" + force_injection!(particles::Particles{Backend}, p_new, fields::NTuple{N, Any}, values::NTuple{N, Any}) where {Backend, N} + +Forcefully injects new particles into the `particles` object. This function modifies the `particles` object in place. + +# Arguments +- `particles::Particles{Backend}`: The particles object to be modified. +- `p_new`: The new particles to be injected. +- `fields::NTuple{N, Any}`: A tuple containing the fields to be updated. +- `values::NTuple{N, Any}`: A tuple containing the values corresponding to the fields. + +# Returns +- Nothing. This function modifies the `particles` object in place. +""" +function force_injection!(particles::Particles{Backend}, p_new, fields::NTuple{N, Any}, values::NTuple{N, Any}) where {Backend, N} + (; coords, index) = particles; + ni = size(index) + @parallel (@idx ni) force_injection!(coords, index, p_new, fields, values) + return nothing +end + +""" + force_injection!(particles::Particles{Backend}, p_new) where {Backend} + +Forces the injection of new particles into the existing `particles` collection. This function modifies the `particles` in place by adding the new particles specified in `p_new`. + +# Arguments +- `particles::Particles{Backend}`: The existing collection of particles to which new particles will be added. The type of backend is specified by the `Backend` parameter. +- `p_new`: The new particles to be injected into the existing collection. +""" +force_injection!(particles::Particles{Backend}, p_new) where {Backend} = force_injection!(particles, p_new, (), ()) + + +@parallel_indices (I...) function force_injection!(coords::NTuple{2}, index, p_new, fields::NTuple{N, Any}, values::NTuple{N, Any}) where {N} + + # check whether there are new particles to inject in the ij-th cell + if !isnan(p_new[I..., begin]) + c = 0 # helper counter + # iterate over particles in the cell + for ip in cellaxes(index) + c += 1 + c > cellnum(index) && continue + doskip(index, ip, I...) || continue + pᵢ = p_new[I..., c] + @index coords[1][ip, I...] = pᵢ[1] + @index coords[2][ip, I...] = pᵢ[2] + @index index[ip, I...] = true + + # force fields to have a given value + for (value, field) in zip(values, fields) + @index field[ip, I...] = value + end + end + end + + return nothing +end \ No newline at end of file diff --git a/src/common.jl b/src/common.jl index 6a9b6b5..38d23e8 100644 --- a/src/common.jl +++ b/src/common.jl @@ -53,6 +53,9 @@ export advection!, advection_LinP!, advection_MQS! include("Particles/injection.jl") export check_injection, inject_particles!, inject_particles_phase!, clean_particles! +include("Particles/forced_injection.jl") +export force_injection! + ## MARKER CHAIN RELATED FILES include("MarkerChain/init.jl")