CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   WHAT IS WRONG WITH MY UDF?! (https://www.cfd-online.com/Forums/fluent/47262-what-wrong-my-udf.html)

Mikael February 7, 2008 05:29

WHAT IS WRONG WITH MY UDF?!
 
I'm trying to take the x-velocity vectors and temperature profile from my outlet and past them on my inlet. I have written these UDF:s to do the job but it will not work. Somebody who can help me debugg it? It gives parse error on line 20 and I dont know why.

Greatful for any help at all!

Mikael ------------------------------------------------ #include "udf.h"

DEFINE_PROFILE(inlet_x_velocity_profile, thread, position) { real x[ND_ND]; real xkoord_out; real ykoord_out; face_t f_outlet; face_t f_inlet; real x_vel; Domain *domain; domain = Get_Domain(1); /*line 19*/ int zone_ID = 5; Thread *thread1 = Lookup_Thread(domain, zone_ID); begin_f_loop(f_outlet, thread1) /* Loop over faces in a face thread to get the information stored on faces. */

{

F_CENTROID(x,f_outlet,thread1);

xkoord_out = x[0];

ykoord_out = x[1];

x_vel = F_U(f_outlet,thread1);

F_PROFILE(f_inlet,thread,position)=x_vel*((xkoord_ out)*(xkoord_out)/(0.0255*0.0255)+((ykoord_out+0.204)*(ykoord_out+0. 204))/(0.0255*0.0255)-1);

} end_f_loop(f_outlet, thread1) --------------------------------------------------- #include "udf.h" /* must be at the beginning of every UDF you write */ #include "sg.h"

DEFINE_PROFILE(inlet_x_velocity_profile, thread, position) { real x[ND_ND]; /* this will hold the position vector */ real xkoord_out; real ykoord_out; face_t f_outlet; face_t f_inlet; real x_vel; real Temp; Domain *domain; /* domain is declared as a variable */ domain = Get_Domain(1); /*line 19*/ int zone_ID=5; /* Zone ID for outlet zone from Boundary Conditions panel */ Thread *thread1 = Lookup_Thread(domain, zone_ID);

begin_f_loop(f_outlet, thread1) /* Loop over faces in a face thread to get the information stored on faces. */

{

F_CENTROID(x,f_outlet,thread1);

xkoord_out = x[0];

ykoord_out = x[1];

Temp = F_T(f_outlet,thread1);

F_PROFILE(f_inlet,thread,position)=Temp*((xkoord_o ut)*(xkoord_out)/(0.0255*0.0255)+((ykoord_out+0.204)*(ykoord_out+0. 204))/(0.0255*0.0255)-1);

} end_f_loop(f_outlet, thread1) --------------------------------------------------------

Mikael February 7, 2008 05:45

Re: WHAT IS WRONG WITH MY UDF?!
 
Bad format on the other message, maybe this is easier to read...

------------------------------------------------

#include "udf.h"

#include "sg.h"

DEFINE_PROFILE(inlet_x_velocity_profile, thread, position) {

real x[ND_ND];

real xkoord_out;

real ykoord_out;

face_t f_outlet;

face_t f_inlet;

real x_vel;

Domain *domain;

domain = Get_Domain(1); /*line 19*/ int zone_ID = 5;

Thread *thread1 = Lookup_Thread(domain, zone_ID);

begin_f_loop(f_outlet, thread1) /* Loop over faces in a face thread to get the information stored on faces. */

{

F_CENTROID(x,f_outlet,thread1);

xkoord_out = x[0];

ykoord_out = x[1];

x_vel = F_U(f_outlet,thread1);

F_PROFILE(f_inlet,thread,position)=x_vel*((xkoord_ out)*(xkoord_out)/(0.0255*0.0255)+((ykoord_out+0.204)*(ykoord_out+0. 204))/(0.0255*0.0255)-1);

}

end_f_loop(f_outlet, thread1)

---------------------------------------------------

#include "udf.h" /* must be at the beginning of every UDF you write */

#include "sg.h"

DEFINE_PROFILE(inlet_x_velocity_profile, thread, position)

{ real x[ND_ND];/* this will hold the position vector */

real xkoord_out;

real ykoord_out;

face_t f_outlet;

face_t f_inlet;

real x_vel;

real Temp; Domain *domain; /* domain is declared as a variable */ domain = Get_Domain(1);

/*line 19*/

int zone_ID=5; /* Zone ID for outlet zone from Boundary Conditions panel */

Thread *thread1 = Lookup_Thread(domain, zone_ID);

begin_f_loop(f_outlet, thread1) /* Loop over faces in a face thread to get the information stored on faces. */

{

F_CENTROID(x,f_outlet,thread1);

xkoord_out = x[0];

ykoord_out = x[1];

Temp = F_T(f_outlet,thread1);

F_PROFILE(f_inlet,thread,position)=Temp*((xkoord_o ut)*(xkoord_out)/(0.0255*0.0255)+((ykoord_out+0.204)*(ykoord_out+0. 204))/(0.0255*0.0255)-1);

}

end_f_loop(f_outlet, thread1)

--------------------------------------------------------


selma February 8, 2008 05:12

Re: WHAT IS WRONG WITH MY UDF?!
 
Hi!

The problem with your UDF is that DEFINE_PROFILE macro (so far I know) is executed within the thread loop.

I hope this will help:

1. DEFINE_ON_DEMAND takes the values of U-velocity at outlet, stores them in 'container'. From there they are assigned to the inlet over F_UDMI. 2. DEFINE_PROFILE is more simple now, because the values you need are already stored in F_UDMI

For sure, there could be a more elegant solution existing, my C-knowledge is rather poor.

The routine will work only if the grid you use has the same number of cells at inlet and outlet, equally distributed (not equidistant) on both sides of domain. Otherwise you have to interpolate in some way.

#include "udf.h"

#define FROM_THREAD_ID 3 //outlet zone ID #define TARGET_THREAD_ID 4 //inlet zone ID

DEFINE_ON_DEMAND(my_demand) { face_t f; double *container; int i=0;

Thread* t = Lookup_Thread(root_domain, FROM_THREAD_ID); if (t == NULL) Error("can't lookup thread in my_demand!\n");

begin_f_loop (f,t)

{

F_UDMI(f,t,0) = F_U(f,t);

container[i] = F_UDMI(f,t,0);

i+=1;

} end_f_loop (f,t)

t = Lookup_Thread(root_domain, TARGET_THREAD_ID); if (t == NULL) Error("can't lookup thread in my_demand!\n");

i=0; begin_f_loop (f,t)

{

F_UDMI(f,t,0) = container[i];

i+=1;

} end_f_loop (f,t) }

DEFINE_PROFILE(inlet_x_velocity_profile, thread, position) {

real x[ND_ND]; real xkoord_out; real ykoord_out; face_t f;

begin_f_loop(f,thread) {

F_CENTROID(x,f,thread);

xkoord_out = x[0];

ykoord_out = x[1];

//here you can define your function:

//F_PROFILE(f_inlet,thread,position)=F_UDMI(f,thread ,0)*((xkoord_out)*(xkoord_out)/(0.0255*0.0255)+((ykoord_out+0.204)*(ykoord_out+0. 204))/(0.0255*0.0255)-1);

F_PROFILE(f,thread,position)= F_UDMI(f,thread,0)*2.;

}

end_f_loop(f, thread) }


Mikael February 12, 2008 07:42

Re: WHAT IS WRONG WITH MY UDF?!
 
Thanks! I have now got my UDF to work (the one you wrote for me) in the matter of getting it compiled and able to load. But there is a problem... When I try to iterate (unsteady) it doesn't seem as the velocity is moved to the inlet immediataly because the velocity contour at the inlet is equally colored and doesnt look at all like the outlet. As the iterations pass the velocity decreases more and more from my average of 1 m/s.. Do know what could be the problem?

Mikael


All times are GMT -4. The time now is 15:26.