Source code for simcardems.value_extractor
import abc
import typing
from enum import Enum
import dolfin
import numpy as np
from . import utils
from .geometry import BaseGeometry
from .lvgeometry import LeftVentricularGeometry
from .slabgeometry import SlabGeometry
logger = utils.getLogger(__name__)
[docs]
def center_func(fmin, fmax):
return fmin + (fmax - fmin) / 2
[docs]
class Boundary(abc.ABC):
def __init__(self, mesh):
self.mesh = mesh
[docs]
@staticmethod
@abc.abstractmethod
def nodes() -> typing.Sequence[str]: ...
[docs]
class LVBoundary(Boundary):
[docs]
@staticmethod
def nodes():
return []
[docs]
class SlabBoundaryNodes(Enum):
center = "center"
xmax = "xmax"
xmin = "xmin"
ymax = "ymax"
ymin = "ymin"
zmax = "zmax"
zmin = "zmin"
[docs]
class SlabBoundary(Boundary):
[docs]
@staticmethod
def nodes():
return SlabBoundaryNodes._member_names_
@property
def boundaries(self):
coords = self.mesh.coordinates()
return dict(
max_x=coords.T[0].max(),
min_x=coords.T[0].min(),
max_y=coords.T[1].max(),
min_y=coords.T[1].min(),
max_z=coords.T[2].max(),
min_z=coords.T[2].min(),
)
@property
def xmin(self):
return [
self.boundaries["min_x"],
center_func(self.boundaries["min_y"], self.boundaries["max_y"]),
center_func(self.boundaries["min_z"], self.boundaries["max_z"]),
]
@property
def xmax(self):
return [
self.boundaries["max_x"],
center_func(self.boundaries["min_y"], self.boundaries["max_y"]),
center_func(self.boundaries["min_z"], self.boundaries["max_z"]),
]
@property
def ymin(self):
return [
center_func(self.boundaries["min_x"], self.boundaries["max_x"]),
self.boundaries["min_y"],
center_func(self.boundaries["min_z"], self.boundaries["max_z"]),
]
@property
def ymax(self):
return [
center_func(self.boundaries["min_x"], self.boundaries["max_x"]),
self.boundaries["max_y"],
center_func(self.boundaries["min_z"], self.boundaries["max_z"]),
]
@property
def zmin(self):
return [
center_func(self.boundaries["min_x"], self.boundaries["max_x"]),
center_func(self.boundaries["min_y"], self.boundaries["max_y"]),
self.boundaries["min_z"],
]
@property
def zmax(self):
return [
center_func(self.boundaries["min_x"], self.boundaries["max_x"]),
center_func(self.boundaries["min_y"], self.boundaries["max_y"]),
self.boundaries["max_z"],
]
@property
def center(self):
return [
center_func(self.boundaries["min_x"], self.boundaries["max_x"]),
center_func(self.boundaries["min_y"], self.boundaries["max_y"]),
center_func(self.boundaries["min_z"], self.boundaries["max_z"]),
]