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/)
-   -   UDF_transient (https://www.cfd-online.com/Forums/fluent-udf/182453-udf_transient.html)

Boh January 10, 2017 08:28

UDF_transient
 
Hi everyone!
I have this UDF:
#include "udf.h"
#include "math.h"
#include "mem.h"
#define Dh 11.85e-3
#define NU 7.54
#define k 0.0264
#define cp 1005
#define ht 16.8
#define rho 1.125
#define Diff 2.82e-5
#define Cads_in 1e-6

DEFINE_PROFILE(transient_conc, t, i)
{
Domain *d;
Thread *t_air_middle;
Thread *t_adsorber;
Thread *t_interface;
Thread *t1;
cell_t c;
cell_t c1;
face_t f;
real xy[ND_ND];
real A[ND_ND];
real Le;
real hm;
real time;
real dt;
real phi;
real Cinf;
real Cinter;
real Cads;
real mh20;
Le = k / (rho*cp*Diff);
hm = (ht*Diff*(pow(Le, 1 / 3))) / k;
d = Get_Domain(1);
t_air_middle = Lookup_Thread(d, 19);
t_interface = Lookup_Thread(d, 8);
time = CURRENT_TIME;
dt = CURRENT_TIMESTEP;
begin_f_loop(f, t)
{

if (time == 0)
{
F_PROFILE(f, t, i) = Cads_in;
}
else
{

Cinf = F_YI(f, t_air_middle, 0);
phi = hm*Cinf*C_R(c,t) ;
F_PROFILE(f, t, i) =phi*dt;
}
}
end_f_loop(f, t)

}
The compling and the inizialization of the problem works....but when I run the simulation I get segmentation fault.
The problem is the C_R(c,t) macro (if I remove it everything works) but I don't know how to solve it, can somebody help me out?
Thanks

KevinZ09 January 10, 2017 11:26

I'd say replace C_R(c,t) by F_R(f,t) and it should work, i.e., replacing the cell variable by its face equivalent.

Boh January 10, 2017 11:46

I get the same error....

KevinZ09 January 10, 2017 13:46

Ok. And you re-compiled everything? If so, are you saying if you replace F_R(f,t) by, e.g., 1 it works? That means keep everything else the same, including the line that contains that macro? If so, what does the segmentation fault say? What's the complete error? And perhaps give more information about your simulation, as it could be caused by Fluent, not necessarily by the UDF.

Boh January 11, 2017 05:07

Thanks for helping me out....I get this error:

Error: received a fatal signal (Segmentation fault).
Error Object: #f

If I don't use C_R(c,t) or F_R(c,t) everything works fine (I kept all the other parts the same).
I'm trying to simulate the accumulation of water in a porous media in 2D. The solver is pressure based.
I noticed that I get the same error with the C_VOLUME(c,t) and C_YI_M1(c,t) macros.
I tried adding and execute_at_end UDF:

real mt;
real density;
real volume;

DEFINE_EXECUTE_AT_END(mass_time)
{
Domain *d;
Thread *t;
face_t f;
cell_t c;
d = Get_Domain(1);
t = Lookup_Thread(d, 27);
begin_f_loop(f, t)
{
density = C_R(c, t);
volume = C_VOLUME(c, t);

}
end_f_loop(f,t)
}
But now I get this error:
Error: Divergence detected in AMG solver: species-0
Error Object: #f
And I don't know if I'm passing to the other function all the values of density or only the last one

KevinZ09 January 11, 2017 05:27

Wait, did you replace C_R(c,t) by F_R(f,t) or by F_R(c,t)? The last one definitely doesn't work, as you're using a cell-thread inside a face-loop. Also, C_R won't work, as it's a cell variable, and you need a face-variable, i.e., F_R. So use F_R(f,t), i.e., the face variable F_R looped over a face thread f (not c). Then let me know if it works or not.

Boh January 11, 2017 05:35

I still get the same error:
Error: received a fatal signal (Segmentation fault).
Error Object: #f
using F_R(f,t)

KevinZ09 January 11, 2017 06:23

That's odd. Couple of suggestions then:

1: Try replacing F_R(f,t) by another face macro, like F_U(f,t).
2: Replace it by a constant like 1., or a more representative value, like the density you expect it to be. See if it still gives a segmentation fault.
3: Also, be careful when using numbers, as 1 and 3 are integers. So when having 1/3, the result is 0. So better type 1.0/3.0, if at least you want a real/double division. Same for time == 0. I'm not sure how that's evaluated, but better write time == 0.0, to be on the safe side.

Boh January 11, 2017 09:47

Thanks for your help..if I use a constant it works but with all the macros (F_T(f,t), F_U(f,t)) I get segmentation fault (I changed also the integers like you suggested..thanks!) or this error:

Error: Write_Data_Section: uninitialized flow field
Error Object: #f

Error: Error writing "| gzip -2cf > FFF.1-1-00000.dat.gz".
Error Object: #f

KevinZ09 January 13, 2017 05:19

What kind of solver are you using? I know you said pressure-based solver, but is it a segregated solver or a coupled solver? And on what face are you trying to prescribe this profile? A boundary face or an interior face?

And try once deleting and unloading the old library and then building and loading a complete new one. Sometimes it helps too.

Boh January 13, 2017 10:49

Thanks for the patience...I use a segregated solver. I have already tried. Thanks!

pakk January 15, 2017 06:56

You are trying to read a variable that does not exist.

In the first code you posted, it was (as Kevin mentioned) C_R(c,t). That gives the density at cell c, but you have given the program no indication of which cell c you are talking about.

If the same problem happens in the code where you use F_R(f,t), there are two options:
1. You fixed it in the wrong way (so please show your updated code!)
2. The density at face f does not exist.

To allow us to help you, you should post the most recent code you have that still gives an error (and tell us exactly which error), and explain on which kind of boundary you attach it. Is it a fluid boundary? A solid boundary? Fluid-solid boundary?

Boh January 19, 2017 08:49

Thanks for your advice...I was using it on a shadow thread and that's way it didn't work...when I specified the cell using the F_C0(f,t) macro everything worked fine


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