diff src/Grids/mapped_grid.jl @ 1688:72776d3d5fd6 feature/grids/curvilinear

Add min_spacing for 2D mapped grids
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 22 Aug 2024 08:14:04 +0200
parents 22a9992471be
children a4c52ae93b11 6eb5b48607e0
line wrap: on
line diff
--- a/src/Grids/mapped_grid.jl	Wed Aug 21 19:23:42 2024 +0200
+++ b/src/Grids/mapped_grid.jl	Thu Aug 22 08:14:04 2024 +0200
@@ -92,6 +92,28 @@
     return ms
 end
 
+function min_spacing(g::MappedGrid{T,2} where T)
+    n, m = size(g)
+
+    ms = Inf
+    for i ∈ 1:n-1, j ∈ 1:m-1 # loop over each cell of the grid
+
+        ms = min(
+            ms,
+            norm(g[i+1,j]-g[i,j]),
+            norm(g[i,j+1]-g[i,j]),
+
+            norm(g[i+1,j]-g[i+1,j+1]),
+            norm(g[i,j+1]-g[i+1,j+1]),
+
+            norm(g[i+1,j+1]-g[i,j]),
+            norm(g[i+1,j]-g[i,j+1]),
+        )
+        # NOTE: This could be optimized to avoid checking all interior edges twice.
+    end
+
+    return ms
+end
 
 """
     normal(g::MappedGrid, boundary)