How to mesh a sphere in pymesh or gmsh?

So, apperantly mshr is on its way out. So, how to generate a surface mesh of triangles in either pymesh or gmsh and more specifically, how do I get it into fenics?
And furhtermore, what is wrong with this code, why does it not work?

N=6
sphere=Sphere(Point(0,0,0,1)
mesh=generate_mesh(sphere,N)
surface=BoundaryMesh(mesh,“exterior”)
V=FunctionSpace(surface,‘P’,1)
Y=Expression('3sqrt(10)(x[0]x[0]-x[1]x[1])(7[x[2][x[2]-1)’,degree=2)
u_n=project(Y,V)
u=TrialFunction(V)
v=TrialFunction(V)
a=inner(grad(u),grad(v))dx
u=Function(V)
L=u_n
v
dx
solve(a==L,u)
Is there something wrong with how I define forms on my surface?

mshr still works for me in dolfin version 2018.1.0 check out this.
and more examples here.

image

Oh, my bad, of course I mean that mshr still works, it is just that it is on its way out (according to my “sources”). More problmatic is that I cannot control the mesh size. What if I want to mesh a sphere with like 4 triangles? (Which is stupid, I know that, but I want to be able to control what’s going on)

If you’re really only interested in the sphere, there’s no need for fancy generators. Just take a look at iso_sphere of meshzoo,https://github.com/nschloe/meshzoo#sphere-surface:

import meshzoo

points, cells = meshzoo.iso_sphere(3)

is

3 Likes

thanks,

but how do I control how fine the mesh is and the “h”, that is to say the largest size of the triangle? And furthermore, how do I take that and write it as a mesh that I can use in FEniCS?

Your code does not seem to work for me :frowning: I must have made a mistake, could you point it out?

import meshzoo as mhz
import meshio as mio
import numpy as np
def meshgetter(refs):
    points, cells = mhz.iso_sphere(refs)
    mesh=mio.Mesh(points,cells)
    name="isosphere"+str(refs)+"xdmf"                                                                                                                                                               
    mio.write(name,points, {'triangle': cells})                                                                                                                                           
meshgetter(8)

Either you use write with the mesh object, or use write_point_cells.

1 Like

yes, I try to do that, but I get the error:
“AttributeError: ‘numpy.ndarray’ object has no attribute ‘items’”
running the above code, regardless if I write mesh created by meshio with write or if I try to write the cells with point and triangles.

This works for me:

import meshzoo
import meshio

n = 8
points, cells = meshzoo.icosa_sphere(n)
name = f"icosa-sphere{n}.xdmf"
meshio.write_points_cells(name, points, {"triangle": cells})
1 Like