offset_momentum   xtlang


Defined in:  https://github.com/digego/extempore/tree/v0.8.9/examples/core/nbody_lang_shootout.xtm

Implementation

(bind-func offset_momentum
  (lambda (nbodies bodies:planet*)
    (let ((px 0.0) (py 0.0) (pz 0.0)
          (b:planet* null)
          (i 0))
      (dotimes (i nbodies)
        (set! b (pref-ptr bodies i))
        (set! px (+ px (* (tref b 3) (tref b 6))))
        (set! py (+ py (* (tref b 4) (tref b 6))))
        (set! pz (+ pz (* (tref b 5) (tref b 6)))))
      (tset! bodies 3 (/ (- 0.0 px) solar_mass))
      (tset! bodies 4 (/ (- 0.0 py) solar_mass))
      (tset! bodies 5 (/ (- 0.0 pz) solar_mass))
      void)))


Back to Index

Similar Entries