Piotr Janik, a Google Summer of Code student working with us at the Concord Consortium in the summer of 2012 created a JavaScript implementation of the Java application Energy2D originally created by Charles Xie at the Concord Consortium.
Energy2D simulates thermal conductivity, convection, and radiation in a an authorable 2D environment. The JavaScript implementation of Energy2D supports over 80 different models originally written for the Java version of Energy2D.
The Java version of Energy2D uses a 100x100 cell grid size. This means that the program is performing a large number of complex array operations on 10,000 cells for every model step. Almost 18 months ago Stephen Bannasch at the Concord Consortium wondered if these modern browsers were now fast enough to perform these calculaions entirely in JavaScript and created the initial JavaScript implementation of Energy2D. The suprisingly fast results convinced us it is now feasible to run complex simulations of this kind in the browser. Piotr extended and re-architected this early prototype to complete the physics modeling and greatly expand the view features. However in this summer's effort we didn't focus on making a web-based authoring environment for creating new models. Instead we implemented scripts to automatically convert the XML-based serialization format to JSON. Currently the Java version of Energy2D models is used to create new models.
At the end of the summer Piotr re-implemented the physics solvers and views for Energy2D in WebGL to find out whether this was practical and what performance gains might be possible. We have only implemented a few of the 80 models in Energy2D-WebGL but initial results indicate speedups ranging from 2X to 15X!
Piotr's article: Under the Hood: Using WebGL to Accelerate Advanced Physics Simulations in the Browser is available on page 14 of our Fall 2012 newsletter. This article and the source code for the JavaScript and GPGPU-based heat solvers in Energy2D provide a good introduction to this topic.
The speedups are particularly noticable in the following cases:
Moving from a 100x100 simulation grid to 500x500 cells increases the computational load 25 times. Implemented in JavaScript without using WebWorkers this means each model step is now 25 times slower. However these kind of grid-based algorithms can be effectively run in parallel and see great speedups when running in WebGL.
JavaScript Energy2D will run somehwat slowly in Android smartphones available today. However the beta version of Firefox for Android supports WebGL and the models run much faster using this capability.
Certain models may benefit from using a more fine-grained model time-step.
It might be practical to make a 3D version with the increased performance available running in WebGL.