Thursday, March 31, 2011

Melting!

This week I implemented an alternative method for local deformations using the paper I described in a previous post. It seems to work pretty well, and by combining some different aspects of both implementations I was able to get a pretty good melting effect which I tied into the "jump" number which I then non-linearly tied to temperature. The jump number describes the viscosity of the fluid before applying shear stress as defining by the relative magnitudes of velocities of particles in a certain area, so by directly correlating this to temperature we can control the viscosity of the fluid with temperature. Some preliminary results are below.

One of the things I did notice is that by using both of these methods, the simulation time step has to be extremely low when considering fluids of extremely high viscosity. Otherwise we get some velocity instabilities which propogate through the entire fluid volume (visualized they look pretty psychadelic) which makes the rigid body object look like its shaking at an extremely high frequency. I tried implementing an adaptive timestep, but the timestep required for my testing was even slower than the timestep I was able to adjust manually...



My next steps will be implementing a mesh-loader->voxelizer->particle filler which will be able to take a mesh, turn it into a voxel grid structure, and then fill that voxel grid structure with particles depending on whether there was a 0 or 1 stored in the voxel grid.

Thursday, March 24, 2011

In Progress Evaluation

Here is an update on my current progress in the project, and a re-evaluation of my goals. Because of some time constraints and mis-judgement on how difficult it would be to perfect/debug/tweak the melting simulation although I was a little bit ahead of myself for the alpha review, I have fallen back behind currently for what I need done for the Beta. However, I do believe what is below is a realistic expectation of goals which can be met by the end of the semester.

X = Completed
x = Started but Unfinished
- = Incomplete


Senior Project
--------
[X] Approach Solidified (IMplementation Papers Solidified)
[X] SPH Integration and Setup
[X] Simple Particle Shader and Rendering Setup
[X] Simple GUI Implementation
[x] Melting Simulation
  [X] Thermal DIffusion
  [X] Elastic Forces
   [x] Temperature/Elastic Tie In

[-] Alternative Melting Simulation Technique*
[x] SPH Optimizations
  [X] XSPH
  [X] Adaptive Localized Artifical Viscosity
  [-] Adaptive TimeStep (CFL Condition)
[-] OBJ Mesh -> Voxelization -> Particle Loading
[-] Surface Reconstruction Shading
  [-] Marching Cubes (External Library for Mesh Output)
  [-] Fluid Method (From Screen Space Fluid Paper to be implemented in GPU)
[-] Particle Output for 3rd Party Packages
[ ] Final Rendering Movie of Melting Metal/Liquid Materials

*Depending on current melting simulation results after they are fully integrated I may decide to tie in an alternative melting method and perhaps interpolate between the two based on the material I'm trying to recreate.

Beta Review Goals
-----------------
[-] Melting Fully Integrated and Working (With Jump/Temperature Tie In)
[-] Mesh Loading/Voxelization/Particle Loading, Etc.

Final Review Goals
------------------
[-] Surface Reconstruction/Shading
[-] Particle Output for 3rd Party Packages
[-] Final Rendering Movies

Wednesday, March 23, 2011

Updated Melting

After spring break and diving back into this project, I've been working on stabilizing and trying to reduce numerical issues/errors with the melting simulation as it currently exists.

(The paper I will refer to below is here)

It seemed like my volume loss during melting was due to a couple of errors in the way I implemented the paper, as well as a poor selection of constants. The problem with melting is that we add several new constants to control viscosity of the fluid, which need some thorough tweaking to play nicely with the rest of the simulation. 

