Continue to Site

Eng-Tips is the largest engineering community on the Internet

Intelligent Work Forums for Engineering Professionals

  • Congratulations GregLocock on being selected by the Eng-Tips community for having the most helpful posts in the forums last week. Way to Go!

Convert ANSYS.f to Fortran subroutine 1

Status
Not open for further replies.

Tecknique

Mechanical
Mar 3, 2005
5
The ansys.f (I have version 8.1) main program allows one to modify it for use as a subroutine in the user's independent Fortran code. I am trying to understand where to place the *USE command in order to call and execute a macro that will build my model. In contrast to the example subroutine given in which multiple calls were made, I will only need to call ANSYS once. Therefore, I can eliminate the DO-Loops and OPEN file statements. Correct???

Also, I have the following code for Subroutine Ansys:

subroutine ansys
#include "impcom.inc
external mainan, menusb
integer mainan
character*640 Command
nCommand = 14
Command = 'START_OF_ANSYS'
200 where = mainan(nCommand,Command)
if (where.eq.-1) goto 900

*** Should I put Command = '*USE,model.mac' here ***
*** since this is the command I want to execute??? ***

call menusb(nCommand,Command)
goto 200
900 return
end

Finally, I was a little puzzled by the presence of the # in the INCLUDE statement. #Include is a C-language command. Fortran 90 should just be INCLUDE 'filename.f' correct. Any ideas?
 
Replies continue below

Recommended for you

Well, after much heartache and finally talking with a software developer at ANSYS, I found out what is going on with the subroutine I placed in my first post on this topic. What I found out from ANSYS is that this subroutine is first preprocessed through a C compiler then sent to a Fortran compiler. I'm a little confused by this statement though. If this subroutine is preprocessed in a C compiler then what type of object file is produced??? Will it be a Fortran source file or what?? In that case, how can a C compiler produce Fortran source files instead of an object file in some type of machine (or pseudo-machine) code format? So, if someone out there has any ideas on this, please share your thoughts.

Also, I would like to share with users out there a huge lesson that I learned. At the outset of my work I was attempting to call ANSYS from Matlab 7.1. Now, Matlab allows, through the use MEX functions, one to call any external C/C++ or Fortran programs. I had the Intel 8.1 Fortran compiler which is compatible with both Matlab and ANSYS. I had intended to use Matlab's MEX capability with the ANSYS.f subroutine to automate, on an iterative basis, the running of a set of ANSYS macros. Periodically, the FE solution data would be delivered back to Matlab where it would be further post-processed by my own native Matlab code. Based on certain criterion, the necessity of further ANSYS runs would then be determined and executed. Well, this was a great idea with the exception of one crucial piece of information which was to be the source of my downfall. The capability for ANSYS to run as a subroutine works only on UNIX platforms. Apparently there are some files and some extra program restructuring that the ANSYS company would have to do in order to make this feature work on the Windows OS. This brings me to the wonderful lesson that I learned: WINDOWS SUCKS!!!!!

Fortunately, I have been able to use a "bubblegum and duct tape approach" to solving my problem. Although the lessons I learned are invaluable, I hope that this post will save someone with similar ideas a lot of time. If any UNIX OS users are out there who have used the ANSYS.f subroutine or any of the Fortran capabilities, please submit a post and let me know how well it works and what the steps are to making Fortran code and ANSYS work together.

Thanks,

Tecknique
 
The C preprocessor just filters the #ifdef statements in the fortran code according to which statements are defined via the -D flag to the preprocessor. The output of the preoprocessor is still fortran code..which is then sent through the appropriate fortran compiler to get the fortran objects. What I've done is just use the ANSCUSTOM file as template to create my own Makefiles. You can see which libraries need to be linked in with your own code such that you can use the ansys subroutines and functions. I've done this for 4 different platforms/OS types(linux,sunos,irix and osf1) and once you do it once it's fairly simple to modify things. I create one generic Makefile and then have various make.inc for the different OS types.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor