Recently, I started working with UPFs. Right now I chiefly work with UPF-functions, however, I want to use UPF-subroutines soon.
With UPF-functions I manage to do the following:
- send messages to the output,
- calculate within the UPF-Fortran file, and
- return any variable value via text output.
Now I want to store the UPF-function's return value as parameter in APDL. Which APDL command does the magic?
As you can see below, I use a batch file (Code 1) to run a Mechanical APDL input file (Code 2) in batch mode. Within Code 2, user01.f (*) is set to be an UPF. For testing, I execute user01.f by issuing the command usr1. This command should be replaced by an appropriate one, storing the UPF-function's return value as parameter.I thought on something like *set,myParam,myReturn , but did not succeed up know.
Finally, a general question: Is the idea of calculating something within a function and handing over the result to APDL okay, or not acceptable at all?
(*) I copied the file to my working directory, which is available from \ANSYS Inc\v180\ansys\customize\user\user01.f (OS Windows). The code is also available in ANSYS Help Viewer (Go to (Ctrl+Shift+D) help/ans_prog/Hlp_P_UPFDEFCMD.html#c7K4r2c9lcd ).
REM set environment variables
REM https://stackoverflow.com/a/4420078
REM https://stackoverflow.com/a/11190331
set ANS_USER_PATH=%~dp0
set ANS_USE_UPF=TRUE
REM set working directory
cd /d %~dp0
REM launch MAPDL
ansys180 -b -i input.inp -o output.txt
REM set environment variable ANS_USER_UPF to FALSE
set ANS_USE_UPF=FALSE
Code 1: Batch file used to run the ANSYS input file (Code 2).
/batch /gopr ! PRINTOUT RESUMED BY /GOP *del,all ! DELETE ALL USER PARAMETERS /UCMD,STAT ! LIST OF USER COMMANDS DEFINED BY /UCMD COMMAND /upf,user01.f ! linking user programmable feature into Mechanical APDL
!
usr1 ! which command stores the return value of usr1 to a variable?
!
/EOF ! End Of File
Code 2: ANSYS input file