Computing Line Integrals
The Ray Tracing Module can be utilized to integrate fields along a line throughout the domain. Example fields include Variables, AuxVariables, Material properties, and Functions.
The discussion that follows will describe how to integrate a variable across a line in a simple diffusion problem. To integrate other fields, the process remains the same except for the definition of the RayKernel.
Problem Definition
We begin with the standard "simple diffusion" problem:
[Mesh]
  [gmg]
    type = GeneratedMeshGenerator
    dim = 2
    nx = 5
    ny = 5
    xmax = 5
    ymax = 5
  []
[]
[Variables/u]
[]
[Kernels/diff]
  type = Diffusion
  variable = u
[]
[BCs]
  [left]
    type = DirichletBC
    variable = u
    boundary = left
    value = 0
  []
  [right]
    type = DirichletBC
    variable = u
    boundary = right
    value = 1
  []
[]
[Executioner]
  type = Steady
  solve_type = 'PJFNK'
  petsc_options_iname = '-pc_type -pc_hypre_type'
  petsc_options_value = 'hypre boomeramg'
[]
For this problem, we seek the value of the integrals (where is the finite-element solution)
and
in which we will denote the first line, , as diag and the second, , as right_up for simplicity.
Note that the integral along the second line, , is trivial due to the Dirichlet boundary condition,
which implies
Defining the Study
A RepeatableRayStudy is defined that generates and executes the rays that compute the variable line integral:
[UserObjects/study]
  type = RepeatableRayStudy
  names = 'diag
           right_up'
  start_points = '0 0 0
                  5 0 0'
  end_points = '5 5 0
                5 5 0'
  execute_on = TIMESTEP_END
  # Needed to cache trace information for RayTracingMeshOutput
  # always_cache_traces = true
  # Needed to cache Ray data for RayTracingMeshOutput
  # data_on_cache_traces = true
[]
The study object defines two rays to be exectued on TIMESTEP_END:
- diagfrom to
- right_upfrom to
Defining the RayKernel
RayKernels are objects that are executed on the segments of the rays. In this case, we wish to compute the integral of a variable so we will define a VariableIntegralRayKernel:
[RayKernels/u_integral]
  type = VariableIntegralRayKernel
  variable = u
[]
The u_integral VariableIntegralRayKernel will accumulate the variable line integral of the u Variable for our defined rays, diag and right_up.
Other commonly used IntegralRayKernels are the FunctionIntegralRayKernel and the MaterialIntegralRayKernel.
Integral Output
Lastly, we need to obtain the accumulated integrals from the study. We will utilize a RayIntegralValue Postprocessor to achieve this:
[Postprocessors]
  [diag_line_integral]
    type = RayIntegralValue
    ray_kernel = u_integral
    ray = diag
  []
  [right_up_line_integral]
    type = RayIntegralValue
    ray_kernel = u_integral
    ray = right_up
  []
[]
The accumulated integrals are seen in output:
Postprocessor Values:
+----------------+--------------------+------------------------+
| time           | diag_line_integral | right_up_line_integral |
+----------------+--------------------+------------------------+
|   0.000000e+00 |       0.000000e+00 |           0.000000e+00 |
|   1.000000e+00 |       3.535534e+00 |           5.000000e+00 |
+----------------+--------------------+------------------------+
Segment-wise Integral Output
The segment-wise accumulated integral can also be outputted in a mesh format using the RayTracingMeshOutput. For more information, see Example.