GasLab Free Gas 3D

GasLab Free Gas 3D 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 3D 4.1pre1 • Viewed 258 times • Downloaded 28 times • Run 0 times
Download the 'GasLab Free Gas 3D' modelDownload this modelEmbed this model

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


WHAT IS IT?

This model is a 3D version of the 2D model Gas Lab Free Gas; it is one in a series of GasLab models. They use the same basic rules for simulating the behavior of gases. Each model integrates different features in order to highlight different aspects of gas behavior.

The basic principle of the models is that gas particles are assumed to have two elementary actions: they move and they collide - either with other particles or with any other objects such as walls.

This model is the simplest gas model in the suite of GasLab models. The particles are moving and colliding with each other with no external constraints, such as gravity or containers. (The world is a torus which means that when a particle hits the edge of the world it "wraps" around to the other side. The box surrounding the world in the 3D view are not walls but simply mark the edges of the world where the particles will wrap.)

In this model, particles are modeled as perfectly elastic ones with no energy except their kinetic energy -- which is due to their motion. Collisions between particles are elastic. Particles are colored according to their speed -- blue for slow, green for medium, and red for high.

HOW IT WORKS

The basic principle of all GasLab models is the following algorithm (for more details, see the model "GasLab Gas in a Box"):

1) A particle moves in a straight line without changing its speed, unless it collides with another particle or bounces off the wall.

2) Two particles "collide" if their surfaces touch. In this model, the time at which any collision is about to occur is measured, and particles move forward until the first pair to collide touch one another. They are collided, and the cycle repeats.

3) The vector of collision for the particles describes the direction of the line connecting their centers.

4) The particles exchange momentum and energy only along this line, conforming to the conservation of momentum and energy for elastic collisions.

5) Each particle is assigned its new speed, direction and energy.

HOW TO USE IT

Initial settings:

- NUMBER-OF-PARTICLES: the number of gas particles.

- TRACE?: Draws the path of one individual particle.

- COLLIDE?: Turns collisions between particles on and off.

- INIT-PARTICLE-SPEED: the initial speed of each particle -- they all start with the same speed.

- PARTICLE-MASS: the mass of each particle -- they all have the same mass.

- PARTICLE-COLOR: indicates the coloring scheme for the particles.

As in most NetLogo models, the first step is to press SETUP. It puts in the initial conditions you have set with the sliders. Be sure to wait till the SETUP button stops before pushing GO.

The GO button runs the models again and again. This is a "forever" button.

Monitors:

- PERCENT FAST, PERCENT MEDIUM, PERCENT SLOW monitors: percent of particles with different speeds: fast (red), medium (green), and slow (blue).

- AVERAGE SPEED: average speed of the particles.

- AVERAGE ENERGY: average kinetic energy of the particles.

Plots:

- SPEED COUNTS: plots the number of particles in each range of speed (fast, medium or slow).

- SPEED HISTOGRAM: speed distribution of all the particles. The gray line is the average value, and the black line is the initial average. The displayed values for speed are ten times the actual values.

- ENERGY HISTOGRAM: the distribution of energies of all the particles, calculated as (m*v^2)/2. The gray line is the average value, and the black line is the initial average.

Initially, all the particles have the same speed but random directions. Therefore the first histogram plots of speed and energy should show only one column each. As the particles repeatedly collide, they exchange energy and head off in new directions, and the speeds are dispersed -- some particles get faster, some get slower, and the plot will show that change.

THINGS TO NOTICE

What is happening to the numbers of particles of different colors? Why are there more blue particles than red ones?

Can you observe collisions and color changes as they happen? For instance, when a red particle hits a green particle, what color do they each become?

Why does the average speed (avg-speed) drop? Does this violate conservation of energy?

This gas is in "endless space" -- no boundaries, no obstructions, but still a finite size! Is there a physical situation like this?

Watch the particle whose path is traced, notice how the path "wraps" around the world. Does the trace resemble Brownian motion? Can you recognize when a collision happens? What factors affect the frequency of collisions? What about the "angularity" of the path? Could you get it to stay "local" or travel all over the world?

