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 
19 template <>
22 {
24  params.addRequiredParam<Point>("start", "The beginning of the line");
25  params.addRequiredParam<Point>("end", "The end of the line");
26  return params;
27 }
28 
30  : GeneralVectorPostprocessor(parameters),
31  _start(getParam<Point>("start")),
32  _end(getParam<Point>("end")),
33  _x_intersections(declareVector("x"))
34 #if LIBMESH_DIM > 1
35  ,
36  _y_intersections(declareVector("y"))
37 #if LIBMESH_DIM > 2
38  ,
39  _z_intersections(declareVector("z"))
40 #endif
41 #endif
42 {
43  _intersections.push_back(&_x_intersections);
44 #if LIBMESH_DIM > 1
45  _intersections.push_back(&_y_intersections);
46 #if LIBMESH_DIM > 2
47  _intersections.push_back(&_z_intersections);
48 #endif
49 #endif
50 
51  _fe_problem.mesh().errorIfDistributedMesh("IntersectionPointsAlongLine");
52 }
53 
54 void
56 {
57  for (unsigned int i = 0; i < _intersections.size(); i++)
58  _intersections[i]->clear();
59 }
60 
61 void
63 {
64  std::vector<Elem *> intersected_elems;
65  std::vector<LineSegment> segments;
66 
67  std::unique_ptr<PointLocatorBase> pl = _fe_problem.mesh().getPointLocator();
68 
69  // We may not have any elements along the given line; if so then
70  // that shouldn't throw a libMesh error.
71  pl->enable_out_of_mesh_mode();
72 
74  _start, _end, _fe_problem.mesh(), *pl, intersected_elems, segments);
75 
76  const unsigned int num_elems = intersected_elems.size();
77 
78  // Quick return in case no elements were found
79  if (num_elems == 0)
80  return;
81 
82  for (unsigned int i = 0; i < LIBMESH_DIM; i++)
83  _intersections[i]->resize(num_elems + 1);
84 
85  // Add the beginning point
86  for (unsigned int i = 0; i < LIBMESH_DIM; i++)
87  (*_intersections[i])[0] = _start(i);
88 
89  // Add the ending point of every segment
90  for (unsigned int i = 0; i < num_elems; i++)
91  {
92  LineSegment & segment = segments[i];
93 
94  const Point & end_point = segment.end();
95 
96  for (unsigned int j = 0; j < LIBMESH_DIM; j++)
97  (*_intersections[j])[i + 1] = end_point(j);
98  }
99 }
const Point & end() const
Ending of the line segment.
Definition: LineSegment.h:65
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.
if(nl->nonlinearSolver() ->matvec &&nl->nonlinearSolver() ->residual_and_jacobian_object)
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:27
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
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:2685
InputParameters validParams< IntersectionPointsAlongLine >()
IntersectionPointsAlongLine(const InputParameters &parameters)
InputParameters validParams< GeneralVectorPostprocessor >()
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:141
virtual void execute() override
Find the elements.
virtual MooseMesh & mesh() override
virtual std::unique_ptr< PointLocatorBase > getPointLocator() const
Proxy function to get a (sub)PointLocator from either the underlying libMesh mesh (default)...
Definition: MooseMesh.C:2730
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