diffusion_sigal_project

No preview image

1 collaborator

Default-person sigal samon (Author)

Tags

(This model has yet to be categorized with any tags)
Model group uhaifa-modeling-11 | Visible to everyone | Changeable by everyone
Model was written in NetLogo 4.0.4 • Viewed 127 times • Downloaded 18 times • Run 1 time
Download the 'diffusion_sigal_project' 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 section could give a general understanding of what the model is trying to show or explain.

HOW IT WORKS

This section could explain what rules the agents use to create the overall behavior of the model.

HOW TO USE IT

This section could explain how to use the model, including a description of each of the items in the interface tab.

THINGS TO NOTICE

This section could give some ideas of things for the user to notice while running the model.

THINGS TO TRY

This section could give some ideas of things for the user to try to do (move sliders, switches, etc.) with the model.

EXTENDING THE MODEL

This section could give some ideas of things to add or change in the procedures tab to make the model more complicated, detailed, accurate, etc.

NETLOGO FEATURES

This section could point out any especially interesting or unusual features of NetLogo that the model makes use of, particularly in the Procedures tab. It might also point out places where workarounds were needed because of missing features.

RELATED MODELS

This section could give the names of models in the NetLogo Models Library or elsewhere which are of related interest.

CREDITS AND REFERENCES

This section could contain a reference to the model's URL on the web if it has one, as well as any other necessary credits or references.

Comments and Questions

פרוצדורת bounce

שרונה שלום. בפרוצדורתהחלפתי את המשתנה bounche במספר אך זה לא עבד.box-edge מה עלי לכתוב במקום box-edg אם אני ?לא רוצה לשים מחוון של גודל הקופסה

Posted almost 13 years ago

כיצד פונים לחלקיקים בתוך הקופסה?

אני רוצה לבקש מהחלקיקים שבתוך הקופסה לשנות צבע לצהוב ולשנות את המסה אך לא הצלחתי לעשותזאת. האם אוכל לקבל עזרה?

Posted almost 13 years ago

כיצד פונים לחלקיקים בתוך הקופסה?

אני רוצה לבקש מהחלקיקים שבתוך הקופסה לשנות צבע לצהוב ולשנות את המסה אך לא הצלחתי לעשותזאת. האם אוכל לקבל עזרה?

Posted almost 13 years ago

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
  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
air-particles perfume-particles
  delta-horizontal-surface   ;; the size of the wall surfaces that run horizontally - the top and bottom of the box
  delta-vertical-surface     ;; the size of the wall surfaces that run vertically - the left and right of the box
]

breed [ particles particle ]

particles-own
[
  speed mass energy          ;; particle info
  last-collision
   step-size
    wall-hits                  ;; # of wall hits during this clock cycle
  momentum-difference        ;; used to calculate pressure from wall hits
  momentum-instant           ;; used to calculate pressure
       
  darkparticle?             
]

to setup
  ca
  set-default-shape particles "circle"
  set max-tick-delta 0.1073
  make-particles
  update-variables
  set init-avg-speed avg-speed
  set init-avg-energy avg-energy
;  setup-plots
;  setup-histograms
;;  do-plotting
  make-box
end 

to
   make-box
  
   ask patches[
    ;; if patches are between (-10,-10) to (-10,-16)...
    if ( pxcor = -10 and pycor <= -10 and pycor >= -16 )
      [set pcolor red]                                 ;; ... draws left edge in red
    ;; if patches are between (-16,-10) to (-16,-16)...
    if ( pxcor = -16 and pycor <= -10 and pycor >= -16 )
      [set pcolor red]                                 ;; ... draws right edge in red
    ;; if patches are between (-10,-10) to (-16,-10)...
    if ( pycor = -10 and pxcor >= -16 and pxcor <= -10 )
      [set pcolor red]                                 ;; ... draws bottom edge in red
    ;; if patches are between (-10,-16) to (-16,-16)...
    if ( pycor = -16 and pxcor >= -16 and pxcor <= -10 )
      [set pcolor red]                                 ;; ... draws upper edge in red
    ]
end 

to go
  ask particles [ move ]
;  ask particles
;  [ if collide? [check-for-collision] ]
;  ifelse (trace?)
;    [ ask particle 0 [ pen-down ] ]
;    [ ask particle 0 [ pen-up ] ]
  tick-advance tick-delta
  if floor ticks > floor (ticks - tick-delta)
  [
    update-variables
;    do-plotting
  ]
  calculate-tick-delta
ask particles [bounce]
  display
end 

to update-variables
  set medium count particles with [color = cyan]
  set slow count particles with [color = cyan]
  set fast count particles with [color = cyan]
  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 

to calculate-tick-delta
  ;; tick-delta is calculated in such way that even the fastest
  ;; particle will jump at most 1 patch length in a tick. As
  ;; particles jump (speed * tick-delta) at every tick, making
  ;; tick length the inverse of the speed of the fastest particle
  ;; (1/max speed) assures that. Having each particle advance at most
  ;; one patch-length is necessary for them not to jump over each other
  ;; without colliding.
  ifelse any? particles with [speed > 0]
    [ set tick-delta min list (1 / (ceiling max [speed] of particles)) max-tick-delta ]
    [ set tick-delta max-tick-delta ]
end 

