Mercurial > repos > public > sbplib_julia
changeset 1556:ec5e7926c37b
Merge refactor/equidistant_grid/signature
author | Jonatan Werpers <jonatan@werpers.com> |
---|---|
date | Sat, 13 Apr 2024 23:49:39 +0200 |
parents | f1eacb923f45 (current diff) 7e165cc0eb68 (diff) |
children | 9113f437431d 81e97d3bec8c efe1fc4cb6b0 |
files | |
diffstat | 17 files changed, 69 insertions(+), 69 deletions(-) [+] |
line wrap: on
line diff
--- a/benchmark/benchmark_laplace.jl Sat Apr 13 23:44:56 2024 +0200 +++ b/benchmark/benchmark_laplace.jl Sat Apr 13 23:49:39 2024 +0200 @@ -10,7 +10,7 @@ function benchmark_const_coeff_1d(;N = 100, order = 4) stencil_set = read_stencil_set(operator_path; order=order) - g = equidistant_grid(N, 0., 1.) + g = equidistant_grid(0., 1., N) D = second_derivative(g, stencil_set) u = rand(size(g)...) u_xx = rand(size(g)...) @@ -25,7 +25,7 @@ function benchmark_var_coeff_1d(;N = 100, order = 4) stencil_set = read_stencil_set(operator_path; order=order) - g = equidistant_grid(N, 0., 1.) + g = equidistant_grid(0., 1., N) c = rand(size(g)...) c_lz = eval_on(g, x -> 0.5) D = second_derivative_variable(g, c, stencil_set) @@ -49,7 +49,7 @@ function benchmark_const_coeff_2d(;N = 100, order = 4) stencil_set = read_stencil_set(operator_path; order=order) - g = equidistant_grid((N,N), (0.,0.,),(1.,1.)) + g = equidistant_grid((0.,0.,),(1.,1.), N, N) D = Laplace(g, stencil_set) u = rand(size(g)...) u_xx = rand(size(g)...) @@ -71,7 +71,7 @@ function benchmark_var_coeff_2d(;N = 100, order = 4) stencil_set = read_stencil_set(operator_path; order=order) - g = equidistant_grid((N,N), (0.,0.,),(1.,1.)) + g = equidistant_grid((0.,0.,),(1.,1.), N, N) c = rand(size(g)...) c_lz = eval_on(g, x-> 0.5) D = second_derivative_variable(g, c, stencil_set, 1) + second_derivative_variable(g, c, stencil_set, 2) @@ -217,4 +217,4 @@ for I ∈ @view CartesianIndices(u)[end-clz_sz+1:end,end-clz_sz+1:end] u_xx[I] = tm[Index{Upper}(I[1]),Index{Upper}(I[2])] end -end \ No newline at end of file +end
--- a/benchmark/benchmarks.jl Sat Apr 13 23:44:56 2024 +0200 +++ b/benchmark/benchmarks.jl Sat Apr 13 23:49:39 2024 +0200 @@ -15,9 +15,9 @@ ll(d) = ntuple(i->0., d) lu(d) = ntuple(i->1., d) -g1 = equidistant_grid(sz(1)[1],ll(1)[1],lu(1)[1]) -g2 = equidistant_grid(sz(2),ll(2),lu(2)) -g3 = equidistant_grid(sz(3),ll(3),lu(3)) +g1 = equidistant_grid(ll(1)[1], lu(1)[1], sz(1)[1]) +g2 = equidistant_grid(ll(2), lu(2), sz(2)) +g3 = equidistant_grid(ll(3), lu(3), sz(3)) v1 = rand(sz(1)...) v2 = rand(sz(2)...)
--- a/src/Grids/equidistant_grid.jl Sat Apr 13 23:44:56 2024 +0200 +++ b/src/Grids/equidistant_grid.jl Sat Apr 13 23:49:39 2024 +0200 @@ -88,7 +88,7 @@ """ - equidistant_grid(size::Dims, limit_lower, limit_upper) + equidistant_grid(limit_lower, limit_upper, dims...) Construct an equidistant grid with corners at the coordinates `limit_lower` and `limit_upper`. @@ -99,24 +99,24 @@ of the grid are not allowed to be negative. The number of equispaced points in each coordinate direction are given -by the tuple `size`. +by the tuple `dims`. -Note: If `limit_lower` and `limit_upper` are integers and `size` would allow a +Note: If `limit_lower` and `limit_upper` are integers and `dims` would allow a completely integer grid, `equidistant_grid` will still return a floating point grid. This simplifies the implementation and avoids certain surprise behaviors. """ -function equidistant_grid(size::Dims, limit_lower, limit_upper) - gs = map(equidistant_grid, size, limit_lower, limit_upper) +function equidistant_grid(limit_lower, limit_upper, dims::Vararg{Int}) + gs = map(equidistant_grid, limit_lower, limit_upper, dims) return TensorGrid(gs...) end """ - equidistant_grid(size::Int, limit_lower::T, limit_upper::T) + equidistant_grid(limit_lower::T, limit_upper::T, size::Int) Constructs a 1D equidistant grid. """ -function equidistant_grid(size::Int, limit_lower::T, limit_upper::T) where T +function equidistant_grid(limit_lower::T, limit_upper::T, size::Int) where T if any(size .<= 0) throw(DomainError("size must be postive")) end
--- a/test/Grids/equidistant_grid_test.jl Sat Apr 13 23:44:56 2024 +0200 +++ b/test/Grids/equidistant_grid_test.jl Sat Apr 13 23:49:39 2024 +0200 @@ -105,34 +105,34 @@ @testset "equidistant_grid" begin - @test equidistant_grid(4,0.0,1.0) isa EquidistantGrid - @test equidistant_grid((4,3),(0.0,0.0),(8.0,5.0)) isa TensorGrid + @test equidistant_grid(0.0,1.0, 4) isa EquidistantGrid + @test equidistant_grid((0.0,0.0),(8.0,5.0), 4, 3) isa TensorGrid # constuctor - @test_throws DomainError equidistant_grid(0,0.0,1.0) - @test_throws DomainError equidistant_grid(1,1.0,1.0) - @test_throws DomainError equidistant_grid(1,1.0,-1.0) + @test_throws DomainError equidistant_grid(0.0, 1.0, 0) + @test_throws DomainError equidistant_grid(1.0, 1.0, 1) + @test_throws DomainError equidistant_grid(1.0, -1.0, 1) - @test_throws DomainError equidistant_grid((0,0),(0.0,0.0),(1.0,1.0)) - @test_throws DomainError equidistant_grid((1,1),(1.0,1.0),(1.0,1.0)) - @test_throws DomainError equidistant_grid((1,1),(1.0,1.0),(-1.0,-1.0)) + @test_throws DomainError equidistant_grid((0.0,0.0),(1.0,1.0), 0, 0) + @test_throws DomainError equidistant_grid((1.0,1.0),(1.0,1.0), 1, 1) + @test_throws DomainError equidistant_grid((1.0,1.0),(-1.0,-1.0), 1, 1) @testset "Base" begin - @test eltype(equidistant_grid(4,0.0,1.0)) == Float64 - @test eltype(equidistant_grid((4,3),(0,0),(1,3))) <: AbstractVector{Float64} + @test eltype(equidistant_grid(0.0, 1.0, 4)) == Float64 + @test eltype(equidistant_grid((0,0),(1,3), 4, 3)) <: AbstractVector{Float64} - @test size(equidistant_grid(4,0.0,1.0)) == (4,) - @test size(equidistant_grid((5,3), (0.0,0.0), (2.0,1.0))) == (5,3) + @test size(equidistant_grid(0.0, 1.0, 4)) == (4,) + @test size(equidistant_grid((0.0,0.0), (2.0,1.0), 5, 3)) == (5,3) - @test size(equidistant_grid((5,3), (0.0,0.0), (2.0,1.0)),1) == 5 - @test size(equidistant_grid((5,3), (0.0,0.0), (2.0,1.0)),2) == 3 + @test size(equidistant_grid((0.0,0.0), (2.0,1.0), 5, 3), 1) == 5 + @test size(equidistant_grid((0.0,0.0), (2.0,1.0), 5, 3), 2) == 3 - @test ndims(equidistant_grid(4,0.0,1.0)) == 1 - @test ndims(equidistant_grid((5,3), (0.0,0.0), (2.0,1.0))) == 2 + @test ndims(equidistant_grid(0.0, 1.0, 4)) == 1 + @test ndims(equidistant_grid((0.0,0.0), (2.0,1.0), 5, 3)) == 2 end @testset "getindex" begin - g = equidistant_grid((5,3), (-1.0,0.0), (0.0,7.11)) + g = equidistant_grid((-1.0,0.0), (0.0,7.11), 5, 3) gp = collect(g); p = [(-1.,0.) (-1.,7.11/2) (-1.,7.11); (-0.75,0.) (-0.75,7.11/2) (-0.75,7.11);
--- a/test/Grids/grid_test.jl Sat Apr 13 23:44:56 2024 +0200 +++ b/test/Grids/grid_test.jl Sat Apr 13 23:49:39 2024 +0200 @@ -47,7 +47,7 @@ @test eval_on(EquidistantGrid(range(0,1,length=4)), x->2x) == 2 .* range(0,1,length=4) - g = equidistant_grid((5,3), (0.0,0.0), (2.0,1.0)) + g = equidistant_grid((0.0,0.0), (2.0,1.0), 5, 3) @test eval_on(g, x̄ -> 0.) isa LazyArray @test eval_on(g, x̄ -> 0.) == fill(0., (5,3))
--- a/test/SbpOperators/boundaryops/boundary_restriction_test.jl Sat Apr 13 23:44:56 2024 +0200 +++ b/test/SbpOperators/boundaryops/boundary_restriction_test.jl Sat Apr 13 23:49:39 2024 +0200 @@ -9,8 +9,8 @@ @testset "boundary_restriction" begin stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order = 4) e_closure = parse_stencil(stencil_set["e"]["closure"]) - g_1D = equidistant_grid(11, 0.0, 1.0) - g_2D = equidistant_grid((11,15), (0.0, 0.0), (1.0,1.0)) + g_1D = equidistant_grid(0.0, 1.0, 11) + g_2D = equidistant_grid((0.0, 0.0), (1.0,1.0), 11, 15) @testset "boundary_restriction" begin @testset "1D" begin
--- a/test/SbpOperators/boundaryops/normal_derivative_test.jl Sat Apr 13 23:44:56 2024 +0200 +++ b/test/SbpOperators/boundaryops/normal_derivative_test.jl Sat Apr 13 23:49:39 2024 +0200 @@ -7,8 +7,8 @@ import Sbplib.SbpOperators.BoundaryOperator @testset "normal_derivative" begin - g_1D = equidistant_grid(11, 0.0, 1.0) - g_2D = equidistant_grid((11,12), (0.0, 0.0), (1.0,1.0)) + g_1D = equidistant_grid(0.0, 1.0, 11) + g_2D = equidistant_grid((0.0, 0.0), (1.0,1.0), 11, 12) @testset "normal_derivative" begin stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) @testset "1D" begin
--- a/test/SbpOperators/volumeops/constant_interior_scaling_operator_test.jl Sat Apr 13 23:44:56 2024 +0200 +++ b/test/SbpOperators/volumeops/constant_interior_scaling_operator_test.jl Sat Apr 13 23:49:39 2024 +0200 @@ -33,7 +33,7 @@ @test_throws DomainError ConstantInteriorScalingOperator(4,(2,3), 3) @testset "Grid constructor" begin - g = equidistant_grid(11, 0., 2.) + g = equidistant_grid(0., 2., 11) @test ConstantInteriorScalingOperator(g, 3., (.1,.2)) isa ConstantInteriorScalingOperator{Float64} end end
--- a/test/SbpOperators/volumeops/derivatives/dissipation_test.jl Sat Apr 13 23:44:56 2024 +0200 +++ b/test/SbpOperators/volumeops/derivatives/dissipation_test.jl Sat Apr 13 23:49:39 2024 +0200 @@ -27,7 +27,7 @@ end @testset "undivided_skewed04" begin - g = equidistant_grid(20, 0., 11.) + g = equidistant_grid(0., 11., 20) D,Dᵀ = undivided_skewed04(g, 1) @test D isa LazyTensor{Float64,1,1} @@ -35,7 +35,7 @@ @testset "Accuracy conditions" begin N = 20 - g = equidistant_grid(N, 0//1,2//1) + g = equidistant_grid(0//1, 2//1, N) h = only(spacing(g)) @testset "D_$p" for p ∈ [1,2,3,4] D,Dᵀ = undivided_skewed04(g, p) @@ -67,7 +67,7 @@ return Dmat end - g = equidistant_grid(11, 0., 1.) + g = equidistant_grid(0., 1., 11) @testset "D_$p" for p ∈ [1,2,3,4] D,Dᵀ = undivided_skewed04(g, p) @@ -80,7 +80,7 @@ @testset "2D" begin N = 20 - g = equidistant_grid((N,2N), (0,0), (2,1)) + g = equidistant_grid((0,0), (2,1), N, 2N) h = spacing.(g.grids) D,Dᵀ = undivided_skewed04(g, 3, 2)
--- a/test/SbpOperators/volumeops/derivatives/first_derivative_test.jl Sat Apr 13 23:44:56 2024 +0200 +++ b/test/SbpOperators/volumeops/derivatives/first_derivative_test.jl Sat Apr 13 23:49:39 2024 +0200 @@ -24,8 +24,8 @@ @testset "Constructors" begin stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) - g₁ = equidistant_grid(11, 0., 1.) - g₂ = equidistant_grid((11,14), (0.,1.), (1.,3.)) + g₁ = equidistant_grid(0., 1., 11) + g₂ = equidistant_grid((0.,1.), (1.,3.), 11, 14) @test first_derivative(g₁, stencil_set) isa LazyTensor{Float64,1,1} @test first_derivative(g₂, stencil_set, 2) isa LazyTensor{Float64,2,2} @@ -38,7 +38,7 @@ @testset "Accuracy conditions" begin N = 20 - g = equidistant_grid(N, 0//1,2//1) + g = equidistant_grid(0//1, 2//1, N) @testset for order ∈ [2,4] stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order) D₁ = first_derivative(g, stencil_set) @@ -68,7 +68,7 @@ @testset "Accuracy on function" begin @testset "1D" begin - g = equidistant_grid(30, 0.,1.) + g = equidistant_grid(0., 1., 30) v = eval_on(g, x->exp(x)) @testset for (order, tol) ∈ [(2, 6e-3),(4, 2e-4)] stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order) @@ -79,7 +79,7 @@ end @testset "2D" begin - g = equidistant_grid((30,60), (0.,0.),(1.,2.)) + g = equidistant_grid((0.,0.),(1.,2.), 30, 60) v = eval_on(g, (x,y)->exp(0.8x+1.2*y)) @testset for (order, tol) ∈ [(2, 6e-3),(4, 3e-4)] stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order)
--- a/test/SbpOperators/volumeops/derivatives/second_derivative_test.jl Sat Apr 13 23:44:56 2024 +0200 +++ b/test/SbpOperators/volumeops/derivatives/second_derivative_test.jl Sat Apr 13 23:49:39 2024 +0200 @@ -15,8 +15,8 @@ closure_stencils = parse_stencil.(stencil_set["D2"]["closure_stencils"]) Lx = 3.5 Ly = 3. - g_1D = equidistant_grid(121, 0.0, Lx) - g_2D = equidistant_grid((121,123), (0.0, 0.0), (Lx, Ly)) + g_1D = equidistant_grid(0.0, Lx, 121) + g_2D = equidistant_grid((0.0, 0.0), (Lx, Ly), 121, 123) @testset "Constructors" begin @testset "1D" begin
--- a/test/SbpOperators/volumeops/derivatives/second_derivative_variable_test.jl Sat Apr 13 23:44:56 2024 +0200 +++ b/test/SbpOperators/volumeops/derivatives/second_derivative_variable_test.jl Sat Apr 13 23:49:39 2024 +0200 @@ -12,7 +12,7 @@ stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) @testset "1D" begin - g = equidistant_grid(11, 0., 1.) + g = equidistant_grid(0., 1., 11) c = [ 1., 3., 6., 10., 15., 21., 28., 36., 45., 55., 66.] @testset "checking c" begin @@ -27,7 +27,7 @@ @testset "application" begin function apply_to_functions(; v, c) - g = equidistant_grid(11, 0., 10.) # h = 1 + g = equidistant_grid(0., 10., 11) # h = 1 c̄ = eval_on(g,c) v̄ = eval_on(g,v) @@ -44,12 +44,12 @@ end @testset "2D" begin - g = equidistant_grid((11,9), (0.,0.), (10.,8.)) # h = 1 + g = equidistant_grid((0.,0.), (10.,8.), 11, 9) # h = 1 c = eval_on(g, (x,y)->x+y) @testset "application" begin function apply_to_functions(dir; v, c) - g = equidistant_grid((11,9), (0.,0.), (10.,8.)) # h = 1 + g = equidistant_grid((0.,0.), (10.,8.), 11, 9) # h = 1 c̄ = eval_on(g,c) v̄ = eval_on(g,v) @@ -89,7 +89,7 @@ Dxv(x,y) = cos(x)*exp(x) - (exp(x) + exp(1.5 - 1.5y))*sin(x) Dyv(x,y) = -1.5(1.5exp(x) + 1.5exp(1.5 - 1.5y))*cos(1.5 - 1.5y) - 2.25exp(1.5 - 1.5y)*sin(1.5 - 1.5y) - g₁ = equidistant_grid((60,67), (0.,0.), (1.,2.)) + g₁ = equidistant_grid((0.,0.), (1.,2.), 60, 67) g₂ = refine(g₁,2) c̄₁ = eval_on(g₁, c) @@ -155,7 +155,7 @@ @testset "application" begin function apply_to_functions(; v, c) - g = equidistant_grid(11, 0., 10.) # h = 1 + g = equidistant_grid(0., 10., 11) # h = 1 c̄ = eval_on(g,c) v̄ = eval_on(g,v) @@ -171,7 +171,7 @@ end @testset "type stability" begin - g = equidistant_grid(11, 0., 10.) # h = 1 + g = equidistant_grid(0., 10., 11) # h = 1 c̄ = eval_on(g,x-> -1) v̄ = eval_on(g,x->1.) @@ -185,7 +185,7 @@ end @testset "2D" begin - g = equidistant_grid((11,9), (0.,0.), (10.,8.)) # h = 1 + g = equidistant_grid((0.,0.), (10.,8.), 11, 9) # h = 1 c = eval_on(g, (x,y)->x+y) @testset "Constructors" begin @test SecondDerivativeVariable(c, interior_stencil, closure_stencils, 1) isa LazyTensor @@ -210,7 +210,7 @@ @testset "application" begin function apply_to_functions(dir; v, c) - g = equidistant_grid((11,9), (0.,0.), (10.,8.)) # h = 1 + g = equidistant_grid((0.,0.), (10.,8.), 11, 9) # h = 1 c̄ = eval_on(g,c) v̄ = eval_on(g,v)
--- a/test/SbpOperators/volumeops/inner_products/inner_product_test.jl Sat Apr 13 23:44:56 2024 +0200 +++ b/test/SbpOperators/volumeops/inner_products/inner_product_test.jl Sat Apr 13 23:49:39 2024 +0200 @@ -10,9 +10,9 @@ Lx = π/2. Ly = Float64(π) Lz = 1. - g_1D = equidistant_grid(77, 0.0, Lx) - g_2D = equidistant_grid((77,66), (0.0, 0.0), (Lx,Ly)) - g_3D = equidistant_grid((10,10, 10), (0.0, 0.0, 0.0), (Lx,Ly,Lz)) + g_1D = equidistant_grid(0.0, Lx, 77) + g_2D = equidistant_grid((0.0, 0.0), (Lx,Ly), 77, 66) + g_3D = equidistant_grid((0.0, 0.0, 0.0), (Lx,Ly,Lz), 10, 10, 10) @testset "inner_product" begin stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) @testset "0D" begin
--- a/test/SbpOperators/volumeops/inner_products/inverse_inner_product_test.jl Sat Apr 13 23:44:56 2024 +0200 +++ b/test/SbpOperators/volumeops/inner_products/inverse_inner_product_test.jl Sat Apr 13 23:49:39 2024 +0200 @@ -9,8 +9,8 @@ @testset "Diagonal-stencil inverse_inner_product" begin Lx = π/2. Ly = Float64(π) - g_1D = equidistant_grid(77, 0.0, Lx) - g_2D = equidistant_grid((77,66), (0.0, 0.0), (Lx,Ly)) + g_1D = equidistant_grid(0.0, Lx, 77) + g_2D = equidistant_grid((0.0, 0.0), (Lx,Ly), 77, 66) @testset "inverse_inner_product" begin stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4) @testset "0D" begin
--- a/test/SbpOperators/volumeops/laplace/laplace_test.jl Sat Apr 13 23:44:56 2024 +0200 +++ b/test/SbpOperators/volumeops/laplace/laplace_test.jl Sat Apr 13 23:49:39 2024 +0200 @@ -8,8 +8,8 @@ # Default stencils (4th order) operator_path = sbp_operators_path()*"standard_diagonal.toml" stencil_set = read_stencil_set(operator_path; order=4) - g_1D = equidistant_grid(101, 0.0, 1.) - g_3D = equidistant_grid((51,101,52), (0.0, -1.0, 0.0), (1., 1., 1.)) + g_1D = equidistant_grid(0.0, 1., 101) + g_3D = equidistant_grid((0.0, -1.0, 0.0), (1., 1., 1.), 51, 101, 52) @testset "Constructors" begin @testset "1D" begin @@ -69,8 +69,8 @@ @testset "laplace" begin operator_path = sbp_operators_path()*"standard_diagonal.toml" stencil_set = read_stencil_set(operator_path; order=4) - g_1D = equidistant_grid(101, 0.0, 1.) - g_3D = equidistant_grid((51,101,52), (0.0, -1.0, 0.0), (1., 1., 1.)) + g_1D = equidistant_grid(0.0, 1., 101) + g_3D = equidistant_grid((0.0, -1.0, 0.0), (1., 1., 1.), 51, 101, 52) @testset "1D" begin Δ = laplace(g_1D, stencil_set)
--- a/test/SbpOperators/volumeops/stencil_operator_distinct_closures_test.jl Sat Apr 13 23:44:56 2024 +0200 +++ b/test/SbpOperators/volumeops/stencil_operator_distinct_closures_test.jl Sat Apr 13 23:49:39 2024 +0200 @@ -8,7 +8,7 @@ import Sbplib.SbpOperators.StencilOperatorDistinctClosures @testset "StencilOperatorDistinctClosures" begin - g = equidistant_grid(11, 0., 1.) + g = equidistant_grid(0., 1., 11) lower_closure = ( Stencil(-1,1, center=1),
--- a/test/SbpOperators/volumeops/volume_operator_test.jl Sat Apr 13 23:44:56 2024 +0200 +++ b/test/SbpOperators/volumeops/volume_operator_test.jl Sat Apr 13 23:49:39 2024 +0200 @@ -14,7 +14,7 @@ @testset "VolumeOperator" begin inner_stencil = CenteredStencil(1/4, 2/4, 1/4) closure_stencils = (Stencil(1/2, 1/2; center=1), Stencil(2.,1.; center=2)) - g = equidistant_grid(11,0.,1.) + g = equidistant_grid(0.,1., 11) @testset "Constructors" begin op = VolumeOperator(inner_stencil,closure_stencils,(11,),even)