# Callback function to set negative values to zero

**URL:** <https://discourse.julialang.org/t/callback-function-to-set-negative-values-to-zero/111902>\
**Category:** Modelling & Simulations\
**Created:** [March 20, 2024, 8:49pm UTC](https://discourse.julialang.org/t/callback-function-to-set-negative-values-to-zero/111902 "2024-03-20T20:49:06Z")\
**Posts on this page:** 1\
**Showing post:** 7

<div class="post-metadata">

**Author:** ![kkakosim](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kkakosim/32/21546_2.png) [@kkakosim](https://discourse.julialang.org/u/kkakosim)\
**Post date:** [March 21, 2024, 5:17am UTC](https://discourse.julialang.org/t/callback-function-to-set-negative-values-to-zero/111902/7 "2024-03-21T05:17:40Z")

</div>

Have you tried implementing the [PositiveDomain()](https://docs.sciml.ai/DiffEqCallbacks/stable/step_control/#DiffEqCallbacks.PositiveDomain) in [DiffEqCallbacks.jl](https://docs.sciml.ai/DiffEqCallbacks/stable/), it was suggested to me for a [similar problem](https://discourse.julialang.org/t/zero-order-extinction-reaction/108749/2), and it appears faster than the “manual” callback-integrator.

However, I noted that my system is indeed keep pushing to negative, and while the u stays close to 0, there a small negative perturbations that cause other u to exceed other physical limits (e.g., exceed mass conservation). I have not tried yet the combinations mentioned earlier by @Dan and @stevengj.

---

_[View the full topic](https://discourse.julialang.org/t/callback-function-to-set-negative-values-to-zero/111902)._
