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

temperature gradient in a microchannel

Register Blogs Community New Posts Updated Threads Search

Like Tree1Likes
  • 1 Post By obscureed

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   March 12, 2018, 03:01
Default temperature gradient in a microchannel
  #1
New Member
 
Phil
Join Date: Apr 2013
Posts: 6
Rep Power: 13
pittsb is on a distinguished road
===============
#include "udf.h"
#include "mem.h"
#include "sg.h"

DEFINE_PROFILE(temp_slip, t, position)
{
real x[ND_ND];
real y,T_wf,T_wc,T_wc_g;
face_t f;
cell_t c;
begin_f_loop(f,t)
{
y = x[1];
T_wf = F_T(f,t);
T_wc = C_T(c,t);
T_wc_g = C_T_G(c,t)[0];

F_PROFILE(f, t, position) = 330.0 + 0.001*T_wc;
/* printf("%d %d %d \n",y,T_wf,T_wc); */
printf("%d %d %d %d\n",y,T_wf,T_wc,T_wc_g);
}
end_f_loop(f,t)
}
===============
I tried to apply the temeperature gradient in a vertical retangulare wall.

First, I tried to see what values are comunicating along the boundary UDF progem and main ANSYS Fuent. Without the C_T_G line I got the results. However, the values y,T_wf,T_wc are so big or zero. Anyway the solution converged.
Next, I insert the C_T_G line. I got the error message like below

Error: received a fatal signal (Segmentation fault).
Erro Object: #f

What happened? Based on the previous questions, I tried pre-iterations and solve/set/expert implimentation. Please help me. Thanks
pittsb is offline   Reply With Quote

Old   March 12, 2018, 06:26
Default
  #2
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 your code
Code:
T_wf = F_T(f,t); 
T_wc = C_T(c,t); 
T_wc_g = C_T_G(c,t)[0];
what are f and c in brackets (f,t) , (c,t) from your point of view?

