|
[Sponsors] |
February 6, 2014, 15:22 |
UDF function for grid spacing
|
#1 |
Member
Ali.E
Join Date: Sep 2010
Location: Lisboa
Posts: 83
Rep Power: 16 |
Dear all,
I want to write a UDF for calculating the grid spacing in 3D. Actually, I want to campute delta_x,delta_y and delta_z for each cell. My study case is a 3 dimension problem around a wing. my quastion is which function should be used? How can I write this udf? (delta_x means the length of a cell across x direction) |
|
February 6, 2014, 15:33 |
|
#2 | |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Quote:
It is hard to imagine that the final output that you are interested in is the cell lengths. Probably you want to use this to calculate something different. (A gradient?) You should explain what you want in the end. Not just to please me, but because the answer depends on what you want. Maybe you can avoid these calculations. Or if you really need them, what you need them for determines how you should deal with triangular meshes etc. |
||
February 7, 2014, 06:33 |
|
#3 | |
Member
Ali.E
Join Date: Sep 2010
Location: Lisboa
Posts: 83
Rep Power: 16 |
Thank you for your response.
Acutally, I want to compute length scale of DES model and the formulation is given as: L_s=sqrt(k)/(Bs*delta_max*C_des*w) Bs=0.09 , C_des=0.61 k=turbulent kinitic energy w=specific dissipation rate delta_max=max(delta_x,delta_y,delta_z) To honest, I am trying to write a UDF that computes this function. Quote:
|
||
February 7, 2014, 06:59 |
|
#4 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Then I guess, from a physical point of view, what you really need is the maximum distance between two points in a cell. Since cells are convex, this is always between two nodes of that cell, so you could loop over all nodes.
Something like this: Code:
DEFINE_ON_DEMAND(calculate_grid_distance) { Domain *domain=Get_Domain(ROOT_DOMAIN_ID); Thread *c_thread; cell_t c; Node *node; int n; thread_loop_c(c_thread, domain) /*loops over all cell threads in domain*/ { begin_c_loop(c, c_thread) /* loops over cells in a cell thread */ { c_node_loop(c,t,n) { node = C_NODE(c,t,n); /* x position is NODE_X(node), y position is NODE_Y(node), z position is NODE_Z(node); do some trick here to calculate distances between all nodes of a cell and store the maximum distance in a UDM (C_UDMI(c,t,0)=maxdistance)*/ } } end_c_loop(c, c_thread) } } |
|
February 7, 2014, 09:32 |
|
#5 | |
Member
Ali.E
Join Date: Sep 2010
Location: Lisboa
Posts: 83
Rep Power: 16 |
Thanks alot for the code. I have another question, how can I compute the distance? I mean that I have x,y,z coordinates of a node whereas I should have previous node coordinates too. In the cell node loop, I give just only one node coordinates. how does UDF save previous node coordinates?
Quote:
|
||
February 7, 2014, 09:40 |
|
#6 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
The UDF does not save the previous coordinates yet, this part you have to add
|
|
February 7, 2014, 11:51 |
|
#7 |
Member
Ali.E
Join Date: Sep 2010
Location: Lisboa
Posts: 83
Rep Power: 16 |
yes, thank you very much, but counter of the loop is the main problem, each cell has several nodes and in a cell node loop, I want to save the the coordinates, but i do not know what is the counter (???). I am beginer in C program and I have worked with Fortran.
c_node_loop(c,t,n) { node = C_NODE(c,t,n); x[???]=NODE_X(node); y[???]=NODE_Y(node); z[???]=NODE_Z(node); } |
|
February 7, 2014, 12:15 |
|
#8 | |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Quote:
Code:
int counter; float x[20],y[20],z[20]; //assuming each cell has 20 nodes or less ... counter=0; c_node_loop(c,t,n) { node = C_NODE(c,t,n); x[counter]=NODE_X(node); y[counter]=NODE_Y(node); z[counter]=NODE_Z(node); ++counter; } |
||
February 7, 2014, 14:36 |
|
#9 | |
Member
Ali.E
Join Date: Sep 2010
Location: Lisboa
Posts: 83
Rep Power: 16 |
Thank you very much. I have just written the UDF as below:
/* This UDF is used to compute relative length scale in DES model*/ #include "udf.h" DEFINE_ON_DEMAND(rls) { Domain *domain=Get_Domain(ROOT_DOMAIN_ID); Thread *c_thread; cell_t c; face_t f; Thread *tf; Node *node; int n,k,counter; real delx,dely,delz,deltamax,maxx=0,maxy=0,maxz=0; float x[10],y[10],z[10]; thread_loop_c(c_thread,domain) /*loops over all cell threads in domain*/ { begin_c_loop(c,c_thread) /* loops over cells in a cell thread */ { c_face_loop(c,c_thread,n) /* loops over faces in a cell thread */ { f=C_FACE(c,c_thread,n); tf = C_FACE_THREAD(c,c_thread,n); counter=0; f_node_loop(f,c_thread,n) /* loops over nodes in a face thread */ { node=F_NODE(c,c_thread,n); x[counter]=NODE_X(node); y[counter]=NODE_Y(node); z[counter]=NODE_Z(node); ++counter; } for (i=0; i<(counter-1); ++i) { for (k=i+1; k<counter; k++) { delx=fabs(fabs(x[i])-fabs(x[k])); dely=fabs(fabs(y[i])-fabs(y[k])); delz=fabs(fabs(z[i])-fabs(z[k])); if (delx>maxx) { maxx=delx; } if (dely>maxy) { maxy=dely; } if (delz>maxz) { maxz=delz; } } } } deltamax=0; if (deltamax<maxx) { deltamax=maxx; } if (deltamax<maxy) { deltamax=maxy; } if (deltamax<maxz) { deltamax=maxz; } C_UDMI(c,c_thread,0)=sqrt(C_K(c,c_thread))/(0.09*0.61*deltamax*C_O(c,c_thread)); } end_c_loop(c,c_thread) } } But it is not worked and it gives an error in Line 20 (c_face_loop(c,c_thread,n)). may I request you to make a comment about the UDF and the error? thanks, Quote:
|
||
February 7, 2014, 14:59 |
|
#10 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 27 |
Hmm, I think I copied that from the Fluent manual, I can not access that now, I'm sorry...
One different thing: your calculation of distance is wrong: Code:
delx=fabs(fabs(x[i])-fabs(x[k])); Code:
delx=fabs(x[i]-x[k]); |
|
February 7, 2014, 15:21 |
|
#11 | |
Member
Ali.E
Join Date: Sep 2010
Location: Lisboa
Posts: 83
Rep Power: 16 |
Many many thanks. I changed the delx,dely,delz, you are right. anyway, I recieve the error too. Please make a comment if you find any idea.
thanks again Quote:
|
||
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
whats the cause of error? | immortality | OpenFOAM Running, Solving & CFD | 13 | March 24, 2021 08:15 |
compressible flow in turbocharger | riesotto | OpenFOAM | 50 | May 26, 2014 02:47 |
udf for radial distribution function in a fluidised bed | ravindra | Fluent UDF and Scheme Programming | 0 | February 24, 2013 07:26 |
using METIS functions in fortran | dokeun | Main CFD Forum | 7 | January 29, 2013 05:06 |
Version 15 on Mac OS X | gschaider | OpenFOAM Installation | 113 | December 2, 2009 11:23 |