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

Getting segmentation fault in below code

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   October 9, 2018, 02:43
Default Getting segmentation fault in below code
  #1
Member
 
Durgesh
Join Date: Oct 2018
Posts: 34
Rep Power: 7
durg is on a distinguished road
Hello!
I am getting a segmentation fault error in below code while going for running the calculation in fluent. Please help me with this. I have tried to resolve this but couldn't do it.
Here I am trying to calculate the liquid fraction and updating in the fluent. Please tell me what to do?

Thank you

Below is the code







#include "udf.h"

DEFINE_INIT(my_init_func, d)
{
cell_t c;
Thread *t;
/* loop over all cell threads in the domain */
d = Get_Domain(1);
thread_loop_c (t,d)
{
//printf("Hello");
/* loop over all cells */
begin_c_loop_all (c,t)
{
C_UDMI(c,t,0)=1; // Liquid fraction current step value
C_UDMI(c,t,1)=1; // Liquid fraction previous step value
C_UDMI(c,t,2)=1; //Temperature modified value
//C_UDMI(c,t,3)=0;
//C_UDMI(c,t,3)=0.40; //Species value
}
end_c_loop_all (c,t)
}
}

//---------------------------Defining constant values for adjust macros-----------------------------------------------

#define rho 11340 // constant density
#define L 24700 // Latent Heat
#define cl 154.9 // Liquid specific heat
#define cs 128 // Solid specific heat
#define Tf 600.5 // Fusion Temperature
#define Te 456.14 //Eutectic Temperature
#define C_eut 0.619 //Eutectic concentration
DEFINE_ADJUST(liquid_fraction,d)
{
cell_t c;
Thread *t;
//printf("Hello");
real rhoH,rhocp,tf,m;
real g;
real lamda;
//printf("Hello");
tf=0.0;
m=(Te-Tf)/C_eut;
printf("Value of m: %f\n",m);
// C_UDMI(c,t,1)=C_LIQF(c,t);
printf("Hello");
//rhocp= rho*(C_UDMI(c,t,1)*cl+(1-C_UDMI(c,t,1))*cs);
//printf("Value of rhocp: %f\n",rhocp);
//rhoH=rhocp*C_T(c,t);
//printf("Value of rhoH: %f\n",rhoH);
//g=(rhoH-(rho*cl*C_T_M1(c,t)))/(rho*L);
//printf("Value of liquidfraction: %f\n",g);
d = Get_Domain(1);
//printf("Hello");
thread_loop_c (t,d)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,1)=C_LIQF(c,t);
rhocp= rho*(C_UDMI(c,t,1)*cl+(1-C_UDMI(c,t,1))*cs);
printf("Value of rhocp: %f\n",rhocp);
rhoH=rhocp*C_T(c,t);
printf("Value of rhoH: %f\n",rhoH);
g=(rhoH-(rho*cl*C_T_M1(c,t)))/(rho*L);
printf("Value of g is: %f\n",g);
if(g>1)
C_UDMI(c,t,0)=1;
else if(0<g<=1)
{
C_UDMI(c,t,1)=C_LIQF(c,t);
C_UDMI(c,t,0)=0.5*(C_UDMI(c,t,1))+0.5*(rhoH-rhocp*C_T_M1(c,t))/(rho*L);
if(C_UDMI(c,t,1)-(C_UDMI(c,t,0))<0.0001)
{
C_LIQF(c,t)=C_UDMI(c,t,0);
tf=tf+0.01;
lamda=pow(10,((1.25+0.36*log(tf))/log(10)));
printf("Value of lamda: %f\n",lamda);
printf("Value of solidification time: %f\n",tf);

}
}
}
end_c_loop(c,t)
C_UDMI(c,t,2)=Tf-m*C_YI(c,t,0);
C_T(c,t)=C_UDMI(c,t,2);
//C_YI(c,t,0)=C_UDMI(c,t,3)/C_UDMI(c,t,0);
}
}
durg is offline   Reply With Quote

Old   October 9, 2018, 04:16
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
You have shown two UDFs in your code. Which one gives the problem?


If it is the first one, the DEFINE_INIT: did you remember to add three UDMs in Fluent?
pakk is offline   Reply With Quote

Old   October 9, 2018, 05:44
Default
  #3
Member
 
