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

DPM-UDF-Segmentation fault

Register Blogs Community New Posts Updated Threads Search

Like Tree2Likes
  • 2 Post By pakk

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 7, 2017, 17:11
Default DPM-UDF-Segmentation fault
  #1
Member
 
yun
Join Date: Jul 2015
Posts: 37
Rep Power: 11
gush is on a distinguished road
hi everyone!

i receive an error while trying to execute a udf, the error message is:
"Error: received a fatal signal (Segmentation fault).
Error Object: #f"

my case is very simple, i would like to get the volume of the cells and flow rate of the particles for now. if i can accomplish it i will change it with more complex problems.

i can compile the udf and load it without any problem. in the problem, i do not interact the continuos phase with the discrete phase(one way coupling) because discrete phase has no affect on the continuous phase. so i can display the particle tracks via Results>Graphics and animations>Particle Tracks>Set up.

i am not experienced on UDF issue and coding. maybe it is very simple but i could not get any proper answer from the forum or from other code examples.

here is the code:
#include "udf.h"
#include "dpm.h"

DEFINE_ON_DEMAND(PSIC)
{
Domain *d;
Thread *t;
cell_t c;
Tracked_Particle *p;

real flowrate;
real volume;

d = Get_Domain(1);
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
volume = C_VOLUME(c,t); /* get cell volume */
flowrate = P_FLOW_RATE(p); /* get flow rate */
C_UDMI(c,t,0) = flowrate/volume;
}
end_c_loop(c,t)
}
}
gush is offline   Reply With Quote

Old   April 10, 2017, 08:02
Default
  #2
Member
 
yun
Join Date: Jul 2015
Posts: 37
Rep Power: 11
gush is on a distinguished road
well i think i found out in the manual that P_FLOW_RATE can only be used with DPM MAcros! so i think, i need to use DEFINE_DPM_OUTPUT somehow. but still stuck here.

i need the particle flow rate (kg/s) in each cell. can anyone have any idea?! i am quite new in UDF and this forum is the only interactive source for me! thanks in advance.
gush is offline   Reply With Quote

Old   April 10, 2017, 14:46
Default
  #3
New Member
 
Swapnil Chavanda
Join Date: Jan 2017
Location: Pune
Posts: 19
Rep Power: 9
swpnl9282@gmail.com is on a distinguished road
Quote:
Originally Posted by gush View Post
hi everyone!

i receive an error while trying to execute a udf, the error message is:
"Error: received a fatal signal (Segmentation fault).
Error Object: #f"

my case is very simple, i would like to get the volume of the cells and flow rate of the particles for now. if i can accomplish it i will change it with more complex problems.

i can compile the udf and load it without any problem. in the problem, i do not interact the continuos phase with the discrete phase(one way coupling) because discrete phase has no affect on the continuous phase. so i can display the particle tracks via Results>Graphics and animations>Particle Tracks>Set up.

i am not experienced on UDF issue and coding. maybe it is very simple but i could not get any proper answer from the forum or from other code examples.

here is the code:
#include "udf.h"
#include "dpm.h"

DEFINE_ON_DEMAND(PSIC)
{
Domain *d;
Thread *t;
cell_t c;
Tracked_Particle *p;

real flowrate;
real volume;

d = Get_Domain(1);
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
volume = C_VOLUME(c,t); /* get cell volume */
flowrate = P_FLOW_RATE(p); /* get flow rate */
C_UDMI(c,t,0) = flowrate/volume;
}
end_c_loop(c,t)
}
}
To avoid this
Please set number of memory locations in UDF

Sent from my Moto G (4) using CFD Online Forum mobile app
swpnl9282@gmail.com is offline   Reply With Quote

Old   April 10, 2017, 14:47
Default
  #4
New Member
 
Swapnil Chavanda
Join Date: Jan 2017
Location: Pune
Posts: 19
Rep Power: 9
swpnl9282@gmail.com is on a distinguished road
As 1
Because in your UDF as above it has only one UDMI

Sent from my Moto G (4) using CFD Online Forum mobile app
swpnl9282@gmail.com is offline   Reply With Quote

Old   April 10, 2017, 15:01
Default
  #5
Member
 
