LCOV - code coverage report
Current view: top level - src/vectorpostprocessors - IntersectionPointsAlongLine.C (source / functions) Hit Total Coverage
Test: idaholab/moose framework: 2bf808 Lines: 40 42 95.2 %
Date: 2025-07-17 01:28:37 Functions: 4 4 100.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : //* This file is part of the MOOSE framework
       2             : //* https://mooseframework.inl.gov
       3             : //*
       4             : //* All rights reserved, see COPYRIGHT for full restrictions
       5             : //* https://github.com/idaholab/moose/blob/master/COPYRIGHT
       6             : //*
       7             : //* Licensed under LGPL 2.1, please see LICENSE for details
       8             : //* https://www.gnu.org/licenses/lgpl-2.1.html
       9             : 
      10             : #include "IntersectionPointsAlongLine.h"
      11             : 
      12             : // MOOSE includes
      13             : #include "LineSegment.h"
      14             : #include "RayTracing.h"
      15             : #include "MooseMesh.h"
      16             : 
      17             : registerMooseObject("MooseApp", IntersectionPointsAlongLine);
      18             : 
      19             : InputParameters
      20       14337 : IntersectionPointsAlongLine::validParams()
      21             : {
      22       14337 :   InputParameters params = GeneralVectorPostprocessor::validParams();
      23       14337 :   params.addClassDescription(
      24             :       "Get the intersection points for all of the elements that are intersected by a line.");
      25       14337 :   params.addRequiredParam<Point>("start", "The beginning of the line");
      26       14337 :   params.addRequiredParam<Point>("end", "The end of the line");
      27       14337 :   return params;
      28           0 : }
      29             : 
      30          36 : IntersectionPointsAlongLine::IntersectionPointsAlongLine(const InputParameters & parameters)
      31             :   : GeneralVectorPostprocessor(parameters),
      32          36 :     _start(getParam<Point>("start")),
      33          36 :     _end(getParam<Point>("end")),
      34          36 :     _x_intersections(declareVector("x"))
      35             : #if LIBMESH_DIM > 1
      36             :     ,
      37          36 :     _y_intersections(declareVector("y"))
      38             : #if LIBMESH_DIM > 2
      39             :     ,
      40          72 :     _z_intersections(declareVector("z"))
      41             : #endif
      42             : #endif
      43             : {
      44          36 :   _intersections.push_back(&_x_intersections);
      45             : #if LIBMESH_DIM > 1
      46          36 :   _intersections.push_back(&_y_intersections);
      47             : #if LIBMESH_DIM > 2
      48          36 :   _intersections.push_back(&_z_intersections);
      49             : #endif
      50             : #endif
      51             : 
      52          36 :   _fe_problem.mesh().errorIfDistributedMesh("IntersectionPointsAlongLine");
      53          36 : }
      54             : 
      55             : void
      56          33 : IntersectionPointsAlongLine::initialize()
      57             : {
      58         132 :   for (unsigned int i = 0; i < _intersections.size(); i++)
      59          99 :     _intersections[i]->clear();
      60          33 : }
      61             : 
      62             : void
      63          33 : IntersectionPointsAlongLine::execute()
      64             : {
      65          33 :   std::vector<Elem *> intersected_elems;
      66          33 :   std::vector<LineSegment> segments;
      67             : 
      68          33 :   std::unique_ptr<libMesh::PointLocatorBase> pl = _fe_problem.mesh().getPointLocator();
      69             : 
      70             :   // We may not have any elements along the given line; if so then
      71             :   // that shouldn't throw a libMesh error.
      72          33 :   pl->enable_out_of_mesh_mode();
      73             : 
      74          66 :   Moose::elementsIntersectedByLine(
      75          33 :       _start, _end, _fe_problem.mesh(), *pl, intersected_elems, segments);
      76             : 
      77          33 :   const unsigned int num_elems = intersected_elems.size();
      78             : 
      79             :   // Quick return in case no elements were found
      80          33 :   if (num_elems == 0)
      81           0 :     return;
      82             : 
      83         132 :   for (const auto i : make_range(Moose::dim))
      84          99 :     _intersections[i]->resize(num_elems + 1);
      85             : 
      86             :   // Add the beginning point
      87         132 :   for (const auto i : make_range(Moose::dim))
      88          99 :     (*_intersections[i])[0] = _start(i);
      89             : 
      90             :   // Add the ending point of every segment
      91         198 :   for (unsigned int i = 0; i < num_elems; i++)
      92             :   {
      93         165 :     LineSegment & segment = segments[i];
      94             : 
      95         165 :     const Point & end_point = segment.end();
      96             : 
      97         660 :     for (const auto j : make_range(Moose::dim))
      98         495 :       (*_intersections[j])[i + 1] = end_point(j);
      99             :   }
     100          33 : }

Generated by: LCOV version 1.14