 # How to obtain Drag and lift Coefficient for Flow Over a Cylinder - Navier Stokes, Benchmark 2D-2 (Re=100, periodic)

Hello everyone, I am calculating the lift and drag coefficients in the code for the N-S 2D-2 (Re=100,periodic) equations. But I do not get quantities which are even close to result of benchmark computations ( http://www.mathematik.tu-dortmund.de/lsiii/cms/papers/SchaeferTurek1996.pdf ) (Table 4). My code is based on Solving PDEs in Python -
The FEniCS Tutorial Volume I
.

I upload only related part of code :

``````from fenics import *
from mshr import *
import numpy as np
......

n=FacetNormal(mesh)
t=0
drag = []
lift = []
C_d = []
C_l = []
p_diff = []
U_mean = 0.2
L = 0.1
bc = MeshFunction("size_t",mesh,mesh.topology().dim()-1)
ds = ds(domain=mesh,subdomain_data=bc, subdomain_id=4)
for j in range(num_steps):

# Update current time
t += dt

# Step 1: Tentative velocity step
b1 = assemble(L1)
[bc.apply(b1) for bc in bcu]
solve(A1, u_.vector(), b1, 'bicgstab', 'hypre_amg')

# Step 2: Pressure correction step
b2 = assemble(L2)
[bc.apply(b2) for bc in bcp]
solve(A2, p_.vector(), b2, 'bicgstab', 'hypre_amg')

# Step 3: Velocity correction step
b3 = assemble(L3)
solve(A3, u_.vector(), b3, 'cg', 'sor')

# Save solution to file (XDMF/HDF5)
xdmffile_u.write(u_, t)
xdmffile_p.write(p_, t)

# Save nodal values to file
timeseries_u.store(u_.vector(), t)
timeseries_p.store(p_.vector(), t)

# Update previous solution
u_n.assign(u_)
p_n.assign(p_)

set_log_level(LogLevel.PROGRESS)
progress += 1
set_log_level(LogLevel.ERROR)
print('u max:', u_.vector().get_local().max())
print('p max:', p_.vector().get_local().max())

F_D = assemble(-force*ds)
F_L = assemble(-force*ds)

C_D = 2/(U_mean**2*L)*F_D
C_L = 2/(U_mean**2*L)*F_L
``````

Also, I am not sure ds(4) or ds(5)

You should Also consider having a look at:
https://jorgensd.github.io/dolfinx-tutorial/chapter2/ns_code2.html
Or

I have already looked at Test problem 2: Flow past a cylinder (DFG 2D-3 benchmark) — FEniCSx tutorial.
But this is for case 2D-3 Benchmark solved by multimesh finite element method.

The key is that the variational forms for a single mesh approach contains all the same terms as the single mesh approach.

Also note that the initial scheme proposed in

Is based on a less accurate splitting scheme than the one in:

Please also consider refining the mesh and spatial discretization.

My point of referring to the multi mesh paper is that you can find the source code at: https://zenodo.org/record/3564206

Source code is really advanced. I need longtime to advance in it.

Do you know if there is any source code for case 2D-2 Benchmark?

I appreciate your help Prof. Dokken

In Case 2D-2, There is not any term U(t)=1.5sin(πt/8)

But the whole point of the two other codes I have supplied is that the discretization, and post processing (computing lift and drag) is verified by solving the 2D-3 benchmark. This means that you should be able to use the same code for 2D-2, as the PDEs are the same, only with a different boundary condition.

Be aware of a few things:

• when you start your flow from a zero state, with a sudden I let velocity as in 2D-2, you get a pressure wave in the startup phase of the problem, that will reduce convergence orders of the space-time L^2 norm.
1 Like

So I need to install Dolfinx. Is installation as same as Dolfin?
What else do you recommend me to install beside Dolfinx?

As both dolfin and dolfinx uses ufl to create variational forms and functionals you can easily change the implementation to dolfin if you want to ,
as the tutorial of dolfinx Im referring to is based on

I would suggest you read through the introduction to the dolfinx tutorial, or check out GitHub - FEniCS/dolfinx: Next generation FEniCS problem solving environment if you want to install dolfinx.