www.mooseframework.org
IntersectionPointsAlongLine.C
Go to the documentation of this file.
1 /****************************************************************/
2 /* DO NOT MODIFY THIS HEADER */
3 /* MOOSE - Multiphysics Object Oriented Simulation Environment */
4 /* */
5 /* (c) 2010 Battelle Energy Alliance, LLC */
6 /* ALL RIGHTS RESERVED */
7 /* */
8 /* Prepared by Battelle Energy Alliance, LLC */
9 /* Under Contract No. DE-AC07-05ID14517 */
10 /* With the U. S. Department of Energy */
11 /* */
12 /* See COPYRIGHT for full restrictions */
13 /****************************************************************/
14 
16 
17 // MOOSE includes
18 #include "LineSegment.h"
19 #include "RayTracing.h"
20 #include "MooseMesh.h"
21 
22 template <>
25 {
27  params.addRequiredParam<Point>("start", "The beginning of the line");
28  params.addRequiredParam<Point>("end", "The end of the line");
29  return params;
30 }
31 
33  : GeneralVectorPostprocessor(parameters),
34  _start(getParam<Point>("start")),
35  _end(getParam<Point>("end")),
36  _x_intersections(declareVector("x"))
37 #if LIBMESH_DIM > 1
38  ,
39  _y_intersections(declareVector("y"))
40 #if LIBMESH_DIM > 2
41  ,
42  _z_intersections(declareVector("z"))
43 #endif
44 #endif
45 {
46  _intersections.push_back(&_x_intersections);
47 #if LIBMESH_DIM > 1
48  _intersections.push_back(&_y_intersections);
49 #if LIBMESH_DIM > 2
50  _intersections.push_back(&_z_intersections);
51 #endif
52 #endif
53 
54  _fe_problem.mesh().errorIfDistributedMesh("IntersectionPointsAlongLine");
55 }
56 
57 void
59 {
60  for (unsigned int i = 0; i < _intersections.size(); i++)
61  _intersections[i]->clear();
62 }
63 
64 void
66 {
67  std::vector<Elem *> intersected_elems;
68  std::vector<LineSegment> segments;
69 
70  std::unique_ptr<PointLocatorBase> pl = _fe_problem.mesh().getPointLocator();
71 
72  // We may not have any elements along the given line; if so then
73  // that shouldn't throw a libMesh error.
74  pl->enable_out_of_mesh_mode();
75 
77  _start, _end, _fe_problem.mesh(), *pl, intersected_elems, segments);
78 
79  const unsigned int num_elems = intersected_elems.size();
80 
81  // Quick return in case no elements were found
82  if (num_elems == 0)
83  return;
84 
85  for (unsigned int i = 0; i < LIBMESH_DIM; i++)
86  _intersections[i]->resize(num_elems + 1);
87 
88  // Add the beginning point
89  for (unsigned int i = 0; i < LIBMESH_DIM; i++)
90  (*_intersections[i])[0] = _start(i);
91 
92  // Add the ending point of every segment
93  for (unsigned int i = 0; i < num_elems; i++)
94  {
95  LineSegment & segment = segments[i];
96 
97  const Point & end_point = segment.end();
98 
99  for (unsigned int j = 0; j < LIBMESH_DIM; j++)
100  (*_intersections[j])[i + 1] = end_point(j);
101  }
102 }
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:33
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
void errorIfDistributedMesh(std::string name) const
Generate a unified error message if the underlying libMesh mesh is a DistributedMesh.
Definition: MooseMesh.C:2473
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...
InputParameters validParams< IntersectionPointsAlongLine >()
IntersectionPointsAlongLine(const InputParameters &parameters)
InputParameters validParams< GeneralVectorPostprocessor >()
virtual std::unique_ptr< PointLocatorBase > getPointLocator() const
Proxy function to get a (sub)PointLocator from either the underlying libMesh mesh (default)...
Definition: MooseMesh.C:2540
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:197
std::vector< VectorPostprocessorValue * > _intersections
Tie them together for convenience.
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Definition: UserObject.h:149
virtual void execute() override
Find the elements.
virtual MooseMesh & mesh() override
const Point & end() const
Ending of the line segment.
Definition: LineSegment.h:71