# Time-averaging Volume Output

*Time-averaging Volume Output in Flow360 allows you to calculate and visualize time-averaged flow variables throughout the entire computational domain. This is essential for statistical analysis of unsteady flows and understanding mean flow characteristics.*

## Available Options

| *Option* | *Description* | *Applicable* |
|----------|---------------|--------------|
| **Output fields** | Flow variables to include in the output |  always |
| **Output format** | Format for saving volume data | always |
| **Start step** | When to begin time-averaging | always |
| **Statistics function** | Statistics to write: `Mean`, `RMS`, or both | always |
| **Averaging reference frame** | Frame in which vector fields are averaged on rotating geometry: `Global` or `Body` | always |
| **Save interval** | When to save outputs | always |
| **Frequency** | How often to save outputs | when **Save interval** is `Custom` |
| **Frequency offset** | Time step at which to start the output animation | when **Save interval** is `Custom` |

```{seealso}
For the underlying physics and configuration of outputs, see the {doc}`/user_guide/OutputConfiguration/OutputConfiguration` user guide.
```

---

## 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

*Select the flow variables to include in the volume output.*

- **Default:** None
- **Example:** `Mach, pressure, velocity`
>**Notes:** see [Available Output Fields](../output-fields.md) for a complete list of fields available for volume outputs.

### Output format

*The file format used to save the volume output data.*

- **Default:** `paraview`
- **Options:** (multi-select; choose one or more)
  - `paraview`
  - `tecplot`
  - `vtkhdf`
  - `ensight`
> **Notes:** 
> - Choose the format that best suits your post-processing workflow.
> - The **Output format** control is multi-select: pick one or more of `paraview`, `tecplot`, `vtkhdf`, or `ensight`. See [Output Formats](19.output-formats.md) for file extensions and details.

### Start step

*Specifies the physical time step to start calculating time averaging.*

- **Default:** `-1` (automatic detection)
- **Example:** `50`
>**Notes:** 
> - Set this to begin averaging after initial transients have died out. When set to `-1`, the solver will automatically determine when to start averaging based on flow convergence.
> - 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)).

### Statistics function

*Selects which statistics are accumulated and written for each output field.*

- **Default:** `Mean`
- **Options:** (multi-select; choose one or more)
  - `Mean`
  - `RMS`
>**Notes:**
> - Selecting both writes the mean under each field's normal name and the RMS under `<field>_rms`.
> - The RMS is taken on the raw signal without subtracting the mean, so it is not a fluctuation intensity about the mean.
> - See {ref}`Time-Averaged Statistics <timeAverageStatistics_userGuide>` for how the accumulation windows behave.

### Averaging reference frame

*Selects the frame in which vector fields are time-averaged on geometry that rotates with the mesh.*

- **Default:** `Global`
- **Options:**
  - `Global`
  - `Body`
>**Notes:**
> - Choose `Body` to average vector fields such as `velocity` in the frame of the rotating geometry, for example on a propeller or rotor blade. With `Global`, their components perpendicular to the rotation axis tend toward zero over full revolutions.
> - Scalar fields, RMS values and cases without rotation are unaffected.
> - All time-averaged volume outputs in a simulation must use the same value.
> - See {ref}`Averaging Vectors on Rotating Geometry <averagingReferenceFrame_userGuide>` for which fields are affected and how forked cases behave.

### Save interval

*Choose the points in the simulaton 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.
> - This output is produced in unsteady simulations only, so no save frequency applies to a steady simulation in either interface, see {ref}`Output Save Frequency <outputFrequency_userGuide>`.

### Frequency

*How often to save outputs, in number of physical time steps.*

- **Default:** `1`
- **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:** 
> - `-1` saves only at end of simulation.
> - Higher frequencies provide better temporal resolution but increase storage requirements.
> - Important for child cases - this parameter refers to the **global** time step (see [Global Time Stepping](#global-time-stepping-in-child-cases)).

### Frequency offset

*The time step at which to start the output animation.*

- **Default:** `0` (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:** 
> - Useful when you want to skip initial transient flow development.
> - Important for child cases - this parameter refers to the **global** time step (see [Global Time Stepping](#global-time-stepping-in-child-cases)).

---

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

```{note}
Time-averaged outputs are only available when using unsteady time stepping methods.
```

</details>

---

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

- **When should I use time-averaged outputs instead of regular volume outputs?**  
  > Time-averaged outputs are ideal when:
  > - You're analyzing statistically steady turbulent flows
  > - You need to filter out transient features or numerical noise
  > - You want to reduce storage requirements while still capturing overall flow behavior
  > - You're interested in mean flow characteristics rather than instantaneous snapshots
  > - You need statistical quantities like mean or RMS values for performance analysis

- **How does the Start Step parameter affect my results?**  
  > The `Start Step` parameter controls when the solver begins accumulating statistics for time-averaging:
  > - Setting it too early may include unwanted transient effects in your averages
  > - Setting it too late may not give enough time for statistical convergence
  > - The automatic setting (`-1`) detects when force coefficients begin to oscillate around a mean value
  > - For better control, monitor your force history and set it manually once transients have subsided

- **How do I get fluctuation intensity from time-averaged outputs?**  
  > RMS is written by [Statistics function](#statistics-function), but it is taken on the raw signal, so it is not a fluctuation intensity about the mean. For that, export both instantaneous and time-averaged data and post-process using ParaView/Tecplot.

- **How long should I run my simulation to get good time-averaged results?**  
  > For statistically meaningful time-averaged results:
  > - Continue at least 5-10 characteristic time periods after starting the averaging
  > - For external aerodynamics, typically 5-10 flow-through times past your geometry
  > - For periodic flows (vortex shedding), at least 20-30 shedding cycles
  > - Monitor key quantities (like forces) to ensure their time averages have converged

- **Do time-averaged outputs increase memory usage?**  
  > Time-averaged outputs require additional memory during the simulation:
  > - For each field being averaged, an additional array must be stored in memory
  > - The memory overhead scales linearly with the number of time-averaged fields
  > - On most modern systems, this is negligible compared to the overall simulation memory requirements
  > - If memory is constrained, be selective about which fields to time-average

- **What's the difference between "Start Step" and "Frequency Offset"?**  
  > These parameters serve different purposes:
  > - `Start Step`: When to begin accumulating data for the time average (affects the averaging calculation)
  > - `Frequency Offset`: When to begin writing output files (affects only output timing, not the calculation)
  > - Typically set `Start Step` based on flow physics (after transients)
  > - Set `Frequency Offset` based on output management preferences

</details>

---

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

```{seealso}
Python API reference: {py:class}`~flow360.TimeAverageVolumeOutput`.
```

```python
# Example of configuring time-averaged volume output
import flow360 as fl

# Define time-averaged volume output settings
time_avg_output = fl.TimeAverageVolumeOutput(
    name="Time Averaged Flow",
    output_format=["paraview"],
    output_fields=["Mach", "pressure", "velocity"],
    frequency=10,           # Save results every 10 time steps
    frequency_offset=100,   # Start saving at time step 100
    start_step=50           # Begin averaging at time step 50
)

# Add to simulation parameters
simulation_params = fl.SimulationParams(
    # ... other simulation parameters ...
    outputs=[time_avg_output]
)
```

</details>