You are on page 1of 3

____________________________________________________________________________________

How to get temperature on a point (created with


‘Surface->Point’) in a UDF
Problem/Description:
How do I get the temperature on a point created with ‘Surface->Point’ in a UDF?

Solution:
The following UDF and Scheme will help you retrieve the position and the cell at the UDF level from a
point created from the GUI (created with ‘Surface --> Point’ menu option). From that information you can
easily compute a 1st order interpolation of the temperature to the point.

The UDF is parallelized and works in UNIX as well as WINDOWS systems.

The procedure is as follows:


One Time action: When we open a new session of Fluent, then we need to read the surface.scm file.
This is only one time action only required when a new session of Fluent is launched.
After this is done, we can work as we do normally.

Compile the UDF and load


Read case
Create the point (You will need to specify the id of the point in the UDF before compiling)
Run the case
Execute on demand

It also works when we open a previously saved cas/dat

Read cas/dat
Execute on demand (Please make sure that the correct id of the point has been specified in the UDF)

/**************************** UDF *****************************/

#include "udf.h"
#include "dx.h"
#include "flowf.h"
#include "cxsurf.h"
#include "sg.h"

/* User input */
#define S_ID 21 /* Surface ID available in Surface>Point...>Manage panel */

DEFINE_ON_DEMAND(point_value)
{
#if !RP_HOST
Domain *domain=Get_Domain(1);
Surface *s;
CX_Cell_Id *cx_cell;
Thread *tc;
real iwork[ND_ND];
cell_t c;
int thread_id;
#endif

real X[ND_ND];
float val;
real pos[ND_ND];

#if !RP_HOST
thread_id = 0;
pos[0] = 0.0;
pos[1] = 0.0;
X[0] = 0.0;
X[1] = 0.0;
#if RP_3D
pos[2] = 0.0;
X[2] = 0.0;
#endif

val = 0.0;

s = SurfaceList + S_ID;
cx_cell = s->cells + 0;
c = RP_CELL(cx_cell);
tc = RP_THREAD(cx_cell);
if (tc != 0) /* Execute if the compute node contains the point */
{
thread_id = THREAD_ID(tc);
pos[0]=Get_Surface_Point_Coord(s->points+s->facets[1],X_DIM);
pos[1]=Get_Surface_Point_Coord(s->points+s->facets[1],Y_DIM);
#if RP_3D
pos[2]=Get_Surface_Point_Coord(s->points+s->facets[1],Z_DIM);
#endif
}

PRF_GRSUM(pos, ND_ND, iwork); /* Makes point Coordinates available at all compute nodes
*/

#endif
node_to_host_real(pos, ND_ND); /* Send the point coordinates to the host */

#if !RP_HOST

/* Pour allouer la mémoire de C_T_G */


Alloc_Storage_Vars(domain, SV_T_RG, SV_T_G, SV_NULL);
T_derivatives(domain);
Free_Storage_Vars(domain, SV_T_RG, SV_NULL);

if (tc != 0) /* Execute if the compute node contains the point */


{
tc = Lookup_Thread(domain, thread_id);
C_CENTROID(X,c,tc);
Message("\n X= %10.5e Y= %10.5e",pos[0],pos[1]);

#if RP_3D
Message(" Z=%10.5e", pos[2]);
#endif

NV_VV(pos,=,pos,-,X);
val = C_T(c,tc)+NV_DOT(C_T_G(c,tc),pos);
Free_Storage_Vars(domain, SV_T_G, SV_NULL);
Message("\n Point Value = %f Cell value %f CELL_X = %f, CELL_Y = %f", val,C_T(c,tc),
X[0], X[1]);
#if RP_3D
Message(" CELL_Z = %f", X[2]);
#endif
}
PRF_GRSUM(X, ND_ND, iwork); /* Makes cell Coordinates available at all compute nodes */
val = PRF_GRSUM1(val); /* Makes point value available at all compute nodes */
#endif

node_to_host_real_1(val); /* Send the point value to the host */

#if RP_HOST
Message("\n Point Value on host = %f ", val);
#endif

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; SCHEME ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;; Please read this scheme file whenever you open a new session of Fluent
(define max-surfaces 1000) ;; Please set this to maximum possible number of surfaces in Fluent or
some comfortable big number
;; Please insure that the surface id for which we execute the UDF, is less than this value
(define (create-my-point) ;; This function is an workaround for the problem of visiting point post
processing in GUI
(let loop ((i 0))
(if (< i max-surfaces)
(begin
(surface? i)
(loop (+ i 1))
)
)
)
)

;; The following command adds the above function in read-case function


;; So that, whenever a new case is read in Fluent, the above function is called
(cx-add-dependent 'read-case #f create-my-point)

You might also like