CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT

UDF issues

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   May 12, 2011, 10:45
Default UDF issues
  #1
Member
 
EH
Join Date: Dec 2010
Posts: 61
Rep Power: 15
ehooi is on a distinguished road
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 C1C2;
 
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(dID_tank);
 
thout Lookup_Thread(dID_out);
 
thb1 Lookup_Thread(dID_back1);
 
thb2 Lookup_Thread(dID_back2);
 
thf1 Lookup_Thread(dID_front1);
 
thf2 Lookup_Thread(dID_front2);
 
thl1 Lookup_Thread(dID_left1);
 
thl2 Lookup_Thread(dID_left2);
 
thr1 Lookup_Thread(dID_right1);
 
thr2 Lookup_Thread(dID_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, &Tout1myid);
   
PRF_CSEND_DOUBLE(i, &Tin1myid);
  }
 }
 
/* Reception of average temperature from node zero */
 
if(! I_AM_NODE_ZERO_P)
 {
  
PRF_CRECV_DOUBLE(0, &Tout10);
  
PRF_CRECV_DOUBLE(0, &Tin10);
 }
 
/* -------------------------------------------------------------------------*/  
 /* Store calculated values in user-defined memory */
 /* Outlet */
 
begin_f_loop(fthout)
 {
  
F_UDMI(f,thout,0) = Tout;
 }
 
end_f_loop(f,thout)
 
 
/* Back 1 */
 
begin_f_loop(fthb1)
 {
  
F_UDMI(f,thb1,1) = Tin;
 }
 
end_f_loop(f,thb1)
 
/* Back 2 */
 
begin_f_loop(fthb2)
 {
  
F_UDMI(f,thb2,2) = Tin;
 }
 
end_f_loop(f,thb2)
 
 
/* Front 1 */
 
begin_f_loop(fthf1)
 {
  
F_UDMI(f,thf1,3) = Tin;
 }
 
end_f_loop(f,thf1)
 
 
/* Front 2 */
 
begin_f_loop(fthf2)
 {
  
F_UDMI(f,thf2,4) = Tin;
 }
 
end_f_loop(f,thf2)
 
/* Left 1 */
 
begin_f_loop(fthl1)
 {
  
F_UDMI(f,thl1,5) = Tin;
 }
 
end_f_loop(f,thl1)
 
/* Left 2 */
 
begin_f_loop(fthl2)
 {
  
F_UDMI(f,thl2,6) = Tin;
 }
 
end_f_loop(f,thl2)
 
/* Right 1 */
 
begin_f_loop(fthr1)
 {
  
F_UDMI(f,thr1,7) = Tin;
 }
 
end_f_loop(f,thr1)
 
 
/* Right 2 */
 
begin_f_loop(fthr2)
 {
  
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
ehooi is offline   Reply With Quote

Old   May 13, 2011, 04:49
Default
  #2
Senior Member
 
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 17
coglione is on a distinguished road
I think the problem is that the grid partition belonging to node-0 does not include all (or even any) cells of this cell_thread "thtank". Hence some or all cells actually within your limits simply can not be found by this node. If so, then running in serial should give correct results. Check this.

cheers
coglione is offline   Reply With Quote

Old   May 13, 2011, 05:42
Default
  #3
Member
 
EH
Join Date: Dec 2010
Posts: 61
Rep Power: 15
ehooi is on a distinguished road
Hi,
Thank you. I think this may be the reason why I am not getting the limits. Unfortunately I have to run it in parallel since this is a very large problem. However, I thought node-0 is the node that stores all the coordinates. Is this correct?

Thanks,
EH



Quote:
Originally Posted by coglione View Post
I think the problem is that the grid partition belonging to node-0 does not include all (or even any) cells of this cell_thread "thtank". Hence some or all cells actually within your limits simply can not be found by this node. If so, then running in serial should give correct results. Check this.

cheers
ehooi is offline   Reply With Quote

Old   May 13, 2011, 06:18
Default
  #4
Member
 
EH
Join Date: Dec 2010
Posts: 61
Rep Power: 15
ehooi is on a distinguished road
Hi again,
I tried reversing the code to compute the temperature at all the non-zero nodes i.e. by using

IF (! I AM NODE ZERO)

After computation, I need to pass the result to node zero. Usually we compute everything in node zero and pass it to nonzero nodes. Is it possible to pass values from non zero nodes to node zero, ie something like this:

compute_node_loop_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);
}

Any help is really appreciated

Thanks,

EH


Quote:
Originally Posted by coglione View Post
I think the problem is that the grid partition belonging to node-0 does not include all (or even any) cells of this cell_thread "thtank". Hence some or all cells actually within your limits simply can not be found by this node. If so, then running in serial should give correct results. Check this.

cheers
ehooi is offline   Reply With Quote

Old   May 13, 2011, 06:21
Default
  #5
Senior Member
 
Max
Join Date: Mar 2009
Posts: 133
Rep Power: 17
coglione is on a distinguished road
No, as far as I know every node has full information about everything but also only in its partition. The only special thing with node-0 is that he is in charge for communication with host.
Thus in general every node has to perform the desired actions on its own and then a global summation has to be done. See section 7.5.4 in the udf manual how this works.

cheers
coglione is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
About UDF compiling issues: 'nmake' Haoyin Shan Fluent UDF and Scheme Programming 15 November 4, 2019 19:05
UDF parallel error: chip-exec: function not found????? shankara.2 Fluent UDF and Scheme Programming 1 January 16, 2012 23:14
How to add a UDF to a compiled UDF library kim FLUENT 3 October 26, 2011 22:38
UDF...UDF...UDF...UDF Luc SEMINEL FLUENT 0 November 25, 2002 05:03
UDF, UDF, UDF, UDF Luc SEMINEL Main CFD Forum 0 November 25, 2002 05:01


All times are GMT -4. The time now is 22:11.