# storing coordinates in array of various blocks with different sizes (structured grid)

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

 August 19, 2015, 06:32 storing coordinates in array of various blocks with different sizes (structured grid) #1 Member   Tom-Robin Teschner Join Date: Dec 2011 Location: Cranfield, UK Posts: 65 Rep Power: 5 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?

August 19, 2015, 12:19
#2
Member

Troy Snyder
Join Date: Jul 2009
Location: Akron, OH
Posts: 90
Rep Power: 9
Quote:
 Originally Posted by t.teschner 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 )```

 August 19, 2015, 14:29 #3 Member   Tom-Robin Teschner Join Date: Dec 2011 Location: Cranfield, UK Posts: 65 Rep Power: 5 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.

 August 19, 2015, 14:40 #4 Member   Troy Snyder Join Date: Jul 2009 Location: Akron, OH Posts: 90 Rep Power: 9 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.

 August 19, 2015, 14:48 #5 Member   Tom-Robin Teschner Join Date: Dec 2011 Location: Cranfield, UK Posts: 65 Rep Power: 5 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

 August 20, 2015, 02:53 #6 Senior Member     Alex Join Date: Jun 2012 Location: Germany Posts: 1,134 Rep Power: 19 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```

 August 20, 2015, 04:14 #7 Member   Tom-Robin Teschner Join Date: Dec 2011 Location: Cranfield, UK Posts: 65 Rep Power: 5 I was not aware of derived types in fortran. Will do some reading up and see if I can use this structure, thanks

 Thread Tools Display Modes Linear Mode

 Posting Rules You may not post new threads You may not post replies You may not post attachments You may not edit your posts BB code is On Smilies are On [IMG] code is On HTML code is OffTrackbacks are On Pingbacks are On Refbacks are On Forum Rules

 Similar Threads Thread Thread Starter Forum Replies Last Post shreyasr ANSYS 7 April 13, 2013 09:34 Mirage ANSYS 0 July 18, 2012 09:14 ozzythewise OpenFOAM Paraview & paraFoam 1 June 30, 2010 11:04 Chuck Leakeas Main CFD Forum 2 May 26, 2000 11:18 Tore Myhrvold Main CFD Forum 5 January 21, 1999 09:09

All times are GMT -4. The time now is 21:41.