diff src/Grids/mapped_grid.jl @ 1696:29b96fc75bee feature/sbp_operators/laplace_curvilinear

Merge feature/grids/manifolds
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 28 Aug 2024 10:50:15 +0200
parents a4c52ae93b11
children 03894fd7b132
line wrap: on
line diff
--- a/src/Grids/mapped_grid.jl	Wed Aug 28 09:56:35 2024 +0200
+++ b/src/Grids/mapped_grid.jl	Wed Aug 28 10:50:15 2024 +0200
@@ -61,6 +61,7 @@
         map(J,lg),
     )
 end
+# TODO: Delete this function
 
 
 function jacobian_determinant(g::MappedGrid)
@@ -69,18 +70,52 @@
     end
 end
 
-function geometric_tensor(g::MappedGrid)
+function metric_tensor(g::MappedGrid)
     return map(jacobian(g)) do ∂x∂ξ
         ∂x∂ξ'*∂x∂ξ
     end
 end
 
-function geometric_tensor_inverse(g::MappedGrid)
+function metric_tensor_inverse(g::MappedGrid)
     return map(jacobian(g)) do ∂x∂ξ
         inv(∂x∂ξ'*∂x∂ξ)
     end
 end
 
+function min_spacing(g::MappedGrid{T,1} where T)
+    n, = size(g)
+
+    ms = Inf
+    for i ∈ 1:n-1
+        ms = min(ms, norm(g[i+1]-g[i]))
+    end
+
+    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)