This is a read only copy of the old FEniCS QA forum. Please visit the new QA forum to ask questions

Mesh for the union of two spheres by CSG

+1 vote

Dear all,

I know we can use the CSG class to generate the mesh for complicated shapes. But I ran in to trouble when i tried to construct the mesh of the union of two spheres, say centered at (0.5,0,0) and (-0.5,0,0) with both radius 1, by the following codes:

from dolfin import *
r = 1.0
x0 = 0.5
sphere1 = Sphere(Point(-x0, 0, 0), r)
sphere2 = Sphere(Point(x0, 0, 0), r)
g3d = sphere1 + sphere2
mesh3d = Mesh(g3d, 10)

then the program would run without stop and I got the following output:

Converting geometry to cgal types.
Convert to nef polyhedron
Removing degenerated facets
Number of degenerate facets: 82
Removing triangles with short edges
Number of degenerate facets: 18
Removing small triangles
Number of degenerate facets: 0
Number of vertices: 909
Number of facets: 1814
Detecting sharp features
Generating mesh
Inserting protection balls...
insert_corners() done. Nb of points in triangulation: 16
insert_balls_on_edges() done. Nb of points in triangulation: 321

Anyone knows how to solve this problem? Thanks very much

JY

asked Dec 12, 2014 by jying FEniCS User (2,020 points)

1 Answer

+1 vote

I can not actually see your problem; changed your code a little bit though, using mshr instead of CGAL directly.

from dolfin import *
from mshr import *
r = 1.0

x0 = 0.5
sphere1 = Sphere(Point(-x0, 0, 0), r)
sphere2 = Sphere(Point(x0, 0, 0), r)
g3d = sphere1 + sphere2
# Use the generate_mesh(domain, resolution) command
mesh3d = generate_mesh(g3d, 30)

plot(mesh3d, interactive=True)

enter image description here

Looks fine to me!

answered Dec 13, 2014 by joakibo FEniCS User (1,140 points)
...