Skip to content

Commit

Permalink
docs: adding warning about *mwrite. Update *vwrite warning to include…
Browse files Browse the repository at this point in the history
… *mwrite (#3296)

* docs: adding warning about *mwrite. Update *vwrite warning to include *mwrite

* chore: adding changelog file 3296.miscellaneous.md

* feat: adding wrapper to *MWRITE which raises a warning if not in non-interactive.

* tests: adding tests

* feat: adding wrapper to raise exception

---------

Co-authored-by: pyansys-ci-bot <92810346+pyansys-ci-bot@users.noreply.github.com>
  • Loading branch information
germa89 and pyansys-ci-bot authored Jul 29, 2024
1 parent 96082d1 commit adbfa38
Show file tree
Hide file tree
Showing 7 changed files with 47 additions and 9 deletions.
1 change: 1 addition & 0 deletions doc/changelog.d/3296.miscellaneous.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
docs: adding warning about *mwrite. Update *vwrite warning to include *mwrite
6 changes: 3 additions & 3 deletions doc/source/user_guide/convert.rst
Original file line number Diff line number Diff line change
Expand Up @@ -288,9 +288,9 @@ which can be done with:
Note that some of the commands with ``/`` are not directly translated
to functions and are instead run as "classic" commands like
``mapdl.run('/COM')``. Also, note that the ``*VWRITE`` command
requires a command immediately following it. This normally locks the
interface, so it's implemented in the background as an input file
``mapdl.run('/COM')``. Also, note that the ``*VWRITE`` and ``*MWRITE`` commands
require a command immediately following it with the desire output format.
This normally locks the interface, so it's implemented in the background as an input file
using the :attr:`Mapdl.non_interactive <ansys.mapdl.core.Mapdl.non_interactive>`
attribute.

Expand Down
2 changes: 2 additions & 0 deletions doc/source/user_guide/mapdl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -1087,6 +1087,8 @@ are unsupported.
+---------------+---------------------------------------------------------------------------------------------------------------------------------+----------------------------------+----------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------+
| * ``*VWRITE`` | |:x:| Not available | |:white_check_mark:| Available | |:exclamation:| Only in :attr:`Mapdl.non_interactive <ansys.mapdl.core.Mapdl.non_interactive>` | If you are working in a local session, it is recommended you use Python function such as ``open``. |
+---------------+---------------------------------------------------------------------------------------------------------------------------------+----------------------------------+----------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------+
| * ``*MWRITE`` | |:x:| Not available | |:white_check_mark:| Available | |:exclamation:| Only in :attr:`Mapdl.non_interactive <ansys.mapdl.core.Mapdl.non_interactive>` | If you are working in a local session, it is recommended you use Python function such as ``open``. |
+---------------+---------------------------------------------------------------------------------------------------------------------------------+----------------------------------+----------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------+
| * ``LSWRITE`` | |:white_check_mark:| Available (Internally running in :attr:`Mapdl.non_interactive <ansys.mapdl.core.Mapdl.non_interactive>`) | |:white_check_mark:| Available | |:exclamation:| Only in :attr:`Mapdl.non_interactive <ansys.mapdl.core.Mapdl.non_interactive>` | |
+---------------+---------------------------------------------------------------------------------------------------------------------------------+----------------------------------+----------------------------------------------------------------------------------------------------------------------+-----------------------------------------------------------------------------------------------------+

Expand Down
4 changes: 4 additions & 0 deletions src/ansys/mapdl/core/_commands/apdl/array_param.py
Original file line number Diff line number Diff line change
Expand Up @@ -353,6 +353,10 @@ def mwrite(
APDL Command: ``*MWRITE``
.. warning::
This command cannot be run interactively. See
:func:`non_interactive <ansys.mapdl.core.Mapdl.non_interactive>`.
Parameters
----------
parr
Expand Down
10 changes: 6 additions & 4 deletions src/ansys/mapdl/core/mapdl_core.py
Original file line number Diff line number Diff line change
Expand Up @@ -104,20 +104,22 @@
"WRITTEN TO FILE"
) # getting the file name is buggy.

VWRITE_REPLACEMENT = """
Cannot use *VWRITE directly as a command in MAPDL
VWRITE_MWRITE_REPLACEMENT = """
Cannot use *VWRITE/*MWRITE directly as a command in MAPDL
service mode. Instead, run it as ``non_interactive``.
For example:
For example, in the *VWRITE case:
with self.non_interactive:
self.vwrite('%s(1)' % parm_name)
self.run('(F20.12)')
"""

## Invalid commands in interactive mode.
INVAL_COMMANDS = {
"*VWR": VWRITE_REPLACEMENT,
"*VWR": VWRITE_MWRITE_REPLACEMENT,
"*MWR": VWRITE_MWRITE_REPLACEMENT,
"*CFO": "Run CFOPEN as ``non_interactive``",
"*CRE": "Create a function within python or run as non_interactive",
"*END": "Create a function within python or run as non_interactive",
Expand Down
26 changes: 25 additions & 1 deletion src/ansys/mapdl/core/mapdl_extended.py
Original file line number Diff line number Diff line change
Expand Up @@ -1509,7 +1509,7 @@ def vwrite(
# cannot be run in interactive mode
if not self._store_commands:
raise MapdlRuntimeError(
"VWRTIE cannot run interactively. \n\nPlease use "
"*VWRITE cannot run interactively. \n\nPlease use "
"``with mapdl.non_interactive:``"
)

Expand All @@ -1536,6 +1536,30 @@ def vwrite(
**kwargs,
)

@wraps(_MapdlCore.mwrite)
def mwrite(
self, parr="", fname="", ext="", label="", n1="", n2="", n3="", **kwargs
):
"""Wrapping *MWRITE"""

# cannot be run in interactive mode
if not self._store_commands:
raise MapdlRuntimeError(
"*MWRITE cannot run interactively. \n\nPlease use "
"``with mapdl.non_interactive:``"
)

return super().mwrite(
parr=parr,
fname=fname,
ext=ext,
label=label,
n1=n1,
n2=n2,
n3=n3,
**kwargs,
)

@wraps(_MapdlCore.nrm)
def nrm(self, name="", normtype="", parr="", normalize="", **kwargs):
"""Wraps *NRM"""
Expand Down
7 changes: 6 additions & 1 deletion tests/test_mapdl.py
Original file line number Diff line number Diff line change
Expand Up @@ -1131,7 +1131,7 @@ def test_cdread_in_apdl_directory(mapdl, cleared):


@pytest.mark.parametrize(
"each_cmd", ["*END", "*vwrite", "/eof", "cmatrix", "*REpeAT", "lSread"]
"each_cmd", ["*END", "*vwrite", "/eof", "cmatrix", "*REpeAT", "lSread", "*mwrite"]
)
def test_inval_commands(mapdl, cleared, each_cmd):
"""Test the output of invalid commands"""
Expand Down Expand Up @@ -2249,6 +2249,11 @@ def test_vwrite_error(mapdl):
mapdl.vwrite("adf")


def test_mwrite_error(mapdl):
with pytest.raises(MapdlRuntimeError):
mapdl.mwrite("adf")


def test_vwrite(mapdl):
with mapdl.non_interactive:
mapdl.run("/out,test_vwrite.txt")
Expand Down

0 comments on commit adbfa38

Please sign in to comment.