Skip to content

Commit

Permalink
Improve interp doc
Browse files Browse the repository at this point in the history
  • Loading branch information
luraess committed Oct 3, 2024
1 parent 528240b commit 169f161
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions docs/src/concepts/grid_operators.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ In the following example, we first define a mask `ω` on the 2D `StructuredGrid`
r = 2.0
init_inclusion = (x,y) -> ifelse(x^2 + y^2 < r^2, 1.0, 0.0)

# mask all other entries other than the initial inclusion
# mask all other entries other than the initial inclusion
set!.vc, grid, init_inclusion)
set!.cv, grid, init_inclusion)
```
Expand Down Expand Up @@ -80,9 +80,24 @@ launch(arch, grid, update_strain_rate! => (ε̇, V, ω, grid))

## Interpolation

Interpolating physical parameters such as permeability and density between various grid locations is frequently necessary on a staggered grid. Chmy.jl provides functions for performing interpolations of field values between different locations.
Interpolating physical parameters such as permeability and density between various grid locations is frequently necessary on a staggered grid. Chmy.jl provides an interface `itp` which interpolates the field `f` from its current location to the specified location(s) `to` using the given interpolation rule `r`. The indices specify the position within the grid at location(s) `to`:

In the following example, we specify to use the linear interpolation rule `lerp` when interpolating nodal values of the density field `ρ`, defined on pressure nodes (with location `(Center(), Center())`) to `ρvx` and `ρvy`, defined on Vx and Vy nodes respectively.
```julia
itp(f, to, r, grid, I...)
```

Available interpolation rules consist of:
- `Linear()` which implements `rule(t, v0, v1) = v0 + t * (v1 - v0)`;
- `HarmonicLinear()` which implements `rule(t, v0, v1) = 1/(1/v0 + t * (1/v1 - 1/v0))`.

Both rules are exposed as convenience wrapper functions `lerp` and `hlerp`, using `Linear()` and `HarmonicLinear()` rules, respectively:

```julia
lerp(f, to, grid, I...) # implements itp(f, to, Linear(), grid, I...)
hlerp(f, to, grid, I...) # implements itp(f, to, HarmonicLinear(), grid, I...)
```

In the following example, we specify to use the linear interpolation rule `lerp` when interpolating nodal values of the density field `ρ`, defined on pressure nodes with location `(Center(), Center())` to `ρvx` and `ρvy`, defined on Vx and Vy nodes, respectively.

```julia
# define density ρ on pressure nodes
Expand All @@ -94,7 +109,7 @@ In the following example, we specify to use the linear interpolation rule `lerp`
ρvy = Field(backend, grid, (Center(), Vertex()))
```

The kernel `interpolate_ρ!` performs the actual interpolation of nodal values and requires the grid information passed by `g`.
The kernel `interpolate_ρ!` performs the actual interpolation and requires the grid information passed by `g`.

```julia
@kernel function interpolate_ρ!(ρ, ρvx, ρvy, g::StructuredGrid, O)
Expand Down

0 comments on commit 169f161

Please sign in to comment.