# Mesh in polar coordinates

**URL:** <https://community.freefem.org/t/mesh-in-polar-coordinates/2738>\
**Category:** General Discussion\
**Created:** [October 3, 2023, 1:38pm UTC](https://community.freefem.org/t/mesh-in-polar-coordinates/2738 "2023-10-03T13:38:45Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![RaghunathBandha](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/raghunathbandha/32/1843_2.png) [@RaghunathBandha](https://community.freefem.org/u/RaghunathBandha)\
**Post date:** [October 3, 2023, 1:38pm UTC](https://community.freefem.org/t/mesh-in-polar-coordinates/2738/1 "2023-10-03T13:38:45Z")

</div>

Suppose we have a domain in polar coordinates with boundary r=f(theta). 0\<=theta\<=2\*pi. How to build a mesh in FreeFem++. Can I use movemesh in polar to polar transformation from (r , theta) coordinates to (r’ , theta’) coordinates. This FreeFem++ is far better than MatLab for FEMians. Any suggestion regarding this will be a great help.  
Thank you!

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [October 4, 2023, 8:01pm UTC](https://community.freefem.org/t/mesh-in-polar-coordinates/2738/2 "2023-10-04T20:01:36Z")

</div>

Just do like a circle mesh:

```auto
func real f(real t){ return 1+0.1*cos(t);}
border bf(t=0,2*pi){ x=f(t)*cos(t);y=f(t)*sin(t}:
mesh Th=buildmesh(bf(30));
plot(Th,wait=1); 

```

---

<div class="post-metadata">

**Author:** ![RaghunathBandha](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/raghunathbandha/32/1843_2.png) [@RaghunathBandha](https://community.freefem.org/u/RaghunathBandha)\
**Post date:** [October 5, 2023, 3:55am UTC](https://community.freefem.org/t/mesh-in-polar-coordinates/2738/3 "2023-10-05T03:55:09Z")

</div>

What about transformation of mesh from polar (r , theta) to polar (r’ , theta’). How to use movemesh ?

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [October 6, 2023, 2:19pm UTC](https://community.freefem.org/t/mesh-in-polar-coordinates/2738/4 "2023-10-06T14:19:53Z")

</div>

pass trough x,y coordinate

---

<div class="post-metadata">

**Author:** ![AdityasOcean](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/adityasocean/32/1938_2.png) [@AdityasOcean](https://community.freefem.org/u/AdityasOcean)\
**Post date:** [December 6, 2023, 1:19pm UTC](https://community.freefem.org/t/mesh-in-polar-coordinates/2738/5 "2023-12-06T13:19:48Z")

</div>

Monsieur,

Can we handle the polar coordinates using the functions such as written below?

```auto
//FE Velocity space
fespace Vh(Th,P2); // P2 elements

Vh u,v, uh, vh;

real eps = 1.0e-10;

func f1 = x;
func f2 = cos(y);
func f3 = sin(y);

// variational formulation
problem lubrication([u,v,p], [uh,vh,ph]) =
   int2d(Th) ( f1^2*nu*dx(u)*dx(uh) + f2^2*nu*dy(u)*dy(uh) )
 + int2d(Th) (f1^2*nu*dx(v)*dx(vh) + f2^2*nu*dy(v)*dy(vh) )
 - int2d(Th) (f1*p*dx(uh))
 - int2d(Th) (f2*p*dy(vh))
 - int1d(Th, Sh) (f1*nu*dx(u)*N.x*uh+f2*nu*dy(u)*N.y*uh)
 - int1d(Th, Ho) (f1*nu*dx(v)*N.x*vh+f2*nu*dy(v)*N.y*vh)
 + int2d(Th) (f1*dx(u)*ph + f2*dy(v)*ph)
 + int2d(Th) (eps*p*ph)
  + on (1, u=0, v=V0)
 + on (2, u=0, v=1.2);

lubrication;

```

I am new to coding in FreeFEM++ and borrowed the idea of generating a 3D cylinder from cube. I don’t know the correctness. But, I got a better result from this code, so a bit surprised.

Thanks and best regards,

---

<div class="post-metadata">

**Author:** ![frederichecht](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/frederichecht/32/15_2.png) [@frederichecht](https://community.freefem.org/u/frederichecht)\
**Post date:** [December 10, 2023, 10:02am UTC](https://community.freefem.org/t/mesh-in-polar-coordinates/2738/6 "2023-12-10T10:02:59Z")

</div>

Sorry, Th is a square or a rectangle, I do not understand what you do.  
I need the full script to be sure.

---

<div class="post-metadata">

**Author:** ![AdityasOcean](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/adityasocean/32/1938_2.png) [@AdityasOcean](https://community.freefem.org/u/AdityasOcean)\
**Post date:** [December 11, 2023, 2:22am UTC](https://community.freefem.org/t/mesh-in-polar-coordinates/2738/7 "2023-12-11T02:22:28Z")

</div>

Dear Sir,

Thank you for your response. Please see the code for the journal bearing and shaft arrangement here -

```auto
load "msh3"
load "shell"
load "medit"

// Body geometry

// Mesh quality
int nu1 = 50; // Mesh quality for the bearing shell
int nu2 = 200; // Mesh quality for the obstacle
int nu3 = 500; // Mesh quality for the shaft
int nu4 = 500; // Mesh quality for the lubricant
real ldratio=2; // Bearing L/diameter ratio

// Dimensions of the shaft, bearing and bearing housing
real Ri=0.350; // Shell bearing inner radius
real Ro=0.380; // Shell bearing outer radius
real clr=0.010 + 3e-4; // Shaft - Bearing clearance
real eccx=0.0, eccy=-0.0100; // Eccentricity of the shaft in bearing housing
real Rs=Ri-clr; // Shaft radius
real wear = 0.0001; // bearing uniform wear
real thck = Ro-Ri; // Bearing thickness

//Propeller shaft
border Sh(t=0,2*pi){x=Rs*cos(t)+eccx; y=Rs*sin(t)+eccy; label=0;}
mesh Shft = buildmesh(Sh(nu1));

//Top Bearing Shell
border bt1(t=pi,0){x=Ri*cos(t);y=Ri*sin(t);label=1;}
border bt2(t=0,thck){x=Ri+t;y=0.;label=2;}
border bt3(t=0,pi){x=Ro*cos(t);y=Ro*sin(t);label=3;}
border bt4(t=0,thck){x=-Ro+t;y=0;label=4;}
mesh Thbt=buildmesh(bt1(nu1) +bt2(nu1) +bt3(nu1) +bt4(nu1));
//plot(Th1t, wait=true);

//Bottom Bearing Shell
border bb1(t=0,pi){x=Ri*cos(t);y=Ri*sin(-t);label=11;}
border bb2(t=0,thck){x=-Ri-t;y=0.;label=12;}
border bb3(t=pi,0){x=Ro*cos(t);y=Ro*sin(-t);label=13;}
border bb4(t=0,thck){x=Ro-t;y=0;label=14;}
mesh Thbb=buildmesh(bb1(nu1) +bb2(nu1) +bb3(nu1) +bb4(nu1));
//plot(Th1b, wait=1);

//Lubricant Domain
mesh Thlub = buildmesh(bb1(-nu4)+bt1(-nu4)+Sh(-nu3));
//Thlub = adaptmesh(Thlub,eccx*eccy);
//plot(Thlub, wait=1);

// Bearing Housing mesh
real R1=Ri+0.07;
real e2=R1-Ro;
border b21(t=0,2*pi){x=R1*cos(t);y=R1*sin(t);label=101;}
border b22(t=0,e2){x=-R1+t;y=0.;label=102;}
border b23(t=2*pi,0){x=Ro*cos(t);y=Ro*sin(t);label=103;}
border b24(t=0,e2){x=Ro+t;y=0;label=104;}
mesh Th1=buildmesh(b21(nu2)+b22(nu2/10)+b23(nu2)+b24(nu2/10));

mesh Th2 = Th1+Shft+Thbt+Thbb+Thlub;

mesh3 Th = buildlayers(Th2, 20, zbound=[0,ldratio*Ri]);

plot(Th2, wait=1);

medit("Stern Bearing Assy", Th);

/////////////////////////////////////////////////////////////////////////////////////////////////////
/* Polar coordinates guidance */
/* x = r*cos(theta) */
/* y = r*sin(theta) */
/* (x,y) ----------> (r,theta) */
/* */
/* dr --------> cos(theta) * dx + sin(theta) * dy */
/* d(theta) --------> 1/r * (-dx*sin(theta) + dy*cos(theta) ) */
/* dr * d(theta) ----> 1/r * dx*dy */
/* */
/* cos(theta) = x/sqrt(x^2 + y^2) */
/* sin(theta) = y/sqrt(x^2 + y^2) */
/* */
/////////////////////////////////////////////////////////////////////////////////////////////////////

```

There are four separate regions for simulating the running of a shaft in a bearing housing with thin shell bearings.

1. Shaft
2. Lubricant film in the clearance region
3. Top and bottom shells (bearings)
4. Bearing housing

The variational formulation is for the lubricant film in the clearance region to determine the radial, whirl velocities and hydrodynamic pressure buildup as the shaft rotates at an RPM.

I want to use the Navier Stokes Equations in polar coordinates for the regions with the polar coordinates functions indicated in the code and solve. Is this the right approach?
