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

Injection initialization generate a segmentation fault!!

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   July 3, 2019, 17:28
Default Injection initialization generate a segmentation fault!!
  #1
Member
 
imane
Join Date: Aug 2018
Posts: 62
Rep Power: 7
zahrae is on a distinguished road
Hello!
I am trying to track the particle trajectory by DPM model using unsteady tracking.
First I simulate steady flow for my continuous phase without activating DPM model, after convergence, I import the profile of velocity and temperature at the outlet for using it as inlet conditions for the new simulation with the DPM.
Now I want to assign the velocity and temperature of the fluid to particles in each injection. However, my domain is a cylinder so I have to work with the cylindrical coordinates.
I used this UDF to impose to particles the velocity of the flow when they will be injected(initialization). The code was compiled successfully but when calculation started I get a Segmentation fault.
Code:
#include "mem.h"
#define Boltzmann 1.3806505e-23
#define pi 3.14159265358979323846
#define nu_f  0.001075
#define b1 0.186
#define b2 0.653
#define b3 0.437
#define b4 7178.74

Domain *d;
/******initializes particle injection properties********/
/************************************************** *****/
DEFINE_DPM_INJECTION_INIT(inj_vel,I)
{
Particle *p;
cell_t c=RP_CELL(&(p->cCell));
Thread *t=RP_THREAD(&(p->cCell));
real NV_VEC(origin), NV_VEC(axis),NV_VEC(V), NV_VEC(r), NV_VEC(R), NV_VEC(B),NV_VEC(W),NV_VEC(del),NV_VEC(delT),NV_VEC(er), NV_VEC(et),NV_VEC(M),NV_VEC(J);
real xc[ND_ND];
real Bmag, rmag,pver,pvet,pvaxis;
real ua, ur, ut;
///transforme the coordinates into cylindrical field///////
/* Get origin vector of fluid region */
NV_V(origin, =, THREAD_VAR(t).cell.origin);   
/* Get axis of fluid region */
NV_V (axis, =, THREAD_VAR(t).cell.axis);  
/* Store the 3 cartesian velocity components in vector V */
N3V_D(V, =, C_U(c,t),C_V(c,t),C_W(c,t));   
/* Get current cell coordinate */
C_CENTROID(xc,c,t);     
/* Calculate (R) = (Xc)-(Origin) */
NV_VV(R, =, xc, -, origin);    
/* Calculate |B| = (R) dot (axis)*/
Bmag = NV_DOT(R,axis);    
 /* Calculate (B) = |B|*axis */
NV_VS(B,=,axis,*,Bmag);     
/* Calculate (r) = (R)-(B) This is the local radial vector*/
NV_VV(r, =, R, -, B);      
/* Calculate |r|*/
rmag = NV_MAG(r);   

if (rmag != 0.)
{
NV_VS (er,=,r,/,rmag);
NV_CROSS(et, axis, er);
ur = NV_DOT(V,er);
ut = NV_DOT(V,et);
ua = NV_DOT(V,axis);
}
else
{
ur = 0.0;
ut = 0.0;
ua = NV_DOT(V,axis);
}
N3V_D(M, =,P_VEL(p)[0],P_VEL(p)[1],P_VEL(p)[2]);   
NV_VS (er,=,r,/,rmag);
NV_CROSS(et, axis, er);
pver = NV_DOT(M,er); 
pvet = NV_DOT(M,et);
pvaxis = NV_DOT(M,axis);
loop(p,I->p_init)
{
cell_t c=RP_CELL(&(p->cCell));
Thread *t=RP_THREAD(&(p->cCell));
pver=ur;
pvet =ut;
pvaxis=ua;
P_T(p)=C_T(c,t);
}
}
Thanks for your help in advance.

Last edited by zahrae; July 5, 2019 at 16:36.
zahrae is offline   Reply With Quote

Old   July 4, 2019, 00:04
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
use message0 macro to figure out which line leads to error

best regards
AlexanderZ is offline   Reply With Quote

Old   July 5, 2019, 16:33
Default
  #3
Member
 
imane
Join Date: Aug 2018
Posts: 62
Rep Power: 7
zahrae is on a distinguished road
Thanks for your reply!
I Insert the message0 macro after each line, but it didn't show me anything, it still generates the same error. Any suggestions?
Code:
 
 #include "udf.h"
