Skip to content
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
45 commits
Select commit Hold shift + click to select a range
73337b5
fix: Optional viz dependency
AlejandroFernandezLuces Apr 1, 2025
1bfe70a
chore: adding changelog file 3820.fixed.md [dependabot-skip]
pyansys-ci-bot Apr 1, 2025
4af92af
fix: Change messages
AlejandroFernandezLuces Apr 1, 2025
2f4314e
Merge branch 'fix/optional-visualizer' of https://github.com/pyansys/…
AlejandroFernandezLuces Apr 1, 2025
624324a
Merge branch 'main' into fix/optional-visualizer
AlejandroFernandezLuces Apr 1, 2025
22a091f
chore: adding changelog file 3820.fixed.md [dependabot-skip]
pyansys-ci-bot Apr 1, 2025
dd44368
feat: Add decorator, move matplotlib to graphics, partial parameter n…
AlejandroFernandezLuces Apr 2, 2025
765256d
Merge branch 'main' into fix/optional-visualizer
AlejandroFernandezLuces Apr 2, 2025
4c985d4
Apply suggestions from code review
AlejandroFernandezLuces Apr 2, 2025
1d36fb0
feat: Add backend selector
AlejandroFernandezLuces Apr 2, 2025
06a7117
Update src/ansys/mapdl/core/mapdl_core.py
AlejandroFernandezLuces Apr 2, 2025
d6f3846
feat: Add `set_default_backend` method and default pyvista backend
AlejandroFernandezLuces Apr 3, 2025
8a38cff
Merge branch 'fix/optional-visualizer' of https://github.com/pyansys/…
AlejandroFernandezLuces Apr 3, 2025
f5844a2
fix: Decorator
AlejandroFernandezLuces Apr 3, 2025
0fec75e
feat: Add new parameter to tests
AlejandroFernandezLuces Apr 3, 2025
1f52384
feat: Change launcher to new Enum
AlejandroFernandezLuces Apr 3, 2025
d4b95c9
fix: Missing vtk=true in examples
AlejandroFernandezLuces Apr 3, 2025
0d5c2fb
fix: CLI input
AlejandroFernandezLuces Apr 3, 2025
e367dd9
fix: Wrong param name
AlejandroFernandezLuces Apr 3, 2025
387a5cc
fix: PR suggestions
AlejandroFernandezLuces Apr 7, 2025
f5556b7
Merge branch 'main' into fix/optional-visualizer
AlejandroFernandezLuces Apr 7, 2025
13798d0
fix: Import
AlejandroFernandezLuces Apr 7, 2025
fbb423a
Merge branch 'fix/optional-visualizer' of https://github.com/pyansys/…
AlejandroFernandezLuces Apr 7, 2025
93404ee
fix: Import
AlejandroFernandezLuces Apr 7, 2025
da82c99
fix: Import
AlejandroFernandezLuces Apr 7, 2025
5b0511c
fix: Missing imports
AlejandroFernandezLuces Apr 7, 2025
eed1822
fix: returning to default state after test
germa89 Apr 7, 2025
ec45e05
feat: making sure we return to default state after testing
germa89 Apr 7, 2025
0963041
fix: update import statements
germa89 Apr 7, 2025
e7956ec
fix: update graphics_backend to use GraphicsBackend enum in failing test
germa89 Apr 7, 2025
568fb42
fix: docstrings in post functions and their test
germa89 Apr 7, 2025
c2f0790
fix: capitalization in enum
germa89 Apr 7, 2025
9d382d6
fix: update graphics_backend handling in convert function and tests
germa89 Apr 7, 2025
2ad65a1
fix: add wraps decorator to requires_graphics function so the docstri…
germa89 Apr 7, 2025
ecd4e1f
Merge branch 'main' into fix/optional-visualizer
germa89 Apr 7, 2025
7b0ddcd
test: Add non existent backend
AlejandroFernandezLuces Apr 8, 2025
9956b2d
test: fix cli test
AlejandroFernandezLuces Apr 8, 2025
826375c
Merge branch 'main' into fix/optional-visualizer
germa89 Apr 14, 2025
64d26c6
ci: auto fixes from pre-commit.com hooks.
pre-commit-ci[bot] Apr 14, 2025
58c9d91
Merge branch 'main' into fix/optional-visualizer
germa89 Apr 14, 2025
34740c4
fix: Add decorator for deprecated param
AlejandroFernandezLuces Apr 14, 2025
7abb577
Merge branch 'fix/optional-visualizer' of https://github.com/pyansys/…
AlejandroFernandezLuces Apr 14, 2025
d0028b9
chore: adding changelog file 3820.fixed.md [dependabot-skip]
pyansys-ci-bot Apr 14, 2025
55bc120
fix: Force keyword-only arguments for non-MAPDL arguments in extended…
germa89 Apr 14, 2025
5f017d8
Apply suggestions from code review
AlejandroFernandezLuces Apr 15, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions doc/changelog.d/3820.fixed.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
fix: Optional graphics dependency
2 changes: 1 addition & 1 deletion doc/source/api/mapdl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@
Mapdl.screenshot
Mapdl.set_log_level
Mapdl.thermal_result
Mapdl.use_vtk
Mapdl.graphics_backend
Mapdl.version


