6
$\begingroup$

In a recent answer to a question on constructing 2D meshes with internal boundaries @user21 provided an extremely useful answer which can be found here.

I have tried to extend this to 3D by constructing a mesh for a Ball with an internal cube, but the mesh that results appears to be only the mesh for the cube.

Can anyone see what I'm doing wrong?

Needs["NDSolve`FEM`"]
ru = RegionUnion[RegionBoundary[Ball[{0, 0, 0}, 10]], Cube[4]];
mesh = ToElementMesh[DiscretizeRegion[ru]]; mesh["Wireframe"]

enter image description here

$\endgroup$
3
  • $\begingroup$ This is different then the other question you mention. Both regions are of the same, full dimensionality 3D. Check the RegionDimenson and RegionEmbeddingDimenstion of all objects in both cases. $\endgroup$ Commented Aug 19 at 4:10
  • $\begingroup$ Also, have a look at UsingOpenCascadeLink. You can generate very sophisticated meshes of complex geometries. Look, for example at the Geometric Modeling section on the FEM core area page, there are links to the notebooks that generate these geometries. $\endgroup$ Commented Aug 19 at 4:13
  • $\begingroup$ Here is an example of what would be equivalent: Needs["NDSolveFEM"] ru = RegionUnion[RegionBoundary[Ball[{0, 0, 0}, 2]], Polygon[{{0, 0, 0}, {1, 0, 0}, {1, 1, 0}, {0, 1, 0}}]]; mesh = ToElementMesh[ru]; mesh["Wireframe"] $\endgroup$ Commented Aug 19 at 4:16

2 Answers 2

6
$\begingroup$
  • Both need RegionBoundary, RegionBoundary[Ball[{0, 0, 0}, 10]] and RegionBoundary@Cube[4]
Needs["NDSolve`FEM`"]
ru = RegionUnion[RegionBoundary[Ball[{0, 0, 0}, 10]], 
   RegionBoundary@Cube[4]];
mesh = ToElementMesh[ru];
mesh["Wireframe"]

enter image description here

$\endgroup$
2
  • 1
    $\begingroup$ (+1) The DiscretizeRegion is not needed. $\endgroup$ Commented Aug 20 at 5:58
  • $\begingroup$ @user21 Thanks, updated. $\endgroup$ Commented Aug 20 at 7:17
4
$\begingroup$

As the ball is larger than the cube, their union is simply the ball. You need not RegionUnion, but RegionDifference:

Needs["NDSolve`FEM`"]
ru = RegionDifference[Ball[{0, 0, 0}, 10], Cube[4]];
mesh = ToElementMesh[DiscretizeRegion[ru]]; mesh["Wireframe"]

enter image description here

$\endgroup$
3
  • $\begingroup$ Thank you @Daniel Huber. But what I’m getting is just the cube mesh. What I want is a mesh that includes the ball and cube, but respects the internal boundary defined by the cube. Motivation is that the cube will be a different material. It’s a mwe. $\endgroup$ Commented Aug 18 at 20:18
  • $\begingroup$ If the cube is a different material form the sphere, then treat the sphere without cube and the cube separately. $\endgroup$ Commented Aug 19 at 8:54
  • $\begingroup$ (+1) The DiscretizeRegion is not needed. $\endgroup$ Commented Aug 20 at 6:00

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.