# 2D Axisymmetric Navier Stokes

**URL:** <https://fenicsproject.discourse.group/t/2d-axisymmetric-navier-stokes/4548>\
**Category:** Uncategorized\
**Created:** [November 17, 2020, 1:50am UTC](https://fenicsproject.discourse.group/t/2d-axisymmetric-navier-stokes/4548 "2020-11-17T01:50:30Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![bcu](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/bcu/32/1872_2.png) [@bcu](https://fenicsproject.discourse.group/u/bcu)\
**Post date:** [November 17, 2020, 1:50am UTC](https://fenicsproject.discourse.group/t/2d-axisymmetric-navier-stokes/4548/1 "2020-11-17T01:50:30Z")

</div>

I am trying to create a 2d axisymmetric solver for the navier stokes. My formulation is written in cylindrical polar coordinates. I am using the r,z, theta components to forumale the navier stokes. I have the formulation down and written below. I’m having trouble defining the trial and test functions for this problem. I’m hoping to solve for the velocity components of the z-direction(x-axis) and r-direction(yaxis) in separate variational forms. Once solved, I would like it to assembled to one u vector consisting of the z,r (x,y) components. It seems that I will need 3 test functions (ux,uy,p). and 2 trial functions w,q. Any guidance with this will be very helpful. Thank you.

 ![Screenshot 2020-11-16 185308](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/8/888c2b53b57daa97073a00dd248bff86a01c069b.png)

This is what I have so far with the solver.

> # Define function space for velocity (ux,uy) and pressure (p)
> 
> W = VectorFunctionSpace(mesh, ‘P’, 2)
> 
> # Define function space for system of velocities
> 
> P1 = FiniteElement(‘P’, triangle, 1)  
> element = MixedElement([P1, P1])  
> V = FunctionSpace(mesh, element)  
> Q = FunctionSpace(mesh, ‘P’, 1)
> 
> # Define boundaries
> 
> inflow = ‘near(x[0], 0)’  
> outflow = ‘near(x[0], 2.2)’  
> walls = ‘near(x[1], 0) || near(x[1], 0.41)’  
> cylinder = ‘on\_boundary && x[0]\>0.1 && x[0]\<0.3 && x[1]\>0.1 && x[1]\<0.3’
> 
> # Define inflow profile
> 
> inflow\_profile = (‘400.0_1.5_x[1]\*(0.41 - x[1]) / pow(0.41, 2)’, ‘0’)
> 
> # Define boundary conditions
> 
> bcu\_inflow = DirichletBC(V, Expression(inflow\_profile, degree=2), inflow)  
> bcu\_walls = DirichletBC(V, Constant((0, 0)), walls)  
> bcu\_cylinder = DirichletBC(V, Constant((0, 0)), cylinder)  
> bcp\_outflow = DirichletBC(Q, Constant(0), outflow)  
> bcu = [bcu\_inflow, bcu\_walls, bcu\_cylinder]  
> bcp = [bcp\_outflow]
> 
> # Define trial and test functions
> 
> w0, w1 = TestFunctions(V)  
> w = Function(W)  
> u = TrialFunction(V)  
> ux, uy = split(u)
> 
> # v = TestFunction(V)
> 
> p = TrialFunction(Q)  
> q = TestFunction(Q)
> 
> # Define functions for solutions at previous and current time steps
> 
> u\_n = Function(V)  
> u\_ = Function(V)  
> p\_n = Function(Q)  
> p\_ = Function(Q)
> 
> ux\_n, uy\_n = split(u\_n)  
> ux\_, uy\_ = split(u\_)
> 
> # Define expressions used in variational forms
> 
> U = 0.5\*(u\_n + u)  
> n = FacetNormal(mesh)  
> f = Constant((0, 0))  
> k = Constant(dt)  
> mu = Constant(mu)  
> rho = Constant(rho)
> 
> x,y = SpatialCoordinate(mesh)  
> uy\_x = uy.dx(0)  
> uy\_y = uy.dx(1)  
> ux\_x = ux.dx(0)  
> ux\_y = ux.dx(1)
> 
> # Define symmetric gradient
> 
> def epsilon(v):  
> return sym(as\_tensor([[v[0].dx(0), 0, v[0].dx(1)],  
> [0, v[0]/x[0], 0],  
> [v[1].dx(0), 0, v[1].dx(1)]]))
> 
> # Define stress tensor
> 
> def sigma(u, p):  
> return 2_mu_epsilon(u) - p\*Identity(3)
> 
> F1 = rho\*((ux - ux\_n) / k)_w0_dx + rho_dot(dot(u\_n, nabla\_grad(u\_n)), w)dx + inner(sigma(U, p\_n), epsilon(w))dx + dot(p\_nn, w)ds   
> - dot(munabla\_grad(U)n, w)ds - muw0(1/y)ux\_ydx   
> + rho((uy - uy\_n) / k)w1dx - mu_w1\*(1/y)_uy\_y_dx + mu_w1_uy\*(1/(y\*y))\*dx  
> a1 = lhs(F1)  
> L1 = rhs(F1)]

---

<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 17, 2020, 7:40am UTC](https://fenicsproject.discourse.group/t/2d-axisymmetric-navier-stokes/4548/2 "2020-11-17T07:40:24Z")

</div>

Please format your code appropriately, by encapsulating it with ```.  
Additionally you should follow the guidelines: [Read before posting: How do I get my question answered?](https://fenicsproject.discourse.group/t/read-before-posting-how-do-i-get-my-question-answered/21)  
and please also be more specific about what issues you are having. Which part of the variational form  
is the source of your trouble?

Finally, please remove the duplicate of this question.

---

<div class="post-metadata">

**Author:** ![bcu](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/bcu/32/1872_2.png) [@bcu](https://fenicsproject.discourse.group/u/bcu)\
**Post date:** [November 17, 2020, 2:39pm UTC](https://fenicsproject.discourse.group/t/2d-axisymmetric-navier-stokes/4548/3 "2020-11-17T14:39:51Z")

</div>

@dokken Sorry about that. I’m new to this forum. I made the changes you requested and will keep those in mind for future post.

---

<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 17, 2020, 3:06pm UTC](https://fenicsproject.discourse.group/t/2d-axisymmetric-navier-stokes/4548/4 "2020-11-17T15:06:28Z")

</div>

Please further specify what your particular issue is.  
Where did you obtain this weak formulation from? What is the particular issue with implementation when you compare it to the mathematical formulation?

---

<div class="post-metadata">

**Author:** ![bcu](https://yyz2.discourse-cdn.com/free1/user_avatar/fenicsproject.discourse.group/bcu/32/1872_2.png) [@bcu](https://fenicsproject.discourse.group/u/bcu)\
**Post date:** [November 17, 2020, 3:35pm UTC](https://fenicsproject.discourse.group/t/2d-axisymmetric-navier-stokes/4548/5 "2020-11-17T15:35:07Z")

</div>

I created the weak formulation based on the theory of pulsatile flow in a tube.

 ![Screenshot 2020-11-17 084525](https://global.discourse-cdn.com/free1/uploads/fenicsproject1/original/2X/d/d8f4d86ce5866b64c85bb7f6ce5d761f84ddad73.png)

> # Define function space for velocity
> 
> W = VectorFunctionSpace(mesh, ‘P’, 2)
> 
> # Define function space for system of velocities
> 
> P1 = FiniteElement(‘P’, triangle, 1)  
> element = MixedElement([P1, P1])  
> V = FunctionSpace(mesh, element)
> 
> Q = FunctionSpace(mesh, ‘P’, 1)

> # Define trial and test functions
> 
> w0, w1 = TestFunctions(V)  
> w = Function(W)  
> u = TrialFunction(V)  
> ux, uy = split(u)
> 
> # v = TestFunction(V)
> 
> p = TrialFunction(Q)  
> q = TestFunction(Q)

I’m don’t know how to define the function space and trial and test functions correctly to solve for the x and y components of velocity separately.

---

<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 17, 2020, 4:52pm UTC](https://fenicsproject.discourse.group/t/2d-axisymmetric-navier-stokes/4548/6 "2020-11-17T16:52:17Z")

</div>

Note that these equations can only be separated if you use a splitting scheme, where p is the pressure from the previous time step. See for instance: [https://reader.elsevier.com/reader/sd/pii/S0010465514003786?token=4E5A707EBD45AB8F645727ED5F013CA5DF4F477BA963F410257DB7ED6B4EB08DAEC027F92C17CC69B9706055D271C6FD](https://reader.elsevier.com/reader/sd/pii/S0010465514003786?token=4E5A707EBD45AB8F645727ED5F013CA5DF4F477BA963F410257DB7ED6B4EB08DAEC027F92C17CC69B9706055D271C6FD)
