www.mooseframework.org
ElementsAlongLine.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 
10 #include "ElementsAlongLine.h"
11 
12 // MOOSE includes
13 #include "LineSegment.h"
14 #include "RayTracing.h"
15 #include "MooseMesh.h"
16 
18 
21 {
23 
24  params.addRequiredParam<Point>("start", "The beginning of the line");
25  params.addRequiredParam<Point>("end", "The end of the line");
26  params.addClassDescription("Outputs the IDs of every element intersected by a user-defined line");
27  return params;
28 }
29 
31  : GeneralVectorPostprocessor(parameters),
32  _start(getParam<Point>("start")),
33  _end(getParam<Point>("end")),
34  _elem_ids(declareVector("elem_ids"))
35 {
36  _fe_problem.mesh().errorIfDistributedMesh("ElementsAlongLine");
37 }
38 
39 void
41 {
42  _elem_ids.clear();
43 }
44 
45 void
47 {
48  std::vector<Elem *> intersected_elems;
49  std::vector<LineSegment> segments;
50 
51  std::unique_ptr<PointLocatorBase> pl = _fe_problem.mesh().getPointLocator();
53  _start, _end, _fe_problem.mesh(), *pl, intersected_elems, segments);
54 
55  unsigned int num_elems = intersected_elems.size();
56 
57  _elem_ids.resize(num_elems);
58 
59  for (unsigned int i = 0; i < num_elems; i++)
60  _elem_ids[i] = intersected_elems[i]->id();
61 }
ElementsAlongLine(const InputParameters &parameters)
Point _start
The beginning of the line.
This class is here to combine the VectorPostprocessor interface and the base class VectorPostprocesso...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
Point _end
The end 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...
void errorIfDistributedMesh(std::string name) const
Generate a unified error message if the underlying libMesh mesh is a DistributedMesh.
Definition: MooseMesh.C:3368
static InputParameters validParams()
registerMooseObject("MooseApp", ElementsAlongLine)
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
virtual void execute() override
Find the elements.
static InputParameters validParams()
FEProblemBase & _fe_problem
Reference to the FEProblemBase for this user object.
Definition: UserObject.h:210
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...
VectorPostprocessorValue & _elem_ids
The elements that intersect the line.
Get all of the elements that are intersected by a line.
virtual std::unique_ptr< PointLocatorBase > getPointLocator() const
Proxy function to get a (sub)PointLocator from either the underlying libMesh mesh (default)...
Definition: MooseMesh.C:3480
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