By Philippe Leefsma (@F3lipek)
It all started with my interest for physic based simulations: since I'm a programmer I always found it so cool to write computer programs where objects are ruled by the laws of physics!
This time I wanted to play with a particle system and see how it could perform in the browser, trying to integrate it into our viewer and have some fun with it. Browsing through the web for some existing samples, I found this cool demo from Jarrod Overson and decided to use it as starting point.
Although working nicely, Jarrod's demo is 2D and a bit too tied to his UI implementation for my needs. My first steps were to add a third dimension to the simulation and also decouple the particle system from the UI so it only takes care about managing the physic and becomes easily pluggable with any other web viewing solution - A.K.A. View & Data API.
The system has four main components:
- Particle objects which hold each particle properties (position, velocity and so on...)
- Particle emitters which are initializing the particle properties upon emission
- Magnetic fields which are imposing their force to the particles at each time step
- Finally the particle system itself which acts as a manager, owning all the objects, it is responsible for updating them and filtering out particles if they go out of defined bounds or their lifetime expire.
My other enhancement to the initial code is a recycling mechanism for the particles: in my sample each particle is referencing a THREE.Mesh in the scene to represent it. It would be too memory intensive to add a mesh to the scene every time a new particle is emitted. So once an existing particle is filtered out, it is pushed to a recycle stack, the mesh is hidden from the scene and when the system needs a new particle, it will first pop out a recycled particle. Only if the recycled bin is empty, a new particle and mesh are created.
A side note on performance and meshes: the View & Data API renderer does not yet support the THREE.PointCloud object (formerly named THREE.ParticleSystem) but the development team does have that in the pipe so it will be interesting to migrate the demo to use point cloud once it's available! In the meantime you can take a look at what is already achievable using THREE.js with the cool potree project.
The first basic demo I created using that particle system is available there - Running on a free Heroku dyno, you may have to reload twice if the first request gets timed out. It's a simple scene with one emitter and two fields so you can play around.
Like Jarrod, I used a library named dat.GUI control from Chome Experiments in order to create the interfaces to tweak the simulation properties. In the viewer you can select emitters or fields and specific properties are appended to a panel dynamically. I found the dat.GUI control pretty slick and really easy to use! Highly recommended it if you need an interface in your project to modify a JavaScript object and don't want to spend hours coding the UI.
I was happy with that sample and didn't plan much modifications, however it caught the attention of a group of scientists at the CERN working on the LHC particle accelerator (Large Hadron Collider), one of the most famous and successful scientific experiments of all time, also the biggest machine on earth.
Running a single experiment in the LHC costs thousands of dollars, as well as several days of calibration and once finished equally as long to analyze the results. This team, called LHC-C (stands for LHC - Cloud) is investigating new cutting edge ways to simulate particle acceleration using cloud technologies. This could not only save a huge amount of preparation time, money but also reduce the risks of producing an earth-wiping blackhole!
They asked if View & Data was up for that task and if we could create a demo project based on the particle engine that would simulate such experiments. I happily went to spend three days with the LHC-C team in order to gather requirements in the field, unfortunately not allowed to take any picture of the premises as only official ones are allowed.
I came up with a pretty convincing demo that you can run from that link and looks as below:
Each of the magnets in the scene can be selected independently and their force modified so very accurate tests can be carried out to see how the overall particle stream gets affected:
Since this one is just a proof of concept, the CERN allowed me to share publicly the source code, so you can take a look at it there: Viewing.Extension.Particle
Because it involves several files, I added a build step to my workflow using webpack, a fantastic tool that is able to bundle all the .js and .css into a single extension file that can be loaded by the viewer. Also highly recommended if you work on medium to large web projects!
The outcome:
The LHC-C team started to use more heavily View & Data API but they needed more than just viewing or gathering particle collisions results. They deal with massive amount of data and also require huge computing power to simulate those experiments... which both sounded like a good candidate for processing in the cloud!
Looking at this success Autodesk headquarters decided to create a new branch in our expending web-services collection, A.K.A. Forge and this is how the Autodesk Physics Web API was created.
Since couple of months, a dedicated team of physicists and programmers are working to the ground to get the Autodesk Physics API ready for June 15, launch of our Forge conference in San Francisco. This API is said to open a whole new perspective in how particle experiments are are conducted allowing for cheaper, faster and better analysis of the results.
The first API to be unveiled will be /collide:
POST - https://developer.api.autodesk.com/physics/v1/collide
A REST POST endpoint where a client can send a payload describing two particles colliding at near light-speed velocity and returning a set of new particles being generated as a result of the collision in JSON format.
An example payload of a collision between a neutrino and a proton may look as follow:
1 {
2 particleA: {
3
4 type: Autodesk.Physics.Particle.Type.NEUTRINO,
5 subType: Autodesk.Physics.Particle.SubType.MUON_NEUTRINO,
6
7 statistic: Autodesk.Physics.Statistic.FERMIONIC,
8
9 // interactions applying to the particule
10 interactions: [
11 Autodesk.Physics.Interactions.WEAK,
12 Autodesk.Physics.Interactions.GRAVITATION
13 ],
14
15 mass: 0.320,
16 electricCharge: 0,
17 spin: 0.5,
18 weakHypercharge: 1,
19
20 //cinematic properties - near light speed velocity
21 velocity: 0.9853563 * Autodesk.Physics.Constants.C,
22 direction: [-1, 0, 0]
23 },
24
25 particleB:{
26
27 type: Autodesk.Physics.Particle.Type.BARYON,
28 subType: Autodesk.Physics.Particle.SubType.PROTON,
29
30 statistic: Autodesk.Physics.Statistic.FERMIONIC,
31
32 composition: {
33 upQuarks: 2,
34 downQuarks: 1
35 },
36
37 // interactions applying to the particule
38 interactions: [
39 Autodesk.Physics.Interactions.WEAK,
40 Autodesk.Physics.Interactions.STRONG,
41 Autodesk.Physics.Interactions.GRAVITATION,
42 Autodesk.Physics.Interactions.ELECTROMAGNETIC
43 ],
44
45 mass: 1.67262177774 * 10E-27,
46 meanLifetime: 2.1 * 1029,
47 electricCharge: 1.60217656535 * 10E-19,
48 chargeRadius: 0.877551,
49 electricDipoleMoment: 5.4 * 10E-24,
50 electricPolarizability: 1.206 * 10E3,
51 magneticMoment: 1.41060674333 * 10E-26,
52 magneticPolarizability: 1.95 * 10E-4,
53 spin: 0.5,
54 isoSpin: 0.5,
55 parity: 1,
56
57 //cinematic properties - near light speed velocity
58 velocity: 0.936454 * Autodesk.Physics.Constants.C,
59 direction: [1, 0, 0]
60 }
61 }
The results can then be directly visualised with View & Particle, a customised version of the viewer specialized in displaying particle collision results:
More amazing API's are in the pipe and will hopefully be ready for June! We can already announce the /multiverse API which will allow to simulate experiments in parallel universes, the /antimatter API which will simulate collisions between antiparticles or the /bigbang API which will reproduce initial conditions of the universe using custom parameters!
The public specifications for the Autodesk Physics API are available since this exact day in prime time at this location. Check it out and stay tuned for more news from the subatomic world!