# Using USim to Solve a Diffusion Problem¶

In this tutorial we show how to use USim to solve a problem with diffusion using the updater diffusion (1d, 2d, 3d) with derivative set to diffusion.

## Required DataStructs¶

The variable that is diffusing is q and is a scalar

<DataStruct q>
kind = nodalArray
onGrid = domain
numComponents = 3
writeOut = 1
</DataStruct>


In addition we define the scalar diffusion coefficient as diffCoeff

<DataStruct diffCoeff>
kind = nodalArray
onGrid = domain
numComponents = 1
writeOut = 1
</DataStruct>


## Solving problems using the derivatives with option diffusion¶

diffCoeff can be defined using a combiner (1d, 2d, 3d). After diffCoeff is computed the diffusion operator can be applied. We use diffusion (1d, 2d, 3d) with derivative set to diffusion to compute the diffusion term. The operator take in q and diffCoeff and the result (in this case) is stored in qnew

<Updater computeDiffusion>
kind = diffusion2d
onGrid = domain
derivative = diffusion
numScalars = 1
coefficient = 1.0
numberOfInterpolationPoints = 8

in = [q,diffCoeff]
out = [qnew]
</Updater>


Note that the complete list of options available in diffusion (1d, 2d, 3d) are diffusion, anisotropicDiffusion and gradientOfDivergence.

## Computing the time step for the diffusion operator¶

Time integration is performed using super time stepping. Super time stepping is a variable stage Runge-Kutta approach that is much faster (by the number of stages) than standard Runge-Kutta methods for solving diffusion problems. The approach requires two time steps. The desired (actual) time step is computed using a timeStepRestrictionUpdater (1d, 2d, 3d). The key here is that STS_CFL=40.0 so it is much higher than the explicitly stable time step for a diffusive system

<Updater timeStepRestriction>

kind = timeStepRestrictionUpdater2d
in = [diffCoeff]

onGrid = domain

cfl = STS_CFL
</TimeStepRestriction>

</Updater>


Next the time step for the super time stepping method is computed where an explicitly stable CFL=0.25 is used. The time step is stored in stsDt

<Updater getSTSdt>
kind = getTimeStepUpdater2d
in = [diffCoeff]
out = [stsDt]
onGrid = domain

cfl = EXPLICIT_CFL
</TimeStepRestriction>
</Updater>


The Super Time Stepping integrator then knows to take the ratio of the desired time step and the explicitly stable time step to compute the number of stages used in the STS Updater.

## An Example Simulation¶

The input file for the problem Diffusion in the USimHS package demonstrates each of the concepts described above.