www.mooseframework.org
NearestPointBase.h
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 
15 #ifndef NEARESTPOINTBASE_H
16 #define NEARESTPOINTBASE_H
17 
18 // MOOSE includes
20 
21 // Forward Declarations
22 class UserObject;
23 
33 template <typename UserObjectType>
36 {
38 
39  params.addRequiredParam<std::vector<Point>>(
40  "points", "Computations will be lumped into values at these points.");
41 
42  // Add in the valid parameters
43  params += validParams<UserObjectType>();
44 
45  return params;
46 }
47 
55 template <typename UserObjectType>
57 {
58 public:
61 
62  virtual void initialize() override;
63  virtual void execute() override;
64  virtual void finalize() override;
65  virtual void threadJoin(const UserObject & y) override;
66 
74  virtual Real spatialValue(const Point & p) const override;
75 
76 protected:
83  std::shared_ptr<UserObjectType> nearestUserObject(const Point & p) const;
84 
85  std::vector<Point> _points;
86  std::vector<std::shared_ptr<UserObjectType>> _user_objects;
87 };
88 
89 template <typename UserObjectType>
91  : ElementIntegralVariableUserObject(parameters), _points(getParam<std::vector<Point>>("points"))
92 {
93  _user_objects.reserve(_points.size());
94 
95  // Build each of the UserObject objects:
96  for (unsigned int i = 0; i < _points.size(); i++)
97  _user_objects.push_back(std::make_shared<UserObjectType>(parameters));
98 }
99 
100 template <typename UserObjectType>
102 {
103 }
104 
105 template <typename UserObjectType>
106 void
108 {
109  for (auto & user_object : _user_objects)
110  user_object->initialize();
111 }
112 
113 template <typename UserObjectType>
114 void
116 {
117  nearestUserObject(_current_elem->centroid())->execute();
118 }
119 
120 template <typename UserObjectType>
121 void
123 {
124  for (auto & user_object : _user_objects)
125  user_object->finalize();
126 }
127 
128 template <typename UserObjectType>
129 void
131 {
132  auto & npla = static_cast<const NearestPointBase &>(y);
133 
134  for (unsigned int i = 0; i < _user_objects.size(); i++)
135  _user_objects[i]->threadJoin(*npla._user_objects[i]);
136 }
137 
138 template <typename UserObjectType>
139 Real
141 {
142  return nearestUserObject(p)->spatialValue(p);
143 }
144 
145 template <typename UserObjectType>
146 std::shared_ptr<UserObjectType>
148 {
149  unsigned int closest = 0;
150  Real closest_distance = std::numeric_limits<Real>::max();
151 
152  for (unsigned int i = 0; i < _points.size(); i++)
153  {
154  const Point & current_point = _points[i];
155 
156  Real current_distance = (p - current_point).norm();
157 
158  if (current_distance < closest_distance)
159  {
160  closest_distance = current_distance;
161  closest = i;
162  }
163  }
164 
165  return _user_objects[closest];
166 }
167 
168 #endif
NearestPointBase(const InputParameters &parameters)
virtual void threadJoin(const UserObject &y) override
Must override.
This UserObject computes averages of a variable storing partial sums for the specified number of inte...
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
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...
std::shared_ptr< UserObjectType > nearestUserObject(const Point &p) const
Get the UserObject that is closest to the point.
std::vector< Point > _points
InputParameters validParams< ElementIntegralVariableUserObject >()
virtual Real spatialValue(const Point &p) const override
Given a Point return the integral value associated with the layer that point falls in for the layered...
virtual void finalize() override
Finalize.
const T & getParam(const std::string &name) const
Retrieve a parameter for the object.
Definition: MooseObject.h:122
const Elem *& _current_elem
The current element pointer (available during execute())
virtual void execute() override
Execute method.
This postprocessor computes a volume integral of the specified variable.
const InputParameters & parameters() const
Get the parameters of the object.
Definition: MooseObject.h:53
std::vector< std::shared_ptr< UserObjectType > > _user_objects
virtual void initialize() override
Called before execute() is ever called so that data can be cleared.
Base class for user-specific data.
Definition: UserObject.h:42
InputParameters nearestPointBaseValidParams()
Because this is a templated base class and template partial specializations are not allowed...