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
Last revision Both sides next revision
summer_2019:ideal_gas_law [2019/08/01 22:45]
wellerd
summer_2019:ideal_gas_law [2019/08/06 15:27]
wellerd
Line 1: Line 1:
-<​code>​ +====== Ideal Gas Law Activity ​====== 
-GlowScript 2.8 VPython +**Follow this link for the activity and the instructions:​ [[https://​trinket.io/​glowscript/​575630aab8?​showInstructions=true|link]]**
-# Constants +
-R=8.314 # Gas constant +
-N_A=6.02E23 # Avogodro'​s constant +
-0.1 # Our container is a cube with L=0.1m on each side +
-Ratom 0.001 # wildly exaggerated size of a gas atom+
  
-# Properties of the gas atoms we are working with +**Or, read the instructions after the image below, and copy the code into your own GlowScript file.**
-N_atoms = 500 # change this to have more or fewer atoms +
-n=N_atoms/​N_A # number of moles of gas atoms+
  
-Molar_mass = 4E-3 # molar mass of helium in kg/mol+You should see something that looks like this:
  
-T = 300 # temperature in Kelvin+{{:​summer_2019:​idealgasparticle.png?​800|}}
  
-# Create ​container ​for our gas atoms +If you click on the "​Instructions"​ tab in the upper right, ​set of instructions ​for the activity should pop up. Click between "​Instructions"​ and "​Result"​ to alternately view the instructions and the animationIf you preferthe same instructions are also listed below.
-container = box(pos=vec(0,​0,​0),​size=vec(L,​L,​L),​ color=color.whiteopacity=0.1)+
  
-v_avg = sqrt(8*R*T/​(pi*Molar_mass)) # average velocity of gas atoms +Try runnning your code. You'll notice that our gas particle is currently escaping the box. 
-#v_rms = sqrt(3*R*T/​(Molar_mass)) # root mean squared velocity of gas atoms +  
-Velocity=v_avg+* **Line 34:** Add an if statement to check for when the gas particle collides with a wall.
  
-Theoretical_Pressure=n*R*T/​(L*L*L*1000) # 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) #ymin=0, ymax=2*Theoretical_Pressure 
-ExperimentalPressureGraph = gcurve(color=color.red,​ label='​Experimental_Pressure'​) 
-TheoreticalPressureGraph = gcurve(color=color.blue,​ label='​Theoretical_Pressure'​) 
-    ​ 
-t=0 # initialize the time variable 
-dt = 2.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 +For more information on glowscript toolscheck out: [[https://www.glowscript.org/docs/​GlowScriptDocs/​index.html]]
-ListOfParticles = [] # Empty list of particles +
-for i in range(0,N_atoms): +
-    newparticle = sphere(pos=vector(L*random()-L/2,​L*random()-L/2,​L*random()-L/​2),​radius=Ratom,​ color=color.green,​opacity=0.7,​ visible = True) #Create a spherical particle at a random postion +
-    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 +
-    newparticle.mass = Molar_mass/N_A #Give the particles the atomic mass 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 True: 
-    rate(9999) 
-    for particle in ListOfParticles:​ 
-        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 are collisions, add some pressure to the total. 
-        if abs(particle.pos.x) >= L/2: 
-            particle.velocity.x = - particle.velocity.x ​ 
-            pcount+=1 ​ 
-            pressure+=particle.mass*abs(particle.velocity.x)/​(L*L*dt) 
-        if abs(particle.pos.y) >= L/2: 
-            particle.velocity.y = - particle.velocity.y  ​ 
-            pcount+=1 ​ 
-            pressure+=particle.mass*abs(particle.velocity.y)/​(L*L*dt) 
-        if abs(particle.pos.z) >= L/2: 
-            particle.velocity.z = - particle.velocity.z ​ 
-            pcount+=1 ​ 
-            pressure+=particle.mass*abs(particle.velocity.z)/​(L*L*dt) 
-    ​ 
-    #The following lines calculate the experimental pressure measured due to particle-wall collisions 
-    if pcount>​=1:​ 
-        Experimental_Pressure=pressure/​pcount # Average the total pressure over the number of particle-wall collisions 
-        Experimental_Pressure=Experimental_Pressure*101325 # Convert from Pa to atm 
-        ExperimentalPressureGraph.plot(t,​Experimental_Pressure) #Graph the experimental pressure 
-        pressure=0 # Reset the pressure tracker 
-        pcount=0 # Reset the pressure counter 
  
-    TheoreticalPressureGraph.plot(t,​Theoretical_Pressure) #Graph theoretical pressure 
  
-    ​t=t+dt +<​code>​ 
-</cone>+GlowScript 2.7 VPython 
 +## Constants 
 +L=0.1 #Give our container a length of 0.1m on each side 
 +N_Avogodro=6.02E23 # Avogodro'​s constant 
 +k_B=1.38E-23 # Boltzmann constant 
 + 
 +## 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 
 + 
 +v_rms=0 # Calculate the root-mean square speed 
 + 
 +## 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) 
 + 
 +## 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 
 +ExperimentalPressureGraph = gcurve(color=color.red,​ label='​Experimental_Pressure'​) #Make a graph for measured pressure 
 + 
 +## Set up the time variables for the while loop 
 +dt = 1E-7 # Time-step 
 +t = 0 # Initialize time variable 
 +pressure=0 # initialize the pressure variable 
 +pcount = 0 # initialize a pressure counter 
 + 
 +## While loop to iterate over time 
 +while True: 
 +    rate(1000) # Determines how fast the simulation runs 
 +    particle.pos = particle.pos + particle.velocity*dt # Update the particle'​s position 
 +     
 +    ## Add if statement for particle-wall collision here 
 +     
 +     
 +    ## Add a graph for experimental pressure here 
 +     
 +     
 +    ​t = t + dt 
 +</code>
  • summer_2019/ideal_gas_law.txt
  • Last modified: 2019/08/06 15:27
  • by wellerd