xgcm / xgcm

python package for analyzing general circulation model output data
http://xgcm.readthedocs.org
MIT License
223 stars 81 forks source link

Compute the stream function associated with the vortical part of the velocity #612

Closed francispoulin closed 7 months ago

francispoulin commented 1 year ago

Is your feature request related to a problem? Please describe. A clear and concise description of what the problem is. Ex. I'm always frustrated when

I am new to xgcm and interested in using the Helmholtz decomposition to study oceanic flows. To do this it is necessary to invert Poisson problems to determine the potential function (for the divergent part of the flow) and the stream function for the vortical part of the flow.

Describe the solution you'd like A clear and concise description of what you want to happen.

At the moment it is very easy to compute the vorticity and the divergence. The only step that is missing is to set up the 2D Laplacian operator and then invert this, with particular boundary conditions of course. I presume this would not be difficult in this framework but I don't know how best to proceed. I would be very interested in doing this if someone wanted to give me some guidance on how to proceed.

Describe alternatives you've considered A clear and concise description of any alternative solutions or features you've considered.

Additional context Add any other context or screenshots about the feature request here.

jbusecke commented 1 year ago

Hi @francispoulin, that is an interesting question. As it stands right now we do not provide an algorithm to do this out of the box. But I wonder if this is something that can be achieved with python only libraries? If you find a way to implement this in e.g. numpy or numba, you could consider implementing that as a Grid ufunc.

francispoulin commented 1 year ago

Thanks @jbusecke.

For the case of a rectangular domain, it should be easy to build a matrix and invert it by imposing certain enough boundary conditions. This is something that I think I could do easily enough using numpy, which is where I will start.

However, if one wanted to solve the poisson problem on an ocean basin with irregular geometry, then one should be more clever. I will look at what the MITgcm does and then asses how easy that is to do.

For the moment, I will learn how ot use the Grid ufunc for this the simple problem and let you know how it works. Thanks again!

miniufo commented 8 months ago

Hi, just came across this issue. You may want to try xinvert

francispoulin commented 7 months ago

Thanks @miniufo ! That looks very useful indeed.

francispoulin commented 7 months ago

xinvert seems to be a library that can do what I was hoping to do.

jbusecke commented 6 months ago

xinvert looks really cool! Would love to see that used with grid_ufuncs!