CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   FLUENT (https://www.cfd-online.com/Forums/fluent/)
-   -   UDF - Execute command : Trigger data sampling and time statistics (https://www.cfd-online.com/Forums/fluent/228146-udf-execute-command-trigger-data-sampling-time-statistics.html)

Bibill June 21, 2020 11:58

UDF - Execute command : Trigger data sampling and time statistics
 
Dear all,

I would like to trigger the data sampling and time statistics as soon as a pre-defined accuracy is reached for a quantity of interest in a UDF.

I guess it should be possible to do it by setting up an rp variable of boolean type and an execute command that starts the sampling as soon as rp variable becomes true and the value of rp variable can be set by UDF.

However i am not really familiar to rp variable and execute command. Is it possible to define the rp variable inside the UDF itself ?
Can anyone help me ? I would truly appreciate your help !

Thanks in advance!

vinerm June 21, 2020 17:29

RP-Variable
 
Defining and setting an rp-variable is straightforward. Use the following command

(make-new-rpvar 'nameofrpvar value type)

e.g., to define a variable lcoeff with initial value 0.81, use

(make-new-rpvar 'lcoeff 0.81 'real)

To fetch its value

(rpgetvar 'lcoeff)

To set it to new value

(rpsetvar 'lcoeff 0.9)

In place of 0.81 or 0.9, you can also use other commands that return a real value. You can use conditional statement in Execute-Commands to check if the value of variable you defined is below or above a specified limit. If that matches, then sampling should be enabled. Other option is to use a boolean instead of real value.

Bibill June 21, 2020 18:18

Thank you for your answer !

And is it possible to set the rp variable value inside the UDF and not by means of the text interface ?
I know how to access the value (e.g RP_Get_Boolean) but not how to modify it...


Thanks in advance!

AlexanderZ June 21, 2020 23:44

you may modify values of rpvariables from UDF

it is convenient to have separated UDF variable which you will use for any modifications and apply its' value to rpvar you need. For instance, you have created rpvariable with name my_rpvar, value False and type boolean
Code:

(make-new-rpvar 'my_rpvar #f 'boolean)
you can apply True value to your rpvar
Code:

#include "udf.h"

DEFINE_ON_DEMAND(get_boolean)
{
cxboolean        my_udf_rpvar;
#if !RP_NODE        /* SERIAL or HOST */
my_udf_rpvar = RP_Get_Boolean("my_rpvar");
my_udf_rpvar = TRUE;
RP_Set_Boolean("my_rpvar",my_udf_rpvar);
#endif /* !RP_NODE */
}

if you are going to use parallel computation, you must define the way to send data from rpvars (which could be done on HOST node only) to "computation" parts of your code (which you want to be on computational nodes). THIS IS NOT DONE FOR THIS EXAMPLE.

More information you can find in Ansys Fluent Customization manual

Bibill June 21, 2020 23:54

Thank you again for your great answer AlexanderZ!

A very last question if you still got time, i have tried to trigger the data sampling with the option "execute command". For that purpose, i have previously defined a rp-variable called "variable" which should help to trigger the data sampling when it becomes equal to 5:

(if (= rpgetvar 'variable 5)\n (/solve/set/data-sampling/yes 1 yes yes));

However it doesn't work, the following error message appears :

Error: eval: unbound variable

Error Object: /solve/set/data-sampling/yes

Do you have an idea of why and how to fix it ?

Thank you in advance again!

AlexanderZ June 22, 2020 02:08

first of all I recommends you to use name which Fluent doesn't use definitely (which could not be a case for just "variable")
use my_variable instead

you may try
Code:

(if (= (rpgetvar 'my_variable) 5) (/solve/set/data-sampling/yes 1 yes yes) ())
or

Code:

(if (= (rpgetvar 'variable) 5) (ti-menu-load-string (format #f "/solve/set/data-sampling/yes 1 yes yes")) ())

Bibill June 22, 2020 03:06

Thanks !! Second option was the good call!!

By chance, is there also a command to reset the data sampling once it has already been triggered ?

vinerm June 22, 2020 08:08

Statistics reset
 
To reset the sampled statistics, you can use the following command

solve init init-flow-stat

sina_sls August 22, 2022 02:58

Quote:

Originally Posted by AlexanderZ (Post 775455)
first of all I recommends you to use name which Fluent doesn't use definitely (which could not be a case for just "variable")
use my_variable instead

you may try
Code:

(if (= (rpgetvar 'my_variable) 5) (/solve/set/data-sampling/yes 1 yes yes) ())
or

Code:

(if (= (rpgetvar 'variable) 5) (ti-menu-load-string (format #f "/solve/set/data-sampling/yes 1 yes yes")) ())

Hi AlexanderZ,

I want to write some text command after each iteration when fluent running , is this possible? If yes how could i do it through UDF?

Regards,


All times are GMT -4. The time now is 10:09.