Skip to content

Conversation

@PProfizi
Copy link
Contributor

@PProfizi PProfizi commented Sep 27, 2022

to allow for plotting of modified meshes with mesh setters.

Use case:

import numpy as np
from ansys.dpf import core as dpf
from ansys.dpf.core import examples

model = dpf.Model(examples.simple_bar)
ncoord_f = model.metadata.meshed_region.nodes.coordinates_field
model.metadata.meshed_region.plot()

my_field_rotation_matrix = dpf.fields_factory.create_scalar_field(1)
my_field_rotation_matrix.data = np.array([[1],[0],[0],[0],[0],[1],[0],[-1],[0]])

op = dpf.operators.geo.rotate()
op.inputs.field.connect(ncoord_f)
op.inputs.field_rotation_matrix.connect(my_field_rotation_matrix)

op = dpf.operators.geo.rotate(field=ncoord_f, field_rotation_matrix=my_field_rotation_matrix)

result_field = op.outputs.field()

mesh = model.metadata.meshed_region
mesh.nodes.coordinates_field = result_field
mesh.plot()
  • Update the vtk grid associated to the mesh when the coordinates are modified via set_coordinates_field or set_property_field(coordinates) (and by extension via nodes.coordinates). -> this uses the pyvista.UnstructuredGrid.points setter.

  • Update the vtk grid associated to the mesh when the connectivity is modified via set_property_field( nodal_properties.nodal_connectivity or element_properties.connectivity). -> there is no setter for pyvista.UnstructuredGrid.cells or pyvista.UnstructuredGrid.cell_connectivity, so the only solution seems to invalidate the grid. This requires more work, yet to solve the current reported bugs this is not necessary as they only concern updating the coordinates.

  • Also reset the grid's data using grid.clear_data() when using Plotter.plot_contour or DpfPlotter.add_mesh.

@PProfizi PProfizi self-assigned this Sep 27, 2022
@codecov
Copy link

codecov bot commented Sep 27, 2022

Codecov Report

Merging #513 (fed2f19) into master (e17deae) will increase coverage by 0.16%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master     #513      +/-   ##
==========================================
+ Coverage   86.79%   86.96%   +0.16%     
==========================================
  Files          67       67              
  Lines        7196     7212      +16     
==========================================
+ Hits         6246     6272      +26     
+ Misses        950      940      -10     

@PProfizi PProfizi changed the title Remove the MeshedRegion.grid cache Reset MeshedRegion.grid when coordinates are updated. Sep 27, 2022
@PProfizi PProfizi marked this pull request as ready for review September 28, 2022 15:45
@PProfizi PProfizi added the bug Something isn't working label Sep 28, 2022
@PProfizi PProfizi requested a review from cbellot000 September 28, 2022 16:02
@PProfizi PProfizi changed the title Reset MeshedRegion.grid when coordinates are updated. Reset MeshedRegion.grid when necessary. Sep 30, 2022
@PProfizi PProfizi changed the title Reset MeshedRegion.grid when necessary. Reset MeshedRegion.grid or its clear its data when necessary. Sep 30, 2022
coordinates_field : PropertyField or Field
"""
self._api.meshed_region_set_coordinates_field(self, coordinates_field)
self._full_grid = None
Copy link
Contributor

Choose a reason for hiding this comment

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

can't we just invalidate the coords of the grid?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rlagha FYI I modified the proposed code as requested.

@rlagha rlagha requested a review from pthieffry October 3, 2022 08:42
@PProfizi PProfizi requested a review from rlagha October 3, 2022 14:56
@PProfizi PProfizi changed the title Reset MeshedRegion.grid or its clear its data when necessary. Reset MeshedRegion.grid or clear its data when necessary. Oct 4, 2022
coordinates_field : PropertyField or Field
"""
self._api.meshed_region_set_coordinates_field(self, coordinates_field)
if self._full_grid is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

@PProfizi In my opinion, we need to think larger. Here the "real" issue is not "when set coordinates is called the grid needs to be updated" but "when the mesh is updated (equivalent to setters are called) the grid is out dated".
With your we will have the same bug if set connectivity, or set element types is called