yun
Join Date: Jul 2015
Posts: 37
Rep Power: 11
gush is on a distinguished road
thank you for the answer Swapnil!

do you mean i need to use one more "c_UDMI(c,t,1)....." after the first one??
can you please be more specific with an example?
gush is offline   Reply With Quote

Old   April 11, 2017, 09:25
Default
  #6
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
There problems in your code are in the following lines:

Code:
flowrate = P_FLOW_RATE(p); /* get flow rate */
C_UDMI(c,t,0) = flowrate/volume;
As the other commenter says, you need at least one UDM enabled to be able to write to a UDM in the second line. Maybe you have this, it is not something we can see from the code. To set this, go in Fluent to 'user-defined', 'Memory', and set the number to 1.

But what is definitely a problem is the first line above. You ask for the flow rate of "p". What is "p"? Fluent does not know. The compiler only knows that it points to a "Tracked_Particle", but you never specified which particle.

You probably mean: the particle in the current cell that I am analyzing. But there might be no particle, or more than one particle. Luckily, Fluent made a macro that finds all particles in a cell. To use it, you can use this code:

Code:
flowrate=0;
begin_particle_cell_loop(p,c,t)
{
   flowrate += P_FLOW_RATE(p);
}
end_particle_cell_loop(p,c,t)
C_UDMI(c,t,0) = flowrate/volume;
Code not tested, so it might contain typos/errors.


A conceptually better solution is probably to stop looping over all cells, but loop over all particles directly, using begin_particle_loop. But this is enough for now.
gush and souza.emer like this.
pakk is offline   Reply With Quote

Old   April 11, 2017, 09:42
Default
  #7
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
And I just realized that you will run into another problem: you say you want to know the flowrate of "the particles". Which particles? At which moment?

Suppose that a particle starts in cell A, moves through cells B and C, and leaves the simulation through cell D, in which cell do you want the flow rate to be counted?

