CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   CFX (https://www.cfd-online.com/Forums/cfx/)
-   -   Coupling a fortran file with CFX (https://www.cfd-online.com/Forums/cfx/161535-coupling-fortran-file-cfx.html)

mahdiaghaie2003@gmail.com October 24, 2015 03:18

Coupling a fortran file with CFX
 
Dear friends
I have time dependent first order differntial equation, solved by runge kutta method in a fortran file. The out put of the calculation is power for a heated pipe. Now how i can compile or execute the fortran file with the simulated pipe in cfx for a transient case? I do not have any experience for this type of coupling.
Thanks

ghorrocks October 24, 2015 05:22

If the fortran calculation is not coupled to the CFD it is very easy - just put the output into a 1D interpolation function.

If the fortran is coupled to the CFD you will need to put the fortran (or a link to it) in a user fortran routine.

mahdiaghaie2003@gmail.com October 24, 2015 05:52

Regarding to problem physics, it is impossible to run fortran and cfx in decoupled format (the fortran file needs some parameters of fluid domain like density and velicity during run. The code gives feedbacks from fluid domain and then calculates power for cfx). Now how i can couple my code with cfx. Please explain the procedure step by step.

ghorrocks October 24, 2015 05:56

My last post described what is required for a coupled fortran routine. There are some examples of how to do this in the CFX documentation. I do not have time to write a step by step guide, especially as one already exists.

mahdiaghaie2003@gmail.com October 24, 2015 06:29

Thanks a lot for answer. How i can have this document ?Please if possible send it for me.

Antanas October 24, 2015 08:31

Quote:

Originally Posted by mahdiaghaie2003@gmail.com (Post 570029)
Thanks a lot for answer. How i can have this document ?Please if possible send it for me.

If you have CFX, then you have help files.

tandem November 17, 2015 20:00

1. You read carefully the part 18.2.1 in CFX of Help CFX. You will know the location to get your Junction Box Routine or User Function.
2. Write Junction Box Routine or User Function to caculate coupling
3. Note that, you have to compile your Junction Box Routine or User Function by "cfx5mkext -64bit name's Junction Box Routine or User Function"
4. Read examples of part 18.8 in CFX of Help CFX

CFXNewbie November 26, 2015 07:28

Thank you for your answers so far!

I have a very similar problem. I have read chapter 18: User Fortran, but I still have no idea how to compile the code. Do I need just a standard Fortran 77 compiler here? As a simple example, I wanted to test this user routine:

#include "cfx5ext.h"
dllexport(test)
SUBROUTINE TEST (NLOC,NRET,NARG,RET,ARGS,CRESLT,CZ,DZ,IZ,LZ,RZ)
C
INTEGER NLOC,NARG,NRET
CHARACTER CRESLT*(*)
REAL ARGS(NLOC,NARG), RET(NLOC,NRET)
C
INTEGER IZ(*)
CHARACTER CZ(*)*(1)
DOUBLE PRECISION DZ(*)
LOGICAL LZ(*)
REAL RZ(*)
C

RET = 2000*ARGS(1,1)

END


Using a Fortran 77 or Fortran 90 compiler produces errors. What do I have to do?

Thanks a lot!

Opaque November 26, 2015 11:24

RET is an array of size NLOC x NRET; therefore, should you not fill in NLOC x NRET entries instead of

RET = 2000 * ARGS(1,1)

For example,

DO IRET = 1,NRET
DO ILOC = 1, NLOC
RET(ILOC,IRET) = 2000 * ARGS(1,1)
ENDDO
ENDDO

Also, you did not say what error has been detected by the compiler..

CFXNewbie November 30, 2015 12:34

1 Attachment(s)
Thank you for your help!
I've tried

#include "cfx5ext.h"
dllexport(reibmodell)
SUBROUTINE REIBMODELL (NLOC,NRET,NARG,RET,ARGS,CRESLT,CZ,DZ,IZ,LZ,RZ)
C
INTEGER NLOC,NARG,NRET
CHARACTER CRESLT*(*)
REAL ARGS(NLOC,NARG), RET(NLOC,NRET)
C
INTEGER IZ(*)
CHARACTER CZ(*)*(1)
DOUBLE PRECISION DZ(*)
LOGICAL LZ(*)
REAL RZ(*)
C

DO IRET = 1,NRET
DO ILOC = 1, NLOC
RET(ILOC,IRET) = 2000 * ARGS(1,1)
ENDDO
ENDDO


END

Thanks a lot! :)

Opaque November 30, 2015 14:23

It would be good to see your compilation line.

It seems the preprocessing directive # are not being used, that is the compile line did not include cpp, or fpp support.

CFXNewbie December 1, 2015 04:39

I think so, too.

Does #include "cfx5ext.h" only work, when Ansys CFX is installed on the system? Because on this machine I don't have Ansys. On the computer, on which I can use Ansys I can compile only Fortran 90 code.

On the attached image you can see the complete Force 3.0 screen with source code, errors....

Thank you!!

CFXNewbie December 13, 2015 07:39

Think I finally got it, thanks!


All times are GMT -4. The time now is 19:36.