www.mooseframework.org
IntersectionPointsAlongLine.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://www.mooseframework.org
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 
11 
12 // MOOSE includes
13 #include "LineSegment.h"
14 #include "RayTracing.h"
15 #include "MooseMesh.h"
16 
18 
21 {
23  params.addClassDescription(
24  "Get the intersection points for all of the elements that are intersected by a line.");
25  params.addRequiredParam<Point>("start", "The beginning of the line");
26  params.addRequiredParam<Point>("end", "The end of the line");
27  return params;
28 }
29 
31  : GeneralVectorPostprocessor(parameters),
32  _start(getParam<Point>("start")),
33  _end(getParam<Point>("end")),
34  _x_intersections(declareVector("x"))
35 #if LIBMESH_DIM > 1
36  ,
37  _y_intersections(declareVector("y"))
38 #if LIBMESH_DIM > 2
39  ,
40  _z_intersections(declareVector("z"))
41 #endif
42 #endif
43 {
44  _intersections.push_back(&_x_intersections);
45 #if LIBMESH_DIM > 1
46  _intersections.push_back(&_y_intersections);
47 #if LIBMESH_DIM > 2
48  _intersections.push_back(&_z_intersections);
49 #endif
50 #endif
51 
52  _fe_problem.mesh().errorIfDistributedMesh("IntersectionPointsAlongLine");
53 }
54 
55 void
57 {
58  for (unsigned int i = 0; i < _intersections.size(); i++)
59  _intersections[i]->clear();
60 }
61 
62 void
64 {
65  std::vector<Elem *> intersected_elems;
66  std::vector<LineSegment> segments;
67 
68  std::unique_ptr<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  pl->enable_out_of_mesh_mode();
73 
75  _start, _end, _fe_problem.mesh(), *pl, intersected_elems, segments);
76 
77  const unsigned int num_elems = intersected_elems.size();
78 
79  // Quick return in case no elements were found
80  if (num_elems == 0)
81  return;
82 
83  for (const auto i : make_range(Moose::dim))
84  _intersections[i]->resize(num_elems + 1);
85 
86  // Add the beginning point
87  for (const auto i : make_range(Moose::dim))
88  (*_intersections[i])[0] = _start(i);
89 
90  // Add the ending point of every segment
91  for (unsigned int i = 0; i < num_elems; i++)
92  {
93  LineSegment & segment = segments[i];
94 
95  const Point & end_point = segment.end();
96 
97  for (const auto j : make_range(Moose::dim))
98  (*_intersections[j])[i + 1] = end_point(j);
99  }
100 }
const Point & end() const
Ending of the line segment.
Definition: LineSegment.h:68
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
VectorPostprocessorValue & _x_intersections
The elements that intersect the line.
VectorPostprocessorValue & _z_intersections
This class is here to combine the VectorPostprocessor interface and the base class VectorPostprocesso...
The LineSegment class is used by the LineMaterialSamplerBase class and for some ray tracing stuff...
Definition: LineSegment.h:29
if(subdm)
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
static constexpr std::size_t dim
This is the dimension of all vector and tensor datastructures used in MOOSE.
Definition: Moose.h:148
VectorPostprocessorValue & _y_intersections
Point _start
The beginning of the line.
void addRequiredParam(const std::string &name, const std::string &doc_string)
This method adds a parameter and documentation string to the InputParameters object that will be extr...
registerMooseObject("MooseApp", IntersectionPointsAlongLine)
void errorIfDistributedMesh(std::string name) const
Generate a unified error message if the underlying libMesh mesh is a DistributedMesh.
Definition: MooseMesh.C:3367
IntersectionPointsAlongLine(const InputParameters &parameters)
static InputParameters validParams()
Get the intersection points for all of the elements that are intersected by a line.
std::vector< VectorPostprocessorValue * > _intersections
Tie them together for convenience.
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Definition: UserObject.h:210
virtual void execute() override
Find the elements.
IntRange< T > make_range(T beg, T end)
virtual MooseMesh & mesh() override
void addClassDescription(const std::string &doc_string)
This method adds a description of the class that will be displayed in the input file syntax dump...
virtual std::unique_ptr< PointLocatorBase > getPointLocator() const
Proxy function to get a (sub)PointLocator from either the underlying libMesh mesh (default)...
Definition: MooseMesh.C:3479
static InputParameters validParams()
void elementsIntersectedByLine(const Point &p0, const Point &p1, const MeshBase &mesh, const PointLocatorBase &point_locator, std::vector< Elem *> &intersected_elems, std::vector< LineSegment > &segments)
Find all of the elements intersected by a line.
Definition: RayTracing.C:192