Build a mesh for the unitary sphere

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.

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

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,

@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

Try the module I uploaded

https://modules.freefem.org/modules/3d-meshing/

Does this solve your problem?

Regards,
/Fotios Kasolis

1 Like

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

In your example
mesh3 Th3=tetgtransfo(Th,transfo=[Rf1,Rf2,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

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