Simulator#

The simulator module links different simulation steps for cardiac modeling. For example, in electrophysiology simulations, you compute fiber orientation and the Purkinje network using the BaseSimulator.compute_fibers and EPSimulator.compute_purkinje methods before running the physical simulation. In mechanical simulations, you compute the stress-free configuration using the MechanicsSimulator.compute_stress_free_configuration method before running the simulation.

You create different simulators based on the application and physics of interest:

Here is a simple code example:

Load a heart model.

import ansys.health.heart.models as models
model = models.HeartModel.load_model("path_to_model.vtu", "path_to_info.partinfo.json")

Set up the LS-DYNA settings.

from ansys.health.heart.simulator.simulator import DynaSettings, MechanicsSimulator
dyna_settings = DynaSettings(
    lsdyna_path="path-to-lsdyna-exe.exe",
    dynatype="intelmpi",
    platform="windows",
    num_cpus=8
)

Instantiate the simulator.

simulator = EPSimulator(
    model=model,
    dyna_settings=dyna_settings,
    simulation_directory="output-path"
)

The settings module saves default modeling parameters. You can load these parameters into the simulator:

simulator.settings.load_defaults()
# Print settings
print(simulator.settings.mechanics.analysis.end_time)
# Output: 800 millisecond
# Change it to 1600 ms
simulator.settings.mechanics.analysis.end_time = Quantity(1600, "ms")
# Save to a YAML file
simulator.settings.save("a-yaml-file.yml")

Alternatively, you can load settings from a YAML file:

simulator.settings.load("a-yaml-file.yml")

Finally, run the relevant steps before running the final simulation of the physics of interest:

simulator.compute_fibers()
simulator.compute_purkinje()
simulator.simulate()

For comprehensive examples, see Simulator examples.