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

"