In this tutorial we describe how to numerically solve the BBM-BBM (Benjamin-Bona-Mahony) equations with variable bottom topography in one dimension, which has been proposed in for two spatial dimensions. The equations describe a dispersive shallow water model, i.e. they extend the well-known shallow water equations in the sense that dispersion is modeled. The shallow water equations are a system of first order hyperbolic partial differential equations that can be written in the form of a balance law. In contrast, the BBM-BBM equations additionally include third-order mixed derivatives. In primitive variables $q = (\eta, v)$ they can be written as:
\[\begin{aligned}
+ \eta_t + ((\eta + D)v)_x - \frac{1}{6}(D^2\eta_{xt})_x &= 0,\\
+ v_t + g\eta_x + \left(\frac{1}{2}v^2\right)_x - \frac{1}{6}(D^2v_t)_{xx} &= 0.
+\end{aligned}\]
Here, $\eta = h + b$ describes the total water height, $h$ the water height above the bottom topography (bathymetry), $b = \eta_0 - D$ the bathymetry and $v$ the velocity in horizontal direction. Here, $\eta_0$ is a reference water height also called still water height. In the case of the BBM-BBM equations, $\eta_0$ is usually taken to be 0. The gravitational acceleration is denoted as $g$. A sketch of the water height and the bathymetry can be found below.
In order to conduct a numerical simulation with DispersiveShallowWater.jl, we perform the following steps.
First, we load the necessary libraries:
using DispersiveShallowWater, OrdinaryDiffEq
As a first step of a numerical simulation, we define the physical setup we want to solve. This includes the set of equations, potentially including physical parameters, initial and boundary conditions as well as the domain. In the following example, the initial condition describes a traveling wave that moves towards a beach, which is modeled by a linearly increasing bathymetry.
equations = BBMBBMEquations1D(bathymetry_type = bathymetry_variable, gravity_constant = 9.81)
+
+function initial_condition_shoaling(x, t, equations::BBMBBMEquations1D, mesh)
+ A = 0.07 # amplitude of wave
+ x0 = -30 # initial center
+ eta = A * exp(-0.1*(x - x0)^2)
+ v = 0
+ D = x <= 0.0 ? 0.7 : 0.7 - 1/50 * x
+ return SVector(eta, v, D)
+end
+
+initial_condition = initial_condition_shoaling
+boundary_conditions = boundary_condition_periodic
+
+coordinates_min = -130.0
+coordinates_max = 20.0
+N = 512
+mesh = Mesh1D(coordinates_min, coordinates_max, N + 1)
Mesh1D{Float64}
+ xmin: -130.0
+ xmax: 20.0
+ N: 513
The first line specifies that we want to solve the BBM-BBM equations with variable bathymetry using a gravitational acceleration $g = 9.81$. Afterwards, we define the initial condition, which is described as a function with the spatial variable x
, the time t
, the equations
and a mesh
as parameters. If an analytical solution is available, the time variable t
can be used, and the initial condition can serve as an analytical solution to be compared with the numerical solution. Otherwise, you can just keep the time variable unused. An initial condition in DispersiveShallowWater.jl is supposed to return an SVector
holding the values for each of the unknown variables. Since the bathymetry is treated as a variable (with time derivative 0) for convenience, we need to provide the value for the primitive variables eta
and v
as well as for D
.
Next, we choose periodic boundary conditions. DispersiveShallowWater.jl also supports reflecting boundary conditions for the BBMBBMEquations1D
, see boundary_condition_reflecting
. Lastly, we define the physical domain as the interval from -130 to 20 and we choose 512 intermediate nodes. The mesh is homogeneous, i.e. the distance between each two nodes is constant. We choose the left boundary very far to the left in order to avoid an interaction of the left- and right-traveling waves.
In the next step, we build a Semidiscretization
that bundles all ingredients for the spatial discretization of the model. Especially, we need to define a Solver
. The simplest way to define a solver is to call the constructor by providing the mesh and a desired order of accuracy. In the following example, we use an accuracy order of 4. The default constructor simply creates periodic first- and second-derivative central finite difference summation-by-parts (SBP) operators of the provided order of accuracy. How to use other summation-by-parts operators, is described in the section on how to customize the solver. Note that for non-periodic boundary conditions, the solver also needs to be created with non-periodic operators, see, e.g. examples/bbm_bbm_1d/bbm_bbm_1d_basic_reflecting.jl.
solver = Solver(mesh, 4)
+
+semi = Semidiscretization(mesh, equations, initial_condition, solver, boundary_conditions = boundary_conditions)
Semidiscretization
+ #spatial dimensions: 1
+ mesh: Mesh1D{Float64} with length 513
+ equations: BBMBBMEquations1D-BathymetryVariable
+ initial condition: initial_condition_shoaling
+ boundary condition: boundary_condition_periodic
+ source terms: nothing
Finally, we put the mesh
, the equations
, the initial_condition
, the solver
and the boundary_conditions
together in a semidiscretization semi
.
Once we have obtained a semidiscretization, we can solve the resulting system of ordinary differential equations. To do so, we specify the time interval that we want to simulate and obtain an ODEProblem
from the SciML ecosystem for ordinary differential equations by calling semidiscretize
on the semidiscretization and the time span. Additionally, we can analyze the numerical solution using an AnalysisCallback
. The analysis includes computing the $L^2$ error and $L^\infty$ error of the different solution's variables compared to the initial condition (or, if available, at the same time analytical solution). Additional errors can be passed by the keyword argument extra_analysis_errors
. Additional integral quantities that should be analyzed can be passed by keyword argument extra_analysis_integrals
. In this example we pass the conservation_error
, which computes the temporal change of the total amount (i.e. integral) of the different variables over time. In addition, the integrals of the total water height $\eta$ waterheight_total
, the velocity
and the entropy
are computed and saved for each time step. The total water height and the total velocity are linear invariants of the BBM-BBM equations, i.e. they do not change over time. The total entropy
\[\mathcal E(t; \eta, v) = \frac{1}{2}\int_\Omega g\eta^2 + (\eta + D)v^2\textrm{d}x\]
is a nonlinear invariant and should be constant over time as well. During the simulation, the AnalysisCallback
will print the results to the terminal.
Finally, the ode
can be solve
d using the interface from OrdinaryDiffEq.jl. This means, we can specify a time-stepping scheme we want to use the tolerances for the adaptive time-stepping and the time values, where the solution values should be saved. In this case, we use the adaptive explicit Runge-Kutta method Tsit5
by Tsitouras of order 5(4). Here, we save the solution at 100 equidistant points.
tspan = (0.0, 25.0)
+ode = semidiscretize(semi, tspan)
+analysis_callback = AnalysisCallback(semi; interval = 10,
+ extra_analysis_errors = (:conservation_error,),
+ extra_analysis_integrals = (waterheight_total,
+ velocity, entropy),
+ io = devnull)
+callbacks = CallbackSet(analysis_callback)
+
+saveat = range(tspan..., length = 100)
+sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7,
+ save_everystep = false, callback = callbacks, saveat = saveat)
retcode: Success
+Interpolation: 1st order linear
+t: 100-element Vector{Float64}:
+ 0.0
+ 0.25252525252525254
+ 0.5050505050505051
+ 0.7575757575757576
+ 1.0101010101010102
+ 1.2626262626262625
+ 1.5151515151515151
+ 1.7676767676767677
+ 2.0202020202020203
+ 2.272727272727273
+ ⋮
+ 22.97979797979798
+ 23.232323232323232
+ 23.484848484848484
+ 23.737373737373737
+ 23.98989898989899
+ 24.242424242424242
+ 24.494949494949495
+ 24.747474747474747
+ 25.0
+u: 100-element Vector{RecursiveArrayTools.ArrayPartition{Float64, Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}}}}:
+ ([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 3.970457144557402e-98, 2.5091219407506056e-99, 1.5587515600325034e-100, 9.519319686177399e-102, 5.714902171134897e-103, 3.3727609949003114e-104, 1.9567539119467424e-105, 1.1159911034969113e-106, 6.2568988186290324e-108, 3.4485093610035348e-109], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-3.325779041744205e-56, 3.4011965413075523e-56, -1.2807538696027833e-56, 9.826119683176091e-57, -4.6680287287724206e-57, 3.001175342086128e-57, -1.5855434667918243e-57, 9.498455359228277e-58, -5.241015968539765e-58, 3.052020781220108e-58 … -8.218188545591878e-52, 3.2201662313922512e-52, -1.2488136389644121e-52, 4.79228932933622e-53, -1.8193621177011714e-53, 6.831547415082826e-54, -2.5360361570521737e-54, 9.289759055229196e-55, -3.344536294188373e-55, 9.250472924829037e-56], [8.222453507086802e-57, 3.873448404262121e-59, 4.565330869024205e-57, 1.7449394471024157e-58, 1.3093650630195066e-57, -9.245317596820392e-59, 3.40275981178711e-58, -7.153827292015671e-59, 9.163270865270449e-59, -3.1390747885212356e-59 … 5.12469610450987e-52, -2.0713910546658284e-52, 8.288600920234501e-53, -3.2827433305265773e-53, 1.2865863216086373e-53, -4.9889102551368584e-54, 1.9140231991875113e-54, -7.261405195661863e-55, 2.8296567364143117e-55, -9.923747107729601e-56], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-4.854238298243815e-53, 4.84207559328581e-53, -1.8542359278093255e-53, 1.4191697538185357e-53, -6.725818788033541e-54, 4.378357263509113e-54, -2.2917827470165684e-54, 1.3932793163615497e-54, -7.62314488482638e-55, 4.4937603076449734e-55 … -9.79734931598478e-49, 3.904823440781395e-49, -1.541129039675115e-49, 6.02195838627626e-50, -2.3292159935299984e-50, 8.915676316174737e-51, -3.3759016982314376e-51, 1.261839502586365e-51, -4.6410607324900014e-52, 1.3207690834248196e-52], [1.8094966051409033e-53, -1.4584786511660685e-55, 9.786374936184838e-54, 2.7312323385305925e-55, 2.84021734414011e-54, -2.1302683254439107e-55, 7.543710614019592e-55, -1.5467057423724359e-55, 2.068453959838124e-55, -6.787775950303608e-56 … 9.230894777908013e-49, -3.7902475744250124e-49, 1.5414575882566153e-49, -6.20803998233289e-50, 2.475448661865994e-50, -9.771389453892757e-51, 3.8185794780909684e-51, -1.4763404074859076e-51, 5.870620291318099e-52, -2.0979004982838445e-52], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-1.1612211718835738e-50, 1.1320331890227538e-50, -4.404006236991932e-51, 3.3635128693063013e-51, -1.5911277418319282e-51, 1.0476780483516305e-51, -5.4387810488677375e-52, 3.3524542123188944e-52, -1.8198186519496972e-52, 1.0856368593014869e-52 … -1.929456066425335e-46, 7.818784130963921e-47, -3.138973152079849e-47, 1.2482510860264523e-47, -4.915864170579566e-48, 1.9168336610106534e-48, -7.397392531849446e-49, 2.818892133204866e-49, -1.0581807616741108e-49, 3.0941252351459184e-50], [5.35248587903968e-51, -1.0908126523545418e-52, 2.825719843987477e-51, 4.999649270071249e-53, 8.297633551680539e-52, -6.593713412456712e-53, 2.2498236092990186e-52, -4.511945040082042e-53, 6.275468773599242e-53, -1.978097471297442e-53 … 2.247834704619979e-46, -9.37457845570809e-47, 3.8740982223584934e-47, -1.5861537292313428e-47, 6.432789261407768e-48, -2.5838370249129887e-48, 1.0280464499208233e-48, -4.048259898546108e-49, 1.6415915630510014e-49, -5.97353331135205e-50], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-1.1119804323377776e-48, 1.0619493650788072e-48, -4.191501029729562e-49, 3.1953368959187576e-49, -1.5096018539387125e-49, 1.0041795032563293e-49, -5.175777801824024e-50, 3.230830117823771e-50, -1.741250884930037e-50, 1.050568111299994e-50 … -1.5404930419740733e-44, 6.341645857637766e-45, -2.5873629836113427e-45, 1.046048072489513e-45, -4.189924738376017e-46, 1.6623634529961544e-46, -6.530368544807206e-47, 2.533639986964123e-47, -9.693362305462435e-48, 2.906320411513561e-48], [5.886854569644889e-49, -1.8735685947785375e-50, 3.0416340466206565e-49, 2.4183124037247207e-51, 9.031958584081732e-50, -7.570802428973542e-51, 2.4955460134500647e-50, -4.91231580876238e-51, 7.070968833595569e-51, -2.1494168998749156e-51 … 2.0605429044757652e-44, -8.72198500672439e-45, 3.659682550483109e-45, -1.5219293589669718e-45, 6.271862536984462e-46, -2.56085952196254e-46, 1.0362422429696266e-46, -4.151204936502761e-47, 1.7143442045458456e-47, -6.344205390808022e-48], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-6.211489582275723e-47, 5.81546813701702e-47, -2.328316144123238e-47, 1.7719331357501066e-47, -8.363944945158328e-48, 5.618388505772216e-48, -2.876693816210618e-48, 1.81811175606707e-48, -9.730228745496913e-49, 5.9386713693290795e-49 … -7.17650056258823e-43, 3.0013975431833195e-43, -1.244539316831306e-43, 5.115597033117466e-44, -2.0840687829385169e-44, 8.413208490493475e-45, -3.36415897788849e-45, 1.3288084863636017e-45, -5.181048699966923e-46, 1.592647914775217e-46], [3.660724460225685e-47, -1.5891513984318492e-48, 1.8525142608939541e-47, -3.960880989816218e-50, 5.564737521323442e-48, -4.9221970330044986e-49, 1.5666329750325675e-48, -3.032662892115052e-49, 4.50917194162671e-49, -1.3229166620894668e-49 … 1.0664480025008597e-42, -4.582708328004503e-43, 1.9527857592379878e-43, -8.250342605828643e-44, 3.4554537888179847e-44, -1.4344790927086694e-44, 5.90432344323674e-45, -2.4065710399895785e-45, 1.012287325883463e-45, -3.8101282644890664e-46], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-2.3254624830756234e-45, 2.1372127057907798e-45, -8.674197790456925e-46, 6.59121251534218e-46, -3.1098296925400897e-46, 2.108109647313978e-46, -1.0729996372745235e-46, 6.86211251186979e-47, -3.6482966678371385e-47, 2.252068970775198e-47 … -2.2526908588845315e-41, 9.568304720180962e-42, -4.030788136867561e-42, 1.6838105396915905e-42, -6.973908768083207e-43, 2.8631445973272826e-43, -1.164746749720682e-43, 4.681076043226782e-44, -1.8589366279149502e-44, 5.853554055871512e-45], [1.4921942283364848e-45, -8.15919134908772e-47, 7.407029533708002e-46, -9.014971991170385e-48, 2.250539004259876e-46, -2.0968874769420873e-47, 6.450330561487091e-47, -1.231102850879017e-47, 1.8847824397981202e-47, -5.3490644649983015e-48 … 3.6367948702954494e-41, -1.5861112039453376e-41, 6.861826196895116e-42, -2.9442873913673353e-42, 1.2528033388966016e-42, -5.2856086836781365e-43, 2.2119647353634306e-43, -9.168669573684192e-44, 3.9259923920259814e-44, -1.502128266410844e-44], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-6.392816377990657e-44, 5.774216065092091e-44, -2.3744579683475947e-44, 1.8017466718696756e-44, -8.500642191902535e-45, 5.811631565428513e-45, -2.9424725510874147e-45, 1.9031303849033325e-45, -1.0055344771491581e-45, 6.276822948899995e-46 … -5.217703733721899e-40, 2.2501059065628934e-40, -9.626624697463508e-41, 4.0852986940347894e-41, -1.7194676518774896e-41, 7.17597111742834e-42, -2.9684639138837185e-42, 1.2132381760288912e-42, -4.904476967023843e-43, 1.5807450779265751e-43], [4.40013485299198e-44, -2.890250864935071e-45, 2.1453560645561546e-44, -4.756544737370504e-46, 6.592646785575389e-45, -6.460292030799568e-46, 1.9222366814029912e-45, -3.62612413990814e-46, 5.699157584187746e-46, -1.5679567579915746e-46 … 9.015108134663185e-40, -3.988983763943425e-40, 1.751562769523995e-40, -7.630454972789248e-41, 3.297370339597659e-41, -1.4133137050000916e-41, 6.0110351560748e-42, -2.5326733194053144e-42, 1.103415541886358e-42, -4.2895165118177205e-43], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-1.3787502334193374e-42, 1.2251192502839373e-42, -5.102248405193265e-43, 3.866657874092403e-43, -1.824950083580649e-43, 1.257661119879837e-43, -6.337805124141576e-44, 4.143833555957976e-44, -2.1765772833304673e-44, 1.37378795469309e-44 … -9.51282788782202e-39, 4.164966872708254e-39, -1.80915102940956e-39, 7.797660095252925e-40, -3.334260945866795e-40, 1.414053595780334e-40, -5.946103260043911e-41, 2.47047497455972e-41, -1.016215556774098e-41, 3.350572085501218e-42], [1.0073885428861368e-42, -7.708119233715229e-44, 4.830052942009514e-43, -1.5552813727030945e-44, 1.5011160325914586e-43, -1.5452619864207697e-44, 4.4499719973326836e-44, -8.316078942701934e-45, 1.338183082358455e-44, -3.5758287881086666e-45 … 1.7417881760014818e-38, -7.813020268974156e-39, 3.482260716723971e-39, -1.539743708303501e-39, 6.755848197872596e-40, -2.9410130725218694e-40, 1.2708797645349479e-40, -5.441183201559245e-41, 2.4110376666396856e-41, -9.519810649594634e-42], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-2.4329941637709415e-41, 2.128619168308982e-41, -8.975456246453618e-42, 6.793904016728482e-42, -3.208924426549458e-42, 2.2281524693440206e-42, -1.118189767781559e-42, 7.387985806736306e-43, -3.859024053600812e-43, 2.4626118935524816e-43 … -1.4216499754663186e-37, 6.32482394347254e-38, -2.787736829138918e-38, 1.2203119351715756e-38, -5.299856734771361e-39, 2.2835485012980265e-39, -9.758579467895981e-40, 4.120411652923998e-40, -1.7241820769378674e-40, 5.812886155811122e-41], [1.872657186046869e-41, -1.6338487867546448e-42, 8.838531968179528e-42, -3.7399466854455896e-43, 2.7781279943687472e-42, -3.0017659658338308e-43, 8.369337392744295e-43, -1.552909644324131e-43, 2.5520131642521197e-43, -6.635102000068554e-44 … 2.7449634847117264e-37, -1.2442829134217103e-37, 5.636081539003042e-38, -2.527732856274979e-38, 1.1261145259104843e-38, -4.9779189360154115e-39, 2.1850367574029315e-39, -9.504002754898425e-40, 4.281941222405797e-40, -1.7167523555044976e-40], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ⋮
+ ([-0.00217685680533027, -0.0010991531445135737, -0.0005923337764093423, 0.0007288095726284962, 1.0194275109218688e-5, -2.791184005523262e-5, 0.001594955812875768, 0.002905011785710017, 0.0030434896861397803, 0.006563986119391616 … -0.002226968849198317, -0.0034417693665080126, -0.0015879257552951088, -0.0030506193587080594, -0.002758057639230283, -0.002142257409915534, -0.0025141586412037987, -0.002446501805835427, -0.001615983613755176, -0.002406693562270876], [-0.005471508691304485, -0.002987187762679309, -0.00166743032831747, -0.0028692320534838603, 0.000857448675759639, 0.004193705413529465, 0.00397829854394835, 0.008535193247844484, 0.01634816143983715, 0.01823311150964839 … 0.013589360496241546, 0.005318476022067737, 0.009735082114485517, 0.0003065851745726979, -0.0026932434186586044, -0.004296179257747148, -0.011985325702656329, -0.016373773848306954, -0.013551798527814341, -0.01538599384719916], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-0.0025058754714979196, -0.0018252401083375491, -0.0012170710172801419, -0.00043468369021890845, -0.0013914765656771295, -0.0006454704444983014, 0.00036249394029753507, 9.227440540610935e-5, 0.0007758495514829827, 0.003202581651833932 … -0.0007495813428485362, -0.002456747137976057, -0.0012479959889909222, -0.0011402444207044696, -0.0017663377218950478, -0.001193229979992048, -0.000931716816200681, -0.0021856746220264545, -0.0019264030106736058, -0.0022388190358733416], [-0.008500215882787427, -0.00805219791399432, -0.006710223227505098, -0.004905797666750656, -0.0001666261354951423, -0.001083199554746685, -0.0028254375538649137, 0.0016951642589465388, 0.005026166210925585, 0.007447947145865322 … 0.014897682145795278, 0.005054647031462805, 0.006518550275388466, 0.003540902403493579, -0.0043373043978368235, -0.006724251036338729, -0.009349183935785451, -0.015967209051955058, -0.01340209625400576, -0.014632665884650104], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-0.0018622554232659689, -0.002112368148555632, -0.0020128406188384524, -0.001880216333125273, -0.002113067693701585, -0.0005376214960134168, -0.0005560853989844735, -0.0013772814500358143, -0.00040220095044861095, 0.00038419516151376665 … -0.000248644540301314, -0.0008151144145284935, -0.0009489768839157051, 7.28096941297243e-5, -0.0001283481162939939, -0.0007489867613501852, -0.00020792449032182094, -0.0014215010258197644, -0.0019272324089571263, -0.0015105892195425034], [-0.008813488862025447, -0.009894126107163958, -0.009049578436370534, -0.005997962024251284, -0.0027405655719355483, -0.005436721583861657, -0.004740852985021509, -0.0014307322256005962, -0.0025661879029612433, -0.00034349854665921363 … 0.012531987314619677, 0.00714977454297149, 0.002231209384303312, 0.0026726519584763866, -0.002647826855488117, -0.008268582883372951, -0.005767823960933372, -0.009963901856291483, -0.012910684832531771, -0.013900945522401764], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-0.0011336758604551008, -0.0019792195079004625, -0.0023947609189683026, -0.0027194686723747206, -0.002231926521601785, -0.0007728104525117712, -0.001600669155281088, -0.0016998849039088215, -0.0007290768221329756, -0.001291383692730251 … -0.00028142436254473003, 0.0006194090192162322, 6.215540719667994e-5, 0.0003747643067752012, 0.001048391121583972, -0.00026078558302440374, -0.00030822367496679507, -0.0003422485370338711, -0.0011555137032242483, -0.0008953442781765807], [-0.006535539122471256, -0.0076241143777406786, -0.008186003096997473, -0.007059659644651693, -0.007102872939836229, -0.008641382954814729, -0.004395705298627607, -0.003180111818457568, -0.005981871859444205, -0.0037794294479861533 … 0.007085304770905998, 0.007493523234803456, 0.0008507984108425065, -0.0011132287002002974, 0.00025969904164029447, -0.005076735635776186, -0.0039436315509447555, -0.0045737640102703776, -0.01145236451807149, -0.012890538549893596], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-0.000851135833074368, -0.0015164577577977698, -0.0019345932262209305, -0.0024032659014423985, -0.001921332679415714, -0.0015998515037231988, -0.0025999763219225936, -0.0015052201056185309, -0.0009566872559455682, -0.0019251462692920225 … 1.8799770818082913e-5, 0.001088695703865266, 0.0013383863926556985, 0.00040840344223673996, 0.001049609894867262, 0.0004982167663835568, -0.00021636506105709828, 0.0004867695319956857, -0.00013149800222100265, -0.0006596159967523429], [-0.0035764780554477047, -0.0038311634821192454, -0.005644616064316287, -0.0073863493665880554, -0.010084275185546495, -0.009495570261902031, -0.004572665787173638, -0.00581328546309656, -0.006793385084488922, -0.004270770683511591 … 0.0025525180456550662, 0.003973798548170368, 0.002524461657229166, -0.002430825320938113, 0.0015236893536634119, 0.00048417341153535176, -0.003597796445159198, -0.003240993175423045, -0.007826563056479661, -0.00951926804165912], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-0.000792698384950789, -0.0009183634647562667, -0.0009349159821018373, -0.0013306484115036292, -0.001410019006893967, -0.002345833020465189, -0.0029018076193522415, -0.0013297671660035344, -0.0016078481233885444, -0.002017818368344056 … 0.0008494957188686227, 0.0007873717125620939, 0.0017733873657229111, 0.0007790090351318196, 0.0005219959065453403, 0.0011961756694673386, 0.0005176803053941935, 0.0007085992217667404, 0.0003672721353326719, -0.0005220550795835614], [-0.0017254112742893558, -0.0015781479578828347, -0.0034054992530155133, -0.006005679262310505, -0.008915461992004292, -0.007499925135415684, -0.005988295367210791, -0.009008284595682292, -0.006719996377650803, -0.004548868639596726 … 0.0013324184812408383, -0.0005038873250596906, 0.0038930111561827296, 0.0008631344596737983, 0.0007359623921429527, 0.0029634522691510882, -0.0026137687746766464, -0.003227914524735462, -0.002719344223435401, -0.0041480429753831104], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-0.0005045949122518567, -0.00039778847670190234, -0.00012800109379726172, -0.0004075931121330661, -0.0008937649160613044, -0.002224067387948437, -0.0021250453422656814, -0.0013232114557564837, -0.002446817876097665, -0.001924979225288271 … 0.0014126497008154811, 0.0005057351615943406, 0.0010930602408452197, 0.0013411320135317878, 0.0005503709527458155, 0.0014037390887323671, 0.0012127672338356232, 0.0005311117049730334, 0.00029343288212945406, -0.00014917439661153245], [-0.0010626077343000252, -0.0013768855203506402, -0.0022001075693596685, -0.003205490405195105, -0.004389788651662657, -0.00396429926460385, -0.007175694729979128, -0.010192145810753492, -0.006305760145897681, -0.006142377770596112 … 0.0016391991005528423, -0.0016699284375452093, 0.0024153412535596035, 0.004492433364497826, -0.00015282110763648892, 0.0013685125368957762, 0.0001163991782617583, -0.0007705176971119998, 0.0014618990740304756, 0.0005201307641519336], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([7.803777012584081e-5, -4.958365526500472e-5, 8.636575719668063e-5, -0.00013921328594881845, -0.00046920070038402884, -0.0011943753024392786, -0.0007045047216961306, -0.0013285352867223824, -0.0027038470573029112, -0.0016414104646436689 … 0.0009539072058629519, 0.0006299179051524403, 0.00024823638152100027, 0.0014908950301170034, 0.0011460682949011218, 0.0010936680333052328, 0.0011515808252157002, 0.00044778090104515103, 0.0002069556786044077, 0.0003893407334413058], [-0.000429362668283144, -0.001399449219067867, -0.0013855062117348394, -0.0005034735769530723, -8.076086669787046e-5, -0.0011306154343168162, -0.006342540477608546, -0.007464876700151907, -0.005243495088844136, -0.008118444341974406 … 0.00021331977084953466, 0.0002720743507073836, -0.0008731720320867966, 0.0035270666910821634, 0.00040421444082648704, 1.8949314836003775e-5, 0.003329633185947914, 0.003410122319406249, 0.0031178119822822367, 0.0027561528810216606], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([0.0006073616394552134, 0.00018073121640871042, -2.6115529692419924e-5, -0.0002524639408818994, -0.00013594028581904763, -8.888977368003006e-6, 0.0004027416082092184, -0.0011463111146034332, -0.0018726075255221775, -0.0010691535848885527 … -0.0001377728660617532, 0.0007896397947969662, 0.00014131258616284197, 0.0009634500994559407, 0.0013121845637720628, 0.0006296389607853126, 0.0005801386500742364, 0.0006577431971270433, 0.0004301853665127418, 0.000735887940542515], [0.0008907054710588714, -8.677905121416249e-5, -0.00015434992446134775, 0.0008370483644539625, 0.0012837063055229688, -0.00021899849219270855, -0.0033339590073813378, -0.002048739315201805, -0.003512596360388568, -0.008205120494151208 … -0.0033667538478959215, 0.0008446571850252335, -0.0031065095778086767, -0.0008884780375352997, 0.0017542421989325252, 0.0018032928029113136, 0.004775568742780649, 0.005711584342451509, 0.0030669676280134905, 0.0033152700567686513], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
After solving the equations, sol
contains the solution for each of the three variables at every spatial point for each of the 100 points in time. The errors and integrals recorded by the AnalysisCallback
can be obtained as NamedTuple
s by errors(analysis_callback)
and integrals(analysis_callback)
.
After running the simulation, the results can be visualized using Plots.jl, which needs to be imported first. Then, we can plot the solution at the final time by calling plot
on a Pair
of the Semidiscretization
and the corresponding ODESolution
sol
. The result is depicted in the following picture.
using Plots
+
+plot(semi => sol)
By default, this will plot the bathymetry, but not the initial (analytical) solution. You can adjust this by passing the boolean values plot_bathymetry
(if true
always plot to first subplot) and plot_initial
. You can also provide a conversion
function that converts the solution. A conversion function should take the values of the primitive variables q
at one node, and the equations
as input and should return an SVector
of any length as output. For a user defined conversion function, there should also exist a function varnames(conversion, equations)
that returns a Tuple
of the variable names used for labelling. The conversion function can, e.g., be prim2cons
or waterheight_total
if one only wants to plot the total water height. The resulting plot will have one subplot for each of the returned variables of the conversion variable. By default, the conversion function is just prim2phys
, which computes the physical variables from the primitive ones, i.e., the identity for most equations.
Plotting an animation over time can, e.g., be done by the following command, which uses step
to plot the solution at a specific time step.
anim = @animate for step in 1:length(sol.u)
+ plot(semi => sol, plot_initial = true, conversion = waterheight_total, step = step, xlim = (-50, 20), ylims = (-0.8, 0.1))
+end
+gif(anim, "shoaling_solution.gif", fps = 25)
[ Info: Saved animation to /home/runner/work/DispersiveShallowWater.jl/DispersiveShallowWater.jl/docs/build/shoaling_solution.gif
It is also possible to plot the solution variables at a fixed spatial point over time by calling plot(semi => sol, x)
for some x
-value, see plot_examples.jl from the reproducibility repository of the master thesis of Joshua Lampert for some examples.
Often, it is interesting to have a look at how the quantities that are recorded by the AnalysisCallback
evolve in time. To this end, you can plot
the AnalysisCallback
by
plot(analysis_callback)
This creates the following figure:
You can see that the linear invariants $\int_\Omega\eta\textrm{d}x$ and $\int_\Omega v\textrm{d}x$ are indeed conserved exactly. The entropy, however, starts growing at around $t = 17$ and rises up to approximately $5e-5$. This is because of the fact that, during the time integration, a nonlinear invariant is not necessarily conserved, even if the semidiscretization conserves the quantity exactly. How to obtain a fully-discrete structure-preserving numerical scheme is explained in the following section.
To obtain entropy-conserving time-stepping schemes DispersiveShallowWater.jl uses the relaxation method introduced in and further developed in . The relaxation method is implemented as a RelaxationCallback
, which takes a function representing the conserved quantity as the keyword argument invariant
. Therefore, we can run the same example as above, but using relaxation on the entropy by simply adding another callback to the CallbackSet
:
analysis_callback = AnalysisCallback(semi; interval = 10,
+ extra_analysis_errors = (:conservation_error,),
+ extra_analysis_integrals = (waterheight_total,
+ velocity, entropy),
+ io = devnull)
+relaxation_callback = RelaxationCallback(invariant = entropy)
+callbacks = CallbackSet(relaxation_callback, analysis_callback)
+sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7,
+ save_everystep = false, callback = callbacks, saveat = saveat)
retcode: Success
+Interpolation: 1st order linear
+t: 100-element Vector{Float64}:
+ 0.0
+ 0.25252525252525254
+ 0.5050505050505051
+ 0.7575757575757576
+ 1.0101010101010102
+ 1.2626262626262625
+ 1.5151515151515151
+ 1.7676767676767677
+ 2.0202020202020203
+ 2.272727272727273
+ ⋮
+ 22.97979797979798
+ 23.232323232323232
+ 23.484848484848484
+ 23.737373737373737
+ 23.98989898989899
+ 24.242424242424242
+ 24.494949494949495
+ 24.747474747474747
+ 25.0
+u: 100-element Vector{RecursiveArrayTools.ArrayPartition{Float64, Tuple{Vector{Float64}, Vector{Float64}, Vector{Float64}}}}:
+ ([0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 3.970457144557402e-98, 2.5091219407506056e-99, 1.5587515600325034e-100, 9.519319686177399e-102, 5.714902171134897e-103, 3.3727609949003114e-104, 1.9567539119467424e-105, 1.1159911034969113e-106, 6.2568988186290324e-108, 3.4485093610035348e-109], [0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0 … 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0, 0.0], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-3.324921341225903e-56, 3.4003392278775506e-56, -1.2804234896829194e-56, 9.82364420057308e-57, -4.6668342992286877e-57, 3.000416201894723e-57, -1.585139524044844e-57, 9.49604905000689e-58, -5.2396831823230444e-58, 3.0512473076899838e-58 … -8.216378693926337e-52, 3.2194486063630217e-52, -1.2485320075219328e-52, 4.7911956292039465e-53, -1.8189419246701166e-53, 6.829950727158614e-54, -2.5354363431910988e-54, 9.28753595301761e-55, -3.343726214808816e-55, 9.24819385353326e-56], [8.218943771654327e-57, 3.8289075624404534e-59, 4.563942530405602e-57, 1.74419169199534e-58, 1.309005377772532e-57, -9.242393999939873e-59, 3.401857200585256e-58, -7.151698897248832e-59, 9.160855824861702e-59, -3.1381741977383297e-59 … 5.122852753413436e-52, -2.0706448636210568e-52, 8.285610784151687e-53, -3.281557456526611e-53, 1.286120951183422e-53, -4.9871035474970967e-54, 1.9133292557590283e-54, -7.258768976584459e-55, 2.8286263472101124e-55, -9.920068569065118e-56], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-4.853849886441891e-53, 4.84169390022459e-53, -1.8540883349109847e-53, 1.4190569651166575e-53, -6.725284778433252e-54, 4.3780073754978166e-54, -2.2916004600873455e-54, 1.393167627429438e-54, -7.622536489047524e-55, 4.493399264084606e-55 … -9.7966531261799e-49, 3.9045433261663156e-49, -1.5410173991839046e-49, 6.021517724236452e-50, -2.329043765756292e-50, 8.915009944998443e-51, -3.3756465655233186e-51, 1.2617430555260487e-51, -4.640701703148933e-52, 1.3206652324646344e-52], [1.8093328345051126e-53, -1.4581990370516792e-55, 9.785500042754149e-54, 2.7310470201820274e-55, 2.839961619323027e-54, -2.1300681042539147e-55, 7.543022972044307e-55, -1.546566107719226e-55, 2.0682634902377048e-55, -6.787164106381849e-56 … 9.230152680029559e-49, -3.789939932890881e-49, 1.541331233502881e-49, -6.20752591190025e-50, 2.47524152437187e-50, -9.77056297988932e-51, 3.81825289677583e-51, -1.476212705655425e-51, 5.87010632408205e-52, -2.097714808577238e-52], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-1.1611473985590145e-50, 1.13196194883751e-50, -4.403727239504989e-51, 3.363299970469017e-51, -1.5910270906442514e-51, 1.0476114619753358e-51, -5.438436525602129e-52, 3.352240609450986e-52, -1.8197030853213765e-52, 1.0855675569477383e-52 … -1.929343054515134e-46, 7.818323023613841e-47, -3.1387867233656763e-47, 1.248176409933903e-47, -4.9155678722608514e-48, 1.91671723202277e-48, -7.396939630338528e-49, 2.8187181475471527e-49, -1.0581148859355585e-49, 3.093930399646064e-50], [5.352122041136788e-51, -1.0907187728750815e-52, 2.825529747029185e-51, 4.999400645962813e-53, 8.29707238250326e-52, -6.593255842435589e-53, 2.2496700713538377e-52, -4.511639878771291e-53, 6.275037249474069e-53, -1.9779638039814205e-53 … 2.2476942667338753e-46, -9.373988856474382e-47, 3.873852891798874e-47, -1.5860525722029576e-47, 6.43237600715173e-48, -2.583669780654212e-48, 1.027979386939183e-48, -4.047993699972233e-49, 1.6414826915910585e-49, -5.973133981547135e-50], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-1.1119276629523957e-48, 1.06189942682095e-48, -4.191302638067528e-49, 3.1951857739688955e-49, -1.5095304901861231e-49, 1.004131818335663e-49, -5.175532778360684e-50, 3.230676299402819e-50, -1.741168250445932e-50, 1.0505179936555778e-50 … -1.5404257270810562e-44, 6.341366748806457e-45, -2.5872482682585856e-45, 1.0460013439038721e-45, -4.189736121638675e-46, 1.6622880271526412e-46, -6.530069847280862e-47, 2.5335231514511037e-47, -9.692911443635543e-48, 2.9061836883318143e-48], [5.886560338977017e-49, -1.8734595002923862e-50, 3.041483473232923e-49, 2.418261231099115e-51, 9.031509130062183e-50, -7.570416340586852e-51, 2.4954207614358614e-50, -4.9120711829513436e-51, 7.070611387451272e-51, -2.1493099984469397e-51 … 2.0604481224320954e-44, -8.721581078855662e-45, 3.659511883950017e-45, -1.521857877914957e-45, 6.271565806822031e-46, -2.5607374547498252e-46, 1.0361924673446293e-46, -4.151003967544369e-47, 1.7142605156125343e-47, -6.343893296891815e-48], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-6.211331717919793e-47, 5.815321524538152e-47, -2.3282570993297435e-47, 1.7718882310243432e-47, -8.363733039600082e-48, 5.618245595338297e-48, -2.8766208357672436e-48, 1.8180653961803254e-48, -9.729981342656042e-49, 5.938519643031749e-49 … -7.176331716381925e-43, 3.0013264369011266e-43, -1.2445096240437769e-43, 5.115474105777932e-44, -2.0840183368967862e-44, 8.413003330736343e-45, -3.3640763214551014e-45, 1.328775590361493e-45, -5.180919414169954e-46, 1.5926077574475929e-46], [3.660627745904715e-47, -1.5891048724032208e-48, 1.8524657185207873e-47, -3.9605751297889326e-50, 5.564591012558082e-48, -4.922064605919434e-49, 1.5665914175588098e-48, -3.0325829464698433e-49, 4.509051573234136e-49, -1.3228818401208303e-49 … 1.0664218883974636e-42, -4.582595388870431e-43, 1.9527373181512895e-43, -8.250136579968605e-44, 3.455366913022899e-44, -1.4344427776617977e-44, 5.904172911138538e-45, -2.406509244883754e-45, 1.0122611361903742e-45, -3.810029006164329e-46], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-2.3254148729260135e-45, 2.1371693707142526e-45, -8.674020631050104e-46, 6.5910780039659816e-46, -3.109766233947364e-46, 2.1080664256313384e-46, -1.0729777036322265e-46, 6.861971364653655e-47, -3.648221884294959e-47, 2.2520225251868596e-47 … -2.2526489635258438e-41, 9.568125221436469e-42, -4.0307118517046704e-42, 1.6837783863604634e-42, -6.973774381759467e-43, 2.8630889136026256e-43, -1.1647238839108542e-43, 4.680983279736572e-44, -1.8588994238087755e-44, 5.853435385015212e-45], [1.4921624255428067e-45, -8.15899860683555e-47, 7.406873214038014e-46, -9.014697792614421e-48, 2.2504912184730037e-46, -2.0968417294685816e-47, 6.450192322482457e-47, -1.2310766421223148e-47, 1.8847417283520658e-47, -5.348950866303645e-48 … 3.636724418691866e-41, -1.5860802274094625e-41, 6.861691073002171e-42, -2.944228921830389e-42, 1.2527782460830162e-42, -5.285501890371945e-43, 2.2119196443060275e-43, -9.168480987400326e-44, 3.9259108730900707e-44, -1.5020968050241964e-44], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-6.392703281193868e-44, 5.774114804979816e-44, -2.3744160472717325e-44, 1.8017148840714676e-44, -8.500492202505221e-45, 5.811528582937049e-45, -2.9424205445570836e-45, 1.9030965547081845e-45, -1.0055166586564009e-45, 6.276711078218573e-46 … -5.217619501689521e-40, 2.250069274177116e-40, -9.626466632757982e-41, 4.085231035008798e-41, -1.7194389252137047e-41, 7.175850168915728e-42, -2.9684134330037166e-42, 1.2132173597547428e-42, -4.904392027715781e-43, 1.580717368006661e-43], [4.400054410751718e-44, -2.890193580286895e-45, 2.1453171868069062e-44, -4.756438666796039e-46, 6.592526625147776e-45, -6.460171298478156e-46, 1.9222013461349093e-45, -3.6260578335125735e-46, 5.699052061732706e-46, -1.56792816307062e-46 … 9.014957545563626e-40, -3.988916612658925e-40, 1.7515330465018094e-40, -7.630324437753789e-41, 3.29731346798516e-41, -1.4132891257661873e-41, 6.010929731936059e-42, -2.5326285233467492e-42, 1.103395851574137e-42, -4.289439343666708e-43], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-1.378725667702062e-42, 1.2250976349500885e-42, -5.102157683601495e-43, 3.86658917378751e-43, -1.8249176468313054e-43, 1.2576386595067885e-43, -6.337692242260892e-44, 4.1437592658476823e-44, -2.1765383986473212e-44, 1.3737632446673838e-44 … -9.51267547862954e-39, 4.164899465939468e-39, -1.8091214630908312e-39, 7.797531378417444e-40, -3.3342053482571085e-40, 1.414029775258397e-40, -5.94600205416277e-41, 2.4704324912729163e-41, -1.0161978911216156e-41, 3.350513017890998e-42], [1.007369983633952e-42, -7.707965100166264e-44, 4.829964825123704e-43, -1.5552475772830224e-44, 1.501088457912012e-43, -1.545232754373165e-44, 4.4498894434006903e-44, -8.315925408677237e-45, 1.3381580466032688e-44, -3.575763013402634e-45 … 1.741759274302865e-38, -7.812889584161371e-39, 3.4822018970150113e-39, -1.5397174571578435e-39, 6.7557319063736995e-40, -2.940961954308189e-40, 1.2708574565983223e-40, -5.441086743871107e-41, 2.410994480538413e-41, -9.519638511199931e-42], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-2.4329531982222997e-41, 2.1285836558594968e-41, -8.975305382850977e-42, 6.79378989998333e-42, -3.208870494739648e-42, 2.2281148544495573e-42, -1.1181709351382598e-42, 7.387860598940072e-43, -3.8589588665969964e-43, 2.4625700179270524e-43 … -1.4216284274384283e-37, 6.324726983613284e-38, -2.787693702900317e-38, 1.2202928646929105e-38, -5.2997730884411837e-39, 2.2835120969506726e-39, -9.758422311501379e-40, 4.120344626856182e-40, -1.7241537315523701e-40, 5.812789282790543e-41], [1.8726247222956765e-41, -1.633818396562492e-42, 8.838380130158878e-42, -3.739873176119231e-43, 2.7780799444027733e-42, -3.0017125561311423e-43, 8.369191266479138e-43, -1.5528826258321646e-43, 2.5519682436171537e-43, -6.634987020252795e-44 … 2.7449204218153752e-37, -1.2442633092114018e-37, 5.635991722103858e-38, -2.5276922309803866e-38, 1.1260962504929728e-38, -4.977837383336191e-39, 2.1850006129344783e-39, -9.503844017108042e-40, 4.281868981254176e-40, -1.716723124452758e-40], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ⋮
+ ([-0.0021659838088560796, -0.001094995519112767, -0.0005920726738234628, 0.000726487683932042, 1.7607760066919087e-5, -1.0517105508412199e-5, 0.0016042118987249707, 0.002911500143986849, 0.00304730876786348, 0.006558264513679322 … -0.002229648760050261, -0.0034368554793553574, -0.0015994702755044578, -0.003045275039634283, -0.0027529422179814545, -0.002149021316105199, -0.0025070202512139698, -0.0024455835509595344, -0.0016212354480479826, -0.0023968852410657156], [-0.005462316236984216, -0.0029946780624172343, -0.001663002733240563, -0.002835764908624419, 0.00089201850046132, 0.004220134093074875, 0.004025575858941669, 0.008567129944843481, 0.01635052584221326, 0.01822508330111086 … 0.013600747370824793, 0.005351861506716238, 0.009689195530436328, 0.0003284345291747709, -0.002678279754703704, -0.004334808585069449, -0.011933874505393498, -0.016317015455508295, -0.013528910892895187, -0.015332363345197657], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-0.0024946509575851485, -0.0018211108261937002, -0.0012193167641072493, -0.00043839507595223425, -0.0013848620123143706, -0.0006355965727136015, 0.00036862797581676534, 0.00010600586774323642, 0.0007869170103643482, 0.0032064862648831056 … -0.0007597031275126621, -0.0024482662039932725, -0.0012515129212970202, -0.001146256769677943, -0.0017575348280612767, -0.0011999057240201368, -0.0009387721551466217, -0.0021804302393484552, -0.0019262159652890358, -0.002232448416912344], [-0.008474305024845898, -0.008025725779320059, -0.0066885481663336065, -0.0048949367574332376, -0.00017412825861877918, -0.0010686022749647355, -0.0027716450397686668, 0.0017391457052397866, 0.005062324656409668, 0.007472315787017857 … 0.014861990674277929, 0.005091421340579877, 0.0064987638362722835, 0.0035055083366255044, -0.004297794278233807, -0.006731806496961922, -0.009336433665380431, -0.01590186318296446, -0.013401193628169387, -0.014629354103317792], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-0.0018597237172830081, -0.00210802986337214, -0.0020098381159790154, -0.0018764289682748011, -0.0021079135790931076, -0.0005391607932686783, -0.000555728737354798, -0.001364537899150523, -0.00039112078345156297, 0.0003959808911244923 … -0.00025689271445576706, -0.0008150365349885976, -0.0009419308453664023, 6.229432693262942e-5, -0.00012951113545819936, -0.0007488590066510768, -0.0002183073337670488, -0.0014174867196701647, -0.0019200772426444497, -0.0015113103521349023], [-0.008785908167303267, -0.009851920630150814, -0.009018710861238797, -0.005998539887104083, -0.002760661611444224, -0.005427871853370662, -0.004711868286319167, -0.0014060017135718082, -0.0025191862616331427, -0.0002966706021025215 … 0.012493799772253135, 0.00714520507032758, 0.0022593556065700526, 0.002631187018466068, -0.0026272442132622693, -0.008223907202660776, -0.005787179690514546, -0.009955159836300893, -0.01290405328272136, -0.013907495809161018], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-0.0011382887415977581, -0.0019755637573443054, -0.0023866475979837628, -0.0027089237075481457, -0.0022280252180604206, -0.0007789160388458304, -0.0016014443519477193, -0.0016938192890582247, -0.0007251832027281969, -0.0012793420128379815 … -0.00027994986104380097, 0.0006097320098220869, 6.803689593571247e-5, 0.0003705179913637498, 0.001036810116500304, -0.00025693997168742917, -0.0003088081128835584, -0.0003440920463287011, -0.0011508462467487495, -0.0008995601062786715], [-0.006526240914208469, -0.007603373094278415, -0.008165663953046657, -0.007053730041389102, -0.007097420191636183, -0.00862489302487809, -0.004397941244998336, -0.003183699039862747, -0.005950273727556587, -0.003740317641528606 … 0.007088430821741589, 0.0074524228512693625, 0.0008896378086855575, -0.001101592027040917, 0.00024442693749676366, -0.0050383643802543185, -0.003960962038994194, -0.0046135653821361795, -0.011431378783413914, -0.012874967436299048], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-0.0008547943895034823, -0.0015148921303084824, -0.0019284466945888557, -0.0023946513342133664, -0.0019187607713894413, -0.0016006518866787712, -0.002595693884560042, -0.0015054156466395858, -0.000960039773720794, -0.0019187642539307973 … 2.5800961533473184e-5, 0.0010792299897630958, 0.0013325044924246093, 0.00041213972519925363, 0.001041378428597442, 0.0004986784529142135, -0.00020927356144979017, 0.00048076743678619315, -0.00013500790692125855, -0.0006613057774831563], [-0.003587329842034334, -0.0038438470097323417, -0.0056441293877573994, -0.007369547273126031, -0.010047988774488599, -0.009470545592115983, -0.004586439281006319, -0.005823732744504588, -0.006784153778523687, -0.004260774894684274 … 0.0025892388372173586, 0.00395033298690205, 0.0025284857890902675, -0.0023802686422693376, 0.0014985027116861836, 0.0004655203736751942, -0.0035915249739959885, -0.003265547193722053, -0.007808778243090269, -0.009496236940963342], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-0.0007911392786587276, -0.000919224725854158, -0.0009360248152808417, -0.0013305081833950552, -0.0014090833019178226, -0.0023384783725006668, -0.0028924694278224033, -0.001331758737569024, -0.0016113731701246667, -0.0020166432097865642 … 0.0008501319386805328, 0.0007865904258221126, 0.0017610419963973753, 0.0007826019388547478, 0.000525801171545036, 0.0011913484760476523, 0.0005200641012586369, 0.0007042413951193037, 0.0003609870405988624, -0.0005197291955477974], [-0.0017393569555297368, -0.001601273393553025, -0.0034159764533118458, -0.0059905397450650865, -0.00887947847168998, -0.0074810160105879524, -0.005989200067180673, -0.008997974585445294, -0.006720449785255635, -0.004561741063495165 … 0.001356331980324725, -0.0004773509531829884, 0.0038631339186478257, 0.0008829572443046423, 0.0007323753118089233, 0.002917518881814044, -0.0025944672795292553, -0.003209158987965865, -0.0027240845338641928, -0.0041465572100801065], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([-0.0005009119017045504, -0.0003997104601284624, -0.00013392608631431567, -0.00041367937266740114, -0.0008943848717876374, -0.002214919529303907, -0.0021174942106503996, -0.001323271425900604, -0.002443602368093167, -0.0019245040114293352 … 0.0014032327699724006, 0.0005107843060473438, 0.0010883824047017117, 0.0013379383930313359, 0.0005579360220463159, 0.0013981282987046634, 0.0012063752145030772, 0.000531724088654463, 0.0002918660500148268, -0.0001466728723783782], [-0.0010643539943989634, -0.0013829707632917036, -0.0022067354929193135, -0.0032054851684968385, -0.004385590315411751, -0.00396494511141954, -0.007157569472104374, -0.010158516669368019, -0.006301951825606894, -0.006152472777288197 … 0.0016245751034126587, -0.001629164027276333, 0.0023914507449591654, 0.004453679560231112, -0.00013577011053784627, 0.0013582070954463957, 0.00012375369689699632, -0.0007458554006880208, 0.001438538950550649, 0.000499635832292823], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([7.877033748191227e-5, -5.0759247674162015e-5, 8.248268091042829e-5, -0.0001439443325207059, -0.0004705917480677116, -0.0011916959882249888, -0.0007052222978299392, -0.0013263353987131448, -0.0026943019655578356, -0.0016389695676998228 … 0.0009447991674192145, 0.000631727250413333, 0.00025492443506419454, 0.001483554284578256, 0.001144682434237616, 0.0010919467830103802, 0.001144978406046934, 0.00045095020034850285, 0.00020988107240592382, 0.00038828103079829087], [-0.0004211236396255794, -0.0013861889826009882, -0.0013829603946879882, -0.0005170403579787806, -0.00010682872152312257, -0.0011472730376918634, -0.006320611679930678, -0.0074343804060480615, -0.005234833248529178, -0.008106430680796013 … 0.00018523029248396585, 0.00027120843819062777, -0.0008647227013845209, 0.003482096619138371, 0.0004159585817721103, 4.9073205477521224e-5, 0.0033143557567943955, 0.0034010197767579695, 0.0030986111294805073, 0.002736843307883402], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
+ ([0.0006041217258656502, 0.0001807892600772976, -2.4516528465226038e-5, -0.00025139259773705773, -0.00013702122351659076, -1.4219361006673308e-5, 0.00039476471951246597, -0.0011439268405886926, -0.0018643765141721856, -0.0010666735203370549 … -0.00013530809660708507, 0.0007851059491441459, 0.00014803025245138917, 0.0009594563951362837, 0.001302879856782529, 0.0006316145210140754, 0.0005807634725256609, 0.0006585897415157578, 0.0004319778826392215, 0.0007320680612231257], [0.0008950650498072832, -7.445962324129421e-5, -0.00014939140095337138, 0.0008245101177075142, 0.0012577416164915923, -0.0002339734757099639, -0.003327573932653731, -0.002049430498257923, -0.0035083927647127614, -0.008176303536859043 … -0.0033664188708153087, 0.0008055185235197423, -0.003080611210550147, -0.0008817593139363724, 0.0017444161811050272, 0.0018201342228179253, 0.004750809314982904, 0.005679923430856077, 0.0030667962038465816, 0.0033111405751278353], [0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7, 0.7 … 0.3584795321637427, 0.35263157894736835, 0.3467836257309941, 0.34093567251461987, 0.33508771929824555, 0.3292397660818713, 0.32339181286549706, 0.31754385964912274, 0.31169590643274847, 0.30584795321637426])
When you use both, an AnalysisCallback
and a RelaxationCallback
, note that the relaxation_callback
needs to come first inside the CallbackSet
as it needs to be invoked prior to the analysis_callback
, such that the analysis_callback
analyzes the solution with the already updated values.
Plotting the analysis_callback
again, we can see that now also the entropy
is conserved up to machine precision.
plot(analysis_callback, ylims = (-5e-16, 5e-16))
In the semidiscretization created above, we used the default SBP operators, which are periodic finite difference operators. Using different SBP operators for the semidiscretization can be done leveraging SummationByPartsOperators.jl, which needs to be imported first:
using SummationByPartsOperators: legendre_derivative_operator, UniformPeriodicMesh1D, couple_discontinuously, PeriodicUpwindOperators
As an example, let us create a semidiscretization based on discontinuous Galerkin (DG) upwind operators. A semidiscretization implemented in DispersiveShallowWater.jl needs one first-derivative and one second-derivative SBP operator. To build the first-derivative operator, we first create a LegendreDerivativeOperator
with polynomial degree 3 on a reference element [-1.0, 1.0]
and a UniformPeriodicMesh1D
for the coupling.
mesh = Mesh1D(coordinates_min, coordinates_max, N)
+accuracy_order = 4
+D_legendre = legendre_derivative_operator(-1.0, 1.0, accuracy_order)
+uniform_mesh = UniformPeriodicMesh1D(mesh.xmin, mesh.xmax, div(mesh.N, accuracy_order))
SummationByPartsOperators.UniformPeriodicMesh1D{Float64} with 128 cells in (-130.0, 20.0)
Upwind DG operators in negative, central and positive operators can be obtained by couple_discontinuously
central = couple_discontinuously(D_legendre, uniform_mesh)
+minus = couple_discontinuously(D_legendre, uniform_mesh, Val(:minus))
+plus = couple_discontinuously(D_legendre, uniform_mesh, Val(:plus))
+D1 = PeriodicUpwindOperators(minus, central, plus)
Upwind SBP first-derivative operators of order 3 on a grid in [-129.99999999999997, 19.999999999999996] using 512 nodes
+and coefficients of Module
In order to still have an entropy-conserving semidiscretization the second-derivative SBP operator needs to be
using SparseArrays: sparse
+D2 = sparse(plus) * sparse(minus)
512×512 SparseArrays.SparseMatrixCSC{Float64, Int64} with 3072 stored entries:
+⎡⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⎤
+⎢⠀⠈⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
+⎢⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
+⎢⠀⠀⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
+⎢⠀⠀⠀⠀⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
+⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
+⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
+⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
+⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
+⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
+⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
+⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
+⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
+⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
+⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⎥
+⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⠀⠀⠀⎥
+⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⠀⠀⎥
+⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣦⡀⠀⠀⠀⎥
+⎢⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣦⡀⠀⎥
+⎣⡀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠈⠻⣦⎦
The Solver
object can now be created by passing the two SBP operators to the constructor, which, in turn, can be used to construct a Semidiscretization
:
solver = Solver(D1, D2)
+semi = Semidiscretization(mesh, equations, initial_condition, solver, boundary_conditions = boundary_conditions)
Semidiscretization
+ #spatial dimensions: 1
+ mesh: Mesh1D{Float64} with length 512
+ equations: BBMBBMEquations1D-BathymetryVariable
+ initial condition: initial_condition_shoaling
+ boundary condition: boundary_condition_periodic
+ source terms: nothing
As before, we can run the simulation by
analysis_callback = AnalysisCallback(semi; interval = 10,
+ extra_analysis_errors = (:conservation_error,),
+ extra_analysis_integrals = (waterheight_total,
+ velocity, entropy),
+ io = devnull)
+relaxation_callback = RelaxationCallback(invariant = entropy)
+callbacks = CallbackSet(relaxation_callback, analysis_callback)
+sol = solve(ode, Tsit5(), abstol = 1e-7, reltol = 1e-7,
+ save_everystep = false, callback = callbacks, saveat = saveat)
+anim = @animate for step in 1:length(sol.u)
+ plot(semi => sol, plot_initial = true, conversion = waterheight_total, step = step, xlim = (-50, 20), ylims = (-0.8, 0.1))
+end
+gif(anim, "shoaling_solution_dg.gif", fps = 25)
[ Info: Saved animation to /home/runner/work/DispersiveShallowWater.jl/DispersiveShallowWater.jl/docs/build/shoaling_solution_dg.gif
For more details see also the documentation of SummationByPartsOperators.jl
Some more examples sorted by the simulated equations can be found in the examples/ subdirectory. Especially, in examples/svaerd_kalisch_1d/ you can find Julia scripts that solve the SvaerdKalischEquations1D
that were not covered in this tutorial. The same steps as described above, however, apply in the same way to these equations. Attention must be paid for these equations because they do not conserve the classical total entropy $\mathcal E$, but a modified entropy $\hat{\mathcal E}$, available as entropy_modified
.
More examples, especially focussing on plotting, can be found in the scripts create_figures.jl and plot_examples.jl from the reproducibility repository of the master thesis of Joshua Lampert.