日照 发表于 2008-2-27 18:18:08

在指定单元坐标加入源项的UDF的问题,麻烦各位解答

我在网上找到一个在指定单元坐标加入源项的UDF程序
有些地方看不明白,请多指教
/***************** UDF ***********************/
/*
* FLUENT User Defined Function
*
* version 4.0
*
*
* Purpose
* -------
* Marks cells that contain coordinates in the a specified input file.
*
* Author
* ------
* William Wangard, Ph.D.
* Fluent, Inc.
* Feb 2003
*
* Note: Fluent, Inc. does not guarantee the rigor of this User-defined function
*
*
* Usage
* -----
*
* Data input format
* -----------------
* The format for the UDF input file (interp-input.dat) is the following:
*
* x0, y0, z0
* x1, y1, z1
* ...
*
*
* Note, if you are using 2D, then you only enter the x- and y-coordinates.
*
*
* Execution
* ---------
* There are 2 functions in this packages: mark, source.
*
*
* Define on Demand function "mark" is used to read the data points from the inpute file
* and locate the points in the domain. Upon finding each point, a UDM is set
* to positive value in that cell.
*
* In FLUENT, you will separate the cell thread by UDM value. Then, you apply
* the Mass source to the source-contatining cell thread.
*
*
*/

#include "udf.h"
#include "surf.h"
#define MAXPOINTS 20000
#define UDM_SOURCE 0
boolean check(void);
static int np = 0;
real coordinates = {{0.}};

struct interpolation_point{
cell_t c;
Thread* t;
};
struct interpolation_point point_list;

boolean check(void)
{
boolean ret = TRUE;
if (sg_udm < 1)
{
ret = FALSE;
Message("Error: You must define at least 1 UDM\n");
}
if (!Data_Valid_P())
{
ret = FALSE;
Message("Error: You must initialize the data field\n");
}
return ret;
}

DEFINE_ON_DEMAND(mark_reset)
{
Domain*d = Get_Domain(1);
Thread*t;
cell_t c;
if (!check()) return;
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,UDM_SOURCE) = 0.0;
}
end_c_loop(c,t);
}
}
DEFINE_ON_DEMAND(mark)
{
&#35;if !RP_HOST
Domain *d = Get_Domain(1);
cell_t c;
CX_Cell_Id cx_cell;
Thread* t;
int points_found = 0, total_points_found=0;
&#35;endif
&#35;if !RP_NODE
FILE* input;
&#35;endif
int n;

/* Check for UDM */
if (!check()) return;
/* READ COORDINATES */
&#35;if !RP_NODE
/* Open input file */
if (!(input = fopen("interp-input.dat","r")))
{
Message0("\nWarning: Could not open interpolation input file...\n");
return;
}
/* Initialize */
for(n=0; n<MAXPOINTS; n++)
{
point_list.c = 0;
point_list.t = NULL;
}
/* Read points from input file */
n = -1;
while (!feof(input))
{
n++;
&#35;if RP_DOUBLE
&#35;if RP_3D
fscanf(input,"%lg %lg %lg", &coordinates, &coordinates, &coordinates)
;
&#35;else
fscanf(input,"%lg %lg", &coordinates, &coordinates);
&#35;endif
&#35;else
&#35;if RP_3D
fscanf(input,"%g %g %g", &coordinates, &coordinates, &coordinates)
;
&#35;else
fscanf(input,"%g %g", &coordinates, &coordinates);
&#35;endif
&#35;endif
}
np = n;

/* Check np with MAXPOINTS */
if (np > MAXPOINTS)
{
Message0("ERROR: You must recompile interpolate UDF with MAXPOINTS at least %i\n", np)
;
return;
}

/* Close input file */
fclose(input);

&#35;endif

/* FIND COORDINATES IN CELLS */
/* Pass coordinates and np to the compute nodes */
host_to_node_real(&coordinates,ND_ND*MAXPOINTS);
host_to_node_int_1(np);
&#35;if !RP_HOST
/* Do computations */
for(n=0;n<np;n++)
{
thread_loop_c(t,d)
{
begin_c_loop_int(c,t)
{
if (SV_is_point_in_cell(&cx_cell, c, t, coordinates))
{
point_list.c = RP_CELL(&cx_cell);
point_list.t = RP_THREAD(&cx_cell);
/* SET UDM HERE */
C_UDMI(point_list.c, point_list.t, UDM_SOURCE) = 1.0;
points_found++;
goto label;
}
}
end_c_loop_int(c,t);
}
label: continue;
}
total_points_found += points_found;
&#35;if PARALLEL
total_points_found = PRF_GISUM1(total_points_found);
&#35;endif

/* PRINT MESSAGE */
if (np != total_points_found)
Message0("\n\n Warning.... %i points found in domain out of %i points in input file\n",
total_points_found, np);
else
Message0("\n\n Interpolate... all %i points located!\n", np);
&#35;endif
}

DEFINE_SOURCE(mass_source,c,t,dS,eqn)
{
real source = 0.0;
real mdot = 1.0;
source = (C_UDMI(c,t,UDM_SOURCE) == 1.0) ? (mdot/C_VOLUME(c,t)) : 0.0;
dS = 0.0;
return source;
}

/************************ END OF UDF *****************************/
请问程序中定义的&#35;include "surf.h"头文件是干嘛的?
还有程序中用于查找坐标的部分我实在是看不懂,我急需用这方面的东西
麻烦高手们多指教。

liuguangyizju 发表于 2021-10-10 16:43:47

surf.h包含很多表面反应的宏。
页: [1]
查看完整版本: 在指定单元坐标加入源项的UDF的问题,麻烦各位解答