diff --git a/.devcontainer/codespaces-dev/requirements.txt b/.devcontainer/codespaces-dev/requirements.txt index fa86460fcc..6ac27d7b71 100644 --- a/.devcontainer/codespaces-dev/requirements.txt +++ b/.devcontainer/codespaces-dev/requirements.txt @@ -1,4 +1,4 @@ -ansys-dpf-core==0.10.1 +ansys-dpf-core==0.11.0 autopep8==2.0.4 matplotlib==3.8.3 scipy==1.12.0 @@ -6,7 +6,7 @@ pandas==2.2.1 pyiges[full]==0.3.1 pytest==8.0.2 pytest-cov==4.1.0 -pyvista==0.43.3 +pyvista==0.43.4 pyansys-tools-report==0.7.0 vtk==9.3.0 pytest-rerunfailures==13.0 diff --git a/.devcontainer/codespaces-docs/requirements.txt b/.devcontainer/codespaces-docs/requirements.txt index 23b2cbd5e9..2591ebf8d8 100644 --- a/.devcontainer/codespaces-docs/requirements.txt +++ b/.devcontainer/codespaces-docs/requirements.txt @@ -1,5 +1,5 @@ sphinx==7.2.6 -ansys-dpf-core==0.10.1 +ansys-dpf-core==0.11.0 ansys-mapdl-reader==0.53.0 ansys-sphinx-theme==0.14.1 grpcio==1.62.0 @@ -10,14 +10,14 @@ jupyterlab>=3.2.8 matplotlib==3.8.3 numpydoc==1.6.0 pandas==2.2.1 -plotly==5.19.0 +plotly==5.20.0 pyiges[full]==0.3.1 pypandoc==1.13 pytest-sphinx==0.6.0 pythreejs==2.4.2 pyvista[trame]==0.43.3 sphinx-autobuild==2024.2.4 -sphinx-autodoc-typehints==1.25.2 +sphinx-autodoc-typehints==2.0.0 sphinx-copybutton==0.5.2 sphinx-gallery==0.15.0 sphinxcontrib-websupport==1.2.7 diff --git a/.devcontainer/devcontainer-local/requirements.txt b/.devcontainer/devcontainer-local/requirements.txt index fa86460fcc..6ac27d7b71 100644 --- a/.devcontainer/devcontainer-local/requirements.txt +++ b/.devcontainer/devcontainer-local/requirements.txt @@ -1,4 +1,4 @@ -ansys-dpf-core==0.10.1 +ansys-dpf-core==0.11.0 autopep8==2.0.4 matplotlib==3.8.3 scipy==1.12.0 @@ -6,7 +6,7 @@ pandas==2.2.1 pyiges[full]==0.3.1 pytest==8.0.2 pytest-cov==4.1.0 -pyvista==0.43.3 +pyvista==0.43.4 pyansys-tools-report==0.7.0 vtk==9.3.0 pytest-rerunfailures==13.0 diff --git a/pyproject.toml b/pyproject.toml index 776b1b0b4e..26ba515fe3 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -82,7 +82,7 @@ doc = [ "ansys-dpf-core==0.10.1", "ansys-mapdl-reader==0.53.0", "ansys-sphinx-theme==0.14.1", - "grpcio==1.62.0", + "grpcio==1.62.1", "imageio-ffmpeg==0.4.9", "imageio==2.34.0", "jupyter_sphinx==0.5.3", @@ -90,7 +90,7 @@ doc = [ "matplotlib==3.8.3", "numpydoc==1.6.0", "pandas==2.2.1", - "plotly==5.19.0", + "plotly==5.20.0", "pyiges[full]==0.3.1", "pypandoc==1.13", "pytest-sphinx==0.6.0", diff --git a/src/ansys/mapdl/core/mapdl_grpc.py b/src/ansys/mapdl/core/mapdl_grpc.py index 440aabfb41..3a7e3bf0f6 100644 --- a/src/ansys/mapdl/core/mapdl_grpc.py +++ b/src/ansys/mapdl/core/mapdl_grpc.py @@ -1084,7 +1084,7 @@ def _kill_server(self): pass if ( - self._version >= 24.2 + self._version and self._version >= 24.2 ): # We can't use the non-cached version because of recursion error. # self.run("/EXIT,NOSAVE,,,,,SERVER") self._ctrl("EXIT") diff --git a/src/ansys/mapdl/core/plotting.py b/src/ansys/mapdl/core/plotting.py index de50516827..516259e291 100644 --- a/src/ansys/mapdl/core/plotting.py +++ b/src/ansys/mapdl/core/plotting.py @@ -21,6 +21,7 @@ # SOFTWARE. """Plotting helper for MAPDL using pyvista""" +from collections import OrderedDict from typing import Any, Optional from warnings import warn @@ -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() @@ -1005,6 +1010,7 @@ def bc_nodes_plotter( # line_width=3, name=name_, label=name_, + opacity=0.50, ) if plot_bc_labels: @@ -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 diff --git a/tests/.image_cache/bc_plot_options[False-False-False].png b/tests/.image_cache/bc_plot_options[False-False-False].png index 5b66f01aa2..1728868519 100644 Binary files a/tests/.image_cache/bc_plot_options[False-False-False].png and b/tests/.image_cache/bc_plot_options[False-False-False].png differ diff --git a/tests/.image_cache/bc_plot_options[False-False-True].png b/tests/.image_cache/bc_plot_options[False-False-True].png index 5b66f01aa2..1728868519 100644 Binary files a/tests/.image_cache/bc_plot_options[False-False-True].png and b/tests/.image_cache/bc_plot_options[False-False-True].png differ diff --git a/tests/.image_cache/bc_plot_options[False-True-False].png b/tests/.image_cache/bc_plot_options[False-True-False].png index 1333a065b6..28100ba910 100644 Binary files a/tests/.image_cache/bc_plot_options[False-True-False].png and b/tests/.image_cache/bc_plot_options[False-True-False].png differ diff --git a/tests/.image_cache/bc_plot_options[False-True-True].png b/tests/.image_cache/bc_plot_options[False-True-True].png index 1333a065b6..28100ba910 100644 Binary files a/tests/.image_cache/bc_plot_options[False-True-True].png and b/tests/.image_cache/bc_plot_options[False-True-True].png differ diff --git a/tests/.image_cache/bc_plot_options[True-False-False].png b/tests/.image_cache/bc_plot_options[True-False-False].png index 6f74c1bf81..e406da5c81 100644 Binary files a/tests/.image_cache/bc_plot_options[True-False-False].png and b/tests/.image_cache/bc_plot_options[True-False-False].png differ diff --git a/tests/.image_cache/bc_plot_options[True-False-True].png b/tests/.image_cache/bc_plot_options[True-False-True].png index 6f74c1bf81..e406da5c81 100644 Binary files a/tests/.image_cache/bc_plot_options[True-False-True].png and b/tests/.image_cache/bc_plot_options[True-False-True].png differ diff --git a/tests/.image_cache/single_glyph[0-FX].png b/tests/.image_cache/single_glyph[0-FX].png new file mode 100644 index 0000000000..294f24ce44 Binary files /dev/null and b/tests/.image_cache/single_glyph[0-FX].png differ diff --git a/tests/.image_cache/single_glyph[0-FY].png b/tests/.image_cache/single_glyph[0-FY].png new file mode 100644 index 0000000000..46482fc575 Binary files /dev/null and b/tests/.image_cache/single_glyph[0-FY].png differ diff --git a/tests/.image_cache/single_glyph[0-FZ].png b/tests/.image_cache/single_glyph[0-FZ].png new file mode 100644 index 0000000000..dad3fbf13a Binary files /dev/null and b/tests/.image_cache/single_glyph[0-FZ].png differ diff --git a/tests/.image_cache/single_glyph[0-UX].png b/tests/.image_cache/single_glyph[0-UX].png new file mode 100644 index 0000000000..2741e91fac Binary files /dev/null and b/tests/.image_cache/single_glyph[0-UX].png differ diff --git a/tests/.image_cache/single_glyph[0-UY].png b/tests/.image_cache/single_glyph[0-UY].png new file mode 100644 index 0000000000..bf80c3813d Binary files /dev/null and b/tests/.image_cache/single_glyph[0-UY].png differ diff --git a/tests/.image_cache/single_glyph[0-UZ].png b/tests/.image_cache/single_glyph[0-UZ].png new file mode 100644 index 0000000000..e43753b722 Binary files /dev/null and b/tests/.image_cache/single_glyph[0-UZ].png differ diff --git a/tests/.image_cache/single_glyph[50-FX].png b/tests/.image_cache/single_glyph[50-FX].png new file mode 100644 index 0000000000..c85a37549e Binary files /dev/null and b/tests/.image_cache/single_glyph[50-FX].png differ diff --git a/tests/.image_cache/single_glyph[50-FY].png b/tests/.image_cache/single_glyph[50-FY].png new file mode 100644 index 0000000000..c3a14d0d96 Binary files /dev/null and b/tests/.image_cache/single_glyph[50-FY].png differ diff --git a/tests/.image_cache/single_glyph[50-FZ].png b/tests/.image_cache/single_glyph[50-FZ].png new file mode 100644 index 0000000000..f465284379 Binary files /dev/null and b/tests/.image_cache/single_glyph[50-FZ].png differ diff --git a/tests/.image_cache/single_glyph[50-UX].png b/tests/.image_cache/single_glyph[50-UX].png new file mode 100644 index 0000000000..33e7cc53f7 Binary files /dev/null and b/tests/.image_cache/single_glyph[50-UX].png differ diff --git a/tests/.image_cache/single_glyph[50-UY].png b/tests/.image_cache/single_glyph[50-UY].png new file mode 100644 index 0000000000..d20dfe554d Binary files /dev/null and b/tests/.image_cache/single_glyph[50-UY].png differ diff --git a/tests/.image_cache/single_glyph[50-UZ].png b/tests/.image_cache/single_glyph[50-UZ].png new file mode 100644 index 0000000000..6c7c3e7b2a Binary files /dev/null and b/tests/.image_cache/single_glyph[50-UZ].png differ diff --git a/tests/.image_cache/single_glyph[500-FX].png b/tests/.image_cache/single_glyph[500-FX].png new file mode 100644 index 0000000000..5c4cfe8144 Binary files /dev/null and b/tests/.image_cache/single_glyph[500-FX].png differ diff --git a/tests/.image_cache/single_glyph[500-FY].png b/tests/.image_cache/single_glyph[500-FY].png new file mode 100644 index 0000000000..5f227299b9 Binary files /dev/null and b/tests/.image_cache/single_glyph[500-FY].png differ diff --git a/tests/.image_cache/single_glyph[500-FZ].png b/tests/.image_cache/single_glyph[500-FZ].png new file mode 100644 index 0000000000..e3213d4c3c Binary files /dev/null and b/tests/.image_cache/single_glyph[500-FZ].png differ diff --git a/tests/.image_cache/single_glyph[500-UX].png b/tests/.image_cache/single_glyph[500-UX].png new file mode 100644 index 0000000000..0c6d11d450 Binary files /dev/null and b/tests/.image_cache/single_glyph[500-UX].png differ diff --git a/tests/.image_cache/single_glyph[500-UY].png b/tests/.image_cache/single_glyph[500-UY].png new file mode 100644 index 0000000000..a009317e01 Binary files /dev/null and b/tests/.image_cache/single_glyph[500-UY].png differ diff --git a/tests/.image_cache/single_glyph[500-UZ].png b/tests/.image_cache/single_glyph[500-UZ].png new file mode 100644 index 0000000000..3fb7634a80 Binary files /dev/null and b/tests/.image_cache/single_glyph[500-UZ].png differ diff --git a/tests/test_plotting.py b/tests/test_plotting.py index 2a105e7d9d..bfaa22e7b0 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -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") @@ -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]) @@ -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