Skip to content

Conversation

@greschd
Copy link
Member

@greschd greschd commented Jul 14, 2023

Add elemental_data and nodal_data attributes to tree objects, which fetch the
data from the mesh query API.

The returned objects have a method to_pyvista, to convert to a plottable object. Currently,
this requires the Model.mesh to be passed in; we may consider how this can be avoided.

Optionally, a component (name to be improved) can be passed, to select which data to
add to the PyVista mesh. If a vector component is selected, the data is converted to arrows.

The possible string constants for component are exposed in the ElementalDataType and
NodalDataType enums, which are auto-converted from their protobuf equivalent.

Helper classes and functions for wrapping mesh query data are defined in _mesh_data.py:

  • a base class MeshDataBase which implements to_pyvista, as well as the construction
    from a mesh query response
  • base classes ElementalData and NodalData, which are the classes to be used to define
    the mesh data classes for each tree object type
  • property helpers elemental_data_property and nodal_data_property, for defining
    the elemental_data and nodal_data properties, respectively.

The mesh data itself is exposed in a separate mesh on the Model. Its class MeshData
also implements a to_pyvista method.

Add a __slots__ class attribute in some places where it was missing, to disallow setting
attributes that are not explicitly defined on tree objects.

@greschd greschd changed the base branch from main to maint/update_dpf_composites_image July 14, 2023 14:24
@greschd greschd force-pushed the feat/extended_mesh_query branch 2 times, most recently from 0472534 to 2da74e4 Compare July 14, 2023 14:48
@greschd greschd marked this pull request as ready for review July 14, 2023 14:49
@greschd greschd force-pushed the feat/extended_mesh_query branch 2 times, most recently from 2cf2968 to 7eba4e8 Compare July 14, 2023 15:49
@greschd
Copy link
Member Author

greschd commented Jul 14, 2023

Note: tests are still missing, follow-up item #234.

At least, some of the mesh query functionality is exercised in the example.

Base automatically changed from maint/update_dpf_composites_image to main July 17, 2023 19:17
@roosre roosre self-requested a review as a code owner July 17, 2023 19:17
) # todo: handle other dtypes
return cls(**kwargs)

def to_pyvista(
Copy link
Contributor

Choose a reason for hiding this comment

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

Having this as a member function closely couples the MeshDataBase object to pyvista. Would it also be an option to make the pyvista conversion a free function?

Copy link
Member Author

Choose a reason for hiding this comment

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

As discussed: The free function approach has the benefit of decoupling the tree objects from PyVista. However -- at least as it currently stands -- it's a bit tricky to make it both easily discoverable / documented, and make mypy happy. This is mostly for two reasons:

  • the return value depends on whether a MeshData, or ElementalData / NodalData is being passed
  • the ElementalData / NodalData case has additional keyword arguments

For now, to avoid a more complex solution, we stick to the method approach. If / when the data containers need to be convertible to multiple different plotting / serialization formats, we can revisit this to avoid bundling all responsibilities into a single class.

@greschd greschd force-pushed the feat/extended_mesh_query branch 2 times, most recently from 365c3df to fa95ce1 Compare August 2, 2023 11:50
Add `elemental_data` and `nodal_data` attributes to tree objects, which fetch the
data from the mesh query API.

The returned objects have a method `to_pyvista`, to convert to a plottable object. Currently,
this requires the `Model.mesh` to be passed in; we may consider how this can be avoided.

Optionally, a `component` (name to be improved) can be passed, to select which data to
add to the PyVista mesh. If a vector component is selected, the data is converted to arrows.

The possible string constants for `component` are exposed in the `ElementalDataType` and
`NodalDataType` enums, which are auto-converted from their protobuf equivalent.

Helper classes and functions for wrapping mesh query data are defined in `_mesh_data.py`:

- a base class `MeshDataBase` which implements `to_pyvista`, as well as the construction
  from a mesh query response
- base classes `ElementalData` and `NodalData`, which are the classes to be used to define
  the mesh data classes for each tree object type
- property helpers `elemental_data_property` and `nodal_data_property`, for defining
  the `elemental_data` and `nodal_data` properties, respectively.

The mesh data itself is exposed in a separate `mesh` on the `Model`. Its class `MeshData`
also implements a `to_pyvista` method.

Add a `__slots__` class attribute in some places where it was missing, to disallow setting
attributes that are not explicitly defined on tree objects.
@greschd greschd force-pushed the feat/extended_mesh_query branch from fa95ce1 to 23c1c22 Compare August 2, 2023 13:03
@greschd greschd merged commit 8ed07ce into main Aug 2, 2023
@greschd greschd deleted the feat/extended_mesh_query branch August 2, 2023 16:08
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.

3 participants