Mercurial > repos > public > sbplib_julia
diff src/Grids/mapped_grid.jl @ 1659:3bbcd496e021 feature/grids/curvilinear
Add function for computing the normal at the boundary of a mapped grid as a grid function
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Fri, 28 Jun 2024 17:02:47 +0200 |
parents | 64452a678e7a |
children | 6d196fb85133 5ea0299b45b4 |
line wrap: on
line diff
--- a/src/Grids/mapped_grid.jl Wed Jun 26 12:41:03 2024 +0200 +++ b/src/Grids/mapped_grid.jl Fri Jun 28 17:02:47 2024 +0200 @@ -80,3 +80,27 @@ end end +""" + normal(g::MappedGrid, boundary) + +The outward pointing normal as a grid function on the boundary +""" +function normal(g::MappedGrid, boundary) + b_indices = boundary_indices(g, boundary) + σ =_boundary_sign(component_type(g), boundary) + return map(jacobian(g)[b_indices...]) do ∂x∂ξ + ∂ξ∂x = inv(∂x∂ξ) + k = grid_id(boundary) + σ*∂ξ∂x[k,:]/norm(∂ξ∂x[k,:]) + end +end + +function _boundary_sign(T, boundary) + if boundary_id(boundary) == Upper() + return one(T) + elseif boundary_id(boundary) == Lower() + return -one(T) + else + throw(ArgumentError("The boundary identifier must be either `Lower()` or `Upper()`")) + end +end