udf-getting the pointer to the cell containing a point
i have an arbitrary (x,y,z) coordinate, how can i get a pointer to the cell which contains this point?
|
I would also like to know that.
|
hi, i have found the answer myself,here you are, in this udf the flow information in special coordinates will be calculated, at first it finds that coordinate is in which cell and then it uses the flow information in that cell and the gradient of flow information in the same cell to fulfil the task,
REGARDS Mohsen ZENDEHBAD #include "udf.h" FILE *uout; FILE *vout; FILE *wout; FILE *pout; FILE *tout; DEFINE_EXECUTE_AT_END(execute_at_end) { double NormalVector[ND_ND];/*face normal vector*/ double FaceCentre[ND_ND];/*centroid coordinates*/ double CellCentroid[ND_ND]; double GoalCentroid[ND_ND]; double p[1037][ND_ND];/*our arbitrary coordinates*/ double PointVector[ND_ND];/*the point subtracted by the face centre*/ int zone_ID; int cnt; int n; int NumberOfPoints; int i; cell_t c; cell_t Goal; face_t f; Thread *t; Thread *tf; Domain *d; NumberOfPoints=1037;/*DON'T FORGET TO ADJUST THIS NUMBER FOR P[][ND_ND] ABOVE*/ /*Copy the data FROM here p[0][0]=0;p[0][1]=0;p[0][2]=-.24; p[1][0]=0;p[1][1]=0;p[1][2]=-.2; p[2][0]=0;p[2][1]=0;p[2][2]=-.15; p[3][0]=0;p[3][1]=0;p[3][2]=-.5; p[4][0]=0;p[4][1]=0;p[4][2]=.1; p[5][0]=0;p[5][1]=0;p[5][2]=.2;*/ p[0][0]=-1.080830e-003;p[0][1]=1.466203e-002;p[0][2]=-2.540000e-001; p[1][0]=-9.981496e-004;p[1][1]=1.404256e-002;p[1][2]=-2.540000e-001; p[2][0]=-9.278523e-004;p[2][1]=1.336367e-002;p[2][2]=-2.540000e-001; p[3][0]=-8.680859e-004;p[3][1]=1.268488e-002;p[3][2]=-2.540000e-001; p[4][0]=-8.172746e-004;p[4][1]=1.202529e-002;p[4][2]=-2.540000e-001; p[5][0]=-7.740778e-004;p[5][1]=1.138906e-002;p[5][2]=-2.540000e-001; p[6][0]=-7.372264e-004;p[6][1]=1.077418e-002;p[6][2]=-2.540000e-001; p[7][0]=-7.056433e-004;p[7][1]=1.017768e-002;p[7][2]=-2.540000e-001; p[8][0]=-6.785430e-004;p[8][1]=9.598250e-003;p[8][2]=-2.540000e-001; p[9][0]=-6.552564e-004;p[9][1]=9.029795e-003;p[9][2]=-1.540000e-001; p[10][0]=-6.352138e-004;p[10][1]=8.474297e-003;p[10][2]=-2.540000e-001; p[11][0]=-6.179302e-004;p[11][1]=7.975751e-003;p[11][2]=-2.540000e-001; p[12][0]=-3.241992e-003;p[12][1]=1.336879e-002;p[12][2]=-2.540000e-001; p[13][0]=-2.993007e-003;p[13][1]=1.275664e-002;p[13][2]=-2.540000e-001; p[14][0]=-2.781275e-003;p[14][1]=1.207569e-002;p[14][2]=-2.540000e-001; p[15][0]=-2.601234e-003;p[15][1]=1.140090e-002;p[15][2]=-2.540000e-001; p[16][0]=-2.448149e-003;p[16][1]=1.077010e-002;p[16][2]=-2.540000e-001; p[17][0]=-2.317991e-003;p[17][1]=1.018746e-002;p[17][2]=-2.540000e-001; p[18][0]=-2.206678e-003;p[18][1]=9.654449e-003;p[18][2]=-2.540000e-001; p[19][0]=-2.110748e-003;p[19][1]=9.170797e-003;p[19][2]=-2.540000e-001; p[20][0]=-2.027918e-003;p[20][1]=8.721691e-003;p[20][2]=-2.540000e-001; p[21][0]=-1.956241e-003;p[21][1]=8.300717e-003;p[21][2]=-2.540000e-001; p[22][0]=-1.894055e-003;p[22][1]=7.930605e-003;p[22][2]=-2.540000e-001; p[23][0]=-1.839947e-003;p[23][1]=7.661217e-003;p[23][2]=-2.540000e-001; p[24][0]=-5.400946e-003;p[24][1]=1.202775e-002;p[24][2]=-2.540000e-001; p[25][0]=-4.981526e-003;p[25][1]=1.139269e-002;p[25][2]=-2.540000e-001; p[26][0]=-4.624768e-003;p[26][1]=1.076338e-002;p[26][2]=-2.540000e-001; p[27][0]=-4.321343e-003;p[27][1]=1.016211e-002;p[27][2]=-2.540000e-001; p[28][0]=-4.063302e-003;p[28][1]=9.611193e-003;p[28][2]=-2.540000e-001; p[29][0]=-3.843872e-003;p[29][1]=9.107834e-003;p[29][2]=-2.540000e-001; p[30][0]=-3.655555e-003;p[30][1]=8.662894e-003;p[30][2]=-2.540000e-001; /*Copy the data UPTO here*/ uout=fopen("uOutput.txt","w"); vout=fopen("vOutput.txt","w"); wout=fopen("wOutput.txt","w"); pout=fopen("pOutput.txt","w"); tout=fopen("tOutput.txt","w"); /*getting the the thread pointing to the default interior*/ d=Get_Domain(1); zone_ID =9; t = Lookup_Thread(d,zone_ID); /*finished getting the the thread pointing to the default interior*/ for(i=0;i<NumberOfPoints;i++) { /*looping over cell in the requested thread*/ thread_loop_c(t,d) { begin_c_loop(c,t) { C_CENTROID(CellCentroid,c,t); cnt=0; c_face_loop(c, t, n) { f= C_FACE(c,t,n); tf= C_FACE_THREAD(c,t,n); F_CENTROID(FaceCentre,f,tf); F_AREA(NormalVector,f,tf); NV_VV(PointVector , = , FaceCentre , - , CellCentroid); if (NV_DOT(PointVector,NormalVector)<0) { NormalVector[0]=-1*NormalVector[0]; NormalVector[1]=-1*NormalVector[1]; NormalVector[2]=-1*NormalVector[2]; } NV_VV(PointVector , = , p[i] , - , FaceCentre); if (NV_DOT(PointVector,NormalVector)>sqrt(NV_MAG(Poin tVector))*1.0e-10) cnt=cnt+1; } /*Message("je suis arrivee%d\n",cnt);*/ if (cnt<1e-2) { Goal=c; GoalCentroid[0]=CellCentroid[0]; GoalCentroid[1]=CellCentroid[1]; GoalCentroid[2]=CellCentroid[2]; Message("Je l'ai trouve%10d\n",i); } } end_c_loop(c, t) } thread_loop_c(t,d) { NV_VV(PointVector , = , p[i] , - , GoalCentroid); /* Message("\nU est %g\n",C_U(Goal,t)); Message("Changement est %g\n",NV_DOT(PointVector,C_U_G(Goal,t))); Message("totale est %g\n",C_U(Goal,t)+NV_DOT(PointVector,C_U_G(Goal,t) )); Message("\nV est %g\n",C_V(Goal,t)); Message("Changement est %g\n",NV_DOT(PointVector,C_V_G(Goal,t))); Message("totale est %g\n",C_V(Goal,t)+NV_DOT(PointVector,C_V_G(Goal,t) )); Message("\nW est %g\n",C_W(Goal,t)); Message("Changement est %g\n",NV_DOT(PointVector,C_W_G(Goal,t))); Message("totale est %g\n",C_W(Goal,t)+NV_DOT(PointVector,C_W_G(Goal,t) )); Message("\nPresion est %g\n",C_P(Goal,t)); Message("Changement est %g\n",NV_DOT(PointVector,C_P_G(Goal,t))); Message("totale est %g\n",C_P(Goal,t)+NV_DOT(PointVector,C_P_G(Goal,t) )); Message("\nTemperature est %g\n",C_T(Goal,t)); Message("Changement est %g\n",NV_DOT(PointVector,C_T_G(Goal,t))); Message("totale est %g\n",C_T(Goal,t)+NV_DOT(PointVector,C_T_G(Goal,t) )); */ fprintf(uout,"%e\n",C_U(Goal,t)+NV_DOT(PointVector ,C_U_G(Goal,t))); fprintf(vout,"%e\n",C_V(Goal,t)+NV_DOT(PointVector ,C_V_G(Goal,t))); fprintf(wout,"%e\n",C_W(Goal,t)+NV_DOT(PointVector ,C_W_G(Goal,t))); fprintf(pout,"%e\n",C_P(Goal,t)+NV_DOT(PointVector ,C_P_G(Goal,t))); /*fprintf(tout,"%e\n",C_T(Goal,t)+NV_DOT(PointVecto r,C_T_G(Goal,t)));*/ } }/*the for loop closes here*/ fclose(uout); fclose(vout); fclose(wout); fclose(pout); fclose(tout); } |
All times are GMT -4. The time now is 09:34. |