CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   problem using property udfs in parallel mode (https://www.cfd-online.com/Forums/fluent-udf/65728-problem-using-property-udfs-parallel-mode.html)

EllenW June 24, 2009 10:26

problem using property udfs in parallel mode
 
Hi,

I'm having a problem when trying to use multiple property udfs in the parallel mode:

I'm modeling two gases in species transport, and used two udf's to define their properties (thermal conductivity). The udf is quite simple: to open a file and read in a list of data, then specify the data to cells according to the cell temperature (see the attached code). Two such udfs were written, one for each gas, and they work well in the serial mode.
However, when I tried to use them in the parallel mode, problem occurred. I parallelized the code as attached. If I only apply one udf to one gas, it worked fine, but if I apply both udfs to both gases, then I got this error message:
Error: > (greater-than): invalid argument [2]: wrong type [not a number]
Error object: 1. #quan

Could anyone please help me explain why this happens? Or point out where I did wrong in parallelizing the code? Thank you very much!

The original udf:

#include "udf.h"
FILE *ifp;
int i;
real k_a[100][2];
DEFINE_EXECUTE_ON_LOADING(table_ka, libudfka)
{
real T, k;
ifp = fopen("k_a.txt", "r");
for (i=0;i<100;i++)
{
fscanf(ifp, "%lf %lf", &T, &k);
k_a[i][0] = T;
k_a[i][1] = k;
}
Message("k_a table was loaded.");
fclose(ifp);
}
DEFINE_PROPERTY(cell_ka, cell, thread)
{
real temp1, k1;
temp1 = C_T(cell, thread);
if(temp1<k_a[0][0])
k1 = k_a[0][1];
for (i=1;i<100;i++)
{
if(temp1>=k_a[i-1][0] && temp1<=k_a[i][0])
k1 = (k_a[i][1]-k_a[i-1][1])*(temp1-k_a[i-1][0])/(k_a[i][0]-k_a[i-1][0])+k_a[i-1][1];
}
if(temp1>k_a[99][0])
k1 = k_a[99][1];
return k1;
}

The parallelized udf:

#include "udf.h"
int i;
real C1[100];
real C2[100];
#if !RP_NODE
FILE *ifp1;
DEFINE_EXECUTE_ON_LOADING(table_ka, libudfka)
{
int ii;
real T1, k1;
ifp1 = fopen("k_a.txt", "r");
for (ii=0;ii<99;ii++)
{
fscanf(ifp1, "%lf %lf", &T1, &k1);
C1[ii] = T1;
C2[ii] = k1;
}
host_to_node_real(C1,100);
host_to_node_real(C2,100);
Message("k_a table was loaded.");
fclose (ifp1);
}
#endif
DEFINE_PROPERTY(cell_ka, cell, thread)
{
real temp1, k1;
real k_a[100][2];
for (i=0;i<100;i++)
{
k_a[i][0] = C1[i];
k_a[i][1] = C2[i];
}
#if !RP_HOST
temp1 = C_T(cell, thread);
if(temp1<k_a[0][0])
k1 = k_a[0][1];
for (i=1; i<100; i++)
{
if (temp1>=k_a[i-1][0] && temp1<=k_a[i][0])
k1 = (k_a[i][1]-k_a[i-1][1])*(temp1-k_a[i-1][0])/(k_a[i][0]-k_a[i-1][0])+k_a[i-1][1];
}
if(temp1>k_a[99][0])
k1 = k_a[99][1];
#endif
return k1;
}


Regards,
ellen

coglione June 25, 2009 06:46

Hi ellen,

this is just a wild guess, but could it be the problem that you defined i as global variable which then is used (and manipulated) by every processor simultaneously? Maybe the value of i within your "for-loops" gets messed up and causes the problem. Try to use local variables and see whether this works.

cheers

EllenW June 25, 2009 11:21

thanks for pointing this out, Coglione. I put "i" in local for the other udf, but forgot to do the same for this one. Now I corrected it, but the error is still there...

I also tried assigning some data to the property array inside the DEFINE_PROPERTY macro, instead of getting data by reading the property data file. I did this for both udfs, and they worked fine in the parallel mode. But when I changed back to file reading, then same problem: the case runs fine with only one udf, and error appears when both udfs are used...

thanks for any suggestions you may have.

ellen

friends.sk July 8, 2009 17:28

Ellen,

You found an answer for this?? I am also stucked up at the same point.

EllenW July 9, 2009 17:02

Hi friends.sk, my code is working now. the two corrections I made to the DEFINE_EXECUTE_ON_LOADING part are:
Compiler directive should be within the execute loop.
Passing of variables from host to node should be outside the compiler directive loop

the second part (DEFINE_PROPERTY) was unchanged.

ellen

friends.sk July 10, 2009 05:31

Hi Ellen, Thanks for the reply. Can you please explain me bit in detail.
Thanks.
SK.


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