.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "gallery/post-processing/example_vtk_export.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_gallery_post-processing_example_vtk_export.py: Exporting results to VTK / ParaView =================================== Once you've got a ``ModalResult`` / ``StaticResult``, sending it downstream to ParaView / VisIt / any VTK-aware tool is a one-liner. :mod:`femorph_solver.io` wraps the pyvista writers so you don't have to hand-roll the point-data scatter. .. GENERATED FROM PYTHON SOURCE LINES 10-22 .. code-block:: Python from __future__ import annotations import tempfile from pathlib import Path import numpy as np import pyvista as pv import femorph_solver from femorph_solver import ELEMENTS .. GENERATED FROM PYTHON SOURCE LINES 23-25 Build + solve a tiny plate -------------------------- .. GENERATED FROM PYTHON SOURCE LINES 25-43 .. code-block:: Python grid = pv.StructuredGrid( *np.meshgrid( np.linspace(0.0, 1.0, 11), np.linspace(0.0, 0.3, 5), np.linspace(0.0, 0.01, 3), indexing="ij", ) ).cast_to_unstructured_grid() m = femorph_solver.Model.from_grid(grid) m.assign(ELEMENTS.HEX8, material={"EX": 2.0e11, "PRXY": 0.30, "DENS": 7850.0}) pts = np.asarray(grid.points) node_nums = np.asarray(grid.point_data["ansys_node_num"]) m.fix(nodes=node_nums[pts[:, 0] < 1e-9].tolist(), dof="ALL") res = m.modal_solve(n_modes=4) .. GENERATED FROM PYTHON SOURCE LINES 44-46 Write every mode as a ``.vtu`` snapshot --------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 46-51 .. code-block:: Python out_dir = Path(tempfile.mkdtemp(prefix="femorph_solver_docs_")) vtu_path = out_dir / "plate_modes.vtu" femorph_solver.io.write_modal_vtk(vtu_path, m, res) print(f"wrote modal snapshot → {vtu_path} ({vtu_path.stat().st_size:,} bytes)") .. rst-class:: sphx-glr-script-out .. code-block:: none wrote modal snapshot → /tmp/femorph_solver_docs_n9l3ibbs/plate_modes.vtu (29,264 bytes) .. GENERATED FROM PYTHON SOURCE LINES 52-54 Inspect the file ---------------- .. GENERATED FROM PYTHON SOURCE LINES 54-62 .. code-block:: Python back = pv.read(str(vtu_path)) vector_arrays = [ name for name in back.point_data if name.startswith("mode_") and name.endswith("_disp") ] print(f"file carries {len(vector_arrays)} mode-shape vector fields:") for name in vector_arrays: print(f" {name}: shape = {back.point_data[name].shape}") .. rst-class:: sphx-glr-script-out .. code-block:: none file carries 4 mode-shape vector fields: mode_1_disp: shape = (165, 3) mode_2_disp: shape = (165, 3) mode_3_disp: shape = (165, 3) mode_4_disp: shape = (165, 3) .. GENERATED FROM PYTHON SOURCE LINES 63-72 For a single static field, the canonical pattern is the same ------------------------------------------------------------ :func:`femorph_solver.io.static_result_to_grid` is the static analogue of :func:`modal_result_to_grid`. Example: .. code-block:: python grid_static = femorph_solver.io.static_result_to_grid(m, static_res) grid_static.save("static.vtu") .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.062 seconds) .. _sphx_glr_download_gallery_post-processing_example_vtk_export.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: example_vtk_export.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: example_vtk_export.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: example_vtk_export.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_