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   September 25, 2019, 13:43
Default Segmentation Fault!
  #1
New Member
 
Join Date: Sep 2019
Posts: 24
Rep Power: 7
NonStopEagle is on a distinguished road
hello everyone,
I am trying to get the velocity gradient values using the udf below, but it throws a segmentation fault.


DEFINE_ON_DEMAND(Gradient_Updation)
{
Domain* d;

face_t f;
cell_t c;
double DUY, DVY, DUX, DVX;
d = Get_Domain(1); /* Get the domain using ANSYS FLUENT utility */
int zone_ID = 8; /* Found in Fluent BC panel and identifies Wall */

Thread *t = Lookup_Thread(d, zone_ID);


begin_f_loop(f, t)
{
t = THREAD_T0(t); /* adjacent cell thread to f */
c = F_C0(f, t);
DUX = C_DUDX(c, t);
F_UDMI(f, t, 0) = DUX;
DVX = C_DVDX(c, t);
F_UDMI(f, t, 1) = DVX;
DUY = C_DUDY(c, t);
F_UDMI(f, t, 2) = DUY;
DVY = C_DVDY(c, t);
F_UDMI(f, t, 3) = DVY;
}
end_f_loop(c, t)


}
Any help will be appreciated.
NonStopEagle is offline   Reply With Quote

Old   September 26, 2019, 01:24
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
did you allocate memory for your UDMs?

fluent GUI -> user-defined -> memory -> udm locations -> 4

best regards
AlexanderZ is offline   Reply With Quote

Old   September 26, 2019, 02:03
Default
  #3
New Member
 
Join Date: Sep 2019
Posts: 24
Rep Power: 7
NonStopEagle is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
did you allocate memory for your UDMs?

fluent GUI -> user-defined -> memory -> udm locations -> 4

best regards
Thanks Alexander for the reply
Yes I have defined sufficient udms. Actually this is a part of a larger udf I am writing for wall slip velocity.
Is there anything else that could be wrong?
Thanks in advance
NonStopEagle
NonStopEagle is offline   Reply With Quote

Old   September 26, 2019, 02:48
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
Code:
#include "udf.h"

DEFINE_ON_DEMAND(Gradient_Updation)
{
Domain* d; 

face_t f;
cell_t c; 
double DUY, DVY, DUX, DVX;
int zone_ID = 8; /* Found in Fluent BC panel and identifies Wall */
Thread *t;

d = Get_Domain(1); /* Get the domain using ANSYS FLUENT utility */
t = Lookup_Thread(d, zone_ID);
begin_f_loop(f, t)
{
t = THREAD_T0(t); /* adjacent cell thread to f */
c = F_C0(f, t);
DUX = C_DUDX(c, t);
F_UDMI(f, t, 0) = DUX;
DVX = C_DVDX(c, t);
F_UDMI(f, t, 1) = DVX;
DUY = C_DUDY(c, t);
F_UDMI(f, t, 2) = DUY;
DVY = C_DVDY(c, t);
F_UDMI(f, t, 3) = DVY;
}
end_f_loop(c, t)


}
compile code, read error log

best regards
AlexanderZ is offline   Reply With Quote

Old   September 27, 2019, 09:07
Default
  #5
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
Quote:
Originally Posted by NonStopEagle View Post
t = THREAD_T0(t); /* adjacent cell thread to f */
I think you want this line outside your loop.
pakk is offline   Reply With Quote

Old   September 27, 2019, 17:24
Default
  #6
New Member
 
Join Date: Sep 2019
Posts: 24
Rep Power: 7
NonStopEagle is on a distinguished road
Thanks for your reply pakk,
But I have changed my method of calculating the gradients. You see, I want to calculate the wall normal gradients of velocity and temperature. The reason i am not using the predefined macros it that they are not limited and produce large values leading to divergence ( I know about reconstruction gradients, bu even then the changes in gradient values as i change under-relaxation in my udf are high and result in large changes in the resulting slip velocity). see my udf below for this.
DEFINE_PROFILE(wall_slip_velocity, t, index)
{
static double T, P, density, MU, K, landa, a_m, du_da, dT_dx, u_f, u, v;
double A[ND_ND];
face_t f;
Thread* t0;
cell_t c0;
double DUR, DVR;
double DUY, DVY, DUX, DVX;
static real gradient;
double uw, dy, grad;
double uc[223];
int i = 0;
int j = 0;
begin_c_loop(c0, t0)
begin_f_loop(f, t)
{
t0 = THREAD_T0(t); /* adjacent cell thread to f */
c0 = F_C0(f, t); /* adjacent cell to f */

// Calculation of gradients
// approximating the normal gradient to be the difference between cell center and wall divided by the half cell distance.
//To get the cell center value.
uc = C_U(c0, t0); // cell center velocity
uw = F_U(c0, t0); // face velocity
Message("UC :%f", uc);

dy = 1.25 * (10 ^ (-8)); // from inflation layer
grad = (uw - uc) / dy;


T = C_T(c0, t0); /* temperature of the cell */
P = C_P(c0, t0); /* peressure of the cell */
density = C_R(c0, t0); /* density of the cell*/
MU = C_MU_L(c0, t0); /* laminar viscosity of the cell */
u = C_U(c0, t0);
v = C_V(c0, t0);
K = C_K_L(c0, t0); /* thermal conductivity of the cell */
landa = (k_B * T) / (sqrt_2 * pi * sigma * sigma * P); /* mean free path line */
F_PROFILE(f, t, index) = relax * (((2 - sigma_v) / sigma_v) * landa * grad);
F_UDMI(f, t, 5) = landa;
i = i + 1;


}
end_f_loop(f, t)
}
the question i have for you is that in the above udf, when i try to calculate the cell center velocities and wall(face) velocities, they return the same values. the gradient is calculated above as,
grad = (cell-center velocity - wall velocity)/(half width of cell)
I expect some difference in the cell-center and face velocity so that the gradient values comes out to be non-zero.

