Skip to content

Commit

Permalink
Merge branch 'main' into fix/rescontrol-arguments-number
Browse files Browse the repository at this point in the history
  • Loading branch information
germa89 authored Jan 31, 2022
2 parents fb6ee2c + 33ec6a5 commit ba42fc6
Show file tree
Hide file tree
Showing 6 changed files with 111 additions and 87 deletions.
9 changes: 9 additions & 0 deletions ansys/mapdl/core/mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1819,7 +1819,16 @@ def get(
"""
command = f"*GET,{par},{entity},{entnum},{item1},{it1num},{item2},{it2num}"
kwargs["mute"] = False

# Checking printout is not suppressed by checking "wrinqr" flag.
flag = 0
if self.wrinqr(1) != 1: # using wrinqr is more reliable than *get
flag = 1
self._run("/gopr")
response = self.run(command, **kwargs)
if flag == 1:
self._run("/nopr")

value = response.split("=")[-1].strip()
try: # always either a float or string
return float(value)
Expand Down
24 changes: 21 additions & 3 deletions ansys/mapdl/core/plotting.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ def general_plotter(
text_color=None,
theme=None,
return_plotter=False,
return_cpos=False,
):
"""General pymapdl plotter for APDL geometry and meshes.
Expand Down Expand Up @@ -158,6 +159,9 @@ def general_plotter(
Return the plotting object rather than showing the plot and
returning the camera position. Default ``False``.
return_cpos : bool, optional
Returns the camera position as an array. Default ``False``.
Returns
-------
cpos or pyvista.Plotter
Expand Down Expand Up @@ -268,21 +272,35 @@ def general_plotter(
if title:
pl.add_title(title)

returns_parameter = []
if return_plotter:
returns_parameter.append(pl)
if return_cpos:
returns_parameter.append(pl.camera_position)

if not returns_parameter:
returns_parameter = None
else:
if len(returns_parameter) == 1:
returns_parameter = returns_parameter[0]
else:
returns_parameter = tuple(returns_parameter)

# permit user to save the figure as a screenshot
if savefig:
pl.show(title=title, auto_close=False, window_size=window_size, screenshot=True)
pl.screenshot(savefig)

# return unclosed plotter
if return_plotter:
return pl
return returns_parameter

# if not returning plotter, close right away
pl.close()

elif return_plotter:
return pl
return returns_parameter
else:
pl.show()

return pl.camera_position
return returns_parameter
5 changes: 2 additions & 3 deletions tests/test_console.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from ansys.mapdl.core.errors import MapdlRuntimeError
from ansys.mapdl.reader import examples
from pyvista.plotting import system_supports_plotting
from pyvista.plotting.renderer import CameraPosition

skip_no_xserver = pytest.mark.skipif(
not system_supports_plotting(), reason="Requires active X Server"
Expand Down Expand Up @@ -214,7 +213,7 @@ def test_kplot(cleared, mapdl_console, tmpdir):

filename = str(tmpdir.mkdir("tmpdir").join("tmp.png"))
cpos = mapdl_console.kplot(savefig=filename)
assert isinstance(cpos, CameraPosition)
assert cpos is None
assert os.path.isfile(filename)

mapdl_console.kplot(knum=True, vtk=False) # make sure legacy still works
Expand Down Expand Up @@ -298,7 +297,7 @@ def test_lplot(cleared, mapdl_console, tmpdir):

filename = str(tmpdir.mkdir("tmpdir").join("tmp.png"))
cpos = mapdl_console.lplot(show_keypoint_numbering=True, savefig=filename)
assert isinstance(cpos, CameraPosition)
assert cpos is None
assert os.path.isfile(filename)

mapdl_console.lplot(vtk=False) # make sure legacy still works
Expand Down
5 changes: 2 additions & 3 deletions tests/test_corba.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
from ansys.mapdl.core.errors import MapdlRuntimeError
from ansys.mapdl.reader import examples
from pyvista.plotting import system_supports_plotting
from pyvista.plotting.renderer import CameraPosition

skip_no_xserver = pytest.mark.skipif(
not system_supports_plotting(), reason="Requires active X Server"
Expand Down Expand Up @@ -209,7 +208,7 @@ def test_kplot(cleared, mapdl_corba, tmpdir):

filename = str(tmpdir.mkdir("tmpdir").join("tmp.png"))
cpos = mapdl_corba.kplot(savefig=filename)
assert isinstance(cpos, CameraPosition)
assert cpos is None
assert os.path.isfile(filename)

mapdl_corba.kplot(knum=True, vtk=False) # make sure legacy still works
Expand Down Expand Up @@ -292,7 +291,7 @@ def test_lplot(cleared, mapdl_corba, tmpdir):

filename = str(tmpdir.mkdir("tmpdir").join("tmp.png"))
cpos = mapdl_corba.lplot(show_keypoint_numbering=True, savefig=filename)
assert isinstance(cpos, CameraPosition)
assert cpos is None
assert os.path.isfile(filename)

mapdl_corba.lplot(vtk=False) # make sure legacy still works
Expand Down
30 changes: 25 additions & 5 deletions tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
from ansys.mapdl.reader import examples
from pyvista import PolyData
from pyvista.plotting import system_supports_plotting
from pyvista.plotting.renderer import CameraPosition

from ansys.mapdl.core.launcher import get_start_instance, launch_mapdl

Expand Down Expand Up @@ -335,7 +334,7 @@ def test_kplot(cleared, mapdl, tmpdir):

filename = str(tmpdir.mkdir("tmpdir").join("tmp.png"))
cpos = mapdl.kplot(savefig=filename)
assert isinstance(cpos, CameraPosition)
assert cpos is None
assert os.path.isfile(filename)

mapdl.kplot(vtk=False) # make sure legacy still works
Expand Down Expand Up @@ -416,7 +415,7 @@ def test_lplot(cleared, mapdl, tmpdir):

filename = str(tmpdir.mkdir("tmpdir").join("tmp.png"))
cpos = mapdl.lplot(show_keypoint_numbering=True, savefig=filename)
assert isinstance(cpos, CameraPosition)
assert cpos is None
assert os.path.isfile(filename)

mapdl.lplot(vtk=False) # make sure legacy still works
Expand All @@ -442,7 +441,7 @@ def test_apdl_logging_start(tmpdir):
text = ''.join(fid.readlines())

assert 'PREP7' in text
assert '!comment test'
assert '!comment test' in text
assert 'K,1,0,0,0' in text
assert 'K,2,1,0,0' in text
assert 'K,3,1,1,0' in text
Expand All @@ -469,7 +468,7 @@ def test_corba_apdl_logging_start(tmpdir):
text = ''.join(fid.readlines())

assert 'PREP7' in text
assert '!comment test'
assert '!comment test' in text
assert 'K,1,0,0,0' in text
assert 'K,2,1,0,0' in text
assert 'K,3,1,1,0' in text
Expand Down Expand Up @@ -1052,6 +1051,27 @@ def test_rescontrol(mapdl):
mapdl.rescontrol("DEFINE", "", "", "", "", "XNNN") # This is default


def test_get_with_gopr(mapdl):
"""Get should work independently of the /gopr state."""

mapdl._run("/gopr")
assert mapdl.wrinqr(1) == 1
par = mapdl.get("__par__", "ACTIVE", "", "TIME", "WALL")
assert mapdl.scalar_param('__par__') is not None
assert par is not None
assert np.allclose(mapdl.scalar_param('__par__'), par)

mapdl._run("/nopr")
assert mapdl.wrinqr(1) == 0
par = mapdl.get("__par__", "ACTIVE", "", "TIME", "WALL")
assert mapdl.scalar_param('__par__') is not None
assert par is not None
assert np.allclose(mapdl.scalar_param('__par__'), par)

mapdl._run("/gopr") # Going back
assert mapdl.wrinqr(1) == 1


def test_print_com(mapdl, capfd):
mapdl.print_com = True
string_ = "Testing print"
Expand Down
Loading

0 comments on commit ba42fc6

Please sign in to comment.