Convert XML scenes to Python scripts and integrate FreeFem simulations with SOFA comparison#3
Convert XML scenes to Python scripts and integrate FreeFem simulations with SOFA comparison#3Fimache wants to merge 3 commits intomain-freefem-sofafrom
Conversation
|
You will need to base this on the |
There was a problem hiding this comment.
Some changes need to be done. My recommendation for this PR is that it only covers the conversion of xml files to python. Let's do the comparison as a next step.
-
It is better if we don't dump the new files at the top of the repository. Move
barre_1d_pyfreefem.pyand the others insideexamples/FreeFEM/. -
beam_2d_sofa.pyruns a simulation replicatingexamples/FreeFEM/beam-2d.scn.barre_1d_sofa.pydoes not. It does not in fact load nor run any SOFA scene. -
All the files in
examples/FreeFEM/*.edpare duplicates ofexamples/FreeFEM/edp. So we should only keep one of them.
For me, this PR should only contain 2 new files: the xml files in examples/FreeFEM/sofa/ converted to SofaPython scripts. So,
examples/FreeFEM/sofa/barre-traction.scn->examples/FreeFEM/sofa/barre-traction.pyexamples/FreeFEM/sofa/beam-2d.scn->examples/FreeFEM/sofa/beam-2d.py
I suggest you keep the same names between the files. It becomes straightforward to understand the conversion.
Use the information here: https://sofapython3.readthedocs.io/en/latest/content/FirstSteps.html#executing-a-simulation
to help you
comparaison.py
Outdated
| """ | ||
| POURQUOI ON PEUT COMPARER LES DEUX CODES MALGRÉ DES MAILLAGES DIFFÉRENTS ? | ||
| =========================================================================== | ||
|
|
||
| PROBLÈME DE DÉPART : | ||
| • FreeFEM génère un maillage triangulaire NON-STRUCTURÉ avec ~4800 nœuds. | ||
| Les nœuds sont placés de façon irrégulière, denses là où le gradient est | ||
| fort (encastrement gauche), plus rares au centre. | ||
|
|
||
| • SOFA utilise une RegularGridTopology 11×4 = 44 nœuds seulement, | ||
| placés sur une grille parfaitement régulière. | ||
| Les lignes y sont : 0.0, 0.67, 1.33, 2.0 | ||
| → aucun nœud à y = 1.0 exactement ! | ||
|
|
||
| SOLUTION — LA GRILLE COMMUNE : | ||
| 1. On crée une grille uniforme 300×80 = 24 000 points couvrant [0,10]×[0,2]. | ||
| 2. On interpole chaque champ (ux, uy) sur cette grille depuis les nœuds bruts : | ||
| - FreeFEM : scipy.griddata(..., method='linear') | ||
| → triangulation Delaunay + interpolation linéaire par morceaux (P1) | ||
| → très fidèle car maillage dense | ||
| - SOFA : scipy.griddata(..., method='cubic') | ||
| → interpolation cubique car 44 points sont trop peu pour 'linear' | ||
| → lisse le champ entre les nœuds réguliers | ||
|
|
||
| 3. Une fois les deux champs sur la même grille, on peut : | ||
| diff[i,j] = SOFA_interpolé[i,j] - FreeFEM_interpolé[i,j] | ||
| et calculer RMSE, erreur relative, histogrammes, etc. | ||
|
|
||
| POURQUOI LA COMPARAISON A DU SENS ? | ||
| Les deux codes résolvent la MÊME équation (élasticité linéaire plane, | ||
| même E, nu, gravité, encastrement gauche). La différence vient de : | ||
| a) La formulation : plane_strain (Vec3, λ=Eν/((1+ν)(1-2ν))) vs | ||
| les coefficients Lamé 3D de FreeFEM (identiques à plane_strain) | ||
| b) La discrétisation : triangles P1 vs Q1 subdivisé en triangles | ||
| c) Le nombre de DDL : 44 nœuds SOFA << 4814 nœuds FreeFEM | ||
| → SOFA est moins précis, mais donne la bonne tendance physique. | ||
|
|
||
| Le tableau récapitulatif vous donne l'écart % entre les deux pour | ||
| chaque quantité d'intérêt (flèche maximale, RMSE, erreur médiane...). | ||
| """ No newline at end of file |
There was a problem hiding this comment.
This is what I want us to avoid doing. For this reason, we will use a mesh that is shared among the two scripts (SOFA vs FreeFEM). We are introducing another factor with the interpolation, the effect of which we are not quantifying.
Will be added in subsequent PRs.
comparaison.py
Outdated
| Usage : | ||
| python compare_freefem_sofa_complet.py | ||
|
|
||
| Fichiers requis (même dossier) : |
There was a problem hiding this comment.
This whole file simply compares the results of two simulations. We don't want that.
Also, the usage instruction references another file.
| ax.set_title("Déplacement axial — Barre 1D (charge uniforme)") | ||
| ax.legend() | ||
| ax.grid(True, alpha=0.3) | ||
|
|
There was a problem hiding this comment.
This file is just a copy of barre_1d_pyfreefem.py with some added lines to load some sofa results. It is not a converted file, from xml to python.
- Convert beam-2d.scn to beam-2d.py - Convert barre-traction.scn to barre-traction.py - Place scripts in examples/Freefem/sofa/ - Remove comparison scripts and duplicate .edp files (to be added in next PR)
This PR adds Python scripts to convert XML scenes to Python and integrate FreeFem simulations with SOFA framework.
The comparison script analyzes both simulation outputs and provides: