comparison test/SbpOperators/volumeops/laplace/laplace_test.jl @ 2055:274f4c1ce4b5 feature/sbp_operators/laplace_curvilinear tip

Add test for SBP property of laplace in mapped grid
author Jonatan Werpers <jonatan@werpers.com>
date Sun, 08 Feb 2026 00:05:40 +0100
parents f3d7e2d7a43f
children
comparison
equal deleted inserted replaced
2054:c08bc343d1cd 2055:274f4c1ce4b5
3 using Diffinitive.SbpOperators 3 using Diffinitive.SbpOperators
4 using Diffinitive.Grids 4 using Diffinitive.Grids
5 using Diffinitive.LazyTensors 5 using Diffinitive.LazyTensors
6 6
7 using StaticArrays 7 using StaticArrays
8 using SparseArrays
9 using Tokens
10 using LinearAlgebra
8 11
9 @testset "Laplace" begin 12 @testset "Laplace" begin
10 # Default stencils (4th order) 13 # Default stencils (4th order)
11 operator_path = sbp_operators_path()*"standard_diagonal.toml" 14 operator_path = sbp_operators_path()*"standard_diagonal.toml"
12 stencil_set = read_stencil_set(operator_path; order=4) 15 stencil_set = read_stencil_set(operator_path; order=4)
105 108
106 Δ = laplace(g, stencil_set) 109 Δ = laplace(g, stencil_set)
107 110
108 @test collect(Δ*gf) isa Array{<:Any,2} 111 @test collect(Δ*gf) isa Array{<:Any,2}
109 @test Δ*gf ≈ map(Δf, g) rtol=2e-2 112 @test Δ*gf ≈ map(Δf, g) rtol=2e-2
113
114
115 @testset "SBP property" begin
116 g = equidistant_grid(c, 20,20)
117 Δ = laplace(g, stencil_set)
118 H = inner_product(g, stencil_set)
119 es = map(boundary_identifiers(g)) do id
120 boundary_restriction(g, stencil_set, id)
121 end
122 ds = map(boundary_identifiers(g)) do id
123 normal_derivative(g, stencil_set, id)
124 end
125 Hᵧs = map(boundary_identifiers(g)) do id
126 inner_product(boundary_grid(g, id), stencil_set)
127 end
128
129 BT = mapreduce(+, es, ds,Hᵧs) do e, d, Hᵧ
130 e'∘Hᵧ∘d
131 end
132 M = -H∘Δ + BT
133
134 M = sparse(M)
135 @test M ≈ M'
136
137 function issemiposdef(A, tol=1e-8)
138 return isposdef(A+tol*I)
139 end
140
141 @test issemiposdef(Symmetric(M))
142 end
110 end 143 end
111 end 144 end
112 145
113 @testset "sat_tensors" begin 146 @testset "sat_tensors" begin
114 # TODO: The following tests should be implemented 147 # TODO: The following tests should be implemented