CornerPointGrid¶
- class petres.grids.CornerPointGrid[source]¶
Bases:
object3D corner-point grid with explicit corner coordinates.
- Parameters:
pillars (PillarGrid) – Lateral pillar geometry defining i–j topology.
zcorn (ndarray) – Corner depths shaped
(2*nk, 2*nj, 2*ni)in Eclipse order.active (ndarray or None, optional) – Boolean mask
(nk, nj, ni);Nonemarks all cells active.zone_index (ndarray or None, optional) – Zone id per cell, same shape as the grid.
0denotes gap.zone_names (dict[int, str], optional) – Mapping of zone id to zone name.
Notes
Properties are managed via
GridPropertiesand are not stored inzcorn. Usefrom_zones()to build grids from stratigraphic zones.- pillars: PillarGrid¶
- __post_init__()[source]¶
Validate grid arrays and initialize zone lookup metadata.
- Raises:
ValueError – If
zcorn,active, or attached property shapes do not match the grid dimensions, or when a property belongs to a different grid.TypeError – If an attached entry in
_propertiesis not aGridPropertyinstance.
Notes
When
activeisNone, an all-active broadcast view is created for memory efficiency.
- summary()[source]¶
Create a human-readable summary of grid dimensions and metadata.
- Returns:
Multi-line summary including shape, active/inactive counts, registered property names, and zone names.
- Return type:
Examples
>>> text = grid.summary() >>> "Grid Summary" in text True
- set_zones(zone_index, zone_names)[source]¶
Assign zone membership arrays and zone-name metadata.
- Parameters:
zone_index (np.ndarray) –
Integer array of shape
(nk, nj, ni)assigning each cell to a zone. Values use this convention:0means gap, undefined, or unassigned.> 0means a valid zone id.
zone_names (dict[int, str], optional) – Mapping from zone id to zone name. If not provided, names will be auto-generated as “Zone {id}”.
- Raises:
ValueError – If shapes mismatch, invalid ids are present, or names are inconsistent.
TypeError – If
zone_indexcannot be converted to an integer ndarray.
- property properties: GridProperties¶
Return the property manager bound to this grid.
- Returns:
Dictionary-like facade used to access and validate cell properties.
- Return type:
GridProperties
- property ni: int¶
Get the number of cells in the i direction.
- Returns:
Cell count along the i axis.
- Return type:
- property nj: int¶
Get the number of cells in the j direction.
- Returns:
Cell count along the j axis.
- Return type:
- property nk: int¶
Get the number of layers in the k direction.
- Returns:
Layer count inferred from
zcorn.- Return type:
- property n_cells: int¶
Get the total number of cells in the grid.
- Returns:
Product of
nk * nj * ni.- Return type:
- property n_active: int¶
Get the number of active cells.
- Returns:
Count of
Truevalues inactive.- Return type:
- property n_inactive: int¶
Get the number of inactive cells.
- Returns:
Difference between total and active cell counts.
- Return type:
- property cell_centers: ndarray¶
Cell centers computed as the mean of 8 corners.
- Returns:
Coordinates shaped
(nk, nj, ni, 3).- Return type:
ndarray
- property cell_volumes: ndarray¶
Cell volumes computed via hexahedral decomposition.
- Returns:
Volumes shaped
(nk, nj, ni).- Return type:
ndarray
- classmethod from_grdecl(path, *, use_actnum=True, use_metadata=True, properties=None)[source]¶
Load a grid from a GRDECL file.
- Parameters:
path (str or Path) – Path to GRDECL file containing COORD/ZCORN (and optional ACTNUM).
use_actnum (bool, default True) – When True, read ACTNUM to set active cells; otherwise all active.
use_metadata (bool, default True) – When True, read metadata keywords from the file.
properties (Sequence[str] | None, default None) – Property names to import. If None, all available properties are imported.
- Returns:
Grid populated from GRDECL arrays.
- Return type:
- to_grdecl(path, *, properties=None, include_actnum=True)[source]¶
Write grid geometry and selected properties to a GRDECL file.
- Parameters:
- Raises:
TypeError – If
propertiesis not a valid sequence of names.MissingEclipseKeywordError – If an included property has no Eclipse keyword configured.
- show(show_inactive=False, scalars=None, color='#BFFF00', cmap='petres', title=None, z_scale=1.0, wells=None, **kwargs)[source]¶
Render the grid in 3D PyVista viewer.
- Parameters:
show_inactive (bool, default False) – Whether to display inactive cells.
scalars (str or None, optional) – Property name to color by; if
Noneuses solid color.color (Any, default DEFAULT_COLOR) – Solid color when
scalarsis not provided. Defaults to the project default color inpetres.config.colors(DEFAULT_COLOR).cmap (str or None, default DEFAULT_CMAP) – Colormap applied when
scalarsis provided.title (str or None, optional) – Figure title.
z_scale (float, default 1.0) – Scale factor for the z-axis.
wells (VerticalWell or Sequence[VerticalWell] or None, optional) – Well(s) to plot on top of the grid. Can be a single VerticalWell or a sequence of them. If
None, no wells are plotted.**kwargs (Any) – Forwarded to viewer
add_grid.
- classmethod from_rectilinear(x, y, z)[source]¶
Create a corner-point grid from rectilinear coordinate vertices.
- Parameters:
x (np.ndarray) – Monotonic x-vertex coordinates with shape
(ni + 1,).y (np.ndarray) – Monotonic y-vertex coordinates with shape
(nj + 1,).z (np.ndarray) – Layer-interface depths with shape
(nk + 1,).
- Returns:
Grid with vertical pillars and broadcasted layer surfaces.
- Return type:
- classmethod from_regular(*, xlim=None, ylim=None, zlim=None, ni=None, nj=None, nk=None, dx=None, dy=None, dz=None)[source]¶
Build a rectilinear corner-point grid from limits or spacings.
- Parameters:
xlim (tuple[float, float] or None, optional) – Minimum and maximum x bounds.
ylim (tuple[float, float] or None, optional) – Minimum and maximum y bounds.
zlim (tuple[float, float] or None, optional) – Minimum and maximum z bounds.
ni (int or None, optional) – Number of cells in i direction.
nj (int or None, optional) – Number of cells in j direction.
nk (int or None, optional) – Number of cells in k direction.
dx (float or None, optional) – Cell size in i direction.
dy (float or None, optional) – Cell size in j direction.
dz (float or None, optional) – Cell size in k direction.
- Returns:
Corner-point grid resolved from the provided geometric constraints.
- Return type:
- classmethod from_zones(*, pillars, zones)[source]¶
Create CornerPointGrid from zones with gap detection.
- Parameters:
pillars (PillarGrid) – Lateral pillar geometry
zones (Sequence[Zone]) – Zones in stratigraphic order (top to bottom)
- Returns:
Grid with gap-filling cells marked as inactive (ACTNUM=0)
- Return type:
- apply_boundary(boundary)[source]¶
Mask grid activity using a boundary polygon.
Cells whose centers fall outside the polygon become inactive (ACTNUM=0).
- Parameters:
boundary (BoundaryPolygon) – XY boundary polygon used to clip the grid.
- Returns:
Updated grid with activity masked by the boundary.
- Return type:
Notes
Updates
activein place; cached property masks may become stale.
- well_indices(well)[source]¶
Locate the surface grid column indices intersected by a vertical well.
- Parameters:
well (VerticalWell or tuple[float, float]) – Well object providing
xandymap coordinates, or a tuple of coordinates.- Returns:
Zero-based
(i, j)indices of the top-surface column containing the well head location. ReturnsNonewhen the well lies outside the grid footprint.- Return type:
Notes
This method performs a geometric XY containment lookup on the grid top surface only. It does not evaluate completion intervals or active-cell status.
- __repr__()[source]¶
Return a compact debug representation of the grid instance.
- Returns:
Representation including shape, active-cell count, and properties.
- Return type:
- __init__(pillars, zcorn, active=None, zone_index=None, zone_names=<factory>, _properties=<factory>, _eclipse_metadata=None)¶