CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

UDF_transient

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   January 10, 2017, 09:28
Default UDF_transient
  #1
Boh
Member
 
Join Date: Sep 2016
Posts: 33
Rep Power: 9
Boh is on a distinguished road
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.
Boh is offline   Reply With Quote

Old   January 10, 2017, 12:26
Default
  #2
Senior Member
 
Kevin
Join Date: Dec 2016
Posts: 138
Rep Power: 9
KevinZ09 is on a distinguished road
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.
KevinZ09 is offline   Reply With Quote

Old   January 10, 2017, 12:46
Default
  #3
Boh
Member
 
Join Date: Sep 2016
Posts: 33
Rep Power: 9
Boh is on a distinguished road
I get the same error....
Boh is offline   Reply With Quote

Old   January 10, 2017, 14:46
Default
  #4
Senior Member
 
Kevin
Join Date: Dec 2016
Posts: 138
Rep Power: 9
KevinZ09 is on a distinguished road
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.
KevinZ09 is offline   Reply With Quote

Old   January 11, 2017, 06:07
Default
  #5
Boh
Member
 
Join Date: Sep 2016
Posts: 33
Rep Power: 9
Boh is on a distinguished road
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
Boh is offline   Reply With Quote

Old   January 11, 2017, 06:27
Default
  #6
Senior Member
 
Kevin
Join Date: Dec 2016
Posts: 138
Rep Power: 9
KevinZ09 is on a distinguished road
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.
KevinZ09 is offline   Reply With Quote

Old   January 11, 2017, 06:35
Default
  #7
Boh
Member
 
Join Date: Sep 2016
Posts: 33
Rep Power: 9
Boh is on a distinguished road
I still get the same error:
Error: received a fatal signal (Segmentation fault).
Error Object: #f
using F_R(f,t)
Boh is offline   Reply With Quote

Old   January 11, 2017, 07:23
Default
  #8
Senior Member
 
Kevin
Join Date: Dec 2016
Posts: 138
Rep Power: 9
KevinZ09 is on a distinguished road
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.
KevinZ09 is offline   Reply With Quote

Old   January 11, 2017, 10:47
Default
  #9
Boh
Member
 
Join Date: Sep 2016
Posts: 33
Rep Power: 9
Boh is on a distinguished road
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
Boh is offline   Reply With Quote

Old   January 13, 2017, 06:19
Default
  #10
Senior Member
 
Kevin
Join Date: Dec 2016
Posts: 138
Rep Power: 9
KevinZ09 is on a distinguished road
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.
KevinZ09 is offline   Reply With Quote

Old   January 13, 2017, 11:49
Default
  #11
Boh
Member
 
Join Date: Sep 2016
Posts: 33
Rep Power: 9
Boh is on a distinguished road
Thanks for the patience...I use a segregated solver. I have already tried. Thanks!
Boh is offline   Reply With Quote

Old   January 15, 2017, 07:56
Default
  #12
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
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?
pakk is offline   Reply With Quote

Old   January 19, 2017, 09:49
Default
  #13
Boh
Member
 
Join Date: Sep 2016
Posts: 33
Rep Power: 9
Boh is on a distinguished road
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
Boh is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On



All times are GMT -4. The time now is 04:55.