Skip to content

Class mgrid::Field2D

ClassList > mgrid > Field2D

More...

  • #include <field.hpp>

Public Functions

Type Name
Field2D () = default
Constructs an empty field (zero rows, zero columns).
Field2D (int nx, int nz)
Constructs an nx bynz field with every element zero.
int cols () noexcept const
Number of columns.
Field2D copy () const
Returns an independent, deep copy of this field.
double * data () noexcept
Pointer to the contiguous row-major element storage.
const double * data () noexcept const
Pointer to the contiguous row-major element storage.
void fill (double value)
Sets every element to value .
double & operator() (int i, int j)
Accesses the element at row i , columnj .
double operator() (int i, int j) const
Reads the element at row i , columnj .
Field2D & operator*= (double s)
Multiplies every element by the scalar s .
Field2D & operator*= (const Field2D & o)
Element-wise multiplies by o .
Field2D & operator+= (double s)
Adds the scalar s to every element.
Field2D & operator+= (const Field2D & o)
Element-wise adds o .
Field2D & operator-= (double s)
Subtracts the scalar s from every element.
Field2D & operator-= (const Field2D & o)
Element-wise subtracts o .
Field2D & operator/= (double s)
Divides every element by the scalar s .
Field2D & operator/= (const Field2D & o)
Element-wise divides by o .
double & operator[] (int i, int j)
Accesses the element at row i , columnj (C++23 subscript).
double operator[] (int i, int j) const
Reads the element at row i , columnj (C++23 subscript).
const std::vector< double > & raw () noexcept const
Read-only access to the underlying row-major element vector.
std::vector< double > & raw () noexcept
Mutable access to the underlying row-major element vector.
void resize (int nx, int nz)
Reshapes the field to nx bynz .
int rows () noexcept const
Number of rows.
std::array< int, 2 > shape () noexcept const
Shape as { rows() , cols() } .
int size () noexcept const
Total element count, rows() * cols() .

Detailed Description

Owning, row-major 2-D array of doubles: the single replacement for blitz::Array<double,2> used throughout the solver.

Invariant:

Storage is row-major and contiguous: element (i, j) lives at data() [i * cols() + j]. The netCDF writer and every raw-pointer hand-off rely on this layout, so it must not change.

Public Functions Documentation

function Field2D [1/2]

Constructs an empty field (zero rows, zero columns).

mgrid::Field2D::Field2D () = default


function Field2D [2/2]

Constructs an nx bynz field with every element zero.

inline mgrid::Field2D::Field2D (
    int nx,
    int nz
) 

Parameters:

  • nx number of rows
  • nz number of columns

function cols

Number of columns.

inline int mgrid::Field2D::cols () noexcept const

Returns:

the column count


function copy

Returns an independent, deep copy of this field.

inline Field2D mgrid::Field2D::copy () const

Returns:

a Field2D that owns its own storage


function data [1/2]

Pointer to the contiguous row-major element storage.

inline double * mgrid::Field2D::data () noexcept

Returns:

pointer to element (0, 0)


function data [2/2]

Pointer to the contiguous row-major element storage.

inline const double * mgrid::Field2D::data () noexcept const

Returns:

const pointer to element (0, 0)


function fill

Sets every element to value .

inline void mgrid::Field2D::fill (
    double value
) 

Parameters:

  • value value written into every element

function operator()

Accesses the element at row i , columnj .

inline double & mgrid::Field2D::operator() (
    int i,
    int j
) 

Parameters:

  • i row index
  • j column index

Returns:

reference to the element

Note:

No bounds checking is performed.


function operator()

Reads the element at row i , columnj .

inline double mgrid::Field2D::operator() (
    int i,
    int j
) const

Parameters:

  • i row index
  • j column index

Returns:

a copy of the element

Note:

No bounds checking is performed.


function operator*=

Multiplies every element by the scalar s .

inline Field2D & mgrid::Field2D::operator*= (
    double s
) 

Parameters:

  • s scalar factor

Returns:

*this


function operator*=

Element-wise multiplies by o .

inline Field2D & mgrid::Field2D::operator*= (
    const Field2D & o
) 

Parameters:

  • o operand field

Returns:

*this

Precondition:

o has the same shape as *this.

Exception:

  • std::invalid_argument if the shapes differ

function operator+=

Adds the scalar s to every element.

inline Field2D & mgrid::Field2D::operator+= (
    double s
) 

Parameters:

  • s scalar addend

Returns:

*this


function operator+=

Element-wise adds o .

inline Field2D & mgrid::Field2D::operator+= (
    const Field2D & o
) 

Parameters:

  • o operand field

Returns:

*this

Precondition:

o has the same shape as *this.

Exception:

  • std::invalid_argument if the shapes differ

function operator-=

Subtracts the scalar s from every element.

inline Field2D & mgrid::Field2D::operator-= (
    double s
) 

Parameters:

  • s scalar subtrahend

Returns:

*this


function operator-=

Element-wise subtracts o .

inline Field2D & mgrid::Field2D::operator-= (
    const Field2D & o
) 

Parameters:

  • o operand field

Returns:

*this

Precondition:

o has the same shape as *this.

Exception:

  • std::invalid_argument if the shapes differ

function operator/=

Divides every element by the scalar s .

inline Field2D & mgrid::Field2D::operator/= (
    double s
) 

Parameters:

  • s scalar divisor

Returns:

*this


function operator/=

Element-wise divides by o .

inline Field2D & mgrid::Field2D::operator/= (
    const Field2D & o
) 

Parameters:

  • o operand field

Returns:

*this

Precondition:

o has the same shape as *this.

Exception:

  • std::invalid_argument if the shapes differ

function operator[]

Accesses the element at row i , columnj (C++23 subscript).

inline double & mgrid::Field2D::operator[] (
    int i,
    int j
) 

Parameters:

  • i row index
  • j column index

Returns:

reference to the element

Note:

No bounds checking is performed.


function operator[]

Reads the element at row i , columnj (C++23 subscript).

inline double mgrid::Field2D::operator[] (
    int i,
    int j
) const

Parameters:

  • i row index
  • j column index

Returns:

a copy of the element

Note:

No bounds checking is performed.


function raw [1/2]

Read-only access to the underlying row-major element vector.

inline const std::vector< double > & mgrid::Field2D::raw () noexcept const

Returns:

const reference to the storage vector


function raw [2/2]

Mutable access to the underlying row-major element vector.

inline std::vector< double > & mgrid::Field2D::raw () noexcept

Returns:

reference to the storage vector


function resize

Reshapes the field to nx bynz .

inline void mgrid::Field2D::resize (
    int nx,
    int nz
) 

Parameters:

  • nx new number of rows
  • nz new number of columns

Postcondition:

Every element is zero.


function rows

Number of rows.

inline int mgrid::Field2D::rows () noexcept const

Returns:

the row count


function shape

Shape as { rows() , cols() } .

inline std::array< int, 2 > mgrid::Field2D::shape () noexcept const

Returns:

a two-element array { rows() , cols() }


function size

Total element count, rows() * cols() .

inline int mgrid::Field2D::size () noexcept const

Returns:

the number of elements



The documentation for this class was generated from the following file include/multigrid/field.hpp