Durgesh
Join Date: Oct 2018
Posts: 34
Rep Power: 7
durg is on a distinguished road
Error is from the adjust macros. I have defined three memory in fluent. Please help me in second udf.
durg is offline   Reply With Quote

Old   October 9, 2018, 21:38
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
did you compile this UDF?
It is recommended to use Message macro instead of printf

best regards
AlexanderZ is offline   Reply With Quote

Old   October 10, 2018, 02:13
Default
  #5
Member
 
Durgesh
Join Date: Oct 2018
Posts: 34
Rep Power: 7
durg is on a distinguished road
Hello!
Yes I have compiled the udf, it is ok. Problem is that in second udf I am trying to store previous time step value of the temperature with UDM and when I am going for calculation in the fluent it is giving me a segmentation fault but when I am removing the code of storing previous temperature value then it is ok.

I have tried several times by changing the position of the code for the previous value of temperature but it is not working. Please tell me where to put the code line for this. Now the problem is with storing the previous time value for the temperature value.

Thank you



#include "udf.h"

DEFINE_INIT(my_init_func, d)
{
cell_t c;
Thread *t;
/* loop over all cell threads in the domain */
d = Get_Domain(1);
thread_loop_c (t,d)
{
//printf("Hello");
/* loop over all cells */
begin_c_loop_all(c,t)
{
C_UDMI(c,t,0)=1; // Liquid fraction current step value
C_UDMI(c,t,1)=1; // Liquid fraction previous step value
C_UDMI(c,t,2)=1; //Temperature previous step value
C_UDMI(c,t,3)=0; //Temperature current step value
//C_UDMI(c,t,3)=0.40; //Species value
}
end_c_loop_all(c,t)
}
}

//---------------------------Defining constant values for adjust macros-----------------------------------------------

#define rho 11340 // constant density
#define L 24700 // Latent Heat
#define cl 154.9 // Liquid specific heat
#define cs 128 // Solid specific heat
#define Tf 600.5 // Fusion Temperature
#define Te 456.14 //Eutectic Temperature
#define C_eut 0.619 //Eutectic concentration

DEFINE_ADJUST(liquid_fraction,d)
{
cell_t c;
Thread *t;
//printf("Hello");
real rhoH,rhocp,tf,m;
real g;
real lamda;
//printf("Hello");
tf=0.0;
m=(Te-Tf)/C_eut;
printf("Value of m: %f\n",m);
// C_UDMI(c,t,1)=C_LIQF(c,t);
printf("Hello");
//rhocp= rho*(C_UDMI(c,t,1)*cl+(1-C_UDMI(c,t,1))*cs);
//printf("Value of rhocp: %f\n",rhocp);
//rhoH=rhocp*C_T(c,t);
//printf("Value of rhoH: %f\n",rhoH);
//g=(rhoH-(rho*cl*C_T_M1(c,t)))/(rho*L);
//printf("Value of liquidfraction: %f\n",g);
d = Get_Domain(1);
//printf("Hello");
thread_loop_c (t,d)
{
begin_c_loop(c,t)
{
//printf("hello");
C_UDMI(c,t,1)=C_LIQF(c,t);
//C_UDMI(c,t,2)=C_T_M1(c,t);
C_UDMI(c,t,3)=C_T(c,t);
rhocp= rho*(C_LIQF(c,t)*cl+(1-C_LIQF(c,t))*cs);
printf("Value of rhocp: %f\n",rhocp);
rhoH=rhocp*C_T(c,t);
printf("Value of rhoH: %f\n",rhoH);
g=(rhoH-(rho*cl*C_UDMI(c,t,2)))/(rho*L);
printf("Value of g is: %f\n",g);
if(g>1)
C_UDMI(c,t,0)=1;
else if(0<g<=1)
{
//C_UDMI(c,t,1)=C_LIQF(c,t);
C_UDMI(c,t,0)=0.5*(C_UDMI(c,t,1))+0.5*(rhoH-rhocp*C_UDMI(c,t,2))/(rho*L);
if(C_UDMI(c,t,1)-(C_UDMI(c,t,0))<0.0001)
{
C_LIQF(c,t)=C_UDMI(c,t,0);
tf=tf+0.01;
lamda=pow(10,((1.25+0.36*log(tf))/log(10)));
printf("Value of lamda: %f\n",lamda);
printf("Value of solidification time: %f\n",tf);
}
}
//C_UDMI(c,t,2)=C_T_M1(c,t);
}
end_c_loop(c,t)
//C_UDMI(c,t,2)=C_T_M1(c,t);
C_UDMI(c,t,3)=Tf-m*C_YI(c,t,0);
C_T(c,t)=C_UDMI(c,t,3);
//C_YI(c,t,0)=C_UDMI(c,t,3)/C_UDMI(c,t,0);
}
//C_UDMI(c,t,2)=C_T_M1(c,t);
}
durg is offline   Reply With Quote

