Jump to content

How to calculate divergence of a vector in Volume VOP?


Recommended Posts

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.

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

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

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

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

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

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

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

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

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

×
×
  • Create New...