# Uniform Refinement

*Uniform refinement creates regions of consistent mesh resolution, particularly useful for capturing off-body flow features such as wakes, shocks, and vortices, while maintaining computational efficiency in regions of uniform flow.*

---

## Available Options

| *Option* | *Description*                  |
|------------|----------------------------------|
| **Spacing** | Target mesh spacing in the region |
| **Assigned boxes and cylinders** | Target volumes for refinement application |

---

## Detailed Descriptions

### Spacing

*Defines the uniform mesh spacing within the refinement region.*

- **Required**
- **Example:** `0.1 m`
>**Note:** Should be chosen based on flow feature size and resolution requirements.

### Assigned boxes and cylinders

*Specifies the volumes where uniform refinement will be applied.*

- **Required**
>**Notes:** 
>  - Must reference valid box or cylinder entities in the geometry. 
>  - Assign the entity by selecting from the list using the + button or select graphically in the viewer region.

---

## Effect on the surface mesh

Whether a uniform refinement also refines the **surface** mesh inside the region depends on the mesher:

- The **GeometryAI** and **snappy** surface meshers refine the surface inside the region.
- The **legacy** and **beta** surface meshers refine the volume mesh only, leaving the surface untouched.

With snappy, this is controlled per refinement by the **project to surface** option (on by default); turn it off to refine the volume only. The option is not available for the other meshers.

```{seealso}
User guide: {ref}`Volumetric refinements: effect on the surface mesh <uniform_refinement_surface_effect>`
```

---

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

- **What happens if uniform refinements overlap?**  
  > The finest (smallest) spacing will be applied in overlapping regions.

- **Can I specify a uniform refinement over a custom volume?**  
  > Not over a fully user-defined custom volume directly. The recommended practice is to cover the target region with one or more overlapping primitive shapes (boxes/cylinders) and apply the uniform refinement to those. For example, an L-shaped region can be covered by two overlapping boxes.

</details>

---

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

```{seealso}
Python API:
- {py:class}`~flow360.UniformRefinement`
```

```python
import flow360 as fl

# Wake region refinement
wake_ref = fl.UniformRefinement(
    name="wake_region",
    entities=[wake_box],
    spacing=0.1 * fl.u.m
)

# Shock region refinement
shock_ref = fl.UniformRefinement(
    name="shock_region",
    entities=[shock_box],
    spacing=0.05 * fl.u.m  # Finer spacing for shock resolution
)

# Near-body refinement
near_body_ref = fl.UniformRefinement(
    name="near_body",
    entities=[near_body_box],
    spacing=0.02 * fl.u.m  # √3 times surface spacing
)
```
</details> 