changeset 1428:a936b414283a feature/grids/curvilinear

Merge bugfix/grids/complete_interface_impl
author Jonatan Werpers <jonatan@werpers.com>
date Thu, 24 Aug 2023 08:50:10 +0200
parents 26e168924cf1 (diff) 18e21601da2d (current diff)
children e87f3465b770
files
diffstat 5 files changed, 23 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/src/Grids/Grids.jl	Wed Aug 23 15:35:01 2023 +0200
+++ b/src/Grids/Grids.jl	Thu Aug 24 08:50:10 2023 +0200
@@ -35,11 +35,14 @@
 export equidistant_grid
 export CartesianBoundary
 
+export CurvilinearGrid
+
 abstract type BoundaryIdentifier end
 
 include("grid.jl")
 include("tensor_grid.jl")
 include("equidistant_grid.jl")
 include("zero_dim_grid.jl")
+include("curvilinear_grid.jl")
 
 end # module
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/src/Grids/curvilinear_grid.jl	Thu Aug 24 08:50:10 2023 +0200
@@ -0,0 +1,1 @@
+struct CurvilinearGrid end
--- a/src/Grids/grid.jl	Wed Aug 23 15:35:01 2023 +0200
+++ b/src/Grids/grid.jl	Thu Aug 24 08:50:10 2023 +0200
@@ -76,7 +76,7 @@
 """
     eval_on(g::Grid, f)
 
-Lazy evaluation `f` on the grid. `f` can either be on the form `f(x,y,...)`
+Lazy evaluation of `f` on the grid. `f` can either be on the form `f(x,y,...)`
 with each coordinate as an argument, or on the form `f(x̄)` taking a
 coordinate vector.
 
@@ -91,5 +91,12 @@
     end
 end
 
+"""
+    eval_on(g::Grid, f::Number)
+
+Lazy evaluation of a scalar `f` on the grid.
+"""
+eval_on(g::Grid, f::Number) = return LazyTensors.LazyConstantArray(f, size(g))
+
 _ncomponents(::Type{<:Number}) = 1
 _ncomponents(T::Type{<:SVector}) = length(T)
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/Grids/curvilinear_grid_test.jl	Thu Aug 24 08:50:10 2023 +0200
@@ -0,0 +1,6 @@
+using Sbplib.Grids
+using Test
+
+@testset "CurvilinearGrid" begin
+    @test CurvilinearGrid isa Any
+end
--- a/test/Grids/grid_test.jl	Wed Aug 23 15:35:01 2023 +0200
+++ b/test/Grids/grid_test.jl	Thu Aug 24 08:50:10 2023 +0200
@@ -38,6 +38,9 @@
     @test eval_on(ZeroDimGrid(1.), x̄->2x̄) isa LazyArray
     @test eval_on(ZeroDimGrid(1.), x̄->2x̄) == fill(2.)
 
+    @test eval_on(ZeroDimGrid(@SVector[1.,2.]), π) isa LazyArray
+    @test eval_on(ZeroDimGrid(@SVector[1.,2.]), π) == fill(π)
+
     @test eval_on(EquidistantGrid(range(0,1,length=4)), x->2x) isa LazyArray
     @test eval_on(EquidistantGrid(range(0,1,length=4)), x->2x) == 2 .* range(0,1,length=4)
 
@@ -49,6 +52,8 @@
 
     @test eval_on(g, x̄ -> sin(x̄[1])*cos(x̄[2])) == map(x̄->sin(x̄[1])*cos(x̄[2]), g)
 
+    @test eval_on(g, π) == fill(π, (5,3))
+
     # Vector valued function
     @test eval_on(g, x̄ -> @SVector[x̄[2], x̄[1]]) isa LazyArray{SVector{2,Float64}}
     @test eval_on(g, x̄ -> @SVector[x̄[2], x̄[1]]) == map(x̄ -> @SVector[x̄[2], x̄[1]], g)