|
[Sponsors] |
Creating UDF with changing velocity with time |
|
LinkBack | Thread Tools | Search this Thread | Display Modes |
March 9, 2017, 01:12 |
Creating UDF with changing velocity with time
|
#1 |
New Member
Join Date: Mar 2017
Posts: 6
Rep Power: 9 |
Hi all,
I was asked to write the UDF for a 2D room and it has to change velocity in terms of time. Like, when the time is 0 to 2 seconds, the velocity magnitude is horizontal. Then 2 to 4 seconds, the velocity changes magnitude and so on until the velocity is vertical. For example, the velocity is flowing into the inlet at 0 degree then changes with time to 90 degrees. After that, it flows down to 0 degree then repeat. It is like moving fan blowing into the inlet from 0 degree to 90 degrees. Please help with this because I have no knowledge on writing UDF at all. Thanks! |
|
March 9, 2017, 03:21 |
|
#2 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26 |
If you have no knowledge on UDFs at all, then start by looking in the Fluent help. See if you can find a UDF that does something similar to what you want, and think about what should be changed. Try this (and don't be afraid to make mistakes).
Then come back here with your first attempt, and we can help from there. |
|
March 9, 2017, 03:53 |
|
#3 | |
New Member
Join Date: Mar 2017
Posts: 6
Rep Power: 9 |
Quote:
Can you help me see whether this CFD is valid? /************************************************** ********************* UDF for transient ************************************************** **********************/ #include "udf.h" DEFINE_PROFILE(velocity_magnitude, t, i) { real velocity; real the_current_time; face_t f; real x; real y; the_current_time = CURRENT_TIME; if ((the_current_time>=0) && (the_current_time<2)) { x=0.1; y=0; } if ((the_current_time>=2) && (the_current_time<4)) { x=0.1; y=0.05; } if ((the_current_time>=4) && (the_current_time<6)) { x=0.1; y=0.1; } if ((the_current_time>=6) && (the_current_time<8)) { x=0.15; y=0.15; } if ((the_current_time>=8) && (the_current_time<10)) { x=0.20; y=0.20; } if ((the_current_time>=10) && (the_current_time<12)) { x=0.25; y=0.25; } if ((the_current_time>=12) && (the_current_time<14)) { x=0.30; y=0.30; } if ((the_current_time>=14) && (the_current_time<16)) { x=0.35; y=0.35; } if ((the_current_time>=16) && (the_current_time<18)) { x=0.40; y=0.40; } if ((the_current_time>=18) && (the_current_time<20)) { x=0.45; y=0.45; } if ((the_current_time>=20) && (the_current_time<22)) { x=0.50; y=0.50; } if ((the_current_time>=22) && (the_current_time<24)) { x=0.55; y=0.55; } if ((the_current_time>=24) && (the_current_time<26)) { x=0.60; y=0.60; } if ((the_current_time>=26) && (the_current_time<28)) { x=0.65; y=0.65; } if ((the_current_time>=28) && (the_current_time<30)) { x=0.70; y=0.70; } if ((the_current_time>=30) && (the_current_time<32)) { x=0.75; y=0.75; } if ((the_current_time>=32) && (the_current_time<34)) { x=0.80; y=0.80; } if ((the_current_time>=34) && (the_current_time<36)) { x=0.85; y=0.85; } if ((the_current_time>=36) && (the_current_time<38)) { x=0.90; y=0.90; } if ((the_current_time>=38) && (the_current_time<40)) { x=0.95; y=0.95; } if ((the_current_time>=40) && (the_current_time<42)) { x=1.0; y=1.0; } if ((the_current_time>=42) && (the_current_time<44)) { x=1.05; y=1.05; } if ((the_current_time>=44) && (the_current_time<46)) { x=1.10; y=1.10; } if ((the_current_time>=46) && (the_current_time<48)) { x=1.15; y=1.15; } if ((the_current_time>=48) && (the_current_time<50)) { x=1.20; y=1.20; } if ((the_current_time>=50) && (the_current_time<52)) { x=1.25; y=1.25; } if ((the_current_time>=52) && (the_current_time<54)) { x=1.30; y=1.30; } if ((the_current_time>=54) && (the_current_time<56)) { x=1.35; y=1.35; } if ((the_current_time>=56) && (the_current_time<58)) { x=1.40; y=1.40; } if ((the_current_time>=58) && (the_current_time<60)) { x=1.45; y=1.45; } if ((the_current_time>=60)) { x=1.5; y=1.5; } begin_f_loop(f,t) { F_PROFILE(f,t,i) = velocity=sqrt(pow(x,2)+pow(y,2)); } end_f_loop(f,t) } |
||
March 9, 2017, 04:04 |
|
#4 | |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26 |
Quote:
I see only one problem in this line: Code:
F_PROFILE(f,t,i) = velocity=sqrt(pow(x,2)+pow(y,2)); The solution that is easiest to understand: make two udfs, one for the x-component and one for the y-component. They can look identical to your UDF, except for the name and the F_PROFILE-line: Code:
DEFINE_PROFILE(velocity_x, t, i) .... F_PROFILE(f,t,i) = x; ... ... DEFINE_PROFILE(velocity_y, t, i) .... F_PROFILE(f,t,i) = y; ... } |
||
March 9, 2017, 04:37 |
|
#5 | |
New Member
Join Date: Mar 2017
Posts: 6
Rep Power: 9 |
Quote:
Actually I was thinking that it can be travelling in constant velocity but the direction of flow needs to vary. So I might want to throw in an angle, like theta to simulate the change of direction of the flow. How can I go about it? or is there other functions to write on it? |
||
March 9, 2017, 04:46 |
|
#6 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26 |
You still have to give x and y components to Fluent. So if you want to use an angle, you have to calculate components by yourself.
But you can use the sine and cosine functions. So, if you have calculated/specified velocity magnitude vmag and angle theta (in radians!), you can use this kind of line: Code:
F_PROFILE(f,t,i) = vmag * cos(theta); |
|
March 9, 2017, 09:27 |
|
#7 | |
New Member
Join Date: Mar 2017
Posts: 6
Rep Power: 9 |
Quote:
Hi! Does this seem correct? /************************************************** ********************* UDF for transient ************************************************** **********************/ #include "udf.h" DEFINE_PROFILE(velocity_x, t, i) { face_t f; real x; real the_current_time; the_current_time = CURRENT_TIME; if ((the_current_time>=0) && (the_current_time<10)) { x=0.1; } begin_f_loop(f,t) { F_PROFILE(f,t,i) = x; } end_f_loop(f,t) } DEFINE_PROFILE(velocity_y, t, i) { face_t f; real y; real the_current_time; the_current_time = CURRENT_TIME; if ((the_current_time>=0) && (the_current_time<2)) { y=0; } if ((the_current_time>=2) && (the_current_time<4)) { y=0.05; } if ((the_current_time>=4) && (the_current_time<6)) { y=0.1; } if ((the_current_time>=6) && (the_current_time<8)) { y=0.2; } if ((the_current_time>=8) && (the_current_time<10)) { y=0.3; } begin_f_loop(f,t) { F_PROFILE(f,t,i) = y; } end_f_loop(f,t) } DEFINE_PROFILE(velocity_magnitude, t, i) { real velocity; real theta; face_t f; real x; real y; begin_f_loop(f,t) { F_PROFILE(f,t,i) = velocity * cos(theta); velocity=sqrt(pow(x,2)+pow(y,2)); theta=atan2(y,x); } end_f_loop(f,t) } |
||
March 9, 2017, 09:40 |
|
#8 |
Senior Member
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26 |
The x-component and y-component seem ok.
The "velocity_magnitude" is wrong. First of all: you don't need it. But even if you would need it: * you calculate vmag and theta after you use them. That is the wrong order. * you calculate vmag and theta using x and y, but x and y are not defined. (They are defined in a different function, but that does not count.) * the velocity magnitude is sqrt(x^2+y^2), no need for cos(theta). So, remove the velocity_magnitude part. And then just try it. The best way to know if your UDF is correct is by using it. |
|
March 9, 2017, 09:46 |
|
#9 | |
New Member
Join Date: Mar 2017
Posts: 6
Rep Power: 9 |
Quote:
But how do i set the time step and number of time steps? I keep getting reversed flow after running for awhile. |
||
Tags |
#ansys, #cfd, #fluent, #timestep, #velocity |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
AMI speed performance | danny123 | OpenFOAM | 21 | October 24, 2020 04:13 |
Time dependent angular velocity calculation UDF | shashankmechguy | Fluent UDF and Scheme Programming | 1 | July 26, 2018 02:23 |
UDF for time dependent angular velocity calculation | shashankmechguy | Fluent UDF and Scheme Programming | 2 | October 24, 2016 04:43 |
Floating point exception error | lpz_michele | OpenFOAM Running, Solving & CFD | 53 | October 19, 2015 02:50 |
Moving mesh | Niklas Wikstrom (Wikstrom) | OpenFOAM Running, Solving & CFD | 122 | June 15, 2014 06:20 |