In what ways is this model an "idealization" of the real world?

THINGS TO TRY

Set all the particles in part of the world, or with the same heading -- what happens? Does this correspond to a physical possibility?

Try different settings, especially the extremes. Are the histograms different? Does the trace pattern change?

Are there other interesting quantities to keep track of?

Look up or calculate the REAL number, size, mass and speed of particles in a typical gas. When you compare those numbers to the ones in the model, are you surprised this model works as well as it does? What physical phenomena might be observed if there really were a small number of big particles in the space around us?

We often say outer space is a vacuum. Is that really true? How many particles would there be in a space the size of this computer?

EXTENDING THE MODEL

Could you find a way to measure or express the "temperature" of this imaginary gas? Try to construct a thermometer.

What happens if there are particles of different masses?

How would you define and calculate pressure in this "boundless" space?

What happens if the gas is inside a container instead of a boundless space?

What happens if the collisions are non-elastic?

How does this 3D model differ from the 2D model?

Set up only two particles to collide head-on. This may help to show how the collision rule works. Remember that the axis of collision is being randomly chosen each time.

What if some of the particles had a "drift" tendency -- a force pulling them in one direction? Could you develop a model of a centrifuge, or charged particles in an electric field?

Find a way to monitor how often particles collide, and how far they go, on average, between collisions. The latter is called the "mean free path". What factors affect its value?

In what ways is this idealization different from the one used to derive the Maxwell-Boltzmann distribution? Specifically, what other code could be used to represent the two-body collisions of particles?

If MORE than two particles arrive on the same patch, the current code says they don't collide. Is this a mistake? How does it affect the results?

Is this model valid for fluids in any aspect? How could it be made to be fluid-like?

NETLOGO FEATURES

Notice the use of the histogram primitive.

CREDITS AND REFERENCES

This was one of the original Connection Machine StarLogo applications (under the name GPCEE) and is now ported to NetLogo as part of the Participatory Simulations project.

HOW TO CITE

If you mention this model in an academic publication, we ask that you include these citations for the model itself and for the NetLogo software:

- Wilensky, U. (2006). NetLogo GasLab Free Gas 3D model. http://ccl.northwestern.edu/netlogo/models/GasLabFreeGas3D. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.

- Wilensky, U. (1999). NetLogo. http://ccl.northwestern.edu/netlogo/. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.

In other publications, please use:

- Copyright 2006 Uri Wilensky. All rights reserved. See http://ccl.northwestern.edu/netlogo/models/GasLabFreeGas3D for terms of use.

COPYRIGHT NOTICE

Copyright 2006 Uri Wilensky. All rights reserved.

Permission to use, modify or redistribute this model is hereby granted, provided that both of the following requirements are followed:

a) this copyright notice is included.

b) this model will not be redistributed for profit without permission from Uri Wilensky. Contact Uri Wilensky for appropriate licenses for redistribution for profit.

This is a 3D version of the 2D model GasLab Free Gas.

Comments and Questions

Click to Run Model

globals
[
  tick-delta                         ;; how much we advance the tick counter this time through
  max-tick-delta                     ;; the largest tick-delta is allowed to be
  min-tick-delta                     ;; the smallest tick-delta is allowed to be
  init-avg-speed init-avg-energy     ;; initial averages
  avg-speed avg-energy               ;; current averages
  fast medium slow                   ;; current counts
  percent-fast percent-medium        ;; percentage of the counts
  percent-slow                       ;; percentage of the counts

  collision-times                    ;; a list that of times of pending collisions
]

breed [ particles particle ]

particles-own
[
  vx vy vz                   ;; velocities rel axes
  speed mass energy          ;; particle info
  collision-time             ;; to determine when collision is
  collision-with             ;; to determine who the collision is with
  last-collision             ;; so they don't collide with one another many times
]

to setup
  ca
  set-default-shape particles "circle"
  set tick-delta .01
  set min-tick-delta .0000001
  make-particles
  check-initial-positions
  update-variables
  set init-avg-speed avg-speed
  set init-avg-energy avg-energy
  setup-histograms
  do-plotting
  if trace?
  [ ask one-of particles [ pd ] ]
