Mesh cube with spherical hole

Hi,

I’ve been looking at the example of generating a cube with a sphere inside from here: Mesh Generation.

The code is:

"
load “msh3”
load “TetGen”
load “medit”
include “MeshSurface.idp”

// Parameters
real hs = 0.1; //mesh size on sphere
int[int] N = [20, 20, 20];
real [int,int] B = [[-1, 1], [-1, 1], [-1, 1]];
int [int,int] L = [[1, 2], [3, 4], [5, 6]];

// Meshes
meshS ThH = SurfaceHex(N, B, L, 1);
meshS ThS = Sphere(0.5, hs, 7, 1);
meshS ThHS = ThH + ThS;
medit(“Hex-Sphere”, ThHS);

real voltet = (hs^3)/6.;
cout << "voltet = " << voltet << endl;

real[int] domain = [0, 0, 0, 1, voltet, 0, 0, 0.7, 2, voltet];
mesh3 Th = tetg(ThHS, switch=“pqaAAYYQ”, nbofregions=2, regionlist=domain);
medit(“Cube with ball”, Th);
"

I want to make the sphere mesh disappear, so that I’m left with a 3D cube mesh without the sphere in the middle. I tried altering the code to the following, but I am unable to save the mesh to an .msh file which I need, I get the error “UNABLE TO OPEN :file_name.msh” … PB Write error !.

What am I doing wrong?

Here is the modified code:

"
load “msh3”
load “TetGen”
load “medit”
include “MeshSurface.idp”

// Parameters
real hs = 0.1; //mesh size on sphere
int[int] N = [20, 20, 20];
real [int,int] B = [[-1, 1], [-1, 1], [-1, 1]];
int [int,int] L = [[1, 2], [3, 4], [5, 6]];

// Meshes
meshS ThH = SurfaceHex(N, B, L, 1);
meshS ThS = Sphere(0.5, hs, 7, 1);
meshS ThHS = ThH + ThS;

medit(“Hex-Sphere”, ThHS);

real voltet = (hs^3)/6.;
cout << "voltet = " << voltet << endl;

real[int] hole = [0., 0., 0.]
real[int] domain = [0, 0, 0, 1, voltet];
mesh3 Th = tetg(ThHS, switch=“pqaAAYYQ”, nbofholes=1, holelist=hole, nbofregions=1, regionlist=domain);
medit(“Cube with ball”, Th);
savemesh(Th, “mesh.msh”);
"

I don’t know about the issue of the sphere, but I noticed that saving a 3d mesh as a .msh file gives such error message. You should try a .mesh file

I see. Do you know any way to convert between the two formats, because the library I’m using needs a .msh format.

Maybe you can find some utility on the web to make the conversion. Otherwise it looks not difficulty to write a script to do it, since the data are the same, only the tag lines differ. You can do the conversion by hand if you have only a few meshes to convert.