Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
trixi-framework
GitHub Repository: trixi-framework/Trixi.jl
Path: blob/main/src/callbacks_step/stepsize_dg1d.jl
2055 views
1
# By default, Julia/LLVM does not use fused multiply-add operations (FMAs).
2
# Since these FMAs can increase the performance of many numerical algorithms,
3
# we need to opt-in explicitly.
4
# See https://ranocha.de/blog/Optimizing_EC_Trixi for further details.
5
@muladd begin
6
#! format: noindent
7
8
function max_dt(u, t, mesh::TreeMesh{1},
9
constant_speed::False, equations, dg::DG, cache)
10
# to avoid a division by zero if the speed vanishes everywhere,
11
# e.g. for steady-state linear advection
12
max_scaled_speed = nextfloat(zero(t))
13
14
@batch reduction=(max, max_scaled_speed) for element in eachelement(dg, cache)
15
max_lambda1 = zero(max_scaled_speed)
16
for i in eachnode(dg)
17
u_node = get_node_vars(u, equations, dg, i, element)
18
lambda1, = max_abs_speeds(u_node, equations)
19
max_lambda1 = max(max_lambda1, lambda1)
20
end
21
inv_jacobian = cache.elements.inverse_jacobian[element]
22
max_scaled_speed = max(max_scaled_speed, inv_jacobian * max_lambda1)
23
end
24
25
return 2 / (nnodes(dg) * max_scaled_speed)
26
end
27
28
function max_dt(u, t, mesh::TreeMesh{1},
29
constant_speed::True, equations, dg::DG, cache)
30
# to avoid a division by zero if the speed vanishes everywhere,
31
# e.g. for steady-state linear advection
32
max_scaled_speed = nextfloat(zero(t))
33
34
max_lambda1, = max_abs_speeds(equations)
35
36
@batch reduction=(max, max_scaled_speed) for element in eachelement(dg, cache)
37
inv_jacobian = cache.elements.inverse_jacobian[element]
38
max_scaled_speed = max(max_scaled_speed, inv_jacobian * max_lambda1)
39
end
40
41
return 2 / (nnodes(dg) * max_scaled_speed)
42
end
43
44
function max_dt(u, t, mesh::StructuredMesh{1},
45
constant_speed::False, equations, dg::DG, cache)
46
# to avoid a division by zero if the speed vanishes everywhere,
47
# e.g. for steady-state linear advection
48
max_scaled_speed = nextfloat(zero(t))
49
50
@batch reduction=(max, max_scaled_speed) for element in eachelement(dg, cache)
51
max_lambda1 = zero(max_scaled_speed)
52
53
for i in eachnode(dg)
54
u_node = get_node_vars(u, equations, dg, i, element)
55
lambda1, = max_abs_speeds(u_node, equations)
56
57
inv_jacobian = cache.elements.inverse_jacobian[i, element]
58
59
max_lambda1 = max(max_lambda1, inv_jacobian * lambda1)
60
end
61
62
max_scaled_speed = max(max_scaled_speed, max_lambda1)
63
end
64
65
return 2 / (nnodes(dg) * max_scaled_speed)
66
end
67
68
function max_dt(u, t, mesh::StructuredMesh{1},
69
constant_speed::True, equations, dg::DG, cache)
70
# to avoid a division by zero if the speed vanishes everywhere,
71
# e.g. for steady-state linear advection
72
max_scaled_speed = nextfloat(zero(t))
73
74
max_lambda1, = max_abs_speeds(equations)
75
76
@batch reduction=(max, max_scaled_speed) for element in eachelement(dg, cache)
77
for i in eachnode(dg)
78
inv_jacobian = cache.elements.inverse_jacobian[i, element]
79
max_scaled_speed = max(max_scaled_speed, inv_jacobian * max_lambda1)
80
end
81
end
82
83
return 2 / (nnodes(dg) * max_scaled_speed)
84
end
85
end # @muladd
86
87