Skip to content

Commit

Permalink
Merge branch 'doc/documenting-non_interactive' of https://github.com/…
Browse files Browse the repository at this point in the history
…pyansys/pymapdl into doc/documenting-non_interactive
  • Loading branch information
germa89 committed Nov 21, 2023
2 parents a2ad1fd + cf53419 commit 9580b6e
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 18 deletions.
33 changes: 16 additions & 17 deletions doc/source/user_guide/mapdl.rst
Original file line number Diff line number Diff line change
Expand Up @@ -161,27 +161,27 @@ the MAPDL instance, and runs it using the
:meth:`Mapdl.input() <ansys.mapdl.core.Mapdl.input>` method.


For instance, the following :meth:`non_interactive context <ansys.mapdl.core.Mapdl.non_interactive>`:
For instance, this example code uses the :meth:`non_interactive context <ansys.mapdl.core.Mapdl.non_interactive>` method to generate input for MAPDL:

.. code:: python
with mapdl.non_interactive:
mapdl.nsel("all")
mapdl.nsel("R", "LOC", "Z", 10)
generates the following input for MAPDL:
The preceding code generates this input for MAPDL:

.. code:: apdl
NSEL,ALL
NSEL,R,LOC,Z,10
which is executed with a :func:`Mapdl.input() <ansys.mapdl.core.Mapdl.input>` call.
This MAPLD input is executed with a :meth:`Mapdl.input() <ansys.mapdl.core.Mapdl.input>` method call.

Because of the non-interactive context not running all the commands until the end,
you might find issues interacting inside it, with Python for instance.
For example, running Python commands such as
:func:`Mapdl.get_array() <ansys.mapdl.core.Mapdl.get_array>`
For example, running Python commands such as the
:meth:`Mapdl.get_array() <ansys.mapdl.core.Mapdl.get_array>` method
inside the context can give you out-of-sync responses.
The following code snippet is a demonstration of this kind of problem:

Expand All @@ -201,8 +201,8 @@ The following code snippet is a demonstration of this kind of problem:
assert klist_inside != klist_outside # Evaluates to true
In the preceding script, the values obtained by
:func:`Mapdl.get_array() <ansys.mapdl.core.Mapdl.get_array>` are different:
In the preceding script, the values obtained by the
:meth:`Mapdl.get_array() <ansys.mapdl.core.Mapdl.get_array>` method are different:

.. code:: pycon
Expand All @@ -211,21 +211,20 @@ In the preceding script, the values obtained by
>>> print(klist_outside)
array([1., 2., 3.])
This is because the first :func:`Mapdl.get_array() <ansys.mapdl.core.Mapdl.get_array>`
call is executed actually *before* the :func:`Mapdl.k() <ansys.mapdl.core.Mapdl.k>` call.
This is because the first :meth:`Mapdl.get_array() <ansys.mapdl.core.Mapdl.get_array>`
method call is executed *before* the :meth:`Mapdl.k() <ansys.mapdl.core.Mapdl.k>` method call.

It is recommend to not retrieve any data in a pythonic way from the MAPDL instance while in the
:meth:`non_interactive context <ansys.mapdl.core.Mapdl.non_interactive>`.
Being aware of this kind of behavior and how
:meth:`non_interactive context <ansys.mapdl.core.Mapdl.non_interactive>`
works is crucial for an advanced usage of PyMAPDL.
You should not retrieve any data in a Pythonic way from the MAPDL instance while using the
:meth:`non_interactive context <ansys.mapdl.core.Mapdl.non_interactive>` method.
Being aware of this kind of behavior and how the :meth:`non_interactive context <ansys.mapdl.core.Mapdl.non_interactive>` method
works is crucial for advanced usage of PyMAPDL.


MAPDL macros
------------
Note that macros created within PyMAPDL (rather than loaded from
a file) do not appear to run correctly. For example, here is the macro
``DISP`` created using the ``*CREATE`` command within APDL and within PyMAPDL:
a file) do not appear to run correctly. For example, here is the ``DISP``
macro created using the ``*CREATE`` command within APDL and within PyMAPDL:


.. tab-set::
Expand Down Expand Up @@ -522,7 +521,7 @@ Prompts
-------
Prompts from MAPDL automatically continued as if MAPDL is in batch
mode. Commands requiring user input, such as the
:func:`Mapdl.vwrite() <ansys.mapdl.core.Mapdl.vwrite>` method fail
:meth:`Mapdl.vwrite() <ansys.mapdl.core.Mapdl.vwrite>` method, fail
and must be entered in non-interactively.


Expand Down
2 changes: 1 addition & 1 deletion src/ansys/mapdl/core/parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -334,7 +334,7 @@ def __getitem__(self, key):
raise MapdlRuntimeError(
"Cannot use `mapdl.parameters` to retrieve parameters when in "
"`non_interactive` mode. "
"Exit non_interactive mode before using this method."
"Exit `non_interactive` mode before using this method."
)

if not isinstance(key, str):
Expand Down

0 comments on commit 9580b6e

Please sign in to comment.