Unifac Model
Unifac Model
Unifac Model
py**
from flask import Flask, render_template, request
import numpy as np
from scipy.optimize import minimize
import matplotlib.pyplot as plt
import io
import base64
import time
app = Flask(__name__)
# Calcul de D_AB
return np.exp(D)
@app.route('/')
def input_data():
return render_template('index.html')
@app.route('/calculate', methods=['POST'])
def calculate():
if request.method == 'POST':
try:
D_AB_exp = float(request.form['D_AB_exp'])
T = float(request.form['T'])
Xa = float(request.form['Xa'])
λ_a = eval(request.form['λ_a'])
λ_b = eval(request.form['λ_b'])
q_a = float(request.form['q_a'])
q_b = float(request.form['q_b'])
D_AB0 = float(request.form['D_AB0'])
D_BA0 = float(request.form['D_BA0'])
# Paramètres initiaux
params_initial = [0, 0]
# Tolerance
tolerance = 1e-12
# Temps de départ
start_time = time.time()
# Paramètres optimisés
a_AB_opt, a_BA_opt = result.x
# Calcul de l'erreur
error = np.abs(D_AB_opt - D_AB_exp)
# Temps d'exécution
execution_time = time.time() - start_time
# Générer la courbe
Xa_values = np.linspace(0, 0.7, 100) # Fraction molaire de A
D_AB_values = calculate_D_AB(Xa_values, a_AB_opt, a_BA_opt, λ_a, λ_b,
q_a, q_b, D_AB0, D_BA0, T)
plt.plot(Xa_values, D_AB_values)
plt.xlabel('Fraction molaire de A')
plt.ylabel('Coefficient de diffusion (cm^2/s)')
plt.title('Variation du coefficient de diffusion en fonction du
fraction molaire')
plt.grid(True)
except Exception as e:
return f"Une erreur s'est produite : {e}"
if __name__ == '__main__':
app.run(debug=True)
**Index.html**
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Entrée des données</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #FAF3DD; /* Couleur beige */
padding: 20px;
}
.container {
max-width: 600px;
margin: auto;
background-color: #FFFFFF; /* Couleur blanche pour le conteneur */
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); /* Ombre légère */
border: 2px solid #000000; /* Cadre noir */
}
.input-group {
margin-bottom: 15px;
}
.input-group label {
display: block;
margin-bottom: 5px;
font-weight: bold;
}
.input-group input {
width: 100%;
padding: 8px; /* Taille réduite des padding */
border: 1px solid #ccc;
border-radius: 4px;
font-size: 16px;
}
.input-group button {
padding: 10px 15px;
background-color: #FFA62B; /* Couleur orange */
color: #FFFFFF;
border: none;
border-radius: 4px;
cursor: pointer;
font-size: 16px;
}
.input-group button:hover {
background-color: #FF8C00; /* Couleur orange foncé au survol */
}
</style>
</head>
<body>
</style>
</head>
<body>
<div class="container">
<h2>Entrée des données</h2>
<form action="/calculate" method="post">
<div class="input-group">
<label for="D_AB_exp">D_AB_exp:</label>
<input type="text" id="D_AB_exp" name="D_AB_exp" required>
</div>
<div class="input-group">
<label for="T">T:</label>
<input type="text" id="T" name="T" required>
</div>
<div class="input-group">
<label for="Xa">Xa:</label>
<input type="text" id="Xa" name="Xa" required>
</div>
<div class="input-group">
<label for="λ_a">λ_a:</label>
<input type="text" id="λ_a" name="λ_a" required>
</div>
<div class="input-group">
<label for="λ_b">λ_b:</label>
<input type="text" id="λ_b" name="λ_b" required>
</div>
<div class="input-group">
<label for="q_a">q_a:</label>
<input type="text" id="q_a" name="q_a" required>
</div>
<div class="input-group">
<label for="q_b">q_b:</label>
<input type="text" id="q_b" name="q_b" required>
</div>
<div class="input-group">
<label for="D_AB0">D_AB0:</label>
<input type="text" id="D_AB0" name="D_AB0" required>
</div>
<div class="input-group">
<label for="D_BA0">D_BA0:</label>
<input type="text" id="D_BA0" name="D_BA0" required>
</div>
<div class="input-group">
<button type="submit">Calculer</button>
</div>
</form>
</div>
</body>
</html>
**Resultat.html**
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="UTF-8">
<title>Résultat du calcul</title>
<style>
body {
font-family: Arial, sans-serif;
background-color: #FAF3DD; /* Couleur beige */
padding: 20px;
}
.container {
max-width: 800px;
margin: auto;
background-color: #FFFFFF; /* Couleur blanche pour le conteneur */
padding: 20px;
border-radius: 8px;
box-shadow: 0 0 10px rgba(0, 0, 0, 0.1); /* Ombre légère */
border: 2px solid #000000; /* Cadre noir */
}
.result-table {
width: 100%;
border-collapse: collapse;
margin-top: 20px;
}
.result-table th, .result-table td {
border: 1px solid #000000; /* Bordure noire */
padding: 10px;
text-align: left;
}
.result-table th {
background-color: #FFA62B; /* Couleur orange pour l'en-tête */
color: #FFFFFF;
}
.graph {
max-width: 600px;
margin-top: 20px;
}
</style>
</head>
<body>
<div class="container">
<h2>Résultat du calcul</h2>
<table class="result-table">
<tr>
<th>Paramètre</th>
<th>Valeur</th>
</tr>
<tr>
<td>Paramètre a_AB optimisé:</td>
<td>{{ a_AB_opt }}</td>
</tr>
<tr>
<td>Paramètre a_BA optimisé:</td>
<td>{{ a_BA_opt }}</td>
</tr>
<tr>
<td>D_AB calculé:</td>
<td>{{ D_AB_opt }}</td>
</tr>
<tr>
<td>Erreur:</td>
<td>{{ error }}</td>
</tr>
<tr>
<td>Nombre d'itérations:</td>
<td>{{ iteration }}</td>
</tr>
<tr>
<td>Temps d'exécution:</td>
<td>{{ execution_time }} secondes</td>
</tr>
</table>
<div class="graph">
<img src="data:image/png;base64,{{ graph }}" alt="Graphique">
</div>
</div>
</body>
</html>