Skip to content

Commit

Permalink
Introduce two notched beam for hotspot detection demo (#26)
Browse files Browse the repository at this point in the history
Signed-off-by: Johannes Mueller <[email protected]>
  • Loading branch information
johannes-mueller authored Sep 1, 2023
1 parent 5f52fc3 commit cff53da
Show file tree
Hide file tree
Showing 6 changed files with 26 additions and 23 deletions.
19 changes: 11 additions & 8 deletions demos/hotspot_plate.ipynb → demos/hotspot_beam.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@
"metadata": {},
"outputs": [],
"source": [
"vm_mesh = pylife.vmap.VMAPImport(\"plate_with_hole.vmap\")\n",
"mesh = (vm_mesh.make_mesh('1', 'STATE-2')\n",
"vm_mesh = pylife.vmap.VMAPImport(\"two_notched_beam.vmap\")\n",
"mesh = (vm_mesh.make_mesh('beam', 'STATE-1')\n",
" .join_coordinates()\n",
" .join_variable('STRESS_CAUCHY')\n",
" .join_variable('DISPLACEMENT')\n",
Expand Down Expand Up @@ -81,7 +81,7 @@
"metadata": {},
"outputs": [],
"source": [
"threshold = .9 # factor of the maximum local value\n",
"threshold = .3 # factor of the maximum local value\n",
"mesh['hotspot'] = mesh.hotspot.calc(\"mises\", threshold)\n",
"display(mesh[['x', 'y', 'z', 'mises', 'hotspot']])"
]
Expand All @@ -103,8 +103,7 @@
"source": [
"grid = pv.UnstructuredGrid(*mesh.mesh.vtk_data())\n",
"plotter = pv.Plotter(window_size=[1920, 1080])\n",
"plotter.add_mesh(grid, scalars=mesh.groupby('element_id')['hotspot'].first().to_numpy(),\n",
" show_edges=True, cmap='prism_r')\n",
"plotter.add_mesh(grid, scalars=mesh.groupby('element_id')['hotspot'].first().to_numpy(), show_edges=True)\n",
"plotter.add_scalar_bar()\n",
"plotter.show()"
]
Expand All @@ -113,7 +112,7 @@
"cell_type": "markdown",
"metadata": {},
"source": [
"### First hotspot"
"### Hotspots"
]
},
{
Expand Down Expand Up @@ -141,7 +140,10 @@
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
"source": [
"third_hotspot = mesh[mesh['hotspot'] == 3]\n",
"display(third_hotspot)"
]
},
{
"cell_type": "code",
Expand All @@ -166,7 +168,8 @@
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3"
"pygments_lexer": "ipython3",
"version": "3.10.9"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion demos/index.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
"\n",
"In a connected FEM mesh, hotspots of a scalar value like damage sum, or von Mises stress can be detected and classified.\n",
"\n",
"[Hotspot detection](hotspot_plate.ipynb)\n",
"[Hotspot detection](hotspot_beam.ipynb)\n",
"\n",
"\n",
"### Gradients in a mesh\n",
Expand Down
Binary file added demos/two_notched_beam.vmap
Binary file not shown.
4 changes: 4 additions & 0 deletions docs/demos/hotspot_beam.nblink
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
{
"path": "../../demos/hotspot_beam.ipynb",
"extra-media": ["../../demos/two_notched_beam.vmap"]
}
4 changes: 0 additions & 4 deletions docs/demos/hotspot_plate.nblink

This file was deleted.

20 changes: 10 additions & 10 deletions tests/demos/test_demo_notebooks.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,27 +38,27 @@ def change_workingdir_dir(monkeypatch):
monkeypatch.chdir('demos')


@testbook('demos/hotspot_plate.ipynb')
def test_hotspot_plate(tb):
@testbook('demos/hotspot_beam.ipynb')
def test_hotspot_beam(tb):
with tb.patch('pyvista.Plotter'):
tb.execute()

tb.inject(
"""
first_hotspot = mesh[mesh['hotspot'] == 1]
pd.testing.assert_index_equal(
first_hotspot.index,
pd.MultiIndex.from_tuples([(456, 5), (456, 6433)], names=['element_id', 'node_id'])
)
assert len(first_hotspot) == 1296
"""
)
tb.inject(
"""
second_hotspot = mesh[mesh['hotspot'] == 2]
pd.testing.assert_index_equal(
second_hotspot.index,
pd.MultiIndex.from_tuples([(2852, 9)], names=['element_id', 'node_id'])
)
assert len(second_hotspot) == 1504
"""
)
tb.inject(
"""
third_hotspot = mesh[mesh['hotspot'] == 3]
assert len(third_hotspot) == 160
"""
)

Expand Down

0 comments on commit cff53da

Please sign in to comment.