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/)
-   -   Fluent UDF Wall Shear Stress Segmentation Fault (https://www.cfd-online.com/Forums/fluent-udf/148907-fluent-udf-wall-shear-stress-segmentation-fault.html)

a1ananth February 22, 2015 11:22

Fluent UDF Wall Shear Stress Segmentation Fault
 
Hi, I am using DEFINE_PROFILE to define wall shear stress value on boundary layer faces. The interpretation is successful but I am getting "Error: received a fatal signal (Segmentation fault)." when I do hybrid initialization. My udf code is:

DEFINE_PROFILE(wall_shear_udf_faces, thread, i)
{
face_t f;
real x[ND_ND];
real ufree;
real wall_shear_value;
real L, U, rho, mu, Re;

ufree = USTAR;

begin_f_loop(f, thread)
{
F_CENTROID(x, f, thread);
printf("X = %f and Y = %f\n\n", x[0], x[1]);

L = sqrt( (x[0] * x[0]) + (x[1] * x[1]) ); // distance formula
printf("Here\n\n");

rho = F_R(f, thread);
printf("L = %f and rho = %f\n\n", L, rho);

mu = F_MU_L(f, thread);
U = F_U(f, thread);

Re = (U * L) / mu;
printf("MU = %f and Re = %f\n\n", mu, Re);

// calculate using reynolds 1/5 power law
wall_shear_value = ((mult * rho) * (ufree * ufree)) / (pow(Re, POWER));

F_PROFILE(f, thread, i) = wall_shear_value;
}
end_f_loop(f, thread)
}

Error occurs in the line rho = F_R(f, thread); .. I know this because it prints "Here" in the fluent console.

Any idea why this error occurs and how to get it running? Thanks ahead!

a1ananth February 22, 2015 20:20

More error description
 
If I give constant values to all the variables it works.. but when I try to use the Face Field Variable Macros, it gives segmentation fault..

subha_meter February 23, 2015 17:34

Quote:

Originally Posted by a1ananth (Post 532877)
Hi, I am using DEFINE_PROFILE to define wall shear stress value on boundary layer faces. The interpretation is successful but I am getting "Error: received a fatal signal (Segmentation fault)." when I do hybrid initialization. My udf code is:

DEFINE_PROFILE(wall_shear_udf_faces, thread, i)
{
face_t f;
real x[ND_ND];
real ufree;
real wall_shear_value;
real L, U, rho, mu, Re;

ufree = USTAR;

begin_f_loop(f, thread)
{
F_CENTROID(x, f, thread);
printf("X = %f and Y = %f\n\n", x[0], x[1]);

L = sqrt( (x[0] * x[0]) + (x[1] * x[1]) ); // distance formula
printf("Here\n\n");

rho = F_R(f, thread);
printf("L = %f and rho = %f\n\n", L, rho);

mu = F_MU_L(f, thread);
U = F_U(f, thread);

Re = (U * L) / mu;
printf("MU = %f and Re = %f\n\n", mu, Re);

// calculate using reynolds 1/5 power law
wall_shear_value = ((mult * rho) * (ufree * ufree)) / (pow(Re, POWER));

F_PROFILE(f, thread, i) = wall_shear_value;
}
end_f_loop(f, thread)
}

Error occurs in the line rho = F_R(f, thread); .. I know this because it prints "Here" in the fluent console.

Any idea why this error occurs and how to get it running? Thanks ahead!


The problem of "segmentation fault" occurs when a solver variable is illegally accessed which in this case I suspect are the density and viscosity variables because they are stored in cell nodes and not in faces.

pakk February 24, 2015 03:23

Quote:

Originally Posted by a1ananth (Post 532877)
Hi, I am using DEFINE_PROFILE to define wall shear stress value on boundary layer faces. The interpretation is successful but I am getting "Error: received a fatal signal (Segmentation fault)." when I do hybrid initialization. My udf code is:

DEFINE_PROFILE(wall_shear_udf_faces, thread, i)
{
face_t f;
real x[ND_ND];
real ufree;
real wall_shear_value;
real L, U, rho, mu, Re;

ufree = USTAR;

begin_f_loop(f, thread)
{
F_CENTROID(x, f, thread);
printf("X = %f and Y = %f\n\n", x[0], x[1]);

L = sqrt( (x[0] * x[0]) + (x[1] * x[1]) ); // distance formula
printf("Here\n\n");

rho = F_R(f, thread);
printf("L = %f and rho = %f\n\n", L, rho);

mu = F_MU_L(f, thread);
U = F_U(f, thread);

Re = (U * L) / mu;
printf("MU = %f and Re = %f\n\n", mu, Re);

// calculate using reynolds 1/5 power law
wall_shear_value = ((mult * rho) * (ufree * ufree)) / (pow(Re, POWER));

F_PROFILE(f, thread, i) = wall_shear_value;
}
end_f_loop(f, thread)
}

Error occurs in the line rho = F_R(f, thread); .. I know this because it prints "Here" in the fluent console.

Any idea why this error occurs and how to get it running? Thanks ahead!

In the line
Code:

rho = F_R(f, thread);
you tell Fluent to get the content of F_R(f,thread), which is the density at the wall. This only works if there is a density at the wall. Before you initialize, there is no value defined for the density at the wall, so if you then ask for this value, Fluent can not get the value. Error.

In your case, if you do initialization, apparently this function is called before the density is set. If the order would have been differently, it would have worked.

I can give you two solution approaches:
1. Change the UDF, so that it first checks if the density is set, and if it is not set, it should use a 'default' value for the density. This is the best solution, but maybe difficult to program.
2. When you want to initialize, remove all calls to this function (or use constant values inside the function), and change the function to the correct version after initialization. This is the quick-and-dirty workaround.


All times are GMT -4. The time now is 23:45.