to bounce  ;; particle procedure
  let new-px 0
  let new-py 0

  ;; if we're not about to hit a wall (yellow patch), or if we're already on a
  ;; wall, we don't need to do any further checks
  if shade-of? red pcolor or not shade-of? red [pcolor] of patch-at dx dy
    [ stop ]
  ;; get the coordinates of the patch we'll be on if we go forward 1
  set new-px round (xcor + dx)
  set new-py round (ycor + dy)
  ;; if hitting left or right wall, reflect heading around x axis
  if (abs new-px = 100)
    [ set heading (- heading)
;      set wall-hits wall-hits + 1
  ;;  if the particle is hitting a vertical wall, only the horizontal component of the speed
  ;;  vector can change.  The change in velocity for this component is 2 * the speed of the particle,
  ;; due to the reversing of direction of travel from the collision with the wall

      set momentum-instant  (abs (sin heading * 2 * mass * speed) / delta-vertical-surface)
      set momentum-difference momentum-difference + momentum-instant
 ]

  ;; if hitting top or bottom wall, reflect heading around y axis
  if (abs new-py = 100)
    [ set heading (180 - heading)
      set wall-hits wall-hits + 1
  ;;  if the particle is hitting a horizontal wall, only the vertical component of the speed
  ;;  vector can change.  The change in velocity for this component is 2 * the speed of the particle,
  ;; due to the reversing of direction of travel from the collision with the wall

    set momentum-instant  (abs (cos heading * 2 * mass * speed) / delta-horizontal-surface)
    set momentum-difference momentum-difference + momentum-instant  ]


;  if (darkparticle? = false) [
;  ask patch new-px new-py
;    [ sprout 1 [
;                 set breed flashes
;                 set birthday ticks
;                 set color red - 3 ] ]
end 

to move  ;; particle procedure
  if patch-ahead (speed * tick-delta) != patch-here
    [ set last-collision nobody ]
  jump (speed * tick-delta)
end 

to check-for-collision  ;; particle procedure
  ;; Here we impose a rule that collisions only take place when there
  ;; are exactly two particles per patch.

  if count other particles-here = 1
  [
    ;; the following conditions are imposed on collision candidates:
    ;;   1. they must have a lower who number than my own, because collision
    ;;      code is asymmetrical: it must always happen from the point of view
    ;;      of just one particle.
    ;;   2. they must not be the same particle that we last collided with on
    ;;      this patch, so that we have a chance to leave the patch after we've
    ;;      collided with someone.
    let candidate one-of other particles-here with
      [who < [who] of myself and myself != last-collision]
    ;; we also only collide if one of us has non-zero speed. It's useless
    ;; (and incorrect, actually) for two particles with zero speed to collide.
    if (candidate != nobody) and (speed > 0 or [speed] of candidate > 0)
    [
      collide-with candidate
      set last-collision candidate
      ask candidate [ set last-collision myself ]
    ]
  ]
end 

;; implements a collision with another particle.
;;
;; THIS IS THE HEART OF THE PARTICLE SIMULATION, AND YOU ARE STRONGLY ADVISED
;; NOT TO CHANGE IT UNLESS YOU REALLY UNDERSTAND WHAT YOU'RE DOING!
;;
;; The two particles colliding are self and other-particle, and while the
;; collision is performed from the point of view of self, both particles are
;; modified to reflect its effects. This is somewhat complicated, so I'll
;; give a general outline here:
;;   1. Do initial setup, and determine the heading between particle centers
;;      (call it theta).
;;   2. Convert the representation of the velocity of each particle from
;;      speed/heading to a theta-based vector whose first component is the
;;      particle's speed along theta, and whose second component is the speed
;;      perpendicular to theta.
;;   3. Modify the velocity vectors to reflect the effects of the collision.
;;      This involves:
;;        a. computing the velocity of the center of mass of the whole system
;;           along direction theta
;;        b. updating the along-theta components of the two velocity vectors.
;;   4. Convert from the theta-based vector representation of velocity back to
;;      the usual speed/heading representation for each particle.
;;   5. Perform final cleanup and update derived quantities.

to collide-with [ other-particle ] ;; particle procedure
  ;;; PHASE 1: initial setup

  ;; for convenience, grab some quantities from other-particle
  let mass2 [mass] of other-particle
  let speed2 [speed] of other-particle
  let heading2 [heading] of other-particle

  ;; 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 (speed * cos (theta - heading))
  let v1l (speed * sin (theta - heading))

  ;; 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 (((mass * v1t) + (mass2 * v2t)) / (mass + 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 speed sqrt ((v1t ^ 2) + (v1l ^ 2))
  set energy (0.5 * mass * (speed ^ 2))
  ;; 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 heading (theta - (atan v1l v1t)) ]

  ;; and do the same for other-particle
  ask other-particle [
    set speed sqrt ((v2t ^ 2) + (v2l ^ 2))
    set energy (0.5 * mass * (speed ^ 2))
    if v2l != 0 or v2t != 0
      [ set heading (theta - (atan v2l v2t)) ]
  ]

  ;; PHASE 5: final updates

  ;; now recolor, since color is based on quantities that may have changed
  recolor
  ask other-particle
    [ recolor ]
end 

to recolor  ;; particle procedure
  ifelse speed < (0.5 * 10)
  [
    set color cyan set size  .40
  ]
  [
    ifelse speed > (1.5 * 10)
      [ set color cyan ]
      [ set color cyan ]
  ]
end 

;;;
;;; drawing procedures
;;;


;; creates initial particles

to make-particles
  create-particles 100
  [
    setup-particle
    random-position
    recolor
  ]
  calculate-tick-delta
end 

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


;; place particle at random location inside the box.

to random-position ;; particle procedure
  setxy ((1 + min-pxcor) + random-float ((2 * max-pxcor) - 2))
        ((1 + min-pycor) + random-float ((2 * max-pycor) - 2))
end 

;to-report last-n [n the-list]
;  ifelse n >= length the-list
;    [ report the-list ]
;    [ report last-n n butfirst the-list ]
;end

There is only one version of this model, created almost 13 years ago by sigal samon.

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.