# Time-averaging Slice Output

*Time-averaging Slice Output in Flow360 allows you to calculate and visualize time-averaged flow variables on 2D cutting planes through the computational domain. This provides statistical data essential for analyzing unsteady flows while keeping file sizes much smaller than full volume outputs.*

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

---

## Available Options

| *Option* | *Description* | *Applicable* |
|----------|---------------|--------------|
| **Output fields** | Flow variables to include in the output | always |
| **Output format** | Format for saving slice data | always |
| **Start step** | When to begin time-averaging | 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` |
| **Assigned slices** | Definition of slice planes | 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

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

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

### Output format

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

- **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 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)).

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

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

- **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:** 
> - 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)).

### Assigned slices

*Defines the 2D cutting planes through the computational domain.*

- **Definition parameters:**
  - **Name:** A unique identifier for the slice
  - **Origin:** The 3D coordinates of a point on the slice plane
  - **Normal:** The normal vector to the slice plane (does not need to be normalized)

- **Example:** 
  ```
  Name: "Midspan"
  Origin: (0, 5, 0)
  Normal: (0, 1, 0)
  ```
>**Note:** Multiple slices can be defined, each with unique name, origin, and normal.

---

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

Time-averaged slice output is particularly useful in the following scenarios:

1. **Analyzing unsteady flows**: For flows with inherent unsteadiness (like vortex shedding, turbulent wakes, or separated flows), time-averaging on strategic slice planes provides mean flow statistics.

2. **Reducing storage requirements**: Instead of saving many instantaneous snapshots, you can capture the statistical behavior with a single time-averaged result.

3. **Flow stability assessment**: Time-averaged slices help determine if a flow has reached a statistically steady state in key regions, even if instantaneous values are fluctuating.

4. **Strategic slice placement**: Position time-averaged slices at these key locations for maximum insight:
   - **Wake regions** to capture mean wake structures
   - **Boundary layer regions** to observe mean separation behavior
   - **Shear layers** to analyze mean mixing characteristics
   - **Rotor disk planes** for time-averaged BET analysis

#### Visual Analysis Tips

When analyzing time-averaged slice data:

- **Compare with instantaneous slices** at the same location to identify regions of high unsteadiness
- **Look for smoothed features** in the time-averaged data that might be obscured by fluctuations in instantaneous snapshots
- **Create streamlines** on time-averaged slices to visualize mean flow patterns
- **Use multiple slices** at different positions to construct a 3D understanding of the mean flow field

</details>

---

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

- **When should I use time-averaged slices instead of instantaneous slices?**  
  > Time-averaged slices 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 to identify average positions of features that move over time (e.g., shock waves, separation points)

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

- **Can I get fluctuation intensity or RMS values from time-averaged slices?**  
  > Currently, Flow360 time-averaged outputs include mean values only, not RMS or fluctuation intensities. To obtain these:
  > - Export both instantaneous and time-averaged slice data
  > - Post-process using ParaView/Tecplot to calculate RMS values
  > - For turbulence quantities, consider using the k and omega fields which represent turbulent kinetic energy and specific dissipation rate

- **How many slices can I define for time-averaging?**  
  > There is no hard limit on the number of slices you can define for time-averaging, but consider:
  > - Each slice adds memory overhead during the simulation
  > - Too many slices may impact performance
  > - Start with strategically placed slices and add more if needed

- **Can I use both time-averaged and instantaneous slice outputs in the same simulation?**  
  > Yes, you can define separate outputs for:
  > - Time-averaged slices for statistical analysis
  > - Instantaneous slices for capturing transient phenomena
  > This approach provides comprehensive coverage of both mean flow characteristics and unsteady features.

</details>

---

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

```python
# Example of configuring time-averaged slice output
from flow360 import u
import flow360 as fl

# Define time-averaged slice output settings
time_avg_slice = fl.TimeAverageSliceOutput(
    name="Time Averaged Wing Sections",
    output_format="paraview",
    slices=[
        fl.Slice(
            name="Root", 
            origin=(0, 0, 0) * u.m, 
            normal=(0, 1, 0)
        ),
        fl.Slice(
            name="Midspan", 
            origin=(0, 0.5, 0) * u.m, 
            normal=(0, 1, 0)
        ),
        fl.Slice(
            name="Tip", 
            origin=(0, 1.0, 0) * u.m, 
            normal=(0, 1, 0)
        )
    ],
    output_fields=["Mach", "pressure", "velocity", "Cp", "Cpt"],
    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_slice]
)
```

</details>
