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?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 16, 2019, 14:46
Default segmentation fault?
  #1
Member
 
Join Date: Apr 2017
Location: india
Posts: 96
Rep Power: 9
sooraj546 is on a distinguished road
Kindly read the attachment before going through the code.
sample explanation:
Add a source term to the cells adjacent to a wall
Problem/Description: How do I add a source term to the cells adjacent to a wall?
Solution:
A source term can be added with a UDF (using the macro ‘DEFINE_SOURCE’).
The UDF below enables: - To add a source term equals to 10 to the cells adjacent to the boundary with the ID equal to ‘boundaryID’ (defined below); - To add a source term equals to 5 to the other cells.
The source term is stored in User-Defined Memory (UDM) via the macro DEFINE_ON_DEMAND. The macro DEFINE_SOURCE returns the value of the UDM.
If the source term changes during the calculation, the DEFINE_ON_DEMAND macro can be adapted in a DEFINE_ADJUST macro.
Here is the code:
#include "udf.h"
/*
This UDF enables
- to add a source term equals to 10 to the cells adjacent to the boundary with the ID equals boundaryID (defined below);
- to add a source term equals to 5 to the other cells.
The source term is stored in User-Defined Memory (UDM) via the macro DEFINE_ON_DEMAND.
The macro DEFINE_SOURCE returns the value of the UDM.
If the source term changes during the calculation, the DEFINE_ON_DEMAND macro can be adapted in a DEFINE_ADJUST macro.
*/
int boundaryID=1;
DEFINE_SOURCE(source,c,t,dS,eqn)
{
return C_UDMI(c,t,0);
}
DEFINE_ON_DEMAND(on_demand_calc)
{
face_t f;
cell_t c;
Domain *domain=Get_Domain(1);
Thread *t;
thread_loop_c(t,domain)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,0)=5;
}
end_c_loop(c,t)
}
thread_loop_f(t,domain)
{
if (THREAD_ID(t)==boundaryID)
{
begin_f_loop(f,t)
{
C_UDMI(F_C0(f,t),THREAD_T0(t),0)=10;
}
end_f_loop(f,t)
}
}
Message0("\n\n UDF DONE \n\n");
}


My code:

DEFINE_ADJUST(calc,domain)
{

face_t f;
Thread *t;
real mf_co,mf_co2;/* variable declaration */
real c_co,c_co2;/* variable declaration */

int boundaryID=1; /*wall ID*/
thread_loop_f(t,domain)
{
if (THREAD_ID(t)==boundaryID)
{
begin_f_loop(f,t)
{

mf_co=C_YI(f, t, 3);
mf_co2=C_YI(f, t, 4);

conc_co=mf_co*C_R(f, t);

C_UDMI(F_C0(f,t),THREAD_T0(t),0)=-0.0092976*c_co;
}
end_f_loop(f,t)
}
Message0("\n\n UDF DONE \n\n");
}
}

DEFINE_SOURCE(CO_source,c,t,dS,eqn)
{
real x[ND_ND];
real source;
source = C_UDMI(F_C0(c,t),THREAD_T0(t),0);
dS[eqn] = 0.0;

return source;
}

segmentation fault is coming because of this line i guess : C_UDMI(F_C0(f,t),THREAD_T0(t),0)=-0.0092976*c_co;

Thanks a lot in advance . Kndly help me out to get rid of this ......................................
Attached Files
File Type: pdf UDF_Source.pdf (76.3 KB, 7 views)
sooraj546 is offline   Reply With Quote

Old   April 17, 2019, 01:19
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
try
Code:
DEFINE_ADJUST(calc,domain)
{

face_t f;
Thread *t;
real mf_co,mf_co2;/* variable declaration */
real c_co,c_co2;/* variable declaration */

int boundaryID=1; /*wall ID*/
thread_loop_f(t,domain)
{
if (THREAD_ID(t)==boundaryID)
{
begin_f_loop(f,t)
{

mf_co=F_YI(f, t, 3);
mf_co2=F_YI(f, t, 4);

conc_co=mf_co*F_R(f, t);

C_UDMI(F_C0(f,t),THREAD_T0(t),0)=-0.0092976*c_co;
}
end_f_loop(f,t)
}
Message0("\n\n UDF DONE \n\n");
}
}

DEFINE_SOURCE(CO_source,c,t,dS,eqn)
{
real source;
source = C_UDMI(c,t,0);
dS[eqn] = 0.0;
return source;
}
best regards
AlexanderZ is offline   Reply With Quote

Old   April 17, 2019, 05:13
Default
  #3
Member
 
Join Date: Apr 2017
Location: india
Posts: 96
Rep Power: 9
sooraj546 is on a distinguished road
thanks a lot for replying,

the highlighted step below has been changed by you to
source = C_UDMI(c,t,0);

But in reality the wall boundary flux is stored in C_UDMI(F_C0(f,t),THREAD_T0(t),0)=-0.0092976*c_co;

