Re: Embedding python in ANSYS: Anyone tried it?

Discussion in 'Python' started by Satish Chimakurthi, Apr 8, 2004.

  1. 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:
    Mobile:859-420-9890
    Office: 859-257-6336 X 80691
     
    Satish Chimakurthi, Apr 8, 2004
    #1
    1. Advertising

  2. Hello,

    "Satish Chimakurthi" <> writes:

    > 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
    --
    / http://starship.python.net/crew/bhoel/
     
    Berthold Höllmann, Apr 8, 2004
    #2
    1. Advertising

  3. 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
     
    Satish Chimakurthi, Apr 8, 2004
    #3
  4. Satish Chimakurthi

    AndreasGoedecke

    Joined:
    Sep 15, 2006
    Messages:
    1
    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
     
    AndreasGoedecke, Sep 16, 2006
    #4
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alan Silver
    Replies:
    10
    Views:
    990
    Alan Silver
    Jan 2, 2006
  2. Will

    Anyone tried Fujaba?

    Will, Feb 4, 2004, in forum: Java
    Replies:
    0
    Views:
    384
  3. asanka
    Replies:
    1
    Views:
    402
    Roedy Green
    Sep 23, 2005
  4. Achim Domma

    Re: PYTHON TO ANSYS

    Achim Domma, Jul 10, 2003, in forum: Python
    Replies:
    0
    Views:
    535
    Achim Domma
    Jul 10, 2003
  5. Berthold =?iso-8859-15?q?H=F6llmann?=

    Embedding python in ANSYS: Anyone tried it?

    Berthold =?iso-8859-15?q?H=F6llmann?=, Apr 5, 2004, in forum: Python
    Replies:
    0
    Views:
    375
    Berthold =?iso-8859-15?q?H=F6llmann?=
    Apr 5, 2004
Loading...

Share This Page