From 169f161c062edfd4d1258afad6f4146873d7b07e Mon Sep 17 00:00:00 2001 From: Ludovic Raess Date: Thu, 3 Oct 2024 20:40:18 +0200 Subject: [PATCH 1/5] Improve interp doc --- docs/src/concepts/grid_operators.md | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/docs/src/concepts/grid_operators.md b/docs/src/concepts/grid_operators.md index bf60cddd..5e513b10 100644 --- a/docs/src/concepts/grid_operators.md +++ b/docs/src/concepts/grid_operators.md @@ -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) ``` @@ -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 @@ -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) From fab220d93bc7835a9ebe55820041a73067687924 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20R=C3=A4ss?= <61313342+luraess@users.noreply.github.com> Date: Fri, 4 Oct 2024 11:10:07 +0200 Subject: [PATCH 2/5] Improve docs from suggestion Co-authored-by: Ivan Utkin --- docs/src/concepts/grid_operators.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/concepts/grid_operators.md b/docs/src/concepts/grid_operators.md index 5e513b10..5bfe2dff 100644 --- a/docs/src/concepts/grid_operators.md +++ b/docs/src/concepts/grid_operators.md @@ -80,7 +80,7 @@ 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 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`: +Chmy.jl provides an interface `itp` which interpolates the field `f` from its location to the specified location `to` using the given interpolation rule `r`. The indices specify the position within the grid at location `to`: ```julia itp(f, to, r, grid, I...) From 6cdbbd957a816d1e891e8cd51567c995119e6bb7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ludovic=20R=C3=A4ss?= <61313342+luraess@users.noreply.github.com> Date: Fri, 4 Oct 2024 11:10:26 +0200 Subject: [PATCH 3/5] Improve docs from suggestion Co-authored-by: Ivan Utkin --- docs/src/concepts/grid_operators.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/concepts/grid_operators.md b/docs/src/concepts/grid_operators.md index 5bfe2dff..57ec91bb 100644 --- a/docs/src/concepts/grid_operators.md +++ b/docs/src/concepts/grid_operators.md @@ -86,7 +86,7 @@ Chmy.jl provides an interface `itp` which interpolates the field `f` from its lo itp(f, to, r, grid, I...) ``` -Available interpolation rules consist of: +Currently implemented interpolation rules are: - `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))`. From ddd8df60f9a911f1efbd5139ee4798d8bbd512c1 Mon Sep 17 00:00:00 2001 From: Ivan Utkin Date: Fri, 4 Oct 2024 11:20:54 +0200 Subject: [PATCH 4/5] Update docs/src/concepts/grid_operators.md MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ludovic Räss <61313342+luraess@users.noreply.github.com> --- docs/src/concepts/grid_operators.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/src/concepts/grid_operators.md b/docs/src/concepts/grid_operators.md index 57ec91bb..e3e9235a 100644 --- a/docs/src/concepts/grid_operators.md +++ b/docs/src/concepts/grid_operators.md @@ -97,7 +97,7 @@ 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. +In the following example, we use the linear interpolation wrapper `lerp` when interpolating nodal values of the density field `ρ`, defined on cell centres, i.e. having the location `(Center(), Center())` to `ρx` and `ρy`, defined on cell interfaces in the x- and y- direction, respectively. ```julia # define density ρ on pressure nodes From 3e59df4f60382e02b84af81b9105bb94ddc4da2b Mon Sep 17 00:00:00 2001 From: Ivan Utkin Date: Fri, 4 Oct 2024 11:23:49 +0200 Subject: [PATCH 5/5] Change example code --- docs/src/concepts/grid_operators.md | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/docs/src/concepts/grid_operators.md b/docs/src/concepts/grid_operators.md index e3e9235a..f35a7df5 100644 --- a/docs/src/concepts/grid_operators.md +++ b/docs/src/concepts/grid_operators.md @@ -100,23 +100,23 @@ hlerp(f, to, grid, I...) # implements itp(f, to, HarmonicLinear(), grid, I...) In the following example, we use the linear interpolation wrapper `lerp` when interpolating nodal values of the density field `ρ`, defined on cell centres, i.e. having the location `(Center(), Center())` to `ρx` and `ρy`, defined on cell interfaces in the x- and y- direction, respectively. ```julia -# define density ρ on pressure nodes +# define density ρ on cell centres ρ = Field(backend, grid, Center()) ρ0 = 3.0; set!(ρ, ρ0) -# allocate memory for density on Vx, Vy nodes -ρvx = Field(backend, grid, (Vertex(), Center())) -ρvy = Field(backend, grid, (Center(), Vertex())) +# allocate memory for density on cell interfaces +ρx = Field(backend, grid, (Vertex(), Center())) +ρy = Field(backend, grid, (Center(), Vertex())) ``` The kernel `interpolate_ρ!` performs the actual interpolation and requires the grid information passed by `g`. ```julia -@kernel function interpolate_ρ!(ρ, ρvx, ρvy, g::StructuredGrid, O) +@kernel function interpolate_ρ!(ρ, ρx, ρy, g::StructuredGrid, O) I = @index(Global, Cartesian) I = I + O - # Interpolate from pressure nodes to Vx, Vy nodes - ρvx = lerp(ρ, location(ρvx), g, I) - ρvy = lerp(ρ, location(ρvy), g, I) + # interpolate from cell centres to cell interfaces + ρx = lerp(ρ, location(ρx), g, I) + ρy = lerp(ρ, location(ρy), g, I) end ```