### Curl Calculation

18054   15   3
Member
22 posts
Joined: Dec. 2009
Offline
I'm looking to calculate curl of a vector field to visualize vorticity within a velocity field.

Curl is stated as the cross product of the vector and the gradient or

From a houdini standpoint the gradient of a vector field is a 3x3matrix, so I don't see how you could possibly do a cross product of a matrix and a vector.

I think I'm missing a key point here since I can't find any information online about this kind of implementation.

Can any math gurus help me out here? I know its available in dop context so I don't think it would be too difficult to get together in sops(vex).
Member
150 posts
Joined: May 2011
Offline
Hi,
I've never seen the gradient expressed as a matrix. What did you do to get this result?

The Volume Gradient VOP or volumegradient() vex function return a gradient vector which should be exactly what you need.

-dennis
Member
1390 posts
Joined: July 2005
Offline
If I'm not mistaken you need a dot product of column vectors in your matrix with normalized x,y,z to get derivatives in x,y,z, which crossed with a velocity will give you a curl.
Member
127 posts
Joined: Nov. 2008
Offline
why not get the curl of the field in dops and then import it in sops?
Bhavesh Pandey.

https://bhaveshpandey.io [bhaveshpandey.io]
Member
373 posts
Joined: March 2009
Offline
If you can do it in dops, there is the gas analysis dop will give you curl from a vector field. I have a good vorticity setup for flip laying around somewhere. I may turn it into a video tutorial this week just for kicks.
Ian Farnsworth
Member
1743 posts
Joined: March 2012
Offline
The curl of a vector field is just a vector field, not a matrix field. The second equation image on Wikipedia is probably what you're looking for. It defines curl directly in terms of derivatives, so there's no ambiguity about cross products: http://en.wikipedia.org/wiki/Curl_%28mathematics%29#Definition [en.wikipedia.org]

Hopefully this helps!
Writing code for fun and profit since... 2005? Wow, I'm getting old.
Member
691 posts
Joined: June 2006
Offline
I have an asset for a post curl calculation in sops; Hope that helps you!!!

Attachments:
SOP_aeb_vorticity.otl (15.3 KB)

Feel The Knowledge, Kiss The Goat!!!
http://vimeo.com/lordpazuzu/videos [vimeo.com]
Member
22 posts
Joined: Dec. 2009
Offline
dennis.weil
Hi,
I've never seen the gradient expressed as a matrix. What did you do to get this result?

The Volume Gradient VOP or volumegradient() vex function return a gradient vector which should be exactly what you need.

-dennis

This is only in terms of scalar fields, a vector field will return a matrix (a vector consists of 3 scalars, so you have 3x the components)

I'm really looking to keep this simple and avoid using a wrapper around the gas analysis dop.
Member
150 posts
Joined: May 2011
Offline
icarus551
This is only in terms of scalar fields, a vector field will return a matrix (a vector consists of 3 scalars, so you have 3x the components)

Thanks, that makes total sense.
Member
22 posts
Joined: Dec. 2009
Offline
Symek, I think that is correct, I took the tensor-vector dot product of the gradient matrix and the normalized vector, then used that in a cross product with the vector, which first look appears to give a correct curl vector.

On a basic vortex velocity field it looks correct, but I need to check it out on a more complex field.
Member
22 posts
Joined: Dec. 2009
Offline
After comparing against the dop generated curl, they definitely don't match (or are even close).

The mystery continues
Staff
820 posts
Joined: July 2006
Offline
The VolumeAnalyis SOP should really have an option to calculate the curl, but in the meantime you can compute the gradient of each velocity component and calculate the curl by hand in VOPs (thereby doing a little extra work: nine derivatives instead of the six minimally required).

See attached for an example of computing the curl of a FLIP sim (and turn on the curl attribute visualization).

Attachments:
curl_in_sops.hip (1.0 MB)

Member
691 posts
Joined: June 2006
Offline
Thanks Johner!!! :shock:
Feel The Knowledge, Kiss The Goat!!!
http://vimeo.com/lordpazuzu/videos [vimeo.com]
Member
22 posts
Joined: Dec. 2009
Offline
johner
The VolumeAnalyis SOP should really have an option to calculate the curl, but in the meantime you can compute the gradient of each velocity component and calculate the curl by hand in VOPs (thereby doing a little extra work: nine derivatives instead of the six minimally required).

See attached for an example of computing the curl of a FLIP sim (and turn on the curl attribute visualization).

I was shown a similar solution which is correctly theoretically, but if you compare it against the dop computed curl they don't even look similar.

I ran a 2D smoke sim (xz axis) to compare. Curl vectors of a 2d field should all point along one axis (y axis). The dop computed curl does this but none of the sop solutions do.

Very mysterious.
Staff
820 posts
Joined: July 2006
Offline
icarus551
I was shown a similar solution which is correctly theoretically, but if you compare it against the dop computed curl they don't even look similar.

I ran a 2D smoke sim (xz axis) to compare. Curl vectors of a 2d field should all point along one axis (y axis). The dop computed curl does this but none of the sop solutions do.

Hmm, I'm not seeing much discrepancy. The attached 2d smoke test creates a curl attribute from both a DOP GasAnalysis-generated field, and the SOP solution. The values aren't identical, but are very close. Switch the smoke sim to 3d and the values are still very close.

Attachments:
curl_2d_smoke.hip (601.2 KB)

Member
22 posts
Joined: Dec. 2009
Offline
Ahh cool, yes its definitely working in your scene. I'll look for why it wasn't working in mine. thanks!

Note: I was using vex gradient() instead of volume analysis sop, I wonder if theres a descrepancy between outputs.

Edit: vex gradient function and volume gradient sop give same result. prolly same code in hdk..