Mercurial > repos > public > sbplib_julia
comparison benchmarks/laplace_benchmark.jl @ 876:4f3924293894 laplace_benchmarks
Add examples and benchmarks folders
author | Vidar Stiernström <vidar.stiernstrom@it.uu.se> |
---|---|
date | Thu, 27 Jan 2022 11:00:31 +0100 |
parents | laplace_benchmark.jl@9929c99754fb |
children |
comparison
equal
deleted
inserted
replaced
875:067a322e4f73 | 876:4f3924293894 |
---|---|
1 using Sbplib.Grids, Sbplib.SbpOperators, Sbplib.LazyTensors, Sbplib.RegionIndices | |
2 using Profile, BenchmarkTools | |
3 | |
4 function apply_laplace!(f, u, L, inds) | |
5 for I in inds | |
6 f[I] = (L*u)[I] | |
7 end | |
8 end | |
9 | |
10 apply_laplace!(f, u, L) = apply_laplace!(f, u, L, eachindex(u)) | |
11 | |
12 region_indices(L, N, ::Lower) = map(x->Index{Lower}(x),1:closure_size(L)) | |
13 region_indices(L, N, ::Interior) = map(x->Index{Interior}(x),closure_size(L)+1:N-closure_size(L)) | |
14 region_indices(L, N, ::Upper) = map(x->Index{Upper}(x),N-closure_size(L)+1:N) | |
15 | |
16 function get_region_indices(L,N) | |
17 ind_lower = region_indices(L, N, Lower()) | |
18 ind_interior = region_indices(L, N, Interior()) | |
19 ind_upper = region_indices(L, N, Upper()) | |
20 return (ind_lower, ind_interior, ind_upper) | |
21 end | |
22 | |
23 function apply_laplace_regions!(f, u, L, region_inds) | |
24 apply_laplace!(f, u, L, region_inds[1]) | |
25 apply_laplace!(f, u, L, region_inds[2]) | |
26 apply_laplace!(f, u, L, region_inds[3]) | |
27 end | |
28 | |
29 # Domain | |
30 N = 4001 | |
31 g = EquidistantGrid(N,0.,1.) | |
32 | |
33 # Operators | |
34 L = Laplace(g,sbp_operators_path()*"standard_diagonal.toml"; order=4) | |
35 u = evalOn(g,x->x^2) | |
36 f = similar(u) | |
37 | |
38 apply_laplace!(f,u,L) #ensure compilation | |
39 @btime apply_laplace!(f,u,L) | |
40 rinds = get_region_indices(L,N) | |
41 apply_laplace_regions!(f,u,L,rinds) #ensure compilation | |
42 @btime apply_laplace_regions!(f,u,L,rinds) |