MFEM v4.9.0
Finite element discretization library
Loading...
Searching...
No Matches
mfem::Array2D< T > Class Template Reference

Dynamic 2D array using row-major layout. More...

#include <array.hpp>

Public Member Functions

 Array2D ()
 
 Array2D (int m, int n)
 Construct an m x n 2D array.
 
 Array2D (const Array2D &)=default
 
 Array2D (Array2D &&)=default
 
void SetSize (int m, int n)
 Set the 2D array size to m x n.
 
int NumRows () const
 
int NumCols () const
 
const T & operator() (int i, int j) const
 
T & operator() (int i, int j)
 
const T * operator[] (int i) const
 
T * operator[] (int i)
 
const T * operator() (int i) const
 
T * operator() (int i)
 
const T * GetRow (int i) const
 
T * GetRow (int i)
 
void GetRow (int i, Array< T > &sa) const
 Extract a copy of the i-th row into the Array sa.
 
void Save (std::ostream &os, int fmt=0) const
 Save the Array2D to the stream out using the format fmt.
 
void Load (std::istream &in, int fmt=0)
 Read an Array2D from the stream in using format fmt.
 
void Load (const char *filename, int fmt=0)
 Read an Array2D from a file.
 
void Load (int new_size0, int new_size1, std::istream &in)
 Set the Array2D dimensions to new_size0 x new_size1 and read that many entries from the stream in.
 
void Copy (Array2D &copy) const
 
void operator= (const T &a)
 Set all entries of the array to the provided constant.
 
Array2Doperator= (const Array2D &)=default
 Copy assignment.
 
Array2Doperator= (Array2D &&)=default
 Move assignment.
 
void Swap (Array2D &other)
 Swap the contents of the Array2D with other.
 
void MakeRef (const Array2D &master)
 Make this Array2D a reference to 'master'.
 
void DeleteAll ()
 Delete all dynamically allocated memory, resetting all dimensions to zero.
 
void Print (std::ostream &out=mfem::out, int width=4)
 Prints array to stream with width elements per row.
 
Max () const
 Find the maximal element in the array, using the comparison operator < for class T.
 
Min () const
 Find the minimal element in the array, using the comparison operator < for class T.
 

Detailed Description

template<class T>
class mfem::Array2D< T >

Dynamic 2D array using row-major layout.

Definition at line 429 of file array.hpp.

Constructor & Destructor Documentation

◆ Array2D() [1/4]

template<class T >
mfem::Array2D< T >::Array2D ( )
inline

Definition at line 436 of file array.hpp.

◆ Array2D() [2/4]

template<class T >
mfem::Array2D< T >::Array2D ( int m,
int n )
inline

Construct an m x n 2D array.

Definition at line 439 of file array.hpp.

◆ Array2D() [3/4]

template<class T >
mfem::Array2D< T >::Array2D ( const Array2D< T > & )
default

◆ Array2D() [4/4]

template<class T >
mfem::Array2D< T >::Array2D ( Array2D< T > && )
default

Member Function Documentation

◆ Copy()

template<class T >
void mfem::Array2D< T >::Copy ( Array2D< T > & copy) const
inline

Definition at line 501 of file array.hpp.

◆ DeleteAll()

template<class T >
void mfem::Array2D< T >::DeleteAll ( )
inline

Delete all dynamically allocated memory, resetting all dimensions to zero.

Definition at line 523 of file array.hpp.

◆ GetRow() [1/3]

template<class T >
T * mfem::Array2D< T >::GetRow ( int i)
inline

Definition at line 460 of file array.hpp.

◆ GetRow() [2/3]

template<class T >
const T * mfem::Array2D< T >::GetRow ( int i) const
inline

Definition at line 459 of file array.hpp.

◆ GetRow() [3/3]

template<class T >
void mfem::Array2D< T >::GetRow ( int i,
Array< T > & sa ) const
inline

Extract a copy of the i-th row into the Array sa.

Definition at line 463 of file array.hpp.

◆ Load() [1/3]

template<class T >
void mfem::Array2D< T >::Load ( const char * filename,
int fmt = 0 )

Read an Array2D from a file.

Definition at line 174 of file array.cpp.

