comparison notebooks/display_examples_nb.jl @ 2074:8fe7233067fb feature/sbp_operators/laplace_curvilinear

Merge feature/grids/geometry_functions
author Jonatan Werpers <jonatan@werpers.com>
date Tue, 17 Feb 2026 21:01:50 +0100
parents a8ea4f94f3c4
children
comparison
equal deleted inserted replaced
2055:274f4c1ce4b5 2074:8fe7233067fb
1 ### A Pluto.jl notebook ###
2 # v0.20.21
3
4 using Markdown
5 using InteractiveUtils
6
7 # ╔═╡ 1f8a7cfa-94cc-41bf-a8c8-2dc5218741e0
8 begin
9 using Pkg
10 Pkg.activate(".")
11
12 using Diffinitive
13 using Diffinitive.Grids
14 using Diffinitive.LazyTensors
15 using Diffinitive.SbpOperators
16 using PlutoUI
17 using StaticArrays
18 end
19
20 # ╔═╡ 885c60d7-d33c-4741-ae49-6a57510ec7b5
21 md"""
22 # Display tests
23 """
24
25 # ╔═╡ 9ee3372a-e78d-4f74-84ce-e04208d1558d
26 repl_show(v) = repr(MIME("text/plain"), v) |> println
27
28 # ╔═╡ 51c02ced-f684-417f-83f1-cade4edda43f
29 md"""
30 Common julia objects to compare with:
31 """
32
33 # ╔═╡ 25c90528-22cd-41ca-8572-ccd946928318
34 1 |> repl_show
35
36 # ╔═╡ e7f3e466-9833-428c-99ad-20bc9d88d951
37 [1,1] |> repl_show
38
39 # ╔═╡ 2e74f9b5-5b4f-4887-8a30-4655d560a45c
40 [1;; 2;;] |> repl_show
41
42 # ╔═╡ 365524b5-3182-4691-9817-1bbec1492c14
43 [1; 2;;] |> repl_show
44
45 # ╔═╡ d5725e1b-bc4f-4a95-975d-179c193908c9
46 [1; 2;; 3; 4;;] |> repl_show
47
48 # ╔═╡ b824ef8d-5026-4861-9a23-45a7939fd38c
49 "hej" |> repl_show
50
51 # ╔═╡ fbe365a2-f95e-4297-8326-c18d22932869
52 Dict("A" => 1, "B"=> 2) |> repl_show
53
54 # ╔═╡ 56670aff-0343-41cb-a653-35a61376dda4
55 1//2 |> repl_show
56
57 # ╔═╡ b5a6491e-a93e-4058-8ceb-be1dc4d4c100
58 BigInt(30) |> repl_show
59
60 # ╔═╡ 828d57a1-ee58-4204-8050-78127821a4c6
61 1:10 |> repl_show
62
63 # ╔═╡ 127d34f6-69f7-4082-a74b-0be86942f153
64 range(0,1,10) |> repl_show
65
66 # ╔═╡ c46a278e-a102-4544-82d8-7df816440410
67 rand(2,2,2,2) |> repl_show
68
69 # ╔═╡ 5aa7079c-8005-47f1-bb82-c35f3aa54b42
70 md"""
71 ## Parameter spaces
72 """
73
74 # ╔═╡ 08f493ed-189c-43f3-86f2-95fc475ec0e7
75 Interval(1,2) |> repl_show
76
77 # ╔═╡ e2dc581f-0949-4be7-8e4b-74deeaffc68d
78 md"""
79 ## Stencil Set
80 """
81
82 # ╔═╡ 272e564f-bd21-4ba2-8d6e-ae4714dc30bc
83 read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2) |> repl_show
84
85 # ╔═╡ f7244bf7-8266-469f-b07f-30c203d9af48
86 md"""
87 ## Grids
88 """
89
90 # ╔═╡ 0e14bd28-5dd1-44c4-abf4-23b70546bd49
91 equidistant_grid(0,1,11) |> repl_show
92
93 # ╔═╡ fcb74341-6b03-4ada-8f5d-bc245c23679b
94 equidistant_grid((0,0),(1,1),10,20) |> repl_show
95
96 # ╔═╡ 8dec053b-eaae-463d-800b-b8d89d5d550b
97 ZeroDimGrid(@SVector[1,2]) |> repl_show
98
99 # ╔═╡ c1172a36-c5d7-47dc-bc79-af0d43a8f6ee
100 let
101 x̄((ξ, η)) = @SVector[2ξ + η*(1-η), 3η+(1+η/2)*ξ^2]
102 J((ξ, η)) = @SMatrix[
103 2 1-2η;
104 (2+η)*ξ 3+1/2*ξ^2;
105 ]
106
107 mapped_grid(x̄, J, 10,10) |> repl_show
108 end
109
110 # ╔═╡ 9c889176-865b-402d-81b5-71957d2878f7
111 md"""
112 ## LazyArrays
113 """
114
115 # ╔═╡ 85e8e748-e575-4a29-80c7-22d110578343
116 LazyTensors.LazyConstantArray(10, (5,)) |> repl_show
117
118 # ╔═╡ 804ad722-9081-4d1d-b0d2-c536a26fe20d
119 LazyTensors.LazyFunctionArray((i,j)->10*i+j, (3,4)) |> repl_show
120
121 # ╔═╡ a70c689d-0851-497f-938a-e5c92ce59ddb
122 md"""
123 ## LazyTensors
124 """
125
126 # ╔═╡ 68c7a1d8-729e-4f38-abf2-26deb7a90cb1
127 md"""
128 ### Basic tensors
129 """
130
131 # ╔═╡ 2afde3fe-96ed-4d7e-a79b-fc880e0da268
132 LazyTensors.IdentityTensor(5) |> repl_show
133
134 # ╔═╡ 5451a071-14ae-47ae-99c5-4d65508d280f
135 LazyTensors.IdentityTensor(4,3) |> repl_show
136
137 # ╔═╡ b6b06fe9-de16-41ca-ad45-eef6dd038485
138 LazyTensors.ScalingTensor(2., (4,3)) |> repl_show
139
140 # ╔═╡ d1c8c3a0-76ec-4c32-853e-0471d71e5cf0
141 LazyTensors.DiagonalTensor([1,2,3,4]) |> repl_show
142
143 # ╔═╡ 6051c144-9982-4bd9-92f9-d0aaf3961872
144 LazyTensors.DenseTensor(rand(2,2,2,2), (1,2), (3,4)) |> repl_show
145
146 # ╔═╡ 83ed7f7e-c88d-4ee4-a53a-1b91e775ff52
147 md"""
148 ### Simple SBP-operators
149 """
150
151 # ╔═╡ 12a9f430-f96b-43f2-bf63-149b5a028fd7
152 begin
153 g1 = equidistant_grid(0,1,10)
154 g2 = equidistant_grid((0,0),(1,1),10, 11)
155 x̄((ξ, η)) = @SVector[2ξ + η*(1-η), 3η+(1+η/2)*ξ^2]
156 J((ξ, η)) = @SMatrix[
157 2 1-2η;
158 (2+η)*ξ 3+1/2*ξ^2;
159 ]
160 mg = mapped_grid(x̄, J, 10,10)
161 stencil_set2 = stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=2)
162 stencil_set4 = stencil_set = read_stencil_set(sbp_operators_path()*"standard_diagonal.toml"; order=4)
163 end;
164
165 # ╔═╡ e44f8d91-1cbf-44be-bef1-40e60c4a777f
166 first_derivative(g1, stencil_set2) |> repl_show
167
168 # ╔═╡ c378b88a-1d74-44a2-bdc1-b371da478de8
169 first_derivative(g1, stencil_set4) |> repl_show
170
171 # ╔═╡ 9614cda7-b48c-4925-89b5-113cf514f20f
172 first_derivative(g2, stencil_set2, 1) |> repl_show
173
174 # ╔═╡ 725e9430-4821-4939-bfef-6c186d2dc500
175 first_derivative(g2, stencil_set4, 2) |> repl_show
176
177 # ╔═╡ e8ca54a1-a6db-40a1-b44a-73e175894df4
178 second_derivative(g1, stencil_set2) |> repl_show
179
180 # ╔═╡ 5d1f10fe-f620-469c-822c-55955a5541ad
181 second_derivative(g1, stencil_set4) |> repl_show
182
183 # ╔═╡ fdc531d4-9d27-41dc-ba79-6febefde223a
184 second_derivative(g2, stencil_set2, 1) |> repl_show
185
186 # ╔═╡ fff2e04a-357f-4254-996e-d5ccd9ff31f8
187 second_derivative(g2, stencil_set4, 2) |> repl_show
188
189 # ╔═╡ 959b071e-1ef6-4f29-aa8b-d88bfef80c00
190 second_derivative_variable(g1, map(x->2x, g1), stencil_set2) |> repl_show
191
192 # ╔═╡ 0a0f7e77-a789-4fb3-a4c2-7853b67788ec
193 second_derivative_variable(g1, map(x->2x, g1), stencil_set4) |> repl_show
194
195 # ╔═╡ 177e0893-fbb1-4bb5-a108-e5990e943ab7
196 second_derivative_variable(g2, map(x->x[1]+x[2], g2), stencil_set2, 1) |> repl_show
197
198 # ╔═╡ f1b6bd54-baf6-4360-aec0-bd8d52497894
199 second_derivative_variable(g2, map(x->x[1]+x[2], g2), stencil_set4, 2) |> repl_show
200
201 # ╔═╡ a8f8343e-cd6f-451d-a2b3-e5f0f561f8af
202 undivided_skewed04(g1,4)[1] |> repl_show
203
204 # ╔═╡ 50291998-7194-4a0d-9c19-eacc48b3f5da
205 undivided_skewed04(g1,4)[2] |> repl_show
206
207 # ╔═╡ 1720af08-85e4-4502-b37e-9fa73008e221
208 undivided_skewed04(g2,4,1)[1] |> repl_show
209
210 # ╔═╡ 4a72f217-2423-4bc1-8452-eb28dde36689
211 undivided_skewed04(g2,4,2)[2] |> repl_show
212
213 # ╔═╡ d51b6bd7-0235-4a51-a989-4f7858363d02
214 md"""
215 ### Inner products
216 """
217
218 # ╔═╡ 48a28ade-73bb-461d-ab96-82f92ed199c8
219 inner_product(g1, stencil_set2) |> repl_show
220
221 # ╔═╡ 3c681a63-94a6-4677-aef7-df903c463896
222 inner_product(g1, stencil_set4) |> repl_show
223
224 # ╔═╡ db735370-153a-40f9-b77f-9f60e30a35c4
225 inner_product(g2, stencil_set2) |> repl_show
226
227 # ╔═╡ 613ebac7-50bc-424c-8fa2-064b64c93319
228 inner_product(g2, stencil_set4) |> repl_show
229
230 # ╔═╡ 9e7d7667-960e-491f-8b83-e3b01a0db5b0
231 inverse_inner_product(g2, stencil_set4) |> repl_show
232
233 # ╔═╡ 29488e48-1d42-4232-9d49-1ee77fb869d8
234 md"""
235 ### Boundary operators
236 """
237
238 # ╔═╡ c3005e74-5b96-4b0c-9c57-b7d02968ed94
239 boundary_restriction(g1, stencil_set, LowerBoundary()) |> repl_show
240
241 # ╔═╡ fd019973-0d54-4e31-b43b-f53a704cb01c
242 boundary_restriction(g1, stencil_set, UpperBoundary()) |> repl_show
243
244 # ╔═╡ df2e8af0-9ca5-4972-8771-f8bea1591f85
245 boundary_restriction(g2, stencil_set, CartesianBoundary{1,LowerBoundary}()) |> repl_show
246
247 # ╔═╡ 8e538109-16a1-4af7-a986-9dc1455b7de7
248 boundary_restriction(g2, stencil_set, CartesianBoundary{2,UpperBoundary}()) |> repl_show
249
250 # ╔═╡ 5f3744a4-72d8-4448-820f-a928bfaaf825
251 normal_derivative(g1, stencil_set, LowerBoundary()) |> repl_show
252
253 # ╔═╡ 4529b5c4-4905-4fd3-9aaa-5f88faa841c8
254 normal_derivative(g1, stencil_set, UpperBoundary()) |> repl_show
255
256 # ╔═╡ c3bb0450-a7d5-44c1-9ca9-9e1ecf2db9f8
257 normal_derivative(g2, stencil_set, CartesianBoundary{1,LowerBoundary}()) |> repl_show
258
259 # ╔═╡ da63e57a-0794-4cd8-9941-ada0e5c1c40e
260 normal_derivative(g2, stencil_set, CartesianBoundary{2,UpperBoundary}()) |> repl_show
261
262 # ╔═╡ 0b951425-979c-4ac9-8581-f690b729bab4
263 md"""
264 ## Tensor operations
265 """
266
267 # ╔═╡ a39bb6e2-f1fe-4206-8ee3-88ff0c075233
268 begin
269 Dx = first_derivative(g2, stencil_set2, 1)
270 Dy = first_derivative(g2, stencil_set4, 2)
271
272 v = map(x->sin(x[1]^2+x[2]^2), g2)
273 end;
274
275 # ╔═╡ 8cd052d9-f40e-4796-aeef-52c02b3bf156
276 Dx+Dy |> repl_show
277
278 # ╔═╡ 1b1b7d12-50ef-4c4e-9376-a353a56540c3
279 Dx∘Dy |> repl_show
280
281 # ╔═╡ 57e48b4c-eef6-433e-98a1-1006e844b368
282 Dx*v |> repl_show
283
284 # ╔═╡ e2bf2649-4770-4f52-9752-b61ce03c6f82
285 (Dx+Dy)*v |> repl_show
286
287 # ╔═╡ d163d363-853d-4d83-a2d3-f8dd6e8f552d
288 (Dx∘Dy)*v |> repl_show
289
290 # ╔═╡ 1c38d3f9-1839-468c-a368-4ef101bd4f18
291 laplace(g2, stencil_set2) |> repl_show
292
293 # ╔═╡ cf84cefb-2dbd-4b8d-880b-47cc350a7c43
294 laplace(g2, stencil_set4) |> repl_show
295
296 # ╔═╡ 67c73667-1f41-47b5-b59a-459787767f29
297 # laplace(mg, stencil_set2) |> repl_show
298
299 # ╔═╡ 4634c1a6-0520-4b0f-8d32-a1fdf2ebaea5
300 md"""
301 ## Appendix
302 """
303
304 # ╔═╡ 24788161-b29a-450a-bd35-f9c29e7ded9a
305 PlutoUI.TableOfContents()
306
307 # ╔═╡ Cell order:
308 # ╟─885c60d7-d33c-4741-ae49-6a57510ec7b5
309 # ╠═9ee3372a-e78d-4f74-84ce-e04208d1558d
310 # ╟─51c02ced-f684-417f-83f1-cade4edda43f
311 # ╠═25c90528-22cd-41ca-8572-ccd946928318
312 # ╠═e7f3e466-9833-428c-99ad-20bc9d88d951
313 # ╠═2e74f9b5-5b4f-4887-8a30-4655d560a45c
314 # ╠═365524b5-3182-4691-9817-1bbec1492c14
315 # ╠═d5725e1b-bc4f-4a95-975d-179c193908c9
316 # ╠═b824ef8d-5026-4861-9a23-45a7939fd38c
317 # ╠═fbe365a2-f95e-4297-8326-c18d22932869
318 # ╠═56670aff-0343-41cb-a653-35a61376dda4
319 # ╠═b5a6491e-a93e-4058-8ceb-be1dc4d4c100
320 # ╠═828d57a1-ee58-4204-8050-78127821a4c6
321 # ╠═127d34f6-69f7-4082-a74b-0be86942f153
322 # ╠═c46a278e-a102-4544-82d8-7df816440410
323 # ╟─5aa7079c-8005-47f1-bb82-c35f3aa54b42
324 # ╠═08f493ed-189c-43f3-86f2-95fc475ec0e7
325 # ╟─e2dc581f-0949-4be7-8e4b-74deeaffc68d
326 # ╠═272e564f-bd21-4ba2-8d6e-ae4714dc30bc
327 # ╟─f7244bf7-8266-469f-b07f-30c203d9af48
328 # ╠═0e14bd28-5dd1-44c4-abf4-23b70546bd49
329 # ╠═fcb74341-6b03-4ada-8f5d-bc245c23679b
330 # ╠═8dec053b-eaae-463d-800b-b8d89d5d550b
331 # ╠═c1172a36-c5d7-47dc-bc79-af0d43a8f6ee
332 # ╟─9c889176-865b-402d-81b5-71957d2878f7
333 # ╠═85e8e748-e575-4a29-80c7-22d110578343
334 # ╠═804ad722-9081-4d1d-b0d2-c536a26fe20d
335 # ╟─a70c689d-0851-497f-938a-e5c92ce59ddb
336 # ╟─68c7a1d8-729e-4f38-abf2-26deb7a90cb1
337 # ╠═2afde3fe-96ed-4d7e-a79b-fc880e0da268
338 # ╠═5451a071-14ae-47ae-99c5-4d65508d280f
339 # ╠═b6b06fe9-de16-41ca-ad45-eef6dd038485
340 # ╠═d1c8c3a0-76ec-4c32-853e-0471d71e5cf0
341 # ╠═6051c144-9982-4bd9-92f9-d0aaf3961872
342 # ╟─83ed7f7e-c88d-4ee4-a53a-1b91e775ff52
343 # ╠═12a9f430-f96b-43f2-bf63-149b5a028fd7
344 # ╠═e44f8d91-1cbf-44be-bef1-40e60c4a777f
345 # ╠═c378b88a-1d74-44a2-bdc1-b371da478de8
346 # ╠═9614cda7-b48c-4925-89b5-113cf514f20f
347 # ╠═725e9430-4821-4939-bfef-6c186d2dc500
348 # ╠═e8ca54a1-a6db-40a1-b44a-73e175894df4
349 # ╠═5d1f10fe-f620-469c-822c-55955a5541ad
350 # ╠═fdc531d4-9d27-41dc-ba79-6febefde223a
351 # ╠═fff2e04a-357f-4254-996e-d5ccd9ff31f8
352 # ╠═959b071e-1ef6-4f29-aa8b-d88bfef80c00
353 # ╠═0a0f7e77-a789-4fb3-a4c2-7853b67788ec
354 # ╠═177e0893-fbb1-4bb5-a108-e5990e943ab7
355 # ╠═f1b6bd54-baf6-4360-aec0-bd8d52497894
356 # ╠═a8f8343e-cd6f-451d-a2b3-e5f0f561f8af
357 # ╠═50291998-7194-4a0d-9c19-eacc48b3f5da
358 # ╠═1720af08-85e4-4502-b37e-9fa73008e221
359 # ╠═4a72f217-2423-4bc1-8452-eb28dde36689
360 # ╟─d51b6bd7-0235-4a51-a989-4f7858363d02
361 # ╠═48a28ade-73bb-461d-ab96-82f92ed199c8
362 # ╠═3c681a63-94a6-4677-aef7-df903c463896
363 # ╠═db735370-153a-40f9-b77f-9f60e30a35c4
364 # ╠═613ebac7-50bc-424c-8fa2-064b64c93319
365 # ╠═9e7d7667-960e-491f-8b83-e3b01a0db5b0
366 # ╟─29488e48-1d42-4232-9d49-1ee77fb869d8
367 # ╠═c3005e74-5b96-4b0c-9c57-b7d02968ed94
368 # ╠═fd019973-0d54-4e31-b43b-f53a704cb01c
369 # ╠═df2e8af0-9ca5-4972-8771-f8bea1591f85
370 # ╠═8e538109-16a1-4af7-a986-9dc1455b7de7
371 # ╠═5f3744a4-72d8-4448-820f-a928bfaaf825
372 # ╠═4529b5c4-4905-4fd3-9aaa-5f88faa841c8
373 # ╠═c3bb0450-a7d5-44c1-9ca9-9e1ecf2db9f8
374 # ╠═da63e57a-0794-4cd8-9941-ada0e5c1c40e
375 # ╟─0b951425-979c-4ac9-8581-f690b729bab4
376 # ╠═a39bb6e2-f1fe-4206-8ee3-88ff0c075233
377 # ╠═8cd052d9-f40e-4796-aeef-52c02b3bf156
378 # ╠═1b1b7d12-50ef-4c4e-9376-a353a56540c3
379 # ╠═57e48b4c-eef6-433e-98a1-1006e844b368
380 # ╠═e2bf2649-4770-4f52-9752-b61ce03c6f82
381 # ╠═d163d363-853d-4d83-a2d3-f8dd6e8f552d
382 # ╠═1c38d3f9-1839-468c-a368-4ef101bd4f18
383 # ╠═cf84cefb-2dbd-4b8d-880b-47cc350a7c43
384 # ╠═67c73667-1f41-47b5-b59a-459787767f29
385 # ╟─4634c1a6-0520-4b0f-8d32-a1fdf2ebaea5
386 # ╠═1f8a7cfa-94cc-41bf-a8c8-2dc5218741e0
387 # ╠═24788161-b29a-450a-bd35-f9c29e7ded9a