# Variational formulation in cylindrical co ordinates

**URL:** https://community.freefem.org/t/variational-formulation-in-cylindrical-co-ordinates/3891
**Category:** General Discussion
**Created:** [April 29, 2025, 11:33am UTC](https://community.freefem.org/t/variational-formulation-in-cylindrical-co-ordinates/3891 "2025-04-29T11:33:11Z")
**Posts on this page:** 5
**Page:** 1

<div class="post-metadata">

### Author: ![sumenchalla](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/sumenchalla/32/2653_2.png) [@sumenchalla](https://community.freefem.org/u/sumenchalla)
#### Post date: [April 29, 2025, 11:33am UTC](https://community.freefem.org/t/variational-formulation-in-cylindrical-co-ordinates/3891/1 "2025-04-29T11:33:11Z")

</div>

Dear professor,

I want to simulate the flow throught pipe using full 3D NS equations. I wanted to write the varional formulation in cylindrical coordinates. I was able to map ‘r’ coordinates with y and ‘z’ coordinates with x. But I’m facing a problem while mapping ‘theta’ coordinates to z. I have searched for this problem in discussions, but I didn’t find any information. Your input will be highly valuable for my research. Kindly let me know any available resources on this topic.

Best regards,  
sumen.

---

<div class="post-metadata">

### Author: ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)
#### Post date: [April 29, 2025, 12:08pm UTC](https://community.freefem.org/t/variational-formulation-in-cylindrical-co-ordinates/3891/2 "2025-04-29T12:08:10Z")

</div>

Dear Sumenchalla,  
In the theta coordinate you have to set periodic boundary conditions. Apart from that I don’t see what problem could occur, until having a particular piece of code.

---

<div class="post-metadata">

### Author: ![sumenchalla](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/sumenchalla/32/2653_2.png) [@sumenchalla](https://community.freefem.org/u/sumenchalla)
#### Post date: [May 1, 2025, 5:12pm UTC](https://community.freefem.org/t/variational-formulation-in-cylindrical-co-ordinates/3891/3 "2025-05-01T17:12:16Z")

</div>

Dear professor,

I genuinely unable to get what you’re trying to emphasize. That is the reason why I took 2 days to read online what is periodic boundary condition is and how to map cylindrical to Cartesian, but I was not able to gather any useful information. I’m add the snippet of variational formulational I have used to simulate axisymmetric pipe flow, please have a look

```auto
	varf NS ([ur,ut,uz,p],[vr,vt,vz,q])=
    		 int2d(th)(
        	    	 (y^2*ur*vr+y^2*ut*vt+y^2*uz*vz)/dt
			+ nu*(y^2*dx(ur)*dx(vr)+y^2*dy(ur)*dy(vr)+ur*vr+y*dy(ur)*vr
			+ y^2*dy(ut)*dy(vt)+y^2*dx(ut)*dx(vt)+ut*vt+y*dy(ut)*vt
			+ y^2*dx(uz)*dx(vz)+y^2*dy(uz)*dy(vz)+y*dy(uz)*vz)
			- p*(y^2*dy(vr)+2*y*vr+y^2*dx(vz))
            		+ q*(ur+y*dy(ur)+y*dx(uz)) )

```

Here I used nondimensional NS equations in cylindrical coordinates, where y represents the radial direction and x represents the axial direction. Now I want to implement non-axisymmetric pipe flow for which delta(u)/delta(theta) will be there. How can I incorporate that term in my variational formulation? Your help will be highly useful for my research

Thanks and regrads,  
sumen.

---

<div class="post-metadata">

### Author: ![fb77](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fb77/32/3796_2.png) [@fb77](https://community.freefem.org/u/fb77)
#### Post date: [May 2, 2025, 9:48am UTC](https://community.freefem.org/t/variational-formulation-in-cylindrical-co-ordinates/3891/4 "2025-05-02T09:48:42Z")

</div>

Dear Sumen,  
I think it should be

```auto
real H=2.;
real R=0.5;
mesh3 Th=cube(2,2,3,[x*H,y*R,z*2*pi]);

fespace Vh(Th,[P2,P2,P2,P1],periodic=[[5,x,y],[6,x,y]]);

real dt=0.01,nu=0.4;

varf NS ([ur,ut,uz,p],[vr,vt,vz,q])=
   int3d(Th)(
      y*(ur*vr+ut*vt+uz*vz)/dt
      + nu*(y*dy(ur)*dy(vr)+(dz(ur)-ut)*(dz(vr)-vt)/y+y*dx(ur)*dx(vr)
      + y*dy(ut)*dy(vt)+(dz(ut)+ur)*(dz(vt)+vr)/y+y*dx(ut)*dx(vt)
      + y*dy(uz)*dy(vz)+dz(uz)*dz(vz)/y+y*dx(uz)*dx(vz))
      - p*(y*dy(vr)+vr+dz(vt)+y*dx(vz))
      - q*(y*dy(ur)+ur+dz(ut)+y*dx(uz))
      - 1.e-8*y*p*q );

```

The periodic nature has to be put in the space Vh.  
I took the formulas for the divergence, vector gradient and differential volume in

> **[Del in cylindrical and spherical coordinates](https://en.wikipedia.org/wiki/Del_in_cylindrical_and_spherical_coordinates)**
>
> This is a list of some vector calculus formulae for working with common curvilinear coordinate systems.
> Note that the operation 
>   
>     
>       
> arctan
> ⁡
>         
> (
>           
>             
> A
> B
>             
>           
> )
>         
>       
>     
> {\\displaystyle \\arctan \\left({\\frac {A}{B}}\\right)}
>   
> must be interpreted as the two-argument inverse tangent, atan2.
>  
>   
>     
>       
>         
>           
>             
>               
> ...

I have not tested the result.

---

<div class="post-metadata">

### Author: ![sumenchalla](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/sumenchalla/32/2653_2.png) [@sumenchalla](https://community.freefem.org/u/sumenchalla)
#### Post date: [May 2, 2025, 3:06pm UTC](https://community.freefem.org/t/variational-formulation-in-cylindrical-co-ordinates/3891/5 "2025-05-02T15:06:20Z")

</div>

Thank you very much for your information, Professor. I will try to implement this variational formulation with my mesh, which was imported from Gmesh.