◆ Load() [2/3]

template<class T >
void mfem::Array2D< T >::Load ( int new_size0,
int new_size1,
std::istream & in )
inline

Set the Array2D dimensions to new_size0 x new_size1 and read that many entries from the stream in.

Definition at line 498 of file array.hpp.

◆ Load() [3/3]

template<class T >
void mfem::Array2D< T >::Load ( std::istream & in,
int fmt = 0 )
inline

Read an Array2D from the stream in using format fmt.

The format fmt can be:

  • 0 - read the number of rows and columns, then the entries
  • 1 - read NumRows() x NumCols() entries, using row-major layout

Definition at line 487 of file array.hpp.

◆ MakeRef()

template<class T >
void mfem::Array2D< T >::MakeRef ( const Array2D< T > & master)
inline

Make this Array2D a reference to 'master'.

Definition at line 519 of file array.hpp.

◆ Max()

template<class T >
T mfem::Array2D< T >::Max ( ) const
inline

Find the maximal element in the array, using the comparison operator < for class T.

Definition at line 530 of file array.hpp.

◆ Min()

template<class T >
T mfem::Array2D< T >::Min ( ) const
inline

Find the minimal element in the array, using the comparison operator < for class T.

Definition at line 534 of file array.hpp.

◆ NumCols()

template<class T >
int mfem::Array2D< T >::NumCols ( ) const
inline

Definition at line 448 of file array.hpp.

◆ NumRows()

template<class T >
int mfem::Array2D< T >::NumRows ( ) const
inline

Definition at line 447 of file array.hpp.

◆ operator()() [1/4]

template<class T >
T * mfem::Array2D< T >::operator() ( int i)
inline

Definition at line 457 of file array.hpp.

◆ operator()() [2/4]

template<class T >
const T * mfem::Array2D< T >::operator() ( int i) const
inline

Definition at line 456 of file array.hpp.

◆ operator()() [3/4]

template<class T >
T & mfem::Array2D< T >::operator() ( int i,
int j )
inline

Definition at line 1129 of file array.hpp.

◆ operator()() [4/4]

template<class T >
const T & mfem::Array2D< T >::operator() ( int i,
int j ) const
inline

Definition at line 1119 of file array.hpp.

◆ operator=() [1/3]

template<class T >
Array2D & mfem::Array2D< T >::operator= ( Array2D< T > && )
default

Move assignment.

◆ operator=() [2/3]

template<class T >
Array2D & mfem::Array2D< T >::operator= ( const Array2D< T > & )
default

Copy assignment.

◆ operator=() [3/3]

template<class T >
void mfem::Array2D< T >::operator= ( const T & a)
inline

Set all entries of the array to the provided constant.

Definition at line 504 of file array.hpp.

◆ operator[]() [1/2]

template<class T >
T * mfem::Array2D< T >::operator[] ( int i)
inline

Definition at line 1148 of file array.hpp.

◆ operator[]() [2/2]

template<class T >
const T * mfem::Array2D< T >::operator[] ( int i) const
inline

Definition at line 1139 of file array.hpp.

◆ Print()

template<class T >
void mfem::Array2D< T >::Print ( std::ostream & out = mfem::out,
int width = 4 )

Prints array to stream with width elements per row.

Definition at line 184 of file array.cpp.

◆ Save()

template<class T >
void mfem::Array2D< T >::Save ( std::ostream & os,
int fmt = 0 ) const
inline

Save the Array2D to the stream out using the format fmt.

The format fmt can be:

  • 0 - write the number of rows and columns, followed by all entries
  • 1 - write only the entries, using row-major layout

Definition at line 475 of file array.hpp.

◆ SetSize()

template<class T >
void mfem::Array2D< T >::SetSize ( int m,
int n )
inline

Set the 2D array size to m x n.

Definition at line 445 of file array.hpp.

◆ Swap()

template<class T >
void mfem::Array2D< T >::Swap ( Array2D< T > & other)
inline

Swap the contents of the Array2D with other.

Implemented without using move assignment, avoiding some unnecessary calls.

Definition at line 1157 of file array.hpp.


The documentation for this class was generated from the following files: