discretize.TreeMesh.nodal_gradient#

TreeMesh.nodal_gradient#

Nodal gradient operator (nodes to edges)

This property constructs the 2nd order numerical gradient operator that maps from nodes to edges. The operator is a sparse matrix \(\mathbf{G_n}\) that can be applied as a matrix-vector product to a discrete scalar quantity \(\boldsymbol{\phi}\) that lives on the nodes, i.e.:

grad_phi = Gn @ phi

Once constructed, the operator is stored permanently as a property of the mesh.

Returns:
(n_edges, n_nodes) scipy.sparse.csr_matrix

The numerical gradient operator from nodes to edges

Notes

In continuous space, the gradient operator is defined as:

\[\vec{u} = \nabla \phi = \frac{\partial \phi}{\partial x}\hat{x} + \frac{\partial \phi}{\partial y}\hat{y} + \frac{\partial \phi}{\partial z}\hat{z}\]

Where \(\boldsymbol{\phi}\) is the discrete representation of the continuous variable \(\phi\) on the nodes and \(\mathbf{u}\) is the discrete representation of \(\vec{u}\) on the edges, nodal_gradient constructs a discrete linear operator \(\mathbf{G_n}\) such that:

\[\mathbf{u} = \mathbf{G_n} \, \boldsymbol{\phi}\]

The Cartesian components of \(\vec{u}\) are defined on their corresponding edges (x, y or z) as follows; e.g. the x-component of the gradient is defined on x-edges. For edge \(i\) which defines a straight path of length \(h_i\) between adjacent nodes \(n_1\) and \(n_2\):

\[u_i = \frac{\phi_{n_2} - \phi_{n_1}}{h_i}\]

Note that \(u_i \in \mathbf{u}\) may correspond to a value on an x, y or z edge. See the example below.