CFD UDF
I am trying to write a UDF that relates the changing crosssectional diameter of 3D irregular channel to the viscosity.
To find the diameter I thought about finding the area of a cross section and find the diameter from there. Thus I need a UDF to add the facets area of a cross section of the channel.
Also can I use the same function to relate several cross sections to the following empirical equation to have changing viscosity along the segment? viscosity= 0.022* exp(Diameter^0.3)
Best Answers

YasserSelima Posts: 944Member
Yes you can use it along the segment ... but it is really tough. There is a macro that loop over the cell faces ... and there is a macro that returns the cells on both sides of the face ... so, you can actually move from a cell to the next. But this is really long to be done every time step for every single cell. Alternatively, do it once through DEFINE_ON_DEMAND and save it in UDM .. then use it during simulations.
However, I believe it is easier to use any CAD software and find the area/diameter as a function of X ...

YasserSelima Posts: 944Member
Not sure about tutorial use UDM, but the procedure is easy ... first you need to set the number of user defined memory in your case. From the graphical user interface, UserDefined then memory and increase the number to 1 or more based on how many variable you need to save.
Then, in your function, the macro is C_UDMI(c,t,i) ... for example
C_UDMI(c,t,0) = 1;
This saves 1 to the UDM number 0 for the cell c in the cell_thread t ... and when you need to use it,x=C_UDMI(c,t,0);
and this makes equal to the value stored in the UDMFor face, same macro but F_UDMI(f,t,i) .. and for nodes N_UDMI ... note that the number available for nodes is set separately.
Answers
Can you show the geometry and the cross section you mean
here is a part of the segment
Is this cross section function of x? You know the equation A=f(x) ?
the flow is in x direction
However, how does the CCENTROID help me in finding the average diameter of the 3D segment. Will this diameter be based on the the average length in the y and the z direction.
You know the geometry, right? Can you find the area/diameter as a function of X?
That is my problem. the geometry is changing and I was thinking about using f_area but I am not sure whether I can use it along the segment?
The segment has an irregularly changing shape thus the CAD software might not be useful.
Is there any tutorial or maybe manual recommendations that might help me use the UDM since I am a beginner
You have to set the number before compiling the code to avoid Fluent crashing
You answers are really helpful. The UDM is explained very nicely thank you.
Just one last thing the value that will be saved to the UDM which is the diameter. Will the diameters be found separately then assigned to each UDMI or there is a direct way to assign them.
You need to loop over all cells ... Inside every loop you are going to loop over faces. There is a macro that tells you if the face is a boundary face or not. Once you find one face as a boundary, check the centroid of the cell to know this is the bottom boundary. ... and now the fun begins. Loop over the faces, find the length of the right face and move to the upper face, find the cell on the other side .. repeat and add the length of the right face to the sum ... at the end, you know the length ... do the loop backowrd to save the sum to all the UDMs of these cells ...
There are many macros under connectivity macros that will help you very much.
Loop over the faces of the outer boundary ...
the macro F_CENTROID(x,f,t) gives you x ... where,
x[0] , x[1], x[2] are the x,y and z coordinates ... if you print this in a file, you can sort them by x and for every x, get y_max and y_min .. z_max and min ... and now you can get an estimation of the area