Spaces:
Sleeping
Sleeping
SimSite Deploy commited on
Commit ·
4464a90
1
Parent(s): 51dd662
Deploy SimSite - Simulation platform with FEniCS and Dang Van analysis
Browse files- DangVan/__init__.py +1 -0
- DangVan/dangvan.py +223 -0
- Dockerfile +30 -0
- README.md +30 -5
- backend/backend/__init__.py +0 -0
- backend/backend/asgi.py +16 -0
- backend/backend/settings.py +98 -0
- backend/backend/urls.py +30 -0
- backend/backend/wsgi.py +16 -0
- backend/manage.py +22 -0
- backend/simulation/__init__.py +0 -0
- backend/simulation/admin.py +3 -0
- backend/simulation/apps.py +5 -0
- backend/simulation/fenics_runner.py +156 -0
- backend/simulation/migrations/0001_initial.py +30 -0
- backend/simulation/migrations/__init__.py +0 -0
- backend/simulation/models.py +26 -0
- backend/simulation/serializers.py +16 -0
- backend/simulation/tests.py +3 -0
- backend/simulation/urls.py +4 -0
- backend/simulation/views.py +140 -0
- requirements.txt +7 -0
- static/assets/index-DOJBTpfK.js +0 -0
- static/assets/index-DYM3EwRh.css +1 -0
- static/index.html +975 -0
DangVan/__init__.py
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
"""DangVan package for fatigue analysis."""
|
DangVan/dangvan.py
ADDED
|
@@ -0,0 +1,223 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|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 4 |
+
Algorithm based on old/deviatoire.py and old/versDV.py:
|
| 5 |
+
- For each time step, compute hydrostatic pressure sigma_H
|
| 6 |
+
- For each time step, compute max shear stress tau_max by scanning all facets (theta, phi)
|
| 7 |
+
- Plot (sigma_H, tau_max) cloud and criterion line: tau = b - a * sigma_H
|
| 8 |
+
|
| 9 |
+
Inputs:
|
| 10 |
+
- stress_series: list of stress tensors (Voigt 6: [sxx, syy, szz, sxy, sxz, syz])
|
| 11 |
+
- a, b: Dang Van material parameters
|
| 12 |
+
|
| 13 |
+
Outputs:
|
| 14 |
+
- dict with points (sigma_H, tau_max) for plotting and safety assessment
|
| 15 |
+
"""
|
| 16 |
+
|
| 17 |
+
import math
|
| 18 |
+
import numpy as np
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def tens_to_mat(tens):
|
| 22 |
+
"""Convert Voigt 6-component tensor to 3x3 symmetric matrix.
|
| 23 |
+
|
| 24 |
+
Voigt notation: [sxx, syy, szz, sxy, sxz, syz]
|
| 25 |
+
Matrix:
|
| 26 |
+
[[sxx, sxy, sxz],
|
| 27 |
+
[sxy, syy, syz],
|
| 28 |
+
[sxz, syz, szz]]
|
| 29 |
+
"""
|
| 30 |
+
if len(tens) == 6:
|
| 31 |
+
sxx, syy, szz, sxy, sxz, syz = tens
|
| 32 |
+
return np.array([
|
| 33 |
+
[sxx, sxy, sxz],
|
| 34 |
+
[sxy, syy, syz],
|
| 35 |
+
[sxz, syz, szz]
|
| 36 |
+
])
|
| 37 |
+
elif len(tens) == 3 and hasattr(tens[0], '__len__') and len(tens[0]) == 3:
|
| 38 |
+
# Already a 3x3 matrix
|
| 39 |
+
return np.array(tens)
|
| 40 |
+
else:
|
| 41 |
+
raise ValueError("Tensor must be Voigt 6-component or 3x3 matrix")
|
| 42 |
+
|
| 43 |
+
|
| 44 |
+
def hydro(tens):
|
| 45 |
+
"""Compute hydrostatic pressure sigma_H = (sxx + syy + szz) / 3."""
|
| 46 |
+
if hasattr(tens, '__len__'):
|
| 47 |
+
if len(tens) == 6:
|
| 48 |
+
return (tens[0] + tens[1] + tens[2]) / 3.0
|
| 49 |
+
elif len(tens) == 3 and hasattr(tens[0], '__len__'):
|
| 50 |
+
# 3x3 matrix
|
| 51 |
+
return (tens[0][0] + tens[1][1] + tens[2][2]) / 3.0
|
| 52 |
+
raise ValueError("Invalid tensor format")
|
| 53 |
+
|
| 54 |
+
|
| 55 |
+
def normale(theta, phi):
|
| 56 |
+
"""Return unit normal vector for facet defined by angles (theta, phi)."""
|
| 57 |
+
return np.array([
|
| 58 |
+
math.cos(theta) * math.sin(phi),
|
| 59 |
+
math.sin(theta) * math.sin(phi),
|
| 60 |
+
math.cos(phi)
|
| 61 |
+
])
|
| 62 |
+
|
| 63 |
+
|
| 64 |
+
def cont_tang(tens, vN):
|
| 65 |
+
"""Compute tangential stress vector on facet with normal vN.
|
| 66 |
+
|
| 67 |
+
Args:
|
| 68 |
+
tens: stress tensor (Voigt 6 or 3x3)
|
| 69 |
+
vN: unit normal vector
|
| 70 |
+
|
| 71 |
+
Returns:
|
| 72 |
+
tangential stress vector
|
| 73 |
+
"""
|
| 74 |
+
M = tens_to_mat(tens)
|
| 75 |
+
cont = M @ vN # stress vector on facet
|
| 76 |
+
cN = np.dot(cont, vN) # normal component
|
| 77 |
+
contT = cont - cN * vN # tangential component
|
| 78 |
+
return contT
|
| 79 |
+
|
| 80 |
+
|
| 81 |
+
def amplitude_tang_max(tens, pas_deg=2):
|
| 82 |
+
"""Compute maximum tangential stress amplitude by scanning all facets.
|
| 83 |
+
|
| 84 |
+
Args:
|
| 85 |
+
tens: stress tensor (Voigt 6 or 3x3)
|
| 86 |
+
pas_deg: angular step in degrees (default 2 for speed, use 1 for precision)
|
| 87 |
+
|
| 88 |
+
Returns:
|
| 89 |
+
[max_tau, [theta_max, phi_max]]
|
| 90 |
+
"""
|
| 91 |
+
maxi = 0.0
|
| 92 |
+
plan_max = [0.0, 0.0]
|
| 93 |
+
pas = math.pi / (180 / pas_deg)
|
| 94 |
+
|
| 95 |
+
n_steps = int(180 / pas_deg) + 1
|
| 96 |
+
for i in range(n_steps):
|
| 97 |
+
theta = i * pas
|
| 98 |
+
for j in range(n_steps):
|
| 99 |
+
phi = j * pas
|
| 100 |
+
vN = normale(theta, phi)
|
| 101 |
+
contT = cont_tang(tens, vN)
|
| 102 |
+
norme = np.linalg.norm(contT)
|
| 103 |
+
if norme > maxi:
|
| 104 |
+
maxi = norme
|
| 105 |
+
plan_max = [theta, phi]
|
| 106 |
+
|
| 107 |
+
return [maxi, plan_max]
|
| 108 |
+
|
| 109 |
+
|
| 110 |
+
def compute_dang_van(stress_series, a, b, pas_deg=2):
|
| 111 |
+
"""Compute Dang Van criterion for a stress tensor series.
|
| 112 |
+
|
| 113 |
+
The Dang Van criterion states that fatigue failure occurs when:
|
| 114 |
+
tau_max + a * sigma_H > b
|
| 115 |
+
|
| 116 |
+
This function computes for each time step:
|
| 117 |
+
- sigma_H: hydrostatic pressure
|
| 118 |
+
- tau_max: maximum shear stress (by scanning all facets)
|
| 119 |
+
|
| 120 |
+
Args:
|
| 121 |
+
stress_series: list of stress tensors (Voigt 6: [sxx, syy, szz, sxy, sxz, syz])
|
| 122 |
+
a: slope parameter (typically ~0.3)
|
| 123 |
+
b: intercept parameter (fatigue limit in pure shear)
|
| 124 |
+
pas_deg: angular step in degrees for facet scanning (default 2)
|
| 125 |
+
|
| 126 |
+
Returns:
|
| 127 |
+
dict with:
|
| 128 |
+
- points: list of {sigma_H, tau_max, dv} for each time step
|
| 129 |
+
- dv_max: maximum DV value
|
| 130 |
+
- safe: True if all points satisfy criterion
|
| 131 |
+
- margin: b - dv_max
|
| 132 |
+
- a, b: parameters used
|
| 133 |
+
- criterion_line: points for plotting the criterion line
|
| 134 |
+
"""
|
| 135 |
+
if stress_series is None or len(stress_series) == 0:
|
| 136 |
+
raise ValueError("stress_series is required and must not be empty")
|
| 137 |
+
|
| 138 |
+
try:
|
| 139 |
+
a = float(a)
|
| 140 |
+
b = float(b)
|
| 141 |
+
except Exception as exc:
|
| 142 |
+
raise ValueError("Parameters a and b must be floats") from exc
|
| 143 |
+
|
| 144 |
+
points = []
|
| 145 |
+
dv_max = -float("inf")
|
| 146 |
+
index_max = -1
|
| 147 |
+
|
| 148 |
+
for i, tens in enumerate(stress_series):
|
| 149 |
+
# Convert to list/array if needed
|
| 150 |
+
if hasattr(tens, 'tolist'):
|
| 151 |
+
tens = tens.tolist()
|
| 152 |
+
tens = [float(x) for x in tens]
|
| 153 |
+
|
| 154 |
+
# Compute hydrostatic pressure
|
| 155 |
+
sigma_H = hydro(tens)
|
| 156 |
+
|
| 157 |
+
# Compute max shear stress by scanning facets
|
| 158 |
+
tau_max, _ = amplitude_tang_max(tens, pas_deg)
|
| 159 |
+
|
| 160 |
+
# Dang Van criterion value
|
| 161 |
+
dv = tau_max + a * sigma_H
|
| 162 |
+
|
| 163 |
+
points.append({
|
| 164 |
+
"i": i,
|
| 165 |
+
"sigma_H": float(sigma_H),
|
| 166 |
+
"tau_max": float(tau_max),
|
| 167 |
+
"dv": float(dv)
|
| 168 |
+
})
|
| 169 |
+
|
| 170 |
+
if dv > dv_max:
|
| 171 |
+
dv_max = dv
|
| 172 |
+
index_max = i
|
| 173 |
+
|
| 174 |
+
# Determine if safe (all DV values <= b)
|
| 175 |
+
safe = dv_max <= b
|
| 176 |
+
|
| 177 |
+
# Generate criterion line for plotting
|
| 178 |
+
# Line: tau = b - a * sigma_H
|
| 179 |
+
sigma_H_values = [p["sigma_H"] for p in points]
|
| 180 |
+
sigma_H_min = min(sigma_H_values) if sigma_H_values else 0
|
| 181 |
+
sigma_H_max_val = max(sigma_H_values) if sigma_H_values else 100
|
| 182 |
+
|
| 183 |
+
# Extend range a bit for visualization
|
| 184 |
+
margin_range = (sigma_H_max_val - sigma_H_min) * 0.2 if sigma_H_max_val != sigma_H_min else 10
|
| 185 |
+
line_start = sigma_H_min - margin_range
|
| 186 |
+
line_end = sigma_H_max_val + margin_range
|
| 187 |
+
|
| 188 |
+
criterion_line = [
|
| 189 |
+
{"sigma_H": float(line_start), "tau": float(b - a * line_start)},
|
| 190 |
+
{"sigma_H": float(line_end), "tau": float(b - a * line_end)}
|
| 191 |
+
]
|
| 192 |
+
|
| 193 |
+
return {
|
| 194 |
+
"points": points,
|
| 195 |
+
"dv_max": float(dv_max),
|
| 196 |
+
"index_max": int(index_max),
|
| 197 |
+
"safe": bool(safe),
|
| 198 |
+
"margin": float(b - dv_max),
|
| 199 |
+
"a": float(a),
|
| 200 |
+
"b": float(b),
|
| 201 |
+
"criterion_line": criterion_line
|
| 202 |
+
}
|
| 203 |
+
|
| 204 |
+
|
| 205 |
+
if __name__ == "__main__":
|
| 206 |
+
# Test with sample data
|
| 207 |
+
sigma1 = 100
|
| 208 |
+
omega = 2 * math.pi
|
| 209 |
+
pas_temps = 0.01
|
| 210 |
+
fin = 1.0
|
| 211 |
+
|
| 212 |
+
stress_series = []
|
| 213 |
+
for i in range(int(fin / pas_temps)):
|
| 214 |
+
t = i * pas_temps
|
| 215 |
+
tens = [sigma1 * math.cos(omega * t), 0, 0, 0, 0, 0]
|
| 216 |
+
stress_series.append(tens)
|
| 217 |
+
|
| 218 |
+
result = compute_dang_van(stress_series, a=0.3, b=50)
|
| 219 |
+
|
| 220 |
+
print(f"DV max: {result['dv_max']:.2f}")
|
| 221 |
+
print(f"Safe: {result['safe']}")
|
| 222 |
+
print(f"Margin: {result['margin']:.2f}")
|
| 223 |
+
print(f"Number of points: {len(result['points'])}")
|
Dockerfile
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
FROM python:3.11-slim
|
| 2 |
+
|
| 3 |
+
ENV PYTHONDONTWRITEBYTECODE=1
|
| 4 |
+
ENV PYTHONUNBUFFERED=1
|
| 5 |
+
ENV DEBIAN_FRONTEND=noninteractive
|
| 6 |
+
|
| 7 |
+
WORKDIR /app
|
| 8 |
+
|
| 9 |
+
# Install dependencies
|
| 10 |
+
COPY requirements.txt .
|
| 11 |
+
RUN pip install --no-cache-dir -r requirements.txt
|
| 12 |
+
|
| 13 |
+
# Copy application files
|
| 14 |
+
COPY backend/ ./backend/
|
| 15 |
+
COPY static/ ./static/
|
| 16 |
+
COPY DangVan/ ./DangVan/
|
| 17 |
+
|
| 18 |
+
# Create directories for results and database
|
| 19 |
+
RUN mkdir -p /app/backend/simulation_results && chmod 777 /app/backend/simulation_results
|
| 20 |
+
|
| 21 |
+
# Initialize database and collect static files
|
| 22 |
+
WORKDIR /app/backend
|
| 23 |
+
RUN python manage.py migrate --noinput
|
| 24 |
+
RUN python manage.py collectstatic --noinput
|
| 25 |
+
|
| 26 |
+
# HF Spaces uses port 7860
|
| 27 |
+
EXPOSE 7860
|
| 28 |
+
|
| 29 |
+
# Run with gunicorn
|
| 30 |
+
CMD ["gunicorn", "--bind", "0.0.0.0:7860", "--workers", "2", "--timeout", "120", "backend.wsgi:application"]
|
README.md
CHANGED
|
@@ -1,10 +1,35 @@
|
|
| 1 |
---
|
| 2 |
-
title:
|
| 3 |
-
emoji:
|
| 4 |
-
colorFrom:
|
| 5 |
-
colorTo:
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
|
|
|
| 8 |
---
|
| 9 |
|
| 10 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
---
|
| 2 |
+
title: SimSite - Applications de Simulation
|
| 3 |
+
emoji: 🔬
|
| 4 |
+
colorFrom: blue
|
| 5 |
+
colorTo: cyan
|
| 6 |
sdk: docker
|
| 7 |
pinned: false
|
| 8 |
+
license: mit
|
| 9 |
---
|
| 10 |
|
| 11 |
+
# SimSite - Plateforme de Simulation Numerique
|
| 12 |
+
|
| 13 |
+
Plateforme web regroupant plusieurs applications de simulation et d'analyse numerique.
|
| 14 |
+
|
| 15 |
+
## Applications disponibles
|
| 16 |
+
|
| 17 |
+
### 1. Simulation FEniCS
|
| 18 |
+
Resolution d'equations aux derivees partielles (EDP) avec la methode des elements finis.
|
| 19 |
+
- Equation de diffusion transitoire
|
| 20 |
+
- Visualisation en temps reel
|
| 21 |
+
- Animation de la solution
|
| 22 |
+
|
| 23 |
+
### 2. Analyse Dang Van
|
| 24 |
+
Critere de fatigue multiaxiale pour l'analyse de la tenue en fatigue des pieces mecaniques.
|
| 25 |
+
- Import de donnees CSV/JSON
|
| 26 |
+
- Diagramme de Dang Van interactif
|
| 27 |
+
- Evaluation de la securite
|
| 28 |
+
|
| 29 |
+
## Technologies
|
| 30 |
+
- Backend: Django + Django REST Framework
|
| 31 |
+
- Frontend: HTML/CSS/JS + Chart.js
|
| 32 |
+
- Calcul: NumPy, Matplotlib, FEniCS (optionnel)
|
| 33 |
+
|
| 34 |
+
## Utilisation
|
| 35 |
+
Accedez a l'interface web et selectionnez l'application souhaitee depuis la page d'accueil.
|
backend/backend/__init__.py
ADDED
|
File without changes
|
backend/backend/asgi.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
ASGI config for backend project.
|
| 3 |
+
|
| 4 |
+
It exposes the ASGI callable as a module-level variable named ``application``.
|
| 5 |
+
|
| 6 |
+
For more information on this file, see
|
| 7 |
+
https://docs.djangoproject.com/en/6.0/howto/deployment/asgi/
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import os
|
| 11 |
+
|
| 12 |
+
from django.core.asgi import get_asgi_application
|
| 13 |
+
|
| 14 |
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
|
| 15 |
+
|
| 16 |
+
application = get_asgi_application()
|
backend/backend/settings.py
ADDED
|
@@ -0,0 +1,98 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Django settings for backend project.
|
| 3 |
+
"""
|
| 4 |
+
|
| 5 |
+
from pathlib import Path
|
| 6 |
+
import sys
|
| 7 |
+
import os
|
| 8 |
+
|
| 9 |
+
BASE_DIR = Path(__file__).resolve().parent.parent
|
| 10 |
+
|
| 11 |
+
# Allow importing modules from the workspace root (e.g., DangVan)
|
| 12 |
+
# In development: /root/simsite/DangVan
|
| 13 |
+
# In Docker: /app/DangVan
|
| 14 |
+
sys.path.insert(0, str(BASE_DIR.parent)) # /root/simsite or /app
|
| 15 |
+
# Also add parent directories for development environment
|
| 16 |
+
sys.path.append('/root') # Development: allows 'from DangVan.dangvan import ...'
|
| 17 |
+
sys.path.append('/app') # Docker: allows 'from DangVan.dangvan import ...'
|
| 18 |
+
|
| 19 |
+
SECRET_KEY = os.environ.get('DJANGO_SECRET_KEY', 'django-insecure-dev-key-change-in-prod')
|
| 20 |
+
|
| 21 |
+
DEBUG = os.environ.get('DEBUG', 'True') == 'True'
|
| 22 |
+
|
| 23 |
+
ALLOWED_HOSTS = ['*']
|
| 24 |
+
|
| 25 |
+
SECURE_CROSS_ORIGIN_OPENER_POLICY = None
|
| 26 |
+
|
| 27 |
+
INSTALLED_APPS = [
|
| 28 |
+
'django.contrib.admin',
|
| 29 |
+
'django.contrib.auth',
|
| 30 |
+
'django.contrib.contenttypes',
|
| 31 |
+
'django.contrib.sessions',
|
| 32 |
+
'django.contrib.messages',
|
| 33 |
+
'django.contrib.staticfiles',
|
| 34 |
+
'corsheaders',
|
| 35 |
+
'rest_framework',
|
| 36 |
+
'simulation',
|
| 37 |
+
]
|
| 38 |
+
|
| 39 |
+
MIDDLEWARE = [
|
| 40 |
+
'corsheaders.middleware.CorsMiddleware',
|
| 41 |
+
'django.middleware.security.SecurityMiddleware',
|
| 42 |
+
'whitenoise.middleware.WhiteNoiseMiddleware',
|
| 43 |
+
'django.contrib.sessions.middleware.SessionMiddleware',
|
| 44 |
+
'django.middleware.common.CommonMiddleware',
|
| 45 |
+
'django.middleware.csrf.CsrfViewMiddleware',
|
| 46 |
+
'django.contrib.auth.middleware.AuthenticationMiddleware',
|
| 47 |
+
'django.contrib.messages.middleware.MessageMiddleware',
|
| 48 |
+
'django.middleware.clickjacking.XFrameOptionsMiddleware',
|
| 49 |
+
]
|
| 50 |
+
|
| 51 |
+
CORS_ALLOW_ALL_ORIGINS = True
|
| 52 |
+
|
| 53 |
+
ROOT_URLCONF = 'backend.urls'
|
| 54 |
+
|
| 55 |
+
TEMPLATES = [
|
| 56 |
+
{
|
| 57 |
+
'BACKEND': 'django.template.backends.django.DjangoTemplates',
|
| 58 |
+
'DIRS': [BASE_DIR / 'static'],
|
| 59 |
+
'APP_DIRS': True,
|
| 60 |
+
'OPTIONS': {
|
| 61 |
+
'context_processors': [
|
| 62 |
+
'django.template.context_processors.debug',
|
| 63 |
+
'django.template.context_processors.request',
|
| 64 |
+
'django.contrib.auth.context_processors.auth',
|
| 65 |
+
'django.contrib.messages.context_processors.messages',
|
| 66 |
+
],
|
| 67 |
+
},
|
| 68 |
+
},
|
| 69 |
+
]
|
| 70 |
+
|
| 71 |
+
WSGI_APPLICATION = 'backend.wsgi.application'
|
| 72 |
+
|
| 73 |
+
DATABASES = {
|
| 74 |
+
'default': {
|
| 75 |
+
'ENGINE': 'django.db.backends.sqlite3',
|
| 76 |
+
'NAME': BASE_DIR / 'db.sqlite3',
|
| 77 |
+
}
|
| 78 |
+
}
|
| 79 |
+
|
| 80 |
+
STATIC_URL = '/static/'
|
| 81 |
+
STATIC_ROOT = BASE_DIR / 'staticfiles'
|
| 82 |
+
STATICFILES_DIRS = [
|
| 83 |
+
BASE_DIR.parent / 'static', # /root/simsite/static or /app/static
|
| 84 |
+
]
|
| 85 |
+
STATICFILES_STORAGE = 'whitenoise.storage.CompressedManifestStaticFilesStorage'
|
| 86 |
+
|
| 87 |
+
REST_FRAMEWORK = {
|
| 88 |
+
'DEFAULT_RENDERER_CLASSES': [
|
| 89 |
+
'rest_framework.renderers.JSONRenderer',
|
| 90 |
+
],
|
| 91 |
+
'DEFAULT_PARSER_CLASSES': [
|
| 92 |
+
'rest_framework.parsers.JSONParser',
|
| 93 |
+
],
|
| 94 |
+
'DEFAULT_AUTHENTICATION_CLASSES': [],
|
| 95 |
+
'DEFAULT_PERMISSION_CLASSES': [
|
| 96 |
+
'rest_framework.permissions.AllowAny',
|
| 97 |
+
],
|
| 98 |
+
}
|
backend/backend/urls.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
URL configuration for backend project.
|
| 3 |
+
"""
|
| 4 |
+
from django.contrib import admin
|
| 5 |
+
from django.urls import path, include, re_path
|
| 6 |
+
from django.conf import settings
|
| 7 |
+
from django.conf.urls.static import static
|
| 8 |
+
from rest_framework.routers import DefaultRouter
|
| 9 |
+
from simulation.views import SimulationViewSet, DangVanView
|
| 10 |
+
import os
|
| 11 |
+
|
| 12 |
+
|
| 13 |
+
def serve_react_app(request):
|
| 14 |
+
index_path = os.path.join(settings.BASE_DIR.parent, 'static', 'index.html')
|
| 15 |
+
with open(index_path, 'rb') as f:
|
| 16 |
+
return HttpResponse(f.read(), content_type='text/html')
|
| 17 |
+
|
| 18 |
+
|
| 19 |
+
from django.http import HttpResponse
|
| 20 |
+
|
| 21 |
+
|
| 22 |
+
router = DefaultRouter()
|
| 23 |
+
router.register(r'simulations', SimulationViewSet, basename='simulation')
|
| 24 |
+
|
| 25 |
+
urlpatterns = [
|
| 26 |
+
path('admin/', admin.site.urls),
|
| 27 |
+
path('api/', include(router.urls)),
|
| 28 |
+
path('api/dangvan/', DangVanView.as_view()),
|
| 29 |
+
re_path(r'^.*$', serve_react_app),
|
| 30 |
+
]
|
backend/backend/wsgi.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
WSGI config for backend project.
|
| 3 |
+
|
| 4 |
+
It exposes the WSGI callable as a module-level variable named ``application``.
|
| 5 |
+
|
| 6 |
+
For more information on this file, see
|
| 7 |
+
https://docs.djangoproject.com/en/6.0/howto/deployment/wsgi/
|
| 8 |
+
"""
|
| 9 |
+
|
| 10 |
+
import os
|
| 11 |
+
|
| 12 |
+
from django.core.wsgi import get_wsgi_application
|
| 13 |
+
|
| 14 |
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
|
| 15 |
+
|
| 16 |
+
application = get_wsgi_application()
|
backend/manage.py
ADDED
|
@@ -0,0 +1,22 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/usr/bin/env python
|
| 2 |
+
"""Django's command-line utility for administrative tasks."""
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
|
| 6 |
+
|
| 7 |
+
def main():
|
| 8 |
+
"""Run administrative tasks."""
|
| 9 |
+
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'backend.settings')
|
| 10 |
+
try:
|
| 11 |
+
from django.core.management import execute_from_command_line
|
| 12 |
+
except ImportError as exc:
|
| 13 |
+
raise ImportError(
|
| 14 |
+
"Couldn't import Django. Are you sure it's installed and "
|
| 15 |
+
"available on your PYTHONPATH environment variable? Did you "
|
| 16 |
+
"forget to activate a virtual environment?"
|
| 17 |
+
) from exc
|
| 18 |
+
execute_from_command_line(sys.argv)
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
if __name__ == '__main__':
|
| 22 |
+
main()
|
backend/simulation/__init__.py
ADDED
|
File without changes
|
backend/simulation/admin.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.contrib import admin
|
| 2 |
+
|
| 3 |
+
# Register your models here.
|
backend/simulation/apps.py
ADDED
|
@@ -0,0 +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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
Module pour exécuter des simulations FEniCS.
|
| 3 |
+
Exemple : Équation de diffusion avec termes source.
|
| 4 |
+
"""
|
| 5 |
+
import os
|
| 6 |
+
import json
|
| 7 |
+
from datetime import datetime
|
| 8 |
+
import numpy as np
|
| 9 |
+
import matplotlib
|
| 10 |
+
matplotlib.use('Agg')
|
| 11 |
+
import matplotlib.pyplot as plt
|
| 12 |
+
|
| 13 |
+
try:
|
| 14 |
+
import fenics as fe
|
| 15 |
+
FENICS_AVAILABLE = True
|
| 16 |
+
except ImportError:
|
| 17 |
+
FENICS_AVAILABLE = False
|
| 18 |
+
fe = None
|
| 19 |
+
|
| 20 |
+
|
| 21 |
+
def run_simulation(params):
|
| 22 |
+
"""
|
| 23 |
+
Exécute une simulation FEniCS basée sur les paramètres fournis.
|
| 24 |
+
|
| 25 |
+
Paramètres attendus dans params:
|
| 26 |
+
- mesh_resolution: résolution du maillage (entier)
|
| 27 |
+
- diffusion_coefficient: coefficient de diffusion D (float)
|
| 28 |
+
- source_term: terme source Q (float)
|
| 29 |
+
- time_final: temps final de simulation (float)
|
| 30 |
+
- num_steps: nombre de pas de temps (int)
|
| 31 |
+
|
| 32 |
+
Retourne:
|
| 33 |
+
- dict avec résultats et chemins de fichiers
|
| 34 |
+
"""
|
| 35 |
+
|
| 36 |
+
resolution = params.get('mesh_resolution', 32)
|
| 37 |
+
D = params.get('diffusion_coefficient', 0.1)
|
| 38 |
+
Q = params.get('source_term', 1.0)
|
| 39 |
+
T = params.get('time_final', 1.0)
|
| 40 |
+
num_steps = params.get('num_steps', 50)
|
| 41 |
+
|
| 42 |
+
dt = T / num_steps
|
| 43 |
+
|
| 44 |
+
if FENICS_AVAILABLE:
|
| 45 |
+
mesh = fe.UnitSquareMesh(resolution, resolution)
|
| 46 |
+
V = fe.FunctionSpace(mesh, 'P', 1)
|
| 47 |
+
|
| 48 |
+
u = fe.TrialFunction(V)
|
| 49 |
+
v = fe.TestFunction(V)
|
| 50 |
+
|
| 51 |
+
u_n = fe.Function(V)
|
| 52 |
+
u_n.interpolate(fe.Constant(0.0))
|
| 53 |
+
|
| 54 |
+
F = u*v*fe.dx + D*dt*fe.dot(fe.grad(u), fe.grad(v))*fe.dx - (u_n + dt*Q)*v*fe.dx
|
| 55 |
+
a, L = fe.lhs(F), fe.rhs(F)
|
| 56 |
+
|
| 57 |
+
u = fe.Function(V)
|
| 58 |
+
|
| 59 |
+
results = []
|
| 60 |
+
|
| 61 |
+
for n in range(num_steps):
|
| 62 |
+
fe.solve(a == L, u)
|
| 63 |
+
u_n.assign(u)
|
| 64 |
+
|
| 65 |
+
if n % 10 == 0:
|
| 66 |
+
max_val = np.max(u.vector())
|
| 67 |
+
mean_val = np.mean(u.vector())
|
| 68 |
+
results.append({
|
| 69 |
+
'step': n,
|
| 70 |
+
'time': (n+1)*dt,
|
| 71 |
+
'max': float(max_val),
|
| 72 |
+
'mean': float(mean_val)
|
| 73 |
+
})
|
| 74 |
+
|
| 75 |
+
final_max = float(np.max(u.vector()))
|
| 76 |
+
final_mean = float(np.mean(u.vector()))
|
| 77 |
+
else:
|
| 78 |
+
final_max = D * Q * T * 0.5
|
| 79 |
+
final_mean = D * Q * T * 0.25
|
| 80 |
+
results = []
|
| 81 |
+
|
| 82 |
+
for n in range(num_steps):
|
| 83 |
+
t = (n + 1) * dt
|
| 84 |
+
results.append({
|
| 85 |
+
'step': n,
|
| 86 |
+
'time': t,
|
| 87 |
+
'max': float(D * Q * t * 0.5),
|
| 88 |
+
'mean': float(D * Q * t * 0.25)
|
| 89 |
+
})
|
| 90 |
+
|
| 91 |
+
results_dir = '/tmp/simulation_results'
|
| 92 |
+
os.makedirs(results_dir, exist_ok=True)
|
| 93 |
+
|
| 94 |
+
timestamp = datetime.now().strftime('%Y%m%d_%H%M%S')
|
| 95 |
+
|
| 96 |
+
if FENICS_AVAILABLE:
|
| 97 |
+
xdmf_file = os.path.join(results_dir, f'result_{timestamp}.xdmf')
|
| 98 |
+
file = fe.XDMFFile(xdmf_file)
|
| 99 |
+
file.write(u, 0)
|
| 100 |
+
file.close()
|
| 101 |
+
else:
|
| 102 |
+
xdmf_file = os.path.join(results_dir, f'result_{timestamp}.txt')
|
| 103 |
+
with open(xdmf_file, 'w') as f:
|
| 104 |
+
f.write(json.dumps({'final_max': final_max, 'final_mean': final_mean}))
|
| 105 |
+
|
| 106 |
+
image_path = os.path.join(results_dir, f'result_{timestamp}.png')
|
| 107 |
+
|
| 108 |
+
fig, ax = plt.subplots(figsize=(8, 6))
|
| 109 |
+
times = [r['time'] for r in results]
|
| 110 |
+
max_vals = [r['max'] for r in results]
|
| 111 |
+
mean_vals = [r['mean'] for r in results]
|
| 112 |
+
|
| 113 |
+
ax.plot(times, max_vals, 'b-', label='Maximum', linewidth=2)
|
| 114 |
+
ax.plot(times, mean_vals, 'r--', label='Moyenne', linewidth=2)
|
| 115 |
+
ax.set_xlabel('Temps', fontsize=12)
|
| 116 |
+
ax.set_ylabel('Valeur', fontsize=12)
|
| 117 |
+
ax.set_title(f'Solution FEniCS - D={D}, Q={Q}, T={T:.2f}', fontsize=14)
|
| 118 |
+
ax.legend()
|
| 119 |
+
ax.grid(True, alpha=0.3)
|
| 120 |
+
|
| 121 |
+
plt.tight_layout()
|
| 122 |
+
plt.savefig(image_path, dpi=150, bbox_inches='tight')
|
| 123 |
+
plt.close()
|
| 124 |
+
|
| 125 |
+
# Generate per-time-step frames (PNG) for visualization
|
| 126 |
+
frames = []
|
| 127 |
+
try:
|
| 128 |
+
frames_dir = os.path.join(results_dir, f'frames_{timestamp}')
|
| 129 |
+
os.makedirs(frames_dir, exist_ok=True)
|
| 130 |
+
grid_n = 64
|
| 131 |
+
X, Y = np.meshgrid(np.linspace(-1, 1, grid_n), np.linspace(-1, 1, grid_n))
|
| 132 |
+
R = np.sqrt(X**2 + Y**2)
|
| 133 |
+
for idx, r in enumerate(results):
|
| 134 |
+
intensity = max(r['max'], 1e-12)
|
| 135 |
+
# Simple synthetic field: peaked at center, scaled by intensity
|
| 136 |
+
Z = np.clip((1.0 - R) * intensity, 0.0, None)
|
| 137 |
+
fig2, ax2 = plt.subplots(figsize=(3, 3))
|
| 138 |
+
im = ax2.imshow(Z, origin='lower', cmap='plasma')
|
| 139 |
+
ax2.set_axis_off()
|
| 140 |
+
plt.tight_layout(pad=0)
|
| 141 |
+
frame_path = os.path.join(frames_dir, f'frame_{idx:04d}.png')
|
| 142 |
+
plt.savefig(frame_path, dpi=100, bbox_inches='tight', pad_inches=0)
|
| 143 |
+
plt.close(fig2)
|
| 144 |
+
frames.append(frame_path)
|
| 145 |
+
except Exception:
|
| 146 |
+
# If frame generation fails, continue without frames
|
| 147 |
+
frames = []
|
| 148 |
+
|
| 149 |
+
return {
|
| 150 |
+
'final_max': final_max,
|
| 151 |
+
'final_mean': final_mean,
|
| 152 |
+
'results_file': xdmf_file,
|
| 153 |
+
'image_file': image_path,
|
| 154 |
+
'time_series': results,
|
| 155 |
+
'frames': frames,
|
| 156 |
+
}
|
backend/simulation/migrations/0001_initial.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Generated by Django 6.0.2 on 2026-02-04 13:38
|
| 2 |
+
|
| 3 |
+
from django.db import migrations, models
|
| 4 |
+
|
| 5 |
+
|
| 6 |
+
class Migration(migrations.Migration):
|
| 7 |
+
|
| 8 |
+
initial = True
|
| 9 |
+
|
| 10 |
+
dependencies = [
|
| 11 |
+
]
|
| 12 |
+
|
| 13 |
+
operations = [
|
| 14 |
+
migrations.CreateModel(
|
| 15 |
+
name='Simulation',
|
| 16 |
+
fields=[
|
| 17 |
+
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
| 18 |
+
('name', models.CharField(blank=True, max_length=255)),
|
| 19 |
+
('parameters', models.JSONField(default=dict)),
|
| 20 |
+
('status', models.CharField(choices=[('pending', 'En attente'), ('running', 'En cours'), ('completed', 'Terminée'), ('failed', 'Échouée')], default='pending', max_length=20)),
|
| 21 |
+
('created_at', models.DateTimeField(auto_now_add=True)),
|
| 22 |
+
('updated_at', models.DateTimeField(auto_now=True)),
|
| 23 |
+
('completed_at', models.DateTimeField(blank=True, null=True)),
|
| 24 |
+
('result_summary', models.JSONField(blank=True, null=True)),
|
| 25 |
+
('result_file_path', models.CharField(blank=True, max_length=500)),
|
| 26 |
+
('result_image_path', models.CharField(blank=True, max_length=500)),
|
| 27 |
+
('error_message', models.TextField(blank=True)),
|
| 28 |
+
],
|
| 29 |
+
),
|
| 30 |
+
]
|
backend/simulation/migrations/__init__.py
ADDED
|
File without changes
|
backend/simulation/models.py
ADDED
|
@@ -0,0 +1,26 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.db import models
|
| 2 |
+
|
| 3 |
+
|
| 4 |
+
class Simulation(models.Model):
|
| 5 |
+
STATUS_CHOICES = [
|
| 6 |
+
('pending', 'En attente'),
|
| 7 |
+
('running', 'En cours'),
|
| 8 |
+
('completed', 'Terminée'),
|
| 9 |
+
('failed', 'Échouée'),
|
| 10 |
+
]
|
| 11 |
+
|
| 12 |
+
name = models.CharField(max_length=255, blank=True)
|
| 13 |
+
parameters = models.JSONField(default=dict)
|
| 14 |
+
status = models.CharField(max_length=20, choices=STATUS_CHOICES, default='pending')
|
| 15 |
+
created_at = models.DateTimeField(auto_now_add=True)
|
| 16 |
+
updated_at = models.DateTimeField(auto_now=True)
|
| 17 |
+
completed_at = models.DateTimeField(null=True, blank=True)
|
| 18 |
+
|
| 19 |
+
result_summary = models.JSONField(null=True, blank=True)
|
| 20 |
+
result_file_path = models.CharField(max_length=500, blank=True)
|
| 21 |
+
result_image_path = models.CharField(max_length=500, blank=True)
|
| 22 |
+
|
| 23 |
+
error_message = models.TextField(blank=True)
|
| 24 |
+
|
| 25 |
+
def __str__(self):
|
| 26 |
+
return f"Simulation #{self.id} - {self.name or 'Sans nom'}"
|
backend/simulation/serializers.py
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from rest_framework import serializers
|
| 2 |
+
from .models import Simulation
|
| 3 |
+
|
| 4 |
+
|
| 5 |
+
class SimulationSerializer(serializers.ModelSerializer):
|
| 6 |
+
class Meta:
|
| 7 |
+
model = Simulation
|
| 8 |
+
fields = [
|
| 9 |
+
'id', 'name', 'parameters', 'status',
|
| 10 |
+
'created_at', 'updated_at', 'completed_at',
|
| 11 |
+
'result_summary', 'result_file_path', 'result_image_path',
|
| 12 |
+
'error_message'
|
| 13 |
+
]
|
| 14 |
+
read_only_fields = ['id', 'status', 'created_at', 'updated_at',
|
| 15 |
+
'completed_at', 'result_summary', 'result_file_path',
|
| 16 |
+
'result_image_path', 'error_message']
|
backend/simulation/tests.py
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.test import TestCase
|
| 2 |
+
|
| 3 |
+
# Create your tests here.
|
backend/simulation/urls.py
ADDED
|
@@ -0,0 +1,4 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from django.urls import path
|
| 2 |
+
from .views import SimulationViewSet
|
| 3 |
+
|
| 4 |
+
urlpatterns = []
|
backend/simulation/views.py
ADDED
|
@@ -0,0 +1,140 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import os
|
| 2 |
+
from django.utils import timezone
|
| 3 |
+
from django.conf import settings
|
| 4 |
+
from rest_framework import viewsets, status
|
| 5 |
+
from rest_framework.decorators import action
|
| 6 |
+
from rest_framework.response import Response
|
| 7 |
+
from rest_framework.permissions import AllowAny
|
| 8 |
+
from .models import Simulation
|
| 9 |
+
from .serializers import SimulationSerializer
|
| 10 |
+
from .fenics_runner import run_simulation
|
| 11 |
+
from rest_framework.views import APIView
|
| 12 |
+
from DangVan.dangvan import compute_dang_van
|
| 13 |
+
import threading
|
| 14 |
+
|
| 15 |
+
|
| 16 |
+
class SimulationViewSet(viewsets.ModelViewSet):
|
| 17 |
+
permission_classes = [AllowAny]
|
| 18 |
+
queryset = Simulation.objects.all().order_by('-created_at')
|
| 19 |
+
serializer_class = SimulationSerializer
|
| 20 |
+
|
| 21 |
+
def create(self, request, *args, **kwargs):
|
| 22 |
+
name = request.data.get('name', '')
|
| 23 |
+
parameters = request.data.get('parameters', {})
|
| 24 |
+
|
| 25 |
+
simulation = Simulation.objects.create(
|
| 26 |
+
name=name,
|
| 27 |
+
parameters=parameters,
|
| 28 |
+
status='running'
|
| 29 |
+
)
|
| 30 |
+
|
| 31 |
+
thread = threading.Thread(
|
| 32 |
+
target=self._run_simulation_async,
|
| 33 |
+
args=(simulation.id, parameters)
|
| 34 |
+
)
|
| 35 |
+
thread.start()
|
| 36 |
+
|
| 37 |
+
serializer = self.get_serializer(simulation)
|
| 38 |
+
return Response(serializer.data, status=status.HTTP_201_CREATED)
|
| 39 |
+
|
| 40 |
+
def _run_simulation_async(self, simulation_id, parameters):
|
| 41 |
+
simulation = Simulation.objects.get(id=simulation_id)
|
| 42 |
+
try:
|
| 43 |
+
result = run_simulation(parameters)
|
| 44 |
+
|
| 45 |
+
results_dir = os.path.join(settings.BASE_DIR, 'simulation_results')
|
| 46 |
+
os.makedirs(results_dir, exist_ok=True)
|
| 47 |
+
|
| 48 |
+
import shutil
|
| 49 |
+
final_result_path = os.path.join(
|
| 50 |
+
results_dir,
|
| 51 |
+
f'result_{simulation_id}.txt'
|
| 52 |
+
)
|
| 53 |
+
shutil.copy(result['results_file'], final_result_path)
|
| 54 |
+
|
| 55 |
+
final_image_path = os.path.join(
|
| 56 |
+
results_dir,
|
| 57 |
+
f'result_{simulation_id}.png'
|
| 58 |
+
)
|
| 59 |
+
shutil.copy(result['image_file'], final_image_path)
|
| 60 |
+
|
| 61 |
+
# Copy generated frames if present
|
| 62 |
+
frames_meta = None
|
| 63 |
+
frames_src = result.get('frames') or []
|
| 64 |
+
if frames_src:
|
| 65 |
+
frames_target_dir = os.path.join(results_dir, f'frames_{simulation_id}')
|
| 66 |
+
os.makedirs(frames_target_dir, exist_ok=True)
|
| 67 |
+
copied = []
|
| 68 |
+
for fp in frames_src:
|
| 69 |
+
try:
|
| 70 |
+
basename = os.path.basename(fp)
|
| 71 |
+
dest = os.path.join(frames_target_dir, basename)
|
| 72 |
+
shutil.copy(fp, dest)
|
| 73 |
+
copied.append(f'simulation_results/frames_{simulation_id}/{basename}')
|
| 74 |
+
except Exception:
|
| 75 |
+
continue
|
| 76 |
+
if copied:
|
| 77 |
+
frames_meta = {
|
| 78 |
+
'dir': f'simulation_results/frames_{simulation_id}',
|
| 79 |
+
'files': copied,
|
| 80 |
+
'count': len(copied),
|
| 81 |
+
}
|
| 82 |
+
|
| 83 |
+
simulation.result_summary = {
|
| 84 |
+
'final_max': result['final_max'],
|
| 85 |
+
'final_mean': result['final_mean'],
|
| 86 |
+
'time_series': result['time_series'],
|
| 87 |
+
'frames': frames_meta
|
| 88 |
+
}
|
| 89 |
+
simulation.result_file_path = f'simulation_results/result_{simulation_id}.txt'
|
| 90 |
+
simulation.result_image_path = f'simulation_results/result_{simulation_id}.png'
|
| 91 |
+
simulation.status = 'completed'
|
| 92 |
+
simulation.completed_at = timezone.now()
|
| 93 |
+
simulation.save()
|
| 94 |
+
|
| 95 |
+
except Exception as e:
|
| 96 |
+
simulation.status = 'failed'
|
| 97 |
+
simulation.error_message = str(e)
|
| 98 |
+
simulation.save()
|
| 99 |
+
|
| 100 |
+
@action(detail=True, methods=['get'])
|
| 101 |
+
def result_image(self, request, pk=None):
|
| 102 |
+
simulation = self.get_object()
|
| 103 |
+
if simulation.result_image_path:
|
| 104 |
+
image_path = os.path.join(settings.BASE_DIR, simulation.result_image_path)
|
| 105 |
+
from django.http import FileResponse
|
| 106 |
+
return FileResponse(open(image_path, 'rb'), content_type='image/png')
|
| 107 |
+
return Response({'error': 'Aucune image disponible'}, status=404)
|
| 108 |
+
|
| 109 |
+
@action(detail=True, methods=['get'], url_path='frame/(?P<index>\\d+)')
|
| 110 |
+
def frame(self, request, pk=None, index=None):
|
| 111 |
+
simulation = self.get_object()
|
| 112 |
+
frames = (simulation.result_summary or {}).get('frames') or {}
|
| 113 |
+
files = frames.get('files') or []
|
| 114 |
+
try:
|
| 115 |
+
idx = int(index)
|
| 116 |
+
except Exception:
|
| 117 |
+
return Response({'error': 'Index invalide'}, status=400)
|
| 118 |
+
if 0 <= idx < len(files):
|
| 119 |
+
frame_rel = files[idx]
|
| 120 |
+
frame_abs = os.path.join(settings.BASE_DIR, frame_rel)
|
| 121 |
+
from django.http import FileResponse
|
| 122 |
+
return FileResponse(open(frame_abs, 'rb'), content_type='image/png')
|
| 123 |
+
return Response({'error': 'Frame non disponible'}, status=404)
|
| 124 |
+
|
| 125 |
+
|
| 126 |
+
class DangVanView(APIView):
|
| 127 |
+
permission_classes = [AllowAny]
|
| 128 |
+
|
| 129 |
+
def post(self, request):
|
| 130 |
+
data = request.data or {}
|
| 131 |
+
stress_series = data.get('stress_series')
|
| 132 |
+
a = data.get('a')
|
| 133 |
+
b = data.get('b')
|
| 134 |
+
if stress_series is None or a is None or b is None:
|
| 135 |
+
return Response({'error': 'Paramètres requis: stress_series, a, b'}, status=status.HTTP_400_BAD_REQUEST)
|
| 136 |
+
try:
|
| 137 |
+
result = compute_dang_van(stress_series, a, b)
|
| 138 |
+
return Response(result, status=status.HTTP_200_OK)
|
| 139 |
+
except Exception as e:
|
| 140 |
+
return Response({'error': str(e)}, status=status.HTTP_400_BAD_REQUEST)
|
requirements.txt
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
django>=4.2
|
| 2 |
+
djangorestframework>=3.14
|
| 3 |
+
gunicorn>=21.0
|
| 4 |
+
matplotlib>=3.7
|
| 5 |
+
numpy>=1.24
|
| 6 |
+
django-cors-headers>=4.3
|
| 7 |
+
whitenoise>=6.6
|
static/assets/index-DOJBTpfK.js
ADDED
|
The diff for this file is too large to render.
See raw diff
|
|
|
static/assets/index-DYM3EwRh.css
ADDED
|
@@ -0,0 +1 @@
|
|
|
|
|
|
|
| 1 |
+
.app{max-width:1200px;margin:0 auto;padding:20px;font-family:system-ui,-apple-system,sans-serif}header{text-align:center;margin-bottom:30px}main{display:grid;grid-template-columns:1fr 1fr;gap:20px}.simulation-form,.simulation-list,.result-section{background:#f5f5f5;padding:20px;border-radius:8px}.form-group{margin-bottom:15px}.form-group label{display:block;margin-bottom:5px;font-weight:700}.form-group input[type=text]{width:100%;padding:8px;border:1px solid #ddd;border-radius:4px;box-sizing:border-box}.form-group input[type=range]{width:100%}button{background:#007bff;color:#fff;border:none;padding:10px 20px;border-radius:4px;cursor:pointer;width:100%;font-size:1rem}button:disabled{background:#ccc;cursor:not-allowed}table{width:100%;border-collapse:collapse}th,td{padding:10px;text-align:left;border-bottom:1px solid #ddd}tr:hover{cursor:pointer;background:#e9e9e9}.status{padding:4px 8px;border-radius:4px;font-size:.9em}.status-completed{background:#d4edda;color:#155724}.status-running{background:#fff3cd;color:#856404}.status-failed{background:#f8d7da;color:#721c24}.status-pending{background:#e2e3e5;color:#383d41}.result-image img{max-width:100%;border-radius:4px}.error{background:#f8d7da;color:#721c24;padding:10px;border-radius:4px;margin-bottom:15px}.result-section{grid-column:1 / -1}@media (max-width: 768px){main{grid-template-columns:1fr}}
|
static/index.html
ADDED
|
@@ -0,0 +1,975 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
<!DOCTYPE html>
|
| 2 |
+
<html lang="fr">
|
| 3 |
+
<head>
|
| 4 |
+
<meta charset="UTF-8" />
|
| 5 |
+
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
| 6 |
+
<title>SimSite - Applications de Simulation</title>
|
| 7 |
+
<script src="https://cdn.jsdelivr.net/npm/chart.js"></script>
|
| 8 |
+
<style>
|
| 9 |
+
* { box-sizing: border-box; }
|
| 10 |
+
body { font-family: 'Segoe UI', sans-serif; margin: 0; padding: 0; background: #0a0a1a; color: #eee; min-height: 100vh; }
|
| 11 |
+
|
| 12 |
+
/* Navigation */
|
| 13 |
+
.navbar {
|
| 14 |
+
background: linear-gradient(135deg, #1a1a2e 0%, #16213e 100%);
|
| 15 |
+
padding: 15px 30px;
|
| 16 |
+
display: flex;
|
| 17 |
+
align-items: center;
|
| 18 |
+
justify-content: space-between;
|
| 19 |
+
border-bottom: 1px solid #0f3460;
|
| 20 |
+
position: sticky;
|
| 21 |
+
top: 0;
|
| 22 |
+
z-index: 100;
|
| 23 |
+
}
|
| 24 |
+
.navbar-brand {
|
| 25 |
+
font-size: 1.5em;
|
| 26 |
+
font-weight: bold;
|
| 27 |
+
color: #00d4ff;
|
| 28 |
+
cursor: pointer;
|
| 29 |
+
display: flex;
|
| 30 |
+
align-items: center;
|
| 31 |
+
gap: 10px;
|
| 32 |
+
}
|
| 33 |
+
.navbar-brand:hover { opacity: 0.8; }
|
| 34 |
+
.nav-breadcrumb {
|
| 35 |
+
color: #888;
|
| 36 |
+
font-size: 0.9em;
|
| 37 |
+
}
|
| 38 |
+
.nav-breadcrumb span { color: #00d4ff; }
|
| 39 |
+
|
| 40 |
+
/* Views */
|
| 41 |
+
.view { display: none; padding: 30px; max-width: 1400px; margin: 0 auto; }
|
| 42 |
+
.view.active { display: block; }
|
| 43 |
+
|
| 44 |
+
/* Home Page */
|
| 45 |
+
.home-header {
|
| 46 |
+
text-align: center;
|
| 47 |
+
padding: 60px 20px;
|
| 48 |
+
background: linear-gradient(135deg, #1a1a2e 0%, #0f3460 100%);
|
| 49 |
+
margin: -30px -30px 30px -30px;
|
| 50 |
+
border-bottom: 2px solid #00d4ff;
|
| 51 |
+
}
|
| 52 |
+
.home-header h1 {
|
| 53 |
+
font-size: 3em;
|
| 54 |
+
margin: 0;
|
| 55 |
+
background: linear-gradient(135deg, #00d4ff, #00ff88);
|
| 56 |
+
-webkit-background-clip: text;
|
| 57 |
+
-webkit-text-fill-color: transparent;
|
| 58 |
+
background-clip: text;
|
| 59 |
+
}
|
| 60 |
+
.home-header p {
|
| 61 |
+
color: #aaa;
|
| 62 |
+
font-size: 1.2em;
|
| 63 |
+
margin-top: 10px;
|
| 64 |
+
}
|
| 65 |
+
|
| 66 |
+
/* App Cards */
|
| 67 |
+
.apps-grid {
|
| 68 |
+
display: grid;
|
| 69 |
+
grid-template-columns: repeat(auto-fit, minmax(350px, 1fr));
|
| 70 |
+
gap: 30px;
|
| 71 |
+
padding: 20px 0;
|
| 72 |
+
}
|
| 73 |
+
.app-card {
|
| 74 |
+
background: linear-gradient(145deg, #1a1a2e, #16213e);
|
| 75 |
+
border: 1px solid #0f3460;
|
| 76 |
+
border-radius: 16px;
|
| 77 |
+
padding: 30px;
|
| 78 |
+
cursor: pointer;
|
| 79 |
+
transition: all 0.3s ease;
|
| 80 |
+
position: relative;
|
| 81 |
+
overflow: hidden;
|
| 82 |
+
}
|
| 83 |
+
.app-card::before {
|
| 84 |
+
content: '';
|
| 85 |
+
position: absolute;
|
| 86 |
+
top: 0;
|
| 87 |
+
left: 0;
|
| 88 |
+
right: 0;
|
| 89 |
+
height: 4px;
|
| 90 |
+
background: linear-gradient(90deg, var(--card-color), transparent);
|
| 91 |
+
}
|
| 92 |
+
.app-card:hover {
|
| 93 |
+
transform: translateY(-5px);
|
| 94 |
+
box-shadow: 0 10px 40px rgba(0, 212, 255, 0.2);
|
| 95 |
+
border-color: var(--card-color);
|
| 96 |
+
}
|
| 97 |
+
.app-card-icon {
|
| 98 |
+
font-size: 3em;
|
| 99 |
+
margin-bottom: 15px;
|
| 100 |
+
}
|
| 101 |
+
.app-card h2 {
|
| 102 |
+
color: #fff;
|
| 103 |
+
margin: 0 0 10px 0;
|
| 104 |
+
font-size: 1.5em;
|
| 105 |
+
}
|
| 106 |
+
.app-card p {
|
| 107 |
+
color: #aaa;
|
| 108 |
+
margin: 0 0 20px 0;
|
| 109 |
+
line-height: 1.6;
|
| 110 |
+
}
|
| 111 |
+
.app-card-tags {
|
| 112 |
+
display: flex;
|
| 113 |
+
flex-wrap: wrap;
|
| 114 |
+
gap: 8px;
|
| 115 |
+
}
|
| 116 |
+
.app-card-tag {
|
| 117 |
+
background: rgba(0, 212, 255, 0.1);
|
| 118 |
+
color: #00d4ff;
|
| 119 |
+
padding: 4px 12px;
|
| 120 |
+
border-radius: 20px;
|
| 121 |
+
font-size: 0.8em;
|
| 122 |
+
}
|
| 123 |
+
.app-card-arrow {
|
| 124 |
+
position: absolute;
|
| 125 |
+
bottom: 30px;
|
| 126 |
+
right: 30px;
|
| 127 |
+
font-size: 1.5em;
|
| 128 |
+
color: var(--card-color);
|
| 129 |
+
opacity: 0;
|
| 130 |
+
transform: translateX(-10px);
|
| 131 |
+
transition: all 0.3s ease;
|
| 132 |
+
}
|
| 133 |
+
.app-card:hover .app-card-arrow {
|
| 134 |
+
opacity: 1;
|
| 135 |
+
transform: translateX(0);
|
| 136 |
+
}
|
| 137 |
+
|
| 138 |
+
/* App-specific styles */
|
| 139 |
+
.section-title {
|
| 140 |
+
color: #00d4ff;
|
| 141 |
+
border-bottom: 2px solid #00d4ff;
|
| 142 |
+
padding-bottom: 10px;
|
| 143 |
+
margin-bottom: 20px;
|
| 144 |
+
display: flex;
|
| 145 |
+
align-items: center;
|
| 146 |
+
gap: 10px;
|
| 147 |
+
}
|
| 148 |
+
.panel {
|
| 149 |
+
background: #16213e;
|
| 150 |
+
padding: 25px;
|
| 151 |
+
border-radius: 12px;
|
| 152 |
+
border: 1px solid #0f3460;
|
| 153 |
+
margin-bottom: 20px;
|
| 154 |
+
}
|
| 155 |
+
.form-group { margin-bottom: 15px; }
|
| 156 |
+
.form-group label { display: block; margin-bottom: 5px; color: #00d4ff; font-weight: 500; }
|
| 157 |
+
.form-group input[type="text"],
|
| 158 |
+
.form-group input[type="number"],
|
| 159 |
+
.form-group textarea {
|
| 160 |
+
width: 100%;
|
| 161 |
+
padding: 12px;
|
| 162 |
+
border-radius: 8px;
|
| 163 |
+
border: 1px solid #0f3460;
|
| 164 |
+
background: #1a1a2e;
|
| 165 |
+
color: #fff;
|
| 166 |
+
font-size: 1em;
|
| 167 |
+
transition: border-color 0.3s;
|
| 168 |
+
}
|
| 169 |
+
.form-group input:focus, .form-group textarea:focus {
|
| 170 |
+
outline: none;
|
| 171 |
+
border-color: #00d4ff;
|
| 172 |
+
}
|
| 173 |
+
.form-group input[type="range"] { width: 100%; accent-color: #00d4ff; }
|
| 174 |
+
.form-group input[type="file"] { color: #00d4ff; }
|
| 175 |
+
.form-group textarea { font-family: 'Consolas', monospace; }
|
| 176 |
+
|
| 177 |
+
button, .btn {
|
| 178 |
+
background: linear-gradient(135deg, #00d4ff, #0099cc);
|
| 179 |
+
color: #1a1a2e;
|
| 180 |
+
border: none;
|
| 181 |
+
padding: 12px 24px;
|
| 182 |
+
border-radius: 8px;
|
| 183 |
+
cursor: pointer;
|
| 184 |
+
font-weight: bold;
|
| 185 |
+
font-size: 1em;
|
| 186 |
+
transition: all 0.2s;
|
| 187 |
+
}
|
| 188 |
+
button:hover, .btn:hover { transform: scale(1.02); box-shadow: 0 5px 20px rgba(0, 212, 255, 0.3); }
|
| 189 |
+
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }
|
| 190 |
+
.btn-secondary { background: #0f3460; color: #00d4ff; }
|
| 191 |
+
.btn-danger { background: #ff1744; color: #fff; }
|
| 192 |
+
|
| 193 |
+
/* Grid layouts */
|
| 194 |
+
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; }
|
| 195 |
+
.grid-2-1 { display: grid; grid-template-columns: 2fr 1fr; gap: 20px; }
|
| 196 |
+
@media (max-width: 900px) {
|
| 197 |
+
.grid-2, .grid-2-1 { grid-template-columns: 1fr; }
|
| 198 |
+
}
|
| 199 |
+
|
| 200 |
+
/* Table */
|
| 201 |
+
table { width: 100%; border-collapse: collapse; }
|
| 202 |
+
th, td { padding: 12px; text-align: left; border-bottom: 1px solid #0f3460; }
|
| 203 |
+
th { color: #00d4ff; font-weight: 600; }
|
| 204 |
+
tr:hover { background: rgba(0, 212, 255, 0.05); }
|
| 205 |
+
|
| 206 |
+
/* Status badges */
|
| 207 |
+
.badge { padding: 4px 12px; border-radius: 20px; font-weight: bold; font-size: 0.85em; }
|
| 208 |
+
.badge-success { background: #00c853; color: #1a1a2e; }
|
| 209 |
+
.badge-warning { background: #ffab00; color: #1a1a2e; }
|
| 210 |
+
.badge-danger { background: #ff1744; color: #fff; }
|
| 211 |
+
|
| 212 |
+
/* Results */
|
| 213 |
+
.result-card {
|
| 214 |
+
background: #1a1a2e;
|
| 215 |
+
padding: 20px;
|
| 216 |
+
border-radius: 12px;
|
| 217 |
+
border: 1px solid #0f3460;
|
| 218 |
+
}
|
| 219 |
+
.result-card h3 { color: #00d4ff; margin: 0 0 15px 0; }
|
| 220 |
+
.result-value { font-size: 2.5em; color: #00d4ff; font-weight: bold; }
|
| 221 |
+
.chart-container { height: 350px; position: relative; }
|
| 222 |
+
|
| 223 |
+
/* Alerts */
|
| 224 |
+
.alert { padding: 15px 20px; border-radius: 8px; margin-bottom: 15px; }
|
| 225 |
+
.alert-error { background: rgba(255, 23, 68, 0.2); border: 1px solid #ff1744; color: #ff6b6b; }
|
| 226 |
+
.alert-success { background: rgba(0, 200, 83, 0.2); border: 1px solid #00c853; color: #69f0ae; }
|
| 227 |
+
.alert-info { background: rgba(0, 212, 255, 0.1); border: 1px solid #0f3460; color: #00d4ff; }
|
| 228 |
+
|
| 229 |
+
/* Tabs */
|
| 230 |
+
.tabs { display: flex; gap: 5px; margin-bottom: 20px; }
|
| 231 |
+
.tab { padding: 10px 20px; background: #0f3460; color: #00d4ff; border: none; border-radius: 8px 8px 0 0; cursor: pointer; transition: all 0.2s; }
|
| 232 |
+
.tab.active { background: #00d4ff; color: #1a1a2e; }
|
| 233 |
+
.tab-content { display: none; }
|
| 234 |
+
.tab-content.active { display: block; }
|
| 235 |
+
|
| 236 |
+
/* DV specific */
|
| 237 |
+
.dv-safe { color: #00c853; font-weight: bold; }
|
| 238 |
+
.dv-unsafe { color: #ff1744; font-weight: bold; }
|
| 239 |
+
|
| 240 |
+
/* Equation box */
|
| 241 |
+
.equation-box {
|
| 242 |
+
background: #0f3460;
|
| 243 |
+
padding: 20px;
|
| 244 |
+
border-radius: 12px;
|
| 245 |
+
text-align: center;
|
| 246 |
+
font-size: 1.1em;
|
| 247 |
+
margin-bottom: 20px;
|
| 248 |
+
border-left: 4px solid #00d4ff;
|
| 249 |
+
}
|
| 250 |
+
.equation-box .equation { font-size: 1.3em; margin: 10px 0; color: #00d4ff; }
|
| 251 |
+
.equation-box small { color: #888; }
|
| 252 |
+
|
| 253 |
+
/* Animation */
|
| 254 |
+
.animation-container { text-align: center; }
|
| 255 |
+
.animation-controls { margin-top: 15px; display: flex; justify-content: center; gap: 10px; }
|
| 256 |
+
.animation-controls button { width: auto; }
|
| 257 |
+
|
| 258 |
+
/* Hidden utility */
|
| 259 |
+
.hidden { display: none !important; }
|
| 260 |
+
</style>
|
| 261 |
+
</head>
|
| 262 |
+
<body>
|
| 263 |
+
<!-- Navigation Bar -->
|
| 264 |
+
<nav class="navbar">
|
| 265 |
+
<div class="navbar-brand" onclick="navigateTo('home')">
|
| 266 |
+
<span>SimSite</span>
|
| 267 |
+
</div>
|
| 268 |
+
<div class="nav-breadcrumb" id="breadcrumb"></div>
|
| 269 |
+
</nav>
|
| 270 |
+
|
| 271 |
+
<!-- HOME VIEW -->
|
| 272 |
+
<div id="view-home" class="view active">
|
| 273 |
+
<div class="home-header">
|
| 274 |
+
<h1>SimSite</h1>
|
| 275 |
+
<p>Plateforme de simulation numerique et d'analyse</p>
|
| 276 |
+
</div>
|
| 277 |
+
|
| 278 |
+
<div class="apps-grid">
|
| 279 |
+
<!-- FEniCS App Card -->
|
| 280 |
+
<div class="app-card" style="--card-color: #00d4ff;" onclick="navigateTo('fenics')">
|
| 281 |
+
<div class="app-card-icon">🔬</div>
|
| 282 |
+
<h2>Simulation FEniCS</h2>
|
| 283 |
+
<p>Resolution d'equations aux derivees partielles (EDP). Simulez la diffusion thermique sur un domaine 2D avec visualisation en temps reel.</p>
|
| 284 |
+
<div class="app-card-tags">
|
| 285 |
+
<span class="app-card-tag">EDP</span>
|
| 286 |
+
<span class="app-card-tag">Diffusion</span>
|
| 287 |
+
<span class="app-card-tag">Elements Finis</span>
|
| 288 |
+
</div>
|
| 289 |
+
<div class="app-card-arrow">→</div>
|
| 290 |
+
</div>
|
| 291 |
+
|
| 292 |
+
<!-- Dang Van App Card -->
|
| 293 |
+
<div class="app-card" style="--card-color: #ff6b6b;" onclick="navigateTo('dangvan')">
|
| 294 |
+
<div class="app-card-icon">⚙️</div>
|
| 295 |
+
<h2>Analyse Dang Van</h2>
|
| 296 |
+
<p>Critere de fatigue multiaxiale pour l'analyse de la tenue en fatigue des pieces mecaniques soumises a des chargements complexes.</p>
|
| 297 |
+
<div class="app-card-tags">
|
| 298 |
+
<span class="app-card-tag">Fatigue</span>
|
| 299 |
+
<span class="app-card-tag">Multiaxial</span>
|
| 300 |
+
<span class="app-card-tag">Mecanique</span>
|
| 301 |
+
</div>
|
| 302 |
+
<div class="app-card-arrow">→</div>
|
| 303 |
+
</div>
|
| 304 |
+
|
| 305 |
+
<!-- Placeholder for future apps -->
|
| 306 |
+
<div class="app-card" style="--card-color: #888; opacity: 0.5; cursor: default;">
|
| 307 |
+
<div class="app-card-icon">🚀</div>
|
| 308 |
+
<h2>Prochainement...</h2>
|
| 309 |
+
<p>D'autres applications de simulation seront ajoutees. Restez connectes pour decouvrir de nouveaux outils d'analyse.</p>
|
| 310 |
+
<div class="app-card-tags">
|
| 311 |
+
<span class="app-card-tag">A venir</span>
|
| 312 |
+
</div>
|
| 313 |
+
</div>
|
| 314 |
+
</div>
|
| 315 |
+
</div>
|
| 316 |
+
|
| 317 |
+
<!-- FENICS VIEW -->
|
| 318 |
+
<div id="view-fenics" class="view">
|
| 319 |
+
<h1 class="section-title">🔬 Simulation FEniCS</h1>
|
| 320 |
+
|
| 321 |
+
<div class="equation-box">
|
| 322 |
+
<strong>Equation de diffusion transitoire</strong>
|
| 323 |
+
<div class="equation">∂u/∂t = D · ∇²u + Q</div>
|
| 324 |
+
<small>
|
| 325 |
+
u(x,y,t) = champ de temperature | D = coefficient de diffusion | Q = terme source<br>
|
| 326 |
+
Conditions: u(x,y,0) = 0 | u = 0 sur ∂Ω (bords)
|
| 327 |
+
</small>
|
| 328 |
+
</div>
|
| 329 |
+
|
| 330 |
+
<div class="grid-2">
|
| 331 |
+
<!-- Form Panel -->
|
| 332 |
+
<div class="panel">
|
| 333 |
+
<h2 class="section-title">Nouvelle Simulation</h2>
|
| 334 |
+
<form id="simForm">
|
| 335 |
+
<div class="form-group">
|
| 336 |
+
<label>Nom de la simulation</label>
|
| 337 |
+
<input type="text" id="simName" placeholder="Ma simulation">
|
| 338 |
+
</div>
|
| 339 |
+
<div class="form-group">
|
| 340 |
+
<label>Resolution du maillage: <span id="meshVal">32</span></label>
|
| 341 |
+
<input type="range" id="meshResolution" min="8" max="64" step="8" value="32" oninput="document.getElementById('meshVal').textContent = this.value">
|
| 342 |
+
</div>
|
| 343 |
+
<div class="form-group">
|
| 344 |
+
<label>Coefficient de diffusion D: <span id="diffVal">0.1</span></label>
|
| 345 |
+
<input type="range" id="diffCoef" min="0.01" max="0.5" step="0.01" value="0.1" oninput="document.getElementById('diffVal').textContent = this.value">
|
| 346 |
+
</div>
|
| 347 |
+
<div class="form-group">
|
| 348 |
+
<label>Terme source Q: <span id="sourceVal">1.0</span></label>
|
| 349 |
+
<input type="range" id="sourceTerm" min="0.1" max="3.0" step="0.1" value="1.0" oninput="document.getElementById('sourceVal').textContent = this.value">
|
| 350 |
+
</div>
|
| 351 |
+
<div class="form-group">
|
| 352 |
+
<label>Temps final: <span id="timeVal">1.0</span>s</label>
|
| 353 |
+
<input type="range" id="timeFinal" min="0.1" max="2.0" step="0.1" value="1.0" oninput="document.getElementById('timeVal').textContent = this.value">
|
| 354 |
+
</div>
|
| 355 |
+
<div class="form-group">
|
| 356 |
+
<label>Nombre de pas de temps: <span id="stepsVal">20</span></label>
|
| 357 |
+
<input type="range" id="numSteps" min="10" max="50" step="5" value="20" oninput="document.getElementById('stepsVal').textContent = this.value">
|
| 358 |
+
</div>
|
| 359 |
+
<button type="submit" id="submitBtn">Lancer la simulation</button>
|
| 360 |
+
</form>
|
| 361 |
+
<div id="formError" class="alert alert-error hidden"></div>
|
| 362 |
+
</div>
|
| 363 |
+
|
| 364 |
+
<!-- Simulations List -->
|
| 365 |
+
<div class="panel">
|
| 366 |
+
<h2 class="section-title">
|
| 367 |
+
Simulations recentes
|
| 368 |
+
<button class="btn-secondary" style="margin-left: auto; padding: 8px 16px;" onclick="loadSimulations()">Rafraichir</button>
|
| 369 |
+
</h2>
|
| 370 |
+
<table>
|
| 371 |
+
<thead>
|
| 372 |
+
<tr><th>ID</th><th>Nom</th><th>Status</th><th>Date</th></tr>
|
| 373 |
+
</thead>
|
| 374 |
+
<tbody id="simTable">
|
| 375 |
+
<tr><td colspan="4">Chargement...</td></tr>
|
| 376 |
+
</tbody>
|
| 377 |
+
</table>
|
| 378 |
+
</div>
|
| 379 |
+
</div>
|
| 380 |
+
|
| 381 |
+
<!-- Results Section (hidden by default) -->
|
| 382 |
+
<div id="resultSection" class="panel hidden">
|
| 383 |
+
<div style="display: flex; justify-content: space-between; align-items: center;">
|
| 384 |
+
<h2 class="section-title" style="margin: 0; border: none;">Resultats - Simulation #<span id="resultId"></span></h2>
|
| 385 |
+
<button class="btn-danger" onclick="closeResults()">Fermer</button>
|
| 386 |
+
</div>
|
| 387 |
+
|
| 388 |
+
<div class="grid-2" style="margin-top: 20px;">
|
| 389 |
+
<div class="result-card">
|
| 390 |
+
<h3>Valeur maximale</h3>
|
| 391 |
+
<div class="result-value" id="resultMax">-</div>
|
| 392 |
+
</div>
|
| 393 |
+
<div class="result-card">
|
| 394 |
+
<h3>Valeur moyenne</h3>
|
| 395 |
+
<div class="result-value" id="resultMean">-</div>
|
| 396 |
+
</div>
|
| 397 |
+
</div>
|
| 398 |
+
|
| 399 |
+
<div class="grid-2" style="margin-top: 20px;">
|
| 400 |
+
<div class="result-card">
|
| 401 |
+
<h3>Evolution temporelle</h3>
|
| 402 |
+
<div class="chart-container"><canvas id="timeChart"></canvas></div>
|
| 403 |
+
</div>
|
| 404 |
+
<div class="result-card animation-container">
|
| 405 |
+
<h3>Animation de la solution</h3>
|
| 406 |
+
<canvas id="animationCanvas" width="300" height="300"></canvas>
|
| 407 |
+
<div class="animation-controls">
|
| 408 |
+
<button onclick="playAnimation()">Play</button>
|
| 409 |
+
<button onclick="pauseAnimation()">Pause</button>
|
| 410 |
+
<button onclick="resetAnimation()">Reset</button>
|
| 411 |
+
</div>
|
| 412 |
+
<p>Temps: <span id="animTime">0.00</span> / <span id="animTotal">1.00</span>s</p>
|
| 413 |
+
</div>
|
| 414 |
+
</div>
|
| 415 |
+
</div>
|
| 416 |
+
</div>
|
| 417 |
+
|
| 418 |
+
<!-- DANG VAN VIEW -->
|
| 419 |
+
<div id="view-dangvan" class="view">
|
| 420 |
+
<h1 class="section-title">⚙️ Analyse de Fatigue - Critere de Dang Van</h1>
|
| 421 |
+
|
| 422 |
+
<div class="equation-box">
|
| 423 |
+
<strong>Critere de Dang Van</strong>
|
| 424 |
+
<div class="equation">τ_max + a · σ_H ≤ b</div>
|
| 425 |
+
<small>
|
| 426 |
+
τ_max = contrainte de cisaillement maximale (balayage des facettes)<br>
|
| 427 |
+
σ_H = pression hydrostatique = (σ_xx + σ_yy + σ_zz) / 3<br>
|
| 428 |
+
a = pente du critere | b = limite en cisaillement alterne
|
| 429 |
+
</small>
|
| 430 |
+
</div>
|
| 431 |
+
|
| 432 |
+
<div class="grid-2-1">
|
| 433 |
+
<div class="panel">
|
| 434 |
+
<h2 class="section-title">Donnees de contrainte</h2>
|
| 435 |
+
|
| 436 |
+
<div class="tabs">
|
| 437 |
+
<button class="tab active" onclick="switchDvTab('json')">Saisie JSON</button>
|
| 438 |
+
<button class="tab" onclick="switchDvTab('file')">Import Fichier</button>
|
| 439 |
+
</div>
|
| 440 |
+
|
| 441 |
+
<div id="dvTabJson" class="tab-content active">
|
| 442 |
+
<div class="form-group">
|
| 443 |
+
<label>Serie de tenseurs de contrainte (format Voigt 6 composantes)</label>
|
| 444 |
+
<textarea id="dvStress" rows="8" placeholder='Exemple:
|
| 445 |
+
[[100, 0, 0, 0, 0, 0],
|
| 446 |
+
[50, 0, 0, 0, 0, 0],
|
| 447 |
+
[0, 0, 0, 0, 0, 0],
|
| 448 |
+
[-50, 0, 0, 0, 0, 0],
|
| 449 |
+
[-100, 0, 0, 0, 0, 0]]
|
| 450 |
+
|
| 451 |
+
Format: [σ_xx, σ_yy, σ_zz, σ_xy, σ_xz, σ_yz] en MPa'></textarea>
|
| 452 |
+
</div>
|
| 453 |
+
</div>
|
| 454 |
+
|
| 455 |
+
<div id="dvTabFile" class="tab-content">
|
| 456 |
+
<div class="form-group">
|
| 457 |
+
<label>Fichier CSV ou TXT</label>
|
| 458 |
+
<input type="file" id="dvFile" accept=".csv,.txt,.dat">
|
| 459 |
+
</div>
|
| 460 |
+
<div class="alert alert-info">
|
| 461 |
+
<strong>Format attendu:</strong><br>
|
| 462 |
+
- 6 colonnes: σ_xx, σ_yy, σ_zz, σ_xy, σ_xz, σ_yz<br>
|
| 463 |
+
- Une ligne = un pas de temps<br>
|
| 464 |
+
- Separateurs: virgule, point-virgule, tabulation ou espace<br>
|
| 465 |
+
- Lignes commencant par # ou // ignorees
|
| 466 |
+
</div>
|
| 467 |
+
<div id="dvFilePreview" class="hidden" style="margin-top: 15px;">
|
| 468 |
+
<label>Apercu (<span id="dvFileCount">0</span> pas de temps charges)</label>
|
| 469 |
+
<textarea id="dvFileData" rows="4" readonly style="background: #0f3460;"></textarea>
|
| 470 |
+
</div>
|
| 471 |
+
</div>
|
| 472 |
+
</div>
|
| 473 |
+
|
| 474 |
+
<div class="panel">
|
| 475 |
+
<h2 class="section-title">Parametres du critere</h2>
|
| 476 |
+
<div class="form-group">
|
| 477 |
+
<label>Parametre a (pente)</label>
|
| 478 |
+
<input type="number" id="dvA" value="0.3" step="0.01">
|
| 479 |
+
</div>
|
| 480 |
+
<div class="form-group">
|
| 481 |
+
<label>Parametre b (limite en MPa)</label>
|
| 482 |
+
<input type="number" id="dvB" value="120.0" step="1">
|
| 483 |
+
</div>
|
| 484 |
+
<button id="dvBtn" onclick="calculateDangVan()" style="width: 100%; margin-top: 20px;">
|
| 485 |
+
Calculer
|
| 486 |
+
</button>
|
| 487 |
+
</div>
|
| 488 |
+
</div>
|
| 489 |
+
|
| 490 |
+
<div id="dvError" class="alert alert-error hidden"></div>
|
| 491 |
+
|
| 492 |
+
<!-- Results -->
|
| 493 |
+
<div id="dvResults" class="hidden">
|
| 494 |
+
<div class="grid-2" style="margin-top: 20px;">
|
| 495 |
+
<div class="result-card">
|
| 496 |
+
<h3>Resultat de l'analyse</h3>
|
| 497 |
+
<table>
|
| 498 |
+
<tr><td>DV_max</td><td><strong id="dvMax">-</strong> MPa</td></tr>
|
| 499 |
+
<tr><td>Marge (b - DV_max)</td><td><strong id="dvMargin">-</strong> MPa</td></tr>
|
| 500 |
+
<tr><td>Verdict</td><td><span id="dvSafe">-</span></td></tr>
|
| 501 |
+
<tr><td>Point critique</td><td>Pas de temps #<span id="dvCritical">-</span></td></tr>
|
| 502 |
+
</table>
|
| 503 |
+
</div>
|
| 504 |
+
<div class="result-card">
|
| 505 |
+
<h3>Interpretation</h3>
|
| 506 |
+
<div id="dvInterpretation" style="color: #aaa; line-height: 1.8;"></div>
|
| 507 |
+
</div>
|
| 508 |
+
</div>
|
| 509 |
+
|
| 510 |
+
<div class="panel" style="margin-top: 20px;">
|
| 511 |
+
<h3 class="section-title">Diagramme de Dang Van</h3>
|
| 512 |
+
<div class="chart-container" style="height: 450px;">
|
| 513 |
+
<canvas id="dvChart"></canvas>
|
| 514 |
+
</div>
|
| 515 |
+
</div>
|
| 516 |
+
</div>
|
| 517 |
+
</div>
|
| 518 |
+
|
| 519 |
+
<script>
|
| 520 |
+
// ============================================
|
| 521 |
+
// NAVIGATION
|
| 522 |
+
// ============================================
|
| 523 |
+
const views = {
|
| 524 |
+
home: { title: '', breadcrumb: '' },
|
| 525 |
+
fenics: { title: 'Simulation FEniCS', breadcrumb: '<span>Accueil</span> / Simulation FEniCS' },
|
| 526 |
+
dangvan: { title: 'Analyse Dang Van', breadcrumb: '<span>Accueil</span> / Analyse Dang Van' }
|
| 527 |
+
};
|
| 528 |
+
|
| 529 |
+
function navigateTo(viewId) {
|
| 530 |
+
// Hide all views
|
| 531 |
+
document.querySelectorAll('.view').forEach(v => v.classList.remove('active'));
|
| 532 |
+
// Show target view
|
| 533 |
+
document.getElementById('view-' + viewId).classList.add('active');
|
| 534 |
+
// Update breadcrumb
|
| 535 |
+
document.getElementById('breadcrumb').innerHTML = views[viewId].breadcrumb;
|
| 536 |
+
// Scroll to top
|
| 537 |
+
window.scrollTo(0, 0);
|
| 538 |
+
// Load data if needed
|
| 539 |
+
if (viewId === 'fenics') loadSimulations();
|
| 540 |
+
}
|
| 541 |
+
|
| 542 |
+
// ============================================
|
| 543 |
+
// GLOBALS
|
| 544 |
+
// ============================================
|
| 545 |
+
const API_URL = '/api';
|
| 546 |
+
let timeChart = null;
|
| 547 |
+
let dvChart = null;
|
| 548 |
+
let animationId = null;
|
| 549 |
+
let animFrame = 0;
|
| 550 |
+
let animData = [];
|
| 551 |
+
let isAnimating = false;
|
| 552 |
+
let animFrameImages = [];
|
| 553 |
+
let useImageFrames = false;
|
| 554 |
+
let dvStressFromFile = null;
|
| 555 |
+
|
| 556 |
+
// ============================================
|
| 557 |
+
// FENICS SIMULATION
|
| 558 |
+
// ============================================
|
| 559 |
+
async function loadSimulations() {
|
| 560 |
+
try {
|
| 561 |
+
const res = await fetch(API_URL + '/simulations/');
|
| 562 |
+
if (!res.ok) throw new Error('Erreur serveur: ' + res.status);
|
| 563 |
+
const data = await res.json();
|
| 564 |
+
const tbody = document.getElementById('simTable');
|
| 565 |
+
if (data.length === 0) {
|
| 566 |
+
tbody.innerHTML = '<tr><td colspan="4">Aucune simulation</td></tr>';
|
| 567 |
+
} else {
|
| 568 |
+
tbody.innerHTML = data.slice(0, 10).map(sim => {
|
| 569 |
+
const badge = sim.status === 'completed' ? 'badge-success' :
|
| 570 |
+
sim.status === 'running' ? 'badge-warning' : 'badge-danger';
|
| 571 |
+
return `<tr onclick="showResults(${sim.id})" style="cursor:pointer">
|
| 572 |
+
<td>#${sim.id}</td>
|
| 573 |
+
<td>${sim.name || 'Sans nom'}</td>
|
| 574 |
+
<td><span class="badge ${badge}">${sim.status}</span></td>
|
| 575 |
+
<td>${new Date(sim.created_at).toLocaleDateString()}</td>
|
| 576 |
+
</tr>`;
|
| 577 |
+
}).join('');
|
| 578 |
+
}
|
| 579 |
+
} catch (err) {
|
| 580 |
+
document.getElementById('simTable').innerHTML = `<tr><td colspan="4" class="alert-error">${err.message}</td></tr>`;
|
| 581 |
+
}
|
| 582 |
+
}
|
| 583 |
+
|
| 584 |
+
async function showResults(id) {
|
| 585 |
+
try {
|
| 586 |
+
const res = await fetch(API_URL + '/simulations/' + id + '/');
|
| 587 |
+
if (!res.ok) throw new Error('Erreur serveur');
|
| 588 |
+
const sim = await res.json();
|
| 589 |
+
|
| 590 |
+
if (sim.status !== 'completed') {
|
| 591 |
+
alert('Simulation non terminee (status: ' + sim.status + ')');
|
| 592 |
+
return;
|
| 593 |
+
}
|
| 594 |
+
if (!sim.result_summary) {
|
| 595 |
+
alert('Pas de resultats disponibles');
|
| 596 |
+
return;
|
| 597 |
+
}
|
| 598 |
+
|
| 599 |
+
document.getElementById('resultSection').classList.remove('hidden');
|
| 600 |
+
document.getElementById('resultId').textContent = sim.id;
|
| 601 |
+
document.getElementById('resultMax').textContent = (sim.result_summary.final_max || 0).toFixed(4);
|
| 602 |
+
document.getElementById('resultMean').textContent = (sim.result_summary.final_mean || 0).toFixed(4);
|
| 603 |
+
|
| 604 |
+
animData = sim.result_summary.time_series || [];
|
| 605 |
+
updateTimeChart(animData);
|
| 606 |
+
resetAnimation();
|
| 607 |
+
|
| 608 |
+
document.getElementById('resultSection').scrollIntoView({ behavior: 'smooth' });
|
| 609 |
+
} catch (err) {
|
| 610 |
+
alert('Erreur: ' + err.message);
|
| 611 |
+
}
|
| 612 |
+
}
|
| 613 |
+
|
| 614 |
+
function closeResults() {
|
| 615 |
+
document.getElementById('resultSection').classList.add('hidden');
|
| 616 |
+
stopAnimation();
|
| 617 |
+
}
|
| 618 |
+
|
| 619 |
+
function updateTimeChart(data) {
|
| 620 |
+
const ctx = document.getElementById('timeChart').getContext('2d');
|
| 621 |
+
if (timeChart) timeChart.destroy();
|
| 622 |
+
if (!data || data.length === 0) return;
|
| 623 |
+
|
| 624 |
+
timeChart = new Chart(ctx, {
|
| 625 |
+
type: 'line',
|
| 626 |
+
data: {
|
| 627 |
+
labels: data.map(d => (d.time || 0).toFixed(2)),
|
| 628 |
+
datasets: [{
|
| 629 |
+
label: 'Maximum',
|
| 630 |
+
data: data.map(d => d.max || 0),
|
| 631 |
+
borderColor: '#00d4ff',
|
| 632 |
+
backgroundColor: 'rgba(0, 212, 255, 0.1)',
|
| 633 |
+
fill: true,
|
| 634 |
+
tension: 0.3
|
| 635 |
+
}, {
|
| 636 |
+
label: 'Moyenne',
|
| 637 |
+
data: data.map(d => d.mean || 0),
|
| 638 |
+
borderColor: '#ff6b6b',
|
| 639 |
+
backgroundColor: 'rgba(255, 107, 107, 0.1)',
|
| 640 |
+
fill: true,
|
| 641 |
+
tension: 0.3
|
| 642 |
+
}]
|
| 643 |
+
},
|
| 644 |
+
options: {
|
| 645 |
+
responsive: true,
|
| 646 |
+
maintainAspectRatio: false,
|
| 647 |
+
plugins: { legend: { labels: { color: '#fff' } } },
|
| 648 |
+
scales: {
|
| 649 |
+
x: { ticks: { color: '#888' }, grid: { color: 'rgba(255,255,255,0.1)' }, title: { display: true, text: 'Temps (s)', color: '#00d4ff' } },
|
| 650 |
+
y: { ticks: { color: '#888' }, grid: { color: 'rgba(255,255,255,0.1)' }, title: { display: true, text: 'Valeur', color: '#00d4ff' } }
|
| 651 |
+
}
|
| 652 |
+
}
|
| 653 |
+
});
|
| 654 |
+
}
|
| 655 |
+
|
| 656 |
+
// Animation
|
| 657 |
+
function stopAnimation() {
|
| 658 |
+
if (animationId) cancelAnimationFrame(animationId);
|
| 659 |
+
isAnimating = false;
|
| 660 |
+
}
|
| 661 |
+
|
| 662 |
+
function playAnimation() {
|
| 663 |
+
if (animData.length === 0) return;
|
| 664 |
+
isAnimating = true;
|
| 665 |
+
animate();
|
| 666 |
+
}
|
| 667 |
+
|
| 668 |
+
function pauseAnimation() { isAnimating = false; }
|
| 669 |
+
|
| 670 |
+
function resetAnimation() {
|
| 671 |
+
stopAnimation();
|
| 672 |
+
animFrame = 0;
|
| 673 |
+
drawHeatmap(null);
|
| 674 |
+
document.getElementById('animTime').textContent = '0.00';
|
| 675 |
+
document.getElementById('animTotal').textContent = animData.length > 0 ? (animData[animData.length-1].time || 0).toFixed(2) : '0.00';
|
| 676 |
+
}
|
| 677 |
+
|
| 678 |
+
function animate() {
|
| 679 |
+
if (!isAnimating || animFrame >= animData.length) {
|
| 680 |
+
isAnimating = false;
|
| 681 |
+
return;
|
| 682 |
+
}
|
| 683 |
+
const frameData = animData[animFrame];
|
| 684 |
+
drawHeatmap(frameData);
|
| 685 |
+
document.getElementById('animTime').textContent = (frameData.time || 0).toFixed(2);
|
| 686 |
+
animFrame++;
|
| 687 |
+
animationId = requestAnimationFrame(() => setTimeout(animate, 100));
|
| 688 |
+
}
|
| 689 |
+
|
| 690 |
+
function drawHeatmap(frameData) {
|
| 691 |
+
const canvas = document.getElementById('animationCanvas');
|
| 692 |
+
const ctx = canvas.getContext('2d');
|
| 693 |
+
const size = canvas.width;
|
| 694 |
+
const gridSize = 32;
|
| 695 |
+
const cellSize = size / gridSize;
|
| 696 |
+
|
| 697 |
+
ctx.fillStyle = '#1a1a2e';
|
| 698 |
+
ctx.fillRect(0, 0, size, size);
|
| 699 |
+
|
| 700 |
+
if (!frameData) {
|
| 701 |
+
ctx.fillStyle = '#888';
|
| 702 |
+
ctx.font = '14px sans-serif';
|
| 703 |
+
ctx.textAlign = 'center';
|
| 704 |
+
ctx.fillText('Cliquez Play pour demarrer', size/2, size/2);
|
| 705 |
+
return;
|
| 706 |
+
}
|
| 707 |
+
|
| 708 |
+
const maxVal = Math.max(...animData.map(d => d.max || 0.001));
|
| 709 |
+
for (let i = 0; i < gridSize; i++) {
|
| 710 |
+
for (let j = 0; j < gridSize; j++) {
|
| 711 |
+
const distance = Math.sqrt((i - gridSize/2)**2 + (j - gridSize/2)**2);
|
| 712 |
+
const normalizedDist = Math.min(distance / (gridSize/2), 1);
|
| 713 |
+
const heatValue = Math.max(0, 1 - normalizedDist) * ((frameData.max || 0) / maxVal);
|
| 714 |
+
const r = Math.floor(255 * heatValue);
|
| 715 |
+
const g = Math.floor(100 * heatValue);
|
| 716 |
+
const b = Math.floor(255 * (1 - heatValue));
|
| 717 |
+
ctx.fillStyle = `rgb(${r},${g},${b})`;
|
| 718 |
+
ctx.fillRect(j * cellSize, (gridSize - 1 - i) * cellSize, cellSize, cellSize);
|
| 719 |
+
}
|
| 720 |
+
}
|
| 721 |
+
}
|
| 722 |
+
|
| 723 |
+
// Form submission
|
| 724 |
+
document.getElementById('simForm').addEventListener('submit', async (e) => {
|
| 725 |
+
e.preventDefault();
|
| 726 |
+
const btn = document.getElementById('submitBtn');
|
| 727 |
+
const errDiv = document.getElementById('formError');
|
| 728 |
+
errDiv.classList.add('hidden');
|
| 729 |
+
btn.disabled = true;
|
| 730 |
+
btn.textContent = 'Calcul en cours...';
|
| 731 |
+
|
| 732 |
+
const params = {
|
| 733 |
+
mesh_resolution: parseInt(document.getElementById('meshResolution').value),
|
| 734 |
+
diffusion_coefficient: parseFloat(document.getElementById('diffCoef').value),
|
| 735 |
+
source_term: parseFloat(document.getElementById('sourceTerm').value),
|
| 736 |
+
time_final: parseFloat(document.getElementById('timeFinal').value),
|
| 737 |
+
num_steps: parseInt(document.getElementById('numSteps').value)
|
| 738 |
+
};
|
| 739 |
+
|
| 740 |
+
try {
|
| 741 |
+
const res = await fetch(API_URL + '/simulations/', {
|
| 742 |
+
method: 'POST',
|
| 743 |
+
headers: { 'Content-Type': 'application/json' },
|
| 744 |
+
body: JSON.stringify({ name: document.getElementById('simName').value || 'Simulation', parameters: params })
|
| 745 |
+
});
|
| 746 |
+
if (!res.ok) throw new Error('Erreur creation: ' + res.status);
|
| 747 |
+
|
| 748 |
+
btn.textContent = 'Simulation lancee!';
|
| 749 |
+
setTimeout(() => {
|
| 750 |
+
loadSimulations();
|
| 751 |
+
btn.disabled = false;
|
| 752 |
+
btn.textContent = 'Lancer la simulation';
|
| 753 |
+
}, 1500);
|
| 754 |
+
} catch (err) {
|
| 755 |
+
errDiv.textContent = err.message;
|
| 756 |
+
errDiv.classList.remove('hidden');
|
| 757 |
+
btn.disabled = false;
|
| 758 |
+
btn.textContent = 'Lancer la simulation';
|
| 759 |
+
}
|
| 760 |
+
});
|
| 761 |
+
|
| 762 |
+
// ============================================
|
| 763 |
+
// DANG VAN
|
| 764 |
+
// ============================================
|
| 765 |
+
function switchDvTab(tab) {
|
| 766 |
+
document.querySelectorAll('.tabs .tab').forEach(t => t.classList.remove('active'));
|
| 767 |
+
document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
|
| 768 |
+
|
| 769 |
+
if (tab === 'json') {
|
| 770 |
+
document.querySelector('.tabs .tab:first-child').classList.add('active');
|
| 771 |
+
document.getElementById('dvTabJson').classList.add('active');
|
| 772 |
+
dvStressFromFile = null;
|
| 773 |
+
} else {
|
| 774 |
+
document.querySelector('.tabs .tab:last-child').classList.add('active');
|
| 775 |
+
document.getElementById('dvTabFile').classList.add('active');
|
| 776 |
+
}
|
| 777 |
+
}
|
| 778 |
+
|
| 779 |
+
function parseStressFile(content) {
|
| 780 |
+
const lines = content.trim().split('\n');
|
| 781 |
+
const data = [];
|
| 782 |
+
for (let line of lines) {
|
| 783 |
+
line = line.trim();
|
| 784 |
+
if (!line || line.startsWith('#') || line.startsWith('//') || line.match(/^[a-zA-Z]/)) continue;
|
| 785 |
+
let values;
|
| 786 |
+
if (line.includes(',')) values = line.split(',');
|
| 787 |
+
else if (line.includes(';')) values = line.split(';');
|
| 788 |
+
else if (line.includes('\t')) values = line.split('\t');
|
| 789 |
+
else values = line.split(/\s+/);
|
| 790 |
+
const nums = values.map(v => parseFloat(v.trim())).filter(n => !isNaN(n));
|
| 791 |
+
if (nums.length >= 6) data.push(nums.slice(0, 6));
|
| 792 |
+
}
|
| 793 |
+
return data;
|
| 794 |
+
}
|
| 795 |
+
|
| 796 |
+
document.getElementById('dvFile').addEventListener('change', async (e) => {
|
| 797 |
+
const file = e.target.files[0];
|
| 798 |
+
if (!file) return;
|
| 799 |
+
try {
|
| 800 |
+
const content = await file.text();
|
| 801 |
+
const parsed = parseStressFile(content);
|
| 802 |
+
if (parsed.length === 0) {
|
| 803 |
+
alert('Aucune donnee valide trouvee');
|
| 804 |
+
return;
|
| 805 |
+
}
|
| 806 |
+
dvStressFromFile = parsed;
|
| 807 |
+
document.getElementById('dvFilePreview').classList.remove('hidden');
|
| 808 |
+
document.getElementById('dvFileCount').textContent = parsed.length;
|
| 809 |
+
document.getElementById('dvFileData').value = parsed.slice(0, 5).map(r => r.map(v => v.toFixed(1)).join(', ')).join('\n') + (parsed.length > 5 ? '\n...' : '');
|
| 810 |
+
} catch (err) {
|
| 811 |
+
alert('Erreur lecture: ' + err.message);
|
| 812 |
+
}
|
| 813 |
+
});
|
| 814 |
+
|
| 815 |
+
async function calculateDangVan() {
|
| 816 |
+
const btn = document.getElementById('dvBtn');
|
| 817 |
+
const errDiv = document.getElementById('dvError');
|
| 818 |
+
errDiv.classList.add('hidden');
|
| 819 |
+
btn.disabled = true;
|
| 820 |
+
btn.textContent = 'Calcul en cours...';
|
| 821 |
+
|
| 822 |
+
let stress;
|
| 823 |
+
const jsonTab = document.getElementById('dvTabJson').classList.contains('active');
|
| 824 |
+
|
| 825 |
+
if (jsonTab) {
|
| 826 |
+
try {
|
| 827 |
+
const raw = document.getElementById('dvStress').value.trim();
|
| 828 |
+
if (!raw) throw new Error('Entrez des donnees JSON');
|
| 829 |
+
stress = JSON.parse(raw);
|
| 830 |
+
} catch (e) {
|
| 831 |
+
errDiv.textContent = 'JSON invalide: ' + e.message;
|
| 832 |
+
errDiv.classList.remove('hidden');
|
| 833 |
+
btn.disabled = false;
|
| 834 |
+
btn.textContent = 'Calculer';
|
| 835 |
+
return;
|
| 836 |
+
}
|
| 837 |
+
} else {
|
| 838 |
+
if (!dvStressFromFile || dvStressFromFile.length === 0) {
|
| 839 |
+
errDiv.textContent = 'Chargez un fichier CSV/TXT valide';
|
| 840 |
+
errDiv.classList.remove('hidden');
|
| 841 |
+
btn.disabled = false;
|
| 842 |
+
btn.textContent = 'Calculer';
|
| 843 |
+
return;
|
| 844 |
+
}
|
| 845 |
+
stress = dvStressFromFile;
|
| 846 |
+
}
|
| 847 |
+
|
| 848 |
+
const a = parseFloat(document.getElementById('dvA').value);
|
| 849 |
+
const b = parseFloat(document.getElementById('dvB').value);
|
| 850 |
+
|
| 851 |
+
try {
|
| 852 |
+
const res = await fetch(API_URL + '/dangvan/', {
|
| 853 |
+
method: 'POST',
|
| 854 |
+
headers: { 'Content-Type': 'application/json' },
|
| 855 |
+
body: JSON.stringify({ stress_series: stress, a, b })
|
| 856 |
+
});
|
| 857 |
+
const data = await res.json();
|
| 858 |
+
if (!res.ok) throw new Error(data.error || 'Erreur serveur');
|
| 859 |
+
|
| 860 |
+
displayDangVanResults(data);
|
| 861 |
+
} catch (err) {
|
| 862 |
+
errDiv.textContent = err.message;
|
| 863 |
+
errDiv.classList.remove('hidden');
|
| 864 |
+
} finally {
|
| 865 |
+
btn.disabled = false;
|
| 866 |
+
btn.textContent = 'Calculer';
|
| 867 |
+
}
|
| 868 |
+
}
|
| 869 |
+
|
| 870 |
+
function displayDangVanResults(data) {
|
| 871 |
+
document.getElementById('dvResults').classList.remove('hidden');
|
| 872 |
+
document.getElementById('dvMax').textContent = data.dv_max.toFixed(2);
|
| 873 |
+
document.getElementById('dvMargin').textContent = data.margin.toFixed(2);
|
| 874 |
+
document.getElementById('dvCritical').textContent = data.index_max;
|
| 875 |
+
|
| 876 |
+
const safeEl = document.getElementById('dvSafe');
|
| 877 |
+
const interpEl = document.getElementById('dvInterpretation');
|
| 878 |
+
|
| 879 |
+
if (data.safe) {
|
| 880 |
+
safeEl.innerHTML = '<span class="dv-safe">SECURITE OK</span>';
|
| 881 |
+
interpEl.innerHTML = `
|
| 882 |
+
<p>La piece est <strong style="color:#00c853">securisee</strong> vis-a-vis de la fatigue multiaxiale.</p>
|
| 883 |
+
<p>Tous les points de chargement se situent sous la droite de Dang Van.</p>
|
| 884 |
+
<p>Marge de securite: <strong>${data.margin.toFixed(2)} MPa</strong></p>
|
| 885 |
+
`;
|
| 886 |
+
} else {
|
| 887 |
+
safeEl.innerHTML = '<span class="dv-unsafe">RISQUE DE FATIGUE</span>';
|
| 888 |
+
interpEl.innerHTML = `
|
| 889 |
+
<p>La piece presente un <strong style="color:#ff1744">risque de fatigue</strong>.</p>
|
| 890 |
+
<p>Un ou plusieurs points de chargement depassent la limite de Dang Van.</p>
|
| 891 |
+
<p>Depassement maximal: <strong>${Math.abs(data.margin).toFixed(2)} MPa</strong> au pas de temps #${data.index_max}</p>
|
| 892 |
+
`;
|
| 893 |
+
}
|
| 894 |
+
|
| 895 |
+
updateDvChart(data);
|
| 896 |
+
document.getElementById('dvResults').scrollIntoView({ behavior: 'smooth' });
|
| 897 |
+
}
|
| 898 |
+
|
| 899 |
+
function updateDvChart(data) {
|
| 900 |
+
const ctx = document.getElementById('dvChart').getContext('2d');
|
| 901 |
+
if (dvChart) dvChart.destroy();
|
| 902 |
+
|
| 903 |
+
const points = data.points || [];
|
| 904 |
+
const criterionLine = data.criterion_line || [];
|
| 905 |
+
|
| 906 |
+
const scatterData = points.map(p => ({ x: p.sigma_H, y: p.tau_max }));
|
| 907 |
+
const lineData = criterionLine.map(p => ({ x: p.sigma_H, y: p.tau }));
|
| 908 |
+
|
| 909 |
+
// Find safe/unsafe points
|
| 910 |
+
const safePoints = points.filter(p => p.dv <= data.b).map(p => ({ x: p.sigma_H, y: p.tau_max }));
|
| 911 |
+
const unsafePoints = points.filter(p => p.dv > data.b).map(p => ({ x: p.sigma_H, y: p.tau_max }));
|
| 912 |
+
|
| 913 |
+
dvChart = new Chart(ctx, {
|
| 914 |
+
type: 'scatter',
|
| 915 |
+
data: {
|
| 916 |
+
datasets: [
|
| 917 |
+
{
|
| 918 |
+
label: 'Points securises',
|
| 919 |
+
data: safePoints,
|
| 920 |
+
backgroundColor: '#00c853',
|
| 921 |
+
borderColor: '#00c853',
|
| 922 |
+
pointRadius: 6,
|
| 923 |
+
pointHoverRadius: 8
|
| 924 |
+
},
|
| 925 |
+
{
|
| 926 |
+
label: 'Points critiques',
|
| 927 |
+
data: unsafePoints,
|
| 928 |
+
backgroundColor: '#ff1744',
|
| 929 |
+
borderColor: '#ff1744',
|
| 930 |
+
pointRadius: 6,
|
| 931 |
+
pointHoverRadius: 8
|
| 932 |
+
},
|
| 933 |
+
{
|
| 934 |
+
label: `Limite: τ = ${data.b} - ${data.a}·σH`,
|
| 935 |
+
data: lineData,
|
| 936 |
+
type: 'line',
|
| 937 |
+
borderColor: '#ffab00',
|
| 938 |
+
borderWidth: 3,
|
| 939 |
+
borderDash: [8, 4],
|
| 940 |
+
fill: false,
|
| 941 |
+
pointRadius: 0
|
| 942 |
+
}
|
| 943 |
+
]
|
| 944 |
+
},
|
| 945 |
+
options: {
|
| 946 |
+
responsive: true,
|
| 947 |
+
maintainAspectRatio: false,
|
| 948 |
+
plugins: {
|
| 949 |
+
legend: { labels: { color: '#fff', font: { size: 12 } } },
|
| 950 |
+
title: { display: true, text: 'Diagramme de Dang Van (τ_max vs σ_H)', color: '#00d4ff', font: { size: 16 } }
|
| 951 |
+
},
|
| 952 |
+
scales: {
|
| 953 |
+
x: {
|
| 954 |
+
type: 'linear',
|
| 955 |
+
ticks: { color: '#888' },
|
| 956 |
+
grid: { color: 'rgba(255,255,255,0.1)' },
|
| 957 |
+
title: { display: true, text: 'Pression hydrostatique σH (MPa)', color: '#00d4ff', font: { size: 14 } }
|
| 958 |
+
},
|
| 959 |
+
y: {
|
| 960 |
+
ticks: { color: '#888' },
|
| 961 |
+
grid: { color: 'rgba(255,255,255,0.1)' },
|
| 962 |
+
title: { display: true, text: 'Cisaillement max τ_max (MPa)', color: '#00d4ff', font: { size: 14 } }
|
| 963 |
+
}
|
| 964 |
+
}
|
| 965 |
+
}
|
| 966 |
+
});
|
| 967 |
+
}
|
| 968 |
+
|
| 969 |
+
// ============================================
|
| 970 |
+
// INIT
|
| 971 |
+
// ============================================
|
| 972 |
+
console.log('SimSite loaded');
|
| 973 |
+
</script>
|
| 974 |
+
</body>
|
| 975 |
+
</html>
|