I would appreciate it, if you could help me with this problem.(Perhaps the method i am using to get the cell center and face values is incorrect).
If such is the case kindly point me in the right direction.
NonStopEagle
NonStopEagle is offline   Reply With Quote

Old   September 28, 2019, 02:54
Default
  #7
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
You are mixing t and t0. One of them is a cell thread, one of them a face thread.

Maybe call them cell_thread and face_thread for clarity, and think about which one you should use where.

Example:

uw = F_U(c0, t0); // face velocity

Well, c0 and t0 are cell-related, not face-related,so this will not give a face velocity.
F_U(f, t) is probably what you want.
pakk is offline   Reply With Quote

Old   September 28, 2019, 03:40
Default
  #8
New Member
 
Join Date: Sep 2019
Posts: 24
Rep Power: 7
NonStopEagle is on a distinguished road
Thanks pakk
I have changed the code as per your recommendations. Now i get the value of cell velocity, but fluent throws a segmentation fault when calculating the face velocity.


the modified udf is as follows: ( I have added comments to signify threads as i understand them, if i am wrong, please feel free to correct me.)


DEFINE_PROFILE(wall_slip_velocity, f_t, index)
{
static double T, P, density, MU, K, landa, a_m, du_da, dT_dx, u_f, u, v;
double A[ND_ND];
face_t f;
Thread* c_t0;
cell_t c0;
double DUR, DVR;
double DUY, DVY, DUX, DVX;
static real gradient;
double uw, dy, grad;
double uc;
int i = 0;
int j = 0;
i = 0;
begin_f_loop(f, f_t) // loop running on faces and along face_thread
{
// Calculation of gradients
// approximating the normal gradient to be the difference between cell center and wall divided by the half cell distance.
//To get the cell center value.
c_t0 = THREAD_T0(f_t); /* adjacent cell thread to f */
c0 = F_C0(f, f_t); /* adjacent cell to f */

uc = C_U(c0, c_t0); // calculating velocity using the adjacent call and cell thread
Message("UC :%f", uc);
uw = F_U(f, f_t); // Calculating velocity using face and face thread
Message("UW :%f", uw);

dy = 1.25 * (10 ^ (-8)); // from inflation layer
grad = (uw - uc) / dy;


T = C_T(c0, c_t0); /* temperature of the cell */
P = C_P(c0, c_t0); /* peressure of the cell */
density = C_R(c0, c_t0); /* density of the cell*/
MU = C_MU_L(c0, c_t0); /* laminar viscosity of the cell */
u = C_U(c0, c_t0);
v = C_V(c0, c_t0);
K = C_K_L(c0, c_t0); /* thermal conductivity of the cell */
landa = (k_B * T) / (sqrt_2 * pi * sigma * sigma * P); /* mean free path line */
F_PROFILE(f, f_t, index) = relax * (((2 - sigma_v) / sigma_v) * landa * grad);
i = i + 1;


}
end_f_loop(f, f_t)
}


I think that fluent maybe does not calculate property values at the faces...hence the segmentation fault. If such is the case, kindly guide me as to how the face velocity can be calculated.


thanks in advance


NonStopEagle
NonStopEagle is offline   Reply With Quote

Old   September 28, 2019, 10:46
Default
  #9
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27
pakk will become famous soon enough
I don't see what could be the problem...

I see another problem in dy: 10^(-8) does not mean what you think it means.

And another problem: your calculated gradient will not be more accurate than the one in Fluent. All problems you get with fluents gradient will also show up in your gradient.
You never stated your goal, but it looks like you are trying to implement a slip condition. I hope that you know that fluent has this already built-in, you can enable it without writing any UDF.
pakk is offline   Reply With Quote

Reply

Tags
udf and programming


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 22:59
Segmentation fault in SU2 V5.0 ygd SU2 2 March 1, 2017 05:38
Segmentation fault when running in parallel Pj. OpenFOAM Running, Solving & CFD 3 April 8, 2015 09:12
Segmentation Fault w/ compiled OF 2.2.0 - motorBike example sudo OpenFOAM Running, Solving & CFD 3 April 2, 2013 18:27
segmentation fault when installing OF-2.1.1 on a cluster Rebecca513 OpenFOAM Installation 9 July 31, 2012 16:06


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