-
Notifications
You must be signed in to change notification settings - Fork 1
Expose mesh data, add plotting capability. #231
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
0472534 to
2da74e4
Compare
2cf2968 to
7eba4e8
Compare
|
Note: tests are still missing, follow-up item #234. At least, some of the mesh query functionality is exercised in the example. |
| ) # todo: handle other dtypes | ||
| return cls(**kwargs) | ||
|
|
||
| def to_pyvista( |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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, orElementalData/NodalDatais being passed - the
ElementalData/NodalDatacase 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.
365c3df to
fa95ce1
Compare
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.
fa95ce1 to
23c1c22
Compare
Add
elemental_dataandnodal_dataattributes to tree objects, which fetch thedata from the mesh query API.
The returned objects have a method
to_pyvista, to convert to a plottable object. Currently,this requires the
Model.meshto 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 toadd to the PyVista mesh. If a vector component is selected, the data is converted to arrows.
The possible string constants for
componentare exposed in theElementalDataTypeandNodalDataTypeenums, which are auto-converted from their protobuf equivalent.Helper classes and functions for wrapping mesh query data are defined in
_mesh_data.py:MeshDataBasewhich implementsto_pyvista, as well as the constructionfrom a mesh query response
ElementalDataandNodalData, which are the classes to be used to definethe mesh data classes for each tree object type
elemental_data_propertyandnodal_data_property, for definingthe
elemental_dataandnodal_dataproperties, respectively.The mesh data itself is exposed in a separate
meshon theModel. Its classMeshDataalso implements a
to_pyvistamethod.Add a
__slots__class attribute in some places where it was missing, to disallow settingattributes that are not explicitly defined on tree objects.