# How to describe the surface of a sphere

**URL:** <https://community.freefem.org/t/how-to-describe-the-surface-of-a-sphere/2624>\
**Category:** General Discussion\
**Created:** [July 28, 2023, 4:02am UTC](https://community.freefem.org/t/how-to-describe-the-surface-of-a-sphere/2624 "2023-07-28T04:02:39Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![PeterQ](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@PeterQ](https://community.freefem.org/u/PeterQ)\
**Post date:** [July 28, 2023, 4:02am UTC](https://community.freefem.org/t/how-to-describe-the-surface-of-a-sphere/2624/1 "2023-07-28T04:02:39Z")

</div>

Hello guys.I am trying to solve a pde on a sphere3.  
And now I want to describe the surface of a sphere3.

 ![微信图片_20230728115724](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/2/205abfea1e19792c0f645456ae4cb5049b565569.png)  
Here are some parts of the code.

```auto
solve lame([u1, u2, u3], [v1, v2, v3])
= int3d(Th3)(
lambda * div(u1, u2, u3) * div(v1, v2, v3)
+ 2.*mu * epsilon(u1, u2, u3)' * epsilon(v1, v2, v3)
)
- int3d(Th3)(omega*omega*(u1*v1+u2*v2+u3*v3))
+ on( _________ , u1=0, u2=0, u3=0)
;

```

Th3 is the sphere I constructed，then the underscore part should fill in the surface of that sphere,but I do not know how to describe it .

---

<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:** [July 29, 2023, 11:00am UTC](https://community.freefem.org/t/how-to-describe-the-surface-of-a-sphere/2624/2 "2023-07-29T11:00:08Z")

</div>

They are some exemple to build a mesh of a sphere

> <https://github.com/FreeFem/FreeFem-sources/blob/master/examples/3d/Sphere-Isocahedron.edp>

---

<div class="post-metadata">

**Author:** ![PeterQ](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@PeterQ](https://community.freefem.org/u/PeterQ)\
**Post date:** [July 30, 2023, 12:31am UTC](https://community.freefem.org/t/how-to-describe-the-surface-of-a-sphere/2624/3 "2023-07-30T00:31:14Z")

</div>

thank you for replying me and maybe I didn’t make it clear enough.  
Actually I’ve built a sphere3.

```auto
// sphere3
real R = 1;
mesh Th=square(10,20,[x*pi-pi/2,2*y*pi]);
// a parametrization of a sphere
func f1 =cos(x)*cos(y);
func f2 =cos(x)*sin(y);
func f3 = sin(x);
func f1x=sin(x)*cos(y);
func f1y=-cos(x)*sin(y);
func f2x=-sin(x)*sin(y);
func f2y=cos(x)*cos(y);
func f3x=cos(x);
func f3y=0;
// $ M = DF^t DF $
func m11=f1x^2+f2x^2+f3x^2;
func m21=f1x*f1y+f2x*f2y+f3x*f3y;
func m22=f1y^2+f2y^2+f3y^2;
func perio=[[4,y],[2,y],[1,x],[3,x]];
real hh=0.05;
real vv= 1/square(hh);
verbosity=2;
Th=adaptmesh(Th,m11*vv,m21*vv,m22*vv,IsMetric=1,periodic=perio);
Th=adaptmesh(Th,m11*vv,m21*vv,m22*vv,IsMetric=1,periodic=perio);
verbosity=2;
real[int] domain =[0.,0.,0.,1,0.01];
mesh3 Th3=tetgtransfo(Th,transfo=[R*f1,R*f2,R*f3],nbofregions=1,regionlist=domain);
Th3=buildBdMesh(Th3);

```

 ![微信图片_20230728115724](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/2/205abfea1e19792c0f645456ae4cb5049b565569.png)  
Th3 is the omega and now how can I describe the sphere surface with the above code ，namely  
 ![2](https://canada1.discourse-cdn.com/flex030/uploads/freefem/original/2X/a/a4701fa1c93684c8acb24769b9e816d51e7e33bd.png)

---

<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:** [July 31, 2023, 10:46am UTC](https://community.freefem.org/t/how-to-describe-the-surface-of-a-sphere/2624/4 "2023-07-31T10:46:37Z")

</div>

Just use the meshS Thb of my script or the meshS Th of your script

---

<div class="post-metadata">

**Author:** ![PeterQ](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@PeterQ](https://community.freefem.org/u/PeterQ)\
**Post date:** [July 31, 2023, 11:01am UTC](https://community.freefem.org/t/how-to-describe-the-surface-of-a-sphere/2624/5 "2023-07-31T11:01:06Z")

</div>

That’s it. Thanks a lot. 🙏

---

<div class="post-metadata">

**Author:** ![PeterQ](https://avatars.discourse-cdn.com/v4/letter/p/df788c/32.png) [@PeterQ](https://community.freefem.org/u/PeterQ)\
**Post date:** [October 7, 2023, 8:19am UTC](https://community.freefem.org/t/how-to-describe-the-surface-of-a-sphere/2624/6 "2023-10-07T08:19:05Z")

</div>

Sorry to bother you again. Could you help me take a look at the following code and tell me if there is a mistake.

```auto
load "msh3"
load "medit" 
load "tetgen"
load "mmg"
include "MeshSurface.idp"

// parameters
real E = 21.5;
real nu = 0.28;
real omega = 15;

// matrix functions
func p11 = 1/(0.7+100*(x-0.1)*(x-0.1)+10*y*y+z*z)-1/(1.3+100*(x+0.1)*(x+0.1)+10*y*y+z*z);
func p22 = -1/(0.7+100*x*x+10*(y-0.2)*(y-0.2)+z*z)+1/(1.3+100*x*x+10*(y+0.2)*(y+0.2)+z*z);
func p33 = 1/(0.7+100*x*x+10*y*y+(z-0.3)*(z-0.3))-1/(1.3+100*x*x+10*y*y+(z+0.3)*(z+0.3));
func p12 = (1/(0.7+100*(x-0.1)*(y-0.1))-1/(1.3+100*(x+0.1)*(y+0.1)))/(1+x*x);
func p13 = (1/(0.7+100*(x-0.2)*(z-0.2))-1/(1.3+100*(x+0.2)*(z+0.2)))/(1+y*y);
func p23 = (1/(0.7+100*(y-0.3)*(z-0.3))-1/(1.3+100*(y+0.3)*(z+0.3)))/(1+z*z);

// sphere3
real R = 1;
mesh Th=square(10,20,[x*pi-pi/2,2*y*pi]);
// a parametrization of a sphere
func f1 =cos(x)*cos(y);
func f2 =cos(x)*sin(y);
func f3 = sin(x);
func f1x=sin(x)*cos(y);
func f1y=-cos(x)*sin(y);
func f2x=-sin(x)*sin(y);
func f2y=cos(x)*cos(y);
func f3x=cos(x);
func f3y=0;
func m11=f1x^2+f2x^2+f3x^2;
func m21=f1x*f1y+f2x*f2y+f3x*f3y;
func m22=f1y^2+f2y^2+f3y^2;
func perio=[[4,y],[2,y],[1,x],[3,x]];
real hh=0.05;
real vv= 1/square(hh);
verbosity=2;
Th=adaptmesh(Th,m11*vv,m21*vv,m22*vv,IsMetric=1,periodic=perio);
Th=adaptmesh(Th,m11*vv,m21*vv,m22*vv,IsMetric=1,periodic=perio);
verbosity=2;
real[int] domain =[0.,0.,0.,1,0.01];
mesh3 Th3=tetgtransfo(Th,transfo=[R*f1,R*f2,R*f3],nbofregions=1,regionlist=domain);
Th3=buildBdMesh(Th3);
savemesh(Th3,"sphere.meshb");

// sphere2
real hsize= 0.1; 
real areaT = hsize*hsize*sqrt(3)/2.;
real areaS= 4*pi*R*R;
real nn = sqrt(areaS/areaT/20.); 
cout << nn << endl; 
meshS Thb=Sphere20(1,nn,1,0);

//fespace
fespace Vh(Th3,[P1,P1,P1]);
Vh<complex> [u1,u2,u3], [v1,v2,v3];
fespace Uh(Thb,[P1,P1,P1]);

// Macro
real sqrt2=sqrt(2.);
macro epsilon(u1,u2,u3) [dx(u1),dy(u2),dz(u3),(dy(u1)+dx(u2))/sqrt2,(dz(u1)+dx(u3))/sqrt2,(dz(u2)+dy(u3))/sqrt2] //
// The sqrt2 is because we want: epsilon(u1,u2,u3)'* epsilon(v1,v2,v3) = epsilon(u): epsilon(v)
macro div(u,v,w) ( dx(u)+dy(v)+dz(w)) //

// Problem
real phi = 5;
func test1 = exp(1i*(sqrt(omega*omega-phi*phi/4)*y+phi*z/2));
func test2 = exp(1i*(-sqrt(omega*omega-phi*phi/4)*y+phi*z/2));
real mu= E/(2*(1+nu));
real lambda = E*nu/((1+nu)*(1-2*nu));

solve lame([u1, u2, u3], [v1, v2, v3])
= int3d(Th3)(
lambda * div(u1, u2, u3) * div(v1, v2, v3)
+ 2.*mu * epsilon(u1, u2, u3)' * epsilon(v1, v2, v3)
)
- int3d(Th3)(omega*omega*(u1*v1+u2*v2+u3*v3))
- int3d(Th3)((p11*v1+p12*v2+p13*v3)*test1)
+ on(Thb, u1=0, u2=0, u3=0)
;

complex mm;
mm = int2d(ThS)(u1+u2+u3);
cout<<mm<<endl;

```

The error message is as follows:

```auto
+ on(Thb, u1=0, u2=0, u3=0)Impossible to cast <PPKN5Fem2D5MeshSE> in <l>
Compile error

```