Kindly help me out.........as i am unsure about................... how to call this memory argument C_UDMI(F_C0(f,t),THREAD_T0(t),0)"


DEFINE_SOURCE(CO_source,c,t,dS,eqn)
{
real x[ND_ND];
real source;
source = C_UDMI(F_C0(c,t),THREAD_T0(t),0);
dS[eqn] = 0.0;

return source;
}
so is this representation correct?
sooraj546 is offline   Reply With Quote

Old   April 17, 2019, 21:55
Default
  #4
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
not correct

Code:
source = C_UDMI(c,t,0);
is correct

Read about C_UDMIs in Ansys Fluent Customization manual

best regards
AlexanderZ is offline   Reply With Quote

Old   April 18, 2019, 00:25
Default
  #5
Member
 
Join Date: Apr 2017
Location: india
Posts: 96
Rep Power: 9
sooraj546 is on a distinguished road
thanks a lot for that reply
sooraj546 is offline   Reply With Quote

Old   April 21, 2019, 02:33
Default
  #6
Member
 
Join Date: Apr 2017
Location: india
Posts: 96
Rep Power: 9
sooraj546 is on a distinguished road
when i add the adjust function its working and displaying msg UDF done etc but when i add the source term..........its hows the error as shown below.

I cant resolve it. Kindly help me out

================================================== ============================

Node 0: Process 2956: Received signal SIGSEGV.

================================================== ============================

================================================== ============================

Node 1: Process 13268: Received signal SIGSEGV.

================================================== ============================

================================================== ============================

Node 2: Process 4248: Received signal SIGSEGV.

================================================== ============================

================================================== ============================

Node 3: Process 3152: Received signal SIGSEGV.

================================================== ============================

================================================== ============================
sooraj546 is offline   Reply With Quote

Old   April 21, 2019, 21:41
Default
  #7
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
what did you put in source?

best regards
AlexanderZ is offline   Reply With Quote

Old   April 22, 2019, 00:48
Default
  #8
Member
 
Join Date: Apr 2017
Location: india
Posts: 96
Rep Power: 9
sooraj546 is on a distinguished road
DEFINE_ADJUST(calc,domain)
{

face_t f;
Thread *t;
real mf_co;/* variable declaration */
real c_co;/* variable declaration */

int boundaryID=1; /*wall ID*/
thread_loop_f(t,domain)
{
if (THREAD_ID(t)==boundaryID)
{
begin_f_loop(f,t)
{
mf_co=F_YI(f, t, 3);
c_co=mf_co*F_R(f, t);
C_UDMI(F_C0(f,t),THREAD_T0(t),6)=-0.0092976*c_co;
}
end_f_loop(f,t)
}
Message0("\n\n UDF DONE \n\n");
}
}

DEFINE_SOURCE(CO_source,c,t,dS,eqn)
{
real source;
source = C_UDMI(c,t,6);
dS[eqn] = 0.0;
return source;
}

this is the code there is nothing much in it to cause any big problem. My domain is just a sphere where all the volumetric reactions are happening thats all
sooraj546 is offline   Reply With Quote

Old   April 22, 2019, 00:54
Default
  #9
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
did you allocate 7 UDMS in fluent gui?

go to user defined -> Memory -> number of UDM Locations -> set 7 (at least)

best regards
AlexanderZ is offline   Reply With Quote

Old   April 22, 2019, 00:57
Default
  #10
Member
 
Join Date: Apr 2017
Location: india
Posts: 96
Rep Power: 9
sooraj546 is on a distinguished road
yes sir..................really sorry the error i am getting is
I cant resolve it. Kindly help me out

================================================== ============================

Node 0: Process 2956: Received signal SIGSEGV.

================================================== ============================

================================================== ============================

Node 1: Process 13268: Received signal SIGSEGV.
not segmentation fault

================================================== ============================

================================================== ============================

Node 2: Process 4248: Received signal SIGSEGV.

================================================== ============================

================================================== ============================

Node 3: Process 3152: Received signal SIGSEGV.

================================================== ============================

================================================== ============================
sooraj546 is offline   Reply With Quote

Old   April 22, 2019, 01:01
Default
  #11
Member
 
Join Date: Apr 2017
Location: india
Posts: 96
Rep Power: 9
sooraj546 is on a distinguished road
Is this because i am attaching C_UDMI(F_C0(f,t),THREAD_T0(t),6) i.e face into source which is kg/m3 etc............... ?
sooraj546 is offline   Reply With Quote

Old   April 22, 2019, 02:38
Default
  #12
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
i dont think so, make a contour of UDMI_6, what are max min values?
best regards
AlexanderZ is offline   Reply With Quote

Old   April 22, 2019, 03:24
Default
  #13
Member
 
