Bruno Machado |
June 10, 2016 15:47 |
Quote:
Originally Posted by Baden
(Post 604336)
I do have one question about the DEFINE_EXECUTE_AT_END macro.
I'm trying to store the calculated value of porosity in the UDMI using the DEFINE_EXECUTE_AT_END macro but I'm not quite sure how to reference the porosity since the C_PROFILE macro requires an index (i).
Code:
#define ID 3.0 /* ID of the fluid */
DEFINE_EXECUTE_AT_END(execute_at_end)
{
Domain *d;
Thread *t;
Thread *t_fluid = Lookup_Thread(d,ID);
cell_t c;
d = Get_Domain(1); /* mixture domain if multiphase */
thread_loop_c(t,d)
{
if (t == t_fluid)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,0) = C_PROFILE(c,t,???)
}
end_c_loop(c,t)
}
}
}
I guess my question is how do I pull the index for the porosity variable so I can reference it?
|
I wrote what I think will work for you. I did not compile, so might have some mistakes. The logic is explained in the code. Hope it clarifies things to you.
Code:
#include "udf.h"
#define ID 3.0 /* ID of the fluid */
/* in this part, the value of the porosity is initialised as 0.8 */
DEFINE_INIT(UDMI0_init,d)
{
Thread *t;
cell_t c;
Thread *t_fluid = Lookup_Thread(d,3); /* 3 is the ID of the fluid */
thread_loop_c(t,d)
{
if (t == t_fluid)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,0) = 0.8;
}
end_c_loop(c,t)
}
}
}
/* this macro will read the value of the UDMI_0. For the first time step, it will be 0.8,
after that, it will use the value of the UDMI_0 calculated in the DEFINE_EXECUTE_AT_END */
DEFINE_PROFILE(porosity_variation,t,i)
{
cell_t c;
begin_c_loop(c,t)
{
C_PROFILE(c,t,i) = C_UDMI(c,t,0);
}
end_c_loop(c,t)
}
/*Since this macro is only executed at the end of each time step, there is no need to an IF statement.
This command will define that phi_0 is the value of the old porosity, then the porosity_new can be solved and followed by the definition of the new value of the UDMI_0.
This value will be read by the DEFINE_PROFILE as the new value of the porosity at the end of each time step*/
DEFINE_EXECUTE_AT_END(execute_at_end)
{
Domain *d;
Thread *t;
Thread *t_fluid = Lookup_Thread(d,ID);
cell_t c;
d = Get_Domain(1); /* mixture domain if multiphase */
real porosity;
real X = 1.0; /* arbitrary constant */
real delta_t = CURRENT_TIMESTEP;
thread_loop_c(t,d)
{
if (t == t_fluid)
{
begin_c_loop(c,t)
{
real phi_0 = C_UDMI(c,t,0);
porosity_new = 1.0 - (-(phi_0 * phi_0) + phi_0 + X * delta_t) / (-phi_0 + X * delta_t + 1.0);
C_UDMI(c,t,0) = porosity_new;
}
}
end_c_loop(c,t)
}
}
}
|