# Time-averaging Surface Output

*Time-averaging Surface Output in Flow360 allows you to collect statistical data for unsteady simulations, providing time-averaged values of flow field variables on geometry surfaces. This is essential for analyzing periodic or turbulent flows where instantaneous values may fluctuate significantly.*

> **Note**: Time-averaging outputs are only available when using unsteady time stepping methods.

---

## Available Options

| *Option* | *Description* |
|----------|---------------|
| **Output fields** | Flow variables to time-average | always |
| **Output format** | File format for the output files | always |
| **Start step** | Time step at which to begin averaging | always |
| **Write single file** | Option to write all surfaces to a single file | always |
| **Save interval** | When to save outputs | always |
| **Frequency** | How often to save the time-averaged output | when **Save interval** is `Custom` |
| **Frequency offset** | Time step at which to begin saving output | when **Save interval** is `Custom` |
| **Assigned boundaries** | Geometry surfaces to apply time-averaging to | always |

---

## Global Time Stepping in Child Cases

When working with **child cases** (cases forked from a parent simulation), it's important to understand that the `Frequency`, `Frequency offset`, and `Start step` parameters refer to the **global** time step, which is transferred from the parent case.

**Example:** If the parent case finished at `time_step=174`, the child case will start from `time_step=175`. If `Frequency=100` is set in the child case, the output will be saved at global time steps 200 (25 time steps into the child simulation), 300 (125 time steps into the child simulation), etc. `Frequency offset` also refers to the global time step, meaning that if in the previously mentioned child case, `Frequency offset=50` was set (with `Frequency=100`), the output would be saved at **global** time steps 250 (75 time steps into the child simulation), 350 (175 time steps into the child simulation), etc.

---

## Detailed Descriptions

### Output fields

*The flow variables that will be time-averaged in the output files.*

- **Example:** `Cp`, `velocity`, `pressure`
>**Note:** see [Available Output Fields](../output-fields.md) for a complete list of fields available for surface outputs.

### Output format

*Specifies the file format for the output files.*

- **Default:** `paraview`
- **Options:**
  - `paraview`
  - `tecplot`
  - `both`
> **Notes:** 
> - Choose the format that best suits your post-processing workflow.
> - Select `paraview` for `.vtu` format, `tecplot` for `.plt` format, or `both` to save in both formats.

### Start step

*Specifies the time step at which to begin the time-averaging process.*

