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

Hooking DEFINE_ON_DEMAND error??????????

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By pakk

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 23, 2015, 01:00
Exclamation Hooking DEFINE_ON_DEMAND error??????????
  #1
Member
 
Anh
Join Date: Sep 2014
Posts: 69
Rep Power: 11
dinhanh is on a distinguished road
Hi, I made UDF to calculate the local grid size for DES turbulence model in that delta=max(dx,dy,dz). Then compare the length scale of 2 equation model (Lt) and length of local grid delta. The results saved in C_UDMI=0 if (Lt>Cdes*delta) and C_UDMI=1 if (Lt<Cdes*delta) in order to plot the region where LES model is actived. But Fluent gave the error warning and could not do anything.
My code is described below (referent from one topic in forum)

#include "udf.h"
#include "math.h"

DEFINE_ON_DEMAND(contour)
{
Domain *domain=Get_Domain(1);
Thread *c_thread;
cell_t c;
Node *node;

int n,i,j,counter=0;
real delx1=0,dely1=0,delz1=0,dx,dy,dz,delta=0,lt,ldes,C des=0.65;
real delx,dely,delz;
real x[500],y[500],z[500];

thread_loop_c(c_thread,domain) /*loops over all cell threads in domain*/
{
begin_c_loop(c,c_thread) /* loops over cells in a cell thread */
{
c_node_loop(c,c_thread,n) /* loops over node in a cell thread */
{
node=C_NODE(c,c_thread,n);
NODE_MARK(node)=0;
}
c_node_loop(c,c_thread,n) /* loops over node in a cell thread */
{
node=C_NODE(c,c_thread,n);
x[counter]=NODE_X(node);
y[counter]=NODE_Y(node);
z[counter]=NODE_Z(node);
counter=counter+1;
if(NODE_MARK(node)==0)
NODE_MARK(node)=1;
}
for (i=0; i<(counter-1); ++i)
{
for (j=i+1; j<counter; j++)
{
dx=fabs(x[i]-x[j]);
dy=fabs(y[i]-y[j]);
dz=fabs(z[i]-z[j]);
delx=max(delx1,dx);
dely=max(dely1,dy);
delz=max(delz1,dz);
delta=max(delx,dely);
delta=max(delta,delz);
}
}

lt=C_K(c,c_thread)/0.09/C_O(c,c_thread);
ldes=Cdes*delta;
if(lt>ldes)
{
C_UDMI(c,c_thread,1)=1;
}
if(lt<ldes)
{
C_UDMI(c,c_thread,1)=0;
}
}
end_c_loop(c,c_thread)
}
}

And the warning of Fluent is as in the picture below.
Please give me the solution for this trouble!! Thank you very much.
Attached Images
File Type: jpg Untitled.jpg (49.7 KB, 9 views)
dinhanh is offline   Reply With Quote

Old   January 23, 2015, 02:59
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
The problem is that you are using a serial code for parallel calculation. In parallel calculation, there is a host node, which does not do any calculation itself, but only distributes the data. (Simplified, but accurate enough for now.)
Your code is run on every node, so the host node is also asked to calculate the local grid, but it has no grid, so you get errors. At least that is what I think is going on.

Two solution strategies:
1. Calculate (this part) in serial mode, with only one compute node.
2. Parallelize your serial UDF. See Fluent UDF manual, section 7.3, and 7.5.1.
pakk is offline   Reply With Quote

Old   January 23, 2015, 09:58
Default
  #3
Member
 
Anh
Join Date: Sep 2014
Posts: 69
Rep Power: 11
dinhanh is on a distinguished road
Quote:
Originally Posted by pakk View Post
The problem is that you are using a serial code for parallel calculation. In parallel calculation, there is a host node, which does not do any calculation itself, but only distributes the data. (Simplified, but accurate enough for now.)
Your code is run on every node, so the host node is also asked to calculate the local grid, but it has no grid, so you get errors. At least that is what I think is going on.

Two solution strategies:
1. Calculate (this part) in serial mode, with only one compute node.
2. Parallelize your serial UDF. See Fluent UDF manual, section 7.3, and 7.5.1.
Thank you for your comment.
You said the error because I run serial code in parallel calculation. But I also wrote UDF code for vaporation pressure which is very simple like this:
#include "udf.h"
#include "math.h"

DEFINE_PROPERTY(vap_pre,c,t)
{
real pvar;
real psat=2198;
pvar=psat+0.5*0.39*C_R(c,t)*C_K(c,t);
return pvar;
}

and doing with parallel calculation, but there are no error or warning from fluent.
dinhanh is offline   Reply With Quote

Old   January 23, 2015, 10:04
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
And that is because in your "vap_pre" code, the parallel code and the serial code are the same.

If your code tries to look up something that has a position (like in your "contour" code, where you loop over all threads and nodes), serial code gives errors in parallel mode. If your code does not do that (like in your "vap_pre" code, where you define a property of a cell based on other properties of that cell), serial code and parallel code are the same.
dinhanh likes this.
pakk is offline   Reply With Quote

Old   January 23, 2015, 10:16
Default
  #5
Member
 
Anh
Join Date: Sep 2014
Posts: 69
Rep Power: 11
dinhanh is on a distinguished road
Oh, I see, Thank you very much for your help
dinhanh is offline   Reply With Quote

Old   January 23, 2015, 10:49
Default
  #6
Member
 
Anh
Join Date: Sep 2014
Posts: 69
Rep Power: 11
dinhanh is on a distinguished road
Quote:
Originally Posted by pakk View Post
And that is because in your "vap_pre" code, the parallel code and the serial code are the same.

If your code tries to look up something that has a position (like in your "contour" code, where you loop over all threads and nodes), serial code gives errors in parallel mode. If your code does not do that (like in your "vap_pre" code, where you define a property of a cell based on other properties of that cell), serial code and parallel code are the same.


Sorry, I have one more question. I read the parallel part in Fluent manual, and I include #if RP_HOST to my code, but the same warning and error still appare. When I use #if PARALLEL the code is ok and running in parallel calculation now. But it mean only serial process is calculted, isn's it?

The code with #if RP_HOST
#include "udf.h"
#include "math.h"
#include "sg_mem.h"

DEFINE_PROPERTY(vap_Re3,c,t)
{
#if !RP_HOST
real pvar;
real psat=2198;
pvar=psat+0.195*(C_RUV(c,t)+C_RVW(c,t)+C_RUW(c,t)) ;
return pvar;
#endif
}

and the similar one with #if !PARALLEL
#include "udf.h"
#include "math.h"
#include "sg_mem.h"

DEFINE_PROPERTY(vap_Re3,c,t)
{
#if !PARALLEL
real pvar;
real psat=2198;
pvar=psat+0.195*(C_RUV(c,t)+C_RVW(c,t)+C_RUW(c,t)) ;
return pvar;
#endif
}
dinhanh is offline   Reply With Quote

Reply


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
Problems with hooking UDF whelk123 Fluent UDF and Scheme Programming 1 August 30, 2010 07:39
Hooking a DPM Particle Heat and Mass Transfer UDF to FLUENT subhankar_bhandari Fluent UDF and Scheme Programming 0 August 19, 2010 03:09
Hooking a DPM Particle Heat and Mass Transfer UDF to FLUENT subhankar_bhandari FLUENT 0 August 19, 2010 03:01
Hooking a DPM Particle Heat and Mass Transfer UDF to FLUENT subhankar_bhandari Main CFD Forum 0 August 19, 2010 03:01
10 reactions udf hooking m&s FLUENT 0 July 6, 2010 00:36


All times are GMT -4. The time now is 01:54.