Old   October 10, 2018, 22:15
Default
  #6
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
how can you get temperature from the previous time step on the first timestep?
that is why you get segmentation error, which means problem with memory.

to avoid this problem you may read temperature from previous timestep from the second timestep using
Code:
N_TIME
macro
N_TIME returns integer number of time steps

so your code may looks like
Code:
if (N_TIME>1) C_UDMI(c,t,2)=C_T_M1(c,t);
best regards
AlexanderZ is offline   Reply With Quote

Old   October 11, 2018, 08:14
Default
  #7
Member
 
Durgesh
Join Date: Oct 2018
Posts: 34
Rep Power: 7
durg is on a distinguished road
Thanks, AlexanderZ for your suggestions. I have tried using N_TIME macros as N_TIME>1 but it is giving me a segmentation fault. Then I tried using macros CURRENT_TIME>0.01 as I have defined in my problem timestep size=0.01, it starts running only in this case and the statement C_UDMI(c,t,2)=C_T_M1(c,t) does not have any effect, as it keeps on giving me a constant value of C_UDMI(c,t,2)=1. I also tried using macros CURRENT_TIME but it failed.
And also when I used C_YI_M1(c,t,0) in one case, on this no segmentation fault got but for temperature case it is giving the error. Please let me know why it is happening.

Thank you.
durg is offline   Reply With Quote

Old   October 12, 2018, 01:13
Default
  #8
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
From Ansys FLuent Customization manual
Quote:
Important
Note that data from C_T_M1 is available only if user-defined scalars are defined. It can also
be used with adaptive time stepping.
I've never used C_T_M1 macro.
You may write temperature into UDMI manually on previous timestep and read it on the next.

I recommend to use DEFINE_EXECUTE_AT_END macro to fill your UDMI with temperature.

best regards
AlexanderZ is offline   Reply With Quote

Old   October 12, 2018, 10:39
Default
  #9
Member
 
Durgesh
Join Date: Oct 2018
Posts: 34
Rep Power: 7
durg is on a distinguished road
With DEFINE_AT_END macro it didn't work. As shown below:

DEFINE_EXECUTE_AT_END(calculate_end)
{
cell_t c;
Thread*t;
Domain*d;
d=Get_Domain(1);
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,2)=C_T_M1(c,t);
}
end_c_loop(c,t)
}


}

I tried above without loop also but it didn't work.

After all this, the problem is due to C_T_M1 only. Instead, I am thinking to use below code to interchange between current-previous temperature value but where to write the statement in the loop because both of them take the same value as I think when I write them together in the loop.

C_UDMI(c,t,2) //UDM for previous value temperature
C_UDMI(c,t,3) //UDM for current value temperature
C_UDMI(c,t,3)=C_T(c,t);
if(N_TIME>=2)
C_UDMI(c,t,2)=C_UDMI(c,t,3);

One more problem is occurring which is in the fluent calculation, there is no change in species concentration where I am solving species equation through fluent only. Please throw light on this.

Thank you
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


Similar Threads
Thread Thread Starter Forum Replies Last Post
[OpenFOAM.org] Paraview 5.4 in shell environment of5x - Segmentation fault (core dumped) dslbkxd OpenFOAM Installation 1 February 3, 2018 00:56
UDM segmentation fault. Tushar_Telmasre Fluent UDF and Scheme Programming 1 March 24, 2017 05:45
Fluent 17 Get_Domain segmentation fault ! hamidnankali Fluent UDF and Scheme Programming 0 September 14, 2016 10:17
[OpenFOAM] Segmentation Fault on start - pvserver using o/s rendering, remote on cluster chrisb2244 ParaView 2 June 8, 2014 21:26
Design Integration with CFD? John C. Chien Main CFD Forum 19 May 17, 2001 15:56


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