Expand Down
17 changes: 9 additions & 8 deletions doc/source/user_guide/plotting.rst
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ transfer the geometry to Python to visualize it:

- :func:`Mapdl.kplot() <ansys.mapdl.core.Mapdl.kplot>`
- :func:`Mapdl.vplot() <ansys.mapdl.core.Mapdl.vplot>`
- :func:`Mapdl.eplot() <ansys.mapdl.core.Mapdl.eplot>`).
- :func:`Mapdl.eplot() <ansys.mapdl.core.Mapdl.eplot>`).

These methods rely on the :class:`ansys.mapdl.core.plotting.visualizer.MapdlPlotter`
method. Combined with the MAPDL geometry commands, you can
Expand Down Expand Up @@ -91,10 +91,10 @@ some element types, performs meshing, and then displays the mesh:
Plotting non-interactively using MAPDL
--------------------------------------
You can also plot using MAPDL's native plotting tools. To use the
native tools, pass ``vtk=False`` when running plotting commands such
native tools, pass ``graphics_backend=GraphicsBackend.MAPDL`` when running plotting commands such
as the :func:`Mapdl.aplot <ansys.mapdl.core.Mapdl.aplot>` and
:func:`Mapdl.eplot <ansys.mapdl.core.Mapdl.eplot>` methods. Plots are
generated within MAPDL and then shown using
generated within MAPDL and then shown using
`Matplotlib <matplotlib_main_>`_.


Expand Down Expand Up @@ -132,15 +132,16 @@ Each of these creates a Matplotlib figure and pause execution.

.. code:: pycon

>>> mapdl.aplot(vtk=False)
>>> mapdl.lplot(vtk=False)
>>> mapdl.kplot(vtk=False)
>>> from ansys.mapdl.core import GraphicsBackend
>>> mapdl.aplot(graphics_backend=GraphicsBackend.MAPDL)
>>> mapdl.lplot(graphics_backend=GraphicsBackend.MAPDL)
>>> mapdl.kplot(graphics_backend=GraphicsBackend.MAPDL)


.. figure:: ../images/aplot.png
:width: 400pt

Area Plot from MAPDL displayed using
Area Plot from MAPDL displayed using
`Matplotlib <matplotlib_main_>`_


Expand All @@ -149,7 +150,7 @@ For more information on plotting functions, see :ref:`ref_plotting_api`.

Plotting keyword options
------------------------
When ``vtk=True``, which is the default, all MAPDL plotting
When ``graphics_backend=GraphicsBackend.PYVISTA``, which is the default, all MAPDL plotting
methods allow you to enter in additional keyword arguments to better
control the plot. For example, you can automatically generate a
screenshot of an area plot or element plot with this code:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@
import numpy as np
import pyvista as pv

