실시간 수천 개 입자 시뮬레이션

8000체에 대한 -체 문제를 실시간으로 시뮬레이션한 것입니다.
 In[1]:= Xsrcf = FileNameJoin[{\$OpenCLLinkPath, "SupportFiles", "NBody.cl"}];
 In[2]:= XNBody = OpenCLFunctionLoad[{srcf}, "nbody_sim", {{"Float4", _, "Input"}, {"Float4", _, "Input"}, _Integer, "Float", "Float", {"Local", "Float"}, {"Float4", _, "Output"}, {"Float4", _, "Output"}}, 256];
 In[3]:= XnumParticles = 8192; deltaT = 0.01; epsSqrt = 1.0; pos = OpenCLMemoryLoad[ RandomReal[Sqrt[numParticles], {numParticles, 4}], "Float4"]; vel = OpenCLMemoryLoad[RandomReal[5, {numParticles, 4}], "Float4"]; newPos = OpenCLMemoryAllocate["Float4", {numParticles, 4}]; newVel = OpenCLMemoryAllocate["Float4", {numParticles, 4}];
 In[4]:= Xcolors = Map[ColorData["CherryTones"], Range[0, 1, 1/numParticles]] //. RGBColor -> List;
 In[5]:= XGraphics3D[{AbsolutePointSize[2], Point[ Dynamic[Refresh[ NBody[pos, vel, numParticles, deltaT, epsSqrt, 256*4, newPos, newVel, numParticles]; NBody[newPos, newVel, numParticles, deltaT, epsSqrt, 256*4, pos, vel, numParticles]; Take[#, 3] & /@ OpenCLMemoryGet[pos], UpdateInterval -> 0]], VertexColors -> colors]}, Boxed -> False, RotationAction -> "Clip"]
 Play Animation »Stop Animation »