Step 2a - Sampling values along a line

In this sidebar we'll go through how to sample variables along a line. As noted previously in Step 2, this problem is expected to provide a solution for the temperature that varies linearly as a function of the coordinate.

The variation of the solution as stored in the Exodus file can be visualized along a line using tools like Paraview, but MOOSE also offers a way of directly outputting values sampled along a line to a comma-separate value (CSV) file. Benefits of doing this include:

- If a calculation is repeated many times, plotting of key quantities can be automated.

- The solution is sampled from the finite element interpolation used internally by MOOSE, which provides the most accurate description of the solution.

- The values sampled along the line could be used for other computations within the MOOSE simulation.

To sample the values along a line, the MOOSE VectorPostprocessor system is used. Whereas a Postprocessor in MOOSE computes a single value, a VectorPostprocessor computes a vector of values. The LineValueSampler is a VectorPostprocessor that computes values at a discrete set of points along a line.

#
# Single block thermal input with a line value sampler
# https://mooseframework.inl.gov/modules/heat_transfer/tutorials/introduction/therm_step02.html
#

[Mesh]
  [generated]
    type = GeneratedMeshGenerator
    dim = 2
    nx = 10
    ny = 10
    xmax = 2
    ymax = 1
  []
[]

[Variables]
  [T]
  []
[]

[Kernels]
  [heat_conduction]
    type = HeatConduction
    variable = T
  []
[]

[Materials]
  [thermal]
    type = HeatConductionMaterial
    thermal_conductivity = 45.0
  []
[]

[BCs]
  [t_left]
    type = DirichletBC
    variable = T
    value = 300
    boundary = 'left'
  []
  [t_right]
    type = FunctionDirichletBC
    variable = T
    function = '300+5*t'
    boundary = 'right'
  []
[]

[Executioner]
  type = Transient
  end_time = 5
  dt = 1
[]

[VectorPostprocessors]
  [t_sampler]
    type = LineValueSampler
    variable = T
    start_point = '0 0.5 0'
    end_point = '2 0.5 0'
    num_points = 20
    sort_by = x
  []
[]

[Outputs]
  exodus = true
  [csv]
    type = CSV
    file_base = therm_step02a_out
    execute_on = final
  []
[]
(moose/modules/heat_transfer/tutorials/introduction/therm_step02a.i)

Input file

VectorPostprocessors

To add sampling along a line, a single block to define a LineValueSampler is nested within the VectorPostprocessors top level block. Most of the parameters are self-explanatory. They define the variable to be sampled, the start and end points of the line, and the number of points. The order that the values are output is controlled by the sort_by parameter, and in this case, they are sorted by the x value since the line is oriented along the axis. For lines that are not oriented along one of the Cartesian axes, the sort_by = id option can be used to sort by the position along the line.

[VectorPostprocessors]
  [t_sampler]
    type = LineValueSampler
    variable = T
    start_point = '0 0.5 0'
    end_point = '2 0.5 0'
    num_points = 20
    sort_by = x
  []
[]
(moose/modules/heat_transfer/tutorials/introduction/therm_step02a.i)

Outputs

Adding the LineValueSampler block will result in values being computed, but they will only exist internally in the code unless CSV output is requested in the Outputs block. The simplest way to request this is to add csv = true, similar to the exodus = true parameter. However, a block specific for the CSV output is added to the Outputs block in this case to allow specifying parameters to make the output more manageable. The file_base parameter permits controlling the base name for the output file. By default a separate CSV file will be output for each time step. To limit the amount of output, the execute_on = final parameter makes the system only output a CSV file for the last time step.

[Outputs]
  exodus = true
  [csv]
    type = CSV
    file_base = therm_step02a_out
    execute_on = final
  []
[]
(moose/modules/heat_transfer/tutorials/introduction/therm_step02a.i)

Exercises

Examining output

First, run the model as-is and examine the CSV file that is output. Try opening that file in a plotting package to visualize the results.

Output at multiple times

Try commenting out the execute_on = final line in the csv output block and re-running the model. You should see multiple CSV files generated – one for each time step.

Once you've run this example we will move on to Step 3, where additional terms will be added to the heat equation.