#include "dpm.h"
#include "mem.h"
#include "math.h"
#define Boltzmann 1.3806505e-23
#define pi 3.14159265358979323846
#define nu_f  0.001075
#define b1 0.186
#define b2 0.653
#define b3 0.437
#define b4 7178.74


/******initializes particle injection properties********/
/************************************************** *****/
DEFINE_DPM_INJECTION_INIT(inj_vel,I)
{
Domain *d;
Particle *p;
cell_t c=RP_CELL(&(p->cCell));
Thread *t=RP_THREAD(&(p->cCell));
real NV_VEC(origin), NV_VEC(axis),NV_VEC(V), NV_VEC(r), NV_VEC(R), NV_VEC(B),NV_VEC(W),NV_VEC(del),NV_VEC(delT),NV_VEC(er), NV_VEC(et),NV_VEC(M),NV_VEC(J);
real xc[ND_ND];
real Bmag, rmag,pver,pvet,pvaxis;
real ua, ur, ut;
Message("point a\n");
///transforme the coordinates into cylindrical field///////
/* Get origin vector of fluid region */
NV_V(origin, =, THREAD_VAR(t).cell.origin);   
Message(" point 1 \n");
/* Get axis of fluid region */
NV_V (axis, =, THREAD_VAR(t).cell.axis);  
Message(" point 2 \n");
/* Store the 3 cartesian velocity components in vector V */
N3V_D(V, =, C_U(c,t),C_V(c,t),C_W(c,t));   
Message(" point 3 \n");
/* Get current cell coordinate */
C_CENTROID(xc,c,t);  
Message(" point 4 \n");   
/* Calculate (R) = (Xc)-(Origin) */
NV_VV(R, =, xc, -, origin);    
Message(" point 5 \n");
/* Calculate |B| = (R) dot (axis)*/
Bmag = NV_DOT(R,axis);  
Message(" point 6 \n");  
 /* Calculate (B) = |B|*axis */
NV_VS(B,=,axis,*,Bmag);   
Message(" point 7 \n");  
/* Calculate (r) = (R)-(B) This is the local radial vector*/
NV_VV(r, =, R, -, B);  
Message(" point 8 \n");    
/* Calculate |r|*/
rmag = NV_MAG(r);   
Message(" point 9 \n");
if (rmag != 0.)
{
NV_VS (er,=,r,/,rmag);
Message(" point 10 \n");
NV_CROSS(et, axis, er);
Message(" point 11 \n");
ur = NV_DOT(V,er);
Message(" point 12 \n");
ut = NV_DOT(V,et);
Message(" point 13 \n");
ua = NV_DOT(V,axis);
Message(" point 14 \n");
}
else
{
ur = 0.0;
Message(" point 15 \n");
ut = 0.0;
Message(" point 16 \n");
ua = NV_DOT(V,axis);
Message(" point 17 \n");
}
N3V_D(M, =,P_VEL(p)[0],P_VEL(p)[1],P_VEL(p)[2]);   
Message(" point 18 \n");
NV_VS (er,=,r,/,rmag);
Message(" point 19 \n");
NV_CROSS(et, axis, er);
Message(" point 20 \n");
pver = NV_DOT(M,er); 
Message(" point 21 \n");
pvet = NV_DOT(M,et);
Message(" point 22 \n");
pvaxis = NV_DOT(M,axis);
Message(" point 23 \n");
loop(p,I->p_init)
{
cell_t c=RP_CELL(&(p->cCell));
Message(" point 24 \n");
Thread *t=RP_THREAD(&(p->cCell));
Message(" point 25 \n");
pver=ur;
Message(" point 26 \n");
pvet =ut;
Message(" point 27 \n");
pvaxis=ua;
Message(" point 28 \n");
P_T(p)=C_T(c,t);
Message(" point 29 \n");
}
}
zahrae is offline   Reply With Quote

Old   July 7, 2019, 17:18
Default
  #4
Member
 
imane
Join Date: Aug 2018
Posts: 62
Rep Power: 7
zahrae is on a distinguished road
AlexanderZ please I need to know if I did something wrong? can you please give me any guidelines?
zahrae is offline   Reply With Quote

Old   July 8, 2019, 00:43
Default
  #5
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
the reason could be the fact, that you didn't define domian

