I want to apply heat on a tube surface (3D). The heat is to be applied on a straight line on the tube. The equation of line is
x= 87.5
y = 126.1620 + (-1*1004.0820)
z= 166.1620 + (-1*-1004.0880)

Since x is constant is given asposition holder, real x[ND_ND];
For this constant value of x, heat is appiled on the line with the equation above. (If y and z are satisfied.
I have created my code below and when I try to interprete it, there is an error report:
Error line 16: invalid type for &&: float && float.
This is the line 16
((y = 126.1620 + (-1*1004.0820)) && (z= 166.1620 + (-1*
-1004.0880)));
How do I correct the error?

#include "udf.h"

/* profile for heat flux*/
DEFINE_PROFILE(heatflux_profile, t, i)
{
/* declaring variables */
real x[ND_ND];   /* this will hold the position vector */
real y;
real z;
face_t f;

begin_f_loop(f, t)
{
F_CENTROID(x, f,t);
if
((y = 126.1620 + (-1*1004.0820)) && (z= 166.1620 + (-1*
-1004.0880)));
F_PROFILE(f, t, i) =500;
else
F_PROFILE(f,t,i)=350;
}
end_f_loop(f, t)
}
4
Contributors
14
Replies
15
Views
8 Years
Discussion Span
Last Post by tendolm

Is this supposed to be C++ or is it some other language?

You do not want the semicolon at the end of the parenthesized portion of the if statement.

Other than that, it seems weird to be assigning y and z a constant value and then testing whether or not either are zero, which is what your code is doing.

Your "line equation" is wrong -- you have defined a point.

Perhaps you intended a test for equality (==), rather than assigment (=). And why the unnecessarily confusing multiplication by -1 in the first expression and double negative in the second?
This seems to make more sense:

if( (y == 126.1620 -1004.0820) && (z == 166.1620 + 1004.0880) ) {
F_PROFILE(f, t, i) =500;
else
F_PROFILE(f,t,i)=350;
}

But begin_f_loop(f, t) and end_f_loop(f, t) don't look like any kind of C/C++ syntax I've ever seen. What is that supposed to be doing? How is it a loop?

This code is developed in C++ and used in a computational fluid dynamics model (CFD), Fluent, and these other fetures are part of Fluent. If I get correct the part of stating my if condition then everything else will work.
If I do not use the if condition and apply only heat to the surface decribed by my line equation. I am able to interprete the code into Fluent. I have writen it as

begin_f_loop(f, t)
{
F_CENTROID(x, f,t);

y = 126.1620 + (-1*1004.0820);
z= 166.1620 + (-1*-1004.0880);
F_PROFILE(f, t, i) =500;

}
end_f_loop(f, t)
}

The oter part is teh same as the previous code. In C++ how do I set the condition if y and z are met.

How do I define a line in 3D

Please assist me form the equation of line. The staring point is (87.5, 126.162, 166.162) and the end point is (87.5, 877.97, 1170.25)

My equation of line is
x=87.5
y= 126.162-(1004.082)t
z=166.162-(-1004.088)t
and 0<=t<=1.
(0 is less or equal to t but t is less or equal to 1)

I want to develop a code that applies one value of heat on this line on a tube and another value on other parts of the tube
This code will then be intepreted in Fluent (computational fluid dynamics package) and used for numerical simulation of temperature change in the tube as a result of applied heat.
Please just assist develop this code in C ignoring parts involving Fluent language. If I get this correct in C then will make necessary changes to suit Fluent

You want to apply one value using the F_PROFILE function to points on your line, and another value using that function "everyplace else", but in C you must define points in terms of discrete values for x, y and z. (Unless there is some way to deal with continuous values in Fluent, but in that case your question is really how to write that in Fluent, not in C.)

Therefore, before we can give you the C code, you must provide ranges for x, y, and z, and you must provide increment sizes for x, y and z in order to compute discrete points in xyz space.

Also, you gave an interval [0,1] for t, but is that really relevant? I don't think you want a 4-dimensional (xyzt) loop. Don't you really want to leave t as a variable in the conditional expression, to be assigned explicit values elsewhere in the code or possibly at runtime?

Dear friends
I have put my problem only in C++ so that you can be able to assist me. Please may you help me to:
1) write corectly the formular to determining Atb. It is supposed to be

Atb = a0 + a1exp(-k/cos_thetaz);


With what I have done am getting wrong answers.

2) for a given value of n be able to print a table of p ie value of (x,y,z), h, n, (n was refered to as t in the first code sent)

3) develop a code such that for the same value of n, I can calculate h for different values of p(x,y,z) for example when x=

