Demonic Particles
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
The Maxwell’s demon is a thought experiment in which there are two rooms, A and B, filled with gas (particles in movement) and connected by a membrane. A creature (called the demon) opens and closes that membrane so that only the faster particles go from A to B, and only the slower particles go from B to A. This contradicts the second law of thermodynamics because at the end the particles would be separated according to their velocities, reverting the entropy.
In this model, a more distributed approach is used. Instead of a single demon opening and closing a membrane, the particles (which are the agents) themselves will decide wether to cross it according to the local information they've gathered.
HOW IT WORKS
At setup time, particles are assigned a random position and speed. The faster ones are coloured with red, while the slower ones are coloured with blue. The white particles have a speed near the average. When two particles pass close to each other (in neighboring patches), they log the other's speed.
Collisions between two particles affect the speed and direction of both particles, and the calculations depend on their original speed, direction and mass. In this model, the mass is assumed to be constant (20) across all the particles.
The environment consists of two rooms separated by a yellow membrane in the middle. The brown walls are solid. That is, the particles bounce when they collide with them. On the other hand, when the particles are about to cross the membrane, they evaluate whether their speed is too different from the mean speed of the neighboring particles they've encountered. If they find this true they cross it, else they bounce. The loss of speed caused by the collision between a particle and a wall or the membrane is ignored in this model. A particle's memory (log of neighbors' speeds) is cleared when it pass through the membrane.
HOW TO USE IT
1. Vary the parameters to your like (population will only take effect at SETUP time).
2. Press setup to initialize the model. Two rooms should appear, filled with a bunch of particles at random positions.
3. Press go to run the model. Particles will start moving and the monitors and plots will vary.
4. You can vary the parameters at run time (except for population) and see how they affect the model. Make only one change at a time in order to observe the responses.
Inputs / Parameters
population: The number of particles in the whole model.
memory: This controls the length of the neighbor-speeds property, in which each particle keeps a record of the speed of the other particles that has passed by near.
traspasing-threshold: If the difference between a particle's speed and the mean of the neighbors' speed is greater than this threshold, the particle will cross through the membrane.
collide: Whether to treat the particles as solid objects and calculate collisions. This code comes from the Connected Chemistry 1 (Bike Tire) model, which can be found in the models library.
Outputs
The monitors and the plot show the variation of the average speed on each room. In the Maxwell's demon thought experiment, the difference of those averages between rooms should increase as time passes, until reaching certain stability.
THINGS TO NOTICE
With what configuration do the particles organize themselves according to their speed more easily? How does the speed of the particles change when they collide?
What does it mean that a particle has a high
speed
in the model? How does it affect the speed of the actual particle in the display? Does the colour of the particles change dynamically according to their speed?Do the particles always end up separated according to their speed? Is this easy to achieve in the model or does it need a special configuration of the parameters? When separation occurs, do the rooms always end up with the same kind of particles (slower or faster)?
When the system is constantly changing, does the difference of the average speed between the rooms stabilize or oscillate?
THINGS TO TRY
Let the model run with the default parameters for a while (adjusting the speed of the model to faster might help). Watch the plot and the monitor of the mean speed for each room. How do the speeds vary for each room? Adjust the speed of the model back to normal. How does the display look now in respect to the begining?
Turn the
collide?
switch. Observe the direction and speed of the particles. How does this affect the dynamism of the system as a whole?Play with the
traspasing-threshold
slider. Do the same value have different effects between two runs of the model? If not, why do this happen?Play with the
memory
slider. A small value means that each particle will only have into account the last encounters when deciding to cross the membrane.
EXTENDING THE MODEL
Let the user choose the membrane's size. A smaller membrane will lead to a smaller probability of a particle hiting it, so the model will be more static and the particles will have a more updated view of the mean speed. Would this affect the distribution of the particles?
Express the temperature of each room according to their average speeds. This would be a pretty nice extra, that would make it easier to show the model to people unexperienced in the laws of thermodynamics.
NETLOGO FEATURES
This model features a more agent-based approach to an old thought experiment, in the sense that the calculations about the average speed on each room are made by each particle and based on local information. Netlogo's views of the agents (turtles) allowed to manage the operations of thousands of them in an easy way.
RELATED MODELS
See Connected Chemistry folder from the Netlogo models library.
See GasLab folder from the Netlogo models library.
There's an alternative implementation of the Maxwell's demon thought experiment in the GasLab folder.
CREDITS AND REFERENCES
Copyright 2016 Paula A. Palacios and 2004 Uri Wilensky*.
This work is licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. To view a copy of this license, visit https://creativecommons.org/licenses/by-nc-sa/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA.
* This model contains part of the code from the Connected Chemistry 1 (Bike Tire) model, by Uri Wilensky, which is also licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0.
Comments and Questions
globals [ color-range ] turtles-own [ speed mass last-collision neighbor-speeds ] to setup clear-all draw-walls create-turtles population [ setxy random-xcor random-ycor avoid-walls set shape "circle" set size 0.5 set mass 20 ;; make sure the speed is never 0 set speed random-float 1 if speed = 0 [ set speed 0.1 ] ;; set the particle's color according to its speed. Red is fast, Sky-blue is ;; slow and white-ish is average ifelse (speed >= 0.5) [ set color scale-color red speed 1.5 0.5 ] [ set color scale-color sky speed -0.5 0.5 ] ;; keeps a record of the speeds of the other turtles in ;; its room set neighbor-speeds ( list speed ) ] reset-ticks end to draw-walls ;; draw membrane ask patches with [ pxcor = 0 ] [ set pcolor yellow ] ;; draw the surrounding walls ask patches with [ pxcor = max-pxcor or pxcor = min-pxcor or pycor = max-pycor or pycor = min-pycor ] [ set pcolor brown ] end ;; reposition turtles that are in a wall patch to avoid-walls if pxcor = 0 [ set xcor (xcor + one-of [1 -1]) ] if pxcor = max-pxcor [ set xcor xcor - 2 ] if pxcor = min-pxcor [ set xcor xcor + 2 ] if pycor = max-pycor [ set ycor ycor - 2 ] if pycor = min-pycor [ set ycor ycor + 2 ] end to go ask turtles [ check-wall-collision update-neighbor-speeds if collide? [ check-for-particlecollision ] let max-speed max [ speed ] of turtles ifelse (speed >= 0.5) [ set color scale-color red ( speed / max-speed ) 1.5 0.5 ] [ set color scale-color sky ( speed / max-speed ) -0.5 0.5 ] ; normalize the speed forward speed / max-speed ] tick end ;; bounce when collides with any wall to check-wall-collision ; check collision with middle wall if [ pxcor ] of patch-ahead 1 = 0 [ ifelse [ pcolor ] of patch-ahead 1 = yellow [ decide-traspase-door ] [ set heading (- heading) ] ] ; check collision with borders if abs ( [ pxcor ] of patch-ahead 1 ) = max-pxcor [ set heading (- heading) ] if abs [ pycor ] of patch-ahead 1 = max-pycor [ set heading (180 - heading) ] end to decide-traspase-door ;; Calculate the difference between a particle speed and its log of other particles' speed let speed-dif abs ( mean neighbor-speeds - speed ) ifelse speed-dif < traspasing-threshold [ set heading (- heading) ] [ jump 2 set neighbor-speeds ( list speed ) ] end ;; update the mean speed that each particle perceives according to ;; their encounters with other turtles to update-neighbor-speeds set neighbor-speeds sentence neighbor-speeds [ speed ] of turtles-on neighbors if length neighbor-speeds > memory [ set neighbor-speeds sublist neighbor-speeds memory length neighbor-speeds ] end ;; From now on, collision is implemented. This code comes from the Connected Chemistry 1 ;; (Bike Tire) model, which can be found in the models library. Copyright to Uri Wilensky, ;; licensed under the Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License. to check-for-particlecollision ;; particle procedure if count other turtles-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 turtles-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 turtles 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 turtles colliding are self and other-particle, and while the ;; collision is performed from the point of view of self, both turtles 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 let mass2 0 let speed2 0 let heading2 0 let theta 0 let v1t 0 let v1l 0 let v2t 0 let v2l 0 let vcm 0 ;;; PHASE 1: initial setup ;; for convenience, grab some quantities from other-particle set mass2 [mass] of other-particle set speed2 [speed] of other-particle set heading2 [heading] of other-particle ;; since turtles are modeled as zero-size points, theta isn't meaningfully ;; defined. we can assign it randomly without affecting the model's outcome. set 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 set v1t (speed * cos (theta - heading)) set v1l (speed * sin (theta - heading)) ;; do the same for other-particle set v2t (speed2 * cos (theta - heading2)) set v2l (speed2 * sin (theta - heading2)) ;;; PHASE 3: manipulate vectors to implement collision ;; compute the velocity of the system's center of mass along theta set 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 * v1t) + (v1l * v1l)) ;; 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)) if v2l != 0 or v2t != 0 [ set heading (theta - (atan v2l v2t)) ] ] end
There is only one version of this model, created almost 9 years ago by Paula Palacios.
Attached files
File | Type | Description | Last updated | |
---|---|---|---|---|
Demonic Particles.png | preview | Preview for 'Demonic Particles' | almost 9 years ago, by Paula Palacios | Download |
This model does not have any ancestors.
This model does not have any descendants.