```python
import numpy
import sympy
from matplotlib import pyplot
%matplotlib inline
from matplotlib import rcParams
rcParams['font.family'] = 'serif'
rcParams['font.size'] = 16
from sympy import init_printing
init_printing()
```


```python
Vmax = 80
L = 11
rho_max = 250
nx = 51
dt = .001 #[hours]
dx = L/nx
```


```python
#Initial Conditions
x = numpy.linspace(0, L, nx)
rho0 = numpy.ones(nx)*10
rho0[10:20] = 50

#Boundary Condition
rho0[0] = 10
```


```python
F, V, t = sympy.symbols('F V t')
#F = Vmax*rho*(1-rho/rho_max)
rho = rho0
```


```python
v0 = Vmax*(1-rho0/rho_max)
vmin = min(v0)/3.6 #units in m/s 
print("Min. velocity at t=0 is: {} m/s".format(vmin))
```


```python
#test code, can do one time step at a time.
#rho_n = rho0.copy()
#test = rho_n
#test[0] = 10
#test[1:] = -dt/dx*(Vmax*rho_n[1:]*(1-rho_n[1:]/rho_max) - Vmax*rho_n[0:-1]*(1-rho_n[0:-1]/rho_max)) + rho_n[1:]
#print(test[0])

#pyplot.figure(figsize=(8,5), dpi=100)
#pyplot.plot(x, test, ls='--', lw=3)
#pyplot.xlim([0,20])
#pyplot.ylim([0,60]);
```


```python
T = 3/60
nt = int(T/dt)

for n in range(nt):
    rho_n = rho.copy()
    
    rho[0] = 10
    rho[1:] = -dt/dx*Vmax*(rho_n[1:]*(1-rho_n[1:]/rho_max) - \
                     rho_n[0:-1]*(1-rho_n[0:-1]/rho_max)) + rho_n[1:]
```


```python
pyplot.figure(figsize=(8,5), dpi=100)
pyplot.plot(x, rho, ls='--', lw=3)
pyplot.xlim([0,20])
pyplot.ylim([0,60]);
```


```python
#find average velocity at t= 3 minutes
V = Vmax*(1- rho/rho_max)
V_ave = numpy.mean(V)/3.6 #units in m/s
print("Average velocity at t=3min. is {}".format(V_ave))

```


```python
Vmax = 80
L = 11
rho_max = 250
nx = 101
dt = .001 #[hours]
dx = L/nx

#Initial Conditions
x = numpy.linspace(0, L, nx)
rho0 = numpy.ones(nx)*10
rho0[10:20] = 50

#Boundary Condition
rho0[0] = 10

rho = rho0 #reset rho to initial condition

#find minimum velocity at t=6 minutes
T = 0.1 # 6 minutes
nt = int(T/dt)

for n in range(nt):
    rho_n = rho.copy()
    rho[0] = 10
    rho[1:] = -dt/dx*Vmax*(rho_n[1:]*(1-rho_n[1:]/rho_max) - \
                     rho_n[0:-1]*(1-rho_n[0:-1]/rho_max)) + rho_n[1:]
    
V = Vmax*(1-rho0/rho_max)
vmin = min(V)/3.6 #units in m/s 
#print(V)
print("Min. velocity at t=6 is: {} m/s".format(vmin))
pyplot.figure(figsize=(8,5), dpi=100)
pyplot.plot(x, rho, ls='--', lw=3)
pyplot.xlim([0,15])
pyplot.ylim([0,60]);
```


```python
Vmax = 136
L = 11
rho_max = 250
nx = 51
dt = .001 #[hours]
dx = L/nx

#Initial Conditions
x = numpy.linspace(0, L, nx)
rho0 = numpy.ones(nx)*10
rho0[10:20] = 50

#Boundary Condition
rho0[0] = 20
rho = rho0
```


```python
v0 = Vmax*(1-rho0/rho_max)
vmin = min(v0)/3.6 #units in m/s 
print("Min. velocity at t=0 is: {} m/s".format(vmin))
```

    Min. velocity at t=0 is: 30.222222222222225 m/s



```python
T = 3/60
nt = int(T/dt)

for n in range(nt):
    rho_n = rho.copy()
    
    rho[0] = 20
    rho[1:] = -dt/dx*Vmax*(rho_n[1:]*(1-rho_n[1:]/rho_max) - \
                     rho_n[0:-1]*(1-rho_n[0:-1]/rho_max)) + rho_n[1:]

pyplot.figure(figsize=(8,5), dpi=100)
pyplot.plot(x, rho, ls='--', lw=3)
pyplot.xlim([0,20])
pyplot.ylim([0,60]);

#find average velocity at t= 3 minutes
V = Vmax*(1- rho/rho_max)
V_ave = numpy.mean(V)/3.6 #units in m/s
print("Average velocity at t=3min. is {}".format(V_ave))
vmin = min(V)/3.6 #units in m/s 
print("Minimum velocity at t=3min. is {}".format(vmin))
```


```python
Vmax = 136
L = 11
rho_max = 250
nx = 51
dt = .001 #[hours]
dx = L/nx

#Initial Conditions
x = numpy.linspace(0, L, nx)
rho0 = numpy.ones(nx)*20
rho0[10:20] = 50

#Boundary Condition
rho0[0] = 20

rho = rho0 #reset rho to initial condition

#find minimum velocity at t=6 minutes
T = 0.1 # 6 minutes
nt = int(T/dt)

for n in range(nt):
    rho_n = rho.copy()
    rho[0] = 20
    rho[1:] = -dt/dx*Vmax*(rho_n[1:]*(1-rho_n[1:]/rho_max) - \
                     rho_n[0:-1]*(1-rho_n[0:-1]/rho_max)) + rho_n[1:]
    
V = Vmax*(1-rho0/rho_max)
vmin = min(V)/3.6 #units in m/s 
print("Min. velocity at t=6 is: {} m/s".format(vmin))
pyplot.figure(figsize=(8,5), dpi=100)
pyplot.plot(x, rho, ls='--', lw=3)
pyplot.xlim([0,15])
pyplot.ylim([0,60]);
```


```python

```

e72ac5d14e32224bb09ada31c04d83b2eafe2dfd
ipynb
Jupyter Notebook
lessons/02_spacetime/Module_2_assignment.ipynb
rbds/Numerical_Methods_working_folder
d929ed7506054e7aa7ba059623c37ecf7d6ae993
CC-BY-3.0
lessons/02_spacetime/Module_2_assignment.ipynb
rbds/Numerical_Methods_working_folder
d929ed7506054e7aa7ba059623c37ecf7d6ae993
CC-BY-3.0
lessons/02_spacetime/Module_2_assignment.ipynb
rbds/Numerical_Methods_working_folder
d929ed7506054e7aa7ba059623c37ecf7d6ae993
CC-BY-3.0
Qwen/Qwen-72B
1. YES
2. YES