Parallelizing “DEFINE ON_DEMAND” & “DEFINE_SOURCE” UDFs to apply x-momentum source from text file

kavatarkavatar Member
edited January 13 in Fluids

Hello,

This problem is related to fluent udf while running in parallel.

I have a text file storing x-momentum source at every cell center of the domain. I store the source term in order of global cell index in the text file. i.e. value in first line correspond to source of cell with index 0, value of second line correspond to source of cell with index 1 and so on. I want to read this text file and add source term to x-momentum equation. My UDF for serial run is given below (which is working fine).

#include "udf.h"

float xSource[194875]; //global array variable

DEFINE_ON_DEMAND(read_source)

{

int i;

FILE *xSourceFile; // declare a FILE pointer

xSourceFile = fopen("Fx.txt", "r"); // open file for reading

Message("xSourceFile file opened\n");


/* loop to read file */

i=0; // initialize before to loop

for (i=0;i<194875;i++)

{

fscanf (xSourceFile, "%f", xSource+i); // one value per line

}

fclose(xSourceFile);

Message("xSourceFile file closed\n");

}

DEFINE_SOURCE(xmom_source,c,t,dS,eqn)

{

dS[eqn]=0.0;

return xSource[c]; //xSource array has values in global index order

}


The above code works fine in serial. To run the same case in parallel I have made following code:


#include "udf.h"

float xSource[194875]; //global array variable

DEFINE_ON_DEMAND(read_source)

{

#if !RP_NODE

int i;

FILE *xSourceFile; // declare a FILE pointer

xSourceFile = fopen("Fx.txt", "r"); // open file for reading

Message("xSourceFile file opened\n");

/* loop to read file */

i=0; // initialize before to loop

for (i=0;i<194875;i++)

{

fscanf (xSourceFile, "%f", xSource+i); // one value per line

}

fclose(xSourceFile);

Message("xSourceFile file closed\n");

#endif

host_to_node_float(xSource,194875);

}

DEFINE_SOURCE(xmom_source,c,t,dS,eqn)

{

#if !RP_HOST

dS[eqn]=0.0;

return xSource[c]; //xSource array has values in global index order

#endif

}


When I use the second udf in parallel case the results are not similar to what I get in serial run with first udf. 

Some observations are:

  • Running first udf in serial give perfect results
  • Running second udf in serial give perfect results (similar to the case with first udf)
  • Running second udf in parallel give a warning as "warning C4716: xmom_source': must return a value". And, the output is also not what is expected and not similar to the case with udf in serial


Can anyone identity the problem in the second udf which can be used in parallel run?

Thanks in advance

Comments

This discussion has been closed.