phdMesh
Version of the Day
|
Multi-dimensional array view of a contiguous block of member data with the array dimension ordinates documented by "tags". More...
Classes | |
class | phdmesh::Array< Scalar, array_order, void, void, void, void, void, void, void, void > |
The not-preferred multi-dimensional Array interface with runtime user-defined dimension ordinates. Typically used when runtime-polymorphic arrays are passed to functions. More... | |
class | phdmesh::ArrayDimTag |
Abstract base class for array dimension tags supplied to the Array template class. More... | |
class | phdmesh::ArrayDimension |
An anonymous array dimension tag, which is NOT the recommended usage. More... | |
class | phdmesh::Array< Scalar, Order, Tag1, Tag2, Tag3, Tag4, Tag5, Tag6, Tag7, Tag8 > |
The preferred multi-dimensional Array interface with compile-time user-defined dimension ordinates. More... | |
Enumerations | |
enum | phdmesh::ArrayOrder { phdmesh::NaturalOrder, phdmesh::FortranOrder, phdmesh::RankZero } |
Define Natural (C-language) or Fortran ordering of array dimensions. A RankZero array does not have an ordering. More... | |
Functions | |
unsigned | phdmesh::array_stride_size (const unsigned rank, const unsigned *const stride) |
Return the total number of members from the array stride. | |
void | phdmesh::array_stride_to_natural_dimensions (const unsigned rank, const unsigned *const stride, unsigned *const dim) |
Generate natural dimension from array stride. | |
void | phdmesh::array_stride_to_natural_indices (const unsigned rank, const unsigned *const stride, const unsigned offset, unsigned *const indices) |
Generate natural indices from array stride. | |
Multi-dimensional array view of a contiguous block of member data with the array dimension ordinates documented by "tags".
Given the user-defined array dimension tags Cartesian3D and Points define a function to find the centroid of an array of points.
void centroid( const Array<double,FortranOrder,Cartesian3D,Points> points , const Array<double,FortranOrder,Cartesian3D> x ) { const unsigned nspace = points.dimension<0>(); const unsigned npoints = points.dimension<1>();
for ( unsigned id = 0 ; ip < npoints ; ++id ) { x(id) = 0 ; } for ( unsigned ip = 0 ; ip < npoints ; ++ip ) { for ( unsigned id = 0 ; id < npoints ; ++id ) { x(id) += points( id , ip ); } } for ( unsigned id = 0 ; ip < npoints ; ++id ) { x(id) /= npoints ; } }
Example of User-defined Array Dimension Tags
struct Cartesian3D : public ArrayDimTag { enum { Size = 3 }; // Default size for this dimension. const char * name() const ; // Supply the pure-virtual function. static const Cartesian3D & tag(); // Runtime singleton for this tag. }; struct Points : public ArrayDimTag { const char * name() const ; // Supply the pure-virtual function. static const Points & tag(); // Runtime singleton for this tag. // NO default Size enumeration. };
Example of Creating an Array
Given a block of memory for the collection of points, wrap it in an Array.
double * chunk = ... ; // Chunk of memory from somewhere unsigned npoints = ... ; // containing a number of points
Array<double,FortranOrder,Cartesian3D,Points> points( chunk , npoints );
The points array has dimension<0> set to Cartesian3D::Size and dimension<1> set to npoints. If the npoints argument where omitted then a compilation error would be generated due to the missing Points::Size enumeration.
enum phdmesh::ArrayOrder |
Define Natural (C-language) or Fortran ordering of array dimensions. A RankZero array does not have an ordering.