ansys / pymapdl

Pythonic interface to MAPDL
https://mapdl.docs.pyansys.com
MIT License
423 stars 120 forks source link

Return values of APDL commands #421

Closed natter1 closed 2 years ago

natter1 commented 3 years ago

For some APDL commands a return value is given in the doc-string (e.g. blc4()), for others the return value is missing (e.g. et()). I would like the doc to mention, if a useful value is returned (often its a string, where its not easy to get anything useful, e.g. mp()). On the other hand, I'm not sure, if the doc should mention any return values at all, because they are not guaranteed as far as I can see:

anum = mapdl.blc4(xcorner=0, ycorner=0, width=10, height=2)  # creates keypoints, lines, area but not nodes
print(anum)  # prints 1

with mapdl.non_interactive:
    anum = mapdl.blc4(xcorner=0, ycorner=0, width=10, height=2)  # creates keypoints, lines, area but not nodes
print(anum)  # prints None
akaszynski commented 3 years ago

Issue is partially with non_interactive. In non_interactive mode, pymapdl is effectively writing out a single input file, uploading to the server (or just writing the file locally if the server is local) and then caching the response. The nice thing about this is that you can run several commands "back to back" without chattiness with the server, so you could potentially run something like:


with mapdl.non_interactive:
    for i in range(1, 10000):
        mapdl.kp(i, i, i, i)

And it will actually run fairly quickly since each command isn't individually handled (communicated, response sent back, and handled by Python). It's a good way of switching between a testing/debug env and a production/batch environment.

Docs might need to be updated to reflect this behavior.

germa89 commented 2 years ago

As @akaszynski said, non returning the output in that case is because of the non_interactive context manager.

However I do agree we should be more explicit about the output. I would mark this as duplicated of #434 because hints would fix this. However hinting PyMAPDL is going to take a while.