Skip to content

Python API for Unstructured Mesh Field Transfer#258

Draft
Sichao25 wants to merge 9 commits intoSCOREC:developfrom
Sichao25:yus/field
Draft

Python API for Unstructured Mesh Field Transfer#258
Sichao25 wants to merge 9 commits intoSCOREC:developfrom
Sichao25:yus/field

Conversation

@Sichao25
Copy link
Contributor

@Sichao25 Sichao25 commented Feb 6, 2026

Introduce Python APIs for transferring fields between unstructured and structured meshes. It includes:

  • Definition of uniform grid field and layout
  • Python bindings for essential transfer functions

@@ -0,0 +1,84 @@
import py_pcms
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make the python module name just pcms instead of py_pcms? This might require writing a __init__.py since the compiled shared library probably still needs to be called py_pcms.so to avoid naming conflicts.


# Create layout
print(" About to create layout...")
layout = py_pcms.create_lagrange_layout(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

default to num_components=1 and Cartesian for the coordinate system.


# Create copied field and copy data
copied = layout.create_field()
py_pcms.copy_field2_Real(original, copied)
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

take of the 2 from the name. Also, we should handle the types internally. So in the interface we take in the field and in the interface layer we dispatch to the appropriate type.

py::arg("data"),
"Set the DOF holder data")

.def("to_mdspan", [](const UniformGridField<2>& self) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

On the python side we should change the name to to_numpy with everything else the same.

I also think there may be a way to avoid the copy: https://pybind11.readthedocs.io/en/stable/advanced/pycpp/numpy.html

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants