|
[Sponsors] |
June 18, 2012, 12:10 |
Save variable in DEFINE_EXECUTE_AT_END
|
#1 |
New Member
|
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); } |
|
June 19, 2012, 05:04 |
|
#2 |
New Member
|
Okay I found a solution.
C_UDMI has to be in a loop, otherwise it crashes. |
|
November 23, 2012, 09:22 |
|
#3 |
Senior Member
Join Date: May 2011
Posts: 231
Rep Power: 16 |
||
Tags |
memory, _at_end |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
OpenFoam-1.6-ext Allwmake compilation error - one last barrier | Pat84 | OpenFOAM Installation | 15 | July 25, 2012 21:49 |
emag beta feature: charge density | charlotte | CFX | 4 | March 22, 2011 09:14 |
error in COMSOL:'ERROR:6164 Duplicate Variable' | bhushas | COMSOL | 1 | May 30, 2008 04:35 |
Env variable not set | gruber2 | OpenFOAM Installation | 5 | December 30, 2005 04:27 |
Replace periodic by inlet-outlet pair | lego | CFX | 3 | November 5, 2002 20:09 |