Join Date: Apr 2017
Location: india
Posts: 96
Rep Power: 9
sooraj546 is on a distinguished road
F_YI(f, t, 3),F_R(f, t)
These two are the problem as its working when i give
C_UDMI(F_C0(f,t),THREAD_T0(t),6)=-0.0092976 its running fine

but when i introduce C_UDMI(F_C0(f,t),THREAD_T0(t),6)=-0.0092976*F_YI(f, t, 3)*F_R(f, t);
Updating solution at time level N... done.
iter continuity x-velocity y-velocity z-velocity energy fe3o4 feo fe co co2 c time/iter

================================================== ============================

Node 0: Process 6044: Received signal SIGSEGV.

================================================== ============================

================================================== ============================

Node 1: Process 3788: Received signal SIGSEGV.

================================================== ============================

================================================== ============================

Node 2: Process 11644: Received signal SIGSEGV. this error comes what to do.?
sooraj546 is offline   Reply With Quote

Old   April 22, 2019, 20:33
Default
  #14
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
check what you get you get using F_YI(f, t, 3) and F_R(f, t) using UDMs

best regards
AlexanderZ is offline   Reply With Quote

Old   April 23, 2019, 01:33
Default
  #15
Member
 
Join Date: Apr 2017
Location: india
Posts: 96
Rep Power: 9
sooraj546 is on a distinguished road
ok sir thanks a lot for ur reply
sooraj546 is offline   Reply With Quote

Old   April 23, 2019, 08:06
Default
  #16
Member
 
Join Date: Apr 2017
Location: india
Posts: 96
Rep Power: 9
sooraj546 is on a distinguished road
the F_YI(f, t, 3) is varying in an increasing pattern shown below and F_R(f, t) varying in an decreasing pattern similarly but dnt know y the overall code is not working.
C_UDMI(F_C0(f,t),THREAD_T0(t),6)=0.0092976*F_YI(f, t, 3) its running fine

but when i introduce C_UDMI(F_C0(f,t),THREAD_T0(t),6)=0.0092976*F_YI(f, t, 3)*F_R(f, t); still not working same error exits.
simlarly when i use C_UDMI(F_C0(f,t),THREAD_T0(t),6)=0.0092976*F_R(f, t); not working same error exits.

so the problem is with F_R(f, t)
what to do
Attached Images
File Type: jpg cosource.jpg (74.1 KB, 5 views)
sooraj546 is offline   Reply With Quote

Old   April 23, 2019, 10:12
Default
  #17
Member
 
Join Date: Apr 2017
Location: india
Posts: 96
Rep Power: 9
sooraj546 is on a distinguished road
there is a warning suggesting

.c(101) warning C4002: too many actual parameters for macro 'F_R'

when i use

C_UDMI(F_C0(f,t),THREAD_T0(t),6)=3*0.00972*F_YI(f, t, 3)*1000*F_R(f,t)/12; line 101

any suggestions sir?
sooraj546 is offline   Reply With Quote

Old   April 24, 2019, 00:44
Default
  #18
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
i dont see any problems in line
Code:
C_UDMI(F_C0(f,t),THREAD_T0(t),6)=3*0.00972*F_YI(f, t, 3)*1000*F_R(f,t)/12;
jowever, you may try to create additional variables for F_YI(f, t, 3) and F_R(f,t)
Code:
real species_mass_fraction, my_rho;
cell_t *c0;
Thread t0;

....
species_mass_fraction = F_YI(f, t, 3);
my_rho = F_R(f,t);
c0 = F_C0(f,t);
t0 = THREAD_T0(t);
C_UDMI(c0,t0,6)=3*0.00972*species_mass_fraction*1000*my_rho/12;
AlexanderZ is offline   Reply With Quote

Old   April 24, 2019, 01:13
Default
  #19
Member
 
Join Date: Apr 2017
Location: india
Posts: 96
Rep Power: 9
sooraj546 is on a distinguished road
same error is coming up sir. Is there any other way of getting individual species density
sooraj546 is offline   Reply With Quote

Old   April 25, 2019, 06:02
Default
  #20
Member
 
Join Date: Apr 2017
Location: india
Posts: 96
Rep Power: 9
sooraj546 is on a distinguished road
thanks a lot everyone.........I have solved it in a different way
sooraj546 is offline   Reply With Quote

Reply

Tags
udf


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
Segmentation fault when running dieselFoam or dieselEngineFoam in parallel francesco OpenFOAM Bugs 4 May 2, 2017 21:59
Segmentation fault in SU2 V5.0 ygd SU2 2 March 1, 2017 04:38
Segmentation fault when running in parallel Pj. OpenFOAM Running, Solving & CFD 3 April 8, 2015 08:12
Segmentation Fault w/ compiled OF 2.2.0 - motorBike example sudo OpenFOAM Running, Solving & CFD 3 April 2, 2013 17:27
segmentation fault when installing OF-2.1.1 on a cluster Rebecca513 OpenFOAM Installation 9 July 31, 2012 15:06


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