end 

to go
  set collision-times [] ;; empty this out for new input
  ask particles
  [
    set collision-time tick-delta
    set collision-with nobody
    if collide? [ detect-collisions ]
  ]

  ifelse( empty? collision-times )
  [ set collision-times lput ( tick-delta ) collision-times ]
  [ set collision-times ( sort collision-times ) ]

    ifelse ( first collision-times ) < tick-delta   ;; if something will collide before the tick
    [
      ask particles [ jump speed * ( first collision-times ) ] ; most particles to first collision
      tick-advance ( first collision-times ) ;; now, collide all the particles that are ready
      ask particles with [ collision-time = ( first collision-times ) ] [
        if collision-with > who [ ;; so that we don't collide the same particles twice
            collide ( turtle collision-with )
            set last-collision collision-with
            ask turtle collision-with [ set last-collision [who] of myself ]
        ]
      ]
    ] [
      ask particles [ jump speed * tick-delta ]
      tick-advance tick-delta
    ]

  ask particles [
    if last-collision != nobody
    [
      if distance turtle last-collision > ( ( ( [size] of turtle last-collision ) / 2 ) + ( size / 2 ) ) * 1.5
      [ set last-collision nobody ]
    ]
  ]

  if floor ticks > floor (ticks - tick-delta) [
    update-variables
    do-plotting
  ]

  display
end 

to update-variables
  set medium count particles with [ speed < ( 1.5 * 10 ) and speed > ( 0.5 * 10 ) ]
  set slow count particles with [ speed < ( 0.5 * 10 ) ]
  set fast count particles with [ speed > ( 1.5 * 10 ) ]
  set percent-medium (medium / count particles) * 100
  set percent-slow (slow / count particles) * 100
  set percent-fast (fast / count particles) * 100
  set avg-speed  mean [speed] of particles
  set avg-energy  mean [energy] of particles
end 


;;;
;;; distance and collision procedures
;;;

to detect-collisions ; particle procedure

