www.mooseframework.org
Public Member Functions | Static Public Member Functions | Protected Member Functions | Protected Attributes | List of all members
NearestPointBase< UserObjectType, BaseType > Class Template Reference

This UserObject computes averages of a variable storing partial sums for the specified number of intervals in a direction (x,y,z). More...

#include <NearestPointBase.h>

Inheritance diagram for NearestPointBase< UserObjectType, BaseType >:
[legend]

Public Member Functions

 NearestPointBase (const InputParameters &parameters)
 
 ~NearestPointBase ()
 
virtual void initialize () override
 
virtual void execute () override
 
virtual void finalize () override
 
virtual void threadJoin (const UserObject &y) override
 
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 average closest to that point. More...
 
virtual const std::vector< Point > & getPoints () const
 Get the points at which the nearest operation is performed. More...
 
virtual const std::vector< Point > spatialPoints () const override
 

Static Public Member Functions

static InputParameters validParams ()
 

Protected Member Functions

void fillPoints ()
 Fills in the _points variable from either 'points' or 'points_file' parameter. More...
 
UserObjectType & nearestUserObject (const Point &p) const
 Get the UserObject that is closest to the point. More...
 
virtual const std::string & name () const
 Get the name of the class. More...
 

Protected Attributes

std::vector< Point > _points
 
std::vector< std::unique_ptr< UserObjectType > > _user_objects
 
const unsigned int _dist_norm
 
const unsigned int _axis
 

Detailed Description

template<typename UserObjectType, typename BaseType>
class NearestPointBase< UserObjectType, BaseType >

This UserObject computes averages of a variable storing partial sums for the specified number of intervals in a direction (x,y,z).

Given a list of points this object computes the layered average closest to each one of those points.

Definition at line 29 of file NearestPointBase.h.

Constructor & Destructor Documentation

◆ NearestPointBase()

template<typename UserObjectType , typename BaseType >
NearestPointBase< UserObjectType, BaseType >::NearestPointBase ( const InputParameters parameters)

Definition at line 117 of file NearestPointBase.h.

118  : BaseType(parameters),
119  _dist_norm(this->template getParam<MooseEnum>("dist_norm")),
120  _axis(this->template getParam<MooseEnum>("axis"))
121 {
122  if (this->template getParam<MooseEnum>("dist_norm") != "radius" &&
123  parameters.isParamSetByUser("axis"))
124  this->template paramError("axis",
125  "'axis' should only be set if 'dist_norm' is set to 'radius'");
126 
127  fillPoints();
128 
129  _user_objects.resize(_points.size());
130 
131  // Build each of the UserObject objects that we will manage manually
132  // If you're looking at this in the future and want to replace this behavior,
133  // _please_ don't do it. MOOSE should manage these objects.
134  for (MooseIndex(_points) i = 0; i < _points.size(); ++i)
135  {
136  const auto uo_type = MooseUtils::prettyCppType<UserObjectType>();
137  auto sub_params = this->_app.getFactory().getValidParams(uo_type);
138  sub_params.applyParameters(parameters, {}, true);
139 
140  const auto sub_name = name() + "_sub" + std::to_string(i);
141  auto uo = this->_app.getFactory().template createUnique<UserObjectType>(
142  uo_type, sub_name, sub_params, this->_tid);
143  _user_objects[i] = std::move(uo);
144  }
145 }
std::vector< std::unique_ptr< UserObjectType > > _user_objects
void fillPoints()
Fills in the _points variable from either &#39;points&#39; or &#39;points_file&#39; parameter.
const unsigned int _axis
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:57
bool isParamSetByUser(const std::string &name) const
Method returns true if the parameter was by the user.
const unsigned int _dist_norm
std::vector< Point > _points

◆ ~NearestPointBase()

template<typename UserObjectType , typename BaseType >
NearestPointBase< UserObjectType, BaseType >::~NearestPointBase ( )

Definition at line 148 of file NearestPointBase.h.

149 {
150 }

Member Function Documentation

◆ execute()

template<typename UserObjectType , typename BaseType >
void NearestPointBase< UserObjectType, BaseType >::execute ( )
overridevirtual

Definition at line 186 of file NearestPointBase.h.

187 {
188  nearestUserObject(_current_elem->vertex_average()).execute();
189 }
UserObjectType & nearestUserObject(const Point &p) const
Get the UserObject that is closest to the point.
virtual void execute() override

◆ fillPoints()

template<typename UserObjectType , typename BaseType >
void NearestPointBase< UserObjectType, BaseType >::fillPoints ( )
protected

Fills in the _points variable from either 'points' or 'points_file' parameter.

Also performs error checking.

Definition at line 154 of file NearestPointBase.h.

Referenced by NearestPointBase< LayeredSideDiffusiveFluxAverage, SideIntegralVariableUserObject >::NearestPointBase().

155 {
156  if (isParamValid("points") && isParamValid("points_file"))
157  mooseError(name(), ": Both 'points' and 'points_file' cannot be specified simultaneously.");
158 
159  if (isParamValid("points"))
160  {
161  _points = this->template getParam<std::vector<Point>>("points");
162  }
163  else if (isParamValid("points_file"))
164  {
165  const FileName & points_file = this->template getParam<FileName>("points_file");
166 
167  MooseUtils::DelimitedFileReader file(points_file, &_communicator);
169  file.read();
170  _points = file.getDataAsPoints();
171  }
172  else
173  mooseError(name(), ": You need to supply either 'points' or 'points_file' parameter.");
174 }
void mooseError(Args &&... args)
Emit an error message with the given stringified, concatenated args and terminate the application...
Definition: MooseError.h:299
Utility class for reading delimited data (e.g., CSV data).
virtual const std::string & name() const
Get the name of the class.
Definition: MooseBase.h:57
std::vector< Point > _points

◆ finalize()

template<typename UserObjectType , typename BaseType >
void NearestPointBase< UserObjectType, BaseType >::finalize ( )
overridevirtual

Reimplemented in NearestPointAverage, and NearestPointIntegralVariablePostprocessor.

Definition at line 193 of file NearestPointBase.h.

194 {
195  for (auto & user_object : _user_objects)
196  user_object->finalize();
197 }
std::vector< std::unique_ptr< UserObjectType > > _user_objects

◆ getPoints()

template<typename UserObjectType, typename BaseType>
virtual const std::vector<Point>& NearestPointBase< UserObjectType, BaseType >::getPoints ( ) const
inlinevirtual

Get the points at which the nearest operation is performed.

Returns
points

Definition at line 55 of file NearestPointBase.h.

55 { return _points; }
std::vector< Point > _points

◆ initialize()

template<typename UserObjectType , typename BaseType >
void NearestPointBase< UserObjectType, BaseType >::initialize ( )
overridevirtual

Definition at line 178 of file NearestPointBase.h.

179 {
180  for (auto & user_object : _user_objects)
181  user_object->initialize();
182 }
std::vector< std::unique_ptr< UserObjectType > > _user_objects

◆ name()

template<typename UserObjectType, typename BaseType>
virtual const std::string& MooseBase::name
inlineprotected

Get the name of the class.

Returns
The name of the class

Definition at line 57 of file MooseBase.h.

57 { return _name; }

◆ nearestUserObject()

template<typename UserObjectType , typename BaseType >
UserObjectType & NearestPointBase< UserObjectType, BaseType >::nearestUserObject ( const Point &  p) const
protected

Get the UserObject that is closest to the point.

Parameters
pThe point.
Returns
The UserObject closest to p.

Definition at line 218 of file NearestPointBase.h.

219 {
220  unsigned int closest = 0;
221  Real closest_distance = std::numeric_limits<Real>::max();
222 
223  for (auto it : Moose::enumerate(_points))
224  {
225  const auto & current_point = it.value();
226 
227  Real current_distance;
228  if (_dist_norm == 0)
229  // the distance is computed using standard norm
230  current_distance = (p - current_point).norm();
231  else
232  {
233  // the distance is to be computed based on radii
234  // in that case, we need to determine the 2 coordinate indices
235  // that define the radius
236  unsigned int i = 0;
237  unsigned int j = 1;
238 
239  if (_axis == 0)
240  i = 2;
241  else if (_axis == 1)
242  j = 2;
243 
244  current_distance = std::abs(
245  std::sqrt(p(i) * p(i) + p(j) * p(j)) -
246  std::sqrt(current_point(i) * current_point(i) + current_point(j) * current_point(j)));
247  }
248 
249  if (current_distance < closest_distance)
250  {
251  closest_distance = current_distance;
252  closest = it.index();
253  }
254  }
255 
256  return *_user_objects[closest];
257 }
_enumerate_range< Iterator > enumerate(Iterator first, Iterator last, typename std::iterator_traits< Iterator >::difference_type initial)
Enumerate function for iterating over a range and obtaining both a reference to the underlying type a...
Definition: Enumerate.h:52
std::vector< std::unique_ptr< UserObjectType > > _user_objects
ADRealEigenVector< T, D, asd > sqrt(const ADRealEigenVector< T, D, asd > &)
auto max(const L &left, const R &right)
const unsigned int _axis
ADRealEigenVector< T, D, asd > abs(const ADRealEigenVector< T, D, asd > &)
auto norm(const T &a) -> decltype(std::abs(a))
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
const unsigned int _dist_norm
std::vector< Point > _points

◆ spatialPoints()

template<typename UserObjectType , typename BaseType >
const std::vector< Point > NearestPointBase< UserObjectType, BaseType >::spatialPoints ( ) const
overridevirtual

Reimplemented in NearestPointIntegralVariablePostprocessor.

Definition at line 261 of file NearestPointBase.h.

262 {
263  std::vector<Point> points;
264 
265  for (MooseIndex(_points) i = 0; i < _points.size(); ++i)
266  {
267  auto layered_base = dynamic_cast<LayeredBase *>(_user_objects[i].get());
268  if (layered_base)
269  {
270  const auto & layers = layered_base->getLayerCenters();
271  auto direction = layered_base->direction();
272 
273  for (const auto & l : layers)
274  {
275  Point pt = _points[i];
276  pt(direction) = l;
277  points.push_back(pt);
278  }
279  }
280  }
281 
282  return points;
283 }
std::vector< std::unique_ptr< UserObjectType > > _user_objects
const std::vector< Real > & getLayerCenters() const
Get the center coordinates for the layers (along given direction)
Definition: LayeredBase.h:67
This base class computes volume integrals of a variable storing partial sums for the specified number...
Definition: LayeredBase.h:36
std::vector< Point > _points

◆ spatialValue()

template<typename UserObjectType , typename BaseType >
Real NearestPointBase< UserObjectType, BaseType >::spatialValue ( const Point &  p) const
overridevirtual

Given a Point return the integral value associated with the layer that point falls in for the layered average closest to that point.

Parameters
pThe point to look for in the layers.

Reimplemented in NearestPointAverage, and NearestPointIntegralVariablePostprocessor.

Definition at line 211 of file NearestPointBase.h.

212 {
213  return nearestUserObject(p).spatialValue(p);
214 }
UserObjectType & nearestUserObject(const Point &p) const
Get the UserObject that is closest to the point.

◆ threadJoin()

template<typename UserObjectType , typename BaseType >
void NearestPointBase< UserObjectType, BaseType >::threadJoin ( const UserObject y)
overridevirtual

Definition at line 201 of file NearestPointBase.h.

202 {
203  auto & npla = static_cast<const NearestPointBase &>(y);
204 
205  for (MooseIndex(_user_objects) i = 0; i < _user_objects.size(); ++i)
206  _user_objects[i]->threadJoin(*npla._user_objects[i]);
207 }
This UserObject computes averages of a variable storing partial sums for the specified number of inte...
std::vector< std::unique_ptr< UserObjectType > > _user_objects
virtual void threadJoin(const UserObject &y) override

◆ validParams()

template<typename UserObjectType , typename BaseType >
InputParameters NearestPointBase< UserObjectType, BaseType >::validParams ( )
static

Definition at line 91 of file NearestPointBase.h.

Referenced by NearestPointLayeredSideAverageFunctor::validParams(), NearestPointLayeredSideIntegralFunctor::validParams(), NearestPointAverage::validParams(), NearestPointLayeredSideIntegral::validParams(), NearestPointLayeredAverage::validParams(), NearestPointLayeredSideAverage::validParams(), NearestPointLayeredIntegral::validParams(), and NearestRadiusLayeredAverage::validParams().

92 {
94 
95  params.addParam<std::vector<Point>>("points",
96  "Computations will be lumped into values at these points.");
97  params.addParam<FileName>("points_file",
98  "A filename that should be looked in for points. Each "
99  "set of 3 values in that file will represent a Point. "
100  "This and 'points' cannot be both supplied.");
101 
102  MooseEnum distnorm("point=0 radius=1", "point");
103  params.addParam<MooseEnum>(
104  "dist_norm", distnorm, "To specify whether the distance is defined based on point or radius");
105  MooseEnum axis("x=0 y=1 z=2", "z");
106  params.addParam<MooseEnum>("axis", axis, "The axis around which the radius is determined");
107 
108  params.addParamNamesToGroup("points points_file dist_norm axis", "Points and distance to points");
109 
110  // Add in the valid parameters
111  params += UserObjectType::validParams();
112 
113  return params;
114 }
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
InputParameters validParams()
This is a "smart" enum class intended to replace many of the shortcomings in the C++ enum type It sho...
Definition: MooseEnum.h:31
void addParam(const std::string &name, const S &value, const std::string &doc_string)
These methods add an option parameter and a documentation string to the InputParameters object...
void addParamNamesToGroup(const std::string &space_delim_names, const std::string group_name)
This method takes a space delimited list of parameter names and adds them to the specified group name...

Member Data Documentation

◆ _axis

template<typename UserObjectType, typename BaseType>
const unsigned int NearestPointBase< UserObjectType, BaseType >::_axis
protected

Definition at line 80 of file NearestPointBase.h.

◆ _dist_norm

template<typename UserObjectType, typename BaseType>
const unsigned int NearestPointBase< UserObjectType, BaseType >::_dist_norm
protected

Definition at line 78 of file NearestPointBase.h.

◆ _points

template<typename UserObjectType, typename BaseType>
std::vector<Point> NearestPointBase< UserObjectType, BaseType >::_points
protected

◆ _user_objects

template<typename UserObjectType, typename BaseType>
std::vector<std::unique_ptr<UserObjectType> > NearestPointBase< UserObjectType, BaseType >::_user_objects
protected

The documentation for this class was generated from the following file: