# Build a mesh for the unitary sphere

**URL:** <https://community.freefem.org/t/build-a-mesh-for-the-unitary-sphere/244>\
**Category:** General Discussion\
**Created:** [February 11, 2020, 10:52am UTC](https://community.freefem.org/t/build-a-mesh-for-the-unitary-sphere/244 "2020-02-11T10:52:42Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![MarcoF](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@MarcoF](https://community.freefem.org/u/MarcoF)\
**Post date:** [February 11, 2020, 10:52am UTC](https://community.freefem.org/t/build-a-mesh-for-the-unitary-sphere/244/1 "2020-02-11T10:52:42Z")

</div>

Dear users,

I’m new to FreeFem++ and I’m trying to build the mesh for the unitary sphere. In particular, I looked at the examples in the documentation [Here](https://github.com/FreeFem/FreeFem-sources/blob/develop/examples/3d/refinesphere.edp).

I need to solve an equation over this domain, so I need to apply some proper boundary conditions, in my example they are just _Homogeneous Dirichlet_ on the whole sphere. For me it will be enough to have a single label referring to the whole boundary, so that I can do in my code just `+on(myLabel, u=0)`

Best regards,  
Marco

---

<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:** [February 11, 2020, 6:25pm UTC](https://community.freefem.org/t/build-a-mesh-for-the-unitary-sphere/244/2 "2020-02-11T18:25:11Z")

</div>

They are lots of examples to build mesh of sphere

examples/3d/fallingspheres.edp

examples/3d/refinesphere.edp

examples/3d/Sphere-Isocahedron.edp

examples/3d/sphere6.edp

examples/3d/sphere2.edp

examples/3d/sphereincube.edp

examples/tutorial/sphere.edp

examples/plugin/refinesphere.edp

examples/eigen/WGM-sphere.edp

and in idp/MeshSurface.idp your have a function

func meshS Sphere(real R,real h,int L,int orientation)

Best regards,

---

<div class="post-metadata">

**Author:** ![MarcoF](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@MarcoF](https://community.freefem.org/u/MarcoF)\
**Post date:** [February 12, 2020, 8:00am UTC](https://community.freefem.org/t/build-a-mesh-for-the-unitary-sphere/244/3 "2020-02-12T08:00:48Z")

</div>

@frederichecht Thanks for your examples. My main issue is that I need also the interior of the sphere as a part of the domain and in your examples you always build the surface, which is just the boundary of my domain.

Up to now I’ve been able to build the boundary (which is of type `meshS`), now I think that I need to use **tetgen** to fill the interior. I’m stuck with the command `tetg` and I always get an error and can’t find a way to fill it.

Do you have a minimal example where the boundary of a solid is filled?

Best regards

---

<div class="post-metadata">

**Author:** ![fotios.kasolis](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/fotios.kasolis/32/18_2.png) [@fotios.kasolis](https://community.freefem.org/u/fotios.kasolis)\
**Post date:** [February 12, 2020, 9:44am UTC](https://community.freefem.org/t/build-a-mesh-for-the-unitary-sphere/244/4 "2020-02-12T09:44:49Z")

</div>

Try the module I uploaded

[https://modules.freefem.org/modules/3d-meshing/](https://modules.freefem.org/modules/3d-meshing/)

Does this solve your problem?

Regards,  
/Fotios Kasolis

---

<div class="post-metadata">

**Author:** ![MarcoF](https://avatars.discourse-cdn.com/v4/letter/m/e19adc/32.png) [@MarcoF](https://community.freefem.org/u/MarcoF)\
**Post date:** [February 12, 2020, 10:18am UTC](https://community.freefem.org/t/build-a-mesh-for-the-unitary-sphere/244/5 "2020-02-12T10:18:41Z")

</div>

Thanks @fotios.kasolis for your useful example,

first of all I had to change in every line you use movemesh23, `mesh3` to `meshS`, otherwise I get an error.

Doing so, I don’t obtain the sphere, but just the coil inside it. I tried to build my sphere following your script and others and it is the following one.

```
load "tetgen"
load "medit"

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);

plot(Th3);

savemesh(Th3,"sphere.meshb");

```

It builds the surface, but my question is: _do I get also the discretization of the interior?_

If not, what should I add/change (probably in `tetgen`)?

---

<div class="post-metadata">

**Author:** ![AFourmont](https://yyz2.discourse-cdn.com/flex030/user_avatar/community.freefem.org/afourmont/32/56_2.png) [@AFourmont](https://community.freefem.org/u/AFourmont)\
**Post date:** [February 13, 2020, 10:28am UTC](https://community.freefem.org/t/build-a-mesh-for-the-unitary-sphere/244/6 "2020-02-13T10:28:23Z")

</div>

In your example  
mesh3 Th3=tetgtransfo(Th,transfo=[R_f1,R_f2,R\*f3],nbofregions=1,regionlist=domain);  
builds and returns a 3d mesh (tetrahedra elements and triangle border elements)

If you want build a true surface mesh (triangle element and edge border element) you must extract the surface and add after the mesh3 building:  
load “msh3”  
Th3=buildBdMesh(Th3);  
meshS ThS=Th3.Gamma;

Axel

---

<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 29, 2023, 1:54am UTC](https://community.freefem.org/t/build-a-mesh-for-the-unitary-sphere/244/9 "2023-07-29T01:54:16Z")

</div>

Hello friend, I have encountered the same problem as you. How did you solve it in the end, that is, how to represent the surface of a sphere through the form of a label
