Added catch so particles don't sink tracers to < 0 #22
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.
I came across an issue that with kelp in the model tracers can go negative, then the PAR calculation fails because it has negative number ^ fraction. I think this is because the kelp is in too high a density and multiple particles are drawing from the same points so it can pull the concentration of a tracer below zero. If NH4 goes negative first then on the next step L_NO3 would become very large from exp(-NH4), this would very quickly make NO3 become negative so L_NO3 would be large and negative. The P term in S(P) would then be large and negative making P go negative, which then causes the error when the PAR is calculated.
I've fixed this by changing the sinking function to sink to min(X-dX*dt, 0) which does mean that the particle gets to take up a tiny amount more than is actually available to it but it prevents the error. I'm not sure this is the best solution but hopefully its okay since it would only occur for one time step when multiple particles are sinking from the same grid point (I think), and I will make it throw a warning so we can see if it is happening often.
I think the only way to fix this properly would be to make the particle calculations happen serially (they are currently dispatched in parallel using the KernalAbstraction stuff like Oceananigans uses).
Do you think that this is an okay solution @johnryantaylor?