Skip to content

Commit

Permalink
Merge branch 'main' into feat/improving-components-api
Browse files Browse the repository at this point in the history
  • Loading branch information
germa89 authored Nov 6, 2023
2 parents 4814c09 + ff8ea46 commit d45c14e
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 17 deletions.
22 changes: 7 additions & 15 deletions src/ansys/mapdl/core/post.py
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,7 @@ def _plot_cell_scalars(self, scalars, show_elem_numbering=False, **kwargs):
# as ``disp`` returns the result for all nodes/elems, we need all node/elem numbers
# and to index to the output node numbers
if hasattr(self._mapdl.mesh, "enum_all"):
enum = self._mapdl.mesh.enum
enum = self._mapdl.mesh.enum_all
else:
enum = self._all_enum

Expand Down Expand Up @@ -666,30 +666,22 @@ def _plot_cell_scalars(self, scalars, show_elem_numbering=False, **kwargs):
# The theoretical approach will be using an intermediate array of the
# size of the MAPDL total number of elements (we do not care about selected).
#
# >>> values = np.zeros(enum.shape)
values = np.zeros(enum.shape)
#
# Then assign the MAPDL values for the selected element (scalars)
#
# >>> values[self.selected_elements] = scalars
values[self.selected_elements] = scalars
#
# Because values are in order, but with python notation, then we can do:
#
# >>> surf_values = values[uni-1] # -1 to set MAPDL element indexing to python indexing
#
# To obtain the surf values of the selected elements in the MAPDL notation
surf_values = values[
uni - 1
] # -1 to set MAPDL element indexing to python indexing
#
# Then to account for the original Pyvista object:
#
# >>> surf_values = surf_values[ridx]
surf_values = surf_values[ridx]
#
# Effective approach
# ------------------
# Now the more efficient approach (not allocating a full size array):
# values = np.zeros(enum[self.selected_elements].shape)
# values = scalars # But this is the scalars itself! Hence, putting all
# together:
surf_values = scalars[uni - 1][ridx]

#######################################################################

meshes = [
Expand Down
35 changes: 33 additions & 2 deletions tests/test_post.py
Original file line number Diff line number Diff line change
Expand Up @@ -765,13 +765,44 @@ def test_plot_incomplete_element_selection(mapdl, contact_solve):
mapdl.esel("S", "ELEM", "", 1, mapdl.mesh.n_elem // 2)
assert mapdl.post_processing.plot_element_displacement() is None

mapdl.nsel("S", "NODE", "", 1, mapdl.mesh.n_elem // 2, 2)
assert mapdl.post_processing.plot_element_displacement() is None

mapdl.nsel("S", "NODE", "", 5, mapdl.mesh.n_elem // 2, 2)
assert mapdl.post_processing.plot_element_displacement() is None

mapdl.vsel("s", "", "", 1)
mapdl.eslv("s")
assert mapdl.post_processing.plot_element_displacement() is None

mapdl.vsel("s", "", "", 2)
mapdl.eslv("s")
assert mapdl.post_processing.plot_element_displacement() is None


@requires("pyvista")
@pytest.mark.xfail(strict=False, reason="The image regression is failing. See #2435")
def test_plot_incomplete_nodal_selection(mapdl, contact_solve):
def test_plot_incomplete_nodal_selection(mapdl, contact_solve, verify_image_cache):
verify_image_cache.skip = True

mapdl.nsel("S", "NODE", "", 1, mapdl.mesh.n_node // 2)
assert mapdl.post_processing.plot_nodal_displacement() is None

mapdl.nsel("S", "NODE", "", 1, mapdl.mesh.n_node // 2, 2)
assert mapdl.post_processing.plot_nodal_displacement() is None

mapdl.nsel("S", "NODE", "", 5, mapdl.mesh.n_node // 2, 2)
assert mapdl.post_processing.plot_nodal_displacement() is None

mapdl.vsel("s", "", "", 1)
mapdl.eslv("S")
mapdl.nsle("S")
assert mapdl.post_processing.plot_nodal_displacement() is None

mapdl.vsel("s", "", "", 2)
mapdl.eslv("S")
mapdl.nsle("S")
assert mapdl.post_processing.plot_nodal_displacement() is None


@requires("pyvista")
def test_general_plotter_returns(mapdl, static_solve, verify_image_cache):
Expand Down

0 comments on commit d45c14e

Please sign in to comment.