;; detect-collisions is a particle procedure that determines the time it takes to the collision between
;; two particles (if one exists).  It solves for the time by representing the equations of motion for
;; distance, velocity, and time in a quadratic equation of the vector components of the relative velocities
;; and changes in position between the two particles and solves for the time until the next collision

  let my-x xcor
  let my-y ycor
  let my-z zcor
  let my-particle-size size
  let my-x-speed (x-velocity heading pitch speed )
  let my-y-speed (y-velocity heading pitch speed )
  let my-z-speed (z-velocity pitch speed )
  let my-last-collision last-collision

  ask other particles with [who != my-last-collision]
  [
    let dpx 0
    let dpy 0
    let dpz 0

    ;; since our world is wrapped, we can't just use calcs like xcor - my-x. Instead, we take the smallest
    ;; of either the wrapped or unwrapped distance for each dimension

    ifelse ( abs ( xcor - my-x ) <= abs ( ( xcor - my-x ) - world-width ) )
      [ set dpx (xcor - my-x) ]
      [ set dpx (xcor - my-x) - world-width ]  ;; relative distance between particles in the x direction
    ifelse ( abs ( ycor - my-y ) <= abs ( ( ycor - my-y ) - world-height ) )
      [ set dpy (ycor - my-y) ]
      [ set dpy (ycor - my-y) - world-height ]    ;; relative distance between particles in the y direction
    ifelse ( abs ( zcor - my-z ) <= abs ( ( zcor - my-z ) - world-depth ) )
      [ set dpz (zcor - my-z) ]
      [ set dpz (zcor - my-z) - world-depth ]       ;; relative distance between particles in the z direction

    let x-speed (x-velocity heading pitch speed ) ;; speed of other particle in the x direction
    let y-speed (y-velocity heading pitch speed ) ;; speed of other particle in the y direction
    let z-speed (z-velocity pitch speed )         ;; speed of other particle in the z direction

    let dvx (x-speed - my-x-speed) ;; relative speed difference between particles in the x direction
    let dvy (y-speed - my-y-speed) ;; relative speed difference between particles in the y direction
    let dvz (z-speed - my-z-speed) ;; relative speed difference between particles in the z direction

    let sum-r (((my-particle-size) / 2 ) + (([size] of self) / 2 )) ;; sum of both particle radii

    ;; To figure out what the difference in position (P1) between two particles at a future time (t) would be,
    ;; one would need to know the current difference in position (P0) between the two particles
    ;; and the current difference in the velocity (V0) between of the two particles.

    ;; The equation that represents the relationship would be:   P1 = P0 + t * V0

    ;; we want find when in time (t), P1 would be equal to the sum of both the particle's radii (sum-r).
    ;; When P1 is equal to is equal to sum-r, the particles will just be touching each other at
    ;; their edges  (a single point of contact).

    ;; Therefore we are looking for when:   sum-r =  P0 + t * V0

    ;; This equation is not a simple linear equation, since P0 and V0 should both have x and y components
    ;;  in their two dimensional vector representation (calculated as dpx, dpy, and dvx, dvy).

    ;; By squaring both sides of the equation, we get:     (sum-r) * (sum-r) =  (P0 + t * V0) * (P0 + t * V0)

    ;;  When expanded gives:   (sum-r ^ 2) = (P0 ^ 2) + (t * PO * V0) + (t * PO * V0) + (t ^ 2 * VO ^ 2)

    ;;  Which can be simplified to:    0 = (P0 ^ 2) - (sum-r ^ 2) + (2 * PO * V0) * t + (VO ^ 2) * t ^ 2

    ;;  Below, we will let p-squared represent:   (P0 ^ 2) - (sum-r ^ 2)
    ;;  and pv represent: (2 * PO * V0)
    ;;  and v-squared represent: (VO ^ 2)

    ;;  then the equation will simplify to:     0 = p-squared + pv * t + v-squared * t^2

    let p-squared   ((dpx * dpx) + (dpy * dpy) + (dpz * dpz)) - (sum-r ^ 2)   ;; p-squared represents difference of the
    ;; square of the radii and the square
    ;; of the initial positions

    let pv  (2 * ((dpx * dvx) + (dpy * dvy) + (dpz * dvz)))  ;;the vector product of the position times the velocity
    let v-squared  ((dvx * dvx) + (dvy * dvy) + (dvz * dvz)) ;; the square of the difference in speeds
    ;; represented as the sum of the squares of the x-component
    ;; and y-component of relative speeds between the two particles

    ;; p-squared, pv, and v-squared are coefficients in the quadratic equation shown above that
    ;; represents how distance between the particles and relative velocity are related to the time,
    ;; t, at which they will next collide (or when their edges will just be touching)

    ;; Any quadratic equation that is the function of time (t), can represented in a general form as:
    ;;   a*t*t + b*t + c = 0,
    ;; where a, b, and c are the coefficients of the three different terms, and has solutions for t
    ;; that can be found by using the quadratic formula.  The quadratic formula states that if a is not 0,
    ;; then there are two solutions for t, either real or complex.

    ;; t is equal to (b +/- sqrt (b^2 - 4*a*c)) / 2*a

    ;; the portion of this equation that is under a square root is referred to here
    ;; as the determinant, D1.   D1 is equal to (b^2 - 4*a*c)
    ;; and:   a = v-squared, b = pv, and c = p-squared.

    let D1 pv ^ 2 -  (4 * v-squared * p-squared)

    ;; the next line next line tells us that a collision will happen in the future if
    ;; the determinant, D1 is >= 0,  since a positive determinant tells us that there is a
    ;; real solution for the quadratic equation.  Quadratic equations can have solutions
    ;; that are not real (they are square roots of negative numbers).  These are referred
    ;; to as imaginary numbers and for many real world systems that the equations represent
    ;; are not real world states the system can actually end up in.

    ;; Once we determine that a real solution exists, we want to take only one of the two
    ;; possible solutions to the quadratic equation, namely the smaller of the two the solutions:

    ;;  (b - sqrt (b^2 - 4*a*c)) / 2*a
    ;;  which is a solution that represents when the particles first touching on their edges.

    ;;  instead of (b + sqrt (b^2 - 4*a*c)) / 2*a
    ;;  which is a solution that represents a time after the particles have penetrated
    ;;  and are coming back out of each other and when they are just touching on their edges.


    let time-to-collision  -1

    if D1 >= 0
      [set time-to-collision (- pv - sqrt D1) / (2 * v-squared) ]        ;;solution for time step

    ;; if time-to-collision is still -1 there is no collision in the future - no valid solution
    ;; note:  negative values for time-to-collision represent where particles would collide
    ;; if allowed to move backward in time.
    ;; if time-to-collision is greater than 1, then we continue to advance the motion
    ;; of the particles along their current trajectories.  They do not collide yet.
    ;; to keep the model from slowing down too much, if the particles are going to collide
    ;; at a time before min-tick-delta, just collide them a min-tick-delta instead

    if ( time-to-collision < tick-delta and time-to-collision > min-tick-delta ) [
      set collision-with ( [who] of myself )
      set collision-time ( time-to-collision )
      set collision-times ( lput ( time-to-collision ) collision-times )
    ]
    if ( time-to-collision < min-tick-delta and time-to-collision > 0 ) [
      set collision-with ( [who] of myself )
      set collision-time ( min-tick-delta )
      set collision-times ( lput ( min-tick-delta ) collision-times )
    ]
  ]
end 

to collide [ particle2 ] ;; turtle procedure
  update-component-vectors
  ask particle2 [ update-component-vectors ]

  ;; find heading and pitch from the center of particle1 to the center of particle2
  let theading towards particle2
  let tpitch towards-pitch particle2

  ;; use these to determine the x, y, z components of theta
  let tx x-velocity theading tpitch 1
  let ty y-velocity theading tpitch 1
  let tz z-velocity tpitch 1

  ;; find the speed of particle1 in the direction of n
  let particle1totheta ortho-projection vx vy vz tx ty tz

  ;; express particle1's movement along theta in terms of xyz
  let x1totheta particle1totheta * tx
  let y1totheta particle1totheta * ty
  let z1totheta particle1totheta * tz

  ;; now we can find the x, y and z components of the particle's velocity that
  ;; aren't in the direction of theta by subtracting the x, y, and z
  ;; components of the velocity in the direction of theta from the components
  ;; of the overall velocity of the particle
  let x1opptheta ( ( vx ) - ( x1totheta ) )
  let y1opptheta ( ( vy ) - ( y1totheta ) )
  let z1opptheta ( ( vz ) - ( z1totheta ) )

  ;; do the same for particle2
  let particle2totheta ortho-projection [vx] of particle2 [vy] of particle2 [vz] of particle2 tx ty tz

  let x2totheta particle2totheta * tx
  let y2totheta particle2totheta * ty
  let z2totheta particle2totheta * tz

  let x2opptheta ( ( [vx] of particle2 ) - ( x2totheta ) )
  let y2opptheta ( ( [vy] of particle2 ) - ( y2totheta ) )
  let z2opptheta ( ( [vz] of particle2 ) - ( z2totheta ) )

  ;; calculate the velocity of the center of mass along theta
  let vcm ( ( ( mass * particle1totheta ) + ( [mass] of particle2 * particle2totheta ) )
      / ( mass + [mass] of particle2 ) )

  ;; switch momentums along theta
  set particle1totheta (2 * vcm - particle1totheta)
  set particle2totheta (2 * vcm - particle2totheta)

  ;; determine the x, y, z components of each particle's new velocities
  ;; in the direction of theta
  set x1totheta particle1totheta * tx
  set y1totheta particle1totheta * ty
  set z1totheta particle1totheta * tz

  set x2totheta particle2totheta * tx
  set y2totheta particle2totheta * ty
  set z2totheta particle2totheta * tz

  ;; now, we add the new velocities along theta to the unchanged velocities
  ;; opposite theta to determine the new heading, pitch, and speed of each particle
  set vx x1totheta + x1opptheta
  set vy y1totheta + y1opptheta
  set vz z1totheta + z1opptheta
  set heading vheading vx vy vz
  set pitch vpitch vx vy vz
  set speed vspeed vx vy vz
  set energy ( 0.5 * mass * speed ^ 2 )
  if particle-color = "red-green-blue" [ recolor ]
  if particle-color = "purple shades" [ recolorshade ]
  if particle-color = "one color" [ recolornone ]

  ask particle2 [
    set vx x2totheta + x2opptheta
    set vy y2totheta + y2opptheta
    set vz z2totheta + z2opptheta
    set heading vheading vx vy vz
    set pitch vpitch vx vy vz
    set speed vspeed vx vy vz
    set energy ( 0.5 * mass * speed ^ 2 )
    if particle-color = "red-green-blue" [ recolor ]
    if particle-color = "purple shades" [ recolorshade ]
    if particle-color = "one color" [ recolornone ]
  ]
