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/)
-   -   User Defined Memory (https://www.cfd-online.com/Forums/fluent-udf/95974-user-defined-memory.html)

sreekargomatam January 9, 2012 09:19

User Defined Memory
 
I use a nonlinear k-e model and the Reynolds Stress is stored in the User defined memory. Is it possible to clear that user defined memory after a set number of iterations while running the case??

ComputerGuy January 14, 2012 16:31

Sure. Is it a transient case or a steady-state case? The define_adjust macro will run once per iteration, and thus you'd need to simply hook your reset macro (with appropriate logic) into define_adjust.

I haven't tried the code below, but it should give you an idea of what to do.
Code:

#include "udf.h"
int IterCounter=1;

DEFINE_ADJUST(adjust_fcn,d)
{
        Thread *t;
        cell_t c;
        /*reset if iterations > 2000 */
        if(IterCounter>2000)
        {
                IterCounter=0;
                thread_loop_c(t,d)
                {
                        if (FLUID_THREAD_P(t))
                        {
                        begin_c_loop_all(c,t)
                                {               
                                        for (i = 0; i < n_udm; i++)
                                        {
                                                /*This loops over all UDM locations and resets them to 0.*/
                                                /* Implement your own values or logic here*/
                                                C_UDMI(c, t, i) = 0.0;
                                        }
                                }
                        end_c_loop_all(c,t)
                        }
                }
        }
        IterCounter=IterCounter+1;
}

ComputerGuy

sreekargomatam January 17, 2012 02:46

Thanks for the code. It's a transient code. Will it make any difference if it's a steady case? If so, how?

ComputerGuy January 17, 2012 09:10

I asked because doing something based on iterations in a transient code doesn't make a lot of sense (while they're correlated with flow time, it's not a fixed relationship, and you'd be resetting at random intervals). By iterations, do you mean time step?

ComputerGuy

Quote:

Originally Posted by sreekargomatam (Post 339654)
Thanks for the code. It's a transient code. Will it make any difference if it's a steady case? If so, how?


sreekargomatam January 17, 2012 09:13

Yes. By iterations I mean the time steps. Is it possible to delete that data at the completion of a case. If I'm running the case for 100seconds, is there someway to delete the user defined memory after 100s from the data file?

ComputerGuy January 17, 2012 09:19

Yes. The simple fix to the code below should clear the UDM after 100 seconds. It's a define on demand to prevent running every iteration for flow times beyond 100s
Code:

#include "udf.h"


DEFINE_ON_DEMAND(eraseudm)
{
        Thread *t;
        Domain *d;
        cell_t c;
        real current_time;
        current_time = CURRENT_TIME;
        d = Get_Domain(1);
        if(current_time>100)
        {
                IterCounter=0;
                thread_loop_c(t,d)
                {
                        if (FLUID_THREAD_P(t))
                        {
                        begin_c_loop_all(c,t)
                                {               
                                        for (i = 0; i < n_udm; i++)
                                        {
                                                /*This loops over all UDM locations and resets them to 0.*/
                                                /* Implement your own values or logic here*/
                                                C_UDMI(c, t, i) = 0.0;
                                        }
                                }
                        end_c_loop_all(c,t)
                        }
                }
        }

}


ComputerGuy


Quote:

Originally Posted by sreekargomatam (Post 339734)
Yes. By iterations I mean the time steps. Is it possible to delete that data at the completion of a case. If I'm running the case for 100seconds, is there someway to delete the user defined memory after 100s from the data file?


moun139 May 18, 2012 17:18

this is my udf to calculate gradient of temperature dt/dy,it write me error fluent reveice .....()

what's wrong ?


#include "udf.h"

DEFINE_ON_DEMAND(store_grad)
{
Domain* d;
Thread *t;
cell_t c;

d=Get_Domain(1);
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,0)=C_T_G(c,t)[1];
}
end_c_loop(c,t)
}
}
thx

Amir May 19, 2012 04:56

Quote:

Originally Posted by moun139 (Post 361927)
this is my udf to calculate gradient of temperature dt/dy,it write me error fluent reveice .....()

what's wrong ?


#include "udf.h"

DEFINE_ON_DEMAND(store_grad)
{
Domain* d;
Thread *t;
cell_t c;

d=Get_Domain(1);
thread_loop_c(t,d)
{
begin_c_loop(c,t)
{
C_UDMI(c,t,0)=C_T_G(c,t)[1];
}
end_c_loop(c,t)
}
}
thx

Hi,

Did you patch the UDM before use?


All times are GMT -4. The time now is 17:07.