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

udf unsteady flow.

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 28, 2015, 21:54
Default udf unsteady flow.
  #1
New Member
 
elliot ward
Join Date: Mar 2015
Posts: 10
Rep Power: 11
elliot is on a distinguished road
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 22:03. Reason: needs to be in udf & scheming
elliot is offline   Reply With Quote

Old   March 28, 2015, 22:13
Default
  #2
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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.
`e` is offline   Reply With Quote

Old   March 28, 2015, 22:26
Default
  #3
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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)
Comments:
  • F_CENTROID is called, and y is evaluated, only once per loop through the faces
  • if/else statements are used to distinguish velocity values with time
  • trailing periods on integers to treat them as real numbers (good coding practice)
  • correct brackets and spacing makes the code easier to read
`e` is offline   Reply With Quote

Old   March 28, 2015, 22:55
Default
  #4
New Member
 
elliot ward
Join Date: Mar 2015
Posts: 10
Rep Power: 11
elliot is on a distinguished road
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
elliot is offline   Reply With Quote

Old   March 28, 2015, 23:02
Default
  #5
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
We don't know what your UDF looks like after you've made my recommended changes, can you post the new version?
`e` is offline   Reply With Quote

Old   March 28, 2015, 23:10
Default
  #6
New Member
 
elliot ward
Join Date: Mar 2015
Posts: 10
Rep Power: 11
elliot is on a distinguished road
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
elliot is offline   Reply With Quote

Old   March 28, 2015, 23:11
Default
  #7
New Member
 
elliot ward
Join Date: Mar 2015
Posts: 10
Rep Power: 11
elliot is on a distinguished road
Sorry, i did tab it but it has reformatted in the post.
elliot is offline   Reply With Quote

Old   March 28, 2015, 23:39
Default
  #8
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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.
`e` is offline   Reply With Quote

Old   March 29, 2015, 00:06
Default
  #9
New Member
 
elliot ward
Join Date: Mar 2015
Posts: 10
Rep Power: 11
elliot is on a distinguished road
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)
}
elliot is offline   Reply With Quote

Old   March 29, 2015, 00:33
Default
  #10
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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
Problem 2:
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
Fixed code:
Code:
if (t==2.)
{
    F_CENTROID(x,f,thread);
    F_PROFILE(f, thread, position) = 0.5;
}
The RP variable macro, RP_Get_Real("physical-time-step"), gives the current physical time step size (in seconds). If you were after the integer number of time steps, then you could directly access this value with the solver macro N_TIME, or indirectly access with the equivalent RP variable macro RP_Get_Integer("time-step").
`e` is offline   Reply With Quote

Old   March 29, 2015, 00:39
Default
  #11
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
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.
`e` is offline   Reply With Quote

Old   March 29, 2015, 01:43
Default
  #12
New Member
 
elliot ward
Join Date: Mar 2015
Posts: 10
Rep Power: 11
elliot is on a distinguished road
Cheers mate, its working now. Your a god send. Sorry it took so long for me to get there.
elliot is offline   Reply With Quote

Old   March 29, 2015, 01:52
Default
  #13
`e`
Senior Member
 
Join Date: Mar 2015
Posts: 892
Rep Power: 18
`e` is on a distinguished road
Awesome, thanks, glad to hear it's working!
`e` 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
unsteady inlet velocity udf jill FLUENT 8 February 10, 2015 06:04
Unsteady interna flow yhoarau OpenFOAM Running, Solving & CFD 2 June 5, 2012 10:42
Unsteady flow and DPM moloykb FLUENT 5 March 21, 2012 03:28
unsteady UDF Sukanta Bhattacharjee FLUENT 0 August 20, 2007 11:11
a UDF for unsteady flow mike FLUENT 0 August 7, 2007 08:06


All times are GMT -4. The time now is 06:57.