Software/code to extract a solenoidal (a.k.a. divergence-free) field from a 2D vector field numerically

Can somebody point me to software/code to extract a solenoidal (a.k.a. divergence-free) field from a 2D vector field numerically?

There are a plethora of papers and documents describing how to do this, but for some reason none of the authors (or anybody else for that matter) puts a simple piece of source code online implementing that functionality. All I found are rather huge packages or very cryptic pieces of code.

Update. More concretely for my situation: I have two 2D arrays of size 64x64 with double-precision floating point numbers. These two arrays represent the x- and y-velocities of a fluid flow. Periodic boundaries are employed. I would like to extract the solenoidal part of the velocities into two new 2D arrays.

• Do you want to do this analytically or do you have your field defined over a mesh? How is it done? Maybe if you write more details about it, somebody can point you in the right direction. – nicoguaro Feb 23 '17 at 14:04
• I thought the tags 'numerical-analysis' and 'numerics' would be sufficient for that. Updated question – Bart Feb 23 '17 at 15:40
• I believe the numerical vs. analytical question was just a specific example of where details are missing. Here is another. Is this over a bounded domain in 2D? If so, is it rectangular? – Bill Greene Feb 23 '17 at 15:44
• Maybe the solenoidal part comes as the solution of certain PDEs? You can check what equations it satisfies. Then solve the PDEs for it. – Pu Zhang Feb 23 '17 at 16:24
• Your question was not specific enough. People made comments trying to help other people understand what you want. Since contributions here are done in people's free time, they prefer to invest that time in well written questions. – nicoguaro Feb 25 '17 at 7:16

I had to do a little bit of editing, such as increasing iteration variable k (dependent on how divergent your input field is) and employing periodic boundaries. After that it worked for me and solved my problem. The article also contains a fairly intuitive description of what the function outputs without going into the details of how it does this.