CFD Online Discussion Forums

CFD Online Discussion Forums (http://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (http://www.cfd-online.com/Forums/fluent-udf/)
-   -   Save variable in DEFINE_EXECUTE_AT_END (http://www.cfd-online.com/Forums/fluent-udf/103366-save-variable-define_execute_at_end.html)

tim.sonderby June 18, 2012 12:10

Save variable in DEFINE_EXECUTE_AT_END
 
HI,

I have a problem to store the CURRENT_TIME so that I can be used in the workbench as a parameter.

I have tried to use C_UDMI(c,t,0) but that does not work (yes I have allocated memory), but that juse returns a FATAL_Vialation.

everything works except for the storage of the time into a variable that can be acceded from the workbench:



/************************************************** ***************
UDF to calculate the variance on concentration. This can be used
for dertermination of the mixing time.

Define the limit for the variance that defines the mixing time.
Make sure that the tracer is the first material in mixture.

Auther: Tim Soenderby
Created: 16 June 2012
Modified: 16 June 2012
************************************************** **************/

#include "udf.h"
#define TAU_LIMIT 1e-8

real num_cells;
real avg_concentration;
real volume;
real TAU;
real mix_time;

DEFINE_EXECUTE_AT_END(store_mixing_time)
{
/* declare domain pointer since it is not passed as an argument to the DEFINE macro */
Domain *d;
Thread *t;
cell_t c;
/* Get the domain 1 (Mixture) */
d = Get_Domain(1);

num_cells = 0.;
volume = 0.;
avg_concentration =0.;
TAU = 0.;

/* Loop over all cell threads in the domain */
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
avg_concentration += C_YI(c,t,0)*C_VOLUME(c,t);
volume += C_VOLUME(c,t);
num_cells += 1;
}
end_c_loop(c,t)
}

avg_concentration = avg_concentration/volume;


/* Loop over all cell threads in the domain */
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
TAU += (C_YI(c,t,0)-avg_concentration)*(C_YI(c,t,0)-avg_concentration);
}
end_c_loop(c,t)
}

/*calculating the variance*/
TAU = 1/(num_cells-1)*TAU;

if (mix_time == 0.)
{
Message("**************** CHECKING IF MIXING TIME IS REACHED ***************\n");
if (( TAU < TAU_LIMIT) && (TAU > 0))
{
mix_time = CURRENT_TIME; /*source of error*/
C_UDMI(c,t,0) = mix_time;
Message("Mixing time is reached, and is: %g\n", mix_time);
}
}

Message("Number of cellss are: %g\n", num_cells);
Message("volume is: %g\n", volume);
Message("avg_cons is: %g\n", avg_concentration);
Message("TAU is: %g\n", TAU);

}

tim.sonderby June 19, 2012 05:04

Okay I found a solution.


C_UDMI has to be in a loop, otherwise it crashes.

Kanarya November 23, 2012 10:22

Quote:

Originally Posted by tim.sonderby (Post 367174)
Okay I found a solution.


C_UDMI has to be in a loop, otherwise it crashes.

Hi,

I would like to save the mass flow rate only at outlet. is it possible with DEFINE_EXECUTE_AT_END?
thanks in advance!!!


All times are GMT -4. The time now is 13:59.