end 


;;;
;;; drawing procedures
;;;

;; creates initial particles

to make-particles
  create-particles number-of-particles
  [
    setup-particle
    random-position
    if particle-color = "red-green-blue" [ recolor ]
    if particle-color = "purple shades" [ recolorshade ]
    if particle-color = "one color" [ recolornone ]
  ]
end 

to setup-particle  ;; particle procedure
  set speed init-particle-speed
  set mass particle-mass
  set energy (0.5 * mass * (speed ^ 2))
end 

;; makes sure particles aren't overlapped at setup

to check-initial-positions
  let check-again? false
  ask particles [
    if particle-overlap? [
      random-position
      set check-again? true
    ]
  ]
  if check-again? [ check-initial-positions ]
end 

to-report particle-overlap? ; particle procedure
  let me ( self )
  let overlap false
  ask other particles [
    if distance ( me ) < ( ( size / 2 ) + ( [size] of me / 2 ) + .1 ) [
      set overlap true
    ]
  ]
  report overlap
end 


;; place particle at random location inside the box.

to random-position ;; particle procedure
  setxyz ((1 + min-pxcor) + random-float ((2 * max-pxcor) - 2))
         ((1 + min-pycor) + random-float ((2 * max-pycor) - 2))
         ((1 + min-pzcor) + random-float ((2 * max-pzcor) - 2)) ;; added for 3d
  set heading random-float 360
  set pitch random-float 360
end 

to move  ;; particle procedure
  jump (speed * tick-delta)
end 

to recolor  ;; particle procedure
  ifelse speed < (0.5 * 10)
  [
    set color blue
  ]
  [
    ifelse speed > (1.5 * 10)
      [ set color red ]
      [ set color green ]
  ]
end 

to recolorshade ;; particle procedure
  ifelse speed < 27
  [ set color 111 + speed / 3 ]
  [ set color 119.999 ]
end 

to recolornone ;; particle procedure
  set color blue + 1
end 


;;;
;;; math procedures
;;;

;; makes sure that the values stored in vx, vy, vz actually reflect
;; the appropriate heading, pitch, speed

to update-component-vectors ;; particle procedure
  set vx ( speed * sin ( heading ) * cos ( pitch ) )
  set vy ( speed * cos ( heading ) * cos ( pitch ) )
  set vz ( speed * sin ( pitch ) )
end 

;; reports velocity of a vector at a given angle and pitch
;; in the direction of x.

to-report x-velocity [ vector-angle vector-pitch vector-speed ]
  let xvel sin( vector-angle ) * abs( cos( vector-pitch ) ) * vector-speed
  report xvel
end 

;; reports velocity of a vector at a given angle and pitch
;; in the direction of y.

to-report y-velocity [ vector-angle vector-pitch vector-speed ]
  let yvel cos( vector-angle ) * abs( cos( vector-pitch ) ) * vector-speed
  report yvel
end 

;; reports velocity of a vector at a given angle and pitch
;; in the direction of z.

to-report z-velocity [ vector-pitch vector-speed ]
  let zvel ( sin( vector-pitch ) * vector-speed )
  report zvel
end 

;; reports speed of a vector given xyz coords

to-report vspeed [ x y z ]
  report ( sqrt( x ^ 2 + y ^ 2 + z ^ 2 ) )
end 

;; reports xt heading of a vector given xyz coords

