tomchor / Oceanostics.jl

Diagnostics for Oceananigans
https://tomchor.github.io/Oceanostics.jl/
MIT License
24 stars 8 forks source link

Add `PotentialEnergy` methods for `BuoyancyTracer` and `SeawaterBuoyancy{<:LinearEquationOfState}` #167

Closed jbisits closed 3 months ago

jbisits commented 3 months ago

Currently PotentialEnergy only works if the BuoyancyModel has a BoussinesqEquationOfState. This PR extends PotentialEnergy to have methods for both BuoyancyTracer and SeawaterBuoyancy{<:LinearEquationOfState}. It does so by dispatching on the BuoyancyModel.

To calculate the potential energy per unit volume for BuoyancyTracer and SeawaterBuoyancy{<:LinearEquationOfState} I have used

$$ E_{p} = bz $$

where $b$ is buoyancy (I think this is what it should be but let me know if not!). In the case of BuoyancyTracer $b$ is exactly the buoyancy tracer and in the case of SeawaterBuoyancy{<:LinearEquationOfState} I compute the buoyancy via

https://github.com/tomchor/Oceanostics.jl/blob/68007f19e61f13152e8a6efd9a568eb933d941b2/src/PotentialEnergyEquationTerms.jl#L22-L23

I am not sure if this is the optimal way to do things so please let me know if you know of better ways to do this!

Once the calculation of $E_{p}$ is confirmed I will add some calculation tests to check things are doing what they should similar to what is currently there for when SeawaterBuoyancy{<:BoussinesqEquationOfState}

https://github.com/tomchor/Oceanostics.jl/blob/68007f19e61f13152e8a6efd9a568eb933d941b2/test/runtests.jl#L345-L358

tomchor commented 3 months ago

I think the math here is correct.

One issue (which I think was also relevant for https://github.com/tomchor/Oceanostics.jl/pull/164 but I didn't catch it then), is that this calculation assumes that gravity_unity_vector==NegativeZDirection(). That's fine, I don't think we need to expand this for an arbitrary gravity_unity_vector (although that'd probably be easy), but I think we should test for that and throw a helpful error otherwise.