CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   Calculate derivatives in a non-uniform grid (https://www.cfd-online.com/Forums/main/219587-calculate-derivatives-non-uniform-grid.html)

Moreza7 August 1, 2019 07:08

Calculate derivatives in a non-uniform grid
 
I have a non-uniform 2D grid (non-equal intervals between nodes). [x,y]
I also have the data (U) calculated on this grid.
I want to calculate the derivatives of U with respect to y and then x.

How can I do this? (Specially using MATLAB)

Светлана August 1, 2019 07:17

Is it rectangular grid?



You could just use matrix operations ie


dmyfdx = (myf(2:end)-myf(1:end-1)) / (coordx(2:end)-coordx(1:end-1))


where myf is your variable and coordx is the x coordinate in the grid. If this is not sufficiently helpful then please create a small test case demonstrating the data format in a small example. Thanks.

Moreza7 August 1, 2019 07:45

Quote:

Originally Posted by Светлана (Post 740721)
Is it rectangular grid?



You could just use matrix operations ie


dmyfdx = (myf(2:end)-myf(1:end-1)) / (coordx(2:end)-coordx(1:end-1))


where myf is your variable and coordx is the x coordinate in the grid. If this is not sufficiently helpful then please create a small test case demonstrating the data format in a small example. Thanks.

Yes, it is rectangular ,but your solution is only useful for first order - first derivative. How about second order and second derivative?

Светлана August 1, 2019 17:17

I think you can view the formulas here


http://web.media.mit.edu/~crtaylor/calculator.html


Vary the number of input points to get the desired order of accuracy.

FMDenaro August 1, 2019 17:39

Quote:

Originally Posted by Moreza7 (Post 740726)
Yes, it is rectangular ,but your solution is only useful for first order - first derivative. How about second order and second derivative?




For example, you have the value f1,f2,f3 at x1,x2,x3. Then you can define a lagrangian second degree polynomial and compute analytically the derivative. More nodes allow you to increase the degree of the polynomial and the accuracy of the derivative.


Have also a look to the textbook of Peric & Ferziger

Moreza7 August 2, 2019 01:23

Quote:

Originally Posted by Светлана (Post 740791)
I think you can view the formulas here


http://web.media.mit.edu/~crtaylor/calculator.html


Vary the number of input points to get the desired order of accuracy.

Thank you ,but this is for uniform grids.


All times are GMT -4. The time now is 17:22.