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

segmentation fault while defining boundary and interior face threads

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 18, 2019, 14:23
Default segmentation fault while defining boundary and interior face threads
  #1
Member
 
Durgesh
Join Date: Oct 2018
Posts: 34
Rep Power: 8
durg is on a distinguished road
Hello!

I am solving a problem in which species and energy equations are solved explicitly for single phase flows but problem is that in fluent as per my knowledge, there is no provision for solving explicitly for single phase flows. So, I am solving species and energy equations explicitly in udf under execute at end macros. In order to give zero-flux boundary condition, there is a need to recognize cells near the boundary so that I can give cells value to the boundary due to zero flux boundary condition.

Here I am writing a code to give zero-flux boundary condition in which I am getting a segmentation fault, please correct me:
I am avoiding to write here other variable inititialization as there is no compilation arror

cell_t c,c0,c1;
face_t f;
Thread *t,*t0,*tt;
Thread *ft,*tp;
Domain *dd;
dd = Get_Domain(1);
thread_loop_f(t,dd)
{
begin_c_loop(c,t)
{
if(THREAD_TYPE(t)==BOUNDARY_FACE_THREAD_P(t))
{
c0=F_C0(f,t);
t0=THREAD_T0(t);
timest=RP_Get_Real("physical-time-step");
if (NNULLP(THREAD_STORAGE(t,SV_DENSITY)))
dens = F_R(f,t); /* Set dens to face value if available */
else
dens = C_R(c0,t0); /* else, set dens to cell value */
NV_DS(psi_vec, =, F_U(f,t), F_V(f,th), F_W(f,t), *,dens);
flux = NV_DOT(psi_vec, A);
F_CENTROID(x0,f,t);
C_CENTROID(x2,c0,t0);
dx=x0[0]-x2[0];
dy=x0[1]-x2[1];
if(dx<0)
dx=-1*dx;
else if(dy<0)
dy=-1*dy;
conv_x=(timest/dx)*((F_UDSI(f,t,1)*MAX(flux,0)-F_UDSI(f,t,1)*MAX(-flux,0))-(F_UDSI(f,t,1)*MAX(flux,0)- F_UDSI(f,t,1)*MAX(-flux,0)));
conv_y=(timest/dy)*((C_UDSI(c0,t0,1)*MAX(flux,0)-F_UDSI(f,t,1)*MAX(-flux,0))- (F_UDSI(f,t,1)*MAX(flux,0)-C_UDSI(c0,t0,1)*MAX(-flux,0)));
rhoC=rhoC1-conv_x-conv_y;
rhom=((1-C_UDMI(c,t,1))*rho)+(C_UDMI(c,t,1)*rho);
F_UDSI(f,t,1)=rhoC/rhom;
}
else
{
c0=F_C0(f,t);
t0=THREAD_T0(t);
c1=F_C1(f,t);
tt=THREAD_T1(t);
C_CENTROID(x2,c0,t0);
C_CENTROID(x3,c1,tt);
dx=x2[0]-x3[0];
dy=x2[1]-x3[1];
if(dx<0)
dx=-1*dx;
else if(dy<0)
dy=-1*dy;
timest=RP_Get_Real("physical-time-step");
NV_DS(psi_vec, =, C_U(c0,t0),C_V(c0,t0),C_W(c0,t0),*,C_R(c0,t0));
NV_DS(psi_vec, +=, C_U(c1,tt),C_V(c1,tt),C_W(c1,tt),*,C_R(c1,tt));
flux = NV_DOT(psi_vec, A)/2.0; /* Average flux through face */
rhoC1=(C_UDMI(c,t,1)*C_UDMI(c,t,4)*rho)+((1-C_UDMI(c,t,1))*C_UDMI(c,t,7)*rhos);
conv_x=(timest/del_x)*((C_UDSI(c0,t0,1)*MAX(flux,0)-C_UDSI(c1,tt,1)*MAX(-flux,0))-(C_UDSI(c1,tt,1)*MAX(flux,0)-C_UDSI(c0,t0,1)*MAX(-flux,0)));
conv_y=(timest/del_y)*((C_UDSI(c0,t0,1)*MAX(flux,0)-C_UDSI(c1,tt,1)*MAX(-flux,0))-(C_UDSI(c1,tt,1)*MAX(flux,0)-C_UDSI(c0,t0,1)*MAX(-flux,0)));
rhoC=rhoC1-conv_x-conv_y;
rhom=((1-C_UDMI(c,t,1))*rhos)+(C_UDMI(c,t,1)*rho);
C_mix=rhoC/rhom;
C_UDSI(c,t,1)=C_mix;
}

/*****rest part of the code***/
}
end_c_loop(c,t)
}

