CFD Online Discussion Forums

CFD Online Discussion Forums (https://www.cfd-online.com/Forums/)
-   Main CFD Forum (https://www.cfd-online.com/Forums/main/)
-   -   storing coordinates in array of various blocks with different sizes (structured grid) (https://www.cfd-online.com/Forums/main/158242-storing-coordinates-array-various-blocks-different-sizes-structured-grid.html)

t.teschner August 19, 2015 06:32

storing coordinates in array of various blocks with different sizes (structured grid)
 
hey there,
I am currently developing a structured mesh based solver with curve linear coordinates and hence my mesh is composed of various blocks. I am wondering how to best store the coordinates (in fortran). If the number of points per block in x and y (in 2d) would be the same for all blocks, it would be straight forward and I would have something like coordinateX(nblocks,nx,ny) but what happens if I have blocks of different sizes? I can't declare enough arrays before hand (like coordinateX1, coordinateX2, coordinate X3 ...) as that would limit the number of blocks per mesh, I also don't want to declare the array with the maximum number of points in x and y as I would waste a lot of computer resources. I'd like to stick with fortran for this problem but I know that in C/C++ it would have been a no brainer (but not an option at the moment).
any ideas?

tas38 August 19, 2015 12:19

Quote:

Originally Posted by t.teschner (Post 560172)
hey there,
I am currently developing a structured mesh based solver with curve linear coordinates and hence my mesh is composed of various blocks. I am wondering how to best store the coordinates (in fortran). If the number of points per block in x and y (in 2d) would be the same for all blocks, it would be straight forward and I would have something like coordinateX(nblocks,nx,ny) but what happens if I have blocks of different sizes? I can't declare enough arrays before hand (like coordinateX1, coordinateX2, coordinate X3 ...) as that would limit the number of blocks per mesh, I also don't want to declare the array with the maximum number of points in x and y as I would waste a lot of computer resources. I'd like to stick with fortran for this problem but I know that in C/C++ it would have been a no brainer (but not an option at the moment).
any ideas?

Is there any issue simply making the arrays allocatable? Then you can declare their
size and de-allocate as needed.

An example...

Code:

integer,parameter:: prec=selected_real_kind(15,307)
real(kind=prec),dimension(:,:,:),allocatable:: coordinateX

...some code...

allocate( coordinateX(nx,ny,nz) )

...some code making use of coordinateX...

deallocate( coordinateX )


t.teschner August 19, 2015 14:29

no, the problem is that nx, ny and nz are different for each block. you could declare one new array for each block but then you would need to know how many blocks you have in advance which somewhat limits you (as stated before).

but i found a solution that is working for me now which comes from unstructured grids (where i feel more comfortable) by having 3 arrays, i.e. coordinateX, coordinateY and coordinateZ where I store all the x,y and z coordinates of all the blocks. that means that these 3 arrays do not necessarily have the same length. then i have a helper array which states from where to where each block is placed inside the coordinate arrays. for example i could have coordinateX = [ 1 0 0 2 0 0 ] and helper(1,1) = 1, helper(1,2) = 3 and helper(2,1) = 4, helper(2,2) = 6. in this case i have two blocks, the first one goes from element 1 to 3 and the second block goes from 4-6. not the most elegant way i find but maybe someone comes up with a better solution. i just put it here in detail in case someone is coming across the same problem and can live with this fix.

tas38 August 19, 2015 14:40

Ok, now I see the issue.

Your solution sounds very similar to the method employed in the Ferziger and Peric
book. Therein all data is stored in 1D arrays with an appropriate indexing function that
incorporates a block identifier, and the i,j,k indices of block of interest. In your case,
the indexing function could simply evolve as the blocks are created rather than be
set a priori.

t.teschner August 19, 2015 14:48

yeah, well, if ferziger and peric are using the same approach, I can't be that much off I guess. I got it from the book of Rainald Löhner (applied cfd techniques) but as I said in the context of unstructured grids. But I guess I have to put up with those more cumbersome datastructure

flotus1 August 20, 2015 02:53

How about using allocatable arrays of derived types in fortran?
Something like this...

Code:

TYPE :: positions
    REAL(DP), DIMENSION(3) :: pos
END TYPE positions

TYPE :: points
  TYPE(positions), DIMENSION(:), ALLOCATABLE :: point
END TYPE points

TYPE(points), DIMENSION(:), ALLOCATABLE :: block


t.teschner August 20, 2015 04:14

I was not aware of derived types in fortran. Will do some reading up and see if I can use this structure, thanks


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