to-report vheading [ x y z ]
  report atan x y
end 

;; reports pitch of a vector given xyz coords

to-report vpitch [ x y z ]
  report round asin ( z / ( vspeed x y z ) )
end 

;; called by ortho-projection

to-report dot-product [ x1 y1 z1 x2 y2 z2 ]
  report ( ( x1 * x2 ) + ( y1 * y2 ) + ( z1 * z2 ) )
end 

;; component of 1 in the direction of 2 (Note order)

to-report ortho-projection [ x1 y1 z1 x2 y2 z2 ]
  let dproduct dot-product x1 y1 z1 x2 y2 z2
  let speed-of-2 ( vspeed x2 y2 z2 )
  ;; if speed is 0 then there's no projection anyway
  ifelse ( speed-of-2 > 0 )
  [ report ( dproduct / speed-of-2 ) ]
  [ report 0 ]
end 

;;;
;;; plotting procedures
;;;

to setup-histograms
  set-current-plot "Speed Histogram"
  set-plot-x-range 0 (init-particle-speed * 2)
  set-plot-y-range 0 ceiling (number-of-particles / 6)
  set-current-plot-pen "medium"
  set-histogram-num-bars 40
  set-current-plot-pen "slow"
  set-histogram-num-bars 40
  set-current-plot-pen "fast"
  set-histogram-num-bars 40
  set-current-plot-pen "init-avg-speed"
  draw-vert-line init-avg-speed

  set-current-plot "Energy Histogram"
  set-plot-x-range 0 (0.5 * (init-particle-speed * 2) * (init-particle-speed * 2) * particle-mass)
  set-plot-y-range 0 ceiling (number-of-particles / 6)
  set-current-plot-pen "medium"
  set-histogram-num-bars 40
  set-current-plot-pen "slow"
  set-histogram-num-bars 40
  set-current-plot-pen "fast"
  set-histogram-num-bars 40
  set-current-plot-pen "init-avg-energy"
  draw-vert-line init-avg-energy
end 

to do-plotting
  set-current-plot "Speed Counts"
  set-current-plot-pen "fast"
  plotxy ticks percent-fast
  set-current-plot-pen "medium"
  plotxy ticks percent-medium
  set-current-plot-pen "slow"
  plotxy ticks percent-slow

  plot-histograms
end 

to plot-histograms
  set-current-plot "Energy histogram"
  set-current-plot-pen "fast"
  histogram [ energy ] of particles with [ speed > ( 1.5 * 10 ) ]
  set-current-plot-pen "medium"
  histogram [ energy ] of particles with [ speed < ( 1.5 * 10 ) and speed > ( 0.5 * 10 ) ]
  set-current-plot-pen "slow"
  histogram [ energy ] of particles with [ speed < ( 0.5 * 10 ) ]
  set-current-plot-pen "avg-energy"
  plot-pen-reset
  draw-vert-line avg-energy

  set-current-plot "Speed histogram"
  set-current-plot-pen "fast"
  histogram [ speed ] of particles with [ speed > ( 1.5 * 10 ) ]
  set-current-plot-pen "medium"
  histogram [ speed ] of particles with [ speed < ( 1.5 * 10 ) and speed > ( 0.5 * 10 ) ]
  set-current-plot-pen "slow"
  histogram [ speed ] of particles with [ speed < ( 0.5 * 10 ) ]
  set-current-plot-pen "avg-speed"
  plot-pen-reset
  draw-vert-line avg-speed
end 

;; histogram procedure

to draw-vert-line [ xval ]
  plotxy xval plot-y-min
  plot-pen-down
  plotxy xval plot-y-max
  plot-pen-up
end 


; Copyright 2006 Uri Wilensky. All rights reserved.
; The full copyright notice is in the Information tab.

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 Model from NetLogo distribution Download this version
Uri Wilensky almost 14 years ago GasLab Free Gas 3D Download this version

Attached files

File Type Description Last updated
GasLab Free Gas 3D.png preview Preview for 'GasLab Free Gas 3D' about 11 years ago, by Uri Wilensky Download

This model does not have any ancestors.

This model does not have any descendants.