CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

UDF for calculating angular velocity in a rotating tank

Register Blogs Community New Posts Updated Threads Search

Like Tree11Likes

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   June 11, 2020, 01:33
Default UDF for calculating angular velocity in a rotating tank
  #1
Member
 
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6
vavnoon is on a distinguished road
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.
Attached Files
File Type: txt udm.txt (507 Bytes, 42 views)
vavnoon is offline   Reply With Quote

Old   June 11, 2020, 06:02
Default
  #2
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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
vavnoon likes this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   June 11, 2020, 07:56
Default
  #3
Member
 
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6
vavnoon is on a distinguished road
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.
vavnoon is offline   Reply With Quote

Old   June 13, 2020, 13:39
Default
  #4
Member
 
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6
vavnoon is on a distinguished road
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
vavnoon is offline   Reply With Quote

Old   June 15, 2020, 04:24
Default Domain and UDMs
  #5
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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.
vavnoon likes this.
__________________
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.
vinerm is offline   Reply With Quote

Old   June 16, 2020, 11:30
Default
  #6
Member
 
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6
vavnoon is on a distinguished road
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)
}


}
vavnoon is offline   Reply With Quote

Old   June 16, 2020, 11:44
Default
  #7
Member
 
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6
vavnoon is on a distinguished road
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
vavnoon is offline   Reply With Quote

Old   June 16, 2020, 11:57
Default Functions
  #8
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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.
vavnoon likes this.
__________________
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.
vinerm is offline   Reply With Quote

Old   June 16, 2020, 13:03
Default
  #9
Member
 
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6
vavnoon is on a distinguished road
Many thanks,

I tried the way as you recommended but it didn't make a difference.
vavnoon is offline   Reply With Quote

Old   June 16, 2020, 13:09
Default Error
  #10
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
What error do you get?
vavnoon likes this.
__________________
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.
vinerm is offline   Reply With Quote

Old   June 16, 2020, 13:16
Default
  #11
Member
 
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6
vavnoon is on a distinguished road
I don't get any error, but the UDM shows zero in everwhere.
vavnoon is offline   Reply With Quote

Old   June 16, 2020, 14:05
Default Udm
  #12
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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.
vavnoon likes this.
__________________
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.
vinerm is offline   Reply With Quote

Old   June 16, 2020, 15:07
Default
  #13
Member
 
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6
vavnoon is on a distinguished road
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.
vavnoon is offline   Reply With Quote

Old   June 16, 2020, 15:35
Default Angular Velocity
  #14
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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?
vavnoon likes this.
__________________
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.
vinerm is offline   Reply With Quote

Old   June 16, 2020, 16:35
Default
  #15
Member
 
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6
vavnoon is on a distinguished road
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.
vavnoon is offline   Reply With Quote

Old   June 17, 2020, 04:54
Default Tangential Velocity
  #16
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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.
vavnoon likes this.
__________________
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.
vinerm is offline   Reply With Quote

Old   June 17, 2020, 08:26
Default
  #17
Member
 
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6
vavnoon is on a distinguished road
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.
Attached Images
File Type: png 1.PNG (17.3 KB, 16 views)
File Type: png 2.PNG (29.5 KB, 9 views)
File Type: png 3.PNG (23.6 KB, 9 views)
File Type: png 4.PNG (32.8 KB, 9 views)
File Type: png 5.PNG (108.2 KB, 14 views)
vavnoon is offline   Reply With Quote

Old   June 17, 2020, 08:36
Default Cff
  #18
Senior Member
 
vinerm's Avatar
 
Vinerm
Join Date: Jun 2009
Location: Nederland
Posts: 2,946
Blog Entries: 1
Rep Power: 36
vinerm will become famous soon enough
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.
vavnoon likes this.
__________________
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.
vinerm is offline   Reply With Quote

Old   June 18, 2020, 11:23
Default
  #19
Member
 
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6
vavnoon is on a distinguished road
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
Attached Images
File Type: png o2.PNG (10.3 KB, 11 views)

Last edited by vavnoon; June 18, 2020 at 11:27. Reason: Attach file
vavnoon is offline   Reply With Quote

Old   June 18, 2020, 12:35
Default
  #20
Member
 
vav noon
Join Date: May 2020
Posts: 49
Rep Power: 6
vavnoon is on a distinguished road
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.).
vavnoon is offline   Reply With Quote

Reply


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


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


All times are GMT -4. The time now is 16:00.