CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   FLUENT (http://www.cfd-online.com/Forums/fluent/)
-   -   UDF DEFINE_EXECUTE_AT_END (http://www.cfd-online.com/Forums/fluent/48226-udf-define_execute_at_end.html)

Giacomo de Renzi May 13, 2008 16:44

UDF DEFINE_EXECUTE_AT_END
 
Good morning.. I've got a problem with a DEFINE_EXECUTE_AT_END UDF, the problem is to calculate the average temperature on a boundary condition at every time step, and then compare it with a check temperature to decide if activate or not an air conditioner, the error which occures is the seguent:

Error: FLUENT received fatal signal (ACCESS_VIOLATION) 1. Note exact events leading to error. 2. Save case/data under new name. 3. Exit program and restart to continue. 4. Report error to your distributor. Error Object: ()

and the UDF is:

#include "udf.h" #define DeltaT_APC 10 #define DeltaT_CPU 20

real t_cpu_in,t_cond_in; real current_time,step;

DEFINE_EXECUTE_AT_END(T_cpu_in) { real temp1,volume,vol_tot;

Thread *cpu_in; cell_t c;

step = CURRENT_TIMESTEP; current_time = CURRENT_TIME;

if (current_time > 2*step) { begin_c_loop(c,cpu_in) { volume=C_VOLUME(c,cpu_in); temp1=C_T_M1(c,cpu_in); vol_tot += volume; t_cpu_in += temp1 * volume; } end_c_loop(c,cpu_in)

t_cpu_in /= vol_tot; } else { t_cpu_in = 293.15; } printf("t_cpu_in: %g\n", t_cpu_in); }

DEFINE_EXECUTE_AT_END(T_cond_in) { real temp2,volume,vol_tot;

Thread *cond_in; cell_t c;

step = CURRENT_TIMESTEP; current_time = CURRENT_TIME;

if (current_time > 2*step) { begin_c_loop(c,cond_in) { volume=C_VOLUME(c,cond_in); temp2=C_T_M1(c,cond_in); vol_tot += volume; t_cond_in += temp2 * volume;

} end_c_loop(c,cond_in)

t_cond_in /= vol_tot; } else { t_cond_in = 293.15; } }

DEFINE_PROFILE(inlet_x_cond_out, cond_out, index) {

real x[ND_ND]; real y; face_t f; begin_f_loop(f, cond_out) { F_CENTROID(x,f,cond_out); y = x[1]; F_PROFILE(f, cond_out, index) = t_cpu_in + DeltaT_CPU; } end_f_loop(f, cond_out) }

DEFINE_PROFILE(inlet_x_cpu_out, cpu_out, index) {

real x[ND_ND]; real y; face_t f;

if (current_time > step && t_cpu_in > 293.15)

begin_f_loop(f, cpu_out) { F_CENTROID(x,f,cpu_out); y = x[1]; F_PROFILE(f, cpu_out, index) = t_cond_in - DeltaT_APC; } end_f_loop(f, cpu_out) }

thank you, I hope You could help me, Giacomo de Renzi

Giacomo de Renzi May 13, 2008 20:43

Re: UDF DEFINE_EXECUTE_AT_END
 
reading UDF_manual I found that I need to use user-defined scalars to have access to C_T_M1: "! Note that data from C_T_M1 is available only if user-defined scalars are used."

has someone got experience with UDS, what kind of UDS I could use to solve my problem? and how?

thanks, Giacomo de Renzi


HP May 15, 2008 10:25

Re: UDF DEFINE_EXECUTE_AT_END
 
Just in case, i'm right...

C_VOLUME(c,t);

I think t should be the thread of your mixture and not a cell thread. Before looping over your cells you should probably loop over all threads. Or you can use Lookup_Thread(domain,Zone_ID) to get your mixture thread


Giacomo de Renzi May 15, 2008 11:55

Re: UDF DEFINE_EXECUTE_AT_END
 
thanks for answering.. I tried using what you suggested me but the same error occurs. (I've also another questione to make.. a Zone is a domain or a thread?)

that's the UDF using ('Lookup_Thread'): (I tried also using a loop over all threads but it's the same..) can you help me?

DEFINE_EXECUTE_AT_END(T_cpu_in) { real temp1,volume,vol_tot; Domain *d; Thread *t = Lookup_Thread(d,6); cell_t c;

step = CURRENT_TIMESTEP; current_time = CURRENT_TIME;

if (current_time > step) { begin_c_loop(c,t) { volume=C_VOLUME(c,t); temp1=C_T(c,t); vol_tot += volume; t_cpu_in += temp1 * volume; } end_c_loop(c,t)

t_cpu_in /= vol_tot; } else { t_cpu_in = 293.15; } printf("t_cpu_in: %g\n", t_cpu_in); }

Giacomo de Renzi May 16, 2008 05:31

Re: UDF DEFINE_EXECUTE_AT_END
 
I tried also the DEFINE_ON_DEMAND UDF copied by the Fluent_UDF_Manual, and the same error occurs.... why does it happen??? please help me!!

that's the UDF, exactly copied by the manual:

#include "udf.h" DEFINE_ON_DEMAND(on_demand_calc) { Domain *d; /* declare domain pointer since it is not passed as an argument to the DEFINE macro */ real tavg = 0.; real tmax = 0.; real tmin = 0.; real temp,volume,vol_tot; Thread *t; cell_t c; d = Get_Domain(1); /* Get the domain using Fluent utility */ /* Loop over all cell threads in the domain */ thread_loop_c(t,d) { /* Compute max, min, volume-averaged temperature */ /* Loop over all cells */ begin_c_loop(c,t) { volume = C_VOLUME(c,t); /* get cell volume */ temp = C_T(c,t); /* get cell temperature */ if (temp < tmin || tmin == 0.) tmin = temp; if (temp > tmax || tmax == 0.) tmax = temp; vol_tot += volume; tavg += temp*volume; } end_c_loop(c,t) tavg /= vol_tot; printf("\n Tmin = %g Tmax = %g Tavg = %g\n",tmin,tmax,tavg);

/* Compute temperature function and store in user-defined memory*/ /*(location index 0) */ begin_c_loop(c,t) { temp = C_T(c,t); C_UDMI(c,t,0) = (temp-tmin)/(tmax-tmin); } end_c_loop(c,t) } }

ycl229 March 25, 2010 05:01

the same question
 
I have the same question that i have not solved.


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