add
Code:
Domain *d;
d=Get_Domain(1);
best regards
AlexanderZ is offline   Reply With Quote

Old   July 8, 2019, 04:59
Default
  #6
Member
 
imane
Join Date: Aug 2018
Posts: 62
Rep Power: 7
zahrae is on a distinguished road
I added these two lines in the code but the same error still remain
zahrae is offline   Reply With Quote

Old   July 8, 2019, 06:18
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
show your UDF,
compile it and show log

RP_CELL macro is defined in "surf.h" library, which is not defined in your UDF, but you said, you've compiled without errors

best regards
AlexanderZ is offline   Reply With Quote

Old   July 8, 2019, 19:26
Default
  #8
Member
 
imane
Join Date: Aug 2018
Posts: 62
Rep Power: 7
zahrae is on a distinguished road
here is the message that I get after compilation:
Code:
> Copied C:\Users\hp\Downloads\Compressed\Nouveau dossier\Nouveau dossier\Nouveau dossier/initial1.c to libudf33\src
Creating user_nt.udf file for 3ddp ...
(system "copy "C:\PROGRA~1\ANSYSI~1\v170\fluent"\fluent17.0.0\src\udf\makefile_nt.udf "libudf33\win64\3ddp\makefile" ")
        1 fichier(s) copi‚(s).
(chdir "libudf33")(chdir "win64\3ddp")# Generating ud_io1.h
initial1.c
C:\Users\hp\Downloads\Compressed\Nouveau dossier\Nouveau dossier\Nouveau dossier\libudf33\src\initial1.c(20) : warning C4700: variable locale 'p' non initialis‚e utilis‚e
# Generating udf_names.c because of makefile initial1.obj
udf_names.c
# Linking libudf.dll because of makefile user_nt.udf udf_names.obj initial1.obj
Microsoft (R) Incremental Linker Version 14.21.27702.2
Copyright (C) Microsoft Corporation.  All rights reserved.

   Création de la bibliothèque libudf.lib et de l'objet libudf.exp

Done.

Opening library "C:\Users\hp\Downloads\Compressed\Nouveau dossier\Nouveau dossier\Nouveau dossier\libudf33"...
Library "C:\Users\hp\Downloads\Compressed\Nouveau dossier\Nouveau dossier\Nouveau dossier\libudf33\win64\3ddp\libudf.dll" opened
	inj_vel
Done.
and also when I add the "surf.h" library and compile it shows me that:
Code:
 

> Copied C:\Users\hp\Downloads\Compressed\Nouveau dossier\Nouveau dossier\Nouveau dossier/initialisation.c to libudf32\src
Creating user_nt.udf file for 3ddp ...
(system "copy "C:\PROGRA~1\ANSYSI~1\v170\fluent"\fluent17.0.0\src\udf\makefile_nt.udf "libudf32\win64\3ddp\makefile" ")
        1 fichier(s) copi‚(s).
(chdir "libudf32")(chdir "win64\3ddp")# Generating ud_io1.h
initialisation.c
C:\Users\hp\Downloads\Compressed\Nouveau dossier\Nouveau dossier\Nouveau dossier\libudf32\src\initialisation.c(22) : warning C4700: variable locale 'p' non initialis‚e utilis‚e
# Generating udf_names.c because of makefile initialisation.obj
udf_names.c
# Linking libudf.dll because of makefile user_nt.udf udf_names.obj initialisation.obj
Microsoft (R) Incremental Linker Version 14.21.27702.2
Copyright (C) Microsoft Corporation.  All rights reserved.

   Création de la bibliothèque libudf.lib et de l'objet libudf.exp

Done.

Opening library "C:\Users\hp\Downloads\Compressed\Nouveau dossier\Nouveau dossier\Nouveau dossier\libudf32"...
Library "C:\Users\hp\Downloads\Compressed\Nouveau dossier\Nouveau dossier\Nouveau dossier\libudf32\win64\3ddp\libudf.dll" opened
	inj_vel
Done.
I see that there is a warning in both cases (warning C4700: variable locale 'p' non initialise utilise),
I don't get it, how to initialize the pârticle, I use originally this UDF for initializing my injected particles?
zahrae is offline   Reply With Quote