As far as other errors, I decided to delve back into my computational linear textbook to try to figure out if I was computing some of the tensor calculations incorrectly. All I will say here is that a tensor dot product with a vector (T . m) is not the same as a matrix M x v (see http://www.polymerprocessing.com/notes/root92a.pdf).  After this I was able to manually set the viscosity and have a lot more control of the melting situation control. The paper describes a "jump" number which also affects the viscosity according to the local shear of particles, but I have not been able to extract good viscosity values from the function they use and so I am unable to simulate solids using that jump number. 

While I have tied my thermal diffusion of temperature function successfully to this jump number which is producing reasonable values, the jump number to viscosity function which is also dependent on deformation tensor magnitude (essentially "shear") is producing viscosity values which are way too low. Because the function is non-linear I do not think I can just scale it up so I will need to either figure out if there is an error or find a new method of viscosity adjustment. Another option would be to ditch the "shear" value altogether and have visc. vary linearly with temperature and the "jump" value. I'm not sure what results this will produce but it is worth a try. Any thoughts on what I should do in this case?

If the simulation is too viscous, the simulation is unstable at the surface boundary so we need to decrease the timestep (the paper claims it solves this by approaching the pressure solve by taking the pressure derivative then updating it using Leap Frog integration, but after testing this method out I actually found it de-stablized my simulation even more and led to more unwanted compression during certain simulations). However I did find a reasonably small timestep which doesn't explode and keeps rigid bodies stable. 

Here is a recap for this week:
(a) Stablized updating stress/deformation tensors through linear algebra magic.
(b) Tested out different methods of updating pressure forces.
  • Decided on first-order density update. SPH pressure force approximation using density.
(c) Implemented XSPH particle velocity correction
  • Adjusts particle velocities with an average velocity from velocities of neighboring particles to avoid  stable clumps of particles.
(d)  New and Improved Localized Artificial Viscosity!
  • To avoid numerical instabilities in the velocity vector field, we adjust the acceleration using a different method which takes into effect local velocities and position differences when adjusting acceleration for art. visc. 
Rigid Body cube being pretty stable after about 1500 iterations (its a guess but it was running for like 5 minutes at around 4 fps so I'm going to guess it was that much...)

Same simulation run at alower viscosity.

Same simulation run at much lower viscosity. Notice the green which shows that area has a higher velocity in contrast with the other simulations.

Friday, February 25, 2011

Alpha Review

Since I went over most of the stuff during the Alpha Review I'll keep this post brief. This week in addition to getting some sweet custom SPH kernels integrated which work really well for the viscosity stuff, I got the thermal diffusion working (temperature diffuses through the fluid until an equilibrium is reached in some distant timestep depending on a thermal diffusion constant) as well as a "real" viscosity term working using deformation and stress tensors. It works pretty well for a "melting" effect currently, although there are a lot of artifacts which I need to work out through playing with good ranges for the constants as well as maybe look at some other possible solutions.

One idea I had, was in addition to having just a "viscous fluid" state, would be a rigid body or solid state, in which pressure forces do not affect the particle itself and instead use rigid body dynamics (intertial tensors, center of mass, torque and the whole shebang) which will interact with the fluid. As adding something like this will really complicate the fluid dynamics and the entire fluid dynamics enginer, I want to stable the current viscosity structure and emulate results from the paper I am implementing before taking the dive, although I believe coupling these two approaches will lead to some really fantastic effects.

Sunday, February 20, 2011

Basic SPH Simulation


This week I finished stripping down and integrating the SPH simulation into my renderer/framework, and found some good initial constants to play with as well as added some fun debugging stuff like hot/cold color ramping for different particle attributes like pressure, current velocity, temperature, etc. This will be useful for future debugging.

The simulation I am using is pretty basic and uses the standard kernels from "Particle-Based Fluid Simulation for Interactive Applications" with viscous error correction (not technically the same thing we want to use, as the viscous error correction value is constant throughout the simulation and only meant to counter numerical instability, without this term the simulation quickly blows up within its own containment box). However it does not take into account particle forces at the fluid boundaries such as surface tension, which would be something interesting to implement.


The next steps in the next couple following days will be to add the "real" viscoscity stress tensor which will have a large effect on the viscoelastic nature of this fluid, and then couple it to the temperature (eventually I want to have the temperature time-variate according to the heat equation ). I will be starting off by implementing it as described in "Particle-based non-Newtonian fluid animation for melting objects" which describes the formulation of not only the stress tensor, but the viscocity function and the heat equation.

Sunday, February 13, 2011

Simple Framework

So, I retracted stomach flu this week, which meant that a weekend of unproductivity turned into about half of a week of unproductivity... I also probably gave it to Joe but from the looks of things it could have been any DMD senior undergrad flu victim who was not properly quarantined.

However, after battling with several CUDA implementations (I do not believe my knowledge of the inner workings of CUDA at this point to properly be able to extend an SPH or particle simulation first) I decided it would be best to integrate and modify an existing and more object oriented CPU implementation. 

In the meantime,  I have set up my simulation framework and UI complete with a camera, FPS tracker, image recorder, and sliders to control simple simulation parameters in the near future. In addition, I set up a particle renderer to allow for multiple modes of rendering the particles (I anticipate having several debug "modes" for rendering particles from viewing pressures, velocities, etc in particles, as well as a framework to be able to use different shaders for particle rendering). 

Although SPH is not fully integrated so the renderer isn't full connected to the proposed particle system, I tapped into my novice shader GPU skillz to make some sample VBO's to hold color and the particle positions, and attached them to the renderer to see how it would work. I stole a lot of the shading code from both the Nvidia particles sample, and Jon's shader loader from CIS565, mostly because I liked the idea of having direct control of the different shaders and because as I have learned in GPU, immediate mode is deprecated and awful so I might as well start learning how to do it correctly now before I solidify some bad habits. 

Here is a video of the simple framework:




More to come soon as I finish modifying and integrating the SPH framework and renderer.

Friday, February 4, 2011

Some Models...

Here are a couple of models I've been sketching for how the simulation should work for different materials.

There are a few things: 1) I realized that with a physically accurate phase changing simulation (thank you Ian for pointing this out) the density and volume will be changing. For water this could potentially be a trivial case, as its fairly incompressible and has a pretty uniform density in its liquid state, and a uniform density which is higher in its solid state due to the way water crystallizes. Other materials such as metal do not act this way, and usually contract as they solidify, and their non-uniform structure (something like granite where the rock is made up of a bunch of different grains of different minerals, each with different properties) means that they might become increasingly more goopy (think like lava, or a slurpee) as the temperature changes. If a weakly compressible flow SPH implementation is controllable as far as these density parameters, it might be good to look into that. Otherwise I will have to figure out a way to fake the density change due to phase change.

2) I am unsure about fracturing in the material as the temperature increases. I believe that in the materials which I have discussed, this bond-breaking is occurring at a microscopic level, and that a lot of the fracturing which occurs in materials is actually a product of physical forces and deformations in combination with material properties at  varying temperatures (forging weakening the metallic bonds in order to more easily deform metal, etc.). I will focus on first simulating multi-phase flow...

3) Do I want to create a multi-phase flow simulation using air and material particles, or just material particles?That is do I want the heat transfer to occur automatically through the particle interactions in the sim through the air, or do I just use material particles and use another method of heat transfer. The system dynamics could be extremely different if I guess or estimate heat transfer through air by using the estimation methods in a lot of papers I've read, although it will definitely speed up simulation times.

In other news, I am trying to get some other SPH implementations I've found to work, but I am not having any luck with FLUIDS v.2, because of some changes made to CUDA 3.x from 2.3. I'm not sure if using this implementation is worth rolling my CUDA installation back to this version, or if it will even help but I am continuing to look for the best SPH implementation which would suit my needs. Although I can definitely say that looking at the source for these particle systems and SPH implementations is really helping me get a hold of what will be difficult to implement as far as the phenomena I've listed below. 

Once I decide on an implementation and get to creating the proper particle dynamics I will post some videos of preliminary results next week.