## Autoroute A7

import matplotlib.pyplot as plt
import numpy as np
from math import pi
### carte
def trace(q_exp, v_exp):
    nb_mesures = len(q_exp)
    c_exp = [0] * nb_mesures
    for i in range(nb_mesures):
        c_exp[i] = q_exp[i] / v_exp[i]
    plt.plot(c_exp, q_exp, 'o')
    plt.xlabel('Concentration (véhicule/km)')
    plt.ylabel('Débit (véhicule/h)')
    plt.show()  
    
q_exp=np.array([ 0., 2000, 4000, 6000, 7000, 6000, 7000, 6000, 7000, 6500])
v_exp=np.array([ 100, 100, 100, 100, 100, 100, 100, 80, 50, 40 ])
trace(q_exp,v_exp)

### question 1
def debit(v_max, c_max, C_ligne):
    # ????
    

def diagramme(v_max, c_max, C_ligne):
    q = debit(v_max, c_max, C_ligne)
    plt.plot(C_ligne, q, marker='o')
    plt.xlabel('Concentration (véhicule/m)')
    plt.ylabel('Débit (véhicule/s)')
    
    plt.plot((0.04, c_max/2, c_max/2),
         (c_max * v_max / 4, c_max * v_max / 4, 0.2),linestyle=":")
    plt.text(0, c_max * v_max / 4, r'$\frac{c_{max} . v_{max}}{4}$',
         verticalalignment='center', fontsize=15)
    plt.text(c_max/2, 0, r'$\frac{c_{max}}{2}$',
         horizontalalignment='center', fontsize=15)
    
    plt.show()
    return q

v_max, c_max = 130*1000/3600, 200/1000
diagramme(v_max, c_max, np.linspace(0,c_max))


### question 4
def C_depart(La, dx, c1, c2, d1, d2):
    # ????

### question 6
def resolution(C , dt , dx , c_max , v_max):
    # ????
            
def resolution_arriere(C , dt , dx , c_max , v_max):
    # ????

### question 9
def resolution_lax(C , dt , dx , c_max , v_max):
    # ????
            

# mise en évidence des tracés    
def graphique(fonction, c1, c2, titre,ax1):
    C = [C_depart(La, dx, c1, c2, d1, d2)]
    t = dt
    while t < Temps:
        C.append([0]*len(C[0]))
        t += dt
    fonction(C, dt, dx, c_max, v_max)

    ax1.plot(np.arange(0,La,dx),C[0],linestyle='--')
    for i in range(1,len(C)-10,10):
        plt.plot(np.arange(0,La,dx),C[i])
    ax1.plot(np.arange(0,La,dx),C[-1],linestyle=':')
    ax1.axvline(x=d1, linestyle='-.', color="grey")
    ax1.axvline(x=d2, linestyle='-.', color="grey")
    ax1.set_ylim([0, 0.2])
    ax1.set_title(titre)

    
La = 8500 # 8.5 km  
Temps= 100 # seconde   
dx= 50 # m
dt= 1 # s 
d1 = La / 3
d2 = 2 * d1
fig = plt.figure()
graphique(resolution, 0.01, 0.03, "Cas 1 Euler Avant", fig.add_subplot(321))
graphique(resolution, 0.12, 0.16, "Cas 2 Euler Avant", fig.add_subplot(322))

graphique(resolution_arriere, 0.01, 0.03, "Cas 1 Euler Arrière", fig.add_subplot(323)) 
graphique(resolution_arriere, 0.12, 0.16, "Cas 2 Euler Arrière", fig.add_subplot(324))

graphique(resolution_lax, 0.01, 0.03, "Cas 1 Lax-Friedriechs", fig.add_subplot(325))
graphique(resolution_lax, 0.12, 0.16, "Cas 2 Lax-Friedriechs", fig.add_subplot(326))
fig.tight_layout()
plt.show()

