BaseContainerHandler
BaseContainerHandler#
- class project_heart.modules.container.basecontainerhandler.BaseContainerHandler(mesh=None, enums={}, log_level=20, *args, **kwargs)#
Data storage obj.
- add_discrete_set(name, discrete_set: numpy.ndarray, replace: bool = False, dtype: numpy.dtype = <class 'numpy.int64'>) None #
Adds a discrete set to the current object. Discreset sets, in this case, are defined as relationships between nodes. It should be a np.ndarray of shape [nx2], in which n refers to the number of relations in the set, and the columns represent node ids of two different set of nodes (relations will be defined rowise).
- Parameters
name (dict key acceptable) – Key reference to discrete set.
discrete_set (np.ndarray) – Array of set relationships defined in rowise fashion (each row of col 0 will be related to each row in col 1). Must be of shape [nx2].
replace (bool, optional) – Flag that prevents overwrites. Defaults to False.
dtype (np.dtype, optional) – If discrete_set is not a np.ndarray, it will be converted to one and dtype will be used to determine it’s type. Defaults to np.int64.
- Raises
KeyError – If replace is invalid and name is already present in self._discrete_sets’
ValueError – If discrete_set is not a np.ndarray and it could not be converted to one; or if shape of array is not [nx2].
- add_nodeset(name: str, ids: numpy.ndarray, overwrite: bool = False, dtype: numpy.dtype = <class 'numpy.int64'>) None #
Adds a list of indexes as a nodeset.
- Parameters
name (str) – nodeset name.
ids (np.ndarray) – list of indexes referencing the nodes of given nodeset.
overwrite (bool, optional) – _description_. Defaults to False.
dtype (np.dtype, optional) – _description_. Defaults to np.int64.
- Raises
ValueError – if ids is not an ndarray
ValueError – if ids is not only composed of integers
ValueError – if max id is greater than number of nodes/points
KeyError – _description_
- add_surface_oi(name: str, ids: numpy.ndarray, overwrite: bool = False, dtype: numpy.dtype = <class 'numpy.int64'>) None #
Adds a surface of interest.
- Parameters
name (str) – surface_oi name.
ids (np.ndarray) – list of indexes referencing the nodes of given surface_oi.
overwrite (bool, optional) – _description_. Defaults to False.
dtype (np.dtype, optional) – _description_. Defaults to np.int64.
- Raises
ValueError – if ids is not an ndarray
ValueError – if ids is not only composed of integers
ValueError – if max id is greater than number of nodes/points
KeyError – _description_
- cells(key: Optional[project_heart.enums.vtk_elements.VTK_ELEMENTS] = None, mask: Optional[numpy.ndarray] = None, as_json_ready=False, **kwargs) dict #
Returns a pointer to the dictionary of cells in the mesh. If key is provided, it returns the array of cells of given key. If key and mask are provided, it returns the specified range of cells of given key and mask.
- Parameters
key (VTK_ELEMENTS, optional) – int corresponding to VTK_ELEMENTS number (ex: 12-> HEXAHEDRON). Defaults to None.
mask (np.ndarray, optional) – An index or boolean mask. Defaults to None.
- Returns
A dictionary containing {VTK_ELEMENTS: np.ndarray([]), …} pairs or a specified range of cells (ndarray (nxm)).
- Return type
dict or np.ndarray
- check_hex8_mesh() bool #
Checks if mesh is composed of pure simple hexahedrons (8 nodes).
- Returns
bool
- check_mesh_data(mesh_data: str) tuple #
Check whether given mesh_data is in mesh or surface mesh
- Parameters
mesh_data (str) – Mesh data name (or Enum corresponding to mesh data name).
- Returns
(in_mesh, in_surf_mesh)
- Return type
tuple (bool, bool)
- check_tet4_mesh() bool #
Checks if mesh is composed of pure simple tetrahedrons (4 nodes).
- Returns
bool
- check_tri3_surfmesh() bool #
Checks if surface mesh is composed of pure simple triangles (3 nodes).
- Returns
bool
- check_vtkElements_mesh(vtk_elem_value: int) bool #
Checks if mesh is composed of pure ‘vtk_elem_value’.
- Parameters
vtk_elem_value (int or Enum) – Vtk element number representation.
- Returns
bool
- check_vtkElements_surfmesh(vtk_elem_value: int) bool #
Checks if surface mesh is composed of pure ‘vtk_elem_value’.
- Parameters
vtk_elem_value (int or Enum) – Vtk element number representation.
- Returns
bool
- elements(key: Optional[project_heart.enums.vtk_elements.VTK_ELEMENTS] = None, mask: Optional[numpy.ndarray] = None, **kwargs) dict #
Alias of self.cells method. Returns a pointer to the dictionary of cells in the mesh. If key is provided, it returns the array of cells of given key. If key and mask are provided, it returns the specified range of cells of given key and mask.
- Parameters
key (VTK_ELEMENTS, optional) – int corresponding to VTK_ELEMENTS number (ex: 12-> HEXAHEDRON). Defaults to None.
mask (np.ndarray, optional) – An index or boolean mask. Defaults to None.
- Returns
A dictionary containing {VTK_ELEMENTS: cells…} pairs or a specified range of cells (ndarray (nxm)).
- Return type
dict or np.ndarray
- classmethod from_nodes_elements(nodes: numpy.ndarray, elements: numpy.ndarray, el_offset: int = 0, p_dtype: numpy.dtype = <class 'numpy.float32'>, e_dtype: numpy.dtype = <class 'numpy.int64'>, **kwargs)#
- Creates a mesh dataset from pre-defined nodes and elements.
Note: as it creates mesh purely based on nodes and elements, any additional information will be ignored.
- Parameters
nodes (np.ndarray) – An array containing [x,y,z] coordinates (size should be nx3).
elements (np.ndarray) – A nested list of elements (expected as np.object array) indicating the node index of each element.
el_offset (int) – offset that indicates which element it should start counting from. Defaults to 0.
p_dtype (np.type, optional) – dtype of points. Defaults to np.float32.
e_dtype (np.type, optional) – dtype of elements. Defaults to np.int64.
- get(what: str = GEO_DATA.STATES, key: Optional[str] = None, mask: Optional[numpy.ndarray] = None, i: Optional[int] = None, t: Optional[float] = None) numpy.ndarray #
This method is convinient way to retrieve specified data from the BaseContainerHandler object. The argument ‘what’ must be specified, it determines the location in which the method will look for the data. The ‘mask’ argument can be used to retrieve only specified range; it can be boolean or index array. If data is to be retrieved from States, a key must be specified. The arguments ‘i’ and ‘t’ can be used to specify a given state timestep; ‘i’ determines the timestep index, while ‘t’ determines the timestep value (if t is not in timesteps, it will look for the closest valid timestep).
Note: if ‘i’ and ‘t’ are specified, ‘i’ will be used and ‘t’ will be ignored.
- Parameters
what (GEO_DATA, optional) – A string inferreing to GEO_DATA (where to look for the data). Defaults to GEO_DATA.STATES.
key (str, enum or list/tuple of keys, optional) – Identifies the state data to be retrieved. If list is provided, will try to vertically stack data. Defaults to None.
mask (np.ndarray or None, optional) – A boolean or index array. Defaults to None.
i (int or None, optional) – Timestep index. Defaults to None.
t (float or None, optional) – Timestep value. Defaults to None.
- Raises
ValueError – If ‘what’ is not int or GEO_DATA.
ValueError – If States is requested but ‘key’ is not specified (is None).
ValueError – If GEO_DATA is invalid.
- Returns
Array of requested data.
- Return type
np.ndarray
- merge_mesh_and_surface_mesh() pyvista.core.pointset.UnstructuredGrid #
Combines mesh and surface mesh into a single mesh dataset. This is often required for some FEA solvers or other libraries (such as LDRB).
- Returns
Merged mesh.
- Return type
pv.UnstructuredGrid
- nodes(mask: Optional[numpy.ndarray] = None) numpy.ndarray #
Alias of self.points method: returns a pointer to the list of points in the mesh.
- Parameters
mask (np.ndarray, optional) – An index or boolean mask. Defaults to None.
- Returns
pointer to array of points [[x,y,z]…] (nx3).
- Return type
np.ndarray
- points(mask: Optional[numpy.ndarray] = None) numpy.ndarray #
Returns a pointer to the list of points in the mesh.
- Parameters
mask (np.ndarray, optional) – An index or boolean mask. Defaults to None.
- Returns
pointer to array of points [[x,y,z]…] (nx3).
- Return type
np.ndarray
- prep_for_gmsh(cellregionIds: numpy.ndarray, mesh: Optional[pyvista.core.pointset.UnstructuredGrid] = None) pyvista.core.pointset.UnstructuredGrid #
Prepares a given mesh for gmsh meshion export. Includes gmsh:physical and gmsh:geometrical data with ‘cellregionIds’ data.
- Parameters
cellregionIds (np.ndarray) – Integer list identifying regions.
mesh (pv.UnstructuredGrid, optional) – Mesh object to export. Defaults to None (uses self.mesh).
- Returns
Mesh dataset with “gmsh:physical” and “gmsh:geometrical” in cell_data.
- Return type
pv.UnstructuredGrid
- smooth_surface(**kwargs)#
Adjust point coordinates using Laplacian smoothing.
Uses Pyvista smoothing method: https://bit.ly/37ee3hU
WARNING: This function applies smoothing at surface level
by modifying their coordinates directly, which does not imply
that cell volumes (if volumetric mesh) will be adjusted.
- states() dict #
Returns a pointer to the the states dictionary in self.States. Only use this method if you want to directly modify states information. Otherwise use ‘self.get’.
- Returns
{DATA_FIELDS: np.ndarray[], …} pairs
- Return type
dict
- tetrahedralize(backend=TETRA_BACKEND.TETGEN, make_manifold=True, **kwargs)#
DOC PENDING.
This is a wrap method for the Wildmeshing library: https://wildmeshing.github.io/python/ and the tetgen library https://tetgen.pyvista.org/. Credits should be to the owners of the original libraries.
- Parameters
backend (_type_, optional) – _description_. Defaults to TETRA_BACKEND.TETGEN.
make_manifold (bool, optional) – _description_. Defaults to True.
- Raises
ImportError – _description_
ImportError – _description_
NotImplementedError – _description_
- timesteps() list #
Returns a pointer to the timesteps array contained in self.States.
- Returns
list of timesteps [0.0, t1, t2 … t]
- Return type
list
- to_csv(filename, **kwargs)#
Write states to csv file