Sunday, November 27, 2011

Systems now have interaction

Before I could have interacting rigid body/fluid systems I first had to create a rigid body class where the rigid bodies are composed of particles. To have a rigid body system, I needed to discritize the body into a set of particles. To do this I utilized a method from [2], which uses opengl to create a 3d texture representing voxels inside and outside the rigid-body. From the resulting 3D texture, I can then generate a particle field. For each of the particles, we need position, velocity, and force for each particle that is contained in the rigid body. Also, for each rigid body we should track the linear and torque forces on the center of mass, velocity of center of mass, angular velocity, and the center of mass position.

To calculate the total linear force on a single rigid body, simply sum all the forces of each particle that belongs to that rigid body. [1]

$F_{total} = \displaystyle \sum_{i=0}^N f_i$

And the total torque can be calculated by summing up the cross product of the linear force with the radius from the center of mass for each particle. [1]

$F_{torque} = \displaystyle \sum_{i=0}^N ((pos_i-pos_{com}) \times f_i)$

Currently I don't have any constraints implemented. Also, I still need to implement the segmented scan to improve the calculation of force totals on the rigid body. Currently I naively loop and sum for each rigid body which is inefficient. I also need to create a renderer which will render rigid body meshes at the appropriate locations.

Here is a video of my progress so far.


Rigid-body and Fluid interaction with velocity vectors from Andrew Young on Vimeo.

In the video above, I render the velocity vectors of each particle. This helps to visualize the flow of the fluid. I plan to create a separate blog to discuss my implementation of the rendering code for the velocity vectors.

The interaction between fluid and rigid-body is modeled by a spring/dampening system. The calculations are based on the following two equations as described in [1].

$f_s = -k(d-r_{ij})\frac{r_{ij}}{\left|r_{ij}\right|}$

$f_d = \eta(v_{j}-v_{i})$

Where k is the spring constant and $\eta$ is the dampening coefficient. I need to experiment with these coefficients to get more accurate results.

I also focused a lot of time to refactoring the code around the System class. The System class was abstract and had very little functionality. When creating the rigid body class, I noticed I was just copying and pasting a lot of code. That was a perfect reason to push things up to the parent class.

I moved a lot of generic functionality as well as several buffers (position, velocity, force) that were common to all systems up to the System class. I then added some rudimentary code to all for interaction between systems. Currently this only works between SPH and Rigidbody systems. Eventually, I hope to have a better interaction framework where you can define new rules of interaction quickly and easily. Then I could add interaction between Flocks and SPH which could provide some very interesting simulations.

Todo:

  1. Verify spacing of the rigid-body system is correct.
  2. Experiment with coefficients for interaction.
  3. Explore the alternative formulations for system interaction.
  4. Continue refactoring the code.
  5. Create a class to better handle particle shapes.



References

[1] Harada, T., Tanaka, M., Koshizuka, S., & Kawaguchi, Y. (2007). Real-time Coupling of Fluids and Rigid Bodies. Proc of the APCOM, 1-13. Retrieved from http://individuals.iii.u-tokyo.ac.jp/~yoichiro/report/report-pdf/harada/international/2007apcom.pdf

[2] Fang, S., & Chen, H. (2000). Hardware accelerated voxelization. Computers & Graphics, 24(3), 433-442. Elsevier. Retrieved from http://www.sciencedirect.com/science/article/pii/S0097849300000388

No comments:

Post a Comment