x=117.433
y=84.62-(1004.08180)n
z=124.621-(-1004.089)n
h=(Pb+Pgr)

x=87.5
y=73.837-(1004.087)n
z=113.837-(-1004.083)n
h=(Pgr+Pd)/2


code:

#include <stdio.h>
main()
{
double x,y,z,n,h,p;
double BETA, AAZI, PHI, LTIME, SMER, LMER, N, ITIME, FTIME, LTUBE, IDTUBE, ODTUBE;
double THLCOEF, TCEF, ETAP, TCD, ATEMP, IAMC, CFFCT0, CFFCT1,CFFCTK,ALT, ALBEDO, FCS1, PI;
double B, P, E,E1,Tcorr, stime, del, omega, cos_theta1,cos_theta2, cos_theta3;
double  cos_theta4, cos_theta5, cos_theta, theta, Ai, iam, cos_thetaz, Rb, Gon;
double a0c, a1c,kc, a0, a1, k,  Atb, Gb, iamd,Pb, x1,x3, Z;
double  f12, fcs, Atd, Gd, Pd, Ggr, Pgr, Pu;
double lower,upper,step;
double cos (), sin(), tan(), acos(), pow(), sqrt();
lower =0.0; /*lower value of n limit*/
upper =1.0; /* upper limit*/
step =0.1; /*step size*/
n=lower;
while (n<=upper)
{
x=87.5;
y = 126.1620 -(1004.0820*n);
z= 166.1620 -(-1004.0880*n);
p=(x,y,z);
BETA =45;    /* defining constants*/
AAZI =15;
PHI= 43;
LTIME= 690.03;
SMER =90;
LMER =89.4;
N =234;
ITIME =690;
FTIME =790;
LTUBE= 1.8;
IDTUBE = 0.0192;
ODTUBE =0.0292;
THLCOEF= 0.9;
TCEF =0.98;
ETAP =0.856;
TCD =0.067;
ATEMP = 298.15;
IAMC = 3.8;
CFFCT0  =0.97;
CFFCT1 = 0.99;
CFFCTK = 1.02;
ALT  =0.27;
ALBEDO = 0.5;
FCS1 = 0.5;
PI =3.141592;
B= 360*(N-81)/364;
P=PI/180;
E=9.87*sin(2*B*P)-7.53*cos(B*P)-1.5*sin(B*P);
E1= 4*(SMER-LMER);
Tcorr=E+E1;
stime = LTIME+Tcorr;
del = 23.45*sin(P*(360*(284+N)/365));
omega = (stime-720)/60*15;
cos_theta1 = sin(del*P)*cos(BETA*P)*sin(PHI*P);
cos_theta2 = sin(del*P)*sin(BETA*P)*cos(PHI*P)*cos(AAZI*P);
cos_theta3 = cos(del*P)*cos(PHI*P)*cos(BETA*P)*cos(omega*P);
cos_theta4 = cos(del*P)*sin(PHI*P)*sin(BETA*P)*cos(AAZI*P)*cos(omega*P);
cos_theta5 = cos(del*P)*sin(BETA*P)*sin(AAZI*P)*sin(omega*P);
cos_theta = cos_theta1-cos_theta2+cos_theta3+cos_theta4+cos_theta5;
theta = acos(cos_theta)*57.295779513;
Ai =tan(pow((theta/2)*P,IAMC));
iam = 1-Ai;
cos_thetaz = cos(del*P)*cos(PHI*P)*cos(omega*P)+sin(del*P)*sin(PHI*P);
Rb =cos_theta/cos_thetaz;
Gon = 1353*(1+0.033*cos(P*(360*N/365)));
a0c =0.4237-0.00821*((6-ALT)*(6-ALT));
a1c = 0.5055+0.00595*((6.5-ALT)*(6.5-ALT));
kc = 0.2711+0.01858*((2.5-ALT)*(2.5-ALT));
a0 = CFFCT0 *a0c;
a1 = CFFCT1*a1c;
k =  CFFCTK *kc;
Atb = a0 + a1*pow(10,(-k/cos_theta));
Gb =Gon*Atb*cos_thetaz;
Pb=TCEF*ETAP*Gb*Rb*iam;
iamd =1-tan(pow(PI/6,IAMC));
x1= acos((ODTUBE-IDTUBE)/TCD);
x3 = acos((ODTUBE+IDTUBE)/TCD);
Z = sqrt(pow(TCD+ODTUBE*cos(PI+x1)- IDTUBE*sin(x1),2.)+
pow(ODTUBE*sin(PI+x1)-IDTUBE*sin(x1),2.));
f12 = 1*((PI-x1-x3)*IDTUBE+Z+(x3-x1)*ODTUBE-TCD*sin(x3))/(2*PI*IDTUBE);
fcs= FCS1 -f12;
Atd = .2710-.2939*Atb;
Gd = Atd*Gon;
Pd = TCEF*ETAP*iamd*Gd*fcs;
Ggr =ALBEDO*(Gb+Gd);
Pgr =TCEF*ETAP*iamd*Ggr*fcs;
Pu=Pb+Pd+Pgr;
h=Pb,
printf("\n%5.4f",Atb,n);
n=n+step;
}
}


