|
| 1 | +# Copyright (C) 2023 - 2025 ANSYS, Inc. and/or its affiliates. |
| 2 | +# SPDX-License-Identifier: MIT |
| 3 | +# |
| 4 | +# |
| 5 | +# Permission is hereby granted, free of charge, to any person obtaining a copy |
| 6 | +# of this software and associated documentation files (the "Software"), to deal |
| 7 | +# in the Software without restriction, including without limitation the rights |
| 8 | +# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 9 | +# copies of the Software, and to permit persons to whom the Software is |
| 10 | +# furnished to do so, subject to the following conditions: |
| 11 | +# |
| 12 | +# The above copyright notice and this permission notice shall be included in all |
| 13 | +# copies or substantial portions of the Software. |
| 14 | +# |
| 15 | +# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 16 | +# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 17 | +# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 18 | +# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 19 | +# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 20 | +# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 21 | +# SOFTWARE. |
| 22 | + |
| 23 | +"""Factory for creating EP material models.""" |
| 24 | + |
| 25 | +from typing import Literal |
| 26 | + |
| 27 | +from pint import Quantity |
| 28 | + |
| 29 | +from ansys.health.heart.settings.material.ep_material import ( |
| 30 | + Active, |
| 31 | + ActiveBeam, |
| 32 | + EPSolverType, |
| 33 | + Passive, |
| 34 | +) |
| 35 | + |
| 36 | + |
| 37 | +def get_default_myocardium_material( |
| 38 | + ep_solver_type: EPSolverType | Literal["Monodomain", "Eikonal", "ReactionEikonal"], |
| 39 | +) -> Active: |
| 40 | + """Get the default myocardium material for a solver type. |
| 41 | +
|
| 42 | + Parameters |
| 43 | + ---------- |
| 44 | + ep_solver_type : EPSolverType | str |
| 45 | + The type of EP solver to select appropriate defaults for. |
| 46 | +
|
| 47 | + Returns |
| 48 | + ------- |
| 49 | + Active |
| 50 | + The default myocardium EP material model. |
| 51 | + """ |
| 52 | + if isinstance(ep_solver_type, str): |
| 53 | + ep_solver_type = EPSolverType(ep_solver_type) |
| 54 | + |
| 55 | + # import defaults depending on solver type. |
| 56 | + if ep_solver_type in (EPSolverType.REACTION_EIKONAL, EPSolverType.EIKONAL): |
| 57 | + from ansys.health.heart.settings.defaults.electrophysiology import ( |
| 58 | + default_myocardium_material_eikonal as defaults, |
| 59 | + ) |
| 60 | + if ep_solver_type == EPSolverType.MONODOMAIN: |
| 61 | + from ansys.health.heart.settings.defaults.electrophysiology import ( |
| 62 | + default_myocardium_material_monodomain as defaults, |
| 63 | + ) |
| 64 | + |
| 65 | + # Remove units from default Quantity values. |
| 66 | + defaults = {k: (v.m if isinstance(v, Quantity) else v) for k, v in defaults.items()} |
| 67 | + |
| 68 | + return Active(**defaults) |
| 69 | + |
| 70 | + |
| 71 | +def get_passive_material( |
| 72 | + ep_solver_type: EPSolverType | Literal["Monodomain", "Eikonal", "ReactionEikonal"], |
| 73 | +) -> Passive: |
| 74 | + """Get the default passive material for a solver type. |
| 75 | +
|
| 76 | + Parameters |
| 77 | + ---------- |
| 78 | + ep_solver_type : EPSolverType | str |
| 79 | + The type of EP solver to select appropriate defaults for. |
| 80 | +
|
| 81 | + Returns |
| 82 | + ------- |
| 83 | + Passive |
| 84 | + The default passive EP material model. |
| 85 | + """ |
| 86 | + if isinstance(ep_solver_type, str): |
| 87 | + ep_solver_type = EPSolverType(ep_solver_type) |
| 88 | + |
| 89 | + # import defaults depending on solver type. |
| 90 | + if ep_solver_type in (EPSolverType.REACTION_EIKONAL, EPSolverType.EIKONAL): |
| 91 | + from ansys.health.heart.settings.defaults.electrophysiology import ( |
| 92 | + default_myocardium_material_eikonal as defaults, |
| 93 | + ) |
| 94 | + if ep_solver_type == EPSolverType.MONODOMAIN: |
| 95 | + from ansys.health.heart.settings.defaults.electrophysiology import ( |
| 96 | + default_myocardium_material_monodomain as defaults, |
| 97 | + ) |
| 98 | + |
| 99 | + # Remove units from default Quantity values. |
| 100 | + defaults = {k: (v.m if isinstance(v, Quantity) else v) for k, v in defaults.items()} |
| 101 | + |
| 102 | + del defaults["sigma_sheet"] |
| 103 | + del defaults["sigma_sheet_normal"] |
| 104 | + |
| 105 | + return Passive(**defaults) |
| 106 | + |
| 107 | + |
| 108 | +def get_default_conduction_system_material( |
| 109 | + ep_solver_type: EPSolverType | Literal["Monodomain", "Eikonal", "ReactionEikonal"], |
| 110 | +) -> ActiveBeam: |
| 111 | + """Get the default conduction-system (beam) material for a solver type. |
| 112 | +
|
| 113 | + Parameters |
| 114 | + ---------- |
| 115 | + ep_solver_type : EPSolverType | str |
| 116 | + The type of EP solver to select appropriate defaults for. |
| 117 | +
|
| 118 | + Returns |
| 119 | + ------- |
| 120 | + ActiveBeam |
| 121 | + The default conduction system material. |
| 122 | + """ |
| 123 | + if isinstance(ep_solver_type, str): |
| 124 | + ep_solver_type = EPSolverType(ep_solver_type) |
| 125 | + |
| 126 | + # import defaults depending on solver type. |
| 127 | + if ep_solver_type in (EPSolverType.REACTION_EIKONAL, EPSolverType.EIKONAL): |
| 128 | + from ansys.health.heart.settings.defaults.electrophysiology import ( |
| 129 | + default_beam_material_eikonal as defaults, |
| 130 | + ) |
| 131 | + elif ep_solver_type == EPSolverType.MONODOMAIN: |
| 132 | + from ansys.health.heart.settings.defaults.electrophysiology import ( |
| 133 | + default_beam_material_monodomain as defaults, |
| 134 | + ) |
| 135 | + |
| 136 | + # Remove units from default Quantity values. |
| 137 | + defaults = {k: (v.m if isinstance(v, Quantity) else v) for k, v in defaults.items()} |
| 138 | + |
| 139 | + return ActiveBeam(**defaults) |
0 commit comments