Skip to content

Struct mgrid::FDVecArray

ClassList > mgrid > FDVecArray

A 2-component vector field on a finite-difference grid. More...

  • #include <fdvecarray.hpp>

Inherits the following classes: mgrid::FDBase

Public Attributes

Type Name
FDArray first
First component of the vector field.
FDArray second
Second component of the vector field.

Public Functions

Type Name
FDVecArray () = default
Constructs an empty vector array with no geometry and no storage.
FDVecArray (double aspect, int nx, int nz)
Constructs an nx bynz vector array, sized, zeroed, with geometry.
int cols () const
Number of columns (z-direction grid points).
void divergence (Field2D & out) const
Computes the divergence (∂first/∂x + ∂second/∂z) at all grid points.
void magnitude (Field2D & out) const
Computes the magnitude of the vector field at all grid points.
FDVecArray & operator+= (const FDVecArray & o)
Component-wise addition assignment.
FDVecArray & operator-= (const FDVecArray & o)
Component-wise subtraction assignment.
void resize (double aspect, int nx, int nz)
Recomputes geometry and reallocates storage for both components.
int rows () const
Number of rows (x-direction grid points).
void write (std::string filestring)
Writes both components to a netCDF-4 file.

Public Functions inherited from mgrid::FDBase

See mgrid::FDBase

Type Name
FDBase () = default
FDBase (const FDBase &) = default
FDBase (FDBase &&) = default
FDBase & operator= (const FDBase &) = default
FDBase & operator= (FDBase &&) = default
double spacing (int n) const
Get the grid spacing in a given direction.
const Axis & x_axis () const
The x grid axis (points, spacing, periodicity).
const Axis & z_axis () const
The z grid axis (points, spacing, periodicity).
virtual ~FDBase () = default

Protected Attributes inherited from mgrid::FDBase

See mgrid::FDBase

Type Name
double aspect_ = {0.0}
double hx_ = {0.0}
double hz_ = {0.0}
int nx_ = {0}
int nz_ = {0}
Axis xAxis_ = {}
double xfactor_ = {0.0}
double xxfactor_ = {0.0}
double xzfactor_ = {0.0}
Axis zAxis_ = {}
double zfactor_ = {0.0}
double zzfactor_ = {0.0}

Protected Functions inherited from mgrid::FDBase

See mgrid::FDBase

Type Name
void calculate_geometry (double aspect, int nx, int nz, AxisKind kx=AxisKind::bounded, AxisKind kz=AxisKind::bounded)
Compute and cache grid spacings and finite-difference factors.

Detailed Description

Composition of two FDArray components: first and second. Both components share the same geometry.

Public Attributes Documentation

variable first

First component of the vector field.

FDArray mgrid::FDVecArray::first;


variable second

Second component of the vector field.

FDArray mgrid::FDVecArray::second;


Public Functions Documentation

function FDVecArray [1/2]

Constructs an empty vector array with no geometry and no storage.

mgrid::FDVecArray::FDVecArray () = default


function FDVecArray [2/2]

Constructs an nx bynz vector array, sized, zeroed, with geometry.

mgrid::FDVecArray::FDVecArray (
    double aspect,
    int nx,
    int nz
) 

Parameters:

  • aspect aspect ratio (horizontal extent / vertical extent)
  • nx number of grid points in the x direction (rows)
  • nz number of grid points in the z direction (columns)

function cols

Number of columns (z-direction grid points).

inline int mgrid::FDVecArray::cols () const

Returns:

the column count from the first component


function divergence

Computes the divergence (∂first/∂x + ∂second/∂z) at all grid points.

void mgrid::FDVecArray::divergence (
    Field2D & out
) const

Parameters:

  • out output field; must have the same shape as *this

Postcondition:

out(i,j) = first.dx(i,j) + second.dz(i,j) for all (i,j)


function magnitude

Computes the magnitude of the vector field at all grid points.

void mgrid::FDVecArray::magnitude (
    Field2D & out
) const

Parameters:

  • out output field; must have the same shape as *this

Postcondition:

out(i,j) = sqrt( first(i,j) ^2 + second(i,j) ^2) for all (i,j)


function operator+=

Component-wise addition assignment.

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

Parameters:

  • o vector array to add; must have the same shape as *this

Returns:

*this


function operator-=

Component-wise subtraction assignment.

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

Parameters:

  • o vector array to subtract; must have the same shape as *this

Returns:

*this


function resize

Recomputes geometry and reallocates storage for both components.

void mgrid::FDVecArray::resize (
    double aspect,
    int nx,
    int nz
) 

Parameters:

  • aspect aspect ratio (horizontal extent / vertical extent)
  • nx new number of grid points in the x direction (rows)
  • nz new number of grid points in the z direction (columns)

Postcondition:

Every element and every boundary value in both components is zero.


function rows

Number of rows (x-direction grid points).

inline int mgrid::FDVecArray::rows () const

Returns:

the row count from the first component


function write

Writes both components to a netCDF-4 file.

void mgrid::FDVecArray::write (
    std::string filestring
) 

Parameters:

  • filestring output path stem; .nc is appended before writing.

Postcondition:

The file holds dims x = rows(), z = cols() and two 2-D double variables "u_x" (= first) and "u_z" (= second).

Exception:

  • netCDF::exceptions::NcException on any netCDF failure.


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