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/)
-   -   Calculating Gradient of a Scalar (https://www.cfd-online.com/Forums/fluent-udf/91194-calculating-gradient-scalar.html)

ali hemmati August 3, 2011 04:17

Calculating Gradient of a Scalar
 
Hello,

I am going to calculate gradient of a scalar (UDS) which is solved through iterations, and its quantity is known. Here is my 'on demand' UDF which tries(!) to store x-gradient of scalar 0 to scalar 1, yet after executing the UDF, I receive an 'ACCESS VIOLATION' error.
Would you please help me.

Thanks.

Code:

#include "udf.h"

DEFINE_ON_DEMAND(grad_calc)
{

Domain *domain;
Thread *t;
cell_t c;

domain = Get_Domain(1);

        thread_loop_c(t,domain)
        {
                begin_c_loop(c,t)
                {
                        C_UDSI(c,t,1) = C_UDSI_G(c,t,0)[0];               
                }
                end_c_loop(c,t)
        }

}


Amir August 3, 2011 15:10

Did you activate 2 UDSs?
Did you set a command in TUI in order to store gradients during iteration?
if yes, before executing this macro, allocate 2nd UDS simply by patching it with arbitrary value.


Amir

ali hemmati August 4, 2011 04:05

Hi Amir,

Thanks for your help. I pursued these two methods and got desired solution:

1. I solved the problem with defining all UDSs before iterating.
2. I solved the problem just by defining scalar 0 and after convergence, I patched scalar 1 to fluid zone with arbitrary value.

Subsequent to things done above, I executed the UDF without any error.

Thanks again.


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