It is quite possible that the current UDF chooses something else than you do. (Maybe the UDF even ignores all particles, because in an uncoupled DPM simulation the particles only 'exist' during the DPM calculation. I don't know.) But it start by knowing what YOU want the UDF to do.
pakk is offline   Reply With Quote

Old   April 11, 2017, 10:12
Default
  #8
Member
 
yun
Join Date: Jul 2015
Posts: 37
Rep Power: 11
gush is on a distinguished road
Quote:
Originally Posted by pakk View Post
And I just realized that you will run into another problem: you say you want to know the flowrate of "the particles". Which particles? At which moment?

Suppose that a particle starts in cell A, moves through cells B and C, and leaves the simulation through cell D, in which cell do you want the flow rate to be counted?

It is quite possible that the current UDF chooses something else than you do. (Maybe the UDF even ignores all particles, because in an uncoupled DPM simulation the particles only 'exist' during the DPM calculation. I don't know.) But it start by knowing what YOU want the UDF to do.
thank you very much for your inspiring answer pakk!

well, what i really want to calculate is the concentration in the each cell. i know it is possible to get concentration values when interaction is enabled. but i dont need interaction of phases. and i should mention that the problem is steady also.

so i need to know the flow rate of particle in each cell, particle residence time in that cell and volume of the cell. then i can calculate the concentration via: [flow rate of particles (kg/s) *particle residence time (s) ] / volume of the cell (m3).

but unfortunately my coding is just one week old. after the long investigations in the forum and the manual, i think i need to use DEFINE_DPM_OUTPUT rather than on_demand. what do you think?

i will try to write and compile a code and inform you accordingly.
thank you very much!
gush is offline   Reply With Quote

Old   April 11, 2017, 10:24
Default
  #9
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
I don't know what is best for you, because I don't know what you need.

Quote:
what i really want to calculate is the concentration in the each cell
The concentration of what?
  • Of particles in the beginning of the DPM calculation.
  • Of particles at the end of the DPM calculation.
  • Of particles at any point in their calculation.
  • Something else.
You should answer this question. Not for me (I don't care ), but for yourself: the code that you need, depends on the answer.
pakk is offline   Reply With Quote

Old   April 11, 2017, 10:32
Default
  #10
Member
 
yun
Join Date: Jul 2015
Posts: 37
Rep Power: 11
gush is on a distinguished road
Quote:
Originally Posted by pakk View Post
I don't know what is best for you, because I don't know what you need.



The concentration of what?
  • Of particles in the beginning of the DPM calculation.
  • Of particles at the end of the DPM calculation.
  • Of particles at any point in their calculation.
  • Something else.
You should answer this question. Not for me (I don't care ), but for yourself: the code that you need, depends on the answer.
the concentration of particles in steady state. at the end of DPM calculation.

i know you dont care but i need your experienced comments!
gush is offline   Reply With Quote

Old   April 11, 2017, 10:47
Default
  #11
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Your liquid is in steady state, your particles most likely are not.

Suppose that I throw a ball at you, and you catch it. (In this analogy, the ball is a particle, the throwing is a dpm simulation.) We are standing in a room where there is no wind (so specifically, the gas flows are steady state).

If your script would be run on this situation, which cell should get a value? The cell containing my hand? The cell containing your hand? Or the cells along the trajectory of the ball?


And if I throw the ball out of a window, so the ball ends up outside the simulation domain. What do you want the script to do with such a ball?

(at the end of the simulation, your particles are 'nowhere', unless you have unfinished trajectories)
pakk is offline   Reply With Quote

Old   April 12, 2017, 05:23
Default
  #12
Member
 
yun
Join Date: Jul 2015
Posts: 37
Rep Power: 11
gush is on a distinguished road
Quote:
Originally Posted by pakk View Post
Your liquid is in steady state, your particles most likely are not.

Suppose that I throw a ball at you, and you catch it. (In this analogy, the ball is a particle, the throwing is a dpm simulation.) We are standing in a room where there is no wind (so specifically, the gas flows are steady state).

If your script would be run on this situation, which cell should get a value? The cell containing my hand? The cell containing your hand? Or the cells along the trajectory of the ball?


And if I throw the ball out of a window, so the ball ends up outside the simulation domain. What do you want the script to do with such a ball?

(at the end of the simulation, your particles are 'nowhere', unless you have unfinished trajectories)
both phases are in steady state. the velocity values of the fluid and the concentration values of the particles are not changing in time on the whole domain.
all cells should get a value. in your analogy; your hand, my hand and the trajectory also.
if you throw the ball out of the window DPM simulation terminates the trajectory at that point.
gush is offline   Reply With Quote

Old   April 12, 2017, 05:38
Default
  #13
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
But your individual particles are NOT in steady state. They move.

You say all cells along the trajectory should get a value. That is possible (computationally), but then you should make clear what value. What should it physically represent?

I can only imagine one thing: the mass of the particles that are on average in this cell volume. (so unit kg)

Then you have to use a macro that is called on every DPM timestep, such as DPM_scalar_update.

The mass flow rate (P_MASS_FLOW(p)) has units kg/s, so you would need to multiply it with the length of the DPM timestep.
pakk is offline   Reply With Quote

Old   April 12, 2017, 06:26
Default
  #14
Member
 
yun
Join Date: Jul 2015
Posts: 37
Rep Power: 11
gush is on a distinguished road
Quote:
Originally Posted by pakk View Post
But your individual particles are NOT in steady state. They move.

You say all cells along the trajectory should get a value. That is possible (computationally), but then you should make clear what value. What should it physically represent?

I can only imagine one thing: the mass of the particles that are on average in this cell volume. (so unit kg)

Then you have to use a macro that is called on every DPM timestep, such as DPM_scalar_update.

The mass flow rate (P_MASS_FLOW(p)) has units kg/s, so you would need to multiply it with the length of the DPM timestep.
individual fluid molecules are also not in steady state. but the concentration values and velocity values are steady. and these are the values i need.

thanks again, i will follow your comments.
gush is offline   Reply With Quote

Old   April 13, 2017, 05:19
Default
  #15
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
The difference is that you are not simulating the positions of the individual fluid molecules, but you are simulating the positions of the individual DPM particles.

Good luck!
pakk is offline   Reply With Quote

Old   May 16, 2017, 06:53
Default UFD of DPM
  #16
New Member
 
Join Date: Jan 2017
Posts: 25
Rep Power: 9
sewgolam is on a distinguished road
Dear sir,

I'm simulating particle in a reactangular domain by using DPM.For that i used a UDF.I'm succesfully complie the UDF but when i'm running it give my e error receive segmental error.Can you help me if ther is a error in my code of where the problem may be:

UDF for the Discrete Phase Model solar reactor
************************************************** *********************/

#include "math.h"
#include "udf.h"
#include "dpm.h"
#include "sg_mem.h"
#include "surf.h" /* for macros: RP_Cell() & RP_Thread() */
#include "prop.h"
#include "pdf_transport.h"


/* GLOBAL CONSTANTS */
#define K0 1.07e6 /*1/s */
#define RHO_C_EXP 8.84 /*mol/m^3 */
#define EA 147.0e3 /*J/mol */
#define M_CH4 16.04e-3 /* kg/mol */
#define M_C 12.01e-3 /* kg/mol */
#define M_H2 4.00e-3/* kg/mol */
#define T_REF1 298. /* K */
#define RG 8.31434 /* Universal gas constant J/mol.K */


DEFINE_DPM_LAW(ParticleLaws,p,coupled)
{
Material *m = P_MATERIAL(p);
cell_t c = P_CELL(p); /* Get Cell and Thread from */
cphase_state_t *cell = &(p->cphase); /* cell information of particle location*/
Thread *t = P_CELL_THREAD(p); /* Particle Structure using new macros*/


real dp, Tp, Tg, Vmix, Vp, Ap, rho_CH4, rho_p, theta_r;
real r_Cex, r_Cmol, r_C, r_H2mol, r_CH4mol;
real h_CH4mol, h_Cmol, h_H2mol, gammadot;
real alpha_p, beta_p;
real Pr, Nu, U;
int CH4 = 0; /* First in list! */

dp= P_DIAM(p);/* Particle diameter */

/*new comment added*/
printf("Content of variable dp is: %d\n", dp); /* \n denotes a new line */

Tp = P_T(p);/* Particle temperature */
Tg = C_T(c,t);/* Gas mixture temperature */
Vmix = C_VOLUME(c,t);/* Gas mixture volume in the cell*/
Vp = M_PI/6.0 * pow(dp,3);/* Particle volume */
Ap = M_PI*pow(dp,2); /* Particle surface */

/* Methane molar density [mol/m^3] */
rho_CH4 = C_YI(c,t,CH4)*C_R(c,t)/M_CH4;

/* Carbon particle molar density [mol/m^3] */
rho_p = C_DPMS_CONCENTRATION(c,t)/M_C;

/* Experimental law for carbon reaction rate [s^-1] from Maag 2011 pag.7 */
r_Cex = K0 * exp(-EA/(Tp*RG)) * rho_CH4/RHO_C_EXP;

/* Molar reaction rates [mol/m^3.s] */
r_Cmol = P_RHO(p)*r_Cex/M_C;
r_CH4mol = -r_Cmol;
r_H2mol = 2.*r_Cmol;

r_C = r_Cmol*M_C;


/* Advance particle mass in time using explicit euler */
if(r_C>0.0)
{

P_MASS(p) = P_MASS(p)/(1-P_DT(p)*r_C/P_RHO(p));
/* P_MASS(p) = P_MASS(p) + P_DT(p) * r_C*Vp;*/

/* Diamter grows, density remans constant */
P_DIAM(p) = pow(6.0*P_MASS(p)/(P_RHO(p)* M_PI), 1./3.);

/* Prandtl number */
Pr = cell->sHeat * cell->mu / cell->tCond;
/* Nusselt number */
Nu = 2.0 + 0.6 * sqrt(p->Re) * pow(Pr, 1./3.);
/* Heat transfer coefficient*/
U = Nu * cell->tCond / dp;
/*Radiation temperature*/
theta_r = pow( C_STORAGE_R_XV(c,t,SV_DO_IRRAD,0) / (4. * SIGMA_SBC), 0.25);

/*Molar specific enthalpy [J/mol]*/
h_CH4mol = -74900. + 11.93*(Tg-T_REF1)+0.5*7.765e-2*(pow(Tg,2)-pow(T_REF1,2))-1.4e5*(1/Tg-1/T_REF1)-(1.841e-5/3.)*(pow(Tg,3)-pow(T_REF1,3));

h_Cmol = 14.58*(Tp-T_REF1)+0.5*9.957e-3*(pow(Tp,2)-pow(T_REF1,2))+8.5e5*(1/Tp-1/T_REF1)+(2.40e-6/3.)*(pow(Tp,3)-pow(T_REF1,3));

h_H2mol = 26.88*(Tp-T_REF1)+0.5*3.590e-3*(pow(Tp,2)-pow(T_REF1,2))-1.1e5*(1/Tp-1/T_REF1);
/* Heat production term due to reactions [W/m^3] */
gammadot =1.*( -r_Cmol*h_Cmol-r_H2mol*h_H2mol-r_CH4mol*h_CH4mol);


/*Coefficients for energy equation scheme */
/*alpha_p = (U*cell->temp + DPM_EMISSIVITY(p,m)*SIGMA_SBC*pow(theta_r,4)+dp/6.*gammadot)/(U+DPM_EMISSIVITY(p,m)*SIGMA_SBC*pow(Tp,3));*/

/*beta_p = Ap*(U+DPM_EMISSIVITY(p,m)*SIGMA_SBC*pow(Tp,3))/(P_MASS(p)*MATERIAL_PROP(m,PROP_Cp));*/

/*Energy equation scheme for DPM model */

/*P_T(p) = alpha_p + (P_T(p)-alpha_p)*exp(-beta_p*P_DT(p));*/

P_T(p) = P_T(p)+(P_DT(p)/(P_MASS(p)*MATERIAL_PROP(m,PROP_Cp)))*(U*Ap*(Tg-Tp)+DPM_EMISSIVITY(p,m)*Ap*(pow(theta_r,4)-pow(Tp,4))+Vp*gammadot);
}
}


/* Calculate the cell source term for gas phase */
static real dpm_relax=0.1; /*dpm source relaxation */
sewgolam is offline   Reply With Quote

Old   June 30, 2017, 04:06
Default Received a fatal Signal ( Segmentation fault )
  #17
Member
 
Muhammad Furqan Ali
Join Date: Oct 2014
Location: beijing
Posts: 53
Rep Power: 12
furqanrk is on a distinguished road
Send a message via Skype™ to furqanrk
Hi everyone !

I hope you are fine. I am using UDF in VOF model in ANSYS FLUENT, although, my VOF model without UDF is running fine. The UDF is written by my friend used it successfully. He has graduated last year after getting the results from same UDF. The UDF was working well on his server. He was using Fluent 6.3 on Linux system. When I am using same case, date and UDF on my laptop the case is not running, although UDF compilation is very fine. I also check it on Linux system too. During or after initialization, Error occurred segmentation fault error. It is very strange that same case and UDF is not working on his office now. Main error occurred when I am hooking ADJUST and EXECUTE-AT-END UDFs. May be there is some problem of writing/calling style is different in Windows and Linux system with 32bit and 64bit. ( this is just my opinion).

I hope you can understand the situation and have a try to fix the problem. I would be highly thankful if you guide me that where is the problem. I can send UDF by email if needed..

Thanks in Advance,
Regards,
M. F. ALi
furqanrk is offline   Reply With Quote

Old   June 30, 2017, 04:11
Default
  #18
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Try to initialize without the UDF, then load the UDF, and continue the simulation.
It could be that the UDF tries to access variables that don't exist yet when you do the initialization.

If you want more concrete help, you should post the relevant UDF code. I am not going to start email contact.
pakk 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
fatal signal segmentation fault in a UDF hares FLUENT 6 January 21, 2017 04:26
Parallel UDF Segmentation fault error KevinZ09 Fluent UDF and Scheme Programming 1 January 9, 2017 06:30
UDF with UDM Error: segmentation fault dj1210 Fluent UDF and Scheme Programming 4 November 24, 2016 10:44
segmentation fault when installing OF-2.1.1 on a cluster Rebecca513 OpenFOAM Installation 9 July 31, 2012 16:06
Segmentation Fault Shawn_A OpenFOAM Running, Solving & CFD 6 October 31, 2011 15:38


All times are GMT -4. The time now is 18:46.