- **Default:** `-1` (at end of simulation)
- **Example:** `5000` (start averaging at time step 5000)
>**Notes:** 
> - Set this to a time step after initial transients have settled for more meaningful statistics.
> - Important for child cases - this parameter refers to the **global** time step, which gets transferred from the parent case (see [Global Time Stepping](#global-time-stepping-in-child-cases)).

### Write single file

*Controls whether all surface outputs are written to a single file instead of one file per surface.*

- **Default:** `false`
- **Options:**
  - `true`
  - `false`

### Save interval

*Choose the points in the simulation where the results are saved.*

- **Default:** `Save at end`
- **Options:**
  - `Save at end`
  - `Custom`
> **Notes:** 
> - Choose `Save at end` to save only the final results of the simulation.
> - Choose `Custom` to save the results in given intervals.

### Frequency

*Controls how often the time-averaged output files are generated.*

- **Default:** `-1` (only at end of simulation)
- **Example:** `100` — saves output every 100 physical time steps.
  - **Standalone case:** If you start a simulation from `time_step=0` with `frequency=100`, outputs are saved at time steps 100, 200, 300, etc.
  - **Parent-child case:** If the parent finished at `time_step=174`, the child starts from `time_step=175`. With `frequency=100` in the child, outputs are saved at global time steps 200 (25 steps into child), 300 (125 steps into child), 400 (225 steps into child), etc.
>**Notes:** 
> - Setting to `-1` will only produce output at the end of the simulation.
> - Important for child cases - this parameter refers to the **global** time step (see [Global Time Stepping](#global-time-stepping-in-child-cases)).

### Frequency offset

*Specifies the time step at which to begin saving the time-averaged output.*

- **Default:** `0` (at beginning of simulation)
- **Example:** `1000` — with `frequency=100`, outputs are saved at time steps 1000, 1100, 1200, etc.
  - **Standalone case:** If you start a simulation from `time_step=0` with `frequency=100` and `frequency_offset=1000`, outputs are saved at time steps 1000, 1100, 1200, etc.
  - **Parent-child case:** If the parent finished at `time_step=174`, the child starts from `time_step=175`. With `frequency=100` and `frequency_offset=200` in the child, outputs are saved at global time steps 200 (25 steps into child), 300 (125 steps into child), 400 (225 steps into child), etc.
>**Notes:** 
> - This setting works in conjunction with `Frequency` to control the time steps at which output is produced.
> - Important for child cases - this parameter refers to the **global** time step (see [Global Time Stepping](#global-time-stepping-in-child-cases)).

### Assigned boundaries

*The geometry surfaces where time-averaging will be applied.*

- **Example:** `wing`, `fuselage`, `all_walls`
>**Note:** You can specify individual surfaces or use pattern matching (e.g., `"wall*"`) to select multiple surfaces.

---

<details>
<summary><h3 style="display:inline-block"> 💡 Tips</h3></summary>

- **Averaging window:** Ensure your simulation runs long enough after the `Start Step` to collect meaningful statistics
- **Transient effects:** Set `Start Step` beyond the initial transient period
- **Periodic flows:** For flows with known periodicity, average over multiple complete cycles
- **Flow stability:** Monitor convergence of time-averaged quantities to ensure statistical stability

**When visualizing time-averaged surface output, consider:**
- Comparing time-averaged and instantaneous fields to identify regions of high unsteadiness
- Using time-averaged fields to calculate stable performance metrics
- Examining the difference between time-averaged and steady-state solutions for similar conditions
- Creating streamlines based on time-averaged velocity fields to reveal mean flow patterns

</details>

---

<details>
<summary><h3 style="display:inline-block"> ❓ Frequently Asked Questions</h3></summary>

- **How is time-averaging calculated?**  
  > Time-averaging is calculated using an average formula:
  > 
  > ```
  > avg_new = avg_old + (new_value - avg_old) / n
  > ```
  > 
  > Where:
  > - `avg_new` is the updated time-average
  > - `avg_old` is the previous time-average
  > - `new_value` is the instantaneous value at the current time step
  > - `n` is the number of samples since the start of averaging

- **What's the difference between time-averaging and animation?**  
  > - **Animation:** Captures instantaneous "snapshots" of the flow at specific time steps (controlled by `Frequency`)
  > - **Time-averaging:** Produces statistical averages over many time steps, reducing noise and revealing mean flow patterns

- **When should I use time-averaging?**  
  > Time-averaging is particularly useful for:
  > 
  > - Turbulent flows where instantaneous values fluctuate significantly
  > - Periodic flows where cycle-to-cycle statistics are of interest
  > - Calculating mean aerodynamic performance metrics in unsteady simulations
  > - Identifying quasi-steady flow features in dynamically changing simulations

</details>

---

<details>
<summary><h3 style="display:inline-block"> 🐍 Python Example Usage</h3></summary>

```python
# Example of setting up time-averaged surface output in Python
time_avg_output = fl.TimeAverageSurfaceOutput(
    name="Wing and Fuselage Time Avg",  # Descriptive name for this output
    output_format="paraview",
    output_fields=["primitiveVars", "Cp"],
    entities=[
        volume_mesh["wing"],
        volume_mesh["fuselage"],
    ],
    start_step=1000,  # Start averaging after time step 1000
    frequency=100,    # Output every 100 time steps
    frequency_offset=1500,  # Start outputting at time step 1500
)
```

</details> 