Sound Across A Medium

No preview image

1 collaborator

Default-person Michael Novak (Author)

Tags

(This model has yet to be categorized with any tags)
Visible to everyone | Changeable by everyone
Model was written in NetLogo 6.0-BETA2 • Viewed 226 times • Downloaded 23 times • Run 0 times
Download the 'Sound Across A Medium' 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?

HOW IT WORKS

HOW TO USE IT

THINGS TO TRY

EXTENDING THE MODEL

NETLOGO FEATURES

CREDITS AND REFERENCES

Developed by Michael Novak, Northwestern University, Evanston, IL.

This model is based on the code from the NetLogo Wave Machine model: http://ccl.northwestern.edu/netlogo/models/WaveMachine. Center for Connected Learning and Computer-Based Modeling, Northwestern University, Evanston, IL.

HOW TO CITE

If you mention this model in a publication, we ask that you include this citation

COPYRIGHT AND LICENSE

Copyright 1997 Uri Wilensky.

CC BY-NC-SA 3.0

This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit http://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.

Commercial licenses are also available. To inquire about commercial licenses, please contact Uri Wilensky at uri@northwestern.edu.

This model was created as part of the project: CONNECTED MATHEMATICS: MAKING SENSE OF COMPLEX PHENOMENA THROUGH BUILDING OBJECT-BASED PARALLEL MODELS (OBPML). The project gratefully acknowledges the support of the National Science Foundation (Applications of Advanced Technologies Program) -- grant numbers RED #9552950 and REC #9632612.

This model was converted to NetLogo as part of the projects: PARTICIPATORY SIMULATIONS: NETWORK-BASED DESIGN FOR SYSTEMS LEARNING IN CLASSROOMS and/or INTEGRATED SIMULATION AND MODELING ENVIRONMENT. The project gratefully acknowledges the support of the National Science Foundation (REPP & ROLE programs) -- grant numbers REC #9814682 and REC-0126227. Converted from StarLogoT to NetLogo, 2001.

Comments and Questions

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

Click to Run Model

globals [
  membrane-edge-x  ;; horizontal distance from center to edge of membrane
  membrane-edge-y  ;; vertical distance from center to edge of membrane
  membrane-center
  detector-value-1
  detector-value-2
  membrane-surface
  atom-batch-twist
 ; driver-vibration-frequency
  red-detector-size
  blue-detector-size
  length-of-simulation
 ; stength-of-push
  empty-space
  #atoms
  vibrate-particles?
  dark-friction-in-medium
  stiffness
  distance-of-blue-squares-from-sound-source
  particle-shape
  friction-in-medium
]

breed [grids grid]
breed [particles particle]
breed [dark-particles dark-particle]
breed [boundaries boundary]
breed [atoms atom]
breed [detectors detector]

particles-own [
  edge?            ;; are we on the edge of the membrane?
  driver?          ;; are we part of the green driving plate?
  x                ;; position on x axis in space
  y                ;; position on y axis in space
  z                ;; position on z axis in space
  velocity         ;; velocity along z axis
  neighbor-particles ;; agentset of particles adjacent to us
]

dark-particles-own [
  edge?
  driver?
  x                ;; position on x axis in space
  y                ;; position on y axis in space
  z                ;; position on z axis in space
  velocity         ;; velocity along z axis
  neighbor-particles ;; agentset of particles adjacent to us
]

boundaries-own [
  edge?
  driver?
  x                ;; position on x axis in space
  y                ;; position on y axis in space
  z                ;; position on z axis in space
  velocity         ;; velocity along z axis
  neighbor-particles ;; agentset of particles adjacent to us
]


patches-own [detector? detector-number]

atoms-own [kind x y offset-distance]

