|
[Sponsors] |
January 10, 2017, 09:28 |
UDF_transient
|
#1 |
Member
Join Date: Sep 2016
Posts: 33
Rep Power: 10 |
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 Last edited by Boh; January 10, 2017 at 10:39. |
|
January 10, 2017, 12:26 |
|
#2 |
Senior Member
Kevin
Join Date: Dec 2016
Posts: 138
Rep Power: 10 |
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.
|
|
January 10, 2017, 12:46 |
|
#3 |
Member
Join Date: Sep 2016
Posts: 33
Rep Power: 10 |
I get the same error....
|
|
January 10, 2017, 14:46 |
|
#4 |
Senior Member
Kevin
Join Date: Dec 2016
Posts: 138
Rep Power: 10 |
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.
|
|
January 11, 2017, 06:07 |
|
#5 |
Member
Join Date: Sep 2016
Posts: 33
Rep Power: 10 |
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 |
|
January 11, 2017, 06:27 |
|
#6 |
Senior Member
Kevin
Join Date: Dec 2016
Posts: 138
Rep Power: 10 |
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.
|
|
January 11, 2017, 06:35 |
|
#7 |
Member
Join Date: Sep 2016
Posts: 33
Rep Power: 10 |
I still get the same error:
Error: received a fatal signal (Segmentation fault). Error Object: #f using F_R(f,t) |
|
January 11, 2017, 07:23 |
|
#8 |
Senior Member
Kevin
Join Date: Dec 2016
Posts: 138
Rep Power: 10 |
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. |
|
January 11, 2017, 10:47 |
|
#9 |
Member
Join Date: Sep 2016
Posts: 33
Rep Power: 10 |
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 |
|
January 13, 2017, 06:19 |
|
#10 |
Senior Member
Kevin
Join Date: Dec 2016
Posts: 138
Rep Power: 10 |
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. |
|
January 13, 2017, 11:49 |
|
#11 |
Member
Join Date: Sep 2016
Posts: 33
Rep Power: 10 |
Thanks for the patience...I use a segregated solver. I have already tried. Thanks!
|
|
January 15, 2017, 07:56 |
|
#12 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
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? |
|
January 19, 2017, 09:49 |
|
#13 |
Member
Join Date: Sep 2016
Posts: 33
Rep Power: 10 |
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
|
|
|
|