# Analysis scripts

## Optional: create a Python environment
A requirements.txt file is provided with the dependencies for running the
scripts. One way to use it is to create a fresh environment as follows:

```bash
python -m venv venv
source venv/bin/activate        # Linux/macOS
# or:
# venv\Scripts\activate         # Windows PowerShell
```
and install the dependencies as
```bash
pip install -r requirements.txt
```

All scripts assume they are run from inside the `analysis_scripts` directory so
that the relative paths to `..` resolve correctly. Unless noted otherwise,
figures are written to `../figures`. To configure the location of the data
and where to output the figures, one can manipulate the associated string
variables in the beginning of each script:
- `DATA`, the path to the folder with the simulation cases. Preset to `..`.
- `SAVE_PATH`, the path where the figure will be saved. Preset to `../figures`.
- `CASE`, the name of the case. For scripts that only operate on a single case
  at a time. Preset to `M1`.

## What is included

### Utilities and data preparation
- `convert_probes_to_hdf5.py` converts ASCII probe output under
  `postProcessing/probes` to `probes_u.hdf5` and `probes_p.hdf5` for a selected
  case.
- `prepare_probes.py` builds a `system/probes` file from inlet face-centre
  coordinates. First, first run `postProcess -func surfaces -time 0` to generate
  the coordinates of the face centres. The relevant configuration for that is
  under `system/surfaces` in each case, which simply sets up sampling `p` from
  the inlet patch.

### Computing statistics from probe data
- `compute_plane_statistics.py` uses `probes_u.hdf5` M1, M2 and M3 to
  compute mean, variance, skewness and flatness profiles, saving
  `plane_stats.txt` into each case directory. You can adapt it to do the same
  for other cases for which you choose to sample probes.
- `compute_spanwise_spectra.py` demonstrates how to compute 1D spanwise energy
  spectra (currently set to process `M1`, but easily configurable) and writes
  `z_spectrum_{u,v,w}.txt`.
- `compute_spectral_coherence.py` shows how to compute linear spectral coherence
  relative to $y^+ = 2$ using `probes_u.hdf5`, currently reads from case `M1`
  but easily configurable.
- `compute_two_point_corrs.py` contains three approaches for computing two-point
  correlations from `probes_u.hdf5` and writes `z_tpcorr_{comp}_fft.txt`,
  `z_tpcorr_{comp}_fullfft.txt`, and `z_tpcorr_{comp}_roll.txt`. The case is
  configurable as in the other scripts.

### Plotting and figure generation
- `post_main.py` produces Figures 2, 3, 4, 5, 6, 9, 10, 12, 13, and 14 for the
  main cases M1, M2 and M3.
- `post_skewness_and_flatness.py` produces Figures 7 and 8 (skewness and
  flatness profiles; DNS data not included).
- `post_pimple_vs_rskym.py` produces Figures 15 and 16 comparing `pimpleFoam`
  and `RKSymFOAM`.
- `post_implicit_vs_sigma.py` produces Figures 17 and 18 comparing implicit LES
  and Sigma LES.
- `post_plane_vs_volume_statistics.py` produces Figure 19 comparing plane- and
  volume-averaged statistics for M2.
- `post_cfl.py` produces Figure 20 comparing different target CFL numbers on the
  M1 grid.
- `post_re180.py` produces Figures 21 and 22 for the Re_tau = 180 cases in
  `re180_simulations`.
- `post_linear_vs_lust.py` produces Figures 23 and 24 comparing linear and LUST
  schemes.
