# diffusion (1d, 2d, 3d)¶

The diffusion updater computes a range of second derivatives of quanties defined on the USim computational mesh using a least squares gradient method. The specific form of the operator can be chosen by derivative to the desired type, as detailed below.

The diffusion updater accepts the parameters below, in addition to those required by Updater.

## Data¶

in (string vector, required)
Defined by the choice of the derivative attribute, as detailed below.
out (string vector, required)
Defined by the choice of the derivative attribute, as detailed below.

## Parameters¶

orderAccuracy (integer, required)
Order of the polynomial that is used to form the operator. Choice of 1, 2 or 3 corresponding, respectively to first, second and third order accuracy. The appropriate choice of order varies on the problem type and the mesh used.
numberOfInterpolationPoints (integer, required)

Number of points to be considerd for the least squares fit. This parameter varies from mesh to mesh and should be determined by computing a known function on the mesh.

The numberOfInterpolationPoints must be greater than (or equal to) the number of coefficients in the polynomial approximation. This means that in 1d the value is 4, in 2D the value is at least 6 and in 3D the value is at least 10.

These choices do not guarantee that a matrix inverse will be found. The following values though appear to be adequate in general: in 1D 4; in 2D 8 and in 3D 20.

coefficient (float, required)
Constant floating point value, c that multiplies the output of the diffusion updater.
derivative (string, required)
The type of derivative that will be performed. Available derivatives are:
diffusion (derivative = diffusion)

Computes $$c\nabla \cdot \left(\kappa \nabla \phi \right)$$ where $$\phi$$ and $$\kappa$$ are scalar quantities defined on the grid and c is a constant coefficient. When derivative = diffusion is specified, the following input and output variables should be specified:

in
1. $$\phi$$ (nodalArray, n-components, required); scalar quantity to compute the Laplacian. If $$n > 1$$ then the Laplacian of each component is computed independently.
2. $$\kappa$$ (nodalArray, n-components, required); scalar diffusion coefficient. n must be the same as for $$\phi$$
out
1. $$c\nabla \cdot \left(\kappa \nabla \phi\right)$$ (nodalArray, n-components, required); Laplacian of $$\phi$$. n must be the same as for $$\phi$$
anisotropicDiffusion (derivative = anisotropicDiffusion)

Computes $$c\nabla \cdot \left(\mathcal{K} \nabla \phi \right)$$ where $$\phi$$ is a scalar quantity and $$\mathcal{K}$$ is a tensor quantity defined on the grid and c is a constant coefficient. When derivative = anisotropicDiffusion is specified, the following input and output variables should be specified:

in
1. $$\phi$$ (nodalArray, 1 component, required); scalar quantity to compute the Laplacian.
2. $$\mathcal{K}$$ (nodalArray, 9-components, required); 9-component diffusion tesnore. Note that in one- and two-dimensions, the ignorable coordinates will be multiplied by zero.
out
1. $$c\nabla \cdot \left(\mathcal{K} \nabla \phi \right)$$ (nodalArray, 1-component, required); Laplacian of $$\phi$$.
gradientOfDivergence (derivative = gradientOfDivergence)

Computes $$c\nabla \left(\kappa \nabla \cdot \mathbf{v} \right)$$ where $$\mathbf{v}$$ is a vector quantity and $$\kappa$$ is a scalar quantity defined on the grid and c is a constant coefficient. When derivative = gradientOfDivergence is specified, the following input and output variables should be specified:

in
1. $$\mathbf{v}$$ (nodalArray, 3-components, required); vector quantity to compute the Laplacian.
2. $$\kappa$$ (nodalArray, 1-component, required); scalar diffusion coefficient.
out
1. $$c\nabla \left(\kappa \nabla \cdot \mathbf{v} \right)$$ (nodalArray, 1-components, required); Laplacian of $$\mathbf{v}$$.

## Example¶

The following code block demonstrates the least squares diffusion operator for computing the laplacian of a scalar quantity with a scalar diffusion coefficient:

<Updater leastSquaresDiffusion>
kind = diffusion2d
onGrid = domain
derivative = diffusion
numScalars = 2
coefficient = 1.0
numberOfInterpolationPoints = 8
in = [q,D]
out = [qnew]
</Updater>


The following code block demonstrates the least squares diffusion operator for computing the laplacian of a scalar quantity with a tensor diffusion coefficient:

<Updater computeDiffusion>
kind = diffusion2d
derivative = anisotropicDiffusion
onGrid = domain
numScalars = 3
coefficient = 1.0

orderAccuracy = 1
numberOfInterpolationPoints = 8

in = [temperature, conductivityTensor]
out = [temperatureNew]
</Updater>


The following code block demonstrates the least squares diffusion operator for computing the laplacian of a vector quantity with a scalar diffusion coefficient:

<Updater derivative>
kind = diffusion2d