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/)
-   -   accessing a variable from the previous iteration (NOT TIMESTEP) (http://www.cfd-online.com/Forums/fluent-udf/115312-accessing-variable-previous-iteration-not-timestep.html)

aditya.pandare March 28, 2013 04:02

accessing a variable from the previous iteration (NOT TIMESTEP)
 
I want to access the pressure from the previous iteration. What is the Macro for that?

I googled it and found only this link: http://www.cfd-online.com/Forums/flu...-used-udf.html

But this is to access the variable in the previous timestep (transient)
since my solution is steady, I want to access pressure from the previous iteration.

Please help!

akm March 28, 2013 12:22

The thread which you have linked (using 2 UDMs) can be applied to your problem as well..

Since you want the pressure field, you only need 1 UDM..
You only need to assign the UDM value as the pressure at previous step.

Now 'previous timestep' or 'previous iteration' is simply a choice of macro.

If your simulation was transient, DEFINE_EXECUTE_AT_END would run at the end of each time-step, but for steady simulation it runs at the end of each iteration..

However, if your setup is transient, and you still need the value at previous iteration, you can use the macro DEFINE_ADJUST, which runs at the beginning of each iteration (before the transport eqns are solved).

aditya.pandare April 1, 2013 01:01

Hello!
Thank you for your reply! according to your instructions, I have written the following code:

DEFINE_EXECUTE_AT_END(pprev)
{
cell_t*c;
Thread *mixture_thread;
Domain *domain;
int zoneid = 10;
domain = Get_Domain(1);
mixture_thread = Lookup_Thread(domain,zoneid);
C_UDMI(c,t,0) = source;
}

Gives a parse error at the "cell_t c line".
(Instead of storing the pressure in the UDM, I am storing the "source" from a previous UDF and underrelaxing it.)
I think the DEFINE_EXECUTE_AT_END doesnt take cell-thread and domain as input argument. So how should I store the source value at every cell so that I can use it from one variable (as in a "for" loop in the underrelaxation UDF)?

Thanks again for your reply.

aditya.pandare April 1, 2013 06:32

Got it to work in the following way:

DEFINE_EXECUTE_AT_END(pprev)
{
real prsr, alpha, pv;
Thread *mixture_thread;
Thread *vap_thread;
Domain *domain;
Domain *vdomain;
int zoneid = 10;
cell_t c;
domain = Get_Domain(1);
vdomain = Get_Domain(3);
mixture_thread = Lookup_Thread(domain,zoneid);
vap_thread = Lookup_Thread(vdomain,zoneid);
pv = -97000;
thread_loop_c(vap_thread,vdomain)
{
begin_c_loop(c,vap_thread)
{
......
}
end_c_loop(c,vap_thread)
}

thread_loop_c(mixture_thread,domain)
{
begin_c_loop(c,mixture_thread)
{
......
}
end_c_loop(c,mixture_thread)
}
}

thank you @akm.


All times are GMT -4. The time now is 23:48.