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<<<{"href": "../../../../syntax/Mesh/index.html"}>>>]
[generated]
type = GeneratedMeshGenerator<<<{"description": "Create a line, square, or cube mesh with uniformly spaced or biased elements.", "href": "../../../../source/meshgenerators/GeneratedMeshGenerator.html"}>>>
dim<<<{"description": "The dimension of the mesh to be generated"}>>> = 2
nx<<<{"description": "Number of elements in the X direction"}>>> = 10
ny<<<{"description": "Number of elements in the Y direction"}>>> = 10
xmax<<<{"description": "Upper X Coordinate of the generated mesh"}>>> = 2
ymax<<<{"description": "Upper Y Coordinate of the generated mesh"}>>> = 1
[]
[]
[Variables<<<{"href": "../../../../syntax/Variables/index.html"}>>>]
[T]
[]
[]
[Kernels<<<{"href": "../../../../syntax/Kernels/index.html"}>>>]
[heat_conduction]
type = HeatConduction<<<{"description": "Diffusive heat conduction term $-\\nabla\\cdot(k\\nabla T)$ of the thermal energy conservation equation", "href": "../../../../source/kernels/HeatConduction.html"}>>>
variable<<<{"description": "The name of the variable that this residual object operates on"}>>> = T
[]
[]
[Materials<<<{"href": "../../../../syntax/Materials/index.html"}>>>]
[thermal]
type = HeatConductionMaterial<<<{"description": "General-purpose material model for heat conduction", "href": "../../../../source/materials/HeatConductionMaterial.html"}>>>
thermal_conductivity<<<{"description": "The thermal conductivity value"}>>> = 45.0
[]
[]
[BCs<<<{"href": "../../../../syntax/BCs/index.html"}>>>]
[t_left]
type = DirichletBC<<<{"description": "Imposes the essential boundary condition $u=g$, where $g$ is a constant, controllable value.", "href": "../../../../source/bcs/DirichletBC.html"}>>>
variable<<<{"description": "The name of the variable that this residual object operates on"}>>> = T
value<<<{"description": "Value of the BC"}>>> = 300
boundary<<<{"description": "The list of boundary IDs from the mesh where this object applies"}>>> = 'left'
[]
[t_right]
type = FunctionDirichletBC<<<{"description": "Imposes the essential boundary condition $u=g(t,\\vec{x})$, where $g$ is a (possibly) time and space-dependent MOOSE Function.", "href": "../../../../source/bcs/FunctionDirichletBC.html"}>>>
variable<<<{"description": "The name of the variable that this residual object operates on"}>>> = T
function<<<{"description": "The forcing function."}>>> = '300+5*t'
boundary<<<{"description": "The list of boundary IDs from the mesh where this object applies"}>>> = 'right'
[]
[]
[Executioner<<<{"href": "../../../../syntax/Executioner/index.html"}>>>]
type = Transient
end_time = 5
dt = 1
[]
[VectorPostprocessors<<<{"href": "../../../../syntax/VectorPostprocessors/index.html"}>>>]
[t_sampler]
type = LineValueSampler<<<{"description": "Samples variable(s) along a specified line", "href": "../../../../source/vectorpostprocessors/LineValueSampler.html"}>>>
variable<<<{"description": "The names of the variables that this VectorPostprocessor operates on"}>>> = T
start_point<<<{"description": "The beginning of the line"}>>> = '0 0.5 0'
end_point<<<{"description": "The ending of the line"}>>> = '2 0.5 0'
num_points<<<{"description": "The number of points to sample along the line"}>>> = 20
sort_by<<<{"description": "What to sort the samples by"}>>> = x
[]
[]
[Outputs<<<{"href": "../../../../syntax/Outputs/index.html"}>>>]
exodus<<<{"description": "Output the results using the default settings for Exodus output."}>>> = true
[csv]
type = CSV<<<{"description": "Output for postprocessors, vector postprocessors, and scalar variables using comma seperated values (CSV).", "href": "../../../../source/outputs/CSV.html"}>>>
file_base<<<{"description": "The desired solution output name without an extension. If not provided, MOOSE sets it with Outputs/file_base when available. Otherwise, MOOSE uses input file name and this object name for a master input or uses master file_base, the subapp name and this object name for a subapp input to set it."}>>> = therm_step02a_out
execute_on<<<{"description": "The list of flag(s) indicating when this object should be executed. For a description of each flag, see https://mooseframework.inl.gov/source/interfaces/SetupInterface.html."}>>> = 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<<<{"href": "../../../../syntax/VectorPostprocessors/index.html"}>>>]
[t_sampler]
type = LineValueSampler<<<{"description": "Samples variable(s) along a specified line", "href": "../../../../source/vectorpostprocessors/LineValueSampler.html"}>>>
variable<<<{"description": "The names of the variables that this VectorPostprocessor operates on"}>>> = T
start_point<<<{"description": "The beginning of the line"}>>> = '0 0.5 0'
end_point<<<{"description": "The ending of the line"}>>> = '2 0.5 0'
num_points<<<{"description": "The number of points to sample along the line"}>>> = 20
sort_by<<<{"description": "What to sort the samples 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<<<{"href": "../../../../syntax/Outputs/index.html"}>>>]
exodus<<<{"description": "Output the results using the default settings for Exodus output."}>>> = true
[csv]
type = CSV<<<{"description": "Output for postprocessors, vector postprocessors, and scalar variables using comma seperated values (CSV).", "href": "../../../../source/outputs/CSV.html"}>>>
file_base<<<{"description": "The desired solution output name without an extension. If not provided, MOOSE sets it with Outputs/file_base when available. Otherwise, MOOSE uses input file name and this object name for a master input or uses master file_base, the subapp name and this object name for a subapp input to set it."}>>> = therm_step02a_out
execute_on<<<{"description": "The list of flag(s) indicating when this object should be executed. For a description of each flag, see https://mooseframework.inl.gov/source/interfaces/SetupInterface.html."}>>> = 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.