to setup
  clear-all
  set stiffness 2
  set vibrate-particles? true
  set empty-space 2
  set #atoms 3
  set friction-in-medium 0
  set distance-of-blue-squares-from-sound-source 10
  set dark-friction-in-medium 6
  ;set stength-of-push 15
  set length-of-simulation 749
 ; set driver-vibration-frequency 30
  set red-detector-size 1
  set blue-detector-size 1
  set atom-batch-twist false
  set membrane-surface ""
  set membrane-surface "rigid"
  set particle-shape "empty circle"




  ask patches with [(pxcor <= max-pxcor  - 1) and pycor >= (min-pycor + empty-space) and pycor <= (max-pycor - empty-space)]
    [ sprout 1
        [ set breed particles
          set color green
           set edge? false
          set driver? (( pxcor >= min-pxcor and pxcor <= min-pxcor + 5) and pxcor != max-pxcor and pycor >= (min-pycor + empty-space) and pycor <= (max-pycor - empty-space))
          if driver? [ set color orange ]
          set x xcor
          set y ycor
          set z 0
          set velocity 0
          repack ]
        ]

   ask patches with [(pxcor <= max-pxcor  - 1) and pycor >= (min-pycor + empty-space) and pycor <= (max-pycor - empty-space)][
     sprout 1
     [
       set breed dark-particles
       set edge? false
       set driver? false

       set x xcor
       set y ycor
       set z 0

       set velocity 0
       set hidden? true
       repack
     ]
   ]
   ask patches with [(pxcor = max-pxcor) and pycor >= (min-pycor + empty-space) and pycor <= (max-pycor - empty-space)][
     sprout 1
     [
       set breed boundaries
       set edge? false
       set driver? false
       set color violet
       set x xcor
       set y ycor
       set z 0
       set velocity 0
       set hidden? true
       repack
     ]
   ]

  ask particles
    [
      let these-particle-neighbors particles-on neighbors4
      let these-boundary-neighbors boundaries-on neighbors4
      let myxcor x
      if (driver? and pxcor = min-pxcor + 5) [set hidden? true]
      set shape "square"
      set size 2

    ifelse myxcor = (max-pxcor - 1) [set neighbor-particles (turtle-set these-particle-neighbors these-boundary-neighbors) with [x != myxcor] ]
      [  set neighbor-particles these-particle-neighbors with [x != myxcor]  ]
     ]

    ask dark-particles
    [
      let these-dark-neighbors dark-particles-on neighbors4
      let these-boundary-neighbors boundaries-on neighbors4
      let myxcor x
      ifelse myxcor = (max-pxcor - 1) [ set neighbor-particles (turtle-set these-dark-neighbors these-boundary-neighbors) with [x != myxcor]]
      [ set neighbor-particles these-dark-neighbors with [x != myxcor]   ]
   ]

   ask boundaries
    [
      let these-dark-neighbors dark-particles-on neighbors4
      let these-particle-neighbors particles-on neighbors4
      let myxcor x
      set neighbor-particles (turtle-set these-dark-neighbors these-particle-neighbors) with [x != myxcor]
     ]

    ask patches [
      let min-xpos -24

      if (pxcor >= (min-xpos + distance-of-blue-squares-from-sound-source) and pxcor <= (min-xpos + distance-of-blue-squares-from-sound-source + 2)  ) and pycor = 0
         [add-detector-stamp 1 [100 100 255 250]]


    ]

    ask patches [
    set detector? false
    sprout 1 [set breed grids set shape "grid" set color [255 255 255 55] stamp die]
    ]

  calculate-detector-values
  make-atoms
  repack
  reset-ticks
end 

to add-detector-stamp [detector-n this-color]
  set detector-number detector-n
  set detector? true
  sprout 1 [
   set breed detectors
   set shape "square"
   set color this-color
   stamp
   die
  ]
end 

