CFD Simulation of Finocyl Grain in Solid Propellant Rocket Motor
CFD Simulation of Finocyl Grain in Solid Propellant Rocket Motor
CFD Simulation of Finocyl Grain in Solid Propellant Rocket Motor
x1, y1, z1
x2, y2, z2
...
xN, yN, zN
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.
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 quantites at the data-point are computed from the following:
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.
Note: Fluent does not guarantee the rigor of this user-defined function.
*/
#include "udf.h"
#include "surf.h"
real coords[MAXPOINTS][ND_ND];
int total_count;
#if !RP_HOST
int total_points_found;
struct interpolation_point{
#if PARALLEL
int partition;
int highest_partition;
#endif
cell_t c;
Thread* t;
boolean found;
};
/* Function Prototypes */
boolean is_point_in_cell(cell_t c, Thread* t, real* x);
#endif
DEFINE_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<MAXPOINTS; i++)
for(n=0; n<NSCALARS+ND_ND; n++)
values[i][n] = 0.0;
#if PARALLEL
for(i=0; i<(NSCALARS+ND_ND)*MAXPOINTS; i++)
work[i] = 0.0;
#endif
if(!interpolation_initialized)
{
Message0("\n\nERROR: Problem did not initialize properly.\n");
}
else
{
if (point_list[point].found
#if PARALLEL
&& (myid == point_list[point].highest_partition)
#endif
)
{
c = point_list[point].c;
t = point_list[point].t;
C_CENTROID(centroid,c,t);
/* Displacement vector */
y0 = 0.0;
NV_VV(dy, =, coords[point], -, centroid);
case 1:
NV_V(grady, =, C_U_G(c,t));
y0 = C_U(c,t);
break;
case 2:
NV_V(grady, =, C_V_G(c,t));
y0 = C_V(c,t);
break;
case 3:
NV_V(grady, =, C_W_G(c,t));
y0 = C_W(c,t);
break;
default:
break;
}
y = y0 + NV_DOT(grady, dy);
values[point][ND_ND + n] = y;
}
}
}
#if PARALLEL
PRF_GRSUM(&values[0][0], (NSCALARS+ND_ND)*MAXPOINTS, work);
#endif
#if PARALLEL
if (I_AM_NODE_ZERO_P)
#endif
{
FILE* output;
output = fopen("interp.out","a");
if (!output)
{
Message("\n\nERROR: Could not open interpolation output file.\n");
return;
}
Message0("Done.\n\n");
#endif
DEFINE_ON_DEMAND(read_points)
{
#if !RP_HOST
Domain* d = Get_Domain(1);
Thread* t;
cell_t c;
int i, point;
#endif
#if !RP_NODE
FILE* input;
int n, m;
n = 0;
while(!feof(input))
{
#if RP_DOUBLE
#if RP_3D
fscanf(input,"%lg %lg %lg\n", &coords[n][0], &coords[n][1], &coords[n][2]);
#else
fscanf(input,"%lg %lg\n", &coords[n][0], &coords[n][1]);
#endif
#else
#if RP_3D
fscanf(input,"%g %g %g\n", &coords[n][0], &coords[n][1], &coords[n][2]);
#else
fscanf(input,"%g %g\n", &coords[n][0], &coords[n][1]);
Message("%g %g\n", coords[n][0], coords[n][1]);
#endif
#endif
n++;
if (n == MAXPOINTS)
{
Message("\n\nWARNING: Number of points in input file has exceeded MAXPOINTS, which
is set to %i\n", MAXPOINTS);
Message(" Recompile UDF with MAXPOINTS >= number of data points in input file.\n");
Message(" ... only %i points will be processed...\n\n", MAXPOINTS);
break;
}
total_count = n;
fclose(input);
#endif
#if !RP_HOST
interpolation_initialized = FALSE;
total_points_found = 0;
#if PARALLEL
for(point=0; point<total_count; point++)
{
point_list[point].highest_partition = PRF_GIHIGH1(point_list[point].partition);
point_list[point].found = PRF_GIHIGH1(point_list[point].found);
}
#endif
#if PARALLEL
total_points_found = PRF_GRSUM1(total_points_found);
#endif
if (total_points_found == total_count)
{
Message0("\nAll points were successfully located.\n");
interpolation_initialized = TRUE;
}
else
{
Message0("ERROR: All points have not been located.\n");
interpolation_initialized = FALSE;
}
#if PARALLEL
interpolation_initialized = PRF_GRLOW1(interpolation_initialized);
#endif
#endif
return;
#if !RP_HOST
/* Center of cell */
C_CENTROID(cell_centroid,c,t);
/* Face normal */
F_AREA(A,f,tf);
/* Centroid on face i */
F_CENTROID(face_centroid,f,tf);
/* If n.v > 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;
#endif
/**************************************/