Fluent 6.2.7: UDF modifications for Hexcore and non-conformal adaption, Parent cells


A UDF that runs perfectly fine on tet, hex and hybrid meshes gives a segmentation error with hexcore. The UDF goes down to the cell face level c_face_loop

The original UDF looks like:

#include "udf.h"

DEFINE_ON_DEMAND(rotor_init)
{

Domain *domain;
Thread *c_thread,*tf;
cell_t c;
face_t f;
real xc[ND_ND],a[ND_ND];
int n,count=0,fcount=0;

domain = Get_Domain(1);

thread_loop_c(c_thread,domain)
{
begin_c_loop_int(c, c_thread)
{
count++;
C_CENTROID(xc,c, c_thread);
c_face_loop(c,c_thread,n)
{

f = C_FACE(c,c_thread,n);
tf = C_FACE_THREAD(c,c_thread,n);
if ( (xc[0] > .568 && xc[0] < .569)
&& (xc[1] > -3.014 && xc[1] < -3.013)
&& (xc[2] > 7.87 && xc[2] < 7.88))
{
Message("xc= %f %f %fn",xc[0],xc[1],xc[2]);
F_AREA(a,f,tf);
/* addressing a[0] below brings out the segmentation violation */
Message("Face area= %fn",a[0]);
}
fcount++;

}
}
end_c_loop_int(c, c_thread)
}
Message("Cell count= %dn",count);
Message("Face count= %dn",fcount);

}
The issue is the following: Hexcore (as well as non-conformal grid adaption in which you should see the same problems) introduces a new concept the PARENT cell. The data structure is a oct-tree (3D) or quad-tree (2D), ie an original quad (Parent)cell gets split into 4 children in 2d (hex into eight children in 3d) when you adapt or when you have hexcore. Thus when you go down to the cell level you have to query if the face is a parent cell. The total area of the parent cell is then the sum of the area of the children etc. The UDF takes the form



#include "udf.h"

DEFINE_ON_DEMAND(rotor_init)
{

Domain *domain;
Thread *c_thread,*tf, *tk;
cell_t c;
face_t f, fk;
real xc[ND_ND],a[ND_ND],an[ND_ND];
int n,nn,count=0,fcount=0;

domain = Get_Domain(1);

thread_loop_c(c_thread,domain)
{
begin_c_loop_int(c, c_thread)
{
count++;
C_CENTROID(xc,c, c_thread);
c_face_loop(c,c_thread,n)
/* n ranges from 0 to 5 depending on the cell type (5 hex, 3 tet)*/
{
f = C_FACE(c,c_thread,n);
tf = C_FACE_THREAD(c,c_thread,n);
if (PARENT_FACE_THREAD_P(tf))
{
/*Message("Parent facen");*/
f_child_loop(f,tf,nn)
{
/*Message("nn %dn",nn);*/
/* nn ranges from 0 to 4*/
/*Message("looping over childrenn");*/
if (!NULL_FACE_P(fk = F_CHILD(f,tf,nn)) &&
!NULLP(tk = F_CHILD_THREAD(f,tf,nn)))
{
if ( (xc[0] > 0.568 && xc[0] < 0.569)
&& (xc[1] > -3.014 && xc[1] < -3.013)
&& (xc[2] > 7.87 && xc[2] < 7.88))
{
Message(" %d %d xc= %f %f %fn",n,nn,xc[0],xc[1],xc[2]);
F_AREA(a,fk,tk);
/* addressing a[0] below brings out the segmentation violation */
Message(" %d %d Face area= %f %f %f n",n,nn,a[0],a[1],a[2]);
}
fcount++;
}


}
}
else
{
if ( (xc[0] > 0.568 && xc[0] < 0.569)
&& (xc[1] > -3.014 && xc[1] < -3.013)
&& (xc[2] > 7.87 && xc[2] < 7.88))
{
Message("%d xc= %f %f %fn",n,xc[0],xc[1],xc[2]);
F_AREA(an,f,tf);
/* addressing a[0] below brings out the segmentation violation */
Message("%d Face area= %f %f %f n",n,an[0],an[1],an[2]);
}
fcount++;


}
}
}
end_c_loop_int(c,c_thread)
}
Message("Cell count= %dn",count);
Message("Face count= %dn",fcount);
}





Show Form
No comments yet. Be the first to add a comment!