L2 Error in Navier Stokes code

Hi,

I am trying to examine the L2 error variation for a refined mesh applied to your Navier-Stokes equation with Poiseuille flow. I observed that the error increases as the mesh is refined, whereas it is expected to decrease.

Specifically, I am varying the values of nx anf ny in the command line:
mesh = create_unit_square(MPI.COMM_WORLD, 10, 10)

within the file ns_code1.ipynb using Binder.
Am I missing something here?

I am attaching three screenshots for the following mesh configurations:
(i) nx = 10, ny = 10

(ii) nx = 50, ny = 50

(iii) nx = 100, ny = 100

Due to media restriction I am just uploading the error screenshot for 100 by 100.
Waiting for responses and suggestions.

Let us first eliminate all solver errors by using direct solvers:

# Solver for step 1

solver1 = PETSc.KSP().create(mesh.comm)
solver1.setOperators(A1)
solver1.setType(PETSc.KSP.Type.PREONLY)
pc1 = solver1.getPC()
pc1.setType(PETSc.PC.Type.LU)
pc1.setFactorSolverType("mumps")

# Solver for step 2
solver2 = PETSc.KSP().create(mesh.comm)
solver2.setOperators(A2)
solver2.setType(PETSc.KSP.Type.PREONLY)
pc2 = solver2.getPC()
pc2.setType(PETSc.PC.Type.LU)
pc2.setFactorSolverType("mumps")

# Solver for step 3
solver3 = PETSc.KSP().create(mesh.comm)
solver3.setOperators(A3)
solver3.setType(PETSc.KSP.Type.PREONLY)
pc3 = solver3.getPC()
pc3.setType(PETSc.PC.Type.LU)
pc3.setFactorSolverType("mumps")

With num_steps=500 I get:

nx=ny=10
Time 10.00, L2-error 5.79e-08, Max error 3.17e-07
nx=ny=20
Time 10.00, L2-error 2.56e-06, Max error 2.42e-05
nx=ny=40
Time 10.00, L2-error 9.17e-06, Max error 1.17e-04
nx=ny=80
Time 10.00, L2-error 4.49e-06, Max error 4.39e-05

However, if we increase num_steps to 1000, we get

nx=ny=10
Time 10.00, L2-error 1.28e-13, Max error 6.10e-13
nx=ny=20
Time 10.00, L2-error 8.42e-09, Max error 7.02e-08
nx=ny=40
Time 10.00, L2-error 6.21e-07, Max error 9.66e-06
nx=ny=80
Time 10.00, L2-error 8.52e-07, Max error 1.41e-05

and with 2000 steps I get

Nx=ny=10
Time 10.00, L2-error 1.44e-14, Max error 2.29e-14
nx=ny=20
Time 10.00, L2-error 3.04e-14, Max error 1.43e-13
nx=ny=40
Time 10.00, L2-error 1.31e-09, Max error 1.61e-08
nx=ny=80
Time 10.00, L2-error 7.52e-08, Max error 1.76e-06

I.e. you observe that the error is drastically reduced when dt is decreased as well. The ratio between spatial and temporal discretization links to the CFL condition, which is required to be bounded for stability: Courant–Friedrichs–Lewy condition - Wikipedia

Several other things to note, is that:

  • Splitting schemes are not great for pressure conditions, as imposed in this tutorial.
  • Splitting schemes are not good for steady flow.

Thanks for the response @dokken

I’ve observed that for a very large number of time steps (i.e., very small time increments), where I expect the CFL condition to be satisfied for all spatial discretizations, the L2 error still increases as the mesh is refined.

Is this correct? I thought the L2 error should consistently decrease with mesh refinement, provided the CFL condition is satisfied.

You would have to share what parameters you are running with, and what error you are observing.

I mean even for what you shared

nx=ny=10
Time 10.00, L2-error 1.28e-13, Max error 6.10e-13
nx=ny=20
Time 10.00, L2-error 8.42e-09, Max error 7.02e-08
nx=ny=40
Time 10.00, L2-error 6.21e-07, Max error 9.66e-06
nx=ny=80
Time 10.00, L2-error 8.52e-07, Max error 1.41e-05

I thought as nx=ny increased, the L2 error would get less for a small enough time increment - or am I mistaken?

(Please bear with me, I am still new to finite elements - I really appreciate the explanations, and thank you for your patience)