Jump to content
magneto

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 :)

  • Like 1

Share this post


Link to post
Share on other sites

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

Share this post


Link to post
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.

  • Like 1

Share this post


Link to post
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.

  • Like 2

Share this post


Link to post
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 this post


Link to post
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):

 

3fP0wLY.png

 

Do you know why the look so different almost inverted?

 

 

Thanks again, I learnt a lot :)

Share this post


Link to post
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

  • Like 3

Share this post


Link to post
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
  • Like 1

Share this post


Link to post
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 this post


Link to post
Share on other sites

Have you tried making the laplacian calculation in a vop?
 

w8I4f1A.jpg

  • Like 1

Share this post


Link to post
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 this post


Link to post
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

  • Like 6

Share this post


Link to post
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 this post


Link to post
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!

  • Like 1

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
Share on other sites

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

  • Like 1

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×