Skip to content
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

Added catch so particles don't sink tracers to < 0 #22

Closed
wants to merge 1 commit into from

Conversation

jagoosw
Copy link
Collaborator

@jagoosw jagoosw commented Aug 16, 2022

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?

Not sure this is the best solution but hopefully its okay
since it would only occur for one timestep when multiple
particles are sinking from the same grid point (I think).
@jagoosw
Copy link
Collaborator Author

jagoosw commented Aug 17, 2022

I have just realized that this is actually a larger issue, since the particles sink from their 8 nearest points, if the grid is finer (e.g. near the top of the non-regular one) an absolute amount of a tracer / volume of a smaller cell is taken from a concentration so the sinking is spread over a smaller volume and has a greater effect on its local points concentration.

Before the distribution of the particles was much finer than the grid, so the sinking was well distributed. But if we have a smaller grid then some points could be sunk from much more than others.

@johnryantaylor
Copy link
Collaborator

Just adding a comment here for posterity: on zoom @jagoosw and I discussed reducing the kelp internal nitrogen stores when setting the nutrient concentration in a cell to zero to prevent negative values. This should have the effect of maintaining conservation of nitrogen.

@jagoosw
Copy link
Collaborator Author

jagoosw commented Aug 18, 2022

Superseded by #35

@jagoosw jagoosw closed this Aug 18, 2022
@jagoosw jagoosw deleted the sink-bug-fix branch August 18, 2022 17:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants