CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Main CFD Forum

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

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

Reply
 
LinkBack Thread Tools Display Modes
Old   August 19, 2015, 06:32
Default 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: 80
Rep Power: 6
t.teschner is on a distinguished road
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?
t.teschner is offline   Reply With Quote

Old   August 19, 2015, 12:19
Default
  #2
Senior Member
 
Troy Snyder
Join Date: Jul 2009
Location: Akron, OH
Posts: 120
Rep Power: 10
tas38 is on a distinguished road
Quote:
Originally Posted by t.teschner View Post
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 )
tas38 is offline   Reply With Quote

Old   August 19, 2015, 14:29
Default
  #3
Member
 
Tom-Robin Teschner
Join Date: Dec 2011
Location: Cranfield, UK
Posts: 80
Rep Power: 6
t.teschner is on a distinguished road
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.
t.teschner is offline   Reply With Quote

Old   August 19, 2015, 14:40
Default
  #4
Senior Member
 
Troy Snyder
Join Date: Jul 2009
Location: Akron, OH
Posts: 120
Rep Power: 10
tas38 is on a distinguished road
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.
tas38 is offline   Reply With Quote

Old   August 19, 2015, 14:48
Default
  #5
Member
 
Tom-Robin Teschner
Join Date: Dec 2011
Location: Cranfield, UK
Posts: 80
Rep Power: 6
t.teschner is on a distinguished road
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
t.teschner is offline   Reply With Quote

Old   August 20, 2015, 02:53
Default
  #6
Senior Member
 
flotus1's Avatar
 
Alex
Join Date: Jun 2012
Location: Germany
Posts: 1,242
Rep Power: 22
flotus1 will become famous soon enoughflotus1 will become famous soon enough
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
flotus1 is offline   Reply With Quote

Old   August 20, 2015, 04:14
Default
  #7
Member
 
Tom-Robin Teschner
Join Date: Dec 2011
Location: Cranfield, UK
Posts: 80
Rep Power: 6
t.teschner is on a distinguished road
I was not aware of derived types in fortran. Will do some reading up and see if I can use this structure, thanks
t.teschner is offline   Reply With Quote

Reply

Thread Tools
Display Modes

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 Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Mesh Conversion : structured to unstructured shreyasr ANSYS 7 April 13, 2013 09:34
convert a structured multiblock grid to an one unstructured: modification of cells Mirage ANSYS 0 July 18, 2012 09:14
View grid coordinates in Paraview ozzythewise OpenFOAM Paraview & paraFoam 1 June 30, 2010 11:04
Grid Independent Solution Chuck Leakeas Main CFD Forum 2 May 26, 2000 11:18
Grid generator for structured grids Tore Myhrvold Main CFD Forum 5 January 21, 1999 09:09


All times are GMT -4. The time now is 20:03.