Open germa89 opened 2 years ago
Pinging @akaszynski @koubaa @FredAns @pmaroneh for visibility
@germa89 I definitely will miss being able to write MAPDL commands in a shell style without objects or function invocation.
Why not just go all the way and implement an MAPDL shell in python using cmdloop. I can show you how.
@koubaa I like the idea of getting rid of mapdl.
in each command. I would like to test the idea of a shell like PyMAPDL.
Even more, I guess cmdloop
could be also used with a context manager so we can have something like:
with mapdl:
n(1,1,1,1) #instead of mapdl.n
e() #instead of mapdl.e()
It think this will be quite useful too.
@germa89 actually cmdloop is more of an interactive thing that would behave more like this:
>>> from ansys.mapdl.core import launch_mapdl
>>> mapdl = launch_mapdl()
>>> mapdl.interpreter()
APDL > /prep7
/OUTPUT FILE= anstmp
*** MAPDL - ENGINEERING ANALYSIS SYSTEM RELEASE 2023 R1 23.1BETA ***
Ansys Mechanical Enterprise
00000000 VERSION=LINUX x64 07:25:41 JUN 01, 2022 CP= 10.118
** WARNING: PRE-RELEASE VERSION OF MAPDL 23.1BETA
ANSYS,INC TESTING IS NOT COMPLETE - CHECK RESULTS CAREFULLY **
***** MAPDL ANALYSIS DEFINITION (PREP7) *****
MAPDL > n,1,1,1,1
/OUTPUT FILE= anstmp
1
MAPDL > exitloop()
>>> mapdl.nlist()
/OUTPUT FILE= anstmp
LIST ALL SELECTED NODES. DSYS= 0
*** MAPDL - ENGINEERING ANALYSIS SYSTEM RELEASE 2023 R1 23.1BETA ***
Ansys Mechanical Enterprise
00000000 VERSION=LINUX x64 14:59:04 MAY 31, 2022 CP= 8.715
** WARNING: PRE-RELEASE VERSION OF MAPDL 23.1BETA
ANSYS,INC TESTING IS NOT COMPLETE - CHECK RESULTS CAREFULLY **
NODE X Y Z THXY THYZ THZX
1 1.0000 1.0000 1.0000 0.00 0.00 0.00
@germa89 Another way closer to what you suggest is to use a contextmanager to override globals during the context
with mapdl.context(globals()):
n(1,1,1,1)
where mapdl.context is a ContextManager that makes a cached copy of globals(), then adds all commands bound to itself to it. when the context manager exits, it restores the cached globals. this means any variable defined within the context would be removed upon exiting.
Do we want to be able (optionally) to create a buffer of commands and send them in one call at the end ?
@FredAns this can be done like this:
buffer = """command1
command2
command3
command4
"""
mapdl.run(buffer)
@koubaa @FredAns
You can send multiple MAPDL commands by using mapdl.input_strings.
I believe mapdl.run
will complain if you have \n
in the input.
Additionally, if you want to buffer PyMAPDL commands, and then send them all at once, you can use the non_interactive
context manager.
Pinging @akaszynski for feedback.
After seeing #1149 , I thought we could use something similar:
and maybe:
I'm not 100% convinced, so some feedback is appreciated.