.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\simulator\ep-simulator-fullheart_rodero.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_simulator_ep-simulator-fullheart_rodero.py: Run a full-heart electrophysiology simulation --------------------------------------------- This example shows how to consume a full-heart model and set it up for the main electrophysiology simulation. It loads a pre-computed heart model and computes the fiber orientation, Purkinje network, and conduction system. It then simulates the electrophysiology. .. GENERATED FROM PYTHON SOURCE LINES 34-43 .. 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 45-49 Perform the required imports ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Import the required modules and set relevant paths, including that of the working directory, heart model, and LS-DYNA executable file. .. GENERATED FROM PYTHON SOURCE LINES 49-62 .. code-block:: Python import os from pathlib import Path from ansys.health.heart.examples import get_preprocessed_fullheart import ansys.health.heart.models as models from ansys.health.heart.simulator import DynaSettings, EPSimulator # Set the working directory and path to the model. This example assumes that there is a workdir = Path.home() / "pyansys-heart" / "downloads" / "Rodero2021" / "01" / "FullHeart" path_to_model, path_to_partinfo, _ = get_preprocessed_fullheart(resolution="2.0mm") .. GENERATED FROM PYTHON SOURCE LINES 63-66 Load the full-heart model ~~~~~~~~~~~~~~~~~~~~~~~~~ Load the full-heart model. .. GENERATED FROM PYTHON SOURCE LINES 66-73 .. code-block:: Python model: models.FullHeart = models.HeartModel.load_model( path_to_model, path_to_partinfo, working_directory=workdir ) # Save the model. model.mesh.save(os.path.join(model.workdir, "simulation_model.vtu")) .. GENERATED FROM PYTHON SOURCE LINES 74-77 Instantiate the simulator ~~~~~~~~~~~~~~~~~~~~~~~~~ Instantiate the simulator and define settings. .. GENERATED FROM PYTHON SOURCE LINES 79-83 .. 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 83-99 .. code-block:: Python # Specify the LS-DYNA path. (The last tested working version is ``intelmpi-linux-DEV-106117``.) lsdyna_path = r"ls-dyna_msmpi.exe" # Instantiate LS-DYNA settings. dyna_settings = DynaSettings( lsdyna_path=lsdyna_path, dynatype="intelmpi", num_cpus=4, platform="windows" ) # Instantiate the simulator, modifying options as necessary. simulator = EPSimulator( model=model, dyna_settings=dyna_settings, simulation_directory=os.path.join(workdir, "simulation-EP"), ) .. GENERATED FROM PYTHON SOURCE LINES 100-103 Load simulation settings ~~~~~~~~~~~~~~~~~~~~~~~~ Load the default settings. .. GENERATED FROM PYTHON SOURCE LINES 103-105 .. code-block:: Python simulator.settings.load_defaults() .. GENERATED FROM PYTHON SOURCE LINES 106-109 Compute fiber orientation ~~~~~~~~~~~~~~~~~~~~~~~~~ Compute fiber orientation and plot the fibers on the entire model. .. GENERATED FROM PYTHON SOURCE LINES 109-122 .. code-block:: Python # Compute ventricular fibers. simulator.compute_fibers(method="D-RBM") # Compute atrial fibers. simulator.model.right_atrium.active = True simulator.model.left_atrium.active = True simulator.model.right_atrium.fiber = True simulator.model.left_atrium.fiber = True simulator.compute_left_atrial_fiber() simulator.compute_right_atrial_fiber(appendage=[39, 29, 98]) simulator.model.plot_fibers(n_seed_points=1000) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/simulator/images/sphx_glr_ep-simulator-fullheart_rodero_001.png :alt: ep simulator fullheart rodero :srcset: /examples/simulator/images/sphx_glr_ep-simulator-fullheart_rodero_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\simulator\images\sphx_glr_ep-simulator-fullheart_rodero_001.vtksz .. rst-class:: sphx-glr-script-out .. code-block:: none .. GENERATED FROM PYTHON SOURCE LINES 123-127 Compute the conduction system ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Compute the conduction system and Purkinje network, and then visualize the results. The action potential propagates faster through this system compared to the rest of the model. .. GENERATED FROM PYTHON SOURCE LINES 127-136 .. code-block:: Python simulator.compute_purkinje() # By calling this method, stimulation is at the atrioventricular node. # If you do not call this method, the two apex regions of the ventricles are stimulated. simulator.compute_conduction_system() simulator.model.plot_purkinje() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/simulator/images/sphx_glr_ep-simulator-fullheart_rodero_002.png :alt: ep simulator fullheart rodero :srcset: /examples/simulator/images/sphx_glr_ep-simulator-fullheart_rodero_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\simulator\images\sphx_glr_ep-simulator-fullheart_rodero_002.vtksz .. GENERATED FROM PYTHON SOURCE LINES 137-141 Start the main simulation ~~~~~~~~~~~~~~~~~~~~~~~~~ Start the main electrophysiology simulation. This uses the previously computed fiber orientation and Purkinje network to set up and run the LS-DYNA model. .. GENERATED FROM PYTHON SOURCE LINES 141-146 .. code-block:: Python # Compute the Eikonal solution. This only computes the activation time. simulator.settings.electrophysiology.analysis.solvertype = "ReactionEikonal" simulator.simulate(folder_name="main-ep-ReactionEikonal") .. rst-class:: sphx-glr-timing **Total running time of the script:** (7 minutes 39.688 seconds) .. _sphx_glr_download_examples_simulator_ep-simulator-fullheart_rodero.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ep-simulator-fullheart_rodero.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ep-simulator-fullheart_rodero.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: ep-simulator-fullheart_rodero.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_