Data Model of a Mesh#
Every mesh is stored in a PolyData instance, which is a subclass of
LinkedDeepDict, therefore essentially being a nest of dictionaries.
Every container in the nest can hold onto points and cells, data attached to
either the points or the cells, or other similar containers. To store data, every container
contains a data object for points, or cells, or for both. These data objects wrap themselves
around instances of awkward.Record, utilizing their effective memory layout, handling of jagged
data and general numba and gpu support.
Data Classes#
- class polymesh.pointdata.PointData(*args, points: ndarray | None = None, coords: ndarray | None = None, wrap: Record | None = None, fields: Iterable | None = None, frame: ReferenceFrame | None = None, newaxis: int = 2, activity: ndarray | None = None, db: Record | None = None, container: PolyDataBase | None = None, **kwargs)[source]#
A class to handle data related to the pointcloud of a polygonal mesh.
Technicall this is a wrapper around an
awkward.Recordinstance.If you are not a developer, you probably don’t have to ever create any instance of this class, but since it operates in the background of every polygonal data structure, it is important to understand how it works.
- property container: PolyDataBase#
Returns the container object of the block.
- property frame: ReferenceFrame#
Returns the frame of the underlying pointcloud.
- pull(key: str, ndf: ndarray | csr_matrix | None = None) ndarray[source]#
Pulls data from the cells in the model. The pulled data is either copied or distributed according to a measure.
- Parameters:
key (str) – A field key to identify data in the databases of the attached CellData instances of the blocks.
ndf (Union[ndarray, csr_matrix], Optional) – The nodal distribution factors to use. If not provided, the default factors are used. Default is None.
See also
nodal_distribution_factors(),collect_nodal_data()
- class polymesh.celldata.CellData(*args, pointdata: PointDataBase | None = None, wrap: Array | Record | None = None, topo: ndarray | None = None, fields: dict | None = None, activity: ndarray | None = None, frames: ndarray | ReferenceFrame | None = None, areas: ndarray | float | None = None, t: ndarray | float | None = None, db: Array | Record | None = None, container: PolyDataBase | None = None, **kwargs)[source]#
A class to handle data related to the cells of a polygonal mesh.
Technically this is a wrapper around an Awkward data object instance.
If you are not a developer, you probably don’t have to ever create any instance of this class, but since it operates in the background of every polygonal data structure, it is useful to understand how it works.
- Parameters:
activity (numpy.ndarray, Optional) – 1d boolean array describing the activity of the elements.
thickness (t or) – 1d float array of thicknesses. Only for 2d cells. Default is None.
areas (numpy.ndarray, Optional) – 1d float array of cross sectional areas. Only for 1d cells. Default is None.
fields (dict, Optional) – Every value of this dictionary is added to the dataset. Default is None.
frames (numpy.ndarray, Optional) – Coordinate axes representing cartesian coordinate frames. Default is None.
topo (numpy.ndarray, Optional) – 2d integer array representing node indices. Default is None.
**kwargs (dict, Optional) – For every key and value pair where the value is a numpy array with a matching shape (has entries for all cells), the key is considered as a field and the value is added to the database.
See also
awkward.Array,awkward.Record- property A#
Returns the thicknesses of the cells.
- property container: PolyDataBase#
Returns the container object of the block.
- property fields#
Returns the fields in the database object.
- property pd: PointDataBase#
Returns the attached point database. This is what the topology of the cells are referring to.
- property pointdata: PointDataBase#
Returns the attached point database. This is what the topology of the cells are referring to.
- pull(data: str | ndarray, ndf: ndarray | csr_matrix | None = None) ndarray[source]#
Pulls data from the attached pointdata. The pulled data is either copied or distributed according to a measure.
- Parameters:
data (str or numpy.ndarray) – Either a field key to identify data in the database of the attached PointData, or a NumPy array.
- set_nodal_distribution_factors(factors: ndarray, key: str | None = None)[source]#
Sets nodal distribution factors.
- Parameters:
factors (numpy.ndarray) – A 3d float array. The length of the array must equal the number pf cells in the block.
key (str, Optional) – A key used to store the values in the database. This makes you able to use more nodal distribution strategies in one model. If not specified, a default key is used.
- source() PolyDataBase[source]#
Retruns the source of the cells. This is the PolyData block that stores the PointData object the topology of the cells are referring to.
- property t#
Returns the thicknesses of the cells.
Mesh Classes#
- class polymesh.linedata.LineData(*args, areas=None, **kwargs)[source]#
Data class for 1d cells.
- plot(*args, scalars=None, backend='plotly', scalar_labels=None, **kwargs)[source]#
Plots the mesh with or without data, using multiple possible backends.
- Parameters:
scalars (numpy.ndarray, Optional) – Stacked nodal information as an 1d or 2d NumPy array. Default is None.
backend (str, Optional) – The backend to use. Possible options are plotly and vtk (vtk is being managed through PyVista) at the moment. Default is ‘plotly’.
scalar_labels (Iterable, Optional) – Labels for the datasets provided with ‘scalars’. Default is None.
- class polymesh.PolyData(pd: PointData | CellData | None = None, cd: CellData | None = None, *args, coords: ndarray | None = None, topo: ndarray | None = None, celltype=None, frame: ReferenceFrame | None = None, newaxis: int = 2, cell_fields: dict | None = None, point_fields: dict | None = None, parent: PolyData | None = None, frames: ndarray | ReferenceFrame | None = None, **kwargs)[source]#
A class to handle complex polygonal meshes.
The PolyData class is the most important class in the library and a backbone of all mesh classes.
The implementation is based on the awkward library, which provides memory-efficient, numba-jittable data classes to deal with dense, sparse, complete or incomplete data. These data structures are managed in pure Python by the DeepDict class.
The class accepts several kinds of inputs, allowing for a wide range of possible use cases. The fastes way to create a PolyData is from predefined PointData and CellData instances, defined separately.
- Parameters:
Examples
To create a simple cube:
>>> from polymesh import PolyData, PointData >>> from polymesh.grid import grid >>> from polymesh.space import StandardFrame >>> from polymesh.cells import H27 >>> size = Lx, Ly, Lz = 100, 100, 100 >>> shape = nx, ny, nz = 10, 10, 10 >>> coords, topo = grid(size=size, shape=shape, eshape='H27') >>> frame = StandardFrame(dim=3) >>> pd = PointData(coords=coords, frame=frame) >>> cd = H27(topo=topo, frames=frame) >>> mesh = PolyData(pd, frame=frame) >>> mesh['A']['Part1'] = PolyData(cd=H27(topo=topo[:10], frames=frame)) >>> mesh['A']['Part2'] = PolyData(cd=H27(topo=topo[10:-10], frames=frame)) >>> mesh['A']['Part3'] = PolyData(cd=H27(topo=topo[-10:], frames=frame)) >>> mesh.plot()
Load a mesh from a PyVista object:
>>> from pyvista import examples >>> from polymesh import PolyData >>> bunny = examples.download_bunny_coarse() >>> mesh = PolyData.from_pv(bunny)
Read from a .vtk file:
>>> from polymesh import PolyData >>> from dewloosh.core.downloads import download_stand >>> vtkpath = download_stand() >>> mesh = PolyData.read(vtkpath)
- blocks(*, inclusive: bool = False, blocktype: Any | None = None, deep: bool = True, **kw) Collection[PolyData][source]#
Returns an iterable over nested blocks.
- Parameters:
inclusive (bool, Optional) – Whether to include the object the call was made upon. Default is False.
blocktype (Any, Optional) – A required type. Default is None, which means theat all subclasses of the PolyData class are accepted. Default is None.
deep (bool, Optional) – If True, parsing goes into deep levels. If False, only the level of the current object is handled.
- Yields:
Any – A PolyData instance. The actual type depends on the ‘blocktype’ parameter.
- blocks_of_cells(i: int | Iterable | None = None) dict[source]#
Returns a dictionary that maps cell indices to blocks.
- bounds(*args, **kwargs) list[source]#
Returns the bounds of the mesh.
Example
>>> from polymesh.examples import download_stand >>> pd = download_stand(read=True) >>> pd.bounds()
- property cell_fields: Iterable[str]#
Returns the fields of all the celldata of the object.
- Returns:
NumPy array of data keys.
- Return type:
- cellblocks(*args, **kwargs) Iterable[PolyData][source]#
Returns an iterable over blocks with CellData. All arguments are forwarded to
blocks().- Yields:
Any – A CellData instance with a CellData.
- cells_around_cells(radius: float, frmt: str = 'dict')[source]#
Returns the neares cells to cells.
- Parameters:
See also
cells_around()
- cells_at_nodes(*args, **kwargs) Iterable[source]#
Returns the neighbouring cells of nodes.
- Returns:
Some kind of iterable, depending on the inputs. See the docs below for further details.
- Return type:
See also
- cells_coords(*, _topo=None, **kwargs) ndarray[source]#
Returns the coordiantes of the cells in explicit format.
- center(target: ReferenceFrame | None = None) ndarray[source]#
Returns the center of the pointcloud of the mesh.
- Parameters:
target (
FrameLike, Optional) – The target frame in which the returned coordinates are to be understood. A None value means the frame the mesh is embedded in. Default is None.- Returns:
A one dimensional float array.
- Return type:
- centers(target: ReferenceFrame | None = None) ndarray[source]#
Returns the centers of the cells.
- Parameters:
target (
FrameLike, Optional) – The target frame in which the returned coordinates are to be understood. A None value means the frame the mesh is embedded in. Default is None.- Returns:
A 2 dimensional float array.
- Return type:
- centralize(target: ReferenceFrame | None = None, inplace: bool = True, axes: Iterable | None = None) PolyData[source]#
Moves all the meshes that belong to the same source such that the current object’s center will be at the origin of its embedding frame.
- Parameters:
target (
FrameLike, Optional) – The target frame the mesh should be central to. A None value means the frame the mesh is embedded in. Default is True.inplace (bool, Optional) – If True, the transformation is done on the instance, otherwise a deep copy is created first. Default is True.
axes (Iterable, Optional) – The axes on which centralization is to be performed. A None value means all axes. Default is None.
Notes
This operation changes the coordinates of all blocks that belong to the same pointcloud as the object the function is called on.
- property config: LinkedDeepDict#
Returns the configuration object.
- Returns:
The configuration object.
- Return type:
Example
>>> from polymesh.examples import download_stand >>> mesh = download_stand(read=True)
To set configuration values related to plotting with pyVista, do the following:
>>> mesh.config['pyvista', 'plot', 'color'] = 'red' >>> mesh.config['pyvista', 'plot', 'style'] = 'wireframe'
Then, when it comes to plotting, you can specify your configuration with the config_key keyword argument:
>>> mesh.pvplot(config_key=('pyvista', 'plot'))
This way, you can store several different configurations for different scenarios.
- coords(*args, return_inds: bool = False, from_cells: bool = False, **kwargs) ndarray[source]#
Returns the coordinates as an array.
- Parameters:
- Return type:
- detach(nummrg: bool = False) PolyData[source]#
Returns a detached version of the mesh.
- Parameters:
nummrg (bool, Optional) – If True, merges node numbering. Default is False.
- property frame: ReferenceFrame#
Returns the frame of the underlying pointcloud.
- classmethod from_meshio(mesh: Mesh) PolyData[source]#
Returns a
PolyDatainstance from ameshio.Meshinstance.
- classmethod from_pv(pvobj: PolyData | PointGrid | UnstructuredGrid) PolyData[source]#
Returns a
PolyDatainstance from apyvista.PolyDataor apyvista.UnstructuredGridinstance.Example
>>> from pyvista import examples >>> from polymesh import PolyData >>> bunny = examples.download_bunny_coarse() >>> mesh = PolyData.from_pv(bunny)
- index_of_closest_cell(target: Iterable) int[source]#
Returns the index of the closest cell to a target.
- index_of_closest_point(target: Iterable) int[source]#
Returns the index of the closest point to a target.
- index_of_furthest_cell(target: Iterable) int[source]#
Returns the index of the furthest cell to a target.
- index_of_furthest_point(target: Iterable) int[source]#
Returns the index of the furthest point to a target.
- is_source(key: str | None = None) bool[source]#
Returns True, if the object is a valid source of data specified by key.
- Parameters:
key (str) – A valid key to the PointData of the mesh. If not specified the key is the key used for storing coorindates.
- k3dplot(scene=None, *, menu_visibility: bool = True, **kwargs)[source]#
Plots the mesh using ‘k3d’ as the backend.
Warning
During this call there is a UserWarning saying ‘Given trait value dtype “float32” does not match required type “float32”’. Although this is weird, plotting seems to be just fine.
- Parameters:
scene (object, Optional) – A K3D plot widget to append to. This can also be given as the first positional argument. Default is None, in which case it is created using a call to
k3d.plot().menu_visibility (bool, Optional) – Whether to show the menu or not. Default is True.
**kwargs (dict, Optional) – Extra keyword arguments forwarded to
to_k3d().
See also
to_k3d(),k3d.plot()
- k_nearest_cell_neighbours(k, *args, knn_options: dict | None = None, **kwargs)[source]#
Returns the k closest neighbours of the cells of the mesh, based on the centers of each cell.
The argument knn_options is passed to the KNN search algorithm, the rest to the centers function of the mesh.
Examples
>>> from polymesh.grid import Grid >>> from polymesh import KNN >>> size = 80, 60, 20 >>> shape = 10, 8, 4 >>> grid = Grid(size=size, shape=shape, eshape='H8') >>> X = grid.centers() >>> i = KNN(X, X, k=3, max_distance=10.0)
See also
KNN()
- lock(create_mappers: bool = False) PolyData[source]#
Locks the layout. If a PolyData instance is locked, missing keys are handled the same way as they would’ve been handled if it was a dict. Also, setting or deleting items in a locked dictionary and not possible and you will experience an error upon trying.
The object is returned for continuation.
- Parameters:
create_mappers (bool, Optional) – If True, some mappers are generated to speed up certain types of searches, like finding a block containing cells based on their indices.
- move(v: Vector | ndarray, frame: ReferenceFrame | None = None, inplace: bool = True) PolyData[source]#
Moves and returns the object or a deep copy of it.
- Parameters:
v (VectorLike, Optional) – A vector describing a translation.
frame (
FrameLike, Optional) – If v is only an array, this can be used to specify a frame in which the components should be understood.inplace (bool, Optional) – If True, the transformation is done on the instance, otherwise a deep copy is created first. Default is True.
Examples
Download the Stanford bunny and move it along global X:
>>> from polymesh.examples import download_bunny >>> import numpy as np >>> bunny = download_bunny(tetra=False, read=True) >>> bunny.move([0.2, 0, 0])
- nodal_adjacency(*args, **kwargs) Any[source]#
Returns the nodal adjecency matrix. The arguments are forwarded to the corresponding utility function (see below) alongside the topology of the mesh as the first argument.
See also
- nodal_adjacency_matrix() spmatrix[source]#
Returns the nodal adjecency matrix. The arguments are forwarded to the corresponding utility function (see below) alongside the topology of the mesh as the first argument.
See also
- Return type:
- nodal_distribution_factors(weights: str | ndarray = 'volume') ndarray | csr_matrix[source]#
Retruns nodal distribution factors for all nodes of all cells as a 2d array. The returned array has the same shape as the topology array, where the j-th factor of the i-th row is the contribution of element i to the j-th node of the cell.
- Parameters:
weights (Union[str, numpy.ndarray], Optional) – The metric which is used to calculate the factors. Valid strings are ‘volume’ and ‘uniform’. If it is an array, it must be an 1d array with a length matching the number of cells. Default is ‘volume’.
- Returns:
An array with the same shape as the topology.
- Return type:
numpy.ndarray or csr_matrix
Note
For a given node, the sum of all contribution factors from all the cells that meet at that node is one.
See also
- plot(*, notebook: bool = False, backend: str = 'pyvista', config_key: str | None = None, **kwargs)[source]#
Plots the mesh using supported backends. The default backend is PyVista.
- Parameters:
notebook (bool, Optional) – Whether to plot in an IPython notebook enviroment. This is only available for PyVista at the moment. Default is False.
backend (str, Optional) – The backend to use. Valid options are ‘k3d’ and ‘pyvista’. Default is ‘pyvista’.
config_key (str, Optional) – A configuration key if the block were configured previously. Default is None.
**kwargs (dict, Optional) – Extra keyword arguments forwarded to the plotter function according to the selected backend.
- property point_fields: Iterable[str]#
Returns the fields of all the pointdata of the object.
- Returns:
NumPy array of data keys.
- Return type:
- pointblocks(*args, **kwargs) Iterable[PolyData][source]#
Returns an iterable over blocks with PointData. All arguments are forwarded to
blocks().- Yields:
Any – A PolyData instance with a PointData.
- points(*, return_inds: bool = False, from_cells: bool = False) PointCloud[source]#
Returns the points as a
PointCloudinstance.Notes
Opposed to
coords(), which returns the coordiantes, it returns the points of a mesh as vectors.See also
- pvplot(*, deepcopy: bool = False, jupyter_backend: str = 'pythreejs', show_edges: bool = True, notebook: bool = False, theme: str | None = None, scalars: str | ndarray | None = None, window_size: Tuple | None = None, return_plotter: bool = False, config_key: Tuple | None = None, plotter: Plotter | None = None, cmap: str | Iterable | None = None, camera_position: Tuple | None = None, lighting: bool = False, edge_color: str | None = None, return_img: bool = False, show_scalar_bar: bool | None = None, **kwargs) None | Plotter | ndarray[source]#
Plots the mesh using PyVista. The parameters listed here only grasp a fraction of what PyVista provides. The idea is to have a function that narrows down the parameters as much as possible to the ones that are most commonly used. If you want more control, create a plotter prior to calling this function and provide it using the parameter plotter. Then by setting return_plotter to True, the function adds the cells to the plotter and returns it for further customization.
- Parameters:
deepcopy (bool, Optional) – If True, a deep copy is created. Default is False.
jupyter_backend (str, Optional) – The backend to use when plotting in a Jupyter enviroment. Default is ‘pythreejs’.
show_edges (bool, Optional) – If True, the edges of the mesh are shown as a wireframe. Default is True.
notebook (bool, Optional) – If True and in a Jupyter enviroment, the plot is embedded into the Notebook. Default is False.
theme (str, Optional) – The theme to use with PyVista. Default is None.
scalars (Union[str, ndarray]) – A string that refers to a field in the celldata objects of the block of the mesh, or a NumPy array with values for each point in the mesh.
window_size (tuple, Optional) – The size of the window, only is notebook is False. Default is None.
return_plotter (bool, Optional) – If True, an instance of
pyvista.Plotteris returned without being shown. Default is False.config_key (tuple, Optional) – A tuple of strings that refer to a configuration for PyVista.
plotter (pyvista.Plotter, Optional) – A plotter to use. If not provided, a plotter is created in the background. Default is None.
cmap (Union[str, Iterable], Optional) – A color map for plotting. See PyVista’s docs for the details. Default is None.
camera_position (tuple, Optional) – Camera position. See PyVista’s docs for the details. Default is None.
lighting (bool, Optional) – Whether to use lighting or not. Default is None.
edge_color (str, Optional) – The color of the edges if show_edges is True. Default is None, which equals to the default PyVista setting.
return_img (bool, Optional) – If True, a screenshot is returned as an image. Default is False.
show_scalar_bar (Union[bool, None], Optional) – Whether to show the scalar bar or not. A None value means that the option is governed by the configurations of the blocks. If a boolean is provided here, it overrides the configurations of the blocks. Default is None.
**kwargs – Extra keyword arguments passed to pyvista.Plotter, it the plotter has to be created.
- Returns:
A PyVista plotter if return_plotter is True, a NumPy array if return_img is True, or nothing.
- Return type:
Union[None, pv.Plotter, numpy.ndarray]
- classmethod read(*args, **kwargs) PolyData[source]#
Reads from a file using PyVista.
Example
Download a .vtk file and read it:
>>> from polymesh import PolyData >>> from polymesh.examples import stand_vtk >>> vtkpath = stand_vtk(read=False) >>> mesh = PolyData.read(vtkpath)
- rewire(deep: bool = True, imap: ndarray | None = None, invert: bool = False) PolyData[source]#
Rewires topology according to the index mapping of the source object.
- Parameters:
deep (bool, Optional) – If True, the action propagates down. Default is True.
imap (numpy.ndarray, Optional) – Index mapper. Either provided as a numpy array, or it gets fetched from the database. Default is None.
invert (bool, Optional) – A flag to indicate wether the provided index map should be inverted or not. Default is False.
Notes
Unless node numbering was modified, subsequent executions have no effect after once called.
- Returns:
Returnes the object instance for continuitation.
- Return type:
- rotate(*args, inplace: bool = True, **kwargs) PolyData[source]#
Rotates and returns the object. Positional and keyword arguments not listed here are forwarded to
neumann.linalg.frame.ReferenceFrame- Parameters:
*args – Forwarded to
neumann.linalg.frame.ReferenceFrame.inplace (bool, Optional) – If True, the transformation is done on the instance, otherwise a deep copy is created first. Default is True.
**kwargs – Forwarded to
neumann.linalg.frame.ReferenceFrame.
Examples
Download the Stanford bunny and rotate it about global Z with 90 degrees:
>>> from polymesh.examples import download_bunny >>> import numpy as np >>> bunny = download_bunny(tetra=False, read=True) >>> bunny.rotate("Space", [0, 0, np.pi/2], "xyz")
- source(key: str | None = None) PolyData | None[source]#
Returns the closest (going upwards in the hierarchy) block that holds on to data with a certain field name. If called without arguments, it is looking for a block with a valid pointcloud, definition, otherwise the field specified by the argument key.
- Parameters:
key (str) – A valid key in any of the blocks with data. Default is None.
- spin(*args, inplace: bool = True, **kwargs) PolyData[source]#
Like rotate, but rotation happens around centroidal axes. Positional and keyword arguments not listed here are forwarded to
neumann.linalg.frame.ReferenceFrame- Parameters:
*args – Forwarded to
neumann.linalg.frame.ReferenceFrame.inplace (bool, Optional) – If True, the transformation is done on the instance, otherwise a deep copy is created first. Default is True.
**kwargs – Forwarded to
neumann.linalg.frame.ReferenceFrame.
Examples
Download the Stanford bunny and spin it about global Z with 90 degrees:
>>> from polymesh.examples import download_bunny >>> import numpy as np >>> bunny = download_bunny(tetra=False, read=True) >>> bunny.spin("Space", [0, 0, np.pi/2], "xyz")
- to_ak(*args, point_fields: Iterable[str] | None = None, cell_fields: Iterable[str] | None = None, **__) Tuple[Array][source]#
Returns the data contained within the mesh as a tuple of two Awkward arrays.
- Parameters:
Example
>>> from polymesh.examples import stand_vtk >>> mesh = stand_vtk(read=True) >>> mesh.to_ak(point_fields=['x'])
- to_dataframe(*args, point_fields: Iterable[str] | None = None, cell_fields: Iterable[str] | None = None, **kwargs)[source]#
Returns the data contained within the mesh to pandas dataframes.
- Parameters:
Example
>>> from polymesh.examples import stand_vtk >>> mesh = stand_vtk(read=True) >>> mesh.to_dataframe(point_fields=['x'])
- to_k3d(*, scene: object | None = None, deep: bool = True, config_key: str | None = None, menu_visibility: bool = True, cmap: list | None = None, show_edges: bool = True, scalars: ndarray | None = None)[source]#
Returns the mesh as a k3d mesh object.
- :: warning:
Calling this method raises a UserWarning inside the traittypes package saying “Given trait value dtype ‘float32’ does not match required type ‘float32’.” However, plotting seems to be fine.
- Returns:
A K3D Plot Widget, which is a result of a call to k3d.plot.
- Return type:
See also
k3d.lines(),k3d.mesh()
- to_lists(*, point_fields: Iterable[str] | None = None, cell_fields: Iterable[str] | None = None) Tuple[list][source]#
Returns data of the object as a tuple of lists. The first is a list of point-related, the other one is cell-related data. Unless specified by ‘fields’, all data is returned from the pointcloud and the related cells of the mesh.
- Parameters:
Example
>>> from polymesh.examples import stand_vtk >>> mesh = stand_vtk(read=True) >>> mesh.to_lists(point_fields=['x'])
- to_parquet(path_pd: str, path_cd: str, *args, point_fields: Iterable[str] | None = None, cell_fields: Iterable[str] | None = None, **kwargs)[source]#
Saves the data contained within the mesh to parquet files.
- Parameters:
path_pd (str) – File path for point-related data.
path_cd (str) – File path for cell-related data.
point_fields (Iterable[str], Optional) – A list of keys that might identify data in a database for the points in the mesh. Default is None.
cell_fields (Iterable[str], Optional) – A list of keys that might identify data in a database for the cells in the mesh. Default is None.
Example
>>> from polymesh.examples import stand_vtk >>> mesh = stand_vtk(read=True) >>> mesh.to_parquet('pd.parquet', 'cd.parquet', point_fields=['x'])
- to_pv(deepcopy: bool = False, multiblock: bool = False, scalars: str | ndarray | None = None) UnstructuredGrid | MultiBlock[source]#
Returns the mesh as a PyVista oject, optionally set up with data.
- Parameters:
deepcopy (bool, Optional) – Default is False.
multiblock (bool, Optional) – Wether to return the blocks as a vtkMultiBlockDataSet or a list of vtkUnstructuredGrid instances. Default is False.
scalars (str or numpy.ndarray, Optional) – A string or an array describing scalar data. Default is None.
- Return type:
pyvista.UnstructuredGrid or pyvista.MultiBlock
- to_standard_form(inplace: bool = True, default_point_fields: dict | None = None, default_cell_fields: dict | None = None) PolyData[source]#
Transforms the problem to standard form, which means a centralized pointdata and regular cell indices.
Notes
Some operation might work better if the layout of the mesh admits the standard form.
- Parameters:
inplace (bool, Optional) – Performs the operations inplace. Default is True.
default_point_fields (dict, Optional) – A dictionary to define default values for missing fields for point related data. If not specified, the default is numpy.nan.
default_cell_fields (dict, Optional) – A dictionary to define default values for missing fields for cell related data. If not specified, the default is numpy.nan.
- to_vtk(deepcopy: bool = False, multiblock: bool = False) vtkUnstructuredGrid | vtkMultiBlockDataSet[source]#
Returns the mesh as a VTK object.
- topology(*args, return_inds: bool = False, jagged: bool | None = None, **kwargs) ndarray | TopologyArray[source]#
Returns the topology.
- Parameters:
return_inds (bool, Optional) – Returns the indices of the points. Default is False.
jagged (bool, Optional) – If True, returns the topology as a
TopologyArrayinstance, even if the mesh is regular. Default is False.
- Returns:
The topology as a 2d integer array.
- Return type:
Union[numpy.ndarray,
TopologyArray]
- unlock() PolyData[source]#
Releases the layout. If a PolyMesh instance is not locked, a missing key creates a new level in the layout, also setting and deleting items becomes an option. Additionally, mappers created with the call generate_cell_mappers are deleted.
The object is returned for continuation.
- class polymesh.TriMesh(*args, points=None, triangles=None, celltype=None, **kwargs)[source]#
A class to handle triangular meshes.
- Parameters:
points (numpy.ndarray, Optional) – 2d numpy array of floats, describing a pointcloud. Default is None.
triangles (numpy.ndarray, Optional) – 2d numpy array of integers, describing the topology of a polygonal mesh. Default is None.
Notes
See the PolyData class for the rest of the possible arguments to the creator of this class. Note that, points and triangles are aliases to coords and topo, but the original terminology is still available.
Examples
Triangulate a rectangle of size 800x600 with a subdivision of 10x10 and calculate the area
>>> from polymesh import TriMesh, CartesianFrame >>> A = CartesianFrame(dim=3) >>> trimesh = TriMesh(size=(800, 600), shape=(10, 10), frame=A) >>> trimesh.area() 480000.0
Extrude to create a tetrahedral mesh
>>> tetmesh = trimesh.extrude(h=300, N=5) >>> tetmesh.volume() 144000000.0
Calculate normals and tell if the triangles form a planar surface or not
>>> trimesh.normals() >>> trimesh.is_planar() True
See also
- edges(return_cells: bool = False)[source]#
Returns point indices of the unique edges in the model. If return_cells is True, it also returns the edge indices of the triangles, referencing the edges.
- Parameters:
return_cells (bool, Optional) – If True, returns the edge indices of the triangles, that can be used to reconstruct the topology. Default is False.
- Returns:
numpy.ndarray – Integer array of indices, representing point indices of edges.
numpy.ndarray, Optional – Integer array of indices, that together with the edge data reconstructs the topology.
- extrude(*args, celltype=None, h: float | None = None, N: int | None = None, **kwargs) PolyData[source]#
Exctrude mesh perpendicular to the plane of the triangulation. The target element type can be specified with the celltype argument.
- to_triobj(*args, **kwargs)[source]#
Returns a triangulation object of a specified backend. See
triangulate()for the details.Note
During the process, the 6-noded triangles of the section are converted into 3-noded ones.
See also
Triangulation,triangulate()
- class polymesh.TetMesh(*args, celltype=None, topo=None, **kwargs)[source]#
A class to handle tetrahedral meshes.
Examples
>>> from polymesh import TriMesh >>> trimesh = TriMesh(size=(800, 600), shape=(10, 10)) >>> tetmesh = trimesh.extrude(h=300, N=5) >>> tetmesh.volume() 144000000.0
- class polymesh.Grid(*args, celltype=None, frame=None, eshape=None, **kwargs)[source]#
A class to generate meshes based on grid-like data. All input arguments are forwarded to
grid(). The difference is that aPolyDatainstance is returned, insted of raw mesh data.Examples
>>> from polymesh.grid import Grid >>> size = 80, 60, 20 >>> shape = 8, 6, 2 >>> grid = Grid(size=size, shape=shape, eshape='H8')
See also