# Scalar interpolation

 This UDF replaces Solution 586, which was found to have problems in parallel.Interpolate p, u, v, and w to point data specified in input file. File format is as followsx1, y1, z1x2, y2, z2...xN, yN, zNIn 2D, no z-coordinate is specified.The UDF reads line separated data in an input file and interpolates the scalar values of p, u, v, and w to the locationsspecified by the coordinates.First the cell containing the coordinate is located. Then the scalar value at the cell center, y0, is obtained from the solver. Then the gradient of the scalar is gotten. Then by the follwing formula:y = y0 + dx . Grad(y),we obtain the value of the scalar at the coordinate. In this formula dx is the vector from the cell centroid to the coordinate.The UDF follows:/**************************************//* UDF To interpolat P, U, V, and W, using linear extrapolation. Data points are specified in (x,y) or (x,y,z), line-separated format in an input file default-named "input". This file is read, and the cells containing each point are identified. If a point is not found, an error is produced and no results can be generated. The scalar quantities at the data-point-containing cell-center are obtained from the solver. The scalar quantites at the data-point are computed from the following: y = y0 + Grad(y) DOT dx, where dx is the displacement from the cell center to the data point and Grad(y) is the gradient of the scalar at the cell center, which is obtained from the solver. NOTE: You must type "solve set expert" int the FLUENT TUI, and answer "yes" to the question about whether memory should not be freed. The UDF consists of two EOD functions: read_points: reads the data file and finds the cells containig the points. Determines if points cannot be located. interpolate: computes the value of the scalar using the above formulae for all scalars (p,u,v,w) Data are written to a file in the following format POINT X Y [Z] P U V [W] AUTHOR: William Wangard, Ph.D. EMAIL: ww@fluent.com Note: Fluent does not guarantee the rigor of this user-defined function. Last Modified on June 3, 2003*/#include "udf.h"#include "surf.h"#define MAXPOINTS 2000#define NSCALARS (1+ND_ND)real coords[MAXPOINTS][ND_ND];int total_count;#if !RP_HOSTint total_points_found;struct interpolation_point{#if PARALLEL int partition; int highest_partition;#endif cell_t c; Thread* t; boolean found;};struct interpolation_point point_list[MAXPOINTS];boolean interpolation_initialized;/* Function Prototypes */boolean is_point_in_cell(cell_t c, Thread* t, real* x);#endifDEFINE_ON_DEMAND(interpolate){#if !RP_HOST Thread* t; cell_t c; real NV_VEC(dy), NV_VEC(grady), NV_VEC(centroid); real y0, y; int point, i, n; real values[MAXPOINTS][NSCALARS+ND_ND];#if PARALLEL real work[(NSCALARS+ND_ND)*MAXPOINTS];#endif /* Initialize values */ for(i=0; i= number of data points in input file.n"); Message(" ... only %i points will be processed...nn", MAXPOINTS); break; } } total_count = n; Message("nnThere are %i sets of coordinates read from input file.n",total_count); fclose(input);#endif /* Initialize coordinates on COMPUTE NODES */ host_to_node_int_1(total_count); host_to_node_real(&coords,ND_ND*MAXPOINTS);#if !RP_HOST interpolation_initialized = FALSE; for(point=0; point 0, then point is beyond "plane" that defines the face and it cannot be inside the cell */ if (NV_DOT(n,v) > 0.0) return FALSE; } /* Otherwise it must be in the cell */ return TRUE;}#endif/**************************************/

 No comments yet. Be the first to add a comment!