# SU2 CFD

SU2 is a separate draggable thumbnail in the CFD pane. It opens `Pages/SU2.html`
with a detached aircraft geometry snapshot, takeoff CG and reference dimensions.
It uses SU2 8.5.0, pinned to the upstream Linux OpenMP release with SHA-256
`aadc800cd9df34deff99d4725f5897f620c9f2979f62ab235313311bf501f09b`.
Gmsh 4.15.2 generates the surrounding tetrahedral volume mesh.

## Supported analysis

The initial integration runs compressible Euler with slip walls, Mach 0.05–2.0,
alpha ±20 deg and beta ±15 deg. All solver coordinates and dimensional quantities
are SI; the page presents geometry in feet, area in ft² and angles in deg.
Axes are X aft, Y right, Z up. Reference area and chord are editable; SU2 uses
the reference chord for all three moment coefficients. Altitude sets a standard
atmosphere. This is a single-condition solve, not a parameter sweep.

First-order Roe is the robust default. Second-order MUSCL is selectable, but
needs mesh/convergence checks and can fail to converge on coarse meshes. Density
residual target and iteration limit are explicit. Completing the iteration limit
does not establish convergence. Convergence here means reaching the density
residual target; it does not establish mesh independence or engineering accuracy.
Euler excludes skin-friction drag, boundary layers and stall. Engine ducts are
passive openings with no mass-flow or propulsion source. RANS is not exposed;
it requires a suitable boundary-layer mesh workflow.

## Geometry and pressure transfer

The shared CFD CAD union and engine subtraction supply a closed surface.
An SU2-specific worker removes slivers with Manifold's 0.01-inch simplification
tolerance. This bounded geometry approximation is displayed on the page and
does not modify the original aircraft. Gmsh retains those prepared wall facets
and meshes only the fluid volume. Its facet-overlap angle tolerance is 0.001 deg
to accommodate thin trailing edges; actual intersecting facets still fail.
Near-body volume size does not retessellate the wall. Far-field half-width is
5–30 maximum aircraft dimensions. Meshing complex or intersecting aircraft
surfaces can fail and is reported as a failed job, without fabricated results.

SU2 writes full surface CSV primitive fields. The adapter matches wall vertices
within a relative 1e-6 coordinate tolerance and averages their Cp over each
prepared triangle. Missing matches and nonfinite coefficients/pressures fail.
Pressure plots use these computed values. Result files contain the exact case,
source checksum, case checksum, result and plot label state. The common FEA
importer recognizes the SU2 schema and uses the existing pressure-strip mapping,
geometry checks and force/moment conservation. It rejects unconverged SU2 results.
Existing right-wing-only and vertical-force/pitch-couple transfer limits apply.

## Saved results and host binding

The `su2` manifest declares geometry input through the existing aerodynamic
geometry selector and only `/SU2` as an aircraft output. The host checks project
identity, input signature, revision and output permissions before saving.
The aircraft dictionary stores conditions, coefficients, convergence history,
mesh counts and plot presentation. Full wall pressures remain in the separate
Save Results for FEA file. Reopening the widget restores the compact summary;
reload the pressure result file to restore its full map. Save As is used for
both exports. Neither plotting nor moving labels invokes the solver.

## Service and deployment

The dedicated service listens on loopback port 8776 and shares the existing
solver job store, session ownership, idempotency, cancellation and six-hour
retention mechanisms. Structured cases are limited to 20 MB, 100,000 vertices,
200,000 surface triangles, 1.5 million volume cells and 10,000 iterations.
One job runs at a time, with a one-hour timeout, two CPU threads and a 2.5 GB
systemd memory limit. Browser clients cannot submit decks, filenames or commands.
The same-origin PHP gateway keeps the VPS credential on the server.

`scripts/deploy-su2-cloud.ps1` installs the pinned runtime, verifies a synthetic
native sphere job and owner isolation, validates the new `/su2/` HTTPS route,
and merges only private `su2_endpoint` / `su2_token` website settings. Existing
solver routes remain in place. The standard website preparation workflow detects
future SU2 source changes after its first verified deployment. Website publishing
is a separate action.

Local use requires SU2 8.5.0 and Python with Gmsh 4.15.2, NumPy and SciPy:

```text
python scripts/su2-server.py --solver /absolute/path/to/SU2_CFD --allow-origin http://127.0.0.1:8767
```

## Verification

`tests/su2.test.mjs` covers saved-file checksums, pressure reference checks,
convergence gating, compact host writes and endpoint selection. `tests/test_su2.py`
covers closed topology, input bounds and configuration generation.
`scripts/check-su2.cjs` uses real browser CAD preparation with a synthetic solver
response to check launch/handoff, cancellation, plots, host saves and exports.
`scripts/su2-smoke.py` runs native SU2 on a synthetic closed sphere through the
service, checking convergence, finite wall pressures, idempotency and ownership.
This smoke test is not an aerodynamic accuracy validation.

Primary references: https://github.com/su2code/SU2/releases/tag/v8.5.0,
https://su2code.github.io/docs_v7/Custom-Output/ and
https://gmsh.info/doc/texinfo/.

## Cloud SU2 from a local preview
`preview-server.py` handles `/CLOUD/su2-api.php` (including the repository-root
`/JETcentral/CLOUD/` prefix) directly for same-origin loopback browser requests.
It reads `_private/jetcentral-su2-settings.php` created by the cloud deployment,
keeps the VPS token server-side, and forwards health, submit, status and cancel
with a separate HttpOnly preview-session owner. Cloud execution from localhost
does not require PHP or a local SU2 installation. Restart an already running
preview server after updating its Python source. The separate Local execution
choice still connects to the local SU2 helper on port 8776.

## Rebuilt surface import
The Aircraft panel accepts `jetcentral-su2-surface-1` bundles containing a validated SU2 `case`, its SHA-256 `caseHash`, and `quality.sampledMaxDeviationM` (metres). Import requires an exact source-aircraft hash match, a valid checksum, nondegenerate faces and closed oriented edges. The page replaces only the analysis mesh and invalidates prior results. Undo restores the original CAD mesh. The same rebuilt geometry is submitted, displayed and saved with pressures; sampled deviation metadata is retained in the saved case. This import does not certify intersection freedom, convergence or aerodynamic accuracy. Geometry changes require a new repair. Aircraft-specific repairs remain outside the website bundle.
