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'
[]
(contrib/moose/modules/ray_tracing/test/tests/raykernels/variable_integral_ray_kernel/simple_diffusion_line_integral.i)

For this problem, we seek the value of the integrals (where uhu_h is the finite-element solution)

L1uh(r) dr,L1={(0,0)+t(5,5)t[0,1]},\int_{L_1} u_h(\vec{r})~dr, \quad L_1 = \{(0, 0) + t(5, 5) \mid t \in [0, 1]\}\,,

and

L2uh(r) dr,L2={(5,0)+t(5,5)t[0,1]},\int_{L_2} u_h(\vec{r})~dr, \quad L_2 = \{(5, 0) + t(5, 5) \mid t \in [0, 1]\}\,,

in which we will denote the first line, L1L_1, as diag and the second, L2L_2, as right_up for simplicity.

Note that the integral along the second line, L2L_2, is trivial due to the Dirichlet boundary condition,

uh(5,y)=1,y[0,5],u_h(5, y) = 1\,, \quad y \in [0, 5]\,,

which implies

L2uh(r) dr=05uh(5,y)dy=05dy=5,L2={(5,0)+t(5,5)t[0,1]}.\int_{L_2} u_h(\vec{r})~dr = \int_0^5 u_h(5, y)\,dy = \int_0^5 dy = 5\,, \quad L_2 = \{(5, 0) + t(5, 5) \mid t \in [0, 1]\}\,.

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
[]
(contrib/moose/modules/ray_tracing/test/tests/raykernels/variable_integral_ray_kernel/simple_diffusion_line_integral.i)

The study object defines two rays to be executed on TIMESTEP_END:

  • diag from (0,0)(0, 0) to (5,5)(5, 5)

  • right_up from (5,0)(5, 0) to (5,5)(5, 5)

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
[]
(contrib/moose/modules/ray_tracing/test/tests/raykernels/variable_integral_ray_kernel/simple_diffusion_line_integral.i)

The u_integral VariableIntegralRayKernel will accumulate the variable line integral of the u Variable for our defined rays, diag and right_up.

commentnote

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
  []
[]
(contrib/moose/modules/ray_tracing/test/tests/raykernels/variable_integral_ray_kernel/simple_diffusion_line_integral.i)

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.