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

**URL:** <https://fenicsproject.discourse.group/t/how-to-obtain-drag-and-lift-coefficient-for-flow-over-a-cylinder-navier-stokes-benchmark-2d-2-re-100-periodic/7129>\
**Category:** Uncategorized\
**Created:** [November 19, 2021, 6:28pm UTC](https://fenicsproject.discourse.group/t/how-to-obtain-drag-and-lift-coefficient-for-flow-over-a-cylinder-navier-stokes-benchmark-2d-2-re-100-periodic/7129 "2021-11-19T18:28:15Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![arash\_goli](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/arash_goli/32/3175_2.png) [@arash\_goli](https://fenicsproject.discourse.group/u/arash_goli)\
**Post date:** [November 19, 2021, 6:28pm UTC](https://fenicsproject.discourse.group/t/how-to-obtain-drag-and-lift-coefficient-for-flow-over-a-cylinder-navier-stokes-benchmark-2d-2-re-100-periodic/7129/1 "2021-11-19T18:28:15Z")

</div>

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](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](https://fenicsproject.org/pub/tutorial/html/._ftut1009.html).

I upload only related part of code :

```auto
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())

    force = -p_*n + nu*dot(sym(grad(u_)),n)
    
    F_D = assemble(-force[0]*ds)
    F_L = assemble(-force[1]*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)

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [November 19, 2021, 7:32pm UTC](https://fenicsproject.discourse.group/t/how-to-obtain-drag-and-lift-coefficient-for-flow-over-a-cylinder-navier-stokes-benchmark-2d-2-re-100-periodic/7129/2 "2021-11-19T19:32:25Z")

</div>

Please format your code with 3x` encapsulation.  
You should Also consider having a look at:  
[https://jorgensd.github.io/dolfinx-tutorial/chapter2/ns\_code2.html](https://jorgensd.github.io/dolfinx-tutorial/chapter2/ns_code2.html)  
Or

> **[A multimesh finite element method for the Navier–Stokes equations based on...](https://www.sciencedirect.com/science/article/abs/pii/S0045782520303145)**
>
> The multimesh finite element method is a technique for solving partial differential equations on multiple non-matching meshes by enforcing interface c…

---

<div class="post-metadata">

**Author:** ![arash\_goli](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/arash_goli/32/3175_2.png) [@arash\_goli](https://fenicsproject.discourse.group/u/arash_goli)\
**Post date:** [November 19, 2021, 7:46pm UTC](https://fenicsproject.discourse.group/t/how-to-obtain-drag-and-lift-coefficient-for-flow-over-a-cylinder-navier-stokes-benchmark-2d-2-re-100-periodic/7129/3 "2021-11-19T19:46:58Z")

</div>

I have already looked at [Test problem 2: Flow past a cylinder (DFG 2D-3 benchmark) — FEniCSx tutorial](https://jorgensd.github.io/dolfinx-tutorial/chapter2/ns_code2.html).  
But this is for case 2D-3 Benchmark solved by multimesh finite element method.

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [November 19, 2021, 7:56pm UTC](https://fenicsproject.discourse.group/t/how-to-obtain-drag-and-lift-coefficient-for-flow-over-a-cylinder-navier-stokes-benchmark-2d-2-re-100-periodic/7129/4 "2021-11-19T19:56:08Z")

</div>

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

> [@arash\_goli](#):
>
> My code is based on [Solving PDEs in Python -  
> The FEniCS Tutorial Volume I](https://fenicsproject.org/pub/tutorial/html/._ftut1009.html).

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

> [@dokken](#):
>
> [Test problem 2: Flow past a cylinder (DFG 2D-3 benchmark) — FEniCSx tutorial](https://jorgensd.github.io/dolfinx-tutorial/chapter2/ns_code2.html)

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: [Source code for: A multimesh finite element method for the Navier-Stokes equations based on projection methods](https://zenodo.org/record/3564206)

---

<div class="post-metadata">

**Author:** ![arash\_goli](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/arash_goli/32/3175_2.png) [@arash\_goli](https://fenicsproject.discourse.group/u/arash_goli)\
**Post date:** [November 20, 2021, 12:29am UTC](https://fenicsproject.discourse.group/t/how-to-obtain-drag-and-lift-coefficient-for-flow-over-a-cylinder-navier-stokes-benchmark-2d-2-re-100-periodic/7129/5 "2021-11-20T00:29:55Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![arash\_goli](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/arash_goli/32/3175_2.png) [@arash\_goli](https://fenicsproject.discourse.group/u/arash_goli)\
**Post date:** [November 20, 2021, 12:33am UTC](https://fenicsproject.discourse.group/t/how-to-obtain-drag-and-lift-coefficient-for-flow-over-a-cylinder-navier-stokes-benchmark-2d-2-re-100-periodic/7129/6 "2021-11-20T00:33:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [November 20, 2021, 8:24am UTC](https://fenicsproject.discourse.group/t/how-to-obtain-drag-and-lift-coefficient-for-flow-over-a-cylinder-navier-stokes-benchmark-2d-2-re-100-periodic/7129/7 "2021-11-20T08:24:29Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![arash\_goli](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/arash_goli/32/3175_2.png) [@arash\_goli](https://fenicsproject.discourse.group/u/arash_goli)\
**Post date:** [November 20, 2021, 5:09pm UTC](https://fenicsproject.discourse.group/t/how-to-obtain-drag-and-lift-coefficient-for-flow-over-a-cylinder-navier-stokes-benchmark-2d-2-re-100-periodic/7129/8 "2021-11-20T17:09:29Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![dokken](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/dokken/32/1560_2.png) [@dokken](https://fenicsproject.discourse.group/u/dokken)\
**Post date:** [November 20, 2021, 7:25pm UTC](https://fenicsproject.discourse.group/t/how-to-obtain-drag-and-lift-coefficient-for-flow-over-a-cylinder-navier-stokes-benchmark-2d-2-re-100-periodic/7129/9 "2021-11-20T19:25:29Z")

</div>

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

> [@arash\_goli](#):
>
> [Solving PDEs in Python -  
> The FEniCS Tutorial Volume I ](https://fenicsproject.org/pub/tutorial/html/._ftut1009.html).

> [@arash\_goli](#):
>
> Is installation as same as Dolfin?  
> What else do you recommend me to install beside Dolfinx?

I would suggest you read through the introduction to the dolfinx tutorial, or check out [GitHub - FEniCS/dolfinx: Next generation FEniCS problem solving environment](https://github.com/FEniCS/dolfinx#installation) if you want to install dolfinx.
