Dynamical Simulation with Finite Elements

April 24, 2009 on 3:35 pm | In Actionscript, Links, Physics | 9 Comments

The finite element method is a very versatile method for any kind of boundary value problem. It was first extensively used in engineering as a tool for structural analysis, but it can also be used for heat flow, fluid and electrodynamical simulation to name some fields.

The underlying principle (as the name implies) is the discretization of the domain of interest into simple connected elements like triangles, rectangles, tetrahedrons or dozens more possible types. Then the physical property (force, velocity, temperature…) is evaluated at the nodes, or vertices if you look at an isolated element, of the resulting mesh. Between vertices, for example inside the volume of a tetrahedron the variable is interpolated.

Now in structural dynamics the elements represent actual physical elements with a mass and a volume (or area in 2D). In comparison to rigid bodies, usually more than one element makes up a body. Consider for example a box:
types
It can be described by two triangular finite elements, or four smaller rectangular elements, or any other mesh covering the box. As a rigid body the box would be described as a … box. So why use these elements if a ‘one element’ formulation is sufficient? Because finite elements offer a number of physical properties which just cannot be described efficiently by a rigid body. For a real time simulation the most important properties are elastic behavior, permanent deformations and breakability.
But how are these elements actually formulated? To illustrate how finite elements are described consider a system of two masses connected by a spring.

types
A spring element with nodes 1 and 2

This is a two node one dimensional element.
The spring’s elongation is linearly proportional to the applied force:

types

where δ ist the elongation, k is the spring constant which describes the spring’s resiliance to deformations and u stands for the displacement from the initial positions of the masses. In equilibrium the two forces at the nodes are opposite to each other.

types

The forces can be expressed by the previously found relation:

types

And these two formulas can be written as a matrix equation:

types

The matrix is called the stiffness matrix K and it contains the material and geometric characteristics of the element. In this simple case it is just a 2×2 matrix but the more complicated an element becomes the size of the matrix can easily reach 12×12 or even bigger sizes.
After finding the description for one lonely spring the next step is to formulate the connection between several elements. So another spring is connected at the right node of the first spring. It has the same stiffness matrix K and subsequently a similar matrix equation, but with a new force and displacement variable for the third node.

types

The two stiffness matrices must be combined to form a global stiffness matrix. For this simple example it looks like this:

types

Where the upper index denotes the element the force stems from and the lower index the node number.
This basically describes the whole procedure behind a finite element formulation: the stiffness matrix is formulated, the mesh generated and the global stiffness matrix is computed. These steps are all done before the actual simulation in which the matrix equation is solved for u, the global displacements. This is done by calculating the inverse of K,

types

which depending on the size of K can be an expensive computation and generally is one reason (the other being high memory requirements) why the finite element method is rarely used for real time physics engines which should be as fast as possible.
But none the less for few elements it is still fast enough to be useful. Hence after all this introduction it is time to present an implementation. The following demo is a dynamical simulation of a bar consisting of 16 triangular elements.

press space to start simulation

This seems at first sight fun to look at but useless, however this finite element method should be integratable into motor2, which would give the best of both worlds. A fast physics engine for rigid bodies and the possibility to simulate deformable (and possibly breakable) objects.
Besides, this is a perfect candidate for using PixelBender since it involves heavy math crunching on big matrices, which doesn’t make sense for the current Box2D iterative impulse solver. Meanwhile Michael is working hard to release the next motor2 version soon, and once it’s done we hope to expand motor2 with finite element capabilities.

Ace of Mace

January 9, 2009 on 5:03 pm | In Games, Links | 3 Comments

Last year some guys started to work on a game called Ace of Mace built on top of my physics engine. It was officially released yesterday and won a price at the Europrix Multimedia Award before. Today it’s featured as the Adobe Site of the day. Great work!

Speaking about motor2, version 0.9 was released at the end of last year, and now I’m working on it to get a major release done.

FlashDevelop 3.0.0 Alpha released

May 25, 2007 on 11:08 am | In Links, Miscellaneous | No Comments

Mika from flashdevelop.org: “Here’s a release that lots of people have been waiting for, FlashDevelop 3. This is an alpha release that may contain bugs or may lack some features but we wanted to start the release cycle for our new baby. We hope you like it.”

Hell yes, I love it! I also tried Flex Builder, but I prefer using FlashDevelop because it’s free, fast and has everything I need for Flash development. The only thing I’m missing is a built-in debugger, but as I understood the guys are also working on it.

More information: http://www.flashdevelop.org/community/viewtopic.php?t=1436

FlashDevelop 2.0.0 released

October 5, 2006 on 9:31 pm | In Links, Miscellaneous | No Comments

Finally, FlashDevelop 2 is released :-) No new features, but some bug fixes and improvements. One outstanding feature is the fast auto-completion for build-in and custom classes, which I never want to miss again. And it already supports AS3 and Flex2 compilation. If you have never used FlashDevelop, give it a try.

Proudly powered by WordPress Theme based upon Pool theme by Borja Fernandez.
Entries and comments feeds.