JuliaIBPM/ViscousFlow.jl

Fields output incorrect dimensions

michaeljehan opened this issue · 4 comments

I am trying to extract the velocity and pressure fields as a 2D array, the system has a 78 x 78 grid, yet it produces a 77×78 array for u velocity, 78 x 77 array for v velocity, and 77 x 77 array for pressure
Screen Shot 2022-01-06 at 10 51 24 PM
Screen Shot 2022-01-06 at 10 51 56 PM
Screen Shot 2022-01-06 at 10 52 20 PM
any idea on how to get it to output as 78 x 78?

The computational method relies on a staggered grid, so all of these quantities "live" at different places. u sits on the vertical edges of the cells, v sits on the horizontal edges of the cells --- collectively, these are Edges{Primal} --- and pressure sits at the center of the cells (Nodes{Primal}). The size 78 x 78 is the number of corners of the cells (Nodes{Dual}) in the grid. Each of the other data types is smaller in at least one dimension.

Why do you need for them to all be the same size array?

I am trying to use the u, v, and p data as input for deep learning training where x and y acts as inputs, and the u, v, and p values are the output. the u,v, and p need to correspond the x,y positions for the training to work.

You can use grid_interpolate! for that, e.g., to force everything to live at the cell centers (where pressure already lives), then:

uc, vc = similar(p), similar(p)
grid_interpolate!(uc,vel.u)
grid_interpolate!(vc,vel.v)

Now, uc and vc are interpolated onto the cell centers. (I've assumed here that p is pressure and vel is the original velocity.)

You can get the x and y coordinates of the cell centers with the coordinates function,

xc, yc = coordinates(p,sys.grid)

I'll give it a try, Thank you so much