|
| CHArray () |
| Default constructor. More...
|
|
| CHArray (const DimT &dim6, const DimT &dim5, const DimT &dim4, const DimT &dim3, const DimT &dim2, const DimT &dim1, const DimT &dim0) |
| Construct with dimensions. More...
|
|
| CHArray (const DimT &dim5, const DimT &dim4, const DimT &dim3, const DimT &dim2, const DimT &dim1, const DimT &dim0) |
|
| CHArray (const DimT &dim4, const DimT &dim3, const DimT &dim2, const DimT &dim1, const DimT &dim0) |
|
| CHArray (const DimT &dim3, const DimT &dim2, const DimT &dim1, const DimT &dim0) |
|
| CHArray (const DimT &dim2, const DimT &dim1, const DimT &dim0) |
|
| CHArray (const DimT &dim1, const DimT &dim0) |
|
| CHArray (const DimT &dim0) |
|
| CHArray (const IntVect &iv, const DimT &dimc1, const DimT &dimc0) |
|
| CHArray (const IntVect &iv, const DimT &dimc0) |
|
| CHArray (const DimT &dimc1, const DimT &dimc0, const IntVect &iv) |
|
| CHArray (const DimT &dimc0, const IntVect &iv) |
|
| CHArray (const Box &box, const DimT &dimc1, const DimT &dimc0) |
|
| CHArray (const Box &box, const DimT &dimc0) |
|
| CHArray (const DimT &dimc1, const DimT &dimc0, const Box &box) |
|
| CHArray (const DimT &dimc0, const Box &box) |
|
void | define (const DimT &dim6, const DimT &dim5, const DimT &dim4, const DimT &dim3, const DimT &dim2, const DimT &dim1, const DimT &dim0) |
| Define the dimensions. More...
|
|
void | define (const DimT &dim5, const DimT &dim4, const DimT &dim3, const DimT &dim2, const DimT &dim1, const DimT &dim0) |
|
void | define (const DimT &dim4, const DimT &dim3, const DimT &dim2, const DimT &dim1, const DimT &dim0) |
|
void | define (const DimT &dim3, const DimT &dim2, const DimT &dim1, const DimT &dim0) |
|
void | define (const DimT &dim2, const DimT &dim1, const DimT &dim0) |
|
void | define (const DimT &dim1, const DimT &dim0) |
|
void | define (const DimT &dim0) |
|
void | define (const IntVect &iv, const DimT &dimc1, const DimT &dimc0) |
|
void | define (const IntVect &iv, const DimT &dimc0) |
|
void | define (const DimT &dimc1, const DimT &dimc0, const IntVect &iv) |
|
void | define (const DimT &dimc0, const IntVect &iv) |
|
void | define (const Box &box, const DimT &dimc1, const DimT &dimc0) |
|
void | define (const Box &box, const DimT &dimc0) |
|
void | define (const DimT &dimc1, const DimT &dimc0, const Box &box) |
|
void | define (const DimT &dimc0, const Box &box) |
|
void | define (void *const addr, const DimT &dim6, const DimT &dim5, const DimT &dim4, const DimT &dim3, const DimT &dim2, const DimT &dim1, const DimT &dim0) |
| Define the dimensions and allocate on 'addr'. More...
|
|
void | define (void *const addr, const DimT &dim5, const DimT &dim4, const DimT &dim3, const DimT &dim2, const DimT &dim1, const DimT &dim0) |
|
void | define (void *const addr, const DimT &dim4, const DimT &dim3, const DimT &dim2, const DimT &dim1, const DimT &dim0) |
|
void | define (void *const addr, const DimT &dim3, const DimT &dim2, const DimT &dim1, const DimT &dim0) |
|
void | define (void *const addr, const DimT &dim2, const DimT &dim1, const DimT &dim0) |
|
void | define (void *const addr, const DimT &dim1, const DimT &dim0) |
|
void | define (void *const addr, const DimT &dim0) |
|
void | define (void *const addr, const IntVect &iv, const DimT &dimc1, const DimT &dimc0) |
|
void | define (void *const addr, const IntVect &iv, const DimT &dimc0) |
|
void | define (void *const addr, const DimT &dimc1, const DimT &dimc0, const IntVect &iv) |
|
void | define (void *const addr, const DimT &dimc0, const IntVect &iv) |
|
void | define (void *const addr, const Box &box, const DimT &dimc1, const DimT &dimc0) |
|
void | define (void *const addr, const Box &box, const DimT &dimc0) |
|
void | define (void *const addr, const DimT &dimc1, const DimT &dimc0, const Box &box) |
|
void | define (void *const addr, const DimT &dimc0, const Box &box) |
|
void | undefine () |
| Deallocate the array. More...
|
|
template<typename T2 > |
CHArray & | operator= (const T2 &val) |
| Assign a constant to the array. More...
|
|
T & | operator() (const ArSp::IIx_t i6, const ArSp::IIx_t i5, const ArSp::IIx_t i4, const ArSp::IIx_t i3, const ArSp::IIx_t i2, const ArSp::IIx_t i1, const ArSp::IIx_t i0) |
| Access an element. More...
|
|
T & | operator() (const ArSp::IIx_t i5, const ArSp::IIx_t i4, const ArSp::IIx_t i3, const ArSp::IIx_t i2, const ArSp::IIx_t i1, const ArSp::IIx_t i0) |
|
T & | operator() (const ArSp::IIx_t i4, const ArSp::IIx_t i3, const ArSp::IIx_t i2, const ArSp::IIx_t i1, const ArSp::IIx_t i0) |
|
T & | operator() (const ArSp::IIx_t i3, const ArSp::IIx_t i2, const ArSp::IIx_t i1, const ArSp::IIx_t i0) |
|
T & | operator() (const ArSp::IIx_t i2, const ArSp::IIx_t i1, const ArSp::IIx_t i0) |
|
T & | operator() (const ArSp::IIx_t i1, const ArSp::IIx_t i0) |
|
T & | operator() (const ArSp::IIx_t i0) |
|
T & | operator() (const IntVect &iv, const ArSp::IIx_t c1, const ArSp::IIx_t c0) |
|
T & | operator() (const IntVect &iv, const ArSp::IIx_t c0) |
|
T & | operator() (const ArSp::IIx_t c1, const ArSp::IIx_t c0, const IntVect &iv) |
|
T & | operator() (const ArSp::IIx_t c0, const IntVect &iv) |
|
const T & | operator() (const ArSp::IIx_t i6, const ArSp::IIx_t i5, const ArSp::IIx_t i4, const ArSp::IIx_t i3, const ArSp::IIx_t i2, const ArSp::IIx_t i1, const ArSp::IIx_t i0) const |
| Constant access to an element. More...
|
|
const T & | operator() (const ArSp::IIx_t i5, const ArSp::IIx_t i4, const ArSp::IIx_t i3, const ArSp::IIx_t i2, const ArSp::IIx_t i1, const ArSp::IIx_t i0) const |
|
const T & | operator() (const ArSp::IIx_t i4, const ArSp::IIx_t i3, const ArSp::IIx_t i2, const ArSp::IIx_t i1, const ArSp::IIx_t i0) const |
|
const T & | operator() (const ArSp::IIx_t i3, const ArSp::IIx_t i2, const ArSp::IIx_t i1, const ArSp::IIx_t i0) const |
|
const T & | operator() (const ArSp::IIx_t i2, const ArSp::IIx_t i1, const ArSp::IIx_t i0) const |
|
const T & | operator() (const ArSp::IIx_t i1, const ArSp::IIx_t i0) const |
|
const T & | operator() (const ArSp::IIx_t i0) const |
|
const T & | operator() (const IntVect &iv, const ArSp::IIx_t c1, const ArSp::IIx_t c0) const |
|
const T & | operator() (const IntVect &iv, const ArSp::IIx_t c0) const |
|
const T & | operator() (const ArSp::IIx_t c1, const ArSp::IIx_t c0, const IntVect &iv) const |
|
const T & | operator() (const ArSp::IIx_t c0, const IntVect &iv) const |
|
Alloc & | getAllocator () |
| Get the allocator. More...
|
|
T * | begin () |
| Access extents of the memory allocated for the array. More...
|
|
const T * | begin () const |
|
T * | end () |
|
const T * | end () const |
|
ArSp::USz_t | size () const |
| Overall size of the array. More...
|
|
ArSp::USz_t | size (const unsigned dim) const |
| Size of a dimension (0 is dimension with contiguous storage) More...
|
|
ArSp::IIx_t | lowerBound (const unsigned dim) const |
| Lower bound of a dimension (0 is dimension with contiguous storage) More...
|
|
ArSp::IIx_t | upperBound (const unsigned dim) const |
| Upper bound of a dimension (0 is dimension with contiguous storage) More...
|
|
ArSp::IIx_t | totalOffset () const |
| Offset from non-zero lower bound. More...
|
|
bool | isAllocated () const |
| Memory has been allocated. More...
|
|
bool | isUsable () const |
| Memory has been allocated and size is > 0. More...
|
|
template<typename T, unsigned Rank, int ArConf, typename Alloc>
class CHArray< T, Rank, ArConf, Alloc >
Multidimensional array class.
- Template Parameters
-
T | Type of element |
Rank | Rank of the array |
ArConf | Configuration of the indexing. Allowable values are: ArZeroRow - Row-ordered indexing with lower bound = 0 ArZeroCol - Column-ordered indexing with lower bound = 0 (DEFAULT) ArRangeRow - Row-ordered indexing with subscript ranges ArRangeCol - Column-ordered indexing with subscript ranges |
Alloc | Allocator for the array |
- Note
-
Default template arguments specify column-ordered arrays since it is expected that this class will be mostly used as storage for data used in Fortran routines.
-
When an assertion fails, note that the indexers label the contiguous dimension as i0 or dim0 and the others from there. This class labels all dimensions assuming row-ordered (C) storage.
-
Currently supports up to rank 7, matching the maximum permitted by the Fortran 2003 standard (the 2008 standard extends this to 15 and this class will be extended once that is commonplace). With IntVects or Boxes used to specify some of the dimensions, 2 extra dimensions are supported, allowing a matrix in each cell. This implies a rank of SpaceDim+2 so you can only add 1 extra dimension if you want to support SpaceDim=6.
-
Empty base-class optimizations are frequently used. On 32-bit arch, sizeof(CHArray<int, 1, ArZeroRow, ArSp::NewArrayAlloc<int> >) = 8 sizeof(CHArray<int, 2, ArZeroRow, ArSp::NewArrayAlloc<int> >) = 12
-
There is support for passing these arrays to Fortran – see Chombo design doc
-
CHMatrix will define a real, rank 2, column-ordered matrix
-
You can also allocate an array of matrices, continguous in memory, using the ArrayOfMatrixAlloc allocator.
Example
*
* CHArray<int, 3> A(2, 2, 2);
* A = 2;
* A(0, 0, 0) = 4;
* std::cout << A << std::endl;
* CHArray<double, 2> B;
* B.define(3, 4);
* B(2, 3) = 5.5;
*
One can also use subscript ranges but the array has to be configured to support this. Ranges are specified with CHRange in place of a size. Any integer types are converted to CHRange(0, int-1). E.g.,
* CHArray<int, 3, ArRangeRow> C(CHRange(-1,0), 2, 2);
* C = 2;
* C(-1, 0, 0) = 4;
*
IntVects are allowed for specifying some of the dimensions so that this class can be used with boxes, e.g:
*
* CHArray<int, SpaceDim+1> A(box.size(), 1)
*
The indices of the IntVect are rearranged so that the first index is always closest to contiguous memory no matter if the actual memory layout is row- ordered or column-ordered. In other words, the first index of the IntVect always has the lowest stride. As such, the allocated memory can be accessed by iterating over the box in Chombo Fortran. Whether the remaining indices (or components) are left or right of the IntVect and the storage order determine if the components are distributed across the IntVects (like with a BaseFab) or are contiguous in each IntVect. The effect is natural; for row storage, components on the right will lead to contigous memory. E.g.,
* typedef CHArray<int, SpaceDim+1, ArZeroRow> CHArrayRS;
* typedef CHArray<int, SpaceDim+1, ArZeroCol> CHArrayCS;
* const IntVect iv(2, 2);
* CHArrayRS ARS_IVComp(iv, 2);
* CHArrayRS ARS_CompIV(2, iv);
* CHArrayCS ACS_IVComp(iv, 2);
* CHArrayCS ACS_CompIV(2, iv);
* int ic = 1;
* for (int j = 0; j != 2; ++j)
* for (int i = 0; i != 2; ++i) // Column storage!
* {
* const IntVect ixv(i, j);
* ARS_IVComp(ixv, 0) = ic;
* ARS_IVComp(ixv, 1) = -ic;
* ARS_CompIV(0, ixv) = ic;
* ARS_CompIV(1, ixv) = -ic;
* ACS_IVComp(ixv, 0) = ic;
* ACS_IVComp(ixv, 1) = -ic;
* ACS_CompIV(0, ixv) = ic;
* ACS_CompIV(1, ixv) = -ic;
* ++ic;
* }
*
* std::cout << "ARS_IVComp: " << ARS_IVComp << std::endl;
* std::cout << "ARS_CompIV: " << ARS_CompIV << std::endl;
* std::cout << "ACS_IVComp: " << ACS_IVComp << std::endl;
* std::cout << "ACS_CompIV: " << ACS_CompIV << std::endl;
*
will produce
* $ ARS_IVComp: 1 -1 2 -2 3 -3 4 -4
* $ ARS_CompIV: 1 2 3 4 -1 -2 -3 -4
* $ ACS_IVComp: 1 2 3 4 -1 -2 -3 -4
* $ ACS_CompIV: 1 -1 2 -2 3 -3 4 -4
*
Note that the IntVects simply expand to dimensions and there is nothing to ensure that you access in the array in the same manner you defined it (i.e., switching the order of the IntVect and the component)!
IntVects are always zero-based and there is no way to specify a range of IntVects. However, one can use Boxes instead of IntVects to define the array but only if the array is configured with subscript ranges (ArConf = ArRangeRow or ArRangeCol)
* Box box(IntVect(-1,-1), IntVect(1, 1));
* CHArray<int, SpaceDim+1, ArRangeRow> AB(box, 2);
* AB = 1;
* AB(IntVect(-1, -1), 0) = 2;
* std::cout << AB << std::endl;
*