# waterfall

Quick CFD Estimator (estimator-grade, not a solver). This script is designed for fast
iteration and comparative design intuition rather than physically accurate CFD.

## What it does
- Loads an STL mesh and slices it along the Z axis.
- Samples surface normals on a regular grid per slice and estimates curvature relative
  to the flow direction.
- Propagates a persistent ray field through slices to derive pressure, velocity, and
  drag proxy metrics.
- Writes text matrices and heatmap images per slice, plus a JSON summary.

## Configuration
Edit `config.json` before running:
- `stl_path`: Path to the STL file.
- `slice_depth`: Thickness of each Z slice.
- `r1_resolution`, `r2_resolution`: Grid resolution across X/Y for each slice
  (must be at least 2).
- `output_path`: Output directory for results.
- `flow_direction` (optional): 3-element vector for incoming flow direction.
  Defaults to `[0, 0, 1]`.
- `ray_weight` (optional): Scalar weight per ray cell (defaults to `1.0`).
- `airspeed`: Flow speed in meters per second.
- `air_density`: Air density in kg/m^3.
- `units`: Label for your geometry units (`m`, `cm`, `mm`, `in`, or `ft`).

Example:
```json
{
  "stl_path": "model.STL",
  "units": "mm",
  "slice_depth": 50,
  "r1_resolution": 30,
  "r2_resolution": 30,
  "airspeed": 30,
  "air_density": 1.225,
  "output_path": "./output",
  "flow_direction": [0, 0, 1],
  "ray_weight": 1.0
}
```

## Usage
Install dependencies (Python 3.10+ recommended):
```bash
pip install numpy trimesh matplotlib rtree scipy
```

Run:
```bash
python main.py
```

## Outputs
For each slice `N`, the script writes:
- `slice_N_pressure.txt`
- `slice_N_velocity.txt`
- `slice_N_drag.txt`
- `slice_N_pressure.png`
- `slice_N_velocity.png`
- `slice_N_drag.png`

It also writes `summary.txt` containing a JSON payload with metadata such as the total
drag metric, force proxy values, slice count, resolutions, STL path, and flow direction.

Console output includes proxy values for drag, lift, and downforce (negative lift), all
reported as estimator-grade metrics. Forces are reported in Newtons using the
dynamic pressure (`0.5 * air_density * airspeed^2`) times each cell area, with optional
`ray_weight` scaling. Drag/lift coefficients are reported as:
`C = Force / (dynamic_pressure * reference_area)`.

## Notes / limitations
- This is an estimator, not a physics-accurate CFD solver.
- The pressure/velocity/drag values are heuristic proxies based on angular loss and
  curvature, not real units.
- Ensure the STL is valid and non-empty. Invalid meshes can yield undefined results.
