DummyMath Benchmark

No preview image

1 collaborator

Uri_dolphin3 Uri Wilensky (Author)

Tags

(This model has yet to be categorized with any tags)
Model group CCL | Visible to everyone | Changeable by group members (CCL)
Model was written in NetLogo 3.2pre2 • Viewed 137 times • Downloaded 23 times • Run 0 times
Download the 'DummyMath Benchmark' modelDownload this modelEmbed this model

Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)


Comments and Questions

Please start the discussion about this model! (You'll first need to log in.)

Click to Run Model

globals [ result ]

to benchmark
  set result 0.0
  random-seed 362
  reset-timer
  setup
  repeat 100000 [ go ]
  set result timer
end 

to setup
  ca
end 

;; I ripped the math out of the collide procedure from the GasLab New Benchmark. ~Forrest (6/06/2006)

to go

  ;;; PHASE 1: initial setup
  let mass1 2.0 + random-float 10.0
  let speed1 2.0 + random-float 10.0
  let heading1 random-float 360

  let mass2 2.0 + random-float 10.0
  let speed2 2.0 + random-float 10.0
  let heading2 random-float 360

  ;; since particles are modeled as zero-size points, theta isn't meaningfully
  ;; defined. we can assign it randomly without affecting the model's outcome.
  let theta (random-float 360)

  ;;; PHASE 2: convert velocities to theta-based vector representation

  ;; now convert my velocity from speed/heading representation to components
  ;; along theta and perpendicular to theta
  let v1t (speed1 * cos (theta - heading1))
  let v1l (speed1 * sin (theta - heading1))

  ;; do the same for other-particle
  let v2t (speed2 * cos (theta - heading2))
  let v2l (speed2 * sin (theta - heading2))



  ;;; PHASE 3: manipulate vectors to implement collision

  ;; compute the velocity of the system's center of mass along theta
  let vcm (((mass1 * v1t) + (mass2 * v2t)) / (mass1 + mass2) )

  ;; now compute the new velocity for each particle along direction theta.
  ;; velocity perpendicular to theta is unaffected by a collision along theta,
  ;; so the next two lines actually implement the collision itself, in the
  ;; sense that the effects of the collision are exactly the following changes
  ;; in particle velocity.
  set v1t (2 * vcm - v1t)
  set v2t (2 * vcm - v2t)

  ;;; PHASE 4: convert back to normal speed/heading

  ;; now convert my velocity vector into my new speed and heading
  set speed1 sqrt ((v1t * v1t) + (v1l * v1l))
  let energy1 (0.5 * mass1 * speed1 * speed1)
  ;; if the magnitude of the velocity vector is 0, atan is undefined. but
  ;; speed will be 0, so heading is irrelevant anyway. therefore, in that
  ;; case we'll just leave it unmodified.
  if v1l != 0 or v1t != 0
    [ set heading1 (theta - (atan v1l v1t)) ]

  ;; and do the same for other-particle
  set speed2 sqrt ((v2t * v2t) + (v2l * v2l))
  let energy2 (0.5 * mass2 * speed2 * speed2)
  if v2l != 0 or v2t != 0
    [ set heading2 (theta - (atan v2l v2t)) ]
end 

There are 3 versions of this model.

Uploaded by When Description Download
Uri Wilensky almost 14 years ago Updated from NetLogo 4.1 Download this version
Uri Wilensky almost 14 years ago DummyMath Benchmark Download this version
Uri Wilensky almost 14 years ago DummyMath Benchmark Download this version

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.