# How to discretize the boundary of two regions?

## Problem

How to discretize a surface constructed with multiple components?

Unsuccessful attempts include combining the objects top and hull using the Mathematica commands Graphics3D, Union, and RegionUnion.

## Other posts investigated

Combine regions?

Boundary discretize region of ellipsoid returns a three dimensional region

How to combine regions of two 3D plots

RegionUnion issues with many Regions

## Example

Combine and mesh the surface defined by these two blocks:

{length, beam, draft} = {50, 3, 4}
pmin={0, 0, 0};
pmax={length, beam, draft};
hull = Cuboid[pmin, pmax];
{topLength, height} = {30, 3};
pmin = {10, 0, draft};
pmax = pmin + {topLength, beam, height};
top = Cuboid[pmin, pmax];
ohp = RegionUnion[top, hull]


### Fails to discretize:

BoundaryDiscretizeRegion[ohp, MaxCellMeasure -> {"Length" -> 5}]
BoundaryDiscretizeRegion: A non-degenerate region is expected at position 1

• pmin = {10, 0, draft - 10^-9}; make the pmin of the top very slighty stick into the hull and it works. If you want a shaper edge, reduce the MaxCellMeasure to something like 0.25. Jul 15, 2020 at 22:52

Here is an option using OpenCascadeLink. OpenCascade is an open source 3D CAD package that often does a better job retaining sharp features with boolean operations and seems to be fairly robust.

Needs["OpenCascadeLink"]
Needs["NDSolveFEM"]
{length, beam, draft} = {50, 3, 4};
pmin = {0, 0, 0};
pmax = {length, beam, draft};
hull = Cuboid[pmin, pmax];
{topLength, height} = {30, 3};
pmin = {10, 0, draft};
pmax = pmin + {topLength, beam, height};
top = Cuboid[pmin, pmax];
groups = bmesh["BoundaryElementMarkerUnion"];
temp = Most[Range[0, 1, 1/(Length[groups])]];
colors = ColorData["BrightBands"][#] & /@ temp
bmesh["Wireframe"["MeshElementStyle" -> FaceForm /@ colors]]
BoundaryDiscretizeRegion[
MeshRegion[
MeshOrderAlteration[
ToElementMesh[bmesh, MaxCellMeasure -> {"Length" -> 5}], 1]]]


Needs["NDSolveFEM"]
`