CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   CFX (https://www.cfd-online.com/Forums/cfx/)
-   -   old value (https://www.cfd-online.com/Forums/cfx/21956-old-value.html)

Martin Schmidt December 19, 2005 04:49

old value
 
hi, i'm new in cfx and i need your help: how can i get the value of a variable one iteration step before in a cel expression without using user fortran?

thx for your help martin

Jo Bouchard December 19, 2005 09:57

Re: old value
 
Hello Martin,

this is my first time on the site, but i think i can help you, i'm a long time user of CFX.

To use a converge variable at step 'j-1' in the computation at step 'j' is impossible (to my knowledge) to do for the solver unless you use user fortran functions. To do that you need to create dump files of the last variables values at each nodes at time step 'j-1' in a user function. Then you can acces the dump file at step 'j' also using user fortran. I have done this in the past, and it works fine altough it can be time consuming for the solver. Also, be careful if your solver works in 'parallel' mode, your fortran code cannot do I/O operations unless they are 'synchronize'. I suggest you run in 'serial' mode.

Hope this helps. Jo Bouchard

TB December 20, 2005 00:21

Re: old value
 
What variable are you referring to? You can monitor a variable at a point in the flow domain for each iteration step. Refer to user manual for CFX-Pre to see how the monitor point is defined.

Martin Schmidt December 20, 2005 12:10

Re: old value
 
hello jo, thank you for your answer. can you send me the source code of your user fortran files? i need a example because i don't understand the chapter user fortran in the manual. my knowledge about fortran is very small.

thx again martin

Martin Schmidt December 20, 2005 12:16

Re: old value
 
thx for your answer, but i need the temperature at step 'j-1' for an expression.

Jo Bouchard December 20, 2005 14:00

Re: old value
 
Hello Martin,

No problem. I have like 2000 lines of Fortran code working with the CFX solver...what I did was complicated, a lot of variable manipulations like to ones you want to do.

There is an outline of the best way to work with user functions. Use the 'main' CFX structure file (the ones starting with SUBROUTINE). Define fortran subroutines to do any extra operations on variables, so you can debug them in the fortran compiler. Join these to the main CFX function. Build the librairies ect...with cfx5kext command. I choose one of the simpler functions I did. Like you can see, i read and write files on my disc in real time with the solver, then use my subroutines to modify them or do any operation I please. Then save the new results, so you kind a control the solver. This one changes boundary conditions in fonction of time. I hope this will get you started:

#include "cfx5ext.h" dllexport(fluxdpl)

SUBROUTINE FLUXDPL (

& NLOC, NRET, NARG, RET, ARGS, CRESLT, CZ,DZ,IZ,LZ,RZ ) CC CC User routine: defines the displacement of the constant flux CC boundary conditions versus time to emulate a mouvement of the plate CC CC -------------------- CC Input CC -------------------- CC CC NLOC - size of current locale CC NRET - number of components in result CC NARG - number of arguments in call CC ARGS() - (NLOC,NARG) argument values CC CC -------------------- CC Modified CC -------------------- CC CC Stacks possibly. CC CC -------------------- CC Output CC -------------------- CC CC RET() - (NLOC,NRET) return values CC CRESLT - 'GOOD' for success CC CC -------------------- CC Details CC -------------------- CC CC Defines the boundary conditions in B Flux CC This routine evaluates the CEL function:- CC CC Fluxdpl(LENGHT,DX,x,t) CC CC================================================ ====================== C C ------------------------------ C Preprocessor includes C ------------------------------ #include "MMS.h" C C ------------------------------ C Global Parameters C ------------------------------ C C ------------------------------ C Argument list C ------------------------------ C

INTEGER NLOC,NARG,NRET C

CHARACTER CRESLT*(4) C

REAL ARGS(NLOC,NARG), RET(NLOC,NRET) C

INTEGER IZ(*)

CHARACTER CZ(*)*(1)

DOUBLE PRECISION DZ(*)

LOGICAL LZ(*)

REAL RZ(*) C C ------------------------------ C External routines C ------------------------------ C C ------------------------------ C Local Parameters C ------------------------------ C C ------------------------------ C Local Variables C ------------------------------ C

INTEGER ILOC, SCALE, MVT

REAL LENGHT, DX, CURRENT_X, FHEAVI

CHARACTER*(MXPNAM) XFILE, FTIME C C ------------------------------ C Stack pointers C ------------------------------ C C================================================= ====================== C C --------------------------- C Executable Statements C --------------------------- C C Initialise RET() to zero.

CALL SET_A_0( RET, NLOC*NRET ) C

SCALE=1000

XFILE='c:\CFX_Files\bd_conditions.txt'

FTIME='c:\CFX_Files\bdctime.txt'

LENGHT=ARGS(1,1)

DX=ARGS(1,2) C Assuming all the nodes pass are at the same time step C update the files for the time and the bd conditions

CALL STATUS_UPDATE(ARGS(1,4),FTIME,XFILE,LENGHT,DX,MXPN AM)

OPEN(unit=51,file=XFILE)

READ(51, *) MVT, CURRENT_X

CLOSE(unit=51)

DO ILOC = 1,NLOC

RET(ILOC,1) = FHEAVI((SCALE*ARGS(ILOC,3)),CURRENT_X)

END DO C C Set success flag.

CRESLT = 'GOOD' C C================================================= ======================

END CC CC

SUBROUTINE STATUS_UPDATE(TIME,FTIME,XFILE,LENGHT,DX,MXPNAM)

!Update the files for the boundary conditions

!Inputs:

!MXPNAM: maximum number of character in file names, 240

!XFILE: dump file name for the past boundary conditions

!FTIME: dump file containing simulation time

!TIME: simulation time

!LENGHT: Lenght in 'x' of the thin plate

!DX: x increment, 2*Frequency*Lenght*delta_t (a parameter in the CFX def file)

IMPLICIT NONE

INTEGER MXPNAM

CHARACTER*(MXPNAM) XFILE, FTIME

REAL TIME, DX, LENGHT C

!Locals

INTEGER MVT, NEW_MVT

REAL PAST_X, CURRENT_X, TIME_A, TIME_ADJ

CHARACTER*(MXPNAM) ITIME C

!Format 99 FORMAT(F12.3) C

!Reading the file 'XFILE'

OPEN(unit=20,file=XFILE)

READ(20, *) MVT, PAST_X C

!Reading the file 'FTIME'

OPEN(unit=21,file=FTIME)

READ(21,99) TIME_A C

!Internal file to insure CFX 'TIME' format

WRITE(ITIME,99) TIME

READ(ITIME,99) TIME_ADJ C

!Decide the comparison value for X

NEW_MVT=MVT

IF (TIME_ADJ .NE. TIME_A) THEN

!Update the time file

REWIND 21

WRITE(21,99) TIME_ADJ

!Update the X position

IF (MVT .EQ. 1) THEN

CURRENT_X=PAST_X+DX

IF (CURRENT_X .GE. LENGHT) NEW_MVT=0

ELSE

CURRENT_X=PAST_X-DX

IF (CURRENT_X .LE. 0.0) NEW_MVT=1

END IF

!Update of the 'XFILE'

PRINT *, 'Call to STATUS_UPDATE'

PRINT *, TIME_ADJ, TIME_A, TIME, NEW_MVT, CURRENT_X

REWIND 20

WRITE(20, *) NEW_MVT, CURRENT_X

END IF

CLOSE(unit=20)

CLOSE(unit=21)

END CC CC

FUNCTION FHEAVI(X,CURRENT_X)

!Computed the heaviside function controling the boundary conditions

!Input:

!X: x position for the node in progress

!CURRENT_X: x limit on the boundarie condition

IMPLICIT NONE

REAL FHEAVI, X, CURRENT_X, XR

CHARACTER*(240) IFX C 99 FORMAT(F12.3)

WRITE(IFX,99) X

READ(IFX,99) XR C

!Compute the FHEAVI value

FHEAVI=0.0

IF (XR .LE. CURRENT_X) FHEAVI=1.0

END

Jo Bouchard December 20, 2005 14:07

Re: old value
 
Sorry, the code is really not clear in this kind of window. I can send you a file if you prefer. Just put your e-mail and I can attach a file. Also, it is cfx5mkext command...

Good luck

Martin Schmidt December 20, 2005 18:50

Re: old value
 
thank you very much

my e-mail: martdojg@mailbox.tu-berlin.de

i'm now on holiday but i'll try in the new year and i'll post if it works.

i already wish you a merry christmas and a happy new year

martin


All times are GMT -4. The time now is 03:39.