changeset 261:01017d2b46b0 boundary_conditions

Store grid spacing as property in EquidistantGrid
author Vidar Stiernström <vidar.stiernstrom@it.uu.se>
date Tue, 26 Nov 2019 08:19:22 -0800
parents f89718833620
children f1e90a92ad74
files Grids/src/EquidistantGrid.jl
diffstat 1 files changed, 15 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/Grids/src/EquidistantGrid.jl	Tue Nov 26 08:18:23 2019 -0800
+++ b/Grids/src/EquidistantGrid.jl	Tue Nov 26 08:19:22 2019 -0800
@@ -10,14 +10,16 @@
     size::NTuple{Dim, Int} # First coordinate direction stored first
     limit_lower::NTuple{Dim, T}
     limit_upper::NTuple{Dim, T}
-    inverse_spacing::NTuple{Dim, T} # The reciprocal of the grid spacing
+    spacing::NTuple{Dim, T} # Grid spacing
+    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)
+        spacing = abs.(limit_upper.-limit_lower)./(size.-1)
+        inverse_spacing = 1.0./spacing
+        return new{Dim,T}(size, limit_lower, limit_upper, spacing, inverse_spacing)
     end
 end
 
@@ -35,10 +37,18 @@
     return length(grid.size)
 end
 
-# Returns the spacing of the grid
+# TODO: Keep the below functions or just use properties?
+# Returns the reciprocal of the spacing of the grid
+#
+function inverse_spacing(grid::EquidistantGrid)
+    return grid.inverse_spacing
+end
+export inverse_spacing
+
+# Returns the reciprocal of the spacing of the grid
 #
 function spacing(grid::EquidistantGrid)
-    return 1.0./grid.inverse_spacing
+    return grid.spacing
 end
 export spacing