Skip to content

Commit

Permalink
Fixing the image cache issue (#2898)
Browse files Browse the repository at this point in the history
  • Loading branch information
germa89 authored Mar 15, 2024
1 parent 93fff98 commit 2e71c2f
Show file tree
Hide file tree
Showing 28 changed files with 79 additions and 11 deletions.
25 changes: 25 additions & 0 deletions src/ansys/mapdl/core/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# SOFTWARE.

"""Plotting helper for MAPDL using pyvista"""
from collections import OrderedDict
from typing import Any, Optional
from warnings import warn

Expand Down Expand Up @@ -58,6 +59,10 @@
"ELECTRICAL": ["VOLT", "CHRGS", "AMPS"],
}

FIELDS_ORDERED_LABELS = FIELDS["MECHANICAL"].copy()
FIELDS_ORDERED_LABELS.extend(FIELDS["THERMAL"])
FIELDS_ORDERED_LABELS.extend(FIELDS["ELECTRICAL"])


# All boundary conditions:
BCS = BC_D.copy()
Expand Down Expand Up @@ -1005,6 +1010,7 @@ def bc_nodes_plotter(
# line_width=3,
name=name_,
label=name_,
opacity=0.50,
)

if plot_bc_labels:
Expand Down Expand Up @@ -1032,6 +1038,25 @@ def bc_nodes_plotter(
)

if plot_bc_legend:
# Reorder labels to keep a consistent order
sorted_dict = OrderedDict()
labels_ = pl.renderer._labels.copy()

# sorting the keys
for symbol in FIELDS_ORDERED_LABELS:
for key, value in labels_.items():
if symbol == value[1]:
sorted_dict[key] = value

# moving the not added labels (just in case)
for key, value in labels_.items():
if value[1] not in FIELDS_ORDERED_LABELS:
sorted_dict[key] = value

assert sorted_dict == labels_

# overwriting labels
pl.renderer._labels = sorted_dict
pl.add_legend(bcolor=None)

return pl
Expand Down
Binary file modified tests/.image_cache/bc_plot_options[False-False-False].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options[False-False-True].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options[False-True-False].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options[False-True-True].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options[True-False-False].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options[True-False-True].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options[True-True-False].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified tests/.image_cache/bc_plot_options[True-True-True].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/.image_cache/single_glyph[0-FX].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/.image_cache/single_glyph[0-FY].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/.image_cache/single_glyph[0-FZ].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/.image_cache/single_glyph[0-UX].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/.image_cache/single_glyph[0-UY].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/.image_cache/single_glyph[0-UZ].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/.image_cache/single_glyph[50-FX].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/.image_cache/single_glyph[50-FY].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/.image_cache/single_glyph[50-FZ].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/.image_cache/single_glyph[50-UX].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/.image_cache/single_glyph[50-UY].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/.image_cache/single_glyph[50-UZ].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/.image_cache/single_glyph[500-FX].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/.image_cache/single_glyph[500-FY].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/.image_cache/single_glyph[500-FZ].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/.image_cache/single_glyph[500-UX].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/.image_cache/single_glyph[500-UY].png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/.image_cache/single_glyph[500-UZ].png
65 changes: 54 additions & 11 deletions tests/test_plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -38,28 +38,51 @@


@pytest.fixture
def bc_example(mapdl, make_block):
def bc_example(mapdl):
mapdl.prep7()
mapdl.et("", 189)

mapdl.n(1, 0, 0, 0)
mapdl.n(2, 1, 0, 0)
mapdl.n(3, 2, 0, 0)
mapdl.n(4, 0, 0, 1)
mapdl.n(5, 1, 0, 1)
mapdl.n(6, 2, 0, 1)

mapdl.nsel("s", "node", "", 1)
mapdl.f("all", "FX", 0)
mapdl.nsel("s", "node", "", 2)
mapdl.f("all", "FY", 0)
mapdl.nsel("s", "node", "", 3)
mapdl.f("all", "FZ", 0)

mapdl.nsel("s", "node", "", 2)
mapdl.f("all", "FX", 100)
mapdl.f("all", "FY", 200)
mapdl.f("all", "FZ", 100)

mapdl.nsel("s", "node", "", 3)
mapdl.nsel("s", "node", "", 4)
mapdl.d("all", "UX", 0)
mapdl.nsel("s", "node", "", 5)
mapdl.d("all", "UY", 0)
mapdl.nsel("s", "node", "", 6)
mapdl.d("all", "UZ", 0)

mapdl.nsel("s", "node", "", 4)
mapdl.d("all", "UX", 1)
mapdl.d("all", "UY", 2)
mapdl.d("all", "UZ", 3)
mapdl.n(7, 0, 1, 0)
mapdl.n(8, 1, 1, 0)
mapdl.n(9, 2, 1, 0)
mapdl.n(10, 0, 2, 0)
mapdl.n(11, 1, 2, 0)
mapdl.n(12, 2, 2, 0)

mapdl.nsel("s", "node", "", 7)
mapdl.f("all", "FX", 10)
mapdl.nsel("s", "node", "", 8)
mapdl.f("all", "FY", 20)
mapdl.nsel("s", "node", "", 9)
mapdl.f("all", "FZ", 30)

mapdl.nsel("s", "node", "", 10)
mapdl.d("all", "UX", 20)
mapdl.nsel("s", "node", "", 11)
mapdl.d("all", "UY", 20)
mapdl.nsel("s", "node", "", 12)
mapdl.d("all", "UZ", 20)

mapdl.nsel("all")

Expand Down Expand Up @@ -212,6 +235,25 @@ def test_eplot_savefig(mapdl, make_block, tmpdir):
assert os.path.isfile(filename)


@pytest.mark.parametrize("field", ["UX", "UY", "UZ", "FX", "FY", "FZ"])
@pytest.mark.parametrize("magnitude", [0, 50, 500])
def test_single_glyph(mapdl, field, magnitude, verify_image_cache):
mapdl.clear()
mapdl.prep7()
mapdl.et("", 189)
mapdl.n(1, 0, 0, 0)

if "U" in field:
mapdl.d(1, field, magnitude)
else:
mapdl.f(1, field, magnitude)

mapdl.allsel()
p = mapdl.nplot(
plot_bc=True, point_size=max(magnitude, 10), render_points_as_spheres=True
)


@pytest.mark.parametrize("return_plotter", [True, False])
@pytest.mark.parametrize("plot_bc_legend", [True, False])
@pytest.mark.parametrize("plot_bc_labels", [True, False])
Expand All @@ -222,6 +264,7 @@ def test_bc_plot_options(
return_plotter,
plot_bc_legend,
plot_bc_labels,
bc_labels_font_size=50,
):
if plot_bc_legend or plot_bc_labels:
# The legend and labels generate highly variance than other tests
Expand Down

0 comments on commit 2e71c2f

Please sign in to comment.