Main Content

Sphere in Cube

This example shows how to create a nested multidomain geometry consisting of a unit sphere and a cube. The first part of the example creates a cube with a spherical cavity. The second part creates a solid sphere embedded in a cube.

Cube with Spherical Cavity

First, create a geometry consisting of a cube with a spherical cavity. This geometry has one cell.

Create a cubic geometry.

g1 = fegeometry(multicuboid(2,2,2));
pdegplot(g1)

Figure contains an axes object. The axes object contains 6 objects of type quiver, text, patch, line.

Create a spherical geometry.

g2 = fegeometry(multisphere(0.5));
pdegplot(g2)

Figure contains an axes object. The axes object contains 5 objects of type quiver, text, patch.

Move the second geometry to fit entirely within the cube g1.

g2 = translate(g2,[0 0 1]);

Create a spherical cavity inside the cube using the cells of the geometry g2.

g3 = addVoid(g1,g2);

Plot the result.

figure
pdegplot(g3,CellLabels="on",FaceAlpha=0.5)

Figure contains an axes object. The axes object contains 6 objects of type quiver, text, patch, line.

Solid Sphere Nested in Cube

Add a solid sphere g2 inside the cube g1.

g4 = addCell(g1,g2);

Plot the result.

pdegplot(g4,CellLabels="on",FaceAlpha=0.5)

Figure contains an axes object. The axes object contains 6 objects of type quiver, text, patch, line.