Re: Embedding python in ANSYS: Anyone tried it?

  • Thread starter Satish Chimakurthi
  • Start date
S

Satish Chimakurthi

Hello Mr. Berthold,

A few months ago, I contemplated interfacing/wrapping ANSYS to Python. I looked at SWIG, BABEL, Boost.Python for this purpose at that time, only to realise that such direct wrapping is not possible since ANSYS libraries are basically Fortran based. I thought of the following work-around to the problem.

ANSYS allows users to compile their own customized version. It gives the user access to its vast libraries with the help of some UPF routines ( look at ANSYS-UPF documentation here http://www.cesup.ufrgs.br/ansys/prog_55/g-upf/UPS1.htm ). You may be knowing this. There is a file called ANSCUSTOM in "/usr/local/ansys/v71/ansys/customize/user" directory. First, I wrote a "Makefile" and a "make.inc" file based on the information in ANSCUSTOM. I then wrote a Fortran code in which I used all the UPF routines I needed to be used with ANSYS. I compiled the Fortran code with "make.inc" simultaneously to get a binary executable. And that's it, I was ready to go. The binary executable could be executed using a specific command which could be found in ANSYS Installation and Configuration manual, I think. In my case, I was using ANSYS 7.1, so, I had to execute it as: "anscust71 -custom ./executable -p ANSYSRF".

Now, with all that I described above, link between Fortran and ANSYS has become possible. You can look at F2PY (Fortran to Python Interface Generator) here http://cens.ioc.ee/projects/f2py2e/ to have an interface between your Python script and Fortran code that you would be writing for the purpose. At the moment, my Python-Fortran interface is very loose. I use Fortran to ANSYS mostly and do postprocessing work in Python.

Please let me know if you think of any other ideas about wrapping Python and ANSYS directly. I would appreciate your assistance.




Thanks

Best Regards,
Satish Kumar Chimakurthi



SATISH KUMAR CHIMAKURTHI
Graduate Research Assistant
CFD GROUP
Mechanical Engineering
UNIVERSITY OF KENTUCKY
Lexington
KENTUCKY - 40508
U.S.A

Email: (e-mail address removed)
Mobile:859-420-9890
Office: 859-257-6336 X 80691
 
B

Berthold Höllmann

Hello,

Satish Chimakurthi said:
Hello Mr. Berthold,

A few months ago, I contemplated interfacing/wrapping ANSYS to
Python. I looked at SWIG, BABEL, Boost.Python for this purpose at
that time, only to realise that such direct wrapping is not possible
since ANSYS libraries are basically Fortran based. I thought of the
following work-around to the problem.

ANSYS allows users to compile their own customized version. It gives
the user access to its vast libraries with the help of some UPF
routines ( look at ANSYS-UPF documentation here
http://www.cesup.ufrgs.br/ansys/prog_55/g-upf/UPS1.htm ). You may be
knowing this. There is a file called ANSCUSTOM in
"/usr/local/ansys/v71/ansys/customize/user" directory. First, I
wrote a "Makefile" and a "make.inc" file based on the information in
ANSCUSTOM. I then wrote a Fortran code in which I used all the UPF
routines I needed to be used with ANSYS. I compiled the Fortran code
with "make.inc" simultaneously to get a binary executable. And
that's it, I was ready to go. The binary executable could be
executed using a specific command which could be found in ANSYS
Installation and Configuration manual, I think. In my case, I was
using ANSYS 7.1, so, I had to execute it as: "anscust71 -custom
./executable -p ANSYSRF".

Now, with all that I described above, link between Fortran and ANSYS
has become possible. You can look at F2PY (Fortran to Python
Interface Generator) here http://cens.ioc.ee/projects/f2py2e/ to
have an interface between your Python script and Fortran code that
you would be writing for the purpose. At the moment, my
Python-Fortran interface is very loose. I use Fortran to ANSYS
mostly and do postprocessing work in Python.

This is what I am thinking about. Our final aim is to wrap as much
functionality of ANSYS to be abble to pre- and postprocess our
calculations with the help of Python modules. I have basic knowledge
about writing UPF in ANSYS and some experience in writing Python
extension modules. I now started wrapping ANSYS UPF routines using
f2py and am already able to call some basic python examples from
ANSYS. I mainly asked because wrapping a sufficiant amout of the ANSYS
interface routines is a lot of stupid typing work, and if sombody else
did it before, it would be nice to share the work :)

I won't link my own ANSYS executable, but save time, space and efforts
by building a dynamic load shared library for ansys which is available
since about ANSYS 6.0 or 6.1. I will do my work using ANSYS 8.1.
Please let me know if you think of any other ideas about wrapping
Python and ANSYS directly. I would appreciate your assistance.

A nice thing to try when the basics run is to provide a python
interface for generating user elements etc. in Python. But I'm afraid
that would require some naugthy magic, is error prone and too much for
the first step.

Kind regards
Berthold Höllmann
 
S

Satish Chimakurthi

Hello Mr.Bernard,
I now started wrapping ANSYS UPF routines using
f2py and am already able to call some basic python examples from
ANSYS. I mainly asked because wrapping a sufficiant amout of the ANSYS
interface routines is a lot of stupid typing work, and if sombody else
did it before, it would be nice to share the work :)

If you have a ready example about how exactly F2PY was used with a
particular UPF routine like "dspget" say, would you mind to send that to me.
I would like to see how it works from Python.
So, with your interface, you are able to invoke Python scripts from ANSYS or
is it the other way round ? Would you please let me know in more detail ?


Best Regards,
Satish
 
Joined
Sep 15, 2006
Messages
1
Reaction score
0
Hi Everyone!

When it comes to "wrapping" Ansys in Python, our experiences using the official Workbench ActiveX controls were very good. Using Windows extensions for Python 2.4, we do something like

import win32com
wb=win32com.client.Dispatch("AnsysWB.WB.100")
wb.SplashScreen.NeedToShow = False
wb.StartApplet="AAOApplet"
wb.Run()
wb.Title="Siemens Corporate Technology PS 8 - Ansys"
sh=wb.AppletList.Applet("AAOApplet").App.Script # scripting host
sh.ans_sendcommand("keyw,pr_gsvof,1")
sh.ans_sendcommand("/nerr,0")


If you do that, an Ansys (Classic!) windows starts up, you can now inject APDL commands with sh.ans_sendcommand() and sh.ans_getvalue().

Of course, we still have to wrap all the commands (similar to what ANSYS did in the ansysCommandMod.js file for their JPDL implementation, see in AISOL/SDK/samples/JPDL directory). But we can do it in Python, without a C compiler.

Of course, nifty things like implementing user elements in Python is not possible using this approach, just the normal APDL stuff.

All the best
Andreas
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,230
Members
46,819
Latest member
masterdaster

Latest Threads

Top