If there is any provision of solving explicitly in fluent for single phase flows please let me know.

Regards
durg is offline   Reply With Quote

Old   April 19, 2019, 02:07
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
first of all check rhoC/rhom; using Message macro
what value do you have in rhom ?
using messgae you may find which line gives you error

best regards
AlexanderZ is offline   Reply With Quote

Old   April 19, 2019, 02:48
Default
  #3
Member
 
Durgesh
Join Date: Oct 2018
Posts: 34
Rep Power: 8
durg is on a distinguished road
Thank you for the reply!
As udf calculation starts it is entering in else condition and using message macro just below c0=F_C0(f,t) line , I found that error is in this line as message is not printing and giving segmentation fault. I think defining c0 is not correct but in many places it is defined like that for getting cell index near the boundary.

Regards
durg is offline   Reply With Quote

Old   April 19, 2019, 03:26
Default
  #4
Member
 
Durgesh
Join Date: Oct 2018
Posts: 34
Rep Power: 8
durg is on a distinguished road
Hello!

Earlier as soon as when udf else condition starts, it was giving me a segmentation fault. Then I used c_face_loop(c,t,n) macros under begin_c_loop(c,t) macros, it runs successfully for some time and then segmentation fault occurs and this I could not able to figure out why it is giving the error when else condition running properly. So, Using c_face_loop, I am able to run my else condition for some time, earlier I couldn't and value of rhoC and rhom are showing correctly.

I am trying to figure out why and where it is giving me segmentation fault after running for sometime, till I am waiting for help from all of you.

regards
durg is offline   Reply With Quote

Old   April 20, 2019, 10:07
Default
  #5
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Quote:
Originally Posted by durg View Post
I am solving a problem in which species and energy equations are solved explicitly for single phase flows but problem is that in fluent as per my knowledge, there is no provision for solving explicitly for single phase flows.
I have no idea what you mean with "provision for solving explicitly for single phase flows".

What do you want to do???

And it looks like you are more or less trying to get a zero-flux boundary of your scalar. If that is the case, there is a much easier way: just set a flux boundary, and put the flux at zero.
pakk is offline   Reply With Quote

Old   April 20, 2019, 12:18
Default
  #6
Member
 
Durgesh
Join Date: Oct 2018
Posts: 34
Rep Power: 8
durg is on a distinguished road
In fluent, all equations of momentum, energy and species for single phase flow it solves implicitly by default. Like in the methods section, under transient formulation there is only option for implicit formulation. But I want to solve energy and species explicitly, for which there is no option for choosing explicitly.
So, I am looking if in fluent whether we can choose explicit formulation in single phase model.

Yes I know I can give zero-flux boundary condition for scalar in boundary condition section but scalar will also solve through explicit by fluent. To solve explicitly I have written energy and species equations in explicit in udf, in which I tried to give boundary condition.

I hope I am able to make understand you. Anyway I have solve the issue of segmentation fault. But I am looking for information regarding preferably on first para and if there is any better way of doing for second para please let me know.

Regards
durg is offline   Reply With Quote

Old   April 20, 2019, 16:15
Default
  #7
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
I am a bit puzzled as to why you keep referring to "single phase". It appears like you can do it for multiphase but not for single phase, but that is probably not what you mean...

But anyway, you want to do it explicitly. Fluent is, as you read, built around implicit methods, so you would have to redo a lot. You do know that implicit and explicit methods that converge, converge to the same result? So for the end result, it does not matter.

Still, accepting that you really have a good reason to do it explicitly: you are using the wrong memory storage. You are using UDS, which you should avoid (for this purpose), and use UDM. As far as I am aware, Fluent does not allow you to write to UDS (you will get a segmentation fault), but you are allowed to write to UDM.
pakk is offline   Reply With Quote

Old   April 20, 2019, 17:18
Default
  #8
Member
 
Durgesh
Join Date: Oct 2018
Posts: 34
Rep Power: 8
durg is on a distinguished road
Thanks a lot!!. It's a good piece of information for me. Yeah, solving either through implicit/explicit should end up with the same result. Another thing, I tried one way to make scalar equation explicit by taking convective and diffusive term into source term using all old-time values and giving no diffusivity and flux function to fluent. Does by defining this way make problem to solve like explicit?

I am just curious to know because I tested by running simulation one by using energy models in fluent and other through UDS define like above and run for 200 secs. There was small difference in the results.

regards
durg is offline   Reply With Quote

Reply


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 15:49.