from ansys.mapdl.core import launch_mapdl
from ansys.mapdl.core import GraphicsBackend, launch_mapdl

###############################################################################
# Launch MAPDL service
Expand Down Expand Up @@ -182,7 +182,7 @@
mapdl.pnum("MAT", 1) # Turn material numbers on
mapdl.allsel("ALL")

mapdl.aplot(vtk=False)
mapdl.aplot(graphics_backend=GraphicsBackend.MAPDL)

###############################################################################
# Mesh
Expand Down
1 change: 0 additions & 1 deletion examples/00-mapdl-examples/2d_plate_with_a_hole.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@
mapdl.esize(plate_esize)
mapdl.amesh(plate_with_hole_anum)
mapdl.eplot(
vtk=True,
cpos="xy",
show_edges=True,
show_axes=False,
Expand Down
10 changes: 5 additions & 5 deletions examples/00-mapdl-examples/3d_notch.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,18 +89,18 @@


mapdl.lsla("S")
mapdl.lplot(vtk=True, show_keypoint_numbering=True)
mapdl.lplot(show_keypoint_numbering=True)
mapdl.lsel("all")

# plot the area using vtk/pyvista
mapdl.aplot(vtk=True, show_area_numbering=True, show_lines=True, cpos="xy")
mapdl.aplot(show_area_numbering=True, show_lines=True, cpos="xy")

# Next, extrude the area to create volume
thickness = 0.01
mapdl.vext(cut_area, dz=thickness)

# Checking volume plot
mapdl.vplot(vtk=True, show_lines=True, show_axes=True, smooth_shading=True)
mapdl.vplot(show_lines=True, show_axes=True, smooth_shading=True)


###############################################################################
Expand All @@ -126,7 +126,7 @@
# line and area numbers identified using aplot

mapdl.asel("S", "AREA", vmin=1, vmax=1)
mapdl.aplot(vtk=True, show_line_numbering=True)
mapdl.aplot(show_line_numbering=True)


mapdl.lsel("NONE")
Expand All @@ -147,7 +147,7 @@
mapdl.esize() # this is tough to automate
mapdl.et(1, "SOLID186")
mapdl.vsweep("all")
mapdl.eplot(vtk=True, show_edges=True, show_axes=False, line_width=2, background="w")
mapdl.eplot(show_edges=True, show_axes=False, line_width=2, background="w")


###############################################################################
Expand Down
16 changes: 7 additions & 9 deletions examples/00-mapdl-examples/bracket_static.py
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@
circle1_Y = (box1[2] + box1[3]) / 2
mapdl.cyl4(circle1_X, circle1_Y, radius)

mapdl.aplot(vtk=True, cpos="xy", show_lines=True)
mapdl.aplot(cpos="xy", show_lines=True)


###############################################################################
Expand All @@ -233,7 +233,7 @@
# as the first circle area.

mapdl.cyl4(circle2_X, circle2_Y, radius)
mapdl.aplot(vtk=True, cpos="xy", show_lines=True)
mapdl.aplot(cpos="xy", show_lines=True)


###############################################################################
Expand Down Expand Up @@ -299,7 +299,7 @@
line3 = mapdl.lfillt("line1", l2, fillet_radius)

mapdl.allsel()
mapdl.lplot(vtk=True, cpos="xy")
mapdl.lplot(cpos="xy")

###############################################################################
# Create fillet area
Expand Down Expand Up @@ -334,7 +334,7 @@
mapdl.lsel("A", "LINE", "", line3)

# plotting ares
mapdl.lplot(vtk=True, cpos="xy", show_line_numbering=True)
mapdl.lplot(cpos="xy", show_line_numbering=True)

###############################################################################
# Then use :meth:`mapdl.al() <ansys.mapdl.core.Mapdl.al>` command to create the areas
Expand All @@ -355,7 +355,7 @@

# Add the area to the main area
mapdl.aadd("all")
mapdl.aplot(vtk=True, cpos="xy", show_lines=True)
mapdl.aplot(cpos="xy", show_lines=True)

###############################################################################
# Create first pin hole
Expand Down Expand Up @@ -410,7 +410,7 @@
# Remove pin hole areas from bracket
mapdl.asba("all", pinhole1)
bracket = mapdl.asba("all", pinhole2)
mapdl.aplot(vtk=True, show_lines=True, cpos="xy")
mapdl.aplot(show_lines=True, cpos="xy")

###############################################################################
# Model definition
Expand Down Expand Up @@ -500,7 +500,6 @@
mapdl.esize(element_size)
mapdl.amesh(bracket)
mapdl.eplot(
vtk=True,
cpos="xy",
show_edges=True,
show_axes=False,
Expand Down Expand Up @@ -612,7 +611,7 @@
#
mapdl.lsel("R", "LOC", "X", 0, pinhole2_X)

mapdl.lplot(vtk=True, cpos="xy")
mapdl.lplot(cpos="xy")

###############################################################################
#
Expand All @@ -634,7 +633,6 @@
mapdl.lsel("R", "LOC", "X", pinhole2_X, pinhole2_X + pinhole_radius)

mapdl.lplot(
vtk=True,
cpos="xy",
show_line_numbering=True,
)
Expand Down
10 changes: 5 additions & 5 deletions examples/00-mapdl-examples/lathe_cutter.py
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@

import numpy as np

from ansys.mapdl.core import launch_mapdl
from ansys.mapdl.core import GraphicsBackend, launch_mapdl
from ansys.mapdl.core.examples.downloads import download_example_data

# cwd = current working directory
Expand Down Expand Up @@ -194,9 +194,9 @@
#
# VTK plots do not show MAPDL plot symbols.
# However, to use MAPDL plotting capabilities, you can set the keyword
# option ``vtk`` to ``False``.

mapdl.lplot(vtk=False)
# option ``backend`` to ``GraphicsBackend.MAPDL``.
mapdl.set_graphics_backend(GraphicsBackend.MAPDL)
mapdl.lplot()

###############################################################################
# Step 4: Pressure load
Expand Down Expand Up @@ -244,7 +244,7 @@
mapdl.nlgeom("On")
mapdl.psf("PRES", "NORM", 3, 0, 1)
mapdl.view(1, -1, 1, 1)
mapdl.eplot(vtk=False)
mapdl.eplot()

###############################################################################
# Solve the model.
Expand Down
2 changes: 1 addition & 1 deletion examples/00-mapdl-examples/mapdl_beam.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@
print(mapdl.mesh.nnum)

# plot the nodes using VTK
mapdl.nplot(vtk=True, nnum=True, cpos="xy", show_bounds=True, point_size=10)
mapdl.nplot(nnum=True, cpos="xy", show_bounds=True, point_size=10)

###############################################################################
# create elements between the nodes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@
for k in [k2, k3, k6, k7]:
mapdl.kesize(k, 0.2)
mapdl.amesh("ALL")
mapdl.eplot(vtk=True, show_edges=True, show_axes=False, line_width=2, background="w")
mapdl.eplot(show_edges=True, show_axes=False, line_width=2, background="w")


###############################################################################
Expand Down
14 changes: 12 additions & 2 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,8 @@ dependencies = [
"ansys-math-core>=0.1.2",
"ansys-platform-instancemanagement~=1.0",
"ansys-tools-path>=0.3.1",
"ansys-tools-visualization-interface>=0.2.6",
"click>=8.1.3", # for CLI interface
"grpcio>=1.30.0", # tested up to grpcio==1.35
"matplotlib>=3.0.0", # for colormaps for pyvista
"numpy>=1.14.0,<3.0.0",
"pexpect>=4.8.0 ; platform_system=='Linux'",
"platformdirs>=3.6.0",
Expand Down Expand Up @@ -53,6 +51,18 @@ jupyter = [
"ipywidgets",
]

graphics = [
"ansys-tools-visualization-interface>=0.2.6",
"matplotlib>=3.0.0", # for colormaps for pyvista
]

all = [
"ansys-tools-visualization-interface>=0.2.6",
"matplotlib>=3.0.0", # for colormaps for pyvista
"jupyterlab>=3",
"ipywidgets",
]

tests = [
"ansys-dpf-core==0.10.1",
"ansys-tools-visualization-interface==0.8.3",
Expand Down
16 changes: 15 additions & 1 deletion src/ansys/mapdl/core/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.

from enum import Enum

###############################################################################
# Imports
# =======
Expand Down Expand Up @@ -73,7 +75,19 @@
_HAS_PYVISTA: bool = is_installed("pyvista")
_HAS_REQUESTS: bool = is_installed("requests")
_HAS_TQDM: bool = is_installed("tqdm")
_HAS_VISUALIZER: bool = is_installed("ansys.tools.visualization_interface")
_HAS_VISUALIZER: bool = is_installed(
"ansys.tools.visualization_interface"
) and is_installed("matplotlib")


class GraphicsBackend(Enum):
"""Graphics backend for PyMAPDL.

This enum is used to set the graphics backend for PyMAPDL.
"""

PYVISTA: str = "pyvista"
MAPDL: str = "mapdl"


# Setup directories
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/mapdl/core/_commands/graphics_/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -293,7 +293,7 @@ def eshape(
warnings.warn(
"pymapdl does not support /ESHAPE when plotting in "
"Python using ``mapdl.eplot()``. "
"Use ``mapdl.eplot(vtk=False)`` "
"Use ``mapdl.eplot(backend=GraphicsBackend.MAPDL)`` "
)
command = f"/ESHAPE,{scale},{key}"
return self.run(command, **kwargs)
Expand Down
2 changes: 1 addition & 1 deletion src/ansys/mapdl/core/_commands/post1_/controls.py
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ def efacet(self, num="", **kwargs):

.. warning::
This will not change element plotting within PyMAPDL with
``eplot(vtk=True)``
``eplot()``

Parameters
----------
Expand Down
21 changes: 16 additions & 5 deletions src/ansys/mapdl/core/cli/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@

import click

from ansys.mapdl.core import GraphicsBackend


@click.command(
short_help="Convert APDL code to PyMAPDL code.",
Expand Down Expand Up @@ -173,10 +175,10 @@
Overrides ``header``, ``add_imports`` and ``auto_exit``.""",
)
@click.option(
"--use_vtk",
"--graphics_backend",
default=None,
type=bool,
help="""It sets the `mapdl.use_vtk` argument equals True or False depending on
type=str,
help="""It sets the `mapdl.graphics_backend` argument depending on
this value. Defaults to `None` which is Mapdl class default.""",
)
@click.option(
Expand Down Expand Up @@ -207,13 +209,22 @@ def convert(
header: str,
print_com: bool,
only_commands: bool,
use_vtk: bool,
graphics_backend: bool,
clear_at_start: bool,
check_parameter_names: bool,
) -> None:
"""Convert MAPDL code to PyMAPDL"""
from ansys.mapdl.core.convert import convert_apdl_block

backend = None
if graphics_backend is not None:
if graphics_backend == "pyvista":
backend = GraphicsBackend.PYVISTA
elif graphics_backend == "mapdl":
backend = GraphicsBackend.MAPDL
else:
backend = None

converted_code = convert_apdl_block(
apdl_strings=file.read(),
loglevel=loglevel,
Expand All @@ -229,7 +240,7 @@ def convert(
header=header,
print_com=print_com,
only_commands=only_commands,
use_vtk=use_vtk,
graphics_backend=backend,
clear_at_start=clear_at_start,
check_parameter_names=check_parameter_names,
)
Expand Down
Loading
Loading