Skip to main content
Update based on updated question.
Source Link
Tim Laska
  • 16.6k
  • 1
  • 35
  • 58

Update

In view of the updated question, the following workflow may be appropriate. If we assume that the boundary mesh is close to the boundary mesh produced by BallMesh, then we can use the Nearest function to match the nodes that are close and simply replace them. For example:

nf = Nearest[ball["Coordinates"] -> "Index"]; newcrd = ball["Coordinates"]; newcrd[[Flatten@nf[bnodes]]] = bnodes; ball2 = ToElementMesh["Coordinates" -> newcrd, "MeshElements" -> ball["MeshElements"]]; ball2["Wireframe"["MeshElement" -> "MeshElements", "MeshElementStyle" -> FaceForm[LightBlue], PlotRange -> {Automatic, {0, 100}, Automatic}]] 

Full volume mesh

Original answer

First, let me note a specific function within the MeshTools package called SphericalShellMesh that will give you control over the number of layers of a spherical shell hexahedron element mesh. The following will show you how to create a layer of hexahedron elements given a quad mesh.

First, generate a Quad mesh of a spherical shell.

(*Import required FEM package*) Needs["NDSolve`FEM`"]; (*Install MeshTools*) (*Uncomment if not installed*) (*ResourceFunction["GitHubInstall"]["c3m-labs","MeshTools"]*) Needs["MeshTools`"] bmesh = SphereMesh[6]; bmesh["Wireframe"[ "MeshElementStyle" -> FaceForm[LightBlue]] ] bmesh["Wireframe"[ "MeshElement" -> "BoundaryElements", "MeshElementStyle" -> FaceForm[LightBlue], PlotRange -> {Automatic, {0, 1}, Automatic}] ] 

Shell mesh

Second, use this code to extrude a single layer of hexahedron elements at 90% of the initial radius.

crd = bmesh["Coordinates"]; inc = ElementIncidents[bmesh["BoundaryElements"]][[1]]; ncrd = Length@crd; crd = Join[crd, ScalingTransform[0.9 {1, 1, 1}]@crd]; hexinc = inc /. {{i_, j_, k_, l_} -> {i, j, k, l, i + ncrd, j + ncrd, k + ncrd, l + ncrd}}; mesh = ToElementMesh["Coordinates" -> crd, "MeshElements" -> {HexahedronElement[hexinc]}]; mesh["Wireframe"[ "MeshElement" -> "MeshElements", "MeshElementStyle" -> FaceForm[LightBlue], PlotRange -> {Automatic, {0, 1}, Automatic}] ] 

Hexahedron mesh

First, let me note a specific function within the MeshTools package called SphericalShellMesh that will give you control over the number of layers of a spherical shell hexahedron element mesh. The following will show you how to create a layer of hexahedron elements given a quad mesh.

First, generate a Quad mesh of a spherical shell.

(*Import required FEM package*) Needs["NDSolve`FEM`"]; (*Install MeshTools*) (*Uncomment if not installed*) (*ResourceFunction["GitHubInstall"]["c3m-labs","MeshTools"]*) Needs["MeshTools`"] bmesh = SphereMesh[6]; bmesh["Wireframe"[ "MeshElementStyle" -> FaceForm[LightBlue]] ] bmesh["Wireframe"[ "MeshElement" -> "BoundaryElements", "MeshElementStyle" -> FaceForm[LightBlue], PlotRange -> {Automatic, {0, 1}, Automatic}] ] 

Shell mesh

Second, use this code to extrude a single layer of hexahedron elements at 90% of the initial radius.

crd = bmesh["Coordinates"]; inc = ElementIncidents[bmesh["BoundaryElements"]][[1]]; ncrd = Length@crd; crd = Join[crd, ScalingTransform[0.9 {1, 1, 1}]@crd]; hexinc = inc /. {{i_, j_, k_, l_} -> {i, j, k, l, i + ncrd, j + ncrd, k + ncrd, l + ncrd}}; mesh = ToElementMesh["Coordinates" -> crd, "MeshElements" -> {HexahedronElement[hexinc]}]; mesh["Wireframe"[ "MeshElement" -> "MeshElements", "MeshElementStyle" -> FaceForm[LightBlue], PlotRange -> {Automatic, {0, 1}, Automatic}] ] 

