.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\simulator\ep-mechanics-simulator-fullheart.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-mechanics-simulator-fullheart.py: Run a full-heart EP mechanics simulation ---------------------------------------- This example shows how to consume a full-heart model and set it up for a coupled electromechanical simulation. .. 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-45 Perform the required imports ~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Import the required modules. .. GENERATED FROM PYTHON SOURCE LINES 45-57 .. code-block:: Python import os from pathlib import Path from pint import Quantity from ansys.health.heart.examples import get_preprocessed_fullheart import ansys.health.heart.models as models from ansys.health.heart.settings.material.ep_material import EPMaterial from ansys.health.heart.settings.material.material import ISO, Mat295 from ansys.health.heart.simulator import DynaSettings, EPMechanicsSimulator .. GENERATED FROM PYTHON SOURCE LINES 58-61 Set the required paths ~~~~~~~~~~~~~~~~~~~~~~ Set the working directory and path to the model. .. GENERATED FROM PYTHON SOURCE LINES 61-68 .. code-block:: Python # Get the path to a preprocessed full-heart model. path_to_model, path_to_partinfo, _ = get_preprocessed_fullheart(resolution="2.0mm") # Set the working directory. workdir = Path.home() / "pyansys-heart" / "downloads" / "Rodero2021" / "01" / "FullHeart" .. GENERATED FROM PYTHON SOURCE LINES 69-71 Load the full-heart model ~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 71-76 .. code-block:: Python # Load the full-heart model. model: models.FullHeart = models.FullHeart(working_directory=workdir) model.load_model_from_mesh(path_to_model, path_to_partinfo) .. GENERATED FROM PYTHON SOURCE LINES 77-79 Instantiate the simulator ~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 79-96 .. code-block:: Python # Create and instantiate a DYNA settings object. Modify where necessary. lsdyna_path = r"your_dyna_exe" dyna_settings = DynaSettings( lsdyna_path=lsdyna_path, dynatype="intelmpi", platform="wsl", num_cpus=4 ) # Instantiate the simulator. simulator = EPMechanicsSimulator( model=model, dyna_settings=dyna_settings, simulation_directory=os.path.join(workdir, "ep-mechanics"), ) # Load default simulation settings. simulator.settings.load_defaults() .. GENERATED FROM PYTHON SOURCE LINES 97-99 Compute the fiber orientation ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 99-112 .. code-block:: Python # Compute fiber orientation in the ventricles and atria. simulator.compute_fibers() simulator.compute_left_atrial_fiber() simulator.compute_right_atrial_fiber(appendage=[39, 29, 98]) # Switch the atria to active. simulator.model.left_atrium.fiber = True simulator.model.left_atrium.active = True simulator.model.right_atrium.fiber = True simulator.model.right_atrium.active = True .. GENERATED FROM PYTHON SOURCE LINES 113-115 Set up the simulation for the mechanical simulations ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 115-138 .. code-block:: Python # Extract elements around atrial caps and assign as a passive material. ring = simulator.model.create_atrial_stiff_ring(radius=5) # Assign a material that is stiffer than the surrounding material. stiff_iso = Mat295(rho=0.001, iso=ISO(itype=-1, beta=2, kappa=10, mu1=0.1, alpha1=2)) ring.meca_material = stiff_iso # Assign the default EP material ring.ep_material = EPMaterial.Active() # plot the mesh simulator.model.plot_mesh() # Compute UHCs (Universal Heart Coordinates). simulator.compute_uhc() # Extract elements close to the valves and assign these a passive material. simulator.model.create_stiff_ventricle_base(stiff_material=stiff_iso) # Compute the stress-free configuration. simulator.compute_stress_free_configuration(overwrite=True) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/simulator/images/sphx_glr_ep-mechanics-simulator-fullheart_001.png :alt: ep mechanics simulator fullheart :srcset: /examples/simulator/images/sphx_glr_ep-mechanics-simulator-fullheart_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-mechanics-simulator-fullheart_001.vtksz .. image-sg:: /examples/simulator/images/sphx_glr_ep-mechanics-simulator-fullheart_002.png :alt: EDVPR :srcset: /examples/simulator/images/sphx_glr_ep-mechanics-simulator-fullheart_002.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 139-146 .. note:: Computing the stress-free configuration is required since the geometry is imaged at end-of-diastole. The ``compute_stress_free_configuration()`` method runs a sequence of static simulations to estimate the stress-free state of the model and the initial stresses present. This step is computationally expensive and can take relatively long. You can consider reusing earlier runs by setting the ``overwrite`` flag to ``False``. This reuses the results of the previous run. .. GENERATED FROM PYTHON SOURCE LINES 148-150 Compute a conduction system ~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 150-160 .. code-block:: Python # Compute the conduction system. simulator.compute_purkinje() # Use landmarks to compute the rest of the conduction system. simulator.compute_conduction_system() # Plot the computed conduction system. simulator.model.plot_purkinje() .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/simulator/images/sphx_glr_ep-mechanics-simulator-fullheart_003.png :alt: ep mechanics simulator fullheart :srcset: /examples/simulator/images/sphx_glr_ep-mechanics-simulator-fullheart_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\simulator\images\sphx_glr_ep-mechanics-simulator-fullheart_003.vtksz .. GENERATED FROM PYTHON SOURCE LINES 161-164 Start the main simulation ~~~~~~~~~~~~~~~~~~~~~~~~~ Set the simulation end time and frequency of output files. .. GENERATED FROM PYTHON SOURCE LINES 164-170 .. code-block:: Python simulator.settings.mechanics.analysis.end_time = Quantity(800, "ms") simulator.settings.mechanics.analysis.dt_d3plot = Quantity(10, "ms") # Save the model to a file. simulator.model.save_model(os.path.join(workdir, "heart_fib_beam.vtu")) .. GENERATED FROM PYTHON SOURCE LINES 171-174 .. note:: A constant pressure is prescribed to the atria. No circulation system is coupled with the atria. .. GENERATED FROM PYTHON SOURCE LINES 174-182 .. code-block:: Python # Use the ReactionEikonal solver for the electrophysiology simulation. simulator.settings.electrophysiology.analysis.solvertype = "ReactionEikonal" # Start main simulation. The ``auto_post`` option is set to ``False`` to avoid # automatic postprocessing. simulator.simulate(auto_post=False) .. GENERATED FROM PYTHON SOURCE LINES 183-188 .. note:: The ``ReactionEikonal`` solver is suitable for coarse meshes and is included here for demonstration purposes. However, it currently supports only a single cardiac cycle. To simulate multiple cardiac cycles, use the ``Monodomain`` solver, which requires a fine mesh and small time step size. .. GENERATED FROM PYTHON SOURCE LINES 190-192 Visualize and animate results LS-PrePost ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 194-200 .. only:: html .. video:: ../../_static/images/rodero_epmechanics_fullheart.mp4 :width: 600 :loop: :class: center .. rst-class:: sphx-glr-timing **Total running time of the script:** (60 minutes 48.195 seconds) .. _sphx_glr_download_examples_simulator_ep-mechanics-simulator-fullheart.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: ep-mechanics-simulator-fullheart.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: ep-mechanics-simulator-fullheart.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: ep-mechanics-simulator-fullheart.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_