.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "examples\preprocessor\demo-material_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_demo-material_pr.py: Define materials ---------------- This example shows how to create a mechanical material and assign it to a heart part. .. GENERATED FROM PYTHON SOURCE LINES 31-33 Import material module ~~~~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 33-53 .. code-block:: Python from pathlib import Path import matplotlib.pyplot as plt from ansys.health.heart.settings.material.curve import ( ActiveCurve, constant_ca2, kumaraswamy_active, ) from ansys.health.heart.settings.material.ep_material import CellModel, EPMaterial from ansys.health.heart.settings.material.material import ( ACTIVE, ANISO, ISO, ActiveModel, Mat295, NeoHookean, ) .. GENERATED FROM PYTHON SOURCE LINES 54-56 .. note:: The unit system for heart modeling in LS-DYNA is ``["MPa", "mm", "N", "ms", "g"]``. .. GENERATED FROM PYTHON SOURCE LINES 58-61 Create a material ~~~~~~~~~~~~~~~~~ Create a Neo-Hookean material as follows. .. GENERATED FROM PYTHON SOURCE LINES 61-62 .. code-block:: Python neo = NeoHookean(rho=0.001, c10=1, nu=0.499) .. rst-class:: sphx-glr-script-out .. code-block:: none C:\Users\ansys\actions-runner\_work\pyansys-heart\pyansys-heart\examples\preprocessor\demo-material_pr.py:61: DeprecationWarning: Call to deprecated class NeoHookean. (Use *MAT_295 with the ISO module instead.) neo = NeoHookean(rho=0.001, c10=1, nu=0.499) .. GENERATED FROM PYTHON SOURCE LINES 63-65 The recommended way to create a Neo-Hookean material is by activating only the isotropic module in MAT_295. .. GENERATED FROM PYTHON SOURCE LINES 65-67 .. code-block:: Python neo2 = Mat295(rho=0.001, iso=ISO(itype=1, beta=2, kappa=1, mu1=0.05, alpha1=2)) .. GENERATED FROM PYTHON SOURCE LINES 68-70 .. note:: For more information on MAT_295, see the `LS-DYNA manuals `_. .. GENERATED FROM PYTHON SOURCE LINES 70-97 .. code-block:: Python # Additional steps follow for creating MAT_295, which is used for myocardium. # step 1: create an isotropic module iso = ISO(k1=1, k2=1, kappa=100) # step 2: create an anisotropic module fiber = ANISO.HGOFiber(k1=1, k2=1) aniso1 = ANISO(fibers=[fiber]) # Create fiber with sheet, and their interactions sheet = ANISO.HGOFiber(k1=1, k2=1) aniso2 = ANISO(fibers=[fiber, sheet], k1fs=1, k2fs=1) # step3: create the active module # example 1: # create active model 1 ac_model1 = ActiveModel.Model1() # create Ca2+ curve ac_curve1 = ActiveCurve(constant_ca2(tb=800, ca2ionm=ac_model1.ca2ionm), type="ca2", threshold=0.5) # build active module active = ACTIVE(model=ac_model1, ca2_curve=ac_curve1) ## Active model 1 must have a constant ca2ion, # but the curve must cross the threshold at every start of the heart beat. .. GENERATED FROM PYTHON SOURCE LINES 98-101 Plot Ca2+ with threshold ~~~~~~~~~~~~~~~~~~~~~~~~ Plot Ca2+ with the threshold. .. GENERATED FROM PYTHON SOURCE LINES 101-112 .. code-block:: Python fig = active.ca2_curve.plot_time_vs_ca2() plt.show() # example 2 # create active model 3 ac_model3 = ActiveModel.Model3() # create a stress curve and show ac_curve3 = ActiveCurve(kumaraswamy_active(t_end=800), type="stress") fig = ac_curve3.plot_time_vs_stress() plt.show() .. rst-class:: sphx-glr-horizontal * .. image-sg:: /examples/preprocessor/images/sphx_glr_demo-material_pr_001.png :alt: demo material pr :srcset: /examples/preprocessor/images/sphx_glr_demo-material_pr_001.png :class: sphx-glr-multi-img * .. image-sg:: /examples/preprocessor/images/sphx_glr_demo-material_pr_002.png :alt: demo material pr :srcset: /examples/preprocessor/images/sphx_glr_demo-material_pr_002.png :class: sphx-glr-multi-img .. GENERATED FROM PYTHON SOURCE LINES 113-116 .. note:: When eta=0 in model 3, the stress curve is the active stress for all elements. If eta!=0, this is the idealized active stress when fiber stretch stays at 1. .. GENERATED FROM PYTHON SOURCE LINES 116-124 .. code-block:: Python # PyAnsys Heart converts the stress curve to Ca2+ curve (input of MAT_295) fig = ac_curve3.plot_time_vs_ca2() plt.show() # build active module active3 = ACTIVE(model=ac_model3, ca2_curve=ac_curve3) .. image-sg:: /examples/preprocessor/images/sphx_glr_demo-material_pr_003.png :alt: demo material pr :srcset: /examples/preprocessor/images/sphx_glr_demo-material_pr_003.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 125-128 Create MAT_295 with modules ~~~~~~~~~~~~~~~~~~~~~~~~~~~ Create MAT_295 with the preceding modules. .. GENERATED FROM PYTHON SOURCE LINES 128-132 .. code-block:: Python iso_mat = Mat295(rho=1, iso=iso, aniso=None, active=None) passive_mat = Mat295(rho=1, iso=iso, aniso=aniso1, active=None) active_mat = Mat295(rho=1, iso=iso, aniso=aniso1, active=active) .. GENERATED FROM PYTHON SOURCE LINES 133-135 Create EP materials ~~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 135-147 .. code-block:: Python ep_mat_active = EPMaterial.Active( sigma_fiber=1, sigma_sheet=0.5, beta=140, cm=0.01, cell_model=CellModel.Tentusscher() ) epinsulator = EPMaterial.Insulator() # import pyvista as pv # ############################################################################## # .. note:: # The Ca2+ curve is ignored if the simulation is coupled with electrophysiology. .. GENERATED FROM PYTHON SOURCE LINES 148-151 Assign materials to a part ~~~~~~~~~~~~~~~~~~~~~~~~~~ Assign the materials to the heart model. .. GENERATED FROM PYTHON SOURCE LINES 154-156 Load a heart model ~~~~~~~~~~~~~~~~~~ .. GENERATED FROM PYTHON SOURCE LINES 158-160 .. note:: You must complete the full heart preprocessing example first. .. GENERATED FROM PYTHON SOURCE LINES 160-177 .. code-block:: Python import ansys.health.heart.examples as examples import ansys.health.heart.models as models heart_model_vtu, heart_model_partinfo, _ = examples.get_preprocessed_fullheart() workdir = str(Path.home() / "pyansys-heart" / "Rodero2021") # Load a full-heart model. heartmodel: models.FullHeart = models.FullHeart(working_directory=workdir) heartmodel.load_model_from_mesh(heart_model_vtu, heart_model_partinfo) heartmodel.plot_mesh(show_edges=False) # Print the default material. You should see that the material is empty. print(heartmodel.left_ventricle.meca_material) print(heartmodel.left_ventricle.ep_material) .. tab-set:: .. tab-item:: Static Scene .. image-sg:: /examples/preprocessor/images/sphx_glr_demo-material_pr_004.png :alt: demo material pr :srcset: /examples/preprocessor/images/sphx_glr_demo-material_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_demo-material_pr_004.vtksz .. rst-class:: sphx-glr-script-out .. code-block:: none Material is empty. Material is empty. .. GENERATED FROM PYTHON SOURCE LINES 178-181 .. note:: If no material is set before writing k files, the default material from the ``settings`` object is used. .. GENERATED FROM PYTHON SOURCE LINES 181-190 .. code-block:: Python # Assign the material that you just created. heartmodel.left_ventricle.meca_material = active_mat heartmodel.left_ventricle.ep_material = ep_mat_active # Print it. You should see the following: # MAT295(rho=1, iso=ISO(itype=-3, beta=0.0, nu=0.499, k1=1, k2=1), aopt=2.0, aniso=ANISO(atype=-1, fibers=[ANISO.HGOFiber(k1=1, k2=1, a=0.0, b=1.0, _theta=0.0, _ftype=1, _fcid=0)], k1fs=None, k2fs=None, vec_a=(1.0, 0.0, 0.0), vec_d=(0.0, 1.0, 0.0), nf=1, intype=0), active=ActiveModel.Model1(t0=None, ca2ion=None, ca2ionm=4.35, n=2, taumax=0.125, stf=0.0, b=4.75, l0=1.58, l=1.85, dtmax=150, mr=1048.9, tr=-1629.0)) # noqa print(heartmodel.left_ventricle.meca_material) print(heartmodel.left_ventricle.ep_material) .. rst-class:: sphx-glr-script-out .. code-block:: none Mat295(rho=1, iso=ISO(itype=-3, beta=0.0, nu=0.4950166112956811, k1=1, k2=1, mu1=None, alpha1=None, kappa=100), aopt=2.0, aniso=ANISO(atype=-1, fibers=[ANISO.HGOFiber(k1=1, k2=1, a=0.0, b=1.0, _theta=0.0, _ftype=1, _fcid=0)], k1fs=None, k2fs=None, vec_a=(1.0, 0.0, 0.0), vec_d=(0.0, 1.0, 0.0), nf=1, intype=0), active=ACTIVE(acid=None, actype=1, acthr=0.5, acdir=1, sf=1.0, ss=0.0, sn=0.0, model=ActiveModel.Model1(t0=None, ca2ion=None, ca2ionm=4.35, n=2, taumax=0.125, stf=0.0, b=4.75, l0=1.58, l=1.85, dtmax=150, mr=1048.9, tr=-1629.0), ca2_curve=)) EPMaterial.Active(sigma_fiber=1, sigma_sheet=0.5, sigma_sheet_normal=0.1, beta=140, cm=0.01, lambda_=None, cell_model=CellModel.Tentusscher(gas_constant=8314.472, t=310, faraday_constant=96485.3415, cm=0.185, vc=0.016404, vsr=0.001094, vss=5.468e-05, pkna=0.03, ko=5.4, nao=140.0, cao=2.0, gk1=5.405, gkr=0.153, gna=14.838, gbna=0.0002, gcal=3.98e-05, gbca=0.000592, gpca=0.1238, gpk=0.0146, pnak=2.724, km=1.0, kmna=40.0, knaca=1000.0, ksat=0.1, alpha=2.5, gamma=0.35, kmca=1.38, kmnai=87.5, kpca=0.0005, k1=0.15, k2=0.045, k3=0.06, k4=0.005, ec=1.5, maxsr=2.5, minsr=1.0, vrel=0.102, vleak=0.00036, vxfer=0.0038, vmaxup=0.006375, kup=0.00025, bufc=0.2, kbufc=0.001, bufsr=10.0, kbufsf=0.3, bufss=0.4, kbufss=0.00025, gks=0.392, gto=0.294, v=-85.23, ki=136.89, nai=8.604, cai=0.000126, cass=0.00036, casr=3.64, rpri=0.9073, xr1=0.00621, xr2=0.4712, xs=0.0095, m=0.00172, h=0.7444, j=0.7045, d=3.373e-05, f=0.7888, f2=0.9755, fcass=0.9953, s=0.999998, r=2.42e-08)) .. GENERATED FROM PYTHON SOURCE LINES 191-192 Create a new part and set material .. GENERATED FROM PYTHON SOURCE LINES 192-199 .. code-block:: Python # # A new part can be created by elements IDs # ids = np.where(heartmodel.mesh.point_data_to_cell_data()["uvc_longitudinal"] > 0.9)[0] # new_part: Part = heartmodel.create_part_by_ids(ids, "new_part") # # Show the part # plotter = heartmodel.plot_part(new_part) .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 7.785 seconds) .. _sphx_glr_download_examples_preprocessor_demo-material_pr.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: demo-material_pr.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: demo-material_pr.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: demo-material_pr.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_