Hexahedron mesh

Update

In view of the updated question, the following workflow may be appropriate. If we assume that the boundary mesh is close to the boundary mesh produced by BallMesh, then we can use the Nearest function to match the nodes that are close and simply replace them. For example:

nf = Nearest[ball["Coordinates"] -> "Index"]; newcrd = ball["Coordinates"]; newcrd[[Flatten@nf[bnodes]]] = bnodes; ball2 = ToElementMesh["Coordinates" -> newcrd, "MeshElements" -> ball["MeshElements"]]; ball2["Wireframe"["MeshElement" -> "MeshElements", "MeshElementStyle" -> FaceForm[LightBlue], PlotRange -> {Automatic, {0, 100}, Automatic}]] 

Full volume mesh

Original answer

First, let me note a specific function within the MeshTools package called SphericalShellMesh that will give you control over the number of layers of a spherical shell hexahedron element mesh. The following will show you how to create a layer of hexahedron elements given a quad mesh.

First, generate a Quad mesh of a spherical shell.

(*Import required FEM package*) Needs["NDSolve`FEM`"]; (*Install MeshTools*) (*Uncomment if not installed*) (*ResourceFunction["GitHubInstall"]["c3m-labs","MeshTools"]*) Needs["MeshTools`"] bmesh = SphereMesh[6]; bmesh["Wireframe"[ "MeshElementStyle" -> FaceForm[LightBlue]] ] bmesh["Wireframe"[ "MeshElement" -> "BoundaryElements", "MeshElementStyle" -> FaceForm[LightBlue], PlotRange -> {Automatic, {0, 1}, Automatic}] ] 

Shell mesh

Second, use this code to extrude a single layer of hexahedron elements at 90% of the initial radius.

crd = bmesh["Coordinates"]; inc = ElementIncidents[bmesh["BoundaryElements"]][[1]]; ncrd = Length@crd; crd = Join[crd, ScalingTransform[0.9 {1, 1, 1}]@crd]; hexinc = inc /. {{i_, j_, k_, l_} -> {i, j, k, l, i + ncrd, j + ncrd, k + ncrd, l + ncrd}}; mesh = ToElementMesh["Coordinates" -> crd, "MeshElements" -> {HexahedronElement[hexinc]}]; mesh["Wireframe"[ "MeshElement" -> "MeshElements", "MeshElementStyle" -> FaceForm[LightBlue], PlotRange -> {Automatic, {0, 1}, Automatic}] ] 

Hexahedron mesh

Source Link
Tim Laska
  • 16.6k
  • 1
  • 35
  • 58

First, let me note a specific function within the MeshTools package called SphericalShellMesh that will give you control over the number of layers of a spherical shell hexahedron element mesh. The following will show you how to create a layer of hexahedron elements given a quad mesh.

First, generate a Quad mesh of a spherical shell.

(*Import required FEM package*) Needs["NDSolve`FEM`"]; (*Install MeshTools*) (*Uncomment if not installed*) (*ResourceFunction["GitHubInstall"]["c3m-labs","MeshTools"]*) Needs["MeshTools`"] bmesh = SphereMesh[6]; bmesh["Wireframe"[ "MeshElementStyle" -> FaceForm[LightBlue]] ] bmesh["Wireframe"[ "MeshElement" -> "BoundaryElements", "MeshElementStyle" -> FaceForm[LightBlue], PlotRange -> {Automatic, {0, 1}, Automatic}] ] 

Shell mesh

Second, use this code to extrude a single layer of hexahedron elements at 90% of the initial radius.

crd = bmesh["Coordinates"]; inc = ElementIncidents[bmesh["BoundaryElements"]][[1]]; ncrd = Length@crd; crd = Join[crd, ScalingTransform[0.9 {1, 1, 1}]@crd]; hexinc = inc /. {{i_, j_, k_, l_} -> {i, j, k, l, i + ncrd, j + ncrd, k + ncrd, l + ncrd}}; mesh = ToElementMesh["Coordinates" -> crd, "MeshElements" -> {HexahedronElement[hexinc]}]; mesh["Wireframe"[ "MeshElement" -> "MeshElements", "MeshElementStyle" -> FaceForm[LightBlue], PlotRange -> {Automatic, {0, 1}, Automatic}] ] 

Hexahedron mesh