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

Access to temperature gradient C_T_G

Register Blogs Community New Posts Updated Threads Search

Like Tree3Likes
  • 1 Post By gearboy
  • 2 Post By AlexanderZ

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   August 17, 2017, 13:05
Default Access to temperature gradient C_T_G
  #1
New Member
 
Join Date: Aug 2017
Posts: 20
Rep Power: 8
cfdstar is on a distinguished road
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)
}
cfdstar is offline   Reply With Quote

Old   August 31, 2017, 04:15
Default
  #2
Senior Member
 
Join Date: Feb 2010
Posts: 164
Rep Power: 17
gearboy is on a distinguished road
Quote:
Originally Posted by cfdstar View Post
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);
mechy likes this.
gearboy is offline   Reply With Quote

Old   February 29, 2020, 04:33
Default
  #3
Senior Member
 
mahdi rostami
Join Date: Jan 2020
Posts: 155
Rep Power: 6
mahdi-united is on a distinguished road
Quote:
Originally Posted by gearboy View Post
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?
mahdi-united is offline   Reply With Quote

Old   October 4, 2020, 05:52
Default
  #4
Senior Member
 
Join Date: Feb 2020
Posts: 114
Rep Power: 6
lbj007 is on a distinguished road
Quote:
Originally Posted by cfdstar View Post
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.
lbj007 is offline   Reply With Quote

Old   October 5, 2020, 01:19
Default
  #5
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
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.
mghr and FelixS like this.
__________________
best regards


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   October 5, 2020, 22:26
Default
  #6
Senior Member
 
Join Date: Feb 2020
Posts: 114
Rep Power: 6
lbj007 is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
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:



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:



now if I change the value to constant like this:



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...
lbj007 is offline   Reply With Quote

Old   October 6, 2020, 03:46
Default
  #7
Senior Member
 
Alexander
Join Date: Apr 2013
Posts: 2,363
Rep Power: 34
AlexanderZ will become famous soon enoughAlexanderZ will become famous soon enough
unfortunately, no idea, how to deal with it.

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


******************************
press LIKE if this message was helpful
AlexanderZ is offline   Reply With Quote

Old   October 6, 2020, 05:54
Default
  #8
Senior Member
 
Join Date: Feb 2020
Posts: 114
Rep Power: 6
lbj007 is on a distinguished road
Quote:
Originally Posted by AlexanderZ View Post
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.
lbj007 is offline   Reply With Quote

Old   November 23, 2020, 22:53
Default use SV_UDS_I, SV_UDSI_G; SV_T_G, SV_H_G
  #9
Member
 
Join Date: Dec 2009
Location: Kanpur, India
Posts: 54
Rep Power: 16
Shoonya is on a distinguished road
Quote:
Originally Posted by lbj007 View Post
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

Last edited by Shoonya; November 24, 2020 at 05:32. Reason: corrected few more lines
Shoonya is offline   Reply With Quote

Old   November 24, 2020, 21:41
Default
  #10
Senior Member
 
Join Date: Feb 2020
Posts: 114
Rep Power: 6
lbj007 is on a distinguished road
Quote:
Originally Posted by Shoonya View Post
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)
lbj007 is offline   Reply With Quote

Old   November 24, 2020, 23:56
Default
  #11
Member
 
Join Date: Dec 2009
Location: Kanpur, India
Posts: 54
Rep Power: 16
Shoonya is on a distinguished road
Quote:
Originally Posted by lbj007 View Post
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 View Post
I think I don't need to use if (NULL != THREAD_STORAGE(t, SV_UDS_I)

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.
Shoonya is offline   Reply With Quote

Old   November 25, 2020, 05:27
Default
  #12
Senior Member
 
Join Date: Feb 2020
Posts: 114
Rep Power: 6
lbj007 is on a distinguished road
Quote:
Originally Posted by Shoonya View Post
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 is offline   Reply With Quote

Old   November 25, 2020, 08:15
Default
  #13
Senior Member
 
Join Date: Feb 2020
Posts: 114
Rep Power: 6
lbj007 is on a distinguished road
Quote:
Originally Posted by Shoonya View Post
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. 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;
lbj007 is offline   Reply With Quote

Old   November 25, 2020, 14:27
Default
  #14
Senior Member
 
Join Date: Nov 2013
Posts: 1,965
Rep Power: 26
pakk will become famous soon enough
You forgot to put brackets after your if statement. Indentation is only for the programmer, not relevant for the compiler.
pakk is offline   Reply With Quote

Old   November 26, 2020, 05:58
Default
  #15
Senior Member
 
Join Date: Feb 2020
Posts: 114
Rep Power: 6
lbj007 is on a distinguished road
Quote:
Originally Posted by pakk View Post
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)
lbj007 is offline   Reply With Quote

Old   December 13, 2020, 18:27
Smile
  #16
New Member
 
amine
Join Date: Dec 2020
Posts: 7
Rep Power: 5
djendara is on a distinguished road
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
djendara is offline   Reply With Quote

Reply

Tags
boundary condition, c_t_g, temperature gradients, 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
CFX, temperature gradient inside particles hmdl CFX 3 January 30, 2016 04:40
Temperature gradient in FLUENT abhi084 FLUENT 0 December 4, 2015 05:27
specified shear at wall - temperature gradient - UDF - access violation error senD Fluent UDF and Scheme Programming 9 September 18, 2014 07:29
how to perform temperature gradient on a particle (Thermophoretic Force) wwt650420 FLUENT 3 March 23, 2011 02:10
Wall correction for the temperature gradient Hagen OpenFOAM 0 March 7, 2011 20:04


All times are GMT -4. The time now is 16:26.