Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
summer_2019:ideal_gas_law [2019/08/05 18:53]
wellerd
summer_2019:ideal_gas_law [2019/08/06 15:27] (current)
wellerd
Line 1: Line 1:
 ====== Ideal Gas Law Activity ====== ====== Ideal Gas Law Activity ======
 +**Follow this link for the activity and the instructions:​ [[https://​trinket.io/​glowscript/​575630aab8?​showInstructions=true|link]]**
  
-===== Part A (Non-Computation) =====+**Or, read the instructions after the image below, and copy the code into your own GlowScript file.**
  
-<WRAP info>+You should see something that looks like this:
  
-==== Learning Goals ====+{{:​summer_2019:​idealgasparticle.png?​800|}}
  
-  * Ideal gas particles move with distribution ​of different speeds. +If you click on the "​Instructions"​ tab in the upper right, ​set of instructions for the activity should pop upClick between "​Instructions"​ and "​Result" ​to alternately view the instructions and the animationIf you prefer, the same instructions are also listed below.
-  * Temperature of ideal gas particles is directly proportional ​to the average kinetic energy of the gas particles. +
-  * No energy is lost during particle-particle and particle-wall collisions.+
  
-</​WRAP>​+  * Try runnning your code. You'll notice that our gas particle is currently escaping the box. 
 +  
 +  * Add an '​if'​ statement to check for when the gas particle collides with a wall, and make the particle move in th opposite direction after contacting the wall.
  
-===== Part B (Computation) =====+  * Enter the equation for v_rms of a gas particle and correct that value in your particle'​s velocity.
  
-Copy and paste the following ​code into Glowscript ​to model the ideal gas law.+  * The pressure of an ideal gas comes from collisions between particles ​and the walls of the container. The pressure is equal to the force (mass times delta_velocity) divided by the area. Add a line to the code that calculates the pressure from our gas atom colliding with the wall. 
 +  * Hint: Everytime that a particle-wall collision occurs, you should increase your pcount, and then average the total pressure by dividing by pcount. 
 + 
 +  * Try to create a pressure vs. time graph that adds another data point for every particle-wall collision. In this simplified ​modelthe pressure versus time graph should be horizontal. 
 +   
 +  * For an extra challenge, try making the particle collisions work in three dimensions. This will build into a more complicated model to be used later. 
 + 
 +For more information on glowscript tools, check out: [[https://​www.glowscript.org/​docs/​GlowScriptDocs/​index.html]]
  
 <​code>​ <​code>​
-GlowScript 2.VPython+GlowScript 2.VPython
 ## Constants ## Constants
-R=8.314 # Gas constant +L=0.1 #Give our container a length of 0.1m on each side 
-N_Avo=6.02E23 # Avogodro'​s constant +N_Avogodro=6.02E23 ​Avogodro'​s constant 
-L = 0.1 # Our container ​is cube with L=0.1m on each side +k_B=1.38E-23 ​Boltzmann constant
-Vol=L*L*L Volume of our cube is 1 Liter +
-Atomic_radius ​0.001 wildly exaggerated size of a gas atom+
  
-container ​box(pos=vec(0,0,0),size=vec(L,L,L), color=color.white,​ opacity=0.1) ​Create a container for our gas atoms+## Gas information 
 +mass 4E-3/​N_Avogodro # helium mass in kg/atom 
 +Ratom=0.01 # exaggerated ​size of helium atom 
 +T=300 Temperature equals 300 K
  
-N_atoms ​300 Number of gas atoms in your simulation +v_rms=Calculate the root-mean square speed
-n=N_atoms/​N_Avo # number of moles of gas atoms+
  
-Molar_mass = 4E-3 molar mass of helium in kg/mol+## Setup a container with a gas particle inside 
 +container = box(pos=vec(0,​0,​0),​ size=vec(L+2*Ratom,​L+2*Ratom,​L+2*Ratom),​ color=color.white,​ opacity=0.1) 
 +particle = sphere(pos=vec(0,​0,​0),​ radius = Ratom, color = color.red) 
 +particle.velocity=vec(500,​0,​0)
  
-T = 300 temperature in Kelvin +## Create a graph to track pressure 
- +Grph1 = graph(title='​Pressure vs Time', xtitle='​Time (s)', ytitle='​Pressure (Pa/atom)', fast=False, ymin=0, ymax=1E-20) #initialize our graphs. Useful boundaries: ymin=0, ymax=5*Theoretical_Pressure
-#v_avg = sqrt(8*R*T/​(pi*Molar_mass)) # average velocity of gas atoms +
-v_rms = sqrt(3*R*T/​(Molar_mass)) # root mean squared velocity of gas atoms +
-Velocity=v_rms #Which velocity would you like to assign your gas atoms: v_avg or v_rms? +
- +
-Theoretical_Pressure=n*R*T/​Vol # Calculate the theoretical ​pressure ​based on the ideal gas law +
- +
-## The lines below create a graph for the heigh vs time. Try creating a graph for the velocity and acceleration +
-Grph1 = graph(title='​Pressure vs Time', xtitle='​Time (s)', ytitle='​Pressure (atm)', fast=False, ymin=0, ymax=5*Theoretical_Pressure) #initialize our graphs. Useful boundaries: ymin=0, ymax=5*Theoretical_Pressure+
 ExperimentalPressureGraph = gcurve(color=color.red,​ label='​Experimental_Pressure'​) #Make a graph for measured pressure ExperimentalPressureGraph = gcurve(color=color.red,​ label='​Experimental_Pressure'​) #Make a graph for measured pressure
-TheoreticalPressureGraph = gcurve(color=color.blue,​ label='​Theoretical_Pressure'​) #Make a graph for theoretical pressure 
-    ​ 
-t=0 # initialize the time variable 
-dt = 5E-9 #time-step interval 
-pressure=0 # initialize the pressure tracker 
-pcount=0 # This counter will track when a particle-wall collision adds to the pressure 
  
-## The following lines create all the particles +## Set up the time variables ​for the while loop 
-ListOfParticles = [] # Empty list of particles +dt 1E-7 # Time-step 
-for i in range(0,​N_atoms):​ #Loop over all of the atoms +Initialize time variable 
-    ​newparticle ​sphere(pos=vector(L*random()-L/​2,​L*random()-L/​2,​L*random()-L/​2),​radius=Atomic_radius,​ color=color.green,​opacity=0.7, visible = True) #Create a spherical particle at a random postion +pressure=initialize ​the pressure variable 
-    ​newparticle.velocity ​vector(Velocity*sin(pi*random())*cos(2*pi*random()),​Velocity*sin(pi*random())*sin(2*pi*random()),​Velocity*cos(pi*random())) ​#Randomize velocity +pcount = 0 initialize a pressure counter
-    ​newparticle.mass ​Molar_mass/​N_Avo ​#Assign particles ​the atomic mass (in kg/atom) of your gas +
-    ​ListOfParticles.append(newparticle) ​#Append the particle to our list of particles+
  
-## The following lines simulate random motion and particle-wall collisions +## While loop to iterate over time 
-while True: #Run infinitely +while True: 
-    rate(9999) #Determines how fast the code runs +    rate(1000) # Determines how fast the simulation ​runs 
-    ​for particle in ListOfParticles:​ #Loop over all partciles +    particle.pos = particle.pos + particle.velocity*dt # Update the particle's position
-        ​particle.pos = particle.pos + particle.velocity*dt #​Update ​position of every particle based on its velocity +
-         +
-        #Check for particle-wall collisions in x,y,z. If there is a collision, reverse ​the velocity direction and add some pressure to the total. +
-        if abs(particle.pos.x) >= L/2: +
-            particle.velocity.x = - particle.velocity.x  +
-            pressure+=particle.mass*abs(particle.velocity.x)/​(L*L*dt) +
-            pcount+=1  +
-        if abs(particle.pos.y) >= L/2: +
-            particle.velocity.y = - particle.velocity.y ​  +
-            pressure+=particle.mass*abs(particle.velocity.y)/​(L*L*dt) +
-            pcount+=1  +
-        if abs(particle.pos.z) >= L/2: +
-            particle.velocity.z = - particle.velocity.z  +
-            pressure+=particle.mass*abs(particle.velocity.z)/​(L*L*dt) +
-            pcount+=1 ​+
     ​     ​
-    #The following lines calculate the experimental pressure measured due to particle-wall ​collisions +    ## Add if statement for particle-wall ​collision here 
-    ​if pcount>​=10:​ #After at least 10 particle-wall collisions occur +     
-        ​Experimental_Pressure=pressure/​pcount # Average the total pressure over the number of particle-wall collisions +     
-        ​Experimental_Pressure=Experimental_Pressure/​101.325 ​Convert from kPa to atm +    ## Add a graph for experimental pressure ​here 
-        ExperimentalPressureGraph.plot(t,​Experimental_Pressure) ​#Graph the experimental pressure +     
-        ​pressure=0 # Reset the pressure tracker +     
-        pcount=0 # Reset the pressure counter +    t = t + dt
- +
-    ​TheoreticalPressureGraph.plot(t,​Theoretical_Pressure) #Graph theoretical pressure +
- +
-    t=t+dt ​#move on to the next time-step+
 </​code>​ </​code>​
  • summer_2019/ideal_gas_law.1565031218.txt.gz
  • Last modified: 2019/08/05 18:53
  • by wellerd