>>> pl.add_mesh(mesh)
"""
if meshed_region.grid is not None:
Copy link
Contributor

Choose a reason for hiding this comment

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

Have you checked what happens with meshes containers?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It works.

@PProfizi PProfizi linked an issue Oct 11, 2022 that may be closed by this pull request
3 tasks
@PProfizi PProfizi requested a review from cbellot000 October 12, 2022 13:38
@PProfizi PProfizi changed the title Reset MeshedRegion.grid or clear its data when necessary. Update MeshedRegion.grid coordinates upon use of MeshedRegion.set_coordinates() Oct 14, 2022
@PProfizi PProfizi changed the title Update MeshedRegion.grid coordinates upon use of MeshedRegion.set_coordinates() Update MeshedRegion.grid coordinates when necessary and clear data before plotting. Oct 14, 2022
@PProfizi PProfizi merged commit f5b7a85 into master Oct 14, 2022
@PProfizi PProfizi deleted the fix/remove_grid_cache branch October 14, 2022 10:45
PProfizi added a commit that referenced this pull request Oct 20, 2022
PProfizi added a commit that referenced this pull request Oct 27, 2022
* Move Documentation to a reusable workflow, can be manually triggered or called by the CI.

* Move tests to tests.yml, can be triggered manually, can be called by the CI.

* Add gate.yml workflow for gatebin testing.

* Install ansys-grpc-dpf==0.4.0 when ANSYS_VERSION=221

* Add wheel and wheelhouse arguments to the tests.yml

* Set wheel and wheelhouse arguments as optional.

* Create a reusable workflow for running examples, which can be triggered manually or called from the CI.

* Set optional arguments as optional

* Update docs workflow to the latest master changes

* Call docs from CI

* Update tests.yml to reflect changes in master

* Add "extra" env

* Update examples.yml to latest in master

* call examples.yml in CI

* Update retro jobs in CI

* Add debug job in CI

* Add gate job in CI

* Update gate.yml

* Update name of docs workflow in ci.yml

* Update needs of draft_release

* Update tests.yml add DOCSTRING argument

* Use lower-case names

* Fix docs.yml

* Rename testing step in tests.yml

* Update tests.yml to current master state.

* Update gate.yml to current master state.

* Update docs.yml to current master state.

* Skip running python-operators examples when on linux.

* Apply changes from #537 to doc job

* Apply changes from #513 to doc job

* Do not automatically run CI on push to release* branch. This can be managed via a PR if necessary. In theory one can push a bump commit and a tag, which requires only the CI on the tag push.

* Add docs_on_release step, add 3.8 to release steps.

* Separate the workflow triggered on v* tag push.

* Schedule CI release every sunday at 1pm UTC.
Condition draft_release step to push of tag.

* Fix pydpf-post_testing workflow branch name issue

* Allow for workflow call of PyDPF-Post testing

* Run PyDPF-Post compatibility testing on both windows and linux

* Run PyDPF-Post compatibility testing on latest tagged revision by default

* PyDPF-Post compatibility testing accepts ANSYS_VERSION as input

* Run PyDPF-Post compatibility testing on non-draft CI

* Run PyDPF-Post compatibility testing on release and weekly CI for 231, 222 and 221

* PyDPF-Post branch name is not required

* Fix PyDPF-Post cloning step

* Make pydpf-post testing necessary for draft_release in ci_release.yml

* Remove concurrency temporarily

* Add back concurrency

* Comment other jobs temporarily

* Add pydpf-post-TOKEN as required input when run from a workflow

* Split repo name construction

* Actually no need for the dpf-post secret

* Fix pydpf-post cloning step.

* Fix pydpf-post cloning step.

* Fix pydpf-post install step.

* Fix pydpf-post install step.

* Fix pydpf-post install step.

* Fix pydpf-post install step.

* Use new "working-directory" input for prepare_tests and test_docstrings actions.

* Fix test API

* Use prepare_v2.2 pydpf-actions

* Uncomment all jobs

* Fix pydpf-post.yml

* Fix pydpf-post.yml - test docstrings in src/

* Quick fix: only use the three first parts of version strings.

* Update deprecated set-output command.

* Fix test-results-post log path

* Use packaging.version.parse instead of our custom version_tuple function.

* Fix setup step

* Fix setup step

* Remove test_version_tuple

* Bump all pydpf-actions to v2.2

* Merge with master, apply changes for test_docker

* Test test_docker on a regular PR
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants