CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Fluent UDF and Scheme Programming (https://www.cfd-online.com/Forums/fluent-udf/)
-   -   Previous time step variable to be used in UDF (https://www.cfd-online.com/Forums/fluent-udf/104904-previous-time-step-variable-used-udf.html)

CFD-user July 18, 2012 08:48

Previous time step variable to be used in UDF
 
Hi,

I am writing an UDF, in which I would like to use the previous time step data. Although, in FLUENT we can access previous time step data for many variables with '_M1', I would need user defined variables previous timestep rather than the standard variables.

For e.g. m(t+dt) = m(t) + ...............

so to solve the above equation for the new time step I will be needing m(t) i.e., previous time step data.

I have been keep on trying this from last few days, but could not crack.

It will be appreciated, if you can throw some light on it.

Regards...

Amir July 18, 2012 12:19

Hi,

Why didn't use other UDM for this purpose?

CFD-user July 19, 2012 08:51

Quote:

Originally Posted by Amir (Post 372184)
Hi,

Why didn't use other UDM for this purpose?


Hi,

Thank you for your reply.

I tried earlier with UDMIs also and did not work. But, I think even UDMIs also store the current time step data only. I will try once again & see.

Regards

Amir July 19, 2012 12:00

Quote:

Originally Posted by CFD-user (Post 372374)
Hi,

Thank you for your reply.

I tried earlier with UDMIs also and did not work. But, I think even UDMIs also store the current time step data only. I will try once again & see.

Regards

It depends how you use and update such memories in order to refer to desired time step.

Bests,

sbaffini July 19, 2012 16:28

What Amir meant to say is that you can save your current time variable in some UDMI and the older one in another UDMI and basically keep updating them as the time passes. In this case you will never need the old time values as you will always reference current time variables

CFD-user July 20, 2012 00:57

Quote:

Originally Posted by Amir (Post 372428)
It depends how you use and update such memories in order to refer to desired time step.

Bests,

Can you please give some example in terms of UDMIs?

CFD-user July 20, 2012 00:58

Quote:

Originally Posted by sbaffini (Post 372473)
What Amir meant to say is that you can save your current time variable in some UDMI and the older one in another UDMI and basically keep updating them as the time passes. In this case you will never need the old time values as you will always reference current time variables

Can you please give some example in terms of UDMIs? Now I will trying with fprintf and fscan options from the file.

Amir July 20, 2012 02:47

Quote:

Originally Posted by CFD-user (Post 372512)
Can you please give some example in terms of UDMIs?

Consider for example 2 UDMs at first: UDM0, UDM1 and initialize them.
Then in your desired define-macro which does a process in each time step you have e.g.:
DEFINE_X(.....)
{
C_UDMI(...,1)=f(....)+C_UDMI(...,0); //here UDM0 refers to previous time step
.
.
.
// At last you have:
C_UDMI(...,0)=C_UDMI(...,1); // prepare UDM0 for the next time step

}

Just note to provide these commands each time steps not each iteration; i.e., if your macro executes each iteration, you need to use a if-clause to restrict the commands for each time step.

Bests,

CFD-user July 24, 2012 03:56

Quote:

Originally Posted by Amir (Post 372530)
Consider for example 2 UDMs at first: UDM0, UDM1 and initialize them.
Then in your desired define-macro which does a process in each time step you have e.g.:
DEFINE_X(.....)
{
C_UDMI(...,1)=f(....)+C_UDMI(...,0); //here UDM0 refers to previous time step
.
.
.
// At last you have:
C_UDMI(...,0)=C_UDMI(...,1); // prepare UDM0 for the next time step

}

Just note to provide these commands each time steps not each iteration; i.e., if your macro executes each iteration, you need to use a if-clause to restrict the commands for each time step.

Bests,

Thanks for your reply.
I have following doubts:
1. For the first time step what would be the value of C_UDMI(...,0)
2. Suppose even if you include it in 'if-else loop' i.e., say for the first time step I will initialise C_UDMI(...,0) in 'if' loop. And subsequently I would use this in else loop. I think I have tried this without inlcuding the if loop for each time step and did not work. I would try for each time-step instead of each iteration and come to you.

Thank you again.

Amir July 24, 2012 05:50

Quote:

Originally Posted by CFD-user (Post 373163)
1. For the first time step what would be the value of C_UDMI(...,0)

The UDM0 value would be the initial value for desire variable. (you can set it appropriately via initialize->patch or via other pre-used UDF)
Quote:

Originally Posted by CFD-user (Post 373163)
2. Suppose even if you include it in 'if-else loop' i.e., say for the first time step I will initialise C_UDMI(...,0) in 'if' loop. And subsequently I would use this in else loop. I think I have tried this without inlcuding the if loop for each time step and did not work. I would try for each time-step instead of each iteration and come to you.

It should work if executed at each time step not each iteration.

Bests,

shashank312 May 23, 2013 18:06

Since Fluent does not handle the coupling of the VOF equation and the UDS equation properly and since the source term in the VOF equation is treated implicitly for volume fraction but explicitly for the UDS variable in question, I need to use "some" variables (suppose I store them in a UDM) from the previous time step. How can I do that? I think I am asking how should I loop w.r.t time?

shashank312 May 24, 2013 16:37

Amir, how and where would you use the if-clause to restrict the commands to each time step?

Светлана May 29, 2014 03:33

same question - how to access a variable value from previous time step - no answer in this thread

pakk May 29, 2014 04:07

Quote:

Originally Posted by Светлана (Post 494640)
same question - how to access a variable value from previous time step - no answer in this thread

Very clear answer in this thread! Store that variable in a UDM, and then access the UDM in the next time step!

PranjalNewton October 18, 2015 05:34

Quote:

Originally Posted by Amir (Post 372530)
Just note to provide these commands each time steps not each iteration; i.e., if your macro executes each iteration, you need to use a if-clause to restrict the commands for each time step.

How is this ensured? i.e. the if-clause?

Tushar_Telmasre March 20, 2017 06:16

Previous Time step data in Custom field functions
 
Quote:

Originally Posted by CFD-user (Post 372140)
Hi,

I am writing an UDF, in which I would like to use the previous time step data. Although, in FLUENT we can access previous time step data for many variables with '_M1', I would need user defined variables previous timestep rather than the standard variables.

For e.g. m(t+dt) = m(t) + ...............

so to solve the above equation for the new time step I will be needing m(t) i.e., previous time step data.

I have been keep on trying this from last few days, but could not crack.

It will be appreciated, if you can throw some light on it.

Regards...



Hello,
can '_M1' Extension be used while defining custom field functions too to get previous time step data?

sbaffini March 20, 2017 06:31

Unless some radical change happened in the last couple of Fluent versions, custom field functions are quite different objects with respect to the data available in UDF, especially _M1 and _M2 variables. What you can do is defining your custom field function in an UDF and save it in an UDM, than just do what explained here to have current and past values available.

nickgaoda July 31, 2018 14:33

Quote:

Originally Posted by Amir (Post 373191)
The UDM0 value would be the initial value for desire variable. (you can set it appropriately via initialize->patch or via other pre-used UDF)

It should work if executed at each time step not each iteration.

Bests,

Hi Amir, If I want to get the time-dependent values of the turbulent kinetic energy, how should I use the UDM?

bagher.aghasi June 23, 2022 01:17

accessing to previous variable can be done by define_execute_at_and macro. at first desired variable should store in a udmi memory at this macro and then this memory can retrieve anywhere in udf. this macro execute at end of last time step so in iterations of new time step its values dont change.
for example
define_execute_at_end(){
domain
*mixture =Get_Domain(2);
fluid_id =8;
Thread t = Lookup_Thread(t,fluid_id);
cell_t c;
begin_c_loop(c,t)
{
C_UDMI(c,t,0) = c_R(c,t);
}
end_c_loop(c,t)
}

define_source(name,c,t,ds,eqn)
{
rho_previous = udmi(c,t,0);
rho = C_R(c,t);
}


All times are GMT -4. The time now is 22:11.