|
33 | 33 | "cell_type": "markdown", |
34 | 34 | "metadata": {}, |
35 | 35 | "source": [ |
36 | | - "First we visually inspect the geometry and check it is as expected.\n", |
| 36 | + "Optionally we can visually inspect the geometry with Paraview and check it is as expected.\n", |
37 | 37 | "\n", |
38 | 38 | "We convert the DAGMC h5m file to a vtkhdf file which can be opened with [Paraview](https://www.paraview.org/download/) or as we do here, loaded with pyvista and viewed interactively in the notebook." |
39 | 39 | ] |
|
47 | 47 | "di.convert_h5m_to_vtkhdf(h5m_filename='dagmc.h5m', vtkhdf_filename='dagmc.vtkhdf')" |
48 | 48 | ] |
49 | 49 | }, |
50 | | - { |
51 | | - "cell_type": "code", |
52 | | - "execution_count": null, |
53 | | - "metadata": {}, |
54 | | - "outputs": [], |
55 | | - "source": [ |
56 | | - "# TEMP WORKAROUND - remove once dagmc_h5m_file_inspector > 0.7.0 (with the ASCII\n", |
57 | | - "# string fix) is installed. Version 0.7.0 writes the 'material_names' field as\n", |
58 | | - "# UTF-8 strings, which VTK's VTKHDF reader cannot read, so the pv.read() below\n", |
59 | | - "# fails with an H5Dread \"no appropriate function for conversion path\" error.\n", |
60 | | - "# Here we rewrite that field as ASCII so VTK can open the file.\n", |
61 | | - "# Fix: https://github.com/fusion-energy/dagmc_h5m_file_inspector/pull/49\n", |
62 | | - "import h5py\n", |
63 | | - "with h5py.File('dagmc.vtkhdf', 'a') as f:\n", |
64 | | - " field_data = f['VTKHDF/FieldData']\n", |
65 | | - " material_names = [\n", |
66 | | - " name.decode() if isinstance(name, (bytes, bytearray)) else str(name)\n", |
67 | | - " for name in field_data['material_names'][:]\n", |
68 | | - " ]\n", |
69 | | - " del field_data['material_names']\n", |
70 | | - " field_data.create_dataset(\n", |
71 | | - " 'material_names', data=material_names, dtype=h5py.string_dtype('ascii')\n", |
72 | | - " )" |
73 | | - ] |
74 | | - }, |
75 | | - { |
76 | | - "cell_type": "code", |
77 | | - "execution_count": null, |
78 | | - "metadata": {}, |
79 | | - "outputs": [], |
80 | | - "source": [ |
81 | | - "# setting the pyvista backend to html makes the plot interactive in the notebook\n", |
82 | | - "pv.set_jupyter_backend('html')\n", |
83 | | - "\n", |
84 | | - "plotter = pv.Plotter()\n", |
85 | | - "\n", |
86 | | - "# reading in the vtkhdf file and colouring the geometry by the material id\n", |
87 | | - "dagmc_geometry = pv.read('dagmc.vtkhdf')\n", |
88 | | - "plotter.add_mesh(dagmc_geometry, scalars='material_id', show_edges=True)\n", |
89 | | - "\n", |
90 | | - "plotter.show()" |
91 | | - ] |
92 | | - }, |
93 | 50 | { |
94 | 51 | "cell_type": "markdown", |
95 | 52 | "metadata": {}, |
|
0 commit comments