to make-atoms



   ask particles with [not edge? and not driver?] [
      let parent self
      let twist (random 4) * 15
      let my-size .4
      let my-color [0 255 0 150]
     if #atoms = 3 [
       let counter 0
       repeat 3 [
         ;show counter
         hatch 1 [
           let offset -15 + random 30
           set breed atoms
           set heading (0 + twist + offset + counter)
           fd .3
           set size my-size
           set offset-distance (xcor  - pxcor)
           set color my-color
           set shape particle-shape
           set hidden? not show-particles-in-medium?
           create-link-from parent [tie set hidden? true]
          ; __set-line-thickness .05
           set kind "atoms"
          ]
         set counter counter + 120
       ]


     ]
     if #atoms = 1 [
      hatch 1 [
        let offset 0
        set breed atoms
        set heading (0 + twist + offset)
        set size my-size * 2
        set color my-color
        set shape particle-shape
        set hidden? not show-particles-in-medium?
        create-link-from parent [tie set hidden? true]
       ; __set-line-thickness .05
        set kind "atoms"
      ]
     ]
    set hidden? true

   ]
end 

to repack  ;; turtle procedure'
  let my-xcor 0
 ask (turtle-set particles boundaries dark-particles) [
  if not edge?
    [
      setxy x y
      set heading -90

      fd z / slide-step

      ]
   ]
end 

to go
  if (ticks >  length-of-simulation) [stop]

  if vibrate-particles? [ask atoms [
      rt random 180 lt random 180]

    ]

  ask particles with [not edge?]
    [ propagate-across-particles friction-in-medium ]
  ask boundaries
    [ propagate-across-particles friction-in-medium]
  ask dark-particles
    [ propagate-across-particles dark-friction-in-medium]

  ask particles

    [
       let driver-vibration-frequency vibration-frequency * 60
      ifelse driver?
        [ set z (vibration-amplitude * -1 * (sin (0.1 * driver-vibration-frequency * ticks)))
          if (0.1 * driver-vibration-frequency * ticks) / 360 >= #-of-repeated-vibrations [set z 0] ]
        [ set z (z + velocity)]
     ]
  ask boundaries      [ set z (z + velocity)]
  ask dark-particles  [ set z (z + velocity)]
  ask atoms [set shape particle-shape]




  repack
  calculate-detector-values
      ask atoms [
       ifelse show-particles-in-medium?
       [set hidden? not show-particles-in-medium?]
       [set hidden? not show-particles-in-medium?]
      ]
    ;;  density-over-space
  tick
end 

to calculate-detector-values
  let value-1 0
  let value-2 0
  let this-pxcor 0
  ifelse Graph-B
  [
    set detector-value-1 count atoms with [detector? and detector-number = 1]
    set detector-value-2 count atoms with [detector? and detector-number = 2]
  ]
  [
    set detector-value-1 "disabled"
    set detector-value-2 "disabled"
  ]
end 

to propagate-across-particles [this-friction-in-medium]  ;; turtle procedure -- propagates the wave from neighboring particles
  set velocity (velocity +  (stiffness * 0.01) *  (sum [z] of neighbor-particles -  2 * z))
  set velocity (((1000 - this-friction-in-medium) / 1000) * velocity)
end 

to watch-a-particle
   let current-atoms atoms with [x = -18 and y = 1]
   if any? current-atoms [
      let this-atom min-n-of 1  current-atoms [who]
      ask atoms [set color [0 255 0 150]]
      ask this-atom [set color [255 0 0 150]  watch-me]

   ]
end 

to density-over-space
  set-current-plot "Graph A: # of particles in each square across the medium "
  clear-plot
  let this-counter -30
  let #atoms-p 0
  ;set atoms-here 0
  repeat 60 [
    set this-counter this-counter + 1
    create-temporary-plot-pen (word this-counter)

    set-plot-pen-mode 1 ; bar mode

    ask patch this-counter 0 [
      set #atoms-p count atoms-here
       set-plot-pen-color green - 1
      ]
    plotxy this-counter #atoms-p
  ]
end 

to inspect-blue-detector
  ask patch (-23 + distance-of-blue-squares-from-sound-source) 1 [
   ; inspect self
  ]
end 


; Copyright 1997 Uri Wilensky.
; See Info tab for full copyright and license.

There are 2 versions of this model.

Uploaded by When Description Download
Michael Novak over 7 years ago removed inspect command Download this version
Michael Novak over 7 years ago Initial upload Download this version

Attached files

No files

This model does not have any ancestors.

This model does not have any descendants.