How To Get Temperature On A Point (Created With Surface - Point') in A UDF
How To Get Temperature On A Point (Created With Surface - Point') in A UDF
How To Get 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.
Read cas/dat
Execute on demand (Please make sure that the correct id of the point has been specified in the 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
#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
#if RP_HOST
Message("\n Point Value on host = %f ", val);
#endif
;; 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))
)
)
)
)