CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)

 xiyuqiu June 29, 2012 14:16

calculate temperature gradient from temperature field

Hello all,

I have a field of temperatures (on nodes) and would like to calculate the temperature gradient (at cell center) from them. I was able to do it for structured cubes using finite difference. However, I am having a hard time to do it for unstructured tetrahedrons. anyone has suggestion?

best

 harbinyg June 29, 2012 20:16

Generally, there are two methods for gradient evaluation: based on Gauss Theorem and the Least-Squares approach

for unstructured grid, i advice you use the Gauss method, which is easy to implement ....

the method is widely known and can be found in lots of textbook of CFD

 xiyuqiu July 2, 2012 12:24

Dear Wu Jian

best,

yu

 xiyuqiu July 25, 2012 00:18

Hello Wu Jian,

I have implemented this Gauss method you suggested. It works great for cells with significant volume. I have tried to run a case with very small cell volume(10^-13) and with same temperature on four nodes (i use tetrahedrons). As expected I got very small flux (10^-14). However, when try to get the gradient, we need to divide the flux by the volume. Therefore, I actually got a significant gradient(10^-1) when I suppose to get zero. Is there anyway I can resolve this? Thanks again for your help.

best,

yu

 harbinyg July 25, 2012 04:53

first of all, i am glad you are working hard to solve your problem.

1. what do you mean by ' significant volume' ? the grid cell with large volume ?

2. I do not care about the size of your cell but the shape ... is your cell regular or not ?

3. Generally, for Gauss method, there is a grid induced error for non-orthogonal grid .

To get high accuarcy, you have to make sue the value at the center of the surface is a good interpolation value from the values of central nodes ....

generally, you may say : phi_surface _1 = fx*phi_left + (1-fx) phi_right

then the question is , if the grid is non-orthogonal, fx is not a good interpolation factor ...

 xiyuqiu July 25, 2012 14:04

Thanks for your time Wu Jian,
I created a tetrahedron cell with (0,0,0) (1,0,0) (0,1,0) and (0,0,1). With the same temperature on all four points, the method work fine . When I reduced the size, the cell is now (0,0,0) (0.00001,0,0) (0,0.00001,0) and (0,0,0.00001). The answer is incorrect.

 leflix July 25, 2012 17:29

Hi Yu,

The proposition of Wu Jian sounds good and it's funny it doesn't work, even if I can see why.

What you may do is to use an interpolation procedure as in finite element.

T(x,y) = h1(x,y)*T1 + h2(x,y)*T2+h3(x,y)*T3

where Ti are the values at each node of a triangle and hi(x,y) are interpolation functions. for example h1(x,y) =(1/2A)*( (y3-y2)(x2-x) - (x3-x2)(y2-y) ) where xi,yi are the coordinates of node i...
you will easily find the other interpolation functions h2(x,y) and h3(x,y) in any finite element text book.
Then when you get T(x,y) you can easily derive it analytically to obtain the gradient.

 FMDenaro July 25, 2012 17:36

Quote:
 Originally Posted by leflix (Post 373565) Hi Yu, What you may do is to use an interpolation procedure as in finite element. T(x,y) = h1(x,y)*T1 + h2(x,y)*T2+h3(x,y)*T3 where Ti are the values at each node of a triangle and hi(x,y) are interpolation functions. for example h1(x,y) =(1/2A)*( (y3-y2)(x2-x) - (x3-x2)(y2-y) ) where xi,yi are the coordinates of node i... you will easily find the other interpolation functions h2(x,y) and h3(x,y) in any finite element text book. Then when you get T(x,y) you can easily derive it to obtain the gradient.
I agree, using the shape function is very simple and you can construct also higher order shape functions by exploting suitable manipulation of the linear ones

 leflix July 25, 2012 17:42

Quote:
 Originally Posted by FMDenaro (Post 373566) I agree, using the shape function is very simple and you can construct also higher order shape functions by exploting suitable manipulation of the linear ones
shape function that's it ! Thanx Filippo I missed the word ! ;)

 julien.decharentenay July 25, 2012 21:53

Hi Yu,

The issue you are having is divide a very small number by another very small number, which give you an erroneous answer (due to machine errors).

There are a number of solution:
1 - Use a normalisation factor for your coordinate system;
2 - Maximise the machine precision (run double precision, on a 64bOS and check the compiler options).

Good luck.
Julien

 xiyuqiu July 26, 2012 12:28

Thank you all for your replies. I think the interpolation will help with temperature averaging on each face. However, my problem is even when the temperatures are the same (i.e. no problem with averaging) I got incorrect temperature gradient. I will try what Julien suggested. Thank you to all again for your help.

best,

yu

 praveen July 26, 2012 23:54

Division is a stable operation. You probably have problem with addition/subtraction. If you are computing determinant, you need to be careful. Check that your cell volume is correct. Write the gradient formula in terms of differences of state variables. You should then get zero gradient for a constant data.

 xiyuqiu July 27, 2012 15:57

I think you are right, praveen. It seems when I sum the flux, I should have zero, but instead I got 10^-10, but my volume is in the order of 10^-10. Therefore, I am getting some non-zero gradient. Would you provide a little more details on "write the gradient formula in terms of differences of stat variables"? I am not sure what it is. Thanks!

 praveen July 27, 2012 22:15

The coefficients should sum to zero

If they dont then try to fix it. Its a round off problem, look at how you compute the coefficients and fix the round off issues.

Since the coefficients should sum to zero, you can also write

This gives zero gradients for constant data. You can use this, but first eliminate roundoff errors also.

 xiyuqiu July 30, 2012 14:38

Thank you Praveen! This is pretty much what I have. My coefficients do not add up to zero. I will try to fix the round off problem. Thanks again for your genuine help.

 All times are GMT -4. The time now is 02:20.