Edited by mike_2000_17: Fixed formatting

You say C++ but you seem to be using C, as you #include <stdio.h> and use printf for printing. So, assuming you are using a C compiler, you should also #include <math.h> at the top of your program, unless you are planning to define your own math functions.

Also, delete the line double cos (), sin(), tan(), acos(), pow(), sqrt(); .

This line:

Atb = a0 + a1*pow(10,(-k/cos_theta));

says
Atb = a_0 + a_1 \cdot 10^{-k/cos theta} which is clearly not what you wrote above.
Presumably you want

Atb = a0 + a1 * exp(-k/cos_theta);

That long, long list of constants consists of constants, so you should define them just once, before the loop, not declare them over and over again inside the loop. p=(x,y,z); is invalid. You have declared p as type double. That is a single value. If you want p to represent a 3-dimensional point, you have to define a structure that can hold 3 values.

Perhaps I am simply not seeing something because it's hidden among all those constants, but I don't see where you actually do anything with x,y,z (and p) after computing their values. Have you omitted something?

Thanks for the correction. I am learning these softwares and do not actually know the differences between them. Yes I will use p when I do the analysis in Fluent. No further calculation will be done just use the 3-dimensional points I have managed to solve other problems. I am left with this p and calculating h for different locations. I think I use "if" but am failing to come up with that part of the code.

You are not making yourself clear. Looking at the code you posted in Post #11, beginning on the line BETA =45; /* defining constants*/ through and including the line h=Pb, ,
everything is constant. (Incidentally, the line "h=Pb" should end with a semicolon ; not a comma.) Therefore, all of those lines should appear before the loop, not inside it.

So it seems you should have

#include <stdio.h>
#include <math.h> // provides math and trig functions

int main()
{
int n; // it is preferable to use integer for counting to avoid rounding problems
double x,y,z,h;   // eliminated p because p is a 3-valued point;
double BETA, AAZI, PHI, LTIME, SMER, LMER, N, ITIME, FTIME, LTUBE, IDTUBE, ODTUBE;
double THLCOEF, TCEF, ETAP, TCD, ATEMP, IAMC, CFFCT0, CFFCT1,CFFCTK,ALT, ALBEDO, FCS1, PI;
double B, P, E,E1,Tcorr, stime, del, omega, cos_theta1,cos_theta2, cos_theta3;
double cos_theta4, cos_theta5, cos_theta, theta, Ai, iam, cos_thetaz, Rb, Gon;
double a0c, a1c,kc, a0, a1, k, Atb, Gb, iamd,Pb, x1,x3, Z;
double f12, fcs, Atd, Gd, Pd, Ggr, Pgr, Pu;
double lower,upper,step;
// don't declare math.h functions: double cos (), sin(), tan(), acos(), pow(), sqrt();

// place all of the constant definitions next

x=87.5;  // x is apparently constant
// next is the loop; I made n an integer from 0 to 10, so I divide by
// 10 in the expressions for y and z
for( n = 0; n < 11; n++ )
{
y = 126.1620 -(1004.0820*n/10);
z= 166.1620 -(-1004.0880*n/10);
// now do something with these values: define points? store them in an array? ...
// otherwise, the values will be overwritten (and lost) on the next iteration
// so you have to add some code here, inside the loop

}
// main function continues ...

}

Lines beginning with // are comments; have no effect on the program

The line: printf("\n%5.4f",Atb,n); made no sense -- why do you want to print the constant value Atb 11 times?

I eliminated the p=(x,y,z) as it is meaningless without a definition for p. Perhaps the Fluent system provides a definition (structure) for a point. If so, you must use the syntax they provide; I can't help you with that. Otherwise, you have to define "point". For example, a point might be defined this way:

typedef struct{
double xval;
double yval;
double zval;
} point;

Then you could create an array of 10 points and assign values to the first point in the array like this:

point pArray[10];
pArray[0].xval = x;
pArray[0].yval = y;
pArray[0].zval = z;

There are many other ways to do this -- it all depends on how you are going to use it.

thank youi very much