Skip to content

Instantly share code, notes, and snippets.

@pshriwise
Last active December 11, 2025 04:24
Show Gist options
  • Select an option

  • Save pshriwise/11d5033c373ab64b7aa728cf28ea3e82 to your computer and use it in GitHub Desktop.

Select an option

Save pshriwise/11d5033c373ab64b7aa728cf28ea3e82 to your computer and use it in GitHub Desktop.
Add surfaces to a set of volumes containing only tet elements
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"id": "22f4067c-a33a-403b-bed2-50348b7ff5c7",
"metadata": {},
"outputs": [],
"source": [
"import pydagmc\n",
"from pymoab import skinner, types"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "23898faa-e995-4335-959a-b91c7be282ac",
"metadata": {},
"outputs": [],
"source": [
"input_file = 'input_file.h5m'\n",
"output_file = 'output_file.h5m'"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "a74fc5ba-fbc2-472d-aaaa-b929477f0005",
"metadata": {},
"outputs": [],
"source": [
"model = pydagmc.Model(input_file)"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "f801118a-be60-494a-9eb4-0896bd89cbfa",
"metadata": {},
"outputs": [],
"source": [
"def get_volume_skin_tris(mb, volume):\n",
" mb_skinner = skinner.Skinner(mb)\n",
" volume_elements = mb.get_entities_by_type(volume.handle, types.MBTET)\n",
" skin_tris = mb_skinner.find_skin(mb.get_root_set(), volume_elements, False, False)\n",
" return skin_tris"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "28231711-d78b-4de2-b6a5-ba11dbb8580b",
"metadata": {},
"outputs": [],
"source": [
"for volume in model.volumes:\n",
" skin_tris = get_volume_skin_tris(model.mb, volume)\n",
" skin_verts = model.mb.get_connectivity(skin_tris)\n",
" surface = model.create_surface()\n",
" \n",
" model.mb.add_entities(surface.handle, skin_tris)\n",
" model.mb.add_entities(surface.handle, skin_verts)\n",
"\n",
" model.mb.add_parent_child(volume.handle, surface.handle)\n",
" surface.forward_volume = volume "
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "1d1f7faa-0f0d-4d23-b57d-dc37e746f542",
"metadata": {},
"outputs": [],
"source": [
"model.write_file(output_file)"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "0131f8b8-c517-4c06-9914-45f5af941b8d",
"metadata": {},
"outputs": [],
"source": [
"model = pydagmc.Model(output_file)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "40fb73e8-2dca-460c-9d04-ba53195ab918",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[Surface 1, 484 triangles]"
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model.volumes[0].surfaces\n"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.7"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment