|
[Sponsors] |
March 28, 2015, 22:54 |
udf unsteady flow.
|
#1 |
New Member
elliot ward
Join Date: Mar 2015
Posts: 10
Rep Power: 11 |
Hi all first time poster here so i'l keep it short and sweet.
Im trying to write a udf for a unsteady flow that varies with time step on a pipe in 2d, (I am having great difficulty). I have written a udf (below), however when I run it in fluent it only runs the last velocity and misses out the rest. Can anyone spot my mistake/s? Any help would be much appreciated. #include "udf.h" DEFINE_PROFILE(inlet_x_velocity, thread, position) { real x[ND_ND]; real y; real t = RP_Get_Real("physical-time-step"); face_t f; begin_f_loop(f, thread) {if (t<=10); F_CENTROID(x,f,thread); y = x[1]; F_PROFILE(f, thread, position) = 1; } {if (t<=11 && t>10); F_CENTROID(x,f,thread); y = x[1]; F_PROFILE(f, thread, position) = 0.5; } {if (t<=12 && t>11); F_CENTROID(x,f,thread); y = x[1]; F_PROFILE(f, thread, position) = 3; } {if (t<=13 && t>12); F_CENTROID(x,f,thread); y = x[1]; if (y<=7) F_PROFILE(f, thread, position) = 9; } if (t<=14 && t>13); { F_CENTROID(x,f,thread); y = x[1]; F_PROFILE(f, thread, position) = 5; } end_f_loop(f, thread) } Last edited by elliot; March 28, 2015 at 23:03. Reason: needs to be in udf & scheming |
|
March 28, 2015, 23:13 |
|
#2 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
First, use tabs and spaces to make your code easier to read. I've tried to make sense of your code but the brackets don't seem to match; does this code compile?
Second, I don't think those if statements are doing what you're intending, have a read of this tutorial on loops in C. |
|
March 28, 2015, 23:26 |
|
#3 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
Here's an example of your first two cases:
Code:
begin_f_loop(f, thread) { F_CENTROID(x,f,thread); y = x[1]; if (t<=10.) F_PROFILE(f, thread, position) = 1.; else if (t<=11.) F_PROFILE(f, thread, position) = 0.5; } end_f_loop(f, thread)
|
|
March 28, 2015, 23:55 |
|
#4 |
New Member
elliot ward
Join Date: Mar 2015
Posts: 10
Rep Power: 11 |
Hi thanks for the reply, yes i can interpret the udf, and have made the recommend changes however fluent still only runs the last velocity profile. Is there anything else you can suggest?
Also sorry for the poor code formatting, and the double posting |
|
March 29, 2015, 00:02 |
|
#5 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
We don't know what your UDF looks like after you've made my recommended changes, can you post the new version?
|
|
March 29, 2015, 00:10 |
|
#6 |
New Member
elliot ward
Join Date: Mar 2015
Posts: 10
Rep Power: 11 |
Sorry, i did tab it but it has reformatted in the post. also i exclude the else term as the caused a parse error,
#include "udf.h" DEFINE_PROFILE(inlet_x_velocity, thread, position) { real x[ND_ND]; real y; real t = RP_Get_Real("physical-time-step"); face_t f; begin_f_loop(f, thread) { if (t<=1.); F_CENTROID(x,f,thread); y = x[1]; F_PROFILE(f, thread, position) = 1; } { if (t<=2.); F_CENTROID(x,f,thread); y = x[1]; F_PROFILE(f, thread, position) = 0.5; } { if (t<=3.); F_CENTROID(x,f,thread); y = x[1]; F_PROFILE(f, thread, position) = 3; } { if (t<=4.); F_CENTROID(x,f,thread); y = x[1]; if (y<=7) F_PROFILE(f, thread, position) = 9; } { if (t<=5.); F_CENTROID(x,f,thread); y = x[1]; F_PROFILE(f, thread, position) = 5; } end_f_loop(f, thread) } Cheers |
|
March 29, 2015, 00:11 |
|
#7 |
New Member
elliot ward
Join Date: Mar 2015
Posts: 10
Rep Power: 11 |
Sorry, i did tab it but it has reformatted in the post.
|
|
March 29, 2015, 00:39 |
|
#8 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
You can use the [CODE] tags for inserting code into posts (retaining the tabs/spacing).
As for your code, again, I recommend you reading this page on if loops because your incorrect usage of the if statements is causing your velocity profile to be defined by your last case. Have a think about what velocity is applied to which face and at which time because currently they're not defined for t > 5 s and for y > 7 m at t <= 4 s. |
|
March 29, 2015, 01:06 |
|
#9 |
New Member
elliot ward
Join Date: Mar 2015
Posts: 10
Rep Power: 11 |
First thanks for spending your time trying to help me. Is this code the correct format for a change in velocity with time step rather than time? also i have tried this variation, still with no luck.
Code:
#include "udf.h" DEFINE_PROFILE(inlet_x_velocity, thread, position) { real x[ND_ND]; real y; real t = RP_Get_Real("physical-time-step"); face_t f; begin_f_loop(f, thread) if (t==1.); F_CENTROID(x,f,thread); y = x[1]; F_PROFILE(f, thread, position) = 1; if (t==2.); F_CENTROID(x,f,thread); F_PROFILE(f, thread, position) = 0.5; if (t==3.); F_CENTROID(x,f,thread); F_PROFILE(f, thread, position) = 3; if (t==4.); F_CENTROID(x,f,thread); if (y<=7) F_PROFILE(f, thread, position) = 9; if (t==5.); F_CENTROID(x,f,thread); F_PROFILE(f, thread, position) = 5; } end_f_loop(f, thread) } |
|
March 29, 2015, 01:33 |
|
#10 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
No worries.
You're still missing the if statement problem so I'll be specific: the semicolon is used to terminate a statement in C, and you've used this semicolon immediately after you've provided the condition of said statement. The second problem with your if statements is that you've not included curly brackets to include multiple lines of code. Problem 1: Code:
if (t==3.); // if t is equal to 3, then do nothing extra F_CENTROID(x,f,thread); // this line is read regardless of whether t==3. or not F_PROFILE(f, thread, position) = 3; // same as the line above Code:
if (t==2.) // correct if statement but only the next line is included F_CENTROID(x,f,thread); // this line is read if t==2. F_PROFILE(f, thread, position) = 0.5; // this line is always read Code:
if (t==2.) { F_CENTROID(x,f,thread); F_PROFILE(f, thread, position) = 0.5; } |
|
March 29, 2015, 01:39 |
|
#11 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
Also, you're missing a starting curly bracket for begin_f_loop.
What velocities are you trying to define (provide both time and position in your descriptions)? I still don't think your logic with the if statements is quite right. |
|
March 29, 2015, 03:43 |
|
#12 |
New Member
elliot ward
Join Date: Mar 2015
Posts: 10
Rep Power: 11 |
Cheers mate, its working now. Your a god send. Sorry it took so long for me to get there.
|
|
March 29, 2015, 03:52 |
|
#13 |
Senior Member
Join Date: Mar 2015
Posts: 892
Rep Power: 18 |
Awesome, thanks, glad to hear it's working!
|
|
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
unsteady inlet velocity udf | jill | FLUENT | 8 | February 10, 2015 07:04 |
Unsteady interna flow | yhoarau | OpenFOAM Running, Solving & CFD | 2 | June 5, 2012 11:42 |
Unsteady flow and DPM | moloykb | FLUENT | 5 | March 21, 2012 04:28 |
unsteady UDF | Sukanta Bhattacharjee | FLUENT | 0 | August 20, 2007 12:11 |
a UDF for unsteady flow | mike | FLUENT | 0 | August 7, 2007 09:06 |