Loading [MathJax]/extensions/tex2jax.js
https://mooseframework.inl.gov
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends
NearestPointAverage.C
Go to the documentation of this file.
1 //* This file is part of the MOOSE framework
2 //* https://mooseframework.inl.gov
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 // MOOSE includes
11 #include "NearestPointAverage.h"
12 
14 
17 {
18  InputParameters params =
20 
21  // The base type (ElementAverageValue) and the user object type (ElementVariableVPP) are
22  // postprocessor and VPP respectively and this object is meant to be a UO
23  params.set<std::string>("_moose_base") = "UserObject";
24 
25  params.addClassDescription(
26  "Compute element variable averages for nearest-point based subdomains");
27 
28  return params;
29 }
30 
33  _np_post_processor_values(declareVector("np_post_processor_values"))
34 {
36 }
37 
38 Real
39 NearestPointAverage::spatialValue(const Point & point) const
40 {
41  unsigned int i = nearestPointIndex(point);
42 
43  if (i >= _np_post_processor_values.size())
44  mooseError("The vector length of vector post processor is ",
46  " but nearestPointIndex() return ",
47  i);
48 
49  return _np_post_processor_values[i];
50 }
51 
52 Real
54 {
55  if (i >= _np_post_processor_values.size())
56  mooseError("The vector length of vector post processor is ",
58  " but you pass in ",
59  i);
60 
61  return _np_post_processor_values[i];
62 }
63 
64 void
66 {
67  if (_user_objects.size() != _np_post_processor_values.size())
68  mooseError("The vector length of the vector postprocessor ",
70  " is different from the number of user objects ",
71  _user_objects.size());
72 
73  unsigned int i = 0;
74  for (auto & user_object : _user_objects)
75  {
76  user_object->finalize();
77  const auto & const_user_object = *user_object;
78  _np_post_processor_values[i++] = const_user_object.getValue();
79  }
80 }
81 
82 unsigned int
84 {
85  unsigned int closest = 0;
86  Real closest_distance = std::numeric_limits<Real>::max();
87 
88  for (auto it : Moose::enumerate(_points))
89  {
90  const auto & current_point = it.value();
91 
92  Real current_distance = (p - current_point).norm();
93 
94  if (current_distance < closest_distance)
95  {
96  closest_distance = current_distance;
97  closest = it.index();
98  }
99  }
100 
101  return closest;
102 }
This UserObject computes averages of a variable storing partial sums for the specified number of inte...
T & set(const std::string &name, bool quiet_mode=false)
Returns a writable reference to the named parameters.
The main MOOSE class responsible for handling user-defined parameters in almost every MOOSE system...
_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< ElementAverageValue > > _user_objects
static InputParameters validParams()
auto max(const L &left, const R &right)
registerMooseObject("MooseApp", NearestPointAverage)
Base class VectorPostprocessors operating on elemental variables.
virtual void finalize() override
Finalize.
NearestPointAverage(const InputParameters &parameters)
auto norm(const T &a) -> decltype(std::abs(a))
VectorPostprocessorValue & _np_post_processor_values
Postprocessor values for each point.
static InputParameters validParams()
virtual Real spatialValue(const Point &point) const override
Given a Point return the integral value associated with the layer that point falls in for the layered...
DIE A HORRIBLE DEATH HERE typedef LIBMESH_DEFAULT_SCALAR_TYPE Real
Real userObjectValue(unsigned int i) const
void mooseError(Args &&... args) const
Emits an error prefixed with object name and type.
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...
This postprocessor computes a volume integral of the specified variable.
unsigned int nearestPointIndex(const Point &point) const
Given a list of points this object computes the average of a variable over the points closest to each...