@@ -41,8 +41,7 @@ For details see Example 5 in Section 3 from (here adapted for dimensional equati
41
41
Exact Traveling-Wave Solutions to Bidirectional Wave Equations
42
42
[DOI: 10.1023/A:1026667903256](https://doi.org/10.1023/A:1026667903256)
43
43
"""
44
- function initial_condition_convergence_test (x,
45
- t,
44
+ function initial_condition_convergence_test (x, t,
46
45
equations:: BBMBBMVariableEquations1D ,
47
46
mesh)
48
47
g = equations. gravity
@@ -58,6 +57,49 @@ function initial_condition_convergence_test(x,
58
57
return SVector (eta, v, D)
59
58
end
60
59
60
+ """
61
+ initial_condition_manufactured(x, t, equations::BBMBBMVariableEquations1D, mesh)
62
+
63
+ A smooth manufactured solution in combination with [`source_terms_manufactured`](@ref).
64
+ """
65
+ function initial_condition_manufactured (x, t,
66
+ equations:: BBMBBMVariableEquations1D ,
67
+ mesh)
68
+ eta = exp (t) * cospi (2 * (x - 2 * t))
69
+ v = exp (t / 2 ) * sinpi (2 * (x - t / 2 ))
70
+ D = 5.0 + 2.0 * cospi (2 * x)
71
+ return SVector (eta, v, D)
72
+ end
73
+
74
+ """
75
+ source_terms_manufactured(q, x, t, equations::BBMBBMVariableEquations1D, mesh)
76
+
77
+ A smooth manufactured solution in combination with [`initial_condition_manufactured`](@ref).
78
+ """
79
+ function source_terms_manufactured (q, x, t, equations:: BBMBBMVariableEquations1D )
80
+ g = equations. gravity
81
+ a1 = cospi (2 * x)
82
+ a2 = sinpi (2 * x)
83
+ a3 = cospi (t - 2 * x)
84
+ a4 = sinpi (t - 2 * x)
85
+ a5 = sinpi (2 * t - 4 * x)
86
+ a6 = sinpi (4 * t - 2 * x)
87
+ a7 = cospi (4 * t - 2 * x)
88
+ dq1 = - 2 * pi ^ 2 * (4 * pi * a6 - a7) * (2 * a1 + 5 )^ 2 * exp (t) / 3 +
89
+ 8 * pi ^ 2 * (a6 + 4 * pi * a7) * (2 * a1 + 5 ) * exp (t) * a2 / 3 +
90
+ 2 * pi * (2 * a1 + 5 ) * exp (t / 2 ) * a3 - 2 * pi * exp (3 * t / 2 ) * a4 * a6 +
91
+ 2 * pi * exp (3 * t / 2 ) * a3 * a7 + 4 * pi * exp (t / 2 ) * a2 * a4 -
92
+ 4 * pi * exp (t) * a6 + exp (t) * a7
93
+ dq2 = 2 * pi * g * exp (t) * a6 -
94
+ pi ^ 2 *
95
+ (8 * (2 * pi * a4 - a3) * (2 * a1 + 5 ) * a2 +
96
+ (a4 + 2 * pi * a3) * (2 * a1 + 5 )^ 2 +
97
+ 4 * (a4 + 2 * pi * a3) * (16 * sinpi (x)^ 4 - 26 * sinpi (x)^ 2 + 7 )) * exp (t / 2 ) /
98
+ 3 - exp (t / 2 ) * a4 / 2 - pi * exp (t / 2 ) * a3 - pi * exp (t) * a5
99
+
100
+ return SVector (dq1, dq2, 0.0 )
101
+ end
102
+
61
103
"""
62
104
initial_condition_dingemans(x, t, equations::BBMBBMVariableEquations1D, mesh)
63
105
100
142
101
143
function create_cache (mesh,
102
144
equations:: BBMBBMVariableEquations1D ,
103
- solver:: Solver ,
145
+ solver,
104
146
initial_condition,
105
147
RealT,
106
148
uEltype)
@@ -113,18 +155,16 @@ function create_cache(mesh,
113
155
K = Diagonal (D .^ 2 )
114
156
if solver. D1 isa PeriodicDerivativeOperator ||
115
157
solver. D1 isa UniformPeriodicCoupledOperator
116
- invImDKD_D = (I - 1 / 6 * sparse (solver. D1) * K * sparse (solver. D1)) \
117
- Matrix (solver. D1)
118
- invImD2K_D = (I - 1 / 6 * sparse (solver. D2) * K) \ Matrix (solver. D1)
158
+ invImDKD = inv (I - 1 / 6 * Matrix (solver. D1) * K * Matrix (solver. D1))
159
+ invImD2K = inv (I - 1 / 6 * Matrix (solver. D2) * K)
119
160
elseif solver. D1 isa PeriodicUpwindOperators
120
- invImDKD_D = (I - 1 / 6 * sparse (solver. D1. minus) * K * sparse (solver. D1. plus)) \
121
- Matrix (solver. D1. minus)
122
- invImD2K_D = (I - 1 / 6 * sparse (solver. D2) * K) \ Matrix (solver. D1. plus)
161
+ invImDKD = inv (I - 1 / 6 * Matrix (solver. D1. minus) * K * Matrix (solver. D1. plus))
162
+ invImD2K = inv (I - 1 / 6 * Matrix (solver. D2) * K)
123
163
else
124
164
@error " unknown type of first-derivative operator"
125
165
end
126
- tmp1 = Array {RealT} (undef, nnodes (mesh))
127
- return (invImDKD_D = invImDKD_D, invImD2K_D = invImD2K_D , tmp1 = tmp1)
166
+ tmp1 = Array {RealT} (undef, nnodes (mesh)) # tmp1 is needed for the `RelaxationCallback`
167
+ return (invImDKD = invImDKD, invImD2K = invImD2K , tmp1 = tmp1)
128
168
end
129
169
130
170
# Discretization that conserves the mass (for eta and v) and the energy for periodic boundary conditions, see
133
173
# [DOI: 10.4208/cicp.OA-2020-0119](https://doi.org/10.4208/cicp.OA-2020-0119)
134
174
# Here, adapted for spatially varying bathymetry.
135
175
function rhs! (du_ode, u_ode, t, mesh, equations:: BBMBBMVariableEquations1D ,
136
- initial_condition,
137
- :: BoundaryConditionPeriodic , solver, cache)
138
- @unpack invImDKD_D, invImD2K_D, tmp1 = cache
176
+ initial_condition, :: BoundaryConditionPeriodic , source_terms,
177
+ solver, cache)
178
+ @unpack invImDKD, invImD2K = cache
139
179
140
180
q = wrap_array (u_ode, mesh, equations, solver)
141
181
dq = wrap_array (du_ode, mesh, equations, solver)
@@ -148,11 +188,21 @@ function rhs!(du_ode, u_ode, t, mesh, equations::BBMBBMVariableEquations1D,
148
188
dD = view (dq, 3 , :)
149
189
fill! (dD, zero (eltype (dD)))
150
190
151
- @. tmp1 = - (D * v + eta * v)
152
- mul! (deta, invImDKD_D, tmp1)
191
+ if solver. D1 isa PeriodicDerivativeOperator ||
192
+ solver. D1 isa UniformPeriodicCoupledOperator
193
+ deta[:] = - solver. D1 * (D .* v + eta .* v)
194
+ dv[:] = - solver. D1 * (equations. gravity * eta + 0.5 * v .^ 2 )
195
+ elseif solver. D1 isa PeriodicUpwindOperators
196
+ deta[:] = - solver. D1. minus * (D .* v + eta .* v)
197
+ dv[:] = - solver. D1. plus * (equations. gravity * eta + 0.5 * v .^ 2 )
198
+ else
199
+ @error " unknown type of first-derivative operator"
200
+ end
201
+
202
+ calc_sources! (dq, q, t, source_terms, equations, solver)
153
203
154
- @. tmp1 = - (equations . gravity * eta + 0.5 * v ^ 2 )
155
- mul! (dv, invImD2K_D, tmp1)
204
+ deta[:] = invImDKD * deta
205
+ dv[:] = invImD2K * dv
156
206
157
207
return nothing
158
208
end
0 commit comments