From 6da9edba755e78a8a9594d6e875287e5b9f3baa5 Mon Sep 17 00:00:00 2001 From: German Date: Mon, 11 Dec 2023 10:58:21 +0100 Subject: [PATCH 1/7] Adding finish command --- examples/00-mapdl-examples/2d_plate_with_a_hole.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/examples/00-mapdl-examples/2d_plate_with_a_hole.py b/examples/00-mapdl-examples/2d_plate_with_a_hole.py index 1b0370b6e3..300b760f0a 100644 --- a/examples/00-mapdl-examples/2d_plate_with_a_hole.py +++ b/examples/00-mapdl-examples/2d_plate_with_a_hole.py @@ -152,6 +152,7 @@ mapdl.run("/SOLU") mapdl.antype("STATIC") output = mapdl.solve() +mapdl.finish() print(output) ############################################################################### @@ -316,6 +317,7 @@ def compute_stress_con(ratio): mapdl.run("/SOLU") mapdl.antype("STATIC") mapdl.solve() + mapdl.finish() # Post-Processing # ~~~~~~~~~~~~~~~ From 7ce4447323cdd6c9cb7b28ae7781cc28b5b6527d Mon Sep 17 00:00:00 2001 From: German Date: Mon, 11 Dec 2023 10:58:53 +0100 Subject: [PATCH 2/7] Using solution() call. --- examples/00-mapdl-examples/2d_plate_with_a_hole.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/examples/00-mapdl-examples/2d_plate_with_a_hole.py b/examples/00-mapdl-examples/2d_plate_with_a_hole.py index 300b760f0a..efb3c879f6 100644 --- a/examples/00-mapdl-examples/2d_plate_with_a_hole.py +++ b/examples/00-mapdl-examples/2d_plate_with_a_hole.py @@ -149,7 +149,7 @@ # Solve the Static Problem # ~~~~~~~~~~~~~~~~~~~~~~~~ # Solve the static analysis -mapdl.run("/SOLU") +mapdl.solution() mapdl.antype("STATIC") output = mapdl.solve() mapdl.finish() @@ -314,7 +314,7 @@ def compute_stress_con(ratio): # Solve the Static Problem # ~~~~~~~~~~~~~~~~~~~~~~~~ - mapdl.run("/SOLU") + mapdl.solution() mapdl.antype("STATIC") mapdl.solve() mapdl.finish() From a225ba326c778f285fff88cecbeca7af091b3540 Mon Sep 17 00:00:00 2001 From: German Date: Mon, 11 Dec 2023 11:15:50 +0100 Subject: [PATCH 3/7] making sure it is not excluded. --- doc/source/examples/index.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/doc/source/examples/index.rst b/doc/source/examples/index.rst index de835a6ad2..aa44e74279 100644 --- a/doc/source/examples/index.rst +++ b/doc/source/examples/index.rst @@ -1,6 +1,7 @@ -.. _ref_examples: +.. _ref_examples: + .. toctree:: :hidden: :maxdepth: 3 From 6a4c0bc8d96a319c576e2a60b58dbc979a1c46ed Mon Sep 17 00:00:00 2001 From: German Date: Mon, 11 Dec 2023 11:46:24 +0100 Subject: [PATCH 4/7] reorder the parts --- doc/source/examples/index.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/doc/source/examples/index.rst b/doc/source/examples/index.rst index aa44e74279..bfa95d33ee 100644 --- a/doc/source/examples/index.rst +++ b/doc/source/examples/index.rst @@ -1,7 +1,5 @@ -.. _ref_examples: - .. toctree:: :hidden: :maxdepth: 3 @@ -12,6 +10,8 @@ extended_examples/index.rst +.. _ref_examples: + ======== Examples ======== From fc725673efb1af2a5c6f34c084de4b13240f8c5a Mon Sep 17 00:00:00 2001 From: German Date: Thu, 14 Dec 2023 11:59:06 +0100 Subject: [PATCH 5/7] Revert "Fixing some plot bugs (#2537)" This reverts commit 00d49f6acbff9958258cc20d7e9eb2a95dd1dd54. --- .github/workflows/ci.yml | 2 +- examples/01-geometry/01-lines.py | 2 +- src/ansys/mapdl/core/mapdl.py | 19 ++------------- src/ansys/mapdl/core/plotting.py | 14 ----------- src/ansys/mapdl/core/theme.py | 2 +- tests/test_plotting.py | 42 -------------------------------- tests/test_post.py | 6 +---- 7 files changed, 6 insertions(+), 81 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index b6a0773ae5..e8e9c18773 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,7 @@ env: DOCKER_PACKAGE: ghcr.io/ansys/mapdl DOCKER_IMAGE_VERSION_DOCS_BUILD: v23.1.0 ON_CI: True - PYTEST_ARGUMENTS: '-vv --durations=10 --maxfail=1 --reruns 1 --reruns-delay 5 --cov=ansys.mapdl.core --cov-report=html' + PYTEST_ARGUMENTS: '-vv --durations=10 --maxfail=10 --reruns 7 --reruns-delay 5 --cov=ansys.mapdl.core --cov-report=html' # Following env vars when changed will "reset" the mentioned cache, # by changing the cache file name. It is rendered as ...-v%RESET_XXX%-... diff --git a/examples/01-geometry/01-lines.py b/examples/01-geometry/01-lines.py index 7ec25e6ea4..0ba015bcab 100644 --- a/examples/01-geometry/01-lines.py +++ b/examples/01-geometry/01-lines.py @@ -44,7 +44,7 @@ k1 = mapdl.k("", 1, 1, 0) k2 = mapdl.k("", 0, 1, 0) lnum = mapdl.larc(k0, k1, k2, 2) -mapdl.lplot(background="w", color="y", line_width=5, cpos="xy") +mapdl.lplot(background="w", color="k", line_width=5, cpos="xy") ############################################################################### diff --git a/src/ansys/mapdl/core/mapdl.py b/src/ansys/mapdl/core/mapdl.py index 5123ebe340..00fba5eec1 100644 --- a/src/ansys/mapdl/core/mapdl.py +++ b/src/ansys/mapdl/core/mapdl.py @@ -1755,14 +1755,8 @@ def vplot( quality of the mesh to display. Varies between 1 (worst) to 10 (best). Applicable when ``vtk=True``. - show_volume_numbering : bool, optional - Display volume numbers when ``vtk=True``. - - show_area_numbering : bool, optional - Display area numbers when ``vtk=True``. - - show_line_numbering : bool, optional - Display line numbers when ``vtk=True``. + show_numbering : bool, optional + Display line and keypoint numbers when ``vtk=True``. **kwargs See :meth:`ansys.mapdl.core.plotting.general_plotter` for @@ -1818,19 +1812,10 @@ def vplot( ) meshes_ = get_meshes_from_plotter(pl) - center_volumes = pl.center for each_mesh in meshes_: each_mesh.cell_data["entity_num"] = int(each_volu) - if show_volume_numbering: - labels.append( - { - "points": np.array(center_volumes), - "labels": [int(each_volu)], - } - ) - meshes.extend(meshes_) meshes = [{"mesh": meshes}] diff --git a/src/ansys/mapdl/core/plotting.py b/src/ansys/mapdl/core/plotting.py index fd50e6117d..490ecb9bbb 100644 --- a/src/ansys/mapdl/core/plotting.py +++ b/src/ansys/mapdl/core/plotting.py @@ -406,20 +406,6 @@ def _general_plotter( if background: plotter.set_background(background) - # Making sure that labels are visible in dark backgrounds - if not text_color and background: - bg = plotter.background_color.float_rgb - # from: https://graphicdesign.stackexchange.com/a/77747/113009 - gamma = 2.2 - threshold = ( - 0.2126 * bg[0] ** gamma + 0.7152 * bg[1] ** gamma + 0.0722 * bg[2] ** gamma - > 0.5 * gamma - ) - if threshold: - text_color = "black" - else: - text_color = "white" - for point in points: plotter.add_points( point["points"], diff --git a/src/ansys/mapdl/core/theme.py b/src/ansys/mapdl/core/theme.py index d103a5ac11..e9c019b1ff 100644 --- a/src/ansys/mapdl/core/theme.py +++ b/src/ansys/mapdl/core/theme.py @@ -55,7 +55,7 @@ class myEmptyClass: ) if _HAS_MATPLOTLIB: - PyMAPDL_cmap: ListedColormap = ListedColormap(MAPDL_colorbar, name="PyMAPDL") + PyMAPDL_cmap: ListedColormap = ListedColormap(MAPDL_colorbar, name="PyMAPDL", N=255) def get_ansys_colors(N=9): diff --git a/tests/test_plotting.py b/tests/test_plotting.py index c9e5acab69..d0710e4679 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -885,45 +885,3 @@ def test_cuadratic_beam(mapdl, cuadratic_beam_problem): ) is None ) - - -@pytest.mark.parametrize("background", ["white", "black", "green", "red"]) -def test_labels_colors_background(mapdl, make_block, background): - # Test if the labels change color according background - mapdl.nplot(background=background, nnum=True) - - -def test_vplot_show_volume_numbering(mapdl, make_block): - mapdl.vplot(show_volume_numbering=True) - - -def test_vplot_area_numbering(mapdl, make_block): - mapdl.vplot(show_area_numbering=True) - - -def test_vplot_line_numbering(mapdl, make_block): - mapdl.vplot(show_line_numbering=True) - - -def test_vplot_multi_numbering(mapdl, make_block): - mapdl.vplot( - show_area_numbering=True, show_line_numbering=True, show_volume_numbering=True - ) - - -def test_vplot_color(mapdl, make_block): - mapdl.vplot(color="gray") - - -def test_vplot_cpos(mapdl, make_block): - mapdl.vplot(cpos="xy") - - -def test_vplot_multiargs(mapdl, make_block): - mapdl.vplot( - color="gray", - cpos="xy", - show_volume_numbering=True, - show_line_numbering=False, - show_area_numbering=True, - ) diff --git a/tests/test_post.py b/tests/test_post.py index 2789abbaf1..387f662fa6 100644 --- a/tests/test_post.py +++ b/tests/test_post.py @@ -10,7 +10,6 @@ if has_dependency("pyvista"): from pyvista import Plotter from pyvista.plotting.renderer import CameraPosition - from ansys.mapdl.core.theme import PyMAPDL_cmap from ansys.mapdl.core import examples from ansys.mapdl.core.post import ( @@ -159,10 +158,7 @@ def test_disp_norm_all(mapdl, static_solve): @requires("pyvista") def test_disp_plot(mapdl, static_solve, comp): assert ( - mapdl.post_processing.plot_nodal_displacement( - comp, smooth_shading=True, cmap=PyMAPDL_cmap - ) - is None + mapdl.post_processing.plot_nodal_displacement(comp, smooth_shading=True) is None ) From c85f92f7700dad4df6cb21515c4fb8203c356df8 Mon Sep 17 00:00:00 2001 From: German Date: Fri, 15 Dec 2023 11:04:32 +0100 Subject: [PATCH 6/7] Reapply "Fixing some plot bugs (#2537)" This reverts commit fc725673efb1af2a5c6f34c084de4b13240f8c5a. --- .github/workflows/ci.yml | 2 +- examples/01-geometry/01-lines.py | 2 +- src/ansys/mapdl/core/mapdl.py | 19 +++++++++++++-- src/ansys/mapdl/core/plotting.py | 14 +++++++++++ src/ansys/mapdl/core/theme.py | 2 +- tests/test_plotting.py | 42 ++++++++++++++++++++++++++++++++ tests/test_post.py | 6 ++++- 7 files changed, 81 insertions(+), 6 deletions(-) diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index e8e9c18773..b6a0773ae5 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -32,7 +32,7 @@ env: DOCKER_PACKAGE: ghcr.io/ansys/mapdl DOCKER_IMAGE_VERSION_DOCS_BUILD: v23.1.0 ON_CI: True - PYTEST_ARGUMENTS: '-vv --durations=10 --maxfail=10 --reruns 7 --reruns-delay 5 --cov=ansys.mapdl.core --cov-report=html' + PYTEST_ARGUMENTS: '-vv --durations=10 --maxfail=1 --reruns 1 --reruns-delay 5 --cov=ansys.mapdl.core --cov-report=html' # Following env vars when changed will "reset" the mentioned cache, # by changing the cache file name. It is rendered as ...-v%RESET_XXX%-... diff --git a/examples/01-geometry/01-lines.py b/examples/01-geometry/01-lines.py index 0ba015bcab..7ec25e6ea4 100644 --- a/examples/01-geometry/01-lines.py +++ b/examples/01-geometry/01-lines.py @@ -44,7 +44,7 @@ k1 = mapdl.k("", 1, 1, 0) k2 = mapdl.k("", 0, 1, 0) lnum = mapdl.larc(k0, k1, k2, 2) -mapdl.lplot(background="w", color="k", line_width=5, cpos="xy") +mapdl.lplot(background="w", color="y", line_width=5, cpos="xy") ############################################################################### diff --git a/src/ansys/mapdl/core/mapdl.py b/src/ansys/mapdl/core/mapdl.py index 00fba5eec1..5123ebe340 100644 --- a/src/ansys/mapdl/core/mapdl.py +++ b/src/ansys/mapdl/core/mapdl.py @@ -1755,8 +1755,14 @@ def vplot( quality of the mesh to display. Varies between 1 (worst) to 10 (best). Applicable when ``vtk=True``. - show_numbering : bool, optional - Display line and keypoint numbers when ``vtk=True``. + show_volume_numbering : bool, optional + Display volume numbers when ``vtk=True``. + + show_area_numbering : bool, optional + Display area numbers when ``vtk=True``. + + show_line_numbering : bool, optional + Display line numbers when ``vtk=True``. **kwargs See :meth:`ansys.mapdl.core.plotting.general_plotter` for @@ -1812,10 +1818,19 @@ def vplot( ) meshes_ = get_meshes_from_plotter(pl) + center_volumes = pl.center for each_mesh in meshes_: each_mesh.cell_data["entity_num"] = int(each_volu) + if show_volume_numbering: + labels.append( + { + "points": np.array(center_volumes), + "labels": [int(each_volu)], + } + ) + meshes.extend(meshes_) meshes = [{"mesh": meshes}] diff --git a/src/ansys/mapdl/core/plotting.py b/src/ansys/mapdl/core/plotting.py index 490ecb9bbb..fd50e6117d 100644 --- a/src/ansys/mapdl/core/plotting.py +++ b/src/ansys/mapdl/core/plotting.py @@ -406,6 +406,20 @@ def _general_plotter( if background: plotter.set_background(background) + # Making sure that labels are visible in dark backgrounds + if not text_color and background: + bg = plotter.background_color.float_rgb + # from: https://graphicdesign.stackexchange.com/a/77747/113009 + gamma = 2.2 + threshold = ( + 0.2126 * bg[0] ** gamma + 0.7152 * bg[1] ** gamma + 0.0722 * bg[2] ** gamma + > 0.5 * gamma + ) + if threshold: + text_color = "black" + else: + text_color = "white" + for point in points: plotter.add_points( point["points"], diff --git a/src/ansys/mapdl/core/theme.py b/src/ansys/mapdl/core/theme.py index e9c019b1ff..d103a5ac11 100644 --- a/src/ansys/mapdl/core/theme.py +++ b/src/ansys/mapdl/core/theme.py @@ -55,7 +55,7 @@ class myEmptyClass: ) if _HAS_MATPLOTLIB: - PyMAPDL_cmap: ListedColormap = ListedColormap(MAPDL_colorbar, name="PyMAPDL", N=255) + PyMAPDL_cmap: ListedColormap = ListedColormap(MAPDL_colorbar, name="PyMAPDL") def get_ansys_colors(N=9): diff --git a/tests/test_plotting.py b/tests/test_plotting.py index d0710e4679..c9e5acab69 100644 --- a/tests/test_plotting.py +++ b/tests/test_plotting.py @@ -885,3 +885,45 @@ def test_cuadratic_beam(mapdl, cuadratic_beam_problem): ) is None ) + + +@pytest.mark.parametrize("background", ["white", "black", "green", "red"]) +def test_labels_colors_background(mapdl, make_block, background): + # Test if the labels change color according background + mapdl.nplot(background=background, nnum=True) + + +def test_vplot_show_volume_numbering(mapdl, make_block): + mapdl.vplot(show_volume_numbering=True) + + +def test_vplot_area_numbering(mapdl, make_block): + mapdl.vplot(show_area_numbering=True) + + +def test_vplot_line_numbering(mapdl, make_block): + mapdl.vplot(show_line_numbering=True) + + +def test_vplot_multi_numbering(mapdl, make_block): + mapdl.vplot( + show_area_numbering=True, show_line_numbering=True, show_volume_numbering=True + ) + + +def test_vplot_color(mapdl, make_block): + mapdl.vplot(color="gray") + + +def test_vplot_cpos(mapdl, make_block): + mapdl.vplot(cpos="xy") + + +def test_vplot_multiargs(mapdl, make_block): + mapdl.vplot( + color="gray", + cpos="xy", + show_volume_numbering=True, + show_line_numbering=False, + show_area_numbering=True, + ) diff --git a/tests/test_post.py b/tests/test_post.py index 387f662fa6..2789abbaf1 100644 --- a/tests/test_post.py +++ b/tests/test_post.py @@ -10,6 +10,7 @@ if has_dependency("pyvista"): from pyvista import Plotter from pyvista.plotting.renderer import CameraPosition + from ansys.mapdl.core.theme import PyMAPDL_cmap from ansys.mapdl.core import examples from ansys.mapdl.core.post import ( @@ -158,7 +159,10 @@ def test_disp_norm_all(mapdl, static_solve): @requires("pyvista") def test_disp_plot(mapdl, static_solve, comp): assert ( - mapdl.post_processing.plot_nodal_displacement(comp, smooth_shading=True) is None + mapdl.post_processing.plot_nodal_displacement( + comp, smooth_shading=True, cmap=PyMAPDL_cmap + ) + is None ) From 10cd2f12fb4776f4543ddb52636e7b8cc2581cd3 Mon Sep 17 00:00:00 2001 From: German Date: Fri, 15 Dec 2023 11:47:18 +0100 Subject: [PATCH 7/7] Undoing components selection. It does not make sense. --- src/ansys/mapdl/core/mesh/mesh.py | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/src/ansys/mapdl/core/mesh/mesh.py b/src/ansys/mapdl/core/mesh/mesh.py index d68b35e1b7..7c41e3f399 100644 --- a/src/ansys/mapdl/core/mesh/mesh.py +++ b/src/ansys/mapdl/core/mesh/mesh.py @@ -156,6 +156,7 @@ def _parse_vtk( # Store original ANSYS element and node information try: grid.point_data["ansys_node_num"] = nnum + except ValueError: grid.point_data["ansys_node_num"] = ( mesh._mapdl.nlist(kinternal="internal").to_array()[:, 0].astype(np.int32) @@ -167,17 +168,6 @@ def _parse_vtk( grid.cell_data["ansys_etype"] = mesh._ans_etype grid.cell_data["ansys_elem_type_num"] = mesh.etype - # add components - # Add element components to unstructured grid - for key, item in mesh.element_components.items(): - mask = np.in1d(mesh.enum, item, assume_unique=True) - grid.cell_data[key] = mask - - # Add node components to unstructured grid - for key, item in mesh.node_components.items(): - mask = np.in1d(nnum, item, assume_unique=True) - grid.point_data[key] = mask - # store node angles if angles is not None: if angles.shape[1] == 3: