CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   UDF for Square Wave (http://www.cfd-online.com/Forums/fluent/43068-udf-square-wave.html)

Emmanuel December 8, 2006 06:57

UDF for Square Wave
 
Hi,

How can I write a simple UDF for a square wave.

Frequency is 220hz

Mean value is 15.59psi

Amplitude is 0.89psi

I want to compare a square wave with my sinusoidal wave.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

#include "udf.h"

DEFINE_PROFILE(unsteady_pressure, thread, position) {

float t, pressure; face_t f;

t = RP_Get_Real("flow-time");

pressure = (15.59+(0.89*sin(220*6.283185307*t)))*6894.757;

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

}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%


Phil December 9, 2006 13:49

Re: UDF for Square Wave
 
I did this at one time. I used a cycle fraction to define when to switch from the positive side of the cycle to negative side.
Calculate cycle fraction as cycle fraction = t/T
where t= flow time and T=time period (1/220)
then use this simple code in place of your last line.


CODE:

begin_f_loop (f, thread)
{
if (cyc_frac < 0.5)
{
F_PROFILE(f,thread,position) = 16.48;
}
else
{
F_PROFILE (f,thread,position) = 14.7;
}
}
end_f_loop (f, thread)


Hope this helps,
Phil

mahbube March 13, 2010 08:36

question
 
Quote:

Originally Posted by Emmanuel
;137486
Hi,

How can I write a simple UDF for a square wave.

Frequency is 220hz

Mean value is 15.59psi

Amplitude is 0.89psi

I want to compare a square wave with my sinusoidal wave.

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

#include "udf.h"

DEFINE_PROFILE(unsteady_pressure, thread, position) {

float t, pressure; face_t f;

t = RP_Get_Real("flow-time");

pressure = (15.59+(0.89*sin(220*6.283185307*t)))*6894.757;

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

}

%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

hi,
would you please say me how you write pressure equation for sinusoidal wave?could you send/give or/and even introduce me some references


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