Thanks for the detailed explanation. I realize the following question is about methods rather than Dedalus, which may not be appropriate here, but perhaps you/other users have some quick tips on maintaining positivity in a spectral code.
After some experimentation, it seems that modifying the grid data cannot remove negative densities (e.g. the filter in
this paper). I suppose this is because abruptly resetting selected grid values to zero doesn't play well with the spectral transformation.
I also tried transforming the variable as you suggested, but I found that the total mass isn't conserved. More specifically, the relevant equation in my problem looks like
d/dt(Q) + v*grad(Q) = - div(Q*F),
where div(v)=0, Q is a density that should be >0, and F is a vector function of other problem variables.
I tried solving for
Y = Q0*(1 + ln(Q/Q0)),
where Q0 is the initial value of Q. So the equation for Y is
d/dt(Y) + v*grad(Y) = -grad(Y)@F - Q0*div(F),
I then add a Laplacian diffusion term D*lap(Q) to the RHS. However, this formulation does not conserve the total mass
V = volume_integral(Q) = volume_integral(Q0*exp(Y/Q0 - 1))
, where I used Dedalus' volume_integral function. Non-conservation manifests in the nonlinear regime.
Thanks very much,
Min-Kai