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

Please Help! Periodic Function that does not use sin/cos

Register Blogs Members List Search Today's Posts Mark Forums Read

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   December 25, 2013, 15:37
Default Please Help! Periodic Function that does not use sin/cos
  #1
New Member
 
Mike
Join Date: Dec 2013
Posts: 7
Rep Power: 12
mabbo009 is on a distinguished road
Im having a really tough time producing this periodic function. essentially, i want the pressure pulse to be turned on for .005 seconds and for that to occur every .01 seconds. This is my code.

/************************************************** *********************
stepfunction.c
UDF for specifying step pressure rise boundary condition
************************************************** **********************/
#include "udf.h"

DEFINE_PROFILE(unsteady_pressure, thread, position)
{
face_t f;
real t_1 = CURRENT_TIME;

int i=0;
float t1, t2, pressure;
t1=0.01*i;
t2=t1+0.005;

if (t_1>=t1 && t_1<=t2)
{
pressure = 101325.0*8.0;
}
else
{
pressure = 101325.0*1.0;
i++;
}


begin_f_loop(f,thread)
{
F_PROFILE(f, thread, position) = pressure;
}
end_f_loop(f, thread)

}


In this code I am getting the initial pulse, but after that nothing happens. This is what happens when an undergrad mech eng is assigned out of there comfort zone tasks. Any and all help is greatly appreciated.
mabbo009 is offline   Reply With Quote

Old   December 30, 2013, 07:59
Default
  #2
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
The problem is in this part:
Code:
real t_1 = CURRENT_TIME;

int i=0;
float t1, t2, pressure;
t1=0.01*i;
t2=t1+0.005;
I suspect that your intention was that variable "i" would loop over all integers, but this is not what happens; "i" is given the value 0, and never changes. That is why you only see one pulse. (Pulse number 0).

What you want, is to remove multiples of 0.01 seconds (your period) from the current time. One way to do this is to replace the code above by:

Code:
real t_1 = CURRENT_TIME;

float t1, t2, pressure;

t_1 -= (int)(t_1/0.01)*0.01;
t1=0;
t2=0.005;
What this code does: suppose that CURRENT_TIME=0.028.
Then at first, t_1=0.028.
If you would calculate t_1/0.01, you would get 2.8.
To round this down: (int)(t_1/0.01) gives 2 (which is 2.8 rounded down).
This means that there are two periods of 0.01 second before the current time. To remove them, subtract them from your initial time:
t_1=t_1 - (int)(t_1/0.01)*0.01.
This would give t_1=0.008 in the rest of your calculation.
Another way to write this in c, what I did in the code above, is t_1 -= (int)(t_1/0.01)*0.01.

Beware: I only derived this, I did not test it.
pakk is offline   Reply With Quote

Old   December 30, 2013, 15:11
Default It worked
  #3
New Member
 
Mike
Join Date: Dec 2013
Posts: 7
Rep Power: 12
mabbo009 is on a distinguished road
Thank you very much for this! My logic for programming is sub par and I doubt I would have figured this one out.
mabbo009 is offline   Reply With Quote

Old   December 31, 2013, 05:13
Default
  #4
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
You're welcome. You were very close to the solution by the way; now that I look at it again, I think your way of programming would have worked if you would have defined "int i=0" outside of your function, making it global. In that way it is not reinitialized to 0, every time that the function is called.

Anyway, it is nice to be able to help somebody who already thought about the problem!
pakk is offline   Reply With Quote

Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

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
[swak4Foam] installation problem with version 0.2.3 Claudio87 OpenFOAM Community Contributions 9 May 8, 2013 10:20
[blockMesh] non-orthogonal faces and incorrect orientation? nennbs OpenFOAM Meshing & Mesh Conversion 7 April 17, 2013 05:42
Periodic sinusoidal wall motion - Field Function smorls STAR-CCM+ 0 March 6, 2013 12:27
OpenFOAM static build on Cray XT5 asaijo OpenFOAM Installation 9 April 6, 2011 12:21
Version 15 on Mac OS X gschaider OpenFOAM Installation 113 December 2, 2009 10:23


All times are GMT -4. The time now is 11:09.