.. 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-21 .. code-block:: Python from __future__ import annotations import tempfile from pathlib import Path import numpy as np import pyvista as pv import femorph_solver .. GENERATED FROM PYTHON SOURCE LINES 22-24 Build + solve a tiny plate -------------------------- .. GENERATED FROM PYTHON SOURCE LINES 24-46 .. 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.et(1, "SOLID185") m.mp("EX", 1, 2.0e11) m.mp("PRXY", 1, 0.30) m.mp("DENS", 1, 7850.0) pts = np.asarray(grid.points) node_nums = np.asarray(grid.point_data["ansys_node_num"]) for nn in node_nums[pts[:, 0] < 1e-9]: m.d(int(nn), "ALL") res = m.modal_solve(n_modes=4) .. rst-class:: sphx-glr-script-out .. code-block:: none /home/runner/_work/solver/solver/examples/post-processing/example_vtk_export.py:34: DeprecationWarning: Model.et(...) is a MAPDL-dialect shortcut and has moved off the Model public surface. Use `APDL(model).et(et_id, name)` for line-by-line APDL deck porting, or the native `Model.assign("HEX8", material)` for new code. m.et(1, "SOLID185") /home/runner/_work/solver/solver/examples/post-processing/example_vtk_export.py:35: DeprecationWarning: Model.mp(...) is a MAPDL-dialect shortcut and has moved off the Model public surface. Use `APDL(model).mp(prop, mat_id, value)` for line-by-line APDL deck porting, or the native `Model.assign(element, {prop: value, ...})` for new code. m.mp("EX", 1, 2.0e11) /home/runner/_work/solver/solver/examples/post-processing/example_vtk_export.py:36: DeprecationWarning: Model.mp(...) is a MAPDL-dialect shortcut and has moved off the Model public surface. Use `APDL(model).mp(prop, mat_id, value)` for line-by-line APDL deck porting, or the native `Model.assign(element, {prop: value, ...})` for new code. m.mp("PRXY", 1, 0.30) /home/runner/_work/solver/solver/examples/post-processing/example_vtk_export.py:37: DeprecationWarning: Model.mp(...) is a MAPDL-dialect shortcut and has moved off the Model public surface. Use `APDL(model).mp(prop, mat_id, value)` for line-by-line APDL deck porting, or the native `Model.assign(element, {prop: value, ...})` for new code. m.mp("DENS", 1, 7850.0) /home/runner/_work/solver/solver/examples/post-processing/example_vtk_export.py:42: DeprecationWarning: Model.d(...) is a MAPDL-dialect shortcut and has moved off the Model public surface. Use `APDL(model).d(node, label, value)` for line-by-line APDL deck porting, or the native `Model.fix(nodes=..., where=..., dof=...)` for new code. m.d(int(nn), "ALL") .. GENERATED FROM PYTHON SOURCE LINES 47-49 Write every mode as a ``.vtu`` snapshot --------------------------------------- .. GENERATED FROM PYTHON SOURCE LINES 49-54 .. 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_yyzlqn12/plate_modes.vtu (29,124 bytes) .. GENERATED FROM PYTHON SOURCE LINES 55-57 Inspect the file ---------------- .. GENERATED FROM PYTHON SOURCE LINES 57-65 .. 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 66-75 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.069 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 `_