UDF issues
Hi all,
I am having some problems with UDF. Basically I have written a UDF which worked well before and now that I have developed a new model, when I use the same UDF, it gives me problems.
The UDF is as follows:
PHP Code:
#include "udf.h" DEFINE_ADJUST(fcn_outlet,d) { /* -------------------------------------------------------------------------*/ #if !RP_HOST /* either serial or compute node process is involved */ /* Variable Declaration */ double Tout = 0.0; double Tin; double Ttemp; double C1, C2; double coord[ND_ND]; double xxmin = 0.27; double xxmax = 0.28; double yymin = -0.012; double yymax = -0.007; double zzmin = -0.68; double zzmax = -0.66; double xx,yy,zz; double nd = 0.0; double hamb = 10.0; double area1 = 0.0416; double area2 = 0.0649; double mtot = 0.174; double mind = 0.0435; double cp = 2470.0; double Tamb = 300.9; double L1 = 0.5757; double L2 = 1.08955; int i; int ID_tank = 30; int ID_out = 68; int ID_back1 = 66; int ID_back2 = 67; int ID_front1 = 60; int ID_front2 = 61; int ID_left1 = 64; int ID_left2 = 65; int ID_right1 = 62; int ID_right2 = 63; cell_t c; face_t f; Thread *thtank; Thread *thout; Thread *thb1; Thread *thb2; Thread *thf1; Thread *thf2; Thread *thl1; Thread *thl2; Thread *thr1; Thread *thr2; thtank = Lookup_Thread(d, ID_tank); thout = Lookup_Thread(d, ID_out); thb1 = Lookup_Thread(d, ID_back1); thb2 = Lookup_Thread(d, ID_back2); thf1 = Lookup_Thread(d, ID_front1); thf2 = Lookup_Thread(d, ID_front2); thl1 = Lookup_Thread(d, ID_left1); thl2 = Lookup_Thread(d, ID_left2); thr1 = Lookup_Thread(d, ID_right1); thr2 = Lookup_Thread(d, ID_right2); /* -------------------------------------------------------------------------*/ /* Begin loop to calculate the temperature of cells surrounding outlet */ /* Computation carried out on node 0 */ if(I_AM_NODE_ZERO_P) { begin_c_loop(c,thtank) { C_CENTROID(coord,c,thtank); xx = coord[0]; yy = coord[1]; zz = coord[2]; if ((xx >= xxmin) && (xx <= xxmax)) { if ((yy >= yymin) && (yy <= yymax)) { Message("ncell = %f\n", zz); if ((zz >= zzmin) && (zz <= zzmax)) { Tout = Tout + C_T(c,thtank); /* Cell temperature */ nd = nd + 1.0; /* Number of cells */ } } } } end_c_loop(c,thtank) Tout = Tout/nd; /* Average cell temperature surrounding outlet */ C1 = -hamb*area1*L1/(mtot*cp); Ttemp = (Tout-Tamb)*exp(C1) + Tamb; C2 = -hamb*area2*L2/(mind*cp); Tin = (Ttemp-Tamb)*exp(C2) + Tamb; Message("ncell = %f\n", nd); Message("Tout = %f\n", Tout); Message("Tin = %f\n", Tin); compute_node_loop_not_zero(i) { PRF_CSEND_DOUBLE(i, &Tout, 1, myid); PRF_CSEND_DOUBLE(i, &Tin, 1, myid); } } /* Reception of average temperature from node zero */ if(! I_AM_NODE_ZERO_P) { PRF_CRECV_DOUBLE(0, &Tout, 1, 0); PRF_CRECV_DOUBLE(0, &Tin, 1, 0); } /* -------------------------------------------------------------------------*/ /* Store calculated values in user-defined memory */ /* Outlet */ begin_f_loop(f, thout) { F_UDMI(f,thout,0) = Tout; } end_f_loop(f,thout) /* Back 1 */ begin_f_loop(f, thb1) { F_UDMI(f,thb1,1) = Tin; } end_f_loop(f,thb1) /* Back 2 */ begin_f_loop(f, thb2) { F_UDMI(f,thb2,2) = Tin; } end_f_loop(f,thb2) /* Front 1 */ begin_f_loop(f, thf1) { F_UDMI(f,thf1,3) = Tin; } end_f_loop(f,thf1) /* Front 2 */ begin_f_loop(f, thf2) { F_UDMI(f,thf2,4) = Tin; } end_f_loop(f,thf2) /* Left 1 */ begin_f_loop(f, thl1) { F_UDMI(f,thl1,5) = Tin; } end_f_loop(f,thl1) /* Left 2 */ begin_f_loop(f, thl2) { F_UDMI(f,thl2,6) = Tin; } end_f_loop(f,thl2) /* Right 1 */ begin_f_loop(f, thr1) { F_UDMI(f,thr1,7) = Tin; } end_f_loop(f,thr1) /* Right 2 */ begin_f_loop(f, thr2) { F_UDMI(f,thr2,8) = Tin; } end_f_loop(f,thr2) #endif } /* -------------------------------------------------------------------------*/
DEFINE_PROFILE(temp_out,t,i) { #if !RP_HOST double flow_time = CURRENT_TIME; face_t f; if (flow_time <= 601.0) { begin_f_loop(f,t) { F_PROFILE(f,t,i) = 333.0; } end_f_loop(f,t) } else { begin_f_loop(f,t) { F_PROFILE(f,t,i) = F_UDMI(f,t,0); } end_f_loop(f,t) } #endif }
DEFINE_PROFILE(temp_back1,t,i) { #if !RP_HOST double flow_time = CURRENT_TIME; face_t f; if (flow_time <= 601.0) { begin_f_loop(f,t) { F_PROFILE(f,t,i) = 333.0; } end_f_loop(f,t) } else { begin_f_loop(f,t) { F_PROFILE(f,t,i) = F_UDMI(f,t,1); } end_f_loop(f,t) } #endif }
DEFINE_PROFILE(temp_back2,t,i) { #if !RP_HOST double flow_time = CURRENT_TIME; face_t f; if (flow_time <= 601.0) { begin_f_loop(f,t) { F_PROFILE(f,t,i) = 333.0; } end_f_loop(f,t) } else { begin_f_loop(f,t) { F_PROFILE(f,t,i) = F_UDMI(f,t,2); } end_f_loop(f,t) } #endif } DEFINE_PROFILE(temp_front1,t,i) { #if !RP_HOST double flow_time = CURRENT_TIME; face_t f; if (flow_time <= 601.0) { begin_f_loop(f,t) { F_PROFILE(f,t,i) = 333.0; } end_f_loop(f,t) } else { begin_f_loop(f,t) { F_PROFILE(f,t,i) = F_UDMI(f,t,3); } end_f_loop(f,t) } #endif } DEFINE_PROFILE(temp_front2,t,i) { #if !RP_HOST double flow_time = CURRENT_TIME; face_t f; if (flow_time <= 601.0) { begin_f_loop(f,t) { F_PROFILE(f,t,i) = 333.0; } end_f_loop(f,t) } else { begin_f_loop(f,t) { F_PROFILE(f,t,i) = F_UDMI(f,t,4); } end_f_loop(f,t) } #endif } DEFINE_PROFILE(temp_left1,t,i) { #if !RP_HOST double flow_time = CURRENT_TIME; face_t f; if (flow_time <= 601.0) { begin_f_loop(f,t) { F_PROFILE(f,t,i) = 333.0; } end_f_loop(f,t) } else { begin_f_loop(f,t) { F_PROFILE(f,t,i) = F_UDMI(f,t,5); } end_f_loop(f,t) } #endif } DEFINE_PROFILE(temp_left2,t,i) { #if !RP_HOST double flow_time = CURRENT_TIME; face_t f; if (flow_time <= 601.0) { begin_f_loop(f,t) { F_PROFILE(f,t,i) = 333.0; } end_f_loop(f,t) } else { begin_f_loop(f,t) { F_PROFILE(f,t,i) = F_UDMI(f,t,6); } end_f_loop(f,t) } #endif }
DEFINE_PROFILE(temp_right1,t,i) { #if !RP_HOST double flow_time = CURRENT_TIME; face_t f; if (flow_time <= 601.0) { begin_f_loop(f,t) { F_PROFILE(f,t,i) = 333.0; } end_f_loop(f,t) } else { begin_f_loop(f,t) { F_PROFILE(f,t,i) = F_UDMI(f,t,7); } end_f_loop(f,t) } #endif } DEFINE_PROFILE(temp_right2,t,i) { #if !RP_HOST double flow_time = CURRENT_TIME; face_t f; if (flow_time <= 601.0) { begin_f_loop(f,t) { F_PROFILE(f,t,i) = 333.0; } end_f_loop(f,t) } else { begin_f_loop(f,t) { F_PROFILE(f,t,i) = F_UDMI(f,t,8); } end_f_loop(f,t) } #endif }
The UDF basically calculates the average of temperature at a certain location to be input as the temperature elsewhere (something like a recirculation system where the temperature at the outlet is the same as the temperature at the inlet.
The problem now is that this part the cells are not within the limits set. In other words, in this section:
if ((xx >= xxmin) && (xx <= xxmax))
{
if ((yy >= yymin) && (yy <= yymax))
{
Message("zz = %f\n", zz);
if ((zz >= zzmin) && (zz <= zzmax))
when I print out the values of zz after xx and yy, they are not within the zzmin and zzmax limit, hence I get a division by zero.
There are definitely cells within the z limit. Anyone knows why this is happening?
Thanks and I really appreciate any help.
Sincerely,
EH
|