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

Error When Calling F_FLUX: received a fatal signal (segmentation fault)

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

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   November 18, 2020, 03:30
Question Error When Calling F_FLUX: received a fatal signal (segmentation fault)
  #1
New Member
 
Zhang Haosen
Join Date: Jun 2020
Posts: 3
Rep Power: 2
zimao is on a distinguished road

Hello, everyone!

I wrote an udf to compute the mass flow rate of the inlet surface, and the core code is simple, modified from another piece of code than can run normally in serial mode. The udf was compiled normally, but an “Segmentation fault” error was reported at runtime. After debugging, I think the bug appears in the process of calling F_FLUX, but I don't know how to modify it.

Can anyone help me, Thanks!

The code and debugging information are pasted below.


Code

PHP Code:
real compute_mass_flow(int zone_id)
{
#if !RP_HOST
    
face_t face;
    
Threadface_thread;
#endif // !RP_HOST
    
real face_mass_flow 0;
    
real mass_flow 0;
#if !RP_HOST
#if !PARALLEL
    
Message("\nbegin to compute mass flow 1\n");
#endif // !PARALLEL
    
if (face_thread Lookup_Thread(domainzone_id))
    {
#if !PARALLEL
        
Message("\nface thread opened correctly\n");
        
Message("\nface thread opened correctly\n");
#endif // !PARALLEL
    
}
#if !PARALLEL
    
Message("\nbegin to compute mass flow 2\n");
    
Message("\ndomain = %d\n"domain);
    
Message("\nzone id = %d\n"zone_id);
#endif // !PARALLEL
    
begin_f_loop(faceface_thread)
    {
#if !PARALLEL
        
Message("\ncheck f_flux\n");
#endif // !PARALLEL
        
face_mass_flow F_FLUX(faceface_thread);
        
mass_flow += face_mass_flow;
#if !PARALLEL
        
mass_flow_cont += 1;
        
Message("\nmass_flow_cont = %d\n"mass_flow_cont);
#endif // !PARALLEL

    
}
    
end_f_loop(faceface_thread)
#endif // !RP_HOST
#if !PARALLEL
        
Message(" \nmass flow computation ended\n");
#endif // !PARALLEL
    
return mass_flow;



Debugging information

PHP Code:
/* debugging information */
begin to compute mass flow 1

face thread opened correctly

face thread opened correctly

begin to compute mass flow 2

domain 
188266920

zone id 
12

check f_flux

Error
:  received a fatal signal (Segmentation fault).

Error:  received a fatal signal (Segmentation fault).
Error Object#f 
zimao is offline   Reply With Quote

Old   November 18, 2020, 21:58
Default Code is correct
  #2
New Member
 
Zhang Haosen
Join Date: Jun 2020
Posts: 3
Rep Power: 2
zimao is on a distinguished road
I didn't read in the .dat file...
zimao is offline   Reply With Quote

Old   November 19, 2020, 03:58
Default
  #3
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 1,638
Rep Power: 23
AlexanderZ will become famous soon enough
Quote:
In the density-based solver, F_FLUX(f,t) will only return a value if one or more scalar equations (for example, turbulence quantities) are being solved that require the mass flux of a face to be stored by the solver.
make sure, initialization in your model is correct. Not sure if mass flow rate is available before any iteration.

in addition, for parallel code I would use following code
Code:
real compute_mass_flow(int zone_id)
{
    face_t face;
    Thread* face_thread;
    real face_mass_flow = 0;
    real mass_flow = 0;
    Message0("\nbegin to compute mass flow 1\n");
    if (face_thread = Lookup_Thread(domain, zone_id))
    {
        Message0("\nface thread opened correctly\n");
        Message0("\nface thread opened correctly\n");
    }
    Message0("\nbegin to compute mass flow 2\n");
    Message0("\ndomain = %d\n", domain);
    Message0("\nzone id = %d\n", zone_id);
    begin_f_loop(face, face_thread)
    {
        Message0("\ncheck f_flux\n");
        face_mass_flow = F_FLUX(face, face_thread);
        mass_flow += face_mass_flow;
        mass_flow_cont += 1;
        Message0("\nmass_flow_cont = %d\n", mass_flow_cont);
    }
    end_f_loop(face, face_thread)
	#if RP_NODE
	mass_flow = PRF_GRSUM1(mass_flow);
	mass_flow_cont = PRF_GRSUM1(mass_flow_cont);
	#endif
    Message0(" \nmass flow computation ended\n");
    return mass_flow;
}
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   November 19, 2020, 09:44
Default
  #4
New Member
 
Zhang Haosen
Join Date: Jun 2020
Posts: 3
Rep Power: 2
zimao is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
make sure, initialization in your model is correct. Not sure if mass flow rate is available before any iteration.

in addition, for parallel code I would use following code
Code:
real compute_mass_flow(int zone_id)
{
    face_t face;
    Thread* face_thread;
    real face_mass_flow = 0;
    real mass_flow = 0;
    Message0("\nbegin to compute mass flow 1\n");
    if (face_thread = Lookup_Thread(domain, zone_id))
    {
        Message0("\nface thread opened correctly\n");
        Message0("\nface thread opened correctly\n");
    }
    Message0("\nbegin to compute mass flow 2\n");
    Message0("\ndomain = %d\n", domain);
    Message0("\nzone id = %d\n", zone_id);
    begin_f_loop(face, face_thread)
    {
        Message0("\ncheck f_flux\n");
        face_mass_flow = F_FLUX(face, face_thread);
        mass_flow += face_mass_flow;
        mass_flow_cont += 1;
        Message0("\nmass_flow_cont = %d\n", mass_flow_cont);
    }
    end_f_loop(face, face_thread)
	#if RP_NODE
	mass_flow = PRF_GRSUM1(mass_flow);
	mass_flow_cont = PRF_GRSUM1(mass_flow_cont);
	#endif
    Message0(" \nmass flow computation ended\n");
    return mass_flow;
}

Thanks for your reply!

Using Message0 can effectively simplify the code, and I didn't take into consideration the situation of using density-based solver. But how can I get mass flow rate when using density-based solver, by multiplying C_R_G, delta_r and F_U?

I seem to have seen related descriptions in the help documentation, that users can specify Fluent to save variables not saved originally, but I can't find these descriptions now.
zimao is offline   Reply With Quote

Old   November 19, 2020, 21:07
Default
  #5
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 1,638
Rep Power: 23
AlexanderZ will become famous soon enough
what I was trying to say, that F_flux should give you mass flow rate if all settings of case are correct.

Segmentation error comes out when you are asking for variables which are not allocated yet. So may be case was not initialized or anything else.

in Ansys Fluent Customization manual there is a code to calculate flux through surface:
Code:
#include "udf.h"
DEFINE_UDS_FLUX(my_uds_flux,f,t,i)
{
cell_t c0, c1 = -1;
Thread *t0, *t1 = NULL;
real NV_VEC(psi_vec), NV_VEC(A), flux = 0.0;
c0 = F_C0(f,t);
t0 = F_C0_THREAD(f,t);
F_AREA(A, f, t);
/* If face lies at domain boundary, use face values; */
/* If face lies IN the domain, use average of adjacent cells. */
if (BOUNDARY_FACE_THREAD_P(t)) /*Most face values will be available*/
{
real dens;
/* Depending on its BC, density may not be set on face thread*/
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,t), F_W(f,t), *, dens);
flux = NV_DOT(psi_vec, A); /* flux through Face */ }
else
{
c1 = F_C1(f,t); /* Get cell on other side of face */
t1 = F_C1_THREAD(f,t);
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,t1),C_V(c1,t1),C_W(c1,t1),*,C_R(c1,t1));
flux = NV_DOT(psi_vec, A)/2.0; /* Average flux through face */
}
/* ANSYS Fluent will multiply the returned value by phi_f (the scalar’s
value at the face) to get the ‘‘complete’’ advective term. */
return flux;
}
you may modify this code little bit, cause you don't need DEFINE_UDS_FLUX macro
change it to face/thread loop instead. define thread ID, cause you know where you would like to get mass flow rate (you may check ID in Fluent GUI)
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Reply

Tags
f_flux, mass flow rate, parallel

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
fluentError: received a fatal signal (Segmentation fault). thomaszhangjing Fluent UDF and Scheme Programming 11 January 13, 2021 09:37
Error: received a fatal signal (Segmentation fault). Error Object: #f Naveen Kumar Gulla FLUENT 0 May 18, 2018 14:12
received a fatal signal (Segmentation fault) using udf to reading node coordinate f.yn FLUENT 1 July 28, 2017 15:55
Error: received a fatal signal (Segmentation fault). MayTheFlowBeWithYou FLUENT 12 June 30, 2017 03:09
receive fluent received a fatal signal (Segmentation fault). chenkaiqe FLUENT 2 March 10, 2015 08:21


All times are GMT -4. The time now is 05:56.