How to calculate divergence of a vector in Volume VOP?

Recommended Posts

Hi,

I know Volume Analysis SOP does this but is it possible to do it in Volume VOP? If so, anyone can post a simple example of how this could be done?

Thanks

Share on other sites

Volume Gradient from File VOP.

Share on other sites

Thanks but that calculates the gradient. I need the divergence of a vector field.

Share on other sites

Is it a matter of evaluating 26 neighbours of any given voxel? Just averaging them and getting the length of that vector doesn't work.

Share on other sites

Have you examined the definition of divergence? From wikipedia, it looks like it's just the sum of the vector components of the gradient.

Share on other sites

Thanks Edward, I did. I spent some more time to get it. What I did is to read the 8 neighbours of each voxel on each side of it and then sum x from the neighbours on X, y from the neighbours on Y, z from the neighbours on Z, and sum all of these. The resulting voxel values (using volumeslice) is different than what I get from Volume Analysis SOP, which also looks different than VDB Analysis SOP.

If I am doing it wrong, why are laplacian volumes of the same volume also look different between Volume Analysis SOP and VDB Analysis SOP? I am confused.

Share on other sites

Thanks Raymond. I understand divergence better now. I ended up with a similar solution but I didn't have step size or -0.5 you are using to multiply in the end. What's the reason for multiplying by -0.5 in the end?

Also I converted the volume into a VDB and calculated divergence using VDB Analysis and got this (left: your method, right: VDB Analysis):

Do you know why the look so different almost inverted?

Thanks again, I learnt a lot

Share on other sites

Looks the same to me. Edited Raymonds hip a little,  just inverted his solution and added VDB control. 100% match.

divergence2.hip

Share on other sites

I chopped my file from a fluid sim recreation in sops, but if you look at the formula for divergence you divide your sum of differences by 2*stepsize.  I believe this comes from a need to have your final output be independent of your fluid resolution, though I don't know enough about descretizing pde equations to give a solid answer.

Edited by ikarus
Share on other sites

Thanks alot guys, helped me massively

Ok when I divided it like Raymond said no more inversion necessary.

Also is there something that needs to be done at the borders? Since the results match, I assume no, but was wondering if there is more to it.

Lastly if I get the divergence of the gradient (using volumegradient), I should get the laplacian? I tried this with VDB Analysis by doing it directly from scalar->scalar, vs scalar->vector->scalar and I got different results.

I just used float noise output instead of vector to feed into gradient and then divergence.

Share on other sites

Have you tried making the laplacian calculation in a vop?

Share on other sites

Thanks ikarus, I basically used your divergence and fed gradient into it. My understanding was instead of vel that you used, if you get the gradient and then feed it into divergence, it will produce laplacian. Is this not correct?

Also a simple question: can you calculate step size automatically? I assume it's any_dimension / number_of_voxels in that dimension? Not sure if one can rely on a single dimension to calculate it, but thought if the voxels are square then it should be.

Share on other sites

laplacian.hipnc

So i built the laplacian op and i get the same result from the sop volume analysis laplacian (slice1 to slice2)

Comparing techniques it appears that splitting the divergence and gradient operations results in a loss of high frequency values (comparing slice2 to slice3 in the file)

Problem with discretizing these pde formulas is the inherent loss of data from sample rate, so simplifying the algorithm to one step probably reduces data loss from sample rate.  just my guess

Share on other sites

Thanks ikarus, I owe you a big one

Lastly do you know if one can also auto calculate the step size? I would be better if I didn't have to figure it out manually because sometimes people use Max Axis option so I don't see the Div Size value in the volume itself.

Thanks again.

Share on other sites

I think there is a primitive intrinsic that has the voxel resolution of the volume, can't check myself right now. Try that!

Share on other sites

Thanks David, I carefully checked and there is only voxel resolution which is available as a vex function too. So to get the step size, one still has to do:

any_axis / number_of_voxels_in_the_same_axis

Unless I am thinking of it wrong.

Thanks again for the help guys.

Share on other sites

Btw guys do you know how to implement curl and curvature? I spent some time trying to break down curl formula but I don't see any commonality with divergence where I could just modify it to calculate curl.

Is it vastly more complicated? I was comparing my results with Volume Analysis Curl but they don't match.

Thanks again.

Share on other sites

Take a look inside Whitewater Source SOP -> SAMPLE_TO_POINTS. It calculates Vorticity there, which is the length of curl.

Share on other sites

Thanks a lot David, it shows it perfectly. I tried it on the same volume we are using and it's exactly the same as VDB's curl. But step size is not considered for curl?

Also is there a built-in HDA that show how to calculate curvature? I saw one in the same subnet but it uses Analysis SOPs.

Thanks again.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×