|
[Sponsors] |
UDF for calculating angular velocity in a rotating tank |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
June 11, 2020, 01:33 |
UDF for calculating angular velocity in a rotating tank
|
#1 |
Member
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6 |
Dear friends,
I am trying to make a simulation of flow in a rotating tank using mesh motion. I want to compute angular velocity in any arbitrary cell after each time step. So I wrote the following UDF using the C_UDMI macro. After applying it and running my case in fluent, I plotted angular velocity contours in several planes. But all of them show the value of zero. I do not know where I am wrong. I appreciate it if you can help me in this regard. Thank you so much. |
|
June 11, 2020, 06:02 |
|
#2 |
Senior Member
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34 |
add d = Get_Domain(1); before loop
you may use Message0 macro to check internal variables used in your code more information in Ansys Fluent Customization manual
__________________
best regards ****************************** press LIKE if this message was helpful |
|
June 11, 2020, 07:56 |
|
#3 |
Member
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6 |
Dear Alexander,
Thank you so much for your comment. Are you sure this expression (d = Get_Domain(1)) is needed? It should be noted that there is no mixture in my case and I have one domain. I think this macro is used when the flow is multiphase. However, I added this to my UDF and tried it. I got the same contours. Do you have any suggestions? Thank you in advance. |
|
June 13, 2020, 13:39 |
|
#4 |
Member
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6 |
For applying the UDM, I just increased the number of User_Defined_Memory to one. Then I interpreted it.
Is it correct? Thank you so much |
|
June 15, 2020, 04:24 |
Domain and UDMs
|
#5 |
Senior Member
|
Domain is always required if you want to fetch or apply any data on to any field, therefore, you need to set d = Get_Domain(1). For multiphase applications, there are always, at least, three domains, while single phase has one.
UDM is a memory and must be set to the number as per the usage in the UDF. Since your UDF is using only one memory, you need to set it to 1. Before using it in the UDF, you also need to initialize the UDM, either using Initialize or using Patch. You can also initialize the UDM values within UDF. But if you access it without initialization, as you are doing it in your code, it will give error.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
June 16, 2020, 11:30 |
|
#6 |
Member
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6 |
Dear Vinerm,
I can't thank you enough. What I understood is that I should use DEFINE_INIT or DEFINE_ON_DEMAND for UDM initialization. So the first time I decided to replace DEFINE_EXECUTE_AT_END with DEFINE_ON_DEMAND. The following is my new UDF. DEFINE_ON_DEMAND(omega) { Domain *d; Thread *t; cell_t c; d = Get_Domain(1); real pos[ND_ND]; real x, z, r, u, w; real Tg_vel; /*tangential velocity*/ real ang_vel; /*angular velocity*/ thread_loop_c(t,d) { begin_c_loop(c,t) { C_CENTROID(pos,c,t); x=pos[0]; z=pos[2]; /*rotating in the y direction*/ r=sqrt(x*x+z*z); u=C_U(c,t); w=C_W(c,t); Tg_vel=sqrt(u*u+w*w); if(r!=0) ang_vel=Tg_vel/r; else ang_vel=0.; C_UDMI(c,t,0)=ang_vel; } end_c_loop(c,t) } } |
|
June 16, 2020, 11:44 |
|
#7 |
Member
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6 |
The second time I decided to use DEFINE_INIT.
Here is my code. # include "udf.h" DEFINE_INIT(initialize,d) { cell_t c; Thread *t; int i; thread_loop_c(t,d) { if (FLUID_THREAD_P(t)) { begin_c_loop(c,t) { for (i=0;i<sg_udm;++i) C_UDMI(c,t,0)=0.0; } end_c_loop_all(c,t) } } } DEFINE_EXECUTE_AT_END(omega) { cell_t c; Thread *t; Domain *d; real pos[ND_ND]; real x, z, r, u, w; real Tg_vel; /*tangential velocity*/ real ang_vel; /*angular velocity*/ d = Get_Domain(1); if (!check_for_UDM()) /* so check for their availability.. */ return; thread_loop_c(t,d) { begin_c_loop_all(c,t) { C_CENTROID(pos,c,t); /*rotating in the y direction*/ x=pos[0]; z=pos[2]; r=sqrt(x*x+z*z); u=C_U(c,t); w=C_W(c,t); Tg_vel=sqrt(u*u+w*w); if(r!=0) ang_vel=Tg_vel/r; else ang_vel=0.; C_UDMI(c,t,0)=ang_vel; } end_c_loop_all(c,t) } } When I interpreted it, I faced some errors. Could anyone please guide me? Thank you so much |
|
June 16, 2020, 11:57 |
Functions
|
#8 |
Senior Member
|
You don't need DEFINE_INIT. Just patch the values for UDM to 0 or initialize the case. So, remove the entire function.
And there is no function called check_for_UDM. No need to use it. Replace r!=0 with r!=0., i.e., add a point at the end. Then it will work alright.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
June 16, 2020, 13:03 |
|
#9 |
Member
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6 |
Many thanks,
I tried the way as you recommended but it didn't make a difference. |
|
June 16, 2020, 13:09 |
Error
|
#10 |
Senior Member
|
What error do you get?
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
June 16, 2020, 13:16 |
|
#11 |
Member
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6 |
I don't get any error, but the UDM shows zero in everwhere.
|
|
June 16, 2020, 14:05 |
Udm
|
#12 |
Senior Member
|
There could be two reasons for that. Firstly, you forgot to hook the UDF after compilation or interpretation. Secondly, there is something wrong with the calculation and the condition never turns out to be true. Otherwise, you would get correct numbers.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
June 16, 2020, 15:07 |
|
#13 |
Member
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6 |
I have already hooked it. Also, I tried to use code just written with Fluent macros.
Here it is: # include "udf.h" DEFINE_EXECUTE_AT_END(omega) { cell_t c; Thread *t; Domain *d; real u; d = Get_Domain(1); thread_loop_c(t,d) { begin_c_loop(c,t) { u=C_U(c,t); C_UDMI(c,t,0)=u; } end_c_loop(c,t) } } Contours plotted this way show zero, although I get non-zero value contours using X velocity at the same planes. Maybe the system running has trouble. Thank you for your time and useful advice. |
|
June 16, 2020, 15:35 |
Angular Velocity
|
#14 |
Senior Member
|
Though it should work yet any particular reason for using UDF. If all you need is angular velocity, then that is directly available under Velocity. Why do you want to save it in UDM?
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
June 16, 2020, 16:35 |
|
#15 |
Member
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6 |
How can I get angular velocity? I didn't find it in FLUENT.
As I mentioned earlier, I want to simulate flow in a rotating tank using mesh motion. It is expected the rotational velocity be variable. After running, I plotted tangential velocity on several planes. The contours show a linear trend. So I want to calculate omega. Anyway, I may need to save some parameters using UDM later. I do appreciate your help. |
|
June 17, 2020, 04:54 |
Tangential Velocity
|
#16 |
Senior Member
|
Tangential Velocity is tangential velocity. You just need to define a custom-field-function as ratio of tangential velocity and radial coordinate. You don't need a UDF for that.
And as far as UDF is concerned, it works perfectly fine as well. I checked it at my end. You might be making some mistake. The process to be followed is as follows. 1. Ensure there is 1 UDM. 2. Patch 0 as its value 3. Compile UDF (I have not tried Interpreter, most likely it should work) 4. Execute UDF using GUI or command (if using DEFINE_ON_DEMAND) or run simulation for a couple of iterations or time-steps after hooking the UDF in its correct place if using DEFINE_EXECUTE_AT_END 5. Display UDM In my opinion, your mistake might be at step 4.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
June 17, 2020, 08:26 |
|
#17 |
Member
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6 |
Dear Vinerm,
I attach a file that exactly shows the process I made it, as you kindly recommended. I'm not familiar with the custom field function. It's better to try to learn it. Thanks so much for your help, I really appreciate it. |
|
June 17, 2020, 08:36 |
Cff
|
#18 |
Senior Member
|
Custom Field Functions are much simpler; just expressions based on primitive or available fields. Those are also available on the same ribbon as User Defined Functions.
Furthermore, how many iterations did you run before displaying UDMs? Do note if angular velocity is really 0, then the UDF is working but the numbers in the UDM will be 0. So, initialize with some random velocity values or check if the tangential velocity is non-zero.
__________________
Regards, Vinerm PM to be used if and only if you do not want something to be shared publicly. PM is considered to be of the least priority. |
|
June 18, 2020, 11:23 |
|
#19 |
Member
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6 |
Many thanks for your advice,
I defined rotational velocity using Custom Field Functions. You're right, it's much simpler. I do appreciate it again. I've attached a pic depicts omega in the midplane. As you can see, It shows that omega varies radially in the narrow region, actually high gradient region, around the rotational axis and it is constant in elsewhere. Does it demonstrate the existence of vortex? Could anyone please help me to understand the physical interpretation? Additional information: 1). Fluid properties: water (rho=993.306, mu=0.0006965) 2). The rotational velocity of the tank: -25 rpm (-2.618 rad/s) Thank you Last edited by vavnoon; June 18, 2020 at 11:27. Reason: Attach file |
|
June 18, 2020, 12:35 |
|
#20 |
Member
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6 |
Furthermore, how many iterations did you run before displaying UDMs? Do note if angular velocity is really 0, then the UDF is working but the numbers in the UDM will be 0. So, initialize with some random velocity values or check if the tangential velocity is non-zero.[/QUOTE]
I displayed UDM before running and also after 100 time steps (every time step has 30 iterations and take 0.001 seconds.). |
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
UDF for inlet velocity alongwith UDF for properties | akshayy224 | FLUENT | 0 | February 1, 2018 10:17 |
[Transient Simulation] Angular Velocity dependent on different parameters than time | ThalesMachado | CFX | 1 | July 28, 2017 07:36 |
UDF for time dependent angular velocity calculation | shashankmechguy | Fluent UDF and Scheme Programming | 2 | October 24, 2016 05:43 |
UDF for defining a body force in Singel ROtating Reference Frame | teymourj | Fluent UDF and Scheme Programming | 9 | August 18, 2016 16:33 |
UDF velocity and temperature | Raj | FLUENT | 3 | February 1, 2009 19:29 |