Ansys Learning Forum › Forums › Discuss Simulation › Fluids › Problem with C_YI(c,t,i) › Reply To: Problem with C_YI(c,t,i)
October 27, 2021 at 4:40 pm
isaps1860
Subscriber
#include "udf.h"
#include
#include
DEFINE_SOURCE(source, c, t, dS, eqn)
{
Thread *tm=THREAD_SUPER_THREAD(t);
Thread **pt = THREAD_SUB_THREADS(tm);
Thread *tp = pt[0];
Thread *ts = pt[1];
Thread *sec;
real source;
int i;
typedef struct
{
double xCoordinate;
double yCoordinate;
double zCoordinate;
} Point;
int data[100];
int number_of_points = 25;
Point points[25];
int main();
{
Point test;
Point test2 ={1, 2, 3};
test.xCoordinate = 1;
points[0].xCoordinate = 0; points[0].yCoordinate = 0; points[0].zCoordinate = 0.0978;
points[1].xCoordinate = 0; points[1].yCoordinate = 0.10; points[1].zCoordinate = 0.068;
points[2].xCoordinate = 0; points[2].yCoordinate = 0.20; points[2].zCoordinate = 0.0532;
points[3].xCoordinate = 0; points[3].yCoordinate = 0.30; points[3].zCoordinate = 0.0132;
points[4].xCoordinate = 0; points[4].yCoordinate = 0.40; points[4].zCoordinate = 0.0324;
points[5].xCoordinate = 0.5; points[5].yCoordinate = 0; points[5].zCoordinate = 0.0244;
points[6].xCoordinate = 0.5; points[6].yCoordinate = 0.10; points[6].zCoordinate = 0.0166;
points[7].xCoordinate = 0.5; points[7].yCoordinate = 0.20; points[7].zCoordinate = 0.011;
points[8].xCoordinate = 0.5; points[8].yCoordinate = 0.30; points[8].zCoordinate = 0.05;
points[9].xCoordinate = 0.5; points[9].yCoordinate = 0.40; points[9].zCoordinate = 0.0092;
points[10].xCoordinate = 1; points[10].yCoordinate = 0; points[10].zCoordinate = 0.0264;
points[11].xCoordinate = 1; points[11].yCoordinate = 0.10; points[11].zCoordinate = 0.0148;
points[12].xCoordinate = 1; points[12].yCoordinate = 0.20; points[12].zCoordinate = 0.011;
points[13].xCoordinate = 1; points[13].yCoordinate = 0.30; points[13].zCoordinate = 0.0116;
points[14].xCoordinate = 1; points[14].yCoordinate = 0.40; points[14].zCoordinate = 0.0444;
points[15].xCoordinate = 1.5; points[15].yCoordinate = 0; points[15].zCoordinate = 0.0256;
points[16].xCoordinate = 1.5; points[16].yCoordinate = 0.10; points[16].zCoordinate = 0.0132;
points[17].xCoordinate = 1.5; points[17].yCoordinate = 0.20; points[17].zCoordinate = 0.0094;
points[18].xCoordinate = 1.5; points[18].yCoordinate = 0.30; points[18].zCoordinate = 0.0092;
points[19].xCoordinate = 1.5; points[19].yCoordinate = 0.40; points[19].zCoordinate = 0.258;
points[20].xCoordinate = 2; points[20].yCoordinate = 0; points[20].zCoordinate = 0.027;
points[21].xCoordinate = 2; points[21].yCoordinate = 0.10; points[21].zCoordinate = 0.014;
points[22].xCoordinate = 2; points[22].yCoordinate = 0.20; points[22].zCoordinate = 0.0106;
points[23].xCoordinate = 2; points[23].yCoordinate = 0.30; points[23].zCoordinate = 0.0122;
points[24].xCoordinate = 2; points[24].yCoordinate = 0.40; points[24].zCoordinate = 0.5102;
real xInput = C_U(c,tp);
real yInput = C_YI(c,ts,i);
printf("x = %.3f, y = %.3f", xInput, yInput);
Point neighbors[4];
neighbors[0] = points[0];
neighbors[1] = points[0];
neighbors[2] = points[0];
neighbors[3] = points[0];
for (int g = 0; g < number_of_points; g++)
{
Point currentPoint = points[g];
if (currentPoint.xCoordinate == floor(xInput))
{
if (currentPoint.yCoordinate == floor(yInput))
{
neighbors[0] = currentPoint;
}
if (currentPoint.yCoordinate == ceil(yInput))
{
neighbors[1] = currentPoint;
}
}
if (currentPoint.xCoordinate == ceil(xInput))
{
if (currentPoint.yCoordinate == floor(yInput))
{
neighbors[2] = currentPoint;
}
if (currentPoint.yCoordinate == ceil(yInput))
{
neighbors[3] = currentPoint;
}
}
if (currentPoint.xCoordinate <= xInput)
{
if (currentPoint.yCoordinate <= yInput)
{
if (xInput - currentPoint.xCoordinate <= xInput - neighbors[0].xCoordinate)
{
if (yInput - currentPoint.yCoordinate <= yInput - neighbors[0].yCoordinate)
{
neighbors[0] = currentPoint;
}
}
}
}
if (currentPoint.xCoordinate >= xInput)
{
if (currentPoint.yCoordinate <= yInput)
{
if (neighbors[2].xCoordinate < xInput)
{
neighbors[2] = currentPoint;
}
if ((currentPoint.xCoordinate - xInput <= neighbors[2].xCoordinate - xInput))
{
if (yInput - currentPoint.yCoordinate <= yInput - neighbors[2].yCoordinate)
{
neighbors[2] = currentPoint;
}
}
}
}
if (currentPoint.xCoordinate <= xInput)
{
if (currentPoint.yCoordinate >= yInput)
{
if ((xInput - currentPoint.xCoordinate <= xInput - neighbors[1].xCoordinate))
{
if (neighbors[1].yCoordinate < yInput)
{
neighbors[1] = currentPoint;
}
if (currentPoint.yCoordinate - yInput <= neighbors[1].yCoordinate - yInput )
{
neighbors[1] = currentPoint;
}
}
}
}
if (currentPoint.xCoordinate >= xInput)
{
if (currentPoint.yCoordinate >= yInput)
{
if (neighbors[3].xCoordinate < xInput)
{
neighbors[3] = currentPoint;
}
if ((currentPoint.xCoordinate - xInput <= neighbors[3].xCoordinate - xInput))
{
if (neighbors[3].yCoordinate < yInput)
{
neighbors[3] = currentPoint;
}
if ( currentPoint.yCoordinate - yInput <= neighbors[3].yCoordinate - yInput)
{
neighbors[3] = currentPoint;
}
}
}
}
}
double leftVertex = neighbors[0].zCoordinate + (neighbors[1].zCoordinate - neighbors[0].zCoordinate) / (neighbors[1].yCoordinate - neighbors[0].yCoordinate) * (yInput - neighbors[0].yCoordinate);
double rightVertex = neighbors[2].zCoordinate + (neighbors[3].zCoordinate - neighbors[2].zCoordinate) / (neighbors[3].yCoordinate - neighbors[2].yCoordinate) * (yInput - neighbors[2].yCoordinate);
double result = leftVertex + (rightVertex - leftVertex) / (neighbors[2].xCoordinate - neighbors[0].xCoordinate) * (xInput - neighbors[0].xCoordinate);
printf("result : %f\n", result);
source = result;
dS[eqn] = 0;
return source;
}
}
#include
#include
DEFINE_SOURCE(source, c, t, dS, eqn)
{
Thread *tm=THREAD_SUPER_THREAD(t);
Thread **pt = THREAD_SUB_THREADS(tm);
Thread *tp = pt[0];
Thread *ts = pt[1];
Thread *sec;
real source;
int i;
typedef struct
{
double xCoordinate;
double yCoordinate;
double zCoordinate;
} Point;
int data[100];
int number_of_points = 25;
Point points[25];
int main();
{
Point test;
Point test2 ={1, 2, 3};
test.xCoordinate = 1;
points[0].xCoordinate = 0; points[0].yCoordinate = 0; points[0].zCoordinate = 0.0978;
points[1].xCoordinate = 0; points[1].yCoordinate = 0.10; points[1].zCoordinate = 0.068;
points[2].xCoordinate = 0; points[2].yCoordinate = 0.20; points[2].zCoordinate = 0.0532;
points[3].xCoordinate = 0; points[3].yCoordinate = 0.30; points[3].zCoordinate = 0.0132;
points[4].xCoordinate = 0; points[4].yCoordinate = 0.40; points[4].zCoordinate = 0.0324;
points[5].xCoordinate = 0.5; points[5].yCoordinate = 0; points[5].zCoordinate = 0.0244;
points[6].xCoordinate = 0.5; points[6].yCoordinate = 0.10; points[6].zCoordinate = 0.0166;
points[7].xCoordinate = 0.5; points[7].yCoordinate = 0.20; points[7].zCoordinate = 0.011;
points[8].xCoordinate = 0.5; points[8].yCoordinate = 0.30; points[8].zCoordinate = 0.05;
points[9].xCoordinate = 0.5; points[9].yCoordinate = 0.40; points[9].zCoordinate = 0.0092;
points[10].xCoordinate = 1; points[10].yCoordinate = 0; points[10].zCoordinate = 0.0264;
points[11].xCoordinate = 1; points[11].yCoordinate = 0.10; points[11].zCoordinate = 0.0148;
points[12].xCoordinate = 1; points[12].yCoordinate = 0.20; points[12].zCoordinate = 0.011;
points[13].xCoordinate = 1; points[13].yCoordinate = 0.30; points[13].zCoordinate = 0.0116;
points[14].xCoordinate = 1; points[14].yCoordinate = 0.40; points[14].zCoordinate = 0.0444;
points[15].xCoordinate = 1.5; points[15].yCoordinate = 0; points[15].zCoordinate = 0.0256;
points[16].xCoordinate = 1.5; points[16].yCoordinate = 0.10; points[16].zCoordinate = 0.0132;
points[17].xCoordinate = 1.5; points[17].yCoordinate = 0.20; points[17].zCoordinate = 0.0094;
points[18].xCoordinate = 1.5; points[18].yCoordinate = 0.30; points[18].zCoordinate = 0.0092;
points[19].xCoordinate = 1.5; points[19].yCoordinate = 0.40; points[19].zCoordinate = 0.258;
points[20].xCoordinate = 2; points[20].yCoordinate = 0; points[20].zCoordinate = 0.027;
points[21].xCoordinate = 2; points[21].yCoordinate = 0.10; points[21].zCoordinate = 0.014;
points[22].xCoordinate = 2; points[22].yCoordinate = 0.20; points[22].zCoordinate = 0.0106;
points[23].xCoordinate = 2; points[23].yCoordinate = 0.30; points[23].zCoordinate = 0.0122;
points[24].xCoordinate = 2; points[24].yCoordinate = 0.40; points[24].zCoordinate = 0.5102;
real xInput = C_U(c,tp);
real yInput = C_YI(c,ts,i);
printf("x = %.3f, y = %.3f", xInput, yInput);
Point neighbors[4];
neighbors[0] = points[0];
neighbors[1] = points[0];
neighbors[2] = points[0];
neighbors[3] = points[0];
for (int g = 0; g < number_of_points; g++)
{
Point currentPoint = points[g];
if (currentPoint.xCoordinate == floor(xInput))
{
if (currentPoint.yCoordinate == floor(yInput))
{
neighbors[0] = currentPoint;
}
if (currentPoint.yCoordinate == ceil(yInput))
{
neighbors[1] = currentPoint;
}
}
if (currentPoint.xCoordinate == ceil(xInput))
{
if (currentPoint.yCoordinate == floor(yInput))
{
neighbors[2] = currentPoint;
}
if (currentPoint.yCoordinate == ceil(yInput))
{
neighbors[3] = currentPoint;
}
}
if (currentPoint.xCoordinate <= xInput)
{
if (currentPoint.yCoordinate <= yInput)
{
if (xInput - currentPoint.xCoordinate <= xInput - neighbors[0].xCoordinate)
{
if (yInput - currentPoint.yCoordinate <= yInput - neighbors[0].yCoordinate)
{
neighbors[0] = currentPoint;
}
}
}
}
if (currentPoint.xCoordinate >= xInput)
{
if (currentPoint.yCoordinate <= yInput)
{
if (neighbors[2].xCoordinate < xInput)
{
neighbors[2] = currentPoint;
}
if ((currentPoint.xCoordinate - xInput <= neighbors[2].xCoordinate - xInput))
{
if (yInput - currentPoint.yCoordinate <= yInput - neighbors[2].yCoordinate)
{
neighbors[2] = currentPoint;
}
}
}
}
if (currentPoint.xCoordinate <= xInput)
{
if (currentPoint.yCoordinate >= yInput)
{
if ((xInput - currentPoint.xCoordinate <= xInput - neighbors[1].xCoordinate))
{
if (neighbors[1].yCoordinate < yInput)
{
neighbors[1] = currentPoint;
}
if (currentPoint.yCoordinate - yInput <= neighbors[1].yCoordinate - yInput )
{
neighbors[1] = currentPoint;
}
}
}
}
if (currentPoint.xCoordinate >= xInput)
{
if (currentPoint.yCoordinate >= yInput)
{
if (neighbors[3].xCoordinate < xInput)
{
neighbors[3] = currentPoint;
}
if ((currentPoint.xCoordinate - xInput <= neighbors[3].xCoordinate - xInput))
{
if (neighbors[3].yCoordinate < yInput)
{
neighbors[3] = currentPoint;
}
if ( currentPoint.yCoordinate - yInput <= neighbors[3].yCoordinate - yInput)
{
neighbors[3] = currentPoint;
}
}
}
}
}
double leftVertex = neighbors[0].zCoordinate + (neighbors[1].zCoordinate - neighbors[0].zCoordinate) / (neighbors[1].yCoordinate - neighbors[0].yCoordinate) * (yInput - neighbors[0].yCoordinate);
double rightVertex = neighbors[2].zCoordinate + (neighbors[3].zCoordinate - neighbors[2].zCoordinate) / (neighbors[3].yCoordinate - neighbors[2].yCoordinate) * (yInput - neighbors[2].yCoordinate);
double result = leftVertex + (rightVertex - leftVertex) / (neighbors[2].xCoordinate - neighbors[0].xCoordinate) * (xInput - neighbors[0].xCoordinate);
printf("result : %f\n", result);
source = result;
dS[eqn] = 0;
return source;
}
}