Source code for femorph_solver.elements._base
"""Abstract element interface."""
from __future__ import annotations
from abc import ABC, abstractmethod
from typing import ClassVar
import numpy as np
CANONICAL_DOFS: tuple[str, ...] = ("UX", "UY", "UZ", "ROTX", "ROTY", "ROTZ")
[docs]
class ElementBase(ABC):
name: ClassVar[str]
n_nodes: ClassVar[int]
n_dof_per_node: ClassVar[int]
vtk_cell_type: ClassVar[int]
dof_labels: ClassVar[tuple[str, ...]]
def __init_subclass__(cls, **kwargs: object) -> None:
super().__init_subclass__(**kwargs)
if "dof_labels" not in cls.__dict__ and "n_dof_per_node" in cls.__dict__:
cls.dof_labels = CANONICAL_DOFS[: cls.n_dof_per_node]
@classmethod
def n_dof(cls) -> int:
return cls.n_nodes * cls.n_dof_per_node
[docs]
@staticmethod
@abstractmethod
def ke(
coords: np.ndarray,
material: dict[str, float],
real: np.ndarray,
) -> np.ndarray:
"""Return the element stiffness matrix in global DOF ordering.
Parameters
----------
coords : (n_nodes, 3) float64
material : mapping with property names as keys (``"EX"``, ``"PRXY"``, ``"DENS"``, ...)
real : 1-D array of real constants
"""
[docs]
@staticmethod
@abstractmethod
def me(
coords: np.ndarray,
material: dict[str, float],
real: np.ndarray,
lumped: bool = False,
) -> np.ndarray:
"""Return the element mass matrix in global DOF ordering."""