changeset 381:dacbcba33d7d

Refactor EquidistantGrid to not store spacing or inverse spacing
author Jonatan Werpers <jonatan@werpers.com>
date Wed, 30 Sep 2020 21:49:48 +0200
parents 81053b1992b6
children 5c10cd0ed1fe
files src/Grids/EquidistantGrid.jl src/SbpOperators/laplace/secondderivative.jl
diffstat 2 files changed, 17 insertions(+), 22 deletions(-) [+]
line wrap: on
line diff
--- a/src/Grids/EquidistantGrid.jl	Wed Sep 30 21:35:10 2020 +0200
+++ b/src/Grids/EquidistantGrid.jl	Wed Sep 30 21:49:48 2020 +0200
@@ -7,17 +7,15 @@
 export EquidistantGrid
 
 struct EquidistantGrid{Dim,T<:Real} <: AbstractGrid
-    size::NTuple{Dim, Int} # First coordinate direction stored first
+    size::NTuple{Dim, Int}
     limit_lower::NTuple{Dim, T}
     limit_upper::NTuple{Dim, T}
-    inverse_spacing::NTuple{Dim, T} # Reciprocal of grid spacing
 
     # General constructor
     function EquidistantGrid(size::NTuple{Dim, Int}, limit_lower::NTuple{Dim, T}, limit_upper::NTuple{Dim, T}) where Dim where T
         @assert all(size.>0)
         @assert all(limit_upper.-limit_lower .!= 0)
-        inverse_spacing = (size.-1)./ abs.(limit_upper.-limit_lower)
-        return new{Dim,T}(size, limit_lower, limit_upper, inverse_spacing)
+        return new{Dim,T}(size, limit_lower, limit_upper)
     end
 end
 
@@ -39,21 +37,24 @@
     return length(grid.size)
 end
 
-# Returns the reciprocal of the spacing of the grid
-#
-function inverse_spacing(grid::EquidistantGrid)
-    return grid.inverse_spacing
-end
-export inverse_spacing
+
+"""
+    spacing(grid::EquidistantGrid)
 
-# Returns the reciprocal of the spacing of the grid
-#
+The spacing between the grid points of the grid.
+"""
+spacing(grid::EquidistantGrid) = abs.(grid.limit_upper.-grid.limit_lower)./(grid.size.-1)
 # TODO: Evaluate if divisions affect performance
-function spacing(grid::EquidistantGrid)
-    return 1.0./grid.inverse_spacing
-end
 export spacing
 
+"""
+    spacing(grid::EquidistantGrid)
+
+The reciprocal of the spacing between the grid points of the grid.
+"""
+inverse_spacing(grid::EquidistantGrid) = 1 ./ spacing(grid)
+export inverse_spacing
+
 # Computes the points of an EquidistantGrid as an array of tuples with
 # the same dimension as the grid.
 #
@@ -79,9 +80,3 @@
     return EquidistantGrid(size, limit_lower, limit_upper)
 end
 export restrict
-
-function pointsalongdim(grid::EquidistantGrid, dim::Integer)
-    @assert dim<=dimension(grid)
-    @assert dim>0
-    points = collect(range(grid.limit_lower[dim],stop=grid.limit_upper[dim],length=grid.size[dim]))
-end
--- a/src/SbpOperators/laplace/secondderivative.jl	Wed Sep 30 21:35:10 2020 +0200
+++ b/src/SbpOperators/laplace/secondderivative.jl	Wed Sep 30 21:49:48 2020 +0200
@@ -13,7 +13,7 @@
 export SecondDerivative
 
 function SecondDerivative(grid::EquidistantGrid{1}, innerStencil, closureStencils)
-    h_inv = grid.inverse_spacing[1]
+    h_inv = inverse_spacing(grid)[1]
     return SecondDerivative(h_inv, innerStencil, closureStencils, size(grid))
 end