# Fourth Order Central Differencing of Flow Field Data? (Post-Processing)

 Register Blogs Members List Search Today's Posts Mark Forums Read

 December 3, 2019, 15:21 Fourth Order Central Differencing of Flow Field Data? (Post-Processing) #1 New Member   Join Date: Dec 2019 Posts: 13 Rep Power: 5 Hi all! I have been tasked with using a Fourth Order Central Differencing scheme to compute the z-vorticity component (Wz = dv/dx - du/dy) within Matlab; given 3D flow field data for velocities (u,v,w) in a 64^3 point domain plus 4x halo / ghost nodes (2x at the start and 2x at the end) for each dimension. This problem stems from a 3D Taylor Green Vortex simulation for a cube of size 0

 December 3, 2019, 15:33 #2 Member   Join Date: Aug 2018 Posts: 77 Rep Power: 7 Start by looking up a 4th order accurate finite difference stencil. It will involve e.g. points at i,i-1,i+1,... just apply it atvery grid point to approcimate the gradients you need.

December 3, 2019, 15:39
#3
New Member

Join Date: Dec 2019
Posts: 13
Rep Power: 5
Quote:
 Originally Posted by vesp Start by looking up a 4th order accurate finite difference stencil. It will involve e.g. points at i,i-1,i+1,... just apply it atvery grid point to approcimate the gradients you need.

I have the stencil: df/dx ~ {(fi-2)-(8fi-1)+(8fi+1)-(fi+2)}/(12dx).

It is the application of this (and the central differencing methodology) to this problem and within Matlab that I am struggling with...

 December 3, 2019, 15:42 #4 Member   Join Date: Aug 2018 Posts: 77 Rep Power: 7 this is already a central difference, so no need to worry about that aspect anymore. What exactlyare you struggling with? Do you understand how to apply a FD to compute a derivate in 1D?

December 3, 2019, 15:54
#5
New Member

Join Date: Dec 2019
Posts: 13
Rep Power: 5
Quote:
 Originally Posted by vesp this is already a central difference, so no need to worry about that aspect anymore. What exactlyare you struggling with? Do you understand how to apply a FD to compute a derivate in 1D?
I'm unsure how to apply this scheme to my data (velocity flow field in 3D) to achieve the Z vorticity field. I'm assuming the method is to derive velocity gradient at each node using the scheme (dv/dx and du/dy) but I'm uncertain how to initialise and compute this in Matlab given the information above.

 December 3, 2019, 15:59 Fourth Order Central Differencing of Flow Field Data? (Post-Processing) #6 Member   Join Date: Aug 2018 Posts: 77 Rep Power: 7 yes, just compute dv/dx by applying it to the field in the x-direction and to u in the y-direction. just loop over all points, you have a structured grid so this is really easy... still not sure what you are struggling with... example: outer loop over all ijk, inner loop 1: i-2 to i+2, compute dv/dx inner loop 2: j-2 to j+2, compute du/dy add at each ijk done

December 3, 2019, 16:08
#7
New Member

Join Date: Dec 2019
Posts: 13
Rep Power: 5
Quote:
 Originally Posted by vesp yes, just compute dv/dx by applying it to the field in the x-direction and to u in the y-direction. just loop over all points, you have a structured grid so this is really easy... still not sure what you are struggling with... example: outer loop over all ijk, inner loop 1: i-2 to i+2, compute dv/dx inner loop 2: j-2 to j+2, compute du/dy add at each ijk done

Do I not need to initialise the boundary conditions before looping the scheme through the points? Is the scheme calculating the velocity gradient from upwind / downstream velocity components (which I already have) or the neighbouring gradients calculated through the loop?

 December 3, 2019, 16:11 #8 Member   Join Date: Aug 2018 Posts: 77 Rep Power: 7 sure. you should fill the ghostcells first, so you can apply the stencil at the boundary points. not sure what you mean by the second part...

 December 4, 2019, 04:49 #9 Senior Member     Paolo Lampitella Join Date: Mar 2009 Location: Italy Posts: 2,124 Blog Entries: 29 Rep Power: 38 You have all the pieces, what we could add is just actually doing it for you... but this looks a lot like a homework. And even if it isn't, you really need to figure this out by yourself. Still... you need to first copy your periodic data in the right ghost cells. For example, the data in the plane at nx+1 needs to be copied in the plane at 0. Those in the plane at nx+2 has to be copied in the plane at -1. Same for the other directions. I obviously don't know the actual indexing of your ghost planes in the code, so you need to figure out this by yourself, mine was just an example. Once this is done, you can loop on all interior i,j,k (no ghosts) and straighforwardly use the derivative formula. Actually, in MATLAB there are more correct ways to do that, involving vectorization, and are also trivial for this structured case. But would leave that for the future. FMDenaro likes this.

 December 5, 2019, 18:45 #10 Member   Join Date: Aug 2018 Posts: 77 Rep Power: 7 did you figure it out?

December 6, 2019, 01:57
#11
Senior Member

Arjun
Join Date: Mar 2009
Location: Nurenberg, Germany
Posts: 1,249
Rep Power: 31
Quote:
 Originally Posted by sbro Hi all! I have been tasked with using a Fourth Order Central Differencing scheme to compute the z-vorticity component (Wz = dv/dx - du/dy) within Matlab; given 3D flow field data for velocities (u,v,w) in a 64^3 point domain plus 4x halo / ghost nodes (2x at the start and 2x at the end) for each dimension. This problem stems from a 3D Taylor Green Vortex simulation for a cube of size 0

Construct proper number of points at the boundary. For fourth order you will need two points at the boundary. Since you are in periodic condition, fill these two points values by copy from the other side of domain.

Now using fourth order central differencing formula compute the gradients.

Using these gradients compute the term that you need to compute.

PS: if you are asked to use 4rth order compact then you would have to solve tri diagonal equations obtaining these gradients (look in literature).

December 6, 2019, 13:23
#12
New Member

Join Date: Dec 2019
Posts: 13
Rep Power: 5
Quote:
 Originally Posted by vesp did you figure it out?
Yes, I got there in the end. As you said, I was confusing myself and it was a more simple problem than I was making it.

Thanks again!

 December 6, 2019, 13:24 #13 Member   Join Date: Aug 2018 Posts: 77 Rep Power: 7 great, glad to help!