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/)
-   -   Access to temperature gradient C_T_G (https://www.cfd-online.com/Forums/fluent-udf/191715-access-temperature-gradient-c_t_g.html)

cfdstar August 17, 2017 13:05

Access to temperature gradient C_T_G
 
Hi,

I wanted to define a shear boundary condition as a function of temperature gradient. Following is the UDF I wrote for this purpose. The UDF only returns the the constant value of 0.0 since the temperature gradient is not accessible. However, from the contour plots, I can see that temperature gradients are available after the first iteration.

If I remove the "if" statement, I receive this error:
Error: received a fatal signal (Segmentation fault).
Error Object: #f


I should mention that I keep temporary solver memory from being freed. Any help to solve this problem is highly appreciated.

#include "udf.h"
#include "mem.h"

DEFINE_PROFILE(WSS, t, i)
{
face_t f;
cell_t c;
real TG;
begin_c_loop(c,t)
{
if (NNULLP(THREAD_STORAGE(t, SV_T_G)))
{
printf("Gradient of Temperature is available \n ");
TG = NV_MAG(C_T_G(c,t));
C_PROFILE(c,t,i)=-0.0001*TG;
} else
{
C_PROFILE(c,t,i)=0.;
}
}
end_c_loop(c,t)
}

gearboy August 31, 2017 04:15

Quote:

Originally Posted by cfdstar (Post 661070)
Hi,

I wanted to define a shear boundary condition as a function of temperature gradient. Following is the UDF I wrote for this purpose. The UDF only returns the the constant value of 0.0 since the temperature gradient is not accessible. However, from the contour plots, I can see that temperature gradients are available after the first iteration.

If I remove the "if" statement, I receive this error:
Error: received a fatal signal (Segmentation fault).
Error Object: #f


I should mention that I keep temporary solver memory from being freed. Any help to solve this problem is highly appreciated.

#include "udf.h"
#include "mem.h"

DEFINE_PROFILE(WSS, t, i)
{
face_t f;
cell_t c;
real TG;
begin_c_loop(c,t)
{
if (NNULLP(THREAD_STORAGE(t, SV_T_G)))
{
printf("Gradient of Temperature is available \n ");
TG = NV_MAG(C_T_G(c,t));
C_PROFILE(c,t,i)=-0.0001*TG;
} else
{
C_PROFILE(c,t,i)=0.;
}
}
end_c_loop(c,t)
}





Alloc_Storage_Vars(domain, SV_T_RG, SV_T_G, SV_NULL);
T_derivatives(domain);
.........
your code....
.........

Free_Storage_Vars(domain, SV_T_RG, SV_NULL);
Free_Storage_Vars(domain, SV_T_G, SV_NULL);

mahdi-united February 29, 2020 04:33

Quote:

Originally Posted by gearboy (Post 662536)
Alloc_Storage_Vars(domain, SV_T_RG, SV_T_G, SV_NULL);
T_derivatives(domain);
.........
your code....
.........

Free_Storage_Vars(domain, SV_T_RG, SV_NULL);
Free_Storage_Vars(domain, SV_T_G, SV_NULL);

hi please help me
what are the arguments for this macros for accessing species mass fraction?

lbj007 October 4, 2020 05:52

Quote:

Originally Posted by cfdstar (Post 661070)
Hi,

I wanted to define a shear boundary condition as a function of temperature gradient. Following is the UDF I wrote for this purpose. The UDF only returns the the constant value of 0.0 since the temperature gradient is not accessible. However, from the contour plots, I can see that temperature gradients are available after the first iteration.

If I remove the "if" statement, I receive this error:
Error: received a fatal signal (Segmentation fault).
Error Object: #f


I should mention that I keep temporary solver memory from being freed. Any help to solve this problem is highly appreciated.

#include "udf.h"
#include "mem.h"

DEFINE_PROFILE(WSS, t, i)
{
face_t f;
cell_t c;
real TG;
begin_c_loop(c,t)
{
if (NNULLP(THREAD_STORAGE(t, SV_T_G)))
{
printf("Gradient of Temperature is available \n ");
TG = NV_MAG(C_T_G(c,t));
C_PROFILE(c,t,i)=-0.0001*TG;
} else
{
C_PROFILE(c,t,i)=0.;
}
}
end_c_loop(c,t)
}

Hi,have you solve this problem,I'm using C_UDSI_G and can't find a way to solve it.

AlexanderZ October 5, 2020 01:19

from manual
Quote:

In order to retain the gradient data (when you want to set up user-defined scalar transport equations, for example), you can prevent the solver from freeing up memory by issuing the text command solve/set/expert and then answering yes to the question, “Keep temporary solver memory from being freed?” Note that when you do this, all of the gradient data is retained, but the calculation requires more memory to run.

lbj007 October 5, 2020 22:26

Quote:

Originally Posted by AlexanderZ (Post 784414)
from manual

I've already tried this,not working.please let me introduce my situation:
now I have used C_UDSI_G to calculate current density successfully in a cas, it can be seen in post-processing, then I write cas and dat. Now I read cas, and when I read dat it shows:

https://cmct.xyz/images/2020/10/06/S...6_10-17-16.png

the process of fluent has already down. I've know the reason for it:when I read dat, it can't access the value of C_UDSI_G immediately because I used define_profile macros and it would first be called:

https://cmct.xyz/images/2020/10/06/1.png

now if I change the value to constant like this:

https://cmct.xyz/images/2020/10/06/2.png

and also need to calcalate for one iteration,until then it won't get wrong when I read dat.:(:(:(

so I wonder if there's a way to read dat normally without these procedure...

AlexanderZ October 6, 2020 03:46

unfortunately, no idea, how to deal with it.

try to remove reading from .dat step.
simulate everything without exit from fluent

lbj007 October 6, 2020 05:54

Quote:

Originally Posted by AlexanderZ (Post 784532)
unfortunately, no idea, how to deal with it.

try to remove reading from .dat step.
simulate everything without exit from fluent

OK,thanks.BTW, will this situation happen when using other macros of gradient,such as C_T_G? or it just goes wrong when using UDS gradient.

Shoonya November 23, 2020 22:53

use SV_UDS_I, SV_UDSI_G; SV_T_G, SV_H_G
 
Quote:

Originally Posted by lbj007 (Post 784371)
Hi,have you solve this problem,I'm using C_UDSI_G and can't find a way to solve it.

Code:

DEFINE_ADJUST(adjust_sources,d)
{
    Thread *t;
    cell_t c;   
 
    double  del_psi_delx, del_psi_dely;

    thread_loop_c(t,d)   
    {
    if (NULL != THREAD_STORAGE(t, SV_UDS_I) &&
        NULL != T_STORAGE_R_NV(t,SV_UDSI_G) )
       
        begin_c_loop(c,t)       
        {           
            del_psi_delx = C_UDSI_G(c,t,0)[0];
            del_psi_dely = C_UDSI_G(c,t,0)[1];

      }
}

See the line SV_UDS_I, SV_UDSI_G. This way you would be able use the UDSI and will not receive the segmentation fault or fetal error.

Best

lbj007 November 24, 2020 21:41

Quote:

Originally Posted by Shoonya (Post 788638)
Code:

DEFINE_ADJUST(adjust_sources,d)
{
    Thread *t;
    cell_t c;   
 
    double  del_psi_delx, del_psi_dely;

    thread_loop_c(t,d)   
    {
    if (NULL != THREAD_STORAGE(t, SV_UDS_I) &&
        NULL != T_STORAGE_R_NV(t,SV_UDSI_G) )
       
        begin_c_loop(c,t)       
        {           
            del_psi_delx = C_UDSI_G(c,t,0)[0];
            del_psi_dely = C_UDSI_G(c,t,0)[1];

      }
}

See the line SV_UDS_I, SV_UDSI_G. This way you would be able use the UDSI and will not receive the segmentation fault or fetal error.

Best

Have you proven its effectiveness?cause I tried using "if (NNULLP(T_STORAGE_R_NV(t0, SV_UDSI_G(0))))" and it didn't work out, I think I don't need to use if (NULL != THREAD_STORAGE(t, SV_UDS_I):confused::confused:

Shoonya November 24, 2020 23:56

Quote:

Originally Posted by lbj007 (Post 788752)
Have you proven its effectiveness?cause I tried using "if (NNULLP(T_STORAGE_R_NV(t0, SV_UDSI_G(0))))" and it didn't work out.


Hi,
Yes, I have checked its effectiveness and in fact I am working on a problem where 3 UDSIs are present and I am using gradients of 2 UDSIs. Without that "if(NULL!=....)" statement my UDF was not working because no memory was allocated to them and when I call them in UDF (i.e., for example C_UDSI_G(c,t,0)[0]), it threw the segmentation fault. When I used that statement my UDF worked fine. Also I checked those gradients by storing them in UDMI's, I and found reasonable results.



Quote:

Originally Posted by lbj007 (Post 788752)
I think I don't need to use if (NULL != THREAD_STORAGE(t, SV_UDS_I):confused::confused:


Ok, what I meant was to use the following (I am directly copying from the code I am using):


Code:

if (NULL != THREAD_STORAGE(t, SV_UDS_I(0)) &&
    NULL != T_STORAGE_R_NV(t,SV_UDSI_G(0)) &&
    NULL != THREAD_STORAGE(t, SV_UDS_I(1)) &&
    NULL != T_STORAGE_R_NV(t,SV_UDSI_G(1)) &&
    NULL != THREAD_STORAGE(t, SV_UDS_I(2)) &&
    NULL != T_STORAGE_R_NV(t,SV_UDSI_G(2)))


rest your wish, I just thought to respond to this thread, although I was not linked to this thread. And I only write on those problems in cfdonline forums in which I too have faced problem at certain stage.

lbj007 November 25, 2020 05:27

Quote:

Originally Posted by Shoonya (Post 788756)
Hi,
Yes, I have checked its effectiveness and in fact I am working on a problem where 3 UDSIs are present and I am using gradients of 2 UDSIs. Without that "if(NULL!=....)" statement my UDF was not working because no memory was allocated to them and when I call them in UDF (i.e., for example C_UDSI_G(c,t,0)[0]), it threw the segmentation fault. When I used that statement my UDF worked fine. Also I checked those gradients by storing them in UDMI's, I and found reasonable results.






Ok, what I meant was to use the following (I am directly copying from the code I am using):


Code:

if (NULL != THREAD_STORAGE(t, SV_UDS_I(0)) &&
    NULL != T_STORAGE_R_NV(t,SV_UDSI_G(0)) &&
    NULL != THREAD_STORAGE(t, SV_UDS_I(1)) &&
    NULL != T_STORAGE_R_NV(t,SV_UDSI_G(1)) &&
    NULL != THREAD_STORAGE(t, SV_UDS_I(2)) &&
    NULL != T_STORAGE_R_NV(t,SV_UDSI_G(2)))


rest your wish, I just thought to respond to this thread, although I was not linked to this thread. And I only write on those problems in cfdonline forums in which I too have faced problem at certain stage.

OK,thanks for sharing:):) I'll try it after.

lbj007 November 25, 2020 08:15

Quote:

Originally Posted by Shoonya (Post 788756)
Hi,
Yes, I have checked its effectiveness and in fact I am working on a problem where 3 UDSIs are present and I am using gradients of 2 UDSIs. Without that "if(NULL!=....)" statement my UDF was not working because no memory was allocated to them and when I call them in UDF (i.e., for example C_UDSI_G(c,t,0)[0]), it threw the segmentation fault. When I used that statement my UDF worked fine. Also I checked those gradients by storing them in UDMI's, I and found reasonable results.






Ok, what I meant was to use the following (I am directly copying from the code I am using):


Code:

if (NULL != THREAD_STORAGE(t, SV_UDS_I(0)) &&
    NULL != T_STORAGE_R_NV(t,SV_UDSI_G(0)) &&
    NULL != THREAD_STORAGE(t, SV_UDS_I(1)) &&
    NULL != T_STORAGE_R_NV(t,SV_UDSI_G(1)) &&
    NULL != THREAD_STORAGE(t, SV_UDS_I(2)) &&
    NULL != T_STORAGE_R_NV(t,SV_UDSI_G(2)))


rest your wish, I just thought to respond to this thread, although I was not linked to this thread. And I only write on those problems in cfdonline forums in which I too have faced problem at certain stage.

Now it's weird,I can't even calculate after adding this, segmentation fault.:confused::confused: here is my profile code,I only changed this when I calculate:

Code:

begin_f_loop(f,f_thread)
        {       
                c0=F_C0(f,f_thread);
            t0=THREAD_T0(f_thread);
                c1=F_C1(f,f_thread);
                t1=THREAD_T1(f_thread);
                tem3=C_T(c0,t0);
                diff=33400*exp(-10300/tem3);
                if (NULL != THREAD_STORAGE(t0, SV_UDS_I(0)) && NULL != T_STORAGE_R_NV(t0,SV_UDSI_G(0)))
                        NV_V(J0,=,C_UDSI_G(c0,t0,0));
                        ja=diff*NV_MAG(J0);
                concen0=1000*C_R(c1,t1)*C_YI(c1,t1,0)/2;
                concen1=1000*C_R(c1,t1)*C_YI(c1,t1,1)/18;
               
                nesta=(8.31447*tem3/(2*96485))*log((concen1*11.555)/(concen0*0.3573778)); 
                acta=8.31447*tem3/2/96485*ja/20000*11.555/concen0*0.3573/concen1;
                uright=1.11-nesta;
                C_UDMI(c0,t0,0)=ja;
                C_UDMI(c0,t0,1)=uright;
                C_UDMI(c0,t0,2)=nesta;
                C_UDMI(c1,t1,3)=ja/2/96485/(1e-4)*0.002; 
                C_UDMI(c0,t0,4)=acta;


pakk November 25, 2020 14:27

You forgot to put brackets after your if statement. Indentation is only for the programmer, not relevant for the compiler.

lbj007 November 26, 2020 05:58

Quote:

Originally Posted by pakk (Post 788860)
You forgot to put brackets after your if statement. Indentation is only for the programmer, not relevant for the compiler.

so I just need to add brackets like this,no need to add else judgment statement

Code:

begin_f_loop(f,f_thread)
{       
        c0=F_C0(f,f_thread);
    t0=THREAD_T0(f_thread);
        c1=F_C1(f,f_thread);
        t1=THREAD_T1(f_thread);
        tem3=C_T(c0,t0);
        diff=33400*exp(-10300/tem3);
        if (NULL != THREAD_STORAGE(t0, SV_UDS_I(0)) && NULL != T_STORAGE_R_NV(t0,SV_UDSI_G(0)))
        {
                NV_V(J0,=,C_UDSI_G(c0,t0,0));
                ja=diff*NV_MAG(J0);
                concen0=1000*C_R(c1,t1)*C_YI(c1,t1,0)/2;
                concen1=1000*C_R(c1,t1)*C_YI(c1,t1,1)/18;
               
                nesta=(8.31447*tem3/(2*96485))*log((concen1*11.555)/(concen0*0.3573778)); 
                acta=8.31447*tem3/2/96485*ja/20000*11.555/concen0*0.3573/concen1;
                uright=1.11-nesta;
                C_UDMI(c0,t0,0)=ja;
                C_UDMI(c0,t0,1)=uright;
                C_UDMI(c0,t0,2)=nesta;
                C_UDMI(c1,t1,3)=ja/2/96485/(1e-4)*0.002; 
                C_UDMI(c0,t0,4)=acta;

                F_PROFILE(f,f_thread,position)=C_UDMI(c0,t0,1);
        }
}
end_f_loop(f,f_thread)


djendara December 13, 2020 18:27

you can prevent the solver from freeing up memory by issuing the text command solve/set/expert yes
you will find the result after computation


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