ansys / pymapdl

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

Generating/writing an APDL input file #1357

Closed mcMunich closed 2 years ago

mcMunich commented 2 years ago

Description of the feature

I assume that the pymapdl somewhere in the background creates a .inp file to feed into the ansys apdl exe. Would it be possible to be able to access /write that that .inp to file? This would allow users to double check pymadpl method by running the .inp in Ansys classic.

Steps for implementing the feature

Divert to write instead of solve (add an argument to the solve command?) This is almost the opposite of the scripts used to read APDL scripts and convert to pymapdl inputs. The reason is to be able to double check pymapdl and also to be able to generate shareable .inp files that other non py users could run with their APDL instances.

Useful links and references

No response

akaszynski commented 2 years ago

Hi @mcMunich,

I assume that the pymapdl somewhere in the background creates a .inp file to feed into the ansys apdl exe.

We're doing something close to that. PyMAPDL talks to the MAPDL process via gRPC (think of it as a connection over the network, even if local) and sends either individual commands, series of commands, or entire blobs of data (when plotting, getting the mesh, etc).

Would it be possible to be able to access /write that that .inp to file? This would allow users to double check pymadpl method by running the .inp in Ansys classic.

That's been a request in the past and we implemented it with log_apdl=True within launch_mapdl. See: APDL Command Logging

Here's the docs if you don't want to go to the link:

APDL Command Logging

While ansys-mapdl-core is designed to make it easier to control an APDL session by calling it using Python, it may be necessary to call MAPDL again using an input file generated from a PyMAPDL script. This is automatically enabled with the log_apdl='apdl.log' parameter. Enabling this parameter will cause Mapdl to write each command run into a log file named "apdl.log" in the active Mapdl.directory. For example:

from ansys.mapdl.core import launch_mapdl

ansys = launch_mapdl(log_apdl='apdl.log')
ansys.prep7()
ansys.k(1, 0, 0, 0)
ansys.k(2, 1, 0, 0)
ansys.k(3, 1, 1, 0)
ansys.k(4, 0, 1, 0)

Will write the following to "apdl.log"

/PREP7,
K,1,0,0,0
K,2,1,0,0
K,3,1,1,0
K,4,0,1,0

This allows for the translation of a Python script to an APDL script except for conditional statements, loops, or functions.

mikerife commented 2 years ago

Hi @mcMunich I'd like to add that the lgwrite command is still available just in case the log_apdl flag was not set. There is a lot more commands written due to how the MAPDL aaS instance is accessed but most text editors can be used to find/delete the non-needed commands. Mainly a lot of /out and /out,anstmp commands. Also if you want to spot check the model there is always the open_gui() option.

Mike

akaszynski commented 2 years ago

Thanks @mikerife. I think this is a better solution because this is more likely to actually replicate what's happening within MAPDL rather than what's just being sent from the client side.

I'm leaving this open to have @germa89 investigate some additional post-processing to cleanup the output from lgwrite and just removing /out/ and /out,anstmp when in server mode. Should be an easy cleanup, and we need to check if lgwrite works when the server is remote on docker.