Skip to content

Commit 2a39130

Browse files
authored
Mode exposed in Mapdl class (#1560)
* Adding 'mode' method to mapdl class * Added unit tests * Clarification in the API section
1 parent 51bf843 commit 2a39130

File tree

9 files changed

+67
-2
lines changed

9 files changed

+67
-2
lines changed

doc/source/contribution_and_api/index.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ This way, it's not possible for you to push code that fails the style checks. Fo
107107

108108
API Reference
109109
=============
110-
This section gives an overview of the API of several public PyMAPDL
111-
classes, functions, and attributes.
110+
This page gives an overview of the API of several public PyMAPDL
111+
classes, functions, and attributes. You can find them
112+
on the left sidebar.
112113

113114
These methods may include some MAPDL commands but are generally
114115
specific to pymapdl specific methods and classes (i.e. methods that

src/ansys/mapdl/core/mapdl.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,7 @@ def __init__(
165165
self._store_commands = False
166166
self._stored_commands = []
167167
self._response = None
168+
self._mode = None
168169

169170
if _HAS_PYVISTA:
170171
if use_vtk is not None: # pragma: no cover
@@ -236,6 +237,26 @@ def print_com(self, value):
236237
f"The property ``print_com`` only allows booleans, but type {type(value)} was supplied."
237238
)
238239

240+
@property
241+
def mode(self):
242+
"""Return the type of instance, namely: grpc, corba or console."""
243+
return self._mode
244+
245+
@property
246+
def is_grpc(self):
247+
"""Return true if using grpc to connect to the MAPDL instance."""
248+
return self._mode == "grpc"
249+
250+
@property
251+
def is_corba(self):
252+
"""Return true if using corba to connect to the MAPDL instance."""
253+
return self._mode == "corba"
254+
255+
@property
256+
def is_console(self):
257+
"""Return true if using console to connect to the MAPDL instance."""
258+
return self._mode == "console"
259+
239260
def _wrap_listing_functions(self):
240261
# Wrapping LISTING FUNCTIONS.
241262
def wrap_listing_function(func):

src/ansys/mapdl/core/mapdl_console.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ def __init__(
9999
print_com=print_com,
100100
**start_parm,
101101
)
102+
self._mode = "console"
102103

103104
def _launch(self, start_parm):
104105
"""Connect to MAPDL process using pexpect"""

src/ansys/mapdl/core/mapdl_corba.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,7 @@ def __init__(
188188
**start_parm,
189189
)
190190

191+
self._mode = "corba"
191192
self._broadcast_logger = None
192193
self._server = None
193194
self._outfile = None

src/ansys/mapdl/core/mapdl_grpc.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,7 @@ def __init__(
322322
print_com=print_com,
323323
**start_parm,
324324
)
325+
self._mode = "grpc"
325326

326327
# gRPC request specific locks as these gRPC request are not thread safe
327328
self._vget_lock = False

tests/test_console.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -587,3 +587,10 @@ def test_load_table(mapdl_console):
587587
)
588588
mapdl_console.load_table("my_conv", my_conv, "TIME")
589589
assert np.allclose(mapdl_console.parameters["my_conv"], my_conv[:, -1])
590+
591+
592+
def test_mode_corba(mapdl_console):
593+
assert mapdl_console.mode == "console"
594+
assert not mapdl_console.is_grpc
595+
assert not mapdl_console.is_corba
596+
assert mapdl_console.is_console

tests/test_corba.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -572,3 +572,10 @@ def test_load_table(mapdl, dim_rows, dim_cols):
572572
)
573573
else:
574574
assert np.allclose(mapdl.parameters["my_conv"], my_conv[1:, 1:], 1e-7)
575+
576+
577+
def test_mode_corba(mapdl_corba):
578+
assert mapdl_corba.mode == "corba"
579+
assert not mapdl_corba.is_grpc
580+
assert mapdl_corba.is_corba
581+
assert not mapdl_corba.is_console

tests/test_grpc.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,3 +364,10 @@ def test__channel_str(mapdl):
364364
assert ":" in mapdl._channel_str
365365
assert re.search("\d{1,3}\.\d{1,3}\.\d{1,3}\.\d{1,3}", mapdl._channel_str)
366366
assert re.search("\d{4,6}", mapdl._channel_str)
367+
368+
369+
def test_mode_corba(mapdl):
370+
assert mapdl.mode == "grpc"
371+
assert mapdl.is_grpc
372+
assert not mapdl.is_corba
373+
assert not mapdl.is_console

tests/test_mapdl.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,3 +1594,22 @@ def test_use_uploading(mapdl, cleared, tmpdir):
15941594
# Raise an error
15951595
with pytest.raises(FileNotFoundError):
15961596
mapdl.use("asdf/myinexistentmacro.mac")
1597+
1598+
1599+
def test_mode(mapdl):
1600+
assert mapdl.mode == "grpc"
1601+
assert mapdl.is_grpc
1602+
assert not mapdl.is_corba
1603+
assert not mapdl.is_console
1604+
1605+
mapdl._mode = "corba" # overwriting underlying parameter
1606+
assert not mapdl.is_grpc
1607+
assert mapdl.is_corba
1608+
assert not mapdl.is_console
1609+
1610+
mapdl._mode = "console" # overwriting underlying parameter
1611+
assert not mapdl.is_grpc
1612+
assert not mapdl.is_corba
1613+
assert mapdl.is_console
1614+
1615+
mapdl._mode = "grpc" # Going back to default

0 commit comments

Comments
 (0)