-
Notifications
You must be signed in to change notification settings - Fork 10
fix particle interaction with planktonIndividual #97
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from 8 commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
96ffbca
fix particle interaction with planktonIndividual
cese427 1189dfb
fiix_particle_interaction
cese427 2c2b36f
fix_particle_interaction
cese427 8aa1f9c
fix_particle_interaction
cese427 24996e2
fix_particle_interaction
cese427 cfce6ad
fix_particle_interaction
cese427 7422d3e
fix_particle_interaction
cese427 43d33f9
fix_particle_interaction
cese427 a367aed
fix_particle_interaction
cese427 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -13,63 +13,71 @@ | |
| return dist | ||
| end | ||
|
|
||
| ##### compare particle distance and Rd, decide whether | ||
| ##### this vesicle will be merged into phytoplankton cell | ||
| @kernel function calc_merge_matrix_kernel!(intac, abiotic, plank, rnd, grid, abio_p) | ||
| i, j = @index(Global, NTuple) | ||
| intac[i,j] = isless(calc_distance(plank.xi[i], plank.yi[i], | ||
| plank.zi[i], plank.x[i], | ||
| plank.y[i], plank.z[i], | ||
| abiotic.xi[j], abiotic.yi[j], | ||
| abiotic.zi[j], abiotic.x[j], | ||
| abiotic.y[j], abiotic.z[j], | ||
| grid), abio_p.Rd * rnd.x[i]) * abiotic.ac[j] | ||
| end | ||
| function calc_merge_matrix!(intac, abiotic, plank, rnd, grid, abio_p, arch::Architecture) | ||
| kernel! = calc_merge_matrix_kernel!(device(arch), (16,16), (size(intac))) | ||
| kernel!(intac, abiotic, plank, rnd, grid, abio_p) | ||
| return nothing | ||
| ##### 1. Reset Interaction | ||
| ##### Clears the Top-K candidate list before each step. | ||
| function reset_interaction!(intac, arch::Architecture) | ||
| @inbounds intac .= 0 | ||
| end | ||
|
|
||
| ##### clean the merge matrix - one vesicle might be close enough | ||
| ##### to two or more phytoplankton cells. | ||
| ##### Only the first phytoplankton cell can uptake this vesicle. | ||
| ##### First, find all indices of 1.0f0 in intac, return an AbstracArray of | ||
| ##### Cartesian Index, e.g., CartesianIndex(phyto_ind, abiotic_ind) | ||
| ##### Then, assign phyto_ind to abiotic.merge[abiotic_ind] | ||
| @kernel function assign_merge_kernel!(abiotic, inds) | ||
| ##### 2. Calculate Interaction Topology | ||
| ##### Revised: Uses random slot assignment to avoid race conditions. | ||
| @kernel function calc_interaction_kernel!(intac, plank, abiotic, rnd, grid, abio_p, max_candidates) | ||
| i = @index(Global) | ||
| abiotic.merg[inds[i][2]] = inds[i][1] | ||
|
|
||
| if plank.ac[i] == 1.0f0 | ||
| for k in 1:length(abiotic.ac) | ||
| if abiotic.ac[k] == 1.0f0 | ||
| dist = calc_distance(plank.xi[i], plank.yi[i], plank.zi[i], plank.x[i], plank.y[i], plank.z[i], | ||
| abiotic.xi[k], abiotic.yi[k], abiotic.zi[k], abiotic.x[k], abiotic.y[k], abiotic.z[k], | ||
| grid) | ||
| if dist < abio_p.Rd | ||
| slot = (i % max_candidates) + 1 | ||
| intac[slot, k] = i | ||
| end | ||
| end | ||
| end | ||
| end | ||
| end | ||
| function assign_merge!(abiotic, inds, arch::Architecture) | ||
| kernel! = assign_merge_kernel!(device(arch), 256, (size(inds,1))) | ||
| kernel!(abiotic, inds) | ||
|
|
||
| function calc_interaction!(intac, plank, abiotic, rnd, grid, abio_p, max_candidates, arch::Architecture) | ||
| kernel! = calc_interaction_kernel!(device(arch), 256, (size(plank.ac, 1))) | ||
| kernel!(intac, plank, abiotic, rnd, grid, abio_p, max_candidates) | ||
| return nothing | ||
| end | ||
|
|
||
| ##### merge particles | ||
| @kernel function merge_particle_kernel!(abiotic, plank) | ||
| i = @index(Global) | ||
| if abiotic.merg[i] ≠ 0 | ||
| @inbounds KernelAbstractions.@atomic plank.ptc[abiotic.merg[i]] += 1.0f0 | ||
| ##### 3. Consume Particle | ||
| ##### Handles actual uptake with capacity limit. Unchanged logic. | ||
| @kernel function consume_particle_kernel!(intac, plank, plank_p, abiotic, max_candidates) | ||
| k = @index(Global) | ||
|
|
||
| if abiotic.ac[k] == 1.0f0 | ||
| for j in 1:max_candidates | ||
| plank_id = intac[j, k] | ||
| if plank_id > 0 | ||
| if plank.ptc[plank_id] < plank_p.max_ptc | ||
| KernelAbstractions.@atomic plank.ptc[plank_id] += 1.0f0 | ||
| abiotic.ac[k] = 0.0f0 | ||
| break | ||
| end | ||
| end | ||
| end | ||
|
|
||
| end | ||
| end | ||
| function merge_particle!(abiotic, plank, arch::Architecture) | ||
| kernel! = merge_particle_kernel!(device(arch), 256, (size(abiotic.ac,1))) | ||
| kernel!(abiotic, plank) | ||
|
|
||
| function consume_particle!(intac, plank, plank_p, abiotic, max_candidates, arch::Architecture) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same above |
||
| kernel! = consume_particle_kernel!(device(arch), 256, (size(abiotic.ac, 1))) | ||
| kernel!(intac, plank, plank_p, abiotic, max_candidates) | ||
| return nothing | ||
| end | ||
|
|
||
| ##### particle interaction wrapper | ||
| function particle_interaction!(abiotic, plank, intac, abio_p, rnd, grid, arch::Architecture) | ||
| rand!(rng_type(arch), rnd.x) # generate random number (0,1) | ||
| calc_merge_matrix!(intac, abiotic, plank, rnd, grid, abio_p, arch) | ||
| inds = findall(isequal(true), intac) | ||
| assign_merge!(abiotic, inds, arch) | ||
| merge_particle!(abiotic, plank, arch) | ||
| unsafe_free!(inds) | ||
| abiotic.ac .*= isless.(abiotic.merg, 1) | ||
| abiotic.merg .= 0 | ||
| function particle_interaction!(abiotic, plank, plank_p, intac, abio_p, rnd, grid, max_candidates, arch::Architecture) | ||
| rand!(rng_type(arch), rnd.x) | ||
| reset_interaction!(intac, arch) | ||
| calc_interaction!(intac, plank, abiotic, rnd, grid, abio_p, max_candidates, arch) | ||
| consume_particle!(intac, plank, plank_p, abiotic, max_candidates, arch) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. same above |
||
|
|
||
| return nothing | ||
| end | ||
|
|
||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
change function name to
merge_particle_kernel!