CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > ANSYS > FLUENT > Fluent UDF and Scheme Programming

Can UDF obtain a variable value in real-time from the nth and (n-1) iteration steps

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   April 8, 2023, 08:34
Default Can UDF obtain a variable value in real-time from the nth and (n-1) iteration steps
  #1
Senior Member
 
Join Date: Feb 2020
Posts: 114
Rep Power: 6
lbj007 is on a distinguished road
Can UDF achieve the following function: monitor the minimum value of a physical quantity, obtain its values at the nth and (n-1)th iteration steps, and when the difference approaches zero, switch a boundary condition mounted with a UDF, such as replacing DEFINE_PROFILE(uright0,f_thread,position) with another DEFINE_PROFILE(uright1,f_thread,position). or maybe scheme can achieve it?
lbj007 is offline   Reply With Quote

Old   April 8, 2023, 13:16
Default
  #2
Member
 
Odisha
Join Date: Jan 2020
Posts: 59
Rep Power: 6
Siba11 is on a distinguished road
Quote:
Originally Posted by lbj007 View Post
Can UDF achieve the following function: monitor the minimum value of a physical quantity, obtain its values at the nth and (n-1)th iteration steps, and when the difference approaches zero, switch a boundary condition mounted with a UDF, such as replacing DEFINE_PROFILE(uright0,f_thread,position) with another DEFINE_PROFILE(uright1,f_thread,position). or maybe scheme can achieve it?
Hi. Yes, it can be done.

Firstly, write a UDF that calculates the difference between the nth and (n-1)th iteration. Simultaneously, define an RP variable in the console (check this page).

Now, when the difference approaches zero, change the value of this RP variable via your first UDF. (using "RP_set_integer").

Now, you can write a second UDF (a DEFINE_PROFILE UDF) with a switch case statement. At some nth iteration, when the RP variable will change its value, it will be detected by the 2nd UDF. And from that iteration onwards, it will switch the boundary condition (using the switch-case statement).
Siba11 is offline   Reply With Quote

Old   April 8, 2023, 22:12
Default
  #3
Senior Member
 
Join Date: Feb 2020
Posts: 114
Rep Power: 6
lbj007 is on a distinguished road
Quote:
Originally Posted by Siba11 View Post
Hi. Yes, it can be done.

Firstly, write a UDF that calculates the difference between the nth and (n-1)th iteration. Simultaneously, define an RP variable in the console (check this page).

Now, when the difference approaches zero, change the value of this RP variable via your first UDF. (using "RP_set_integer").

Now, you can write a second UDF (a DEFINE_PROFILE UDF) with a switch case statement. At some nth iteration, when the RP variable will change its value, it will be detected by the 2nd UDF. And from that iteration onwards, it will switch the boundary condition (using the switch-case statement).
Hi, Thank you for your detailed explanation, but there's one more thing I'm not sure, how can I obtain the variable's values at the nth and (n-1)th iteration steps in real time? More specially, how can I store the value of the previous iteration step?I know there are previous time step Macros, such as C_T_M1(c,t) for transient calculations, but what can be used for steady simulations?
lbj007 is offline   Reply With Quote

Old   April 10, 2023, 03:21
Default
  #4
Member
 
Odisha
Join Date: Jan 2020
Posts: 59
Rep Power: 6
Siba11 is on a distinguished road
Hi. You can use an array (or even pointers) to store the values at each iteration using the in-built macro N_ITER.
Siba11 is offline   Reply With Quote

Old   April 10, 2023, 09:57
Default
  #5
Senior Member
 
Join Date: Feb 2020
Posts: 114
Rep Power: 6
lbj007 is on a distinguished road
Quote:
Originally Posted by Siba11 View Post
Hi. You can use an array (or even pointers) to store the values at each iteration using the in-built macro N_ITER.
Hi, can you give me a simple example for how to use it? I'm not sure what do you mean. N_ITER is just a number, how can it be used to monitor the current step and the previous step in real-time?
lbj007 is offline   Reply With Quote

Old   April 11, 2023, 16:16
Default
  #6
Member
 
Odisha
Join Date: Jan 2020
Posts: 59
Rep Power: 6
Siba11 is on a distinguished road
Quote:
Originally Posted by lbj007 View Post
Hi, can you give me a simple example for how to use it? I'm not sure what do you mean. N_ITER is just a number, how can it be used to monitor the current step and the previous step in real-time?
Hi. you can do something like this :

Code:
int A[100];

if (N_ITER == 1)
A[N_ITER] = C_T(c,t); // assuming you are working with temperature.

if (N_ITER > 1)
{
A[N_ITER] = C_T(c,t);
diff = A[N_ITER] - A[N_ITER - 1];
 
  if ('diff' satisfies the tolerance)
    RP_Set_Integer ("rp-variable", 1);
}
When the rp-variable will change, it will be detected by the console. You can use a DEFINE_ADJUST UDF for this task.
Siba11 is offline   Reply With Quote

Old   April 13, 2023, 00:28
Default
  #7
Senior Member
 
Join Date: Feb 2020
Posts: 114
Rep Power: 6
lbj007 is on a distinguished road
Quote:
Originally Posted by Siba11 View Post
Hi. You can use an array (or even pointers) to store the values at each iteration using the in-built macro N_ITER.
Quote:
Originally Posted by Siba11 View Post
Hi. you can do something like this :

Code:
int A[100];

if (N_ITER == 1)
A[N_ITER] = C_T(c,t); // assuming you are working with temperature.

if (N_ITER > 1)
{
A[N_ITER] = C_T(c,t);
diff = A[N_ITER] - A[N_ITER - 1];
 
  if ('diff' satisfies the tolerance)
    RP_Set_Integer ("rp-variable", 1);
}
When the rp-variable will change, it will be detected by the console. You can use a DEFINE_ADJUST UDF for this task.
Hi, a new question, I didn't see the reason for using the 'rp' variable here. Following your steps, we could define a global variable in the udf to achieve the same functionality.
lbj007 is offline   Reply With Quote

Reply

Tags
iteration steps, scheme, udf


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
batch command to run fluent from nth time step solomon FLUENT 13 August 25, 2015 21:05


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