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/)
-   -   Simulation takes too long time - Applying w/m³ to cells, UDF works (https://www.cfd-online.com/Forums/fluent-udf/182613-simulation-takes-too-long-time-applying-w-m-cells-udf-works.html)

h0rst January 14, 2017 08:32

Simulation takes too long time - Applying w/m³ to cells, UDF works
 
Hello everybody,

from APDL, i extracted mesh and w/m³ created in a tube flowed through by water.
I imported the mesh in the Fluent model. The w/m³ I took from a .txt file which I created with Apdl and applied the w/m³ to each cell by UDF which works. The source code is as follows:




#include "udf.h"
#define lines 6672
DEFINE_SOURCE(energy_source,cell,thread,dS,eqn)
{
FILE *hs;
int n;
real x[ND_ND];
real source = 0.;

float array1[lines];

if (1==1)
{
hs=fopen("ejheatcoord.txt","r");

for (n=0;n<lines;n++)
{
fscanf(hs,"%g",&array1[n]);
}
fclose(hs);
}

C_CENTROID(x,cell,thread);
dS[eqn] = 0;

source=array1[cell];

return source;
}




I hooked the Udf as a source term to cell conditions of the tube.

If I simplify the model (6672 elements), it takes 5 minutes for one iteration.
When I do not simplify this which is necessary, I use 130000 elements.

Any ideas how to fasten up the calculating process?


Best regards
h0rst

flotus1 January 14, 2017 08:48

What your UDF does: For EVERY iteration and EVERY cell, it reads the whole file and then adjusts the source value for this one cell. Even if the source value was supposed to change during the iteration process, this would be unnecessarily complicated.
Can't you use a profile file instead that is read once at the beginning of the simulation? Not absolutely sure if this is possible with a source term. Otherwise, use a second UDF that reads the file at the beginning of the simulation once to speed things up.

h0rst January 14, 2017 09:47

Thank you for the fast answer!

I see your point and would like to do it with 2 Udfs.

The problem is, that when I interpret UDF, I can always only chose one.

Do I need to compile or is it somehow possible to have two Udf's used by using the interpreter?



Best regards
h0rst

flotus1 January 14, 2017 10:14

Did you put both UDFs in the same file? This should usually work even in interpreted mode.
With execution speed and parallelism in mind, you might need to switch to compiled mode sooner or later.

h0rst January 14, 2017 11:24

it worked out :)

thank you so much!


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