why do you have
Code:
begin_f_loop(f,t)
{
for f, but nothing for c ?

from your code
Code:
real x[ND_ND];
real y;
.....
y = x[1];
here you've defined x as 2D or 3D array (depends on your case)
and than asked y to be equal to x[1]. What value is stored in x[1]?

In Ansys fluent customization manual pay attention to:
Code:
begin_c_loop(c,t)
F_CENTROID(x,f,t);
C_CENTROID(x,c,t);
Regarding C_T_G, may be you need pre-iteration approach, because
Code:
Error: received a fatal signal (Segmentation fault).
Erro Object: #f
means, something is not defined yet, most likely gradient.
Debug code without C_T_G first, than add it.

best regards
AlexanderZ is offline   Reply With Quote

Old   March 12, 2018, 22:31
Default
  #3
New Member
 
Phil
Join Date: Apr 2013
Posts: 6
Rep Power: 13
pittsb is on a distinguished road
Thanks a lot.
==================================
what are f and c in brackets (f,t) , (c,t) from your point of view?
==================================
In a 2d domain, (f,t) , (c,t) are locations of face(f) and cell(c), respectively.
==================================
why do you have
Code:
begin_f_loop(f,t)
{
for f, but nothing for c ?
==================================
I want to apply temperature gradient boundary conditions along the wall which means the boundary face. I changed "f" to "c".
==================================
from your code
Code:
real x[ND_ND];
real y;
.....
y = x[1];
here you've defined x as 2D or 3D array (depends on your case)
and than asked y to be equal to x[1]. What value is stored in x[1]?
==================================
For the values of y,T_wf,T_wc,T_wc_g

1633131590 0 0 0
-42712596 0 0 0
-1718845012 0 0 0
899989867 0 0 0
-775854318 0 0 0
1842980562 0 0 0
165406993 0 0 0

==================================
In Ansys fluent customization manual pay attention to:
Code:
begin_c_loop(c,t)
F_CENTROID(x,f,t);
C_CENTROID(x,c,t);
Regarding C_T_G, may be you need pre-iteration approach
==================================
I got no error message.
pittsb is offline   Reply With Quote

Old   March 12, 2018, 22:32
Default
  #4
New Member
 
Phil
Join Date: Apr 2013
Posts: 6
Rep Power: 13
pittsb is on a distinguished road
#include "udf.h"
#include "mem.h"
#include "sg.h"

DEFINE_PROFILE(temp_slip, t, position)
{
real x[2];


real y,T_wf,T_wc,T_wc_g;
face_t f;
cell_t c;


begin_c_loop(c,t)
{

F_CENTROID(x,f,t);
C_CENTROID(x,c,t);

y = x[1];
T_wf = F_T(f,t);
T_wc = C_T(c,t);
/* T_wc_g = C_T_G(c,t)[0]; */

F_PROFILE(f, t, position) = 330.0 + 0.001*T_wc;

/* printf("%d %d %d \n",y,T_wf,T_wc); */
printf("%d %d %d %d\n",y,T_wf,T_wc,T_wc_g);

}
end_c_loop(c,t)
}
pittsb is offline   Reply With Quote

Old   March 13, 2018, 00:38
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
you code has errors

In Ansys fluent customization manual pay attention to:
Code:

Code:
begin_f_loop(f,t)
begin_c_loop(c,t)
F_CENTROID(x,f,t);
C_CENTROID(x,c,t);
best regards
AlexanderZ is offline   Reply With Quote

Old   March 14, 2018, 01:37
Default
  #6
New Member
 
Phil
Join Date: Apr 2013
Posts: 6
Rep Power: 13
pittsb is on a distinguished road
Thanks for the quick reply AlexanderZ.
To make sure the variables between UDF and Fluent, I printed the cordinates, boundary wall temperature, and F_PROFILE. As you see below numbers, these numbers are wrong. What happened?

====================================
#include "udf.h"
#include "mem.h"
#include "sg.h"

DEFINE_PROFILE(temp_slip, t, position)
{
real x[ND_ND];
real y1,y2,T_wc,T_wc_g;
cell_t c;

begin_c_loop(c,t)
{
C_CENTROID(x,c,t);
y1 = x[1];
y2 = x[2];
T_wc = C_T(c,t);
/* T_wc_g = C_T_G(c,t)[0];
*/
F_PROFILE(c, t, position) = 330.0 + 0.001*T_wc;

printf("%d %d %d %d\n",y1,y2,T_wc,F_PROFILE(c, t, position));
}
end_c_loop(c,t)
}

====================================
-1928693984 -1928693984 142152092 142152092
690429126 690429126 142152092 142152092
-985703290 -985703290 142152092 142152092
1633131590 1633131590 142152092 142152092
-42712596 -42712596 142152092 142152092
-1718845012 -1718845012 142152092 142152092
899989867 899989867 142152092 142152092
-775854318 -775854318 142152092 142152092
1842980562 1842980562 142152092 142152092
165406993 165406993 142152092 142152092
====================================
pittsb is offline   Reply With Quote

Old   March 14, 2018, 02:57
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
it is recommended to use Message macros instead of printf function
In Ansys Fluent Customization Manual go to chpter 3.7. Input/Output Macros

there you may fined detailed information about input/output

In your last version code you've used %d macros for output. However, %d is used for integers only, but you want real. So you need %f

code was
Code:
printf("%d %d %d %d\n",y1,y2,T_wc,F_PROFILE(c, t, position));
to be
Code:
Message("%f %f %f %f\n",y1,y2,T_wc,F_PROFILE(c, t, position));
best regards
AlexanderZ is offline   Reply With Quote

Old   March 14, 2018, 08:55
Default
  #8
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
Hi Pittsb,

Your original code assumed that it had access to both (c,t) and (f,t) -- which is not possible: a Thread *t pointer can be a cell-thread pointer or a face-thread pointer, but not both at once. Also, c was never assigned a value. (I'm repeating or rephrasing what AlexanderZ has already pointed out.)

Your latest code is passed the thread pointer t, and assumes that it can access cell values. This seems unlikely to me: DEFINE_PROFILE is typically applied as a boundary condition, and therefore applied to a face zone, so t will be a face-thread pointer.

You might not get errors from the latest code, because the storage of cells in a cell-thread is the same as faces in a face-thread, and the loops are the same. But still, it is dangerous to be so unclear. For example, you have chance of reaching C_T_G(c,tc), but you have no chance of reaching F_T_G(f,tf) or C_T_G(f,tf). I have used tf instead of t for a face-thread pointer, and tc for a cell-thread pointer -- this is very useful notation to remind yourself which is which.

If you need access to the cell that a face (f,tf) is part of, then you need:
Thread *ct;
cell_t c;
ct = F_C0_THREAD(f,tf);
c = F_C0(f,tf);
(And as soon as you use F_C0, you should wonder whether you actually wanted the cell on the other side of the face: F_C1,F_C1_THREAD. In this case, we might be sure that these are boundary faces, in which case there can be only one cell, and it will always be C0.)

Good luck!
Ed
AlexanderZ likes this.
obscureed is offline   Reply With Quote

Old   March 20, 2018, 00:23
Default
  #9
New Member
 
Phil
Join Date: Apr 2013
Posts: 6
Rep Power: 13
pittsb is on a distinguished road
Thanks a lot for explaining the face and the cell. Now, I decided to focus on the face which is a wall boundary. Without this line " T_wf_g = F_T_G(f,tf)[0]; " which represents "dT/dx", the results looks good. With F_T_G command, I got the error message "error C2109: subscript requires array or pointer". What happened?
===========================================
#include "udf.h"
#include "mem.h"
#include "sg.h"

DEFINE_PROFILE(temp_slip, tf, position)
{
real x[2];
real y1,y2,T_wf,T_wf_g;

face_t f;

/* Thread *ct;
ct = F_C0_THREAD(f,tf);
c = F_C0(f,tf);
*/
begin_f_loop(f,tf)
{
F_CENTROID(x,f,tf);
y1 = x[0];
y2 = x[1];

T_wf = F_T(f,tf);
T_wf_g = F_T_G(f,tf)[0];

F_PROFILE(f, tf, position) = 330.0 + 0.001*T_wf_g;
Message("%f %f %f %f\n",y1,y2,T_wf,T_wf_g);
}
end_f_loop(f,tf)
===========================================

Last edited by pittsb; March 20, 2018 at 20:17.
pittsb is offline   Reply With Quote

Old   March 22, 2018, 10:03
Default
  #10
Senior Member
 
Join Date: Sep 2017
Posts: 246
Rep Power: 12
obscureed is on a distinguished road
Hi Pittsb,

What happened is that F_T_G does not exist. (Sorry, it was me who first mentioned F_T_G, in the context of things that are not possible. Perhaps I should have mentioned just how hopeless that quest is: completely.) Your compiler's error message does not say this, perhaps because the compiler still has some hope that you will define it later, during linking or something. But the compiler is sure that you need to define it as an array if you refer to F_T_G(f,tf)[0].

In an ideal world, there would be documentation of what variables are sometimes available in Fluent UDFs, and how you should check whether they are available, and so on. This is not an ideal world. You can see that C_T_G exists, because it is defined in one of the header files (specifically, mem.h) that are part of a standard Fluent installation.

The fact that F_T_G does not exist in the header files definitely indicates that Fluent simply does allow you to access gradient values at faces, probably because it does not store those values there, and possibly does not even calculate them. If you want a gradient there, you will need to use the local cell version, or calculate one for yourself. (At first sight, this sounds fairly simple, in principle. It might turn out to be difficult once you consider all the edge cases -- I'm not sure.)

Good luck!
Ed
obscureed is offline   Reply With Quote

Reply


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
Access to temperature gradient C_T_G cfdstar Fluent UDF and Scheme Programming 15 December 13, 2020 19:27
Temperature gradient for the internal Field. Philipp Dietrich OpenFOAM Programming & Development 0 July 2, 2014 04:15
How to create a temperature gradient in thin wall and two dimensions leggman7 Main CFD Forum 0 October 30, 2013 00:21
How to get temperature gradient in dat.file jason feng FLUENT 0 September 30, 2013 00:39
Direct calculation of temperature gradient J.W.Ryu FLUENT 5 December 27, 2001 07:39


All times are GMT -4. The time now is 18:50.