Old   July 9, 2019, 00:57
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
when you run your UDF did you ever get ????
Code:
point a
from
Code:
Message("point a\n");
where did you find these macro? THREAD_VAR(t).cell
everywhere I've found this macro it is used as Boolean (true or false)
how this should work from your point of view?
Code:
NV_V(origin, =, THREAD_VAR(t).cell.origin);
Go step by step, run this
Code:
 #include "udf.h"
#include "dpm.h"
#include "mem.h"
#include "math.h"
#define Boltzmann 1.3806505e-23
#define pi 3.14159265358979323846
#define nu_f  0.001075
#define b1 0.186
#define b2 0.653
#define b3 0.437
#define b4 7178.74


/******initializes particle injection properties********/
/************************************************** *****/
DEFINE_DPM_INJECTION_INIT(inj_vel,I)
{
Domain *d;
Particle *p;
cell_t c=RP_CELL(&(p->cCell));
Thread *t=RP_THREAD(&(p->cCell));
real NV_VEC(origin), NV_VEC(axis),NV_VEC(V), NV_VEC(r), NV_VEC(R), NV_VEC(B),NV_VEC(W),NV_VEC(del),NV_VEC(delT),NV_VEC(er), NV_VEC(et),NV_VEC(M),NV_VEC(J);
real xc[ND_ND];
real Bmag, rmag,pver,pvet,pvaxis;
real ua, ur, ut;
Message("point a\n");
///transforme the coordinates into cylindrical field///////
/* Get origin vector of fluid region */

}
get "point a" as response, add new functionality. step by step

best regards
AlexanderZ is offline   Reply With Quote

Old   July 9, 2019, 11:01
Default
  #10
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
Your problem is that you forget to loop. See your code (simplified):

Code:
DEFINE_DPM_INJECTION_INIT(inj_vel,I)
{
Particle *p;
cell_t c=RP_CELL(&(p->cCell));
...
 }
You first tell Fluent that p is a pointer to a particle, but it is not initialized. And in the next line, you tell Fluent to look up the cell corresponding to the particle that p points to. But p points to nothing! So fluent returns a segmentation fault.

What do you want? You first want p to point to the first particle in the injection. Then to the second. Then to the third. And so on. So it's a loop. And the Fluent manual on DEFINE_DPM_INJECTION_INIT shows how to use this loop! So just add this loop, and let p loop over all particles in the injection:

Code:
DEFINE_DPM_INJECTION_INIT(inj_vel,I)
{
Particle *p;
loop(p,I->p) {
 cell_t c=RP_CELL(&(p->cCell));
  ...
 }
}
pakk is offline   Reply With Quote

Old   July 9, 2019, 18:41
Default
  #11
Member
 
imane
Join Date: Aug 2018
Posts: 62
Rep Power: 7
zahrae is on a distinguished road
AlexanderZ thanks for your cooperation
1-even I use the macro
Code:
 Message("point a\n");
I don't get any message after running the code.
2- Actually first I didn't know how to program the conversion from cartesian to cylindrical coordinates by Fluent macros and I did some research. I found
Code:
  NV_V(origin, =, THREAD_VAR(t).cell.origin);
in this link : http://www.eureka.im/538.html
so I use the part of the code in my own program, I think
Code:
  NV_V(origin, =, THREAD_VAR(t).cell.origin);
is used to obtain the origin if cell is the origin of the fluid region, because in this UDF the axis and the origin of the axis are arbitrary. The axis is not aligned with any cartesian direction and is in the form of (ex,ey,ez).
3- I run
Code:
  
 #include "udf.h"
#include "dpm.h"
#include "mem.h"
#include "math.h"
#define Boltzmann 1.3806505e-23
#define pi 3.14159265358979323846
#define nu_f  0.001075
#define b1 0.186
#define b2 0.653
#define b3 0.437
#define b4 7178.74


/******initializes particle injection properties********/
/************************************************** *****/
DEFINE_DPM_INJECTION_INIT(inj_vel,I)
{
Domain *d;
Particle *p;
cell_t c=RP_CELL(&(p->cCell));
Thread *t=RP_THREAD(&(p->cCell));
real NV_VEC(origin), NV_VEC(axis),NV_VEC(V), NV_VEC(r), NV_VEC(R), NV_VEC(B),NV_VEC(W),NV_VEC(del),NV_VEC(delT),NV_VEC(er), NV_VEC(et),NV_VEC(M),NV_VEC(J);
real xc[ND_ND];
real Bmag, rmag,pver,pvet,pvaxis;
real ua, ur, ut;
Message("point a\n");
///transforme the coordinates into cylindrical field///////
/* Get origin vector of fluid region */

}
but still the same warning!
zahrae is offline   Reply With Quote

Old   July 9, 2019, 19:00
Default
  #12
Member
 
imane
Join Date: Aug 2018
Posts: 62
Rep Power: 7
zahrae is on a distinguished road
pakk thanks for your explanation!

1- I used the
Code:
 loop(p,I->p_init) { }
but after converting the coordinates from cartesian to cylindrical ones
2- after your suggestion the warning is gone and also the segmentation fault. I think my program was wrong. I did some changes now, do you think my code is correct now, first I transformed the velocities of fluid and particles from cartesian to cylindrical and I suppose that the velocity and temperature of particles at the inlet of my pipe initially equal to those of the fluid.


Code:
 #include "udf.h"
#include "dpm.h"
#include "mem.h"
#include "math.h"
#define Boltzmann 1.3806505e-23
#define pi 3.14159265358979323846
#define nu_f  0.001075
#define b1 0.186
#define b2 0.653
#define b3 0.437
#define b4 7178.74


/******initializes particle injection properties********/
/************************************************** *****/
DEFINE_DPM_INJECTION_INIT(inj_vel,I)
{
Domain *d;
d=Get_Domain(1);
Particle *p;
loop(p,I->p_init)
{
cell_t c=RP_CELL(&(p->cCell));
Thread *t=RP_THREAD(&(p->cCell));
real NV_VEC(origin), NV_VEC(axis),NV_VEC(V), NV_VEC(r), NV_VEC(R), NV_VEC(B),NV_VEC(W),NV_VEC(del),NV_VEC(delT),NV_VEC(er), NV_VEC(et),NV_VEC(M),NV_VEC(J);
real xc[ND_ND];
real Bmag, rmag,pver,pvet,pvaxis;
real ua, ur, ut;
///transforme the coordinates into cylindrical field///////
/* Get origin vector of fluid region */
NV_V(origin, =, THREAD_VAR(t).cell.origin);   
/* Get axis of fluid region */
NV_V (axis, =, THREAD_VAR(t).cell.axis);  
/* Store the 3 cartesian velocity components in vector V */
N3V_D(V, =, C_U(c,t),C_V(c,t),C_W(c,t));   
/* Get current cell coordinate */
C_CENTROID(xc,c,t);    
/* Calculate (R) = (Xc)-(Origin) */
NV_VV(R, =, xc, -, origin);    
/* Calculate |B| = (R) dot (axis)*/
Bmag = NV_DOT(R,axis);   
 /* Calculate (B) = |B|*axis */
NV_VS(B,=,axis,*,Bmag);   
/* Calculate (r) = (R)-(B) This is the local radial vector*/
NV_VV(r, =, R, -, B);  
/* Calculate |r|*/
rmag = NV_MAG(r);   
if (rmag != 0.)
{
NV_VS (er,=,r,/,rmag);
NV_CROSS(et, axis, er);
ur = NV_DOT(V,er);
ut = NV_DOT(V,et);
ua = NV_DOT(V,axis);
pver = NV_DOT(M,er); 
pvet = NV_DOT(M,et);
pvaxis = NV_DOT(M,axis);
}
else
{
ur = 0.0;
ut = 0.0;
ua = NV_DOT(V,axis);
pver = 0.0;
pvet =0.0;
pvaxis = NV_DOT(M,axis);
}
pver=ur;
pvet =ut;
pvaxis=ua;
P_T(p)=C_T(c,t);
}
}
zahrae 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
Segmentation fault Tushar_Telmasre Fluent UDF and Scheme Programming 4 June 1, 2017 16:19
injection problem Mark New FLUENT 0 August 4, 2013 01:30
segmentation fault when installing OF-2.1.1 on a cluster Rebecca513 OpenFOAM Installation 9 July 31, 2012 15:06
Segmentation Fault Shawn_A OpenFOAM Running, Solving & CFD 6 October 31, 2011 14:38
KIVA and Segmentation Fault Felix Main CFD Forum 2 January 18, 2006 01:24


All times are GMT -4. The time now is 14:24.