CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Injection initialization generate a segmentation fault!! (https://www.cfd-online.com/Forums/fluent-udf/218779-injection-initialization-generate-segmentation-fault.html)

zahrae July 3, 2019 17:28

Injection initialization generate a segmentation fault!!
 
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.

AlexanderZ July 4, 2019 00:04

use message0 macro to figure out which line leads to error

best regards

zahrae July 5, 2019 16:33

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 July 7, 2019 17:18

AlexanderZ please I need to know if I did something wrong? can you please give me any guidelines?

AlexanderZ July 8, 2019 00:43

the reason could be the fact, that you didn't define domian

add
Code:

Domain *d;
d=Get_Domain(1);

best regards

zahrae July 8, 2019 04:59

I added these two lines in the code but the same error still remain :(

AlexanderZ July 8, 2019 06:18

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

zahrae July 8, 2019 19:26

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?

AlexanderZ July 9, 2019 00:57

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

pakk July 9, 2019 11:01

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));
  ...
 }
}


zahrae July 9, 2019 18:41

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 July 9, 2019 19:00

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 :p
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);
}
}



All times are GMT -4. The time now is 17:02.