@@ -257,19 +257,46 @@ function test_twodnavierstokes_advection(dt, stepper, dev::Device=CPU(); n=128,
257257 isapprox (prob. vars. ζ, ζf, rtol= rtol_twodnavierstokes)
258258end
259259
260- function test_twodnavierstokes_energyenstrophy (dev:: Device = CPU ())
260+ function test_twodnavierstokes_energyenstrophypalinstrophy (dev:: Device = CPU ())
261261 nx, Lx = 128 , 2 π
262262 ny, Ly = 126 , 3 π
263263
264264 grid = TwoDGrid (dev; nx, Lx, ny, Ly)
265265 x, y = gridpoints (grid)
266266
267267 k₀, l₀ = 2 π/ grid. Lx, 2 π/ grid. Ly # fundamental wavenumbers
268- ψ₀ = @. sin (2 k₀* x) * cos (2 l₀* y) + 2 sin (k₀* x) * cos (3 l₀* y)
269- ζ₀ = @. - ((2 k₀)^ 2 + (2 l₀)^ 2 )* sin (2 k₀* x) * cos (2 l₀* y) - (k₀^ 2 + (3 l₀)^ 2 )* 2 sin (k₀* x) * cos (3 l₀* y)
268+ ψ₀ = @. sin (2 k₀ * x) * cos (2 l₀ * y) + 2 sin (k₀ * x) * cos (3 l₀ * y)
269+ ζ₀ = @. - ((2 k₀)^ 2 + (2 l₀)^ 2 ) * sin (2 k₀ * x) * cos (2 l₀ * y) - (k₀^ 2 + (3 l₀)^ 2 ) * 2 sin (k₀ * x) * cos (3 l₀ * y)
270270
271- energy_calc = 29 / 9
272- enstrophy_calc = 2701 / 162
271+ #=
272+
273+ We can analytically compute the energy, enstrophy, and palinstrophy
274+ that corresponds to the above initial condition using Mathematica
275+
276+ k0 = 2 Pi/Lx; l0 = 2 Pi/Ly;
277+
278+ psi[x_, y_] = Sin[2 k0 x] Cos[2 l0 y] + 2 Sin[k0 x] Cos[3 l0 y];
279+ u[x, y] = -D[psi[x, y], y];
280+ v[x, y] = D[psi[x, y], x];
281+ zeta[x, y] = D[v[x, y], x] - D[u[x, y], y];
282+
283+ E0 = Integrate[
284+ 1/2 (u[x, y]^2 + v[x, y]^2), {x, 0, Lx}, {y, 0, Ly}] / (Lx Ly);
285+ E0 /. {Lx -> 2 Pi, Ly -> 3 Pi}
286+
287+ Z0 = Integrate[1/2 zeta[x, y]^2, {x, 0, Lx}, {y, 0, Ly}] / (Lx Ly);
288+ Z0 /. {Lx -> 2 Pi, Ly -> 3 Pi}
289+
290+ P0 = Integrate[
291+ 1/2 (D[zeta[x, y], x]^2 + D[zeta[x, y], y]^2), {x, 0, Lx}, {y, 0,
292+ Ly}] / (Lx Ly);
293+ P0 /. {Lx -> 2 Pi, Ly -> 3 Pi}
294+
295+ =#
296+
297+ energy_analytic = 29 / 9
298+ enstrophy_analytic = 2701 / 162
299+ palinstrophy_analytic = 126277 / 1458
273300
274301 prob = TwoDNavierStokes. Problem (dev; nx, Lx, ny, Ly, stepper= " ForwardEuler" )
275302
@@ -278,14 +305,16 @@ function test_twodnavierstokes_energyenstrophy(dev::Device=CPU())
278305 TwoDNavierStokes. set_ζ! (prob, ζ₀)
279306 TwoDNavierStokes. updatevars! (prob)
280307
281- energyζ₀ = TwoDNavierStokes. energy (prob)
282- enstrophyζ₀ = TwoDNavierStokes. enstrophy (prob)
308+ energy₀ = TwoDNavierStokes. energy (prob)
309+ enstrophy₀ = TwoDNavierStokes. enstrophy (prob)
310+ palinstrophy₀ = TwoDNavierStokes. palinstrophy (prob)
283311
284312 params = TwoDNavierStokes. Params (p. ν, p. nν)
285313
286- (isapprox (energyζ₀, energy_calc, rtol= rtol_twodnavierstokes) &&
287- isapprox (enstrophyζ₀, enstrophy_calc, rtol= rtol_twodnavierstokes) &&
288- TwoDNavierStokes. addforcing! (prob. timestepper. N, sol, cl. t, cl, v, p, g)== nothing && p == params)
314+ return (isapprox (energy₀, energy_analytic, rtol= rtol_twodnavierstokes) &&
315+ isapprox (enstrophy₀, enstrophy_analytic, rtol= rtol_twodnavierstokes) &&
316+ isapprox (palinstrophy₀, palinstrophy_analytic, rtol= rtol_twodnavierstokes) &&
317+ TwoDNavierStokes. addforcing! (prob. timestepper. N, sol, cl. t, cl, v, p, g)== nothing && p == params)
289318end
290319
291320function test_twodnavierstokes_problemtype (dev, T)
0 commit comments