Skip to content

FESAPI Python Binding Issue: UnstructuredGridRepresentation.setGeometry() Type Error #367

@CVA-AntoineE

Description

@CVA-AntoineE

Summary

The Python bindings for resqml2::UnstructuredGridRepresentation::setGeometry() and setHexahedraOnlyGeometry() consistently fail with type errors when passing FESAPI array types (DoubleArray, UInt64Array, UInt8Array), despite the method signatures appearing correct in Python.

Environment

  • FESAPI Version: 2.14.0 (with pip install fesapi)
  • Python Version: 3.11+
  • Operating System: Windows 11

Expected Behavior

The following code should successfully set unstructured grid geometry:

import fesapi
import numpy as np

# Create repository and grid
repo = fesapi.DataObjectRepository()
grid = repo.createUnstructuredGridRepresentation(
    "uuid-here",
    "Test Grid",
    100  # cell count
)

# Create HDF proxy
hdf_proxy = repo.createHdfProxy(
    "uuid-here",
    "HDF5 Proxy",
    "",
    "",
    fesapi.DataObjectRepository.openingMode_READ_WRITE
)

# Prepare arrays
points = fesapi.DoubleArray(300)  # 100 points * 3 coords
for i in range(300):
    points.setitem(i, float(i))

face_indices = fesapi.UInt64Array(600)  # 100 cells * 6 faces
for i in range(600):
    face_indices.setitem(i, int(i % 100))

node_indices = fesapi.UInt64Array(2400)  # ~4 nodes per face avg
for i in range(2400):
    node_indices.setitem(i, int(i % 100))

face_handedness = fesapi.UInt8Array(600)
for i in range(600):
    face_handedness.setitem(i, 1)

# This should work but fails
grid.setHexahedraOnlyGeometry(
    face_handedness,  # uint8_t *
    points,           # double *
    100,              # pointCount
    100,              # faceCount
    hdf_proxy,        # AbstractHdfProxy *
    face_indices,     # uint64_t *
    node_indices      # uint64_t *
)

Actual Behavior

The call fails with:

TypeError: Wrong number or type of arguments for overloaded function 'Resqml2_UnstructuredGridRepresentation_setHexahedraOnlyGeometry'.
  Possible C/C++ prototypes are:
    resqml2::UnstructuredGridRepresentation::setHexahedraOnlyGeometry(uint8_t *,double *,uint64_t,uint64_t,eml2::AbstractHdfProxy *,uint64_t *,uint64_t *,eml2::AbstractLocal3dCrs *)
    resqml2::UnstructuredGridRepresentation::setHexahedraOnlyGeometry(uint8_t *,double *,uint64_t,uint64_t,eml2::AbstractHdfProxy *,uint64_t *,uint64_t *)

Investigation

Python Signature (via inspect)

import inspect
print(inspect.signature(grid.setHexahedraOnlyGeometry))

Output:

(cellFaceIsRightHanded: 'uint8_t *', points: 'double *', pointCount: 'uint64_t',
 faceCount: 'uint64_t', proxy: 'Eml2_AbstractHdfProxy', faceIndicesPerCell: 'uint64_t *',
 nodeIndicesPerFace: 'uint64_t *', localCrs: 'Eml2_AbstractLocal3dCrs' = None) -> 'void'

The signature appears correct, but the SWIG-generated code doesn't accept the FESAPI array types.

Tested Approaches

  1. FESAPI Array Types (DoubleArray, UInt64Array, UInt8Array)

    • Created via constructor: fesapi.DoubleArray(size)
    • Populated with setitem(index, value)
    • Result: Type error
  2. NumPy Arrays (contiguous, correct dtype)

    • np.ascontiguousarray(data, dtype=np.float64)
    • np.ascontiguousarray(data, dtype=np.uint64)
    • np.ascontiguousarray(data, dtype=np.uint8)
    • Result: Type error
  3. Different Method Variants

    • setGeometry() - Full signature with cumulative counts
    • setHexahedraOnlyGeometry() - Simplified for hexahedra
    • setTetrahedraOnlyGeometry() - Simplified for tetrahedra
    • Result: All fail with same error
  4. With/Without Optional Parameters

    • Tried with explicit None for localCrs
    • Tried without localCrs parameter
    • Result: Both fail

Successful Method Calls

The following FESAPI methods work correctly with the same array types:

# Property creation works fine
prop = repo.createContinuousProperty(...)
fesapi_values = fesapi.DoubleArray(n)
for i, val in enumerate(values):
    fesapi_values.setitem(i, float(val))

prop.pushBackDoubleHdf5Array3dOfValues(
    fesapi_values,  # DoubleArray accepted here
    n_cells, 1, 1,
    min_val, max_val,
    hdf_proxy
)
# ✓ This works!

This proves the SWIG bindings can accept FESAPI array types in some contexts.

Additional Information

Related Methods Affected

All of these methods show the same issue:

  • setGeometry()
  • setHexahedraOnlyGeometry()
  • setTetrahedraOnlyGeometry()
  • setGeometryUsingExistingDatasets() (different signature, but may have similar issues)

Metadata

Metadata

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions