FLUENT V6 - UDF for accessing field variables at the nodes of a face thread
It is sometimes necessary to retrieve the values of specific variables at the nodes of your mesh. This could be done by looping over cells/faces and accessing the interpolated data at the nodes.
The UDF (DEFINE_ON_DEMAND) included in this solution provides an example for accessing pressure data on the nodes of a boundary surface. Before executing the UDF, please make sure: 1. Data is available (case is initialized/ solved/ data file is read) 2. The correct boundary zone ID is provided 3. The correct field variable name is provided /***************************************************************************** * UDF to access field variable data at nodes for a face zone ****************************************************************************/ #include "udf.h" #include "dx.h" #include "mem.h" #define ID 3 /* Zone ID (in boundary condition panel) on which node data is to be obtained */ char *what = "pressure"; /* field variable name for which data is to be extracted */ /* For single phase cases, the names of the field variables can be obtained from FLUENT TUI mode. Example: /display/contours/ => this lists all the field variables that are available. */ /* For multi phase cases, the names of the field variables can be obtained from FLUENT TUI mode. Example: /display/contours/phase-x => this lists all the field variables (y) that are available. The filed variable name = "phase-x-y" => x = phase number ( 1, 2 etc.), y = variable name displayed in TUI. */ DEFINE_ON_DEMAND(my_node_values) { real x, y; int n; face_t f; Node *v; Domain *d = Get_Domain(1); Thread *t = Lookup_Thread(d, ID); FILE *fp = fopen("test_file.txt", "w"); Node_Function_Values(d, what); /* Initalize all node marks on the thread == 0 */ begin_f_loop(f, t) { f_node_loop(f, t, n) { v=F_NODE(f,t,n); NODE_MARK(v) = 0; } } end_f_loop(f, t); /* Loop over the nodes and get the data */ begin_f_loop(f, t) { f_node_loop(f, t, n) { v = F_NODE(f,t,n); x = NODE_X(v); y = NODE_Y(v); if(NODE_MARK(v) == 0) /* if not already visited */ fprintf(fp, "%gt%gt%14.8En", x , y, NODE_VALUE(v)); NODE_MARK(v) = 1; } } end_f_loop(f, t); fclose(fp); } |
||