CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   Help! Function not LOOPing (http://www.cfd-online.com/Forums/fluent/48797-help-function-not-looping.html)

xtrios July 16, 2008 17:06

Help! Function not LOOPing
 
Hi, I'm trying to define a loop to generate a recurring capacitor charge-discharge function to be interpreted in FLUENT as an input profile. For some reason, it doesn't seem to be looping at all. I get the first curve, then it stays constant (at 0). There are no errors in interpreting so I'm guessing it is ok syntax wise. All the variables are properly specified. Am I missing something important to make sure it loops?

Here is what it should look like: http://commons.wikimedia.org/wiki/Im...-discharge.svg

/* modeled after an RC charging-discharging curve */ /* p = entire period (including resting time) */ /* xp = cross-over point from charging to discharging */ /* pb = period (total charge-discharge time) */ /* a = amplitude*/

p=20; xp=3; pb=5; a=5; flow_time1=0; flow_time3=pb; begin_f_loop(f, thread)

{F_CENTROID(x,f,thread);

if (flow_time == (flow_time3+p))

{ flow_time1=flow_time1+p;

flow_time3=flow_time3+p; }

if ((flow_time > flow_time1) && (flow_time < flow_time3))

{ flow_time2=flow_time - flow_time1;

if (flow_time2 <= xp)

{F_PROFILE(f,thread,nv) = a*(1-exp(-flow_time2/(pb/6))); }

else

{F_PROFILE(f,thread,nv) = a*(exp((xp-flow_time2)/(pb/10))); } else { F_PROFILE(f,thread,nv) = 0; } } end_f_loop(f, thread)


xtrios July 16, 2008 17:12

Re: Help! Function not LOOPing
 
I need to add:

the flow_time is obtained from this line outside the loop:

real flow_time = RP_Get_Real("flow-time");

xtrios July 17, 2008 15:44

Help! UDF for time-based repeated pressure profile
 
Hi, I included a different version, which should hopefully be easier to decipher, but with the same idea and problem. This UDF is for a pressure inlet. I can get the first wave, but after that it remains at the constant pressure. Based on my understanding of the code, the wave should be repeated every "p" seconds, but it does not do that. Would totally appreciate it if someone could point out any conceptual or programming errors =)

#include "udf.h" #include "math.h"

DEFINE_PROFILE(inlet_pressure,t,nv) {

face_t f;

real flow_time = RP_Get_Real("flow-time");

real PEEP, p, xp, pb, a, flow_time1, flow_time2, flow_time3, pressure;

PEEP=5;

pb=5;

p=15;

xp=3;

a=10;

flow_time1=0;

flow_time3=pb;

if (flow_time == (flow_time1+p))

{

flow_time1 = flow_time1 + p;

flow_time3 = flow_time3 + p;

}

if ((flow_time > flow_time1) && (flow_time < flow_time3))

{

flow_time2 = flow_time - flow_time1;

pressure = PEEP + a*(1-exp(-flow_time2/(pb/6)));

begin_f_loop(f,t)

{

F_PROFILE(f,t,nv) = pressure;

}

end_f_loop(f,t)

}

else

{

begin_f_loop(f,t)

{

F_PROFILE(f,t,nv) = PEEP;

}

end_f_loop(f,t)

} }


All times are GMT -4. The time now is 21:49.