CFD Online Logo CFD Online URL
www.cfd-online.com
[Sponsors]
Home > Forums > Software User Forums > OpenFOAM > OpenFOAM Programming & Development

How would you dynamically allocate higher order arrays in OF?

Register Blogs Community New Posts Updated Threads Search

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old   February 2, 2015, 09:50
Default How would you dynamically allocate higher order arrays in OF?
  #1
Member
 
Rudolf Hellmuth
Join Date: Sep 2012
Location: Dundee, Scotland
Posts: 40
Rep Power: 13
rudolf.hellmuth is on a distinguished road
Hallo,

I need to allocate higher order arrays in OF, like 3D, 4D large matrices. I couldn't find any native OF class that do that. For 1D arrays I am using PtrList. In the case of 3rd order array, is it possible to use?:
Code:
PtrList<PtrList<PtrList<scalar>>>> array;
array.setSize[sizeX];
forAll(array, i)
{
    array[i].setSize[sizeY];
    forAll(array[i], j)
    {
        array[i][j].setSize[sizeZ];
    }
}
Is this safe in terms of memory leak? The member function PtrList::set would act funny, wouldn't it?

Or should I ratter allocate in a standard way?

Code:
scalar*** array;
array = new scalar**[sizeX];
for(int i = 0; i < sizeX; ++i)
{
     array[i] = new scalar*[sizeY];
     for(int j = 0; j < sizeY; ++j)
     {
          array[i][j] = new scalar[sizeZ];
     }
}
Then deallocate the array within delete loop in the class destructor.

How would you rather do that?

Best regards,
Rudolf
rudolf.hellmuth is offline   Reply With Quote

Reply


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
higher order discretisation scheme Simon Smokes Main CFD Forum 2 August 23, 2014 07:19
Higher order discretization on staggered grid Chandra Shekhar Main CFD Forum 9 January 27, 2005 16:31
Higher Order FV Schemes for unstructured meshes Apurva Shukla Main CFD Forum 4 December 15, 2000 09:17
Gradient Estimation for Higher Order Schemes jianxia Main CFD Forum 0 June 6, 2000 19:40
Higher order FVM Sergey Smirnov Main CFD Forum 10 April 15, 2000 01:49


All times are GMT -4. The time now is 09:58.