Line | Exclusive | Inclusive | Code |
---|---|---|---|
1 | macro timeout(seconds, expr, fail = nothing) | ||
2 | quote | ||
3 | tsk = @task $(esc(expr)) | ||
4 | schedule(tsk) | ||
5 | Timer($(esc(seconds))) do timer | ||
6 | istaskdone(tsk) || Base.throwto(tsk, InterruptException()) | ||
7 | end | ||
8 | try | ||
9 | fetch(tsk) | ||
10 | catch err | ||
11 | Base.printstyled("Timed Out.\n"; color = :red) | ||
12 | $(esc(fail)) | ||
13 | end | ||
14 | end | ||
15 | end | ||
16 | |||
17 | 1 (0 %) |
1 (0 %)
samples spent in brusselator_f
1 (100 %) (incl.) when called from brusselator_2d_loop line 49
1 (100 %)
samples spent calling
+
brusselator_f(x, y) = (((x - 3 // 10) ^ 2 + (y - 6 // 10) ^ 2) ≤ 0.01) * 5
|
|
18 | |||
19 | limit(a, N) = ifelse(a == N + 1, 1, ifelse(a == 0, N, a)) | ||
20 | |||
21 | function init_brusselator_2d(xyd, N) | ||
22 | N = length(xyd) | ||
23 | u = zeros(N, N, 2) | ||
24 | for I in CartesianIndices((N, N)) | ||
25 | x = xyd[I[1]] | ||
26 | y = xyd[I[2]] | ||
27 | u[I, 1] = 22 * (y * (1 - y))^(3 / 2) | ||
28 | u[I, 2] = 27 * (x * (1 - x))^(3 / 2) | ||
29 | end | ||
30 | return u | ||
31 | end | ||
32 | |||
33 | function generate_brusselator_problem(N::Int; sparsity = nothing, kwargs...) | ||
34 | xyd_brusselator = range(0; stop = 1, length = N) | ||
35 | |||
36 |
29 (11 %)
samples spent in brusselator_2d_loop
function brusselator_2d_loop(du_, u_, p)
29 (100 %) (incl.) when called from NonlinearFunction line 2356 |
||
37 | A, B, α, δx = p | ||
38 | α = α / δx ^ 2 | ||
39 | |||
40 | du = reshape(du_, N, N, 2) | ||
41 | u = reshape(u_, N, N, 2) | ||
42 | |||
43 | @inbounds for I in CartesianIndices((N, N)) | ||
44 | i, j = Tuple(I) | ||
45 | x, y = xyd_brusselator[I[1]], xyd_brusselator[I[2]] | ||
46 | ip1, im1 = limit(i + 1, N), limit(i - 1, N) | ||
47 | jp1, jm1 = limit(j + 1, N), limit(j - 1, N) | ||
48 | |||
49 | 16 (6 %) |
9 (56 %)
samples spent calling
*
du[i, j, 1] = α * (u[im1, j, 1] + u[ip1, j, 1] + u[i, jp1, 1] + u[i, jm1, 1] -
2 (12 %) samples spent calling + 1 (6 %) samples spent calling setindex! 1 (6 %) samples spent calling literal_pow 1 (6 %) samples spent calling getindex 1 (6 %) samples spent calling brusselator_f 1 (6 %) samples spent calling * |
|
50 | 4u[i, j, 1]) + | ||
51 | B + u[i, j, 1] ^ 2 * u[i, j, 2] - (A + 1) * u[i, j, 1] + | ||
52 | brusselator_f(x, y) | ||
53 | |||
54 | 13 (5 %) | du[i, j, 2] = α * (u[im1, j, 2] + u[ip1, j, 2] + u[i, jp1, 2] + u[i, jm1, 2] - | |
55 | 4u[i, j, 2]) + | ||
56 | A * u[i, j, 1] - u[i, j, 1] ^ 2 * u[i, j, 2] | ||
57 | end | ||
58 | return nothing | ||
59 | end | ||
60 | |||
61 | p = (3.4, 1.0, 10.0, step(xyd_brusselator)) | ||
62 | |||
63 | u0 = init_brusselator_2d(xyd_brusselator, N) | ||
64 | |||
65 | nlfunc = NonlinearFunction(brusselator_2d_loop; sparsity) | ||
66 | return NonlinearProblem(nlfunc, vec(u0), p; | ||
67 | termination_condition=AbsNormTerminationMode(), kwargs...) | ||
68 | end |