.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\preprocessor\compute-atrial-fibers_pr.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_examples_preprocessor_compute-atrial-fibers_pr.py: Generate atrial fibers ---------------------- This example shows how to generate atrial fibers using the Laplace-Dirichlet Rule-Based (LDRB) method. .. GENERATED FROM PYTHON SOURCE LINES 31-40 .. warning:: When using a standalone version of the DPF Server, you must accept the `license terms `_. To accept these terms, you can set this environment variable: .. code-block:: python import os os.environ["ANSYS_DPF_ACCEPT_LA"] = "Y" .. GENERATED FROM PYTHON SOURCE LINES 42-46 Perform the required imports ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Import the required modules and set relevant paths, including that of the working directory, model, and LS-DYNA executable file. This example uses DEV-104373-g6d20c20aee. .. GENERATED FROM PYTHON SOURCE LINES 46-71 .. code-block:: Python import os from pathlib import Path import numpy as np import pyvista as pv from ansys.health.heart.examples import get_preprocessed_fullheart import ansys.health.heart.models as models from ansys.health.heart.simulator import BaseSimulator, DynaSettings # Specify the path to the working directory and heart model. The following path assumes # that a preprocessed model is already available workdir = Path.home() / "pyansys-heart" / "downloads" / "Rodero2021" / "01" / "FullHeart" path_to_model, path_to_partinfo, _ = get_preprocessed_fullheart() # Specify LS-DYNA path lsdyna_path = r"ls-dyna_smp" # Load heart model model: models.FourChamber = models.FourChamber(working_directory=workdir) model.load_model_from_mesh(path_to_model, path_to_model.replace(".vtu", ".partinfo.json")) .. GENERATED FROM PYTHON SOURCE LINES 72-75 Instantiate the simulator ~~~~~~~~~~~~~~~~~~~~~~~~~ Instantiate the simulator and modify options as needed. .. GENERATED FROM PYTHON SOURCE LINES 77-81 .. note:: The ``DynaSettings`` object supports several LS-DYNA versions and platforms, including ``smp``, ``intempi``, ``msmpi``, ``windows``, ``linux``, and ``wsl``. Choose the one that works for your setup. .. GENERATED FROM PYTHON SOURCE LINES 81-99 .. code-block:: Python # instantiate LS-DYNA settings of choice dyna_settings = DynaSettings( lsdyna_path=lsdyna_path, dynatype="intelmpi", num_cpus=4, platform="windows" ) simulator = BaseSimulator( model=model, dyna_settings=dyna_settings, simulation_directory=os.path.join(workdir, "simulation"), ) simulator.settings.load_defaults() # remove fiber/sheet information if it already exists model.mesh.cell_data["fiber"] = np.zeros((model.mesh.n_cells, 3)) model.mesh.cell_data["sheet"] = np.zeros((model.mesh.n_cells, 3)) .. GENERATED FROM PYTHON SOURCE LINES 100-102 Compute atrial fibers ~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 102-110 .. code-block:: Python # compute left atrium fiber la = simulator.compute_left_atrial_fiber() # Appendage apex point should be manually given to compute right atrium fiber appendage_apex = [39, 29, 98] ra = simulator.compute_right_atrial_fiber(appendage_apex) .. GENERATED FROM PYTHON SOURCE LINES 111-114 .. note:: You might need to define an appropriate point for the right atrial appendage. The list specifies the x, y, and z coordinates close to the appendage. .. GENERATED FROM PYTHON SOURCE LINES 116-118 Plot left atrial bundles ~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 118-122 .. code-block:: Python la.cell_data["bundle"] = la.cell_data["bundle"].astype(np.int32) la.set_active_scalars("bundle") la.plot() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/preprocessor/images/sphx_glr_compute-atrial-fibers_pr_001.png :alt: compute atrial fibers pr :srcset: /examples/preprocessor/images/sphx_glr_compute-atrial-fibers_pr_001.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: C:\Users\ansys\actions-runner\_work\pyansys-heart\pyansys-heart\doc\source\examples\preprocessor\images\sphx_glr_compute-atrial-fibers_pr_001.vtksz .. GENERATED FROM PYTHON SOURCE LINES 123-125 Plot right atrial bundles ~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 125-130 .. code-block:: Python ra.cell_data["bundle"] = ra.cell_data["bundle"].astype(np.int32) ra.set_active_scalars("bundle") ra.plot() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/preprocessor/images/sphx_glr_compute-atrial-fibers_pr_002.png :alt: compute atrial fibers pr :srcset: /examples/preprocessor/images/sphx_glr_compute-atrial-fibers_pr_002.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: C:\Users\ansys\actions-runner\_work\pyansys-heart\pyansys-heart\doc\source\examples\preprocessor\images\sphx_glr_compute-atrial-fibers_pr_002.vtksz .. GENERATED FROM PYTHON SOURCE LINES 131-133 Plot left atrial fibers ~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 133-143 .. code-block:: Python # plot left atrial fibers plotter = pv.Plotter() mesh = la.ctp() streamlines = mesh.streamlines(vectors="e_l", source_radius=50, n_points=5000) tubes = streamlines.tube() plotter.add_mesh(mesh, opacity=0.5, color="white") plotter.add_mesh(tubes, color="red") plotter.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/preprocessor/images/sphx_glr_compute-atrial-fibers_pr_003.png :alt: compute atrial fibers pr :srcset: /examples/preprocessor/images/sphx_glr_compute-atrial-fibers_pr_003.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: C:\Users\ansys\actions-runner\_work\pyansys-heart\pyansys-heart\doc\source\examples\preprocessor\images\sphx_glr_compute-atrial-fibers_pr_003.vtksz .. GENERATED FROM PYTHON SOURCE LINES 144-146 Plot right atrial fibers ~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 146-156 .. code-block:: Python # plot right atrial fibers plotter = pv.Plotter() mesh = ra.ctp() streamlines = mesh.streamlines(vectors="e_l", source_radius=50, n_points=5000) tubes = streamlines.tube() plotter.add_mesh(mesh, opacity=0.5, color="white") plotter.add_mesh(tubes, color="red") plotter.show() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/preprocessor/images/sphx_glr_compute-atrial-fibers_pr_004.png :alt: compute atrial fibers pr :srcset: /examples/preprocessor/images/sphx_glr_compute-atrial-fibers_pr_004.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: C:\Users\ansys\actions-runner\_work\pyansys-heart\pyansys-heart\doc\source\examples\preprocessor\images\sphx_glr_compute-atrial-fibers_pr_004.vtksz .. GENERATED FROM PYTHON SOURCE LINES 157-159 Plot full fibers on full heart model ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 159-160 .. code-block:: Python fiber_plot = model.plot_fibers(n_seed_points=5000) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/preprocessor/images/sphx_glr_compute-atrial-fibers_pr_005.png :alt: compute atrial fibers pr :srcset: /examples/preprocessor/images/sphx_glr_compute-atrial-fibers_pr_005.png :class: sphx-glr-single-img .. tab-item:: Interactive Scene .. offlineviewer:: C:\Users\ansys\actions-runner\_work\pyansys-heart\pyansys-heart\doc\source\examples\preprocessor\images\sphx_glr_compute-atrial-fibers_pr_005.vtksz .. rst-class:: sphx-glr-timing **Total running time of the script:** (2 minutes 35.823 seconds) .. _sphx_glr_download_examples_preprocessor_compute-atrial-fibers_pr.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: compute-atrial-fibers_pr.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: compute-atrial-